diff options
-rw-r--r-- | Add-a-new-level-cap.md | 115 |
1 files changed, 76 insertions, 39 deletions
diff --git a/Add-a-new-level-cap.md b/Add-a-new-level-cap.md index bfb1838..fbe21ff 100644 --- a/Add-a-new-level-cap.md +++ b/Add-a-new-level-cap.md @@ -1,6 +1,32 @@ -**TODO**: Add context lines to the diffs, use diff syntax highlighting, and explain what this tutorial will accomplish. +This tutorial guides you through changing the max level. You will add a new variable, modify level cap logic, and optionally remove gaining exp. once a pokemon is the max level. -1. In `engine/pokemon/experience.asm`, go to line 9: `cp LOW(MAX_LEVEL + 1)`. This is what we first need to change. Before the `ld a, d` on the line before it, add code to load the new level cap into register `b`. +**TODO**: +Investigate wether one is able to set the level cap by modifying `MAX_LEVEL EQU [0-255]` in `constants/battle_constants.asm`. + +## 1. Add Level Cap variable +First, we want to add a `wLevelCap` variable to `wram.asm` in the root folder. +In `wram.asm`, go to line 2668, `wBeverlyFightCount:: db ; unused`. +Since this byte is unused, you can replace it. +Replace this line with `wLevelCap:: db`. +This is the value we'll be checking for the level cap + +```diff +; fight counts +wJackFightCount:: db ; d9f2 +- wBeverlyFightCount:: db ; unused ++ wLevelCap:: db +wHueyFightCount:: db +wGavenFightCount:: db +``` + +To set the level cap, write this in a script: +`loadmem wLevelCap, [0-255] ; number from 0 to 255 representing what your level cap should be` + +## 2. Replace first level cap check + +In `engine/pokemon/experience.asm`, go to line 9: `cp LOW(MAX_LEVEL + 1)`. +This is what we first need to change. +Before the `ld a, d` on the line before it, add code to load the new level cap into register `b`. ```diff .next_level @@ -17,7 +43,11 @@ call CalcExpAtLevel ``` -2. There are now five more instances of `MAX_LEVEL` that you'll need to change. First, go to the `.no_exp_overflow` label located in `engine/battle/core.asm`. Instead of storing the `MAX_LEVEL` value, we load our custom max level. +## 3. Replace the rest of the cap checks + +There are now five more instances of `MAX_LEVEL` that you'll need to change. +First, go to the `.no_exp_overflow` label located in `engine/battle/core.asm`. +Instead of storing the `MAX_LEVEL` value, we load our custom max level. ```diff .no_exp_overflow @@ -56,11 +86,11 @@ Next, `ctrl + f` for the next instance of `MAX_LEVEL`, located in the `.not_max_ ld a, [hl] + cp b + pop bc - cp MAX_LEVEL +- cp MAX_LEVEL jp nc, .next_mon ``` -Third, ctrl + f for the next instance of MAX_LEVEL. You'll notice there's a `ld a, [wBattleMonLevel]` before it. Before this, add +Third, ctrl + f for the next instance of MAX_LEVEL, located in the `AnimateExpBar` label. You'll notice there's a `ld a, [wBattleMonLevel]` before it. Before this, add ```diff AnimateExpBar: @@ -71,54 +101,65 @@ AnimateExpBar: cp [hl] jp nz, .finish ++ ld a, [wLevelCap] ++ push bc ++ ld b, a ld a, [wBattleMonLevel] - cp MAX_LEVEL - jp nc, .finish -``` -After `ld a, [wBattleMonLevel]`, add - -```diff + cp b + pop bc +- cp MAX_LEVEL + jp nc, .finish ``` -Fourth, ctrl + f for the next instance of MAX_LEVEL. Replace `ld d, MAX_LEVEL` with + +Fourth, ctrl + f for the next instance of MAX_LEVEL. Replace `ld d, MAX_LEVEL` with loading the custom max level. ```diff + ld [hli], a + ld [hl], a + +.NoOverflow: + push af + ld a, [wLevelCap] + ld d, a + pop af + callfar CalcExpAtLevel + ldh a, [hProduct + 1] + ld b, a ``` -Fifth, ctrl + f for the final instance of MAX_LEVEL. You'll notice before it reads `ld a, e`. Before this, add +Fifth, ctrl + f for the final instance of MAX_LEVEL. You'll notice before it reads `ld a, e`. Before this, lod the level cap into b, then do the comparison on that. ```diff + ld a, e + ld d, a + +.LoopLevels: + ld a, [wLevelCap] + push bc + ld b, a -``` -Then, after `ld a, e`, add - -```diff + ld a, e +- cp MAX_LEVEL + cp b + pop bc + jr nc, .FinishExpBar + cp d + jr z, .FinishExpBar + inc a ``` Now you're done with replacing the max level checks with the level cap checks. -3. Now, you need to add wLevelCap to wram.asm in the root folder. In wram.asm, go to line 2668, `wBeverlyFightCount:: db ; unused`. Since this byte is unused, you can replace it. Replace this line with `wLevelCap:: db`. +## 4. Optional: Remove exp. gain text at max level -4. Optional: You'll notice that the exp. gain text still displays when you reach the level cap. To remove this, go to line 7059 in engine/battle/core.asm, which should be about the lines of +You'll notice that the exp. gain text still displays when you reach the level cap. +To remove this, go to line 7059 in `engine/battle/core.asm`, which should be about the lines of ```diff +.stat_exp_awarded + inc de inc de dec c jr nz, .stat_exp_loop -``` - -Add this routine after it: - -```diff + pop bc + ld hl, MON_LEVEL + add hl, bc @@ -130,19 +171,22 @@ Add this routine after it: + pop bc + jp nc, .next_mon + push bc + xor a + ldh [hMultiplicand + 0], a + ldh [hMultiplicand + 1], a + ld a, [wEnemyMonBaseExp] ``` Next, go to ```diff +.EvenlyDivideExpAmongParticipants: +; count number of battle participants + ld a, [wBattleParticipantsNotFainted] + ld b, a ld c, PARTY_LENGTH ld d, 0 .count_loop -``` - -Underneath this, add - -```diff + push bc + push de + ld a, [wLevelCap] @@ -164,18 +208,11 @@ Underneath this, add + ld a, d + jr .no_exp +.gains_exp -``` - -Last, under that is - -```diff xor a srl b adc d ld d, a ++.no_exp + dec c + jr nz, .count_loop ``` - -After this, add `.no_exp` - -To set a level cap, write this in a script: -`loadmem wLevelCap, number from 0 to 255 representing what your level cap should be`
\ No newline at end of file |