This document obtained from 1whoistornapart's website: http://sonic_death.byethost31.com/DW3Spell.txt LEARNING SPELLS There are several arrays which interact to control how learning spells work. The first set of arrays represent the levels which spells are learned at and how the spells are learned. It only indirectly controls which actual spell is learned, which can be a source of confusion. Goof-offs learn their stuff in a similar way to useful classes learning spells. When you level-up, the game will compare your new level to this array, in a way that's kind of hard to explain. First of all, any byte that says "3F" is junk, and is just there to make the index align properly (you'll see why the index is important later). What may surprise you is that there are two different ways spells can be learned. Which method the spell uses is determined by the sign bit (MSB), we'll start with the easier one, which is used when the sign bit is set (e.g. the fourth byte of the Wizard's array). Hero's magic levels: 02 3F 3F 0A 17 3F 3F 1F 3F 3F 3F 3F 3F 3F 3F 3F 1A 29 3F 3F 3F 06 3F 3F 3F 3F 04 1D 21 3F 3F 26 23 3F 10 3F 12 3F 07 3F 3F 3F 0C 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 14 3F 3F 3F 0E 3F 3F FF Wizard's magic levels: 01 11 24 87 0E 1D 0B 17 26 05 14 1A 20 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 8F 0C 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 0D 9B A5 A2 3F 3F 3F 84 89 3F 98 3F 95 A8 3F 3F 1E 3F 19 23 12 0A 21 13 FF Pilgrim's magic levels: 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F 0C 1A A4 3F 3F 96 1C A9 02 94 3F 3F 85 01 0E 1E 3F 22 3F 18 26 09 90 0D 87 3F 3F 3F 3F 3F 88 12 3F 3F 3F 3F 20 3F 3F 0B 0F 3F 3F 3F 3F 3F 3F 3F 3F FF Sage's magic levels: 01 11 24 87 0E 1D 0B 17 26 05 14 1A 20 0C 1A A4 3F 3F 96 1C A9 02 94 8F 0C 85 01 0E 1E 3F 22 3F 18 26 09 90 0D 87 0D 9B A5 A2 3F 88 12 84 89 3F 98 20 95 A8 0B 0F 1E 3F 19 23 12 0A 21 13 FF Goof-Off stuff: 1C 14 28 10 0A 05 18 13 07 22 1D 03 0F 20 02 5F 1F 2D 0E 1E 25 27 1A 15 0B 32 46 55 21 3C 0C 1B 12 23 FF At every level up, each byte is checked one-by-one. If the sign bit is set, then your current level is compared to the value of the byte ANDed with 0x3F. If your level is greater than or equal to this value, then you have a 50/50 chance to learn the spell. Should it fail, you'll keep getting the same 50/50 chance every subsequent level-up until you either learn the spell or hit level 99. In general, it is usually the status-inflicting and stat-altering battle spells that are learned this way. If the sign bit is clear, then things get a little more complicated, but at least with this method you have a guaranteed range of levels to learn the spell (unlike the previous method where if your luck is really bad you might not learn the spell until several levels later than you should). If the byte does not equal 0x3F (as I said before, those are junk) then the value is subtracted from your level. The result of this subtraction must lie between 0 and 2 inclusive to be eligible to learn the spell. A 3x3 array represents your chance to learn the spell when compared with the RNG. The difference between your level and the byte value represent one of the indexes: Chance [0][?]: FF, 80, 0 Chance [1][?]: FF, FF, 80 Chance [2][?]: FF, FF, FF Notice that if your current level is two levels higher than the coded level, you WILL learn the spell regardless of what the RNG does. Now, we'll have to dip back into how stat gains at level-ups are calculated. The characters Baseline Intelligence (without 10 added) is compared to their current Intelligence. The second index in the previous array starts at 2 and is decremented for each of the following that are true: (Intelligence - BaseIntGain * Level) + 15 >= 0 (Intelligence - BaseIntGain * Level) + 15 >= 25 If the first check is not true, the second check is skipped entirely. While the intent of the first check seems to be catching if your Intelligence is well under the Baseline through underflow, you can also miss this chance by having your Intelligence be far OVER the baseline, through Seed farming or class change. The processor can't tell the difference between 128 and -128 without context. (The algorithm should swap the order of addition and subtraction, then use a BCC instead of a BMI, to account for high intelligence values vs. low levels). Fortunately, this should only be noticeable if class-changing into a Sage from a very high-level Wizard/Pilgrim/GoofOff. Now, retrieve the spell chance from the previous 2D array. For example, if our level is exactly equal to the coded level, and we pass one Intelligence check but miss the other, we'll use Chance[0][1] which is 0x80. If (Rand(0..255) <= Chance[x][y]) the spell is learned. Note that this is actually a 129/256 chance, not 128/256. If the chance is 0xFF, it is impossible for the RNG to return a number higher than that. For the rare 0 chance, there is still a 1/256 chance to learn the spell. Hero's magic bits: 00 1A 15 2A 03 26 24 22 10 1B 04 1C 07 20 11 1F FF FF FF FF FF FF FF FF 1A 26 3B 37 1B 1C 20 1F Wizard's magic bits: 00 2D 09 2E 03 26 06 18 01 17 0A 0C 04 32 07 30 02 27 0B 29 05 28 08 33 3B 26 3A 3D 38 36 3C 39 Pilgrim's magic bits: 2B 1A 15 34 0D 19 25 22 2C 1B 12 35 0E 24 16 23 31 1C 13 1E 0F 20 14 21 1A 34 1B 35 20 1C 1E 21 (Sage = Wizard and Pilgrim) GoofOff stuff: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 (wow that's hard to remember, huh?) Now we've learned a spell, but we still don't know WHAT exactly we've learned. This array determines which bit in the heroes' magic arrays to set to represent learning the spell. To use it, we must recall the index of the value we tested against our level earlier. For example, the first spell a Pilgrim will learn from levelling is the "2" at index 0x15. (The "1" later on is the default Heal spell. The game will still perform all the necessary operations to learn Heal, but then will check the magic byte, see that it is already learned and move on without changing anything. This what what screws you over if you use the Hero's magic glitch!) OK, so we have our index number settled as 0x15. Now we have to step through the values in this second array until we find a value that matches the index. This will happen in short order at index 2. Now this index will tell what bit to turn on in the Pilgrim's magic list. Spell page (byte number) = Index / 8 Bit number = Index % 8 Pilgrims don't have to worry about their magic being contained in a different set of bytes than Wizard magic, the way the pointers are set up takes care of that automatically. As for which individual bit to check and set, it would be calculated by Bit = 1 << (Index % 8 - 1) Notice that in these arrays the same number can appear twice. This corresponds to spells that can be used both in battle and on the field. They are learned at the same time, obviously, yet still a different bit must be set for each. For reference, here are the charts telling what bit represents what spell. Hero Magic: Page 0 1 3 Bit 7 = Sleep Healusall Healusall Bit 6 = StopSpell Lightning Vivify Bit 5 = Return Vivify Healall Bit 4 = Firebal Boom Healmore Bit 3 = Ironize Healall Repel Bit 2 = Expel Firebane Outside Bit 1 = Heal Healmore Return Bit 0 = Blaze Zap Heal Wizard Magic: Page 0 1 2 3 Bit 7 = Slow Bounce Chance Open Bit 6 = Bang Boom Explodet Invisible Bit 5 = Return Bikill Transform CurseOff Bit 4 = Fireball Firebane Firevolt Day-Night Bit 3 = Increase Icespears BeDragon Stepguard Bit 2 = IceBolt Snowblast Snowstorm X-Ray Bit 1 = Upper RobMagic Chaos Return Bit 0 = Blaze Blazemore Blazemost Outside Pilgrim Magic: Page 0 1 2 3 Bit 7 = Sleep Awake Revive Revive Bit 6 = Surround Limbo Sacrifice Healus Bit 5 = SpeedUP Stopspell Vivify Healall Bit 4 = Infernos Infermore Infermost Vivify Bit 3 = Antidote NumbOff Healus NumbOff Bit 2 = Expel Beat Defeat Healmore Bit 1 = Heal Healmore Healall Antidote Bit 0 = Sap Defense Barrier Heal As far as I can tell, Sages learn spells just as if they were both Priests and Wizards. I know nothing about what all the Goof-Off stuff is, but now that I know where to look it shouldn't be too hard to figure out. Well, even though you now know how to read all those numbers, it's probably still a good idea to make a chart with the listings of spell per level. Really, for a game whose code is usually well organized and logical, this part of it is totally haphazard :( My guess is that the spell names and damage effects were all coded in before they decided the levels to learn them at, then had to conform the level arrays around the pre-defined spell IDs, hence all the garbage data in there. If a discrete range of three levels are given, you WILL learn the spell on one of those levels, depending on how intelligent you are. If it has an asterisk, then the number represents the earliest opportunity to learn the spell. You will have a 50/50 chance to learn it, and another 50/50 every subsequent level until it is learned, regardless of intelligence or how many levels have gone by. HERO WIZARD PILGRIM Spell: Level: | Spell: Level: | Spell: Level: Blaze 2-4 | Blaze start | Heal start Heal 4-6 | Upper 4* | Expel 2-4 Expel 6-8 | IceBolt 5-7 | SpeedUP 5* Return 7-9 | Fireball 7* | Surround 7* Fireball 10-12 | Increase 9* | Sap 8* Ironize 12-14 | Outside 10-12 | Sleep 9-11 Outside 15-17 | Bang 11-13 | Antidote 11-13 Sleep 16-18 | Slow 12-14 | Infernos 12-14 Stopspell 18-20 | Return 14-16 | Stopspell 13-15 Repel 20-22 | Firebane 14-16 | Healmore 14-16 Firebane 23-25 | RobMagic 15* | NumbOff 15-17 Zap 26-28 | Blazemore 17-19 | Awake 16* Healmore 29-31 | X-Ray 18-20 | Defense 18-20 Boom 31-33 | Stepguard 19-21 | Limbo 20* Healall 33-35 | Snowblast 20-22 | Beat 22* Vivify 35-37 | Bikill 21* | Vivify 24-26 Healusall 38-40 | Boom 23-25 | Infermore 26-28 Lightning 41-43 | Bounce 24* | Defeat 28-30 | Day-Night 25-27 | Healall 30-32 | Snowstorm 26-28 | Barrier 32-34 | Chaos 27* | Healus 34-36 | Firevolt 29-31 | Infermost 36* | CurseOff 30-32 | Revive 38-40 | IceSpears 32-34 | Sacrifice 41* | Invisible 33-35 | | BeDragon 34* | | Open 35-37 | | Blazemost 36-38 | | Transform 37* | | Explodet 38-40 | | Chance 40* |