decrement_pp.asm 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. DecrementPP:
  2. ; after using a move, decrement pp in battle and (if not transformed?) in party
  3. ld a, [de]
  4. cp STRUGGLE
  5. ret z ; if the pokemon is using "struggle", there's nothing to do
  6. ; we don't decrement PP for "struggle"
  7. ld hl, wPlayerBattleStatus1
  8. ld a, [hli] ; load the wPlayerBattleStatus1 pokemon status flags and increment hl to load the
  9. ; wPlayerBattleStatus2 status flags later
  10. and (1 << STORING_ENERGY) | (1 << THRASHING_ABOUT) | (1 << ATTACKING_MULTIPLE_TIMES)
  11. ret nz ; if any of these statuses are true, don't decrement PP
  12. bit USING_RAGE, [hl]
  13. ret nz ; don't decrement PP either if Pokemon is using Rage
  14. ld hl, wBattleMonPP ; PP of first move (in battle)
  15. ; decrement PP in the battle struct
  16. call .DecrementPP
  17. ; decrement PP in the party struct
  18. ld a, [wPlayerBattleStatus3]
  19. bit TRANSFORMED, a
  20. ret nz ; Return if transformed. Pokemon Red stores the "current pokemon's" PP
  21. ; separately from the "Pokemon in your party's" PP. This is
  22. ; duplication -- in all cases *other* than Pokemon with Transform.
  23. ; Normally, this means we have to go on and make the same
  24. ; modification to the "party's pokemon" PP that we made to the
  25. ; "current pokemon's" PP. But, if we're dealing with a Transformed
  26. ; Pokemon, it has separate PP for the move set that it copied from
  27. ; its opponent, which is *not* the same as its real PP as part of your
  28. ; party. So we return, and don't do that part.
  29. ld hl, wPartyMon1PP ; PP of first move (in party)
  30. ld a, [wPlayerMonNumber] ; which mon in party is active
  31. ld bc, wPartyMon2 - wPartyMon1
  32. call AddNTimes ; calculate address of the mon to modify
  33. .DecrementPP:
  34. ld a, [wPlayerMoveListIndex] ; which move (0, 1, 2, 3) did we use?
  35. ld c, a
  36. ld b, 0
  37. add hl ,bc ; calculate the address in memory of the PP we need to decrement
  38. ; based on the move chosen.
  39. dec [hl] ; Decrement PP
  40. ret