diff options
-rw-r--r-- | Allow-more-trainer-parties,-with-individual-DVs,-stat-experience,-nicknames,-variable-teams,-etc..md (renamed from Allow-more-trainer-parties,-with-individual-DVs,-stat-experience,-and-nicknames.md) | 124 |
1 files changed, 123 insertions, 1 deletions
diff --git a/Allow-more-trainer-parties,-with-individual-DVs,-stat-experience,-and-nicknames.md b/Allow-more-trainer-parties,-with-individual-DVs,-stat-experience,-nicknames,-variable-teams,-etc..md index 59d93f1..1fe38d3 100644 --- a/Allow-more-trainer-parties,-with-individual-DVs,-stat-experience,-and-nicknames.md +++ b/Allow-more-trainer-parties,-with-individual-DVs,-stat-experience,-nicknames,-variable-teams,-etc..md @@ -13,6 +13,7 @@ This tutorial will fix all of those problems. 4. [Add a trainer type flag for stat experience](#4-add-a-trainer-type-flag-for-stat-experience) 5. [Allow trainer data to be stored in multiple banks](#5-allow-trainer-data-to-be-stored-in-multiple-banks) 6. [Add a trainer type flag for variable parties](#6-add-a-trainer-type-flag-for-variable-parties) +7. [Add a trainer type flag for happiness](#7-add-a-trainer-type-flag-for-happiness) ## 1. Refactor trainer types to use bit flags @@ -1446,5 +1447,126 @@ Now the enemy trainer's team will vary depending on how many badges you have. A few things to note about this: - One trainer ID applies to all 17 parties, depending on your badge count. So you don't have to repeat the trainer's name 17 times. -- Each party can have its own actual type (normal, item, moves, or item+moves). +- Each party can have its own actual type (normal, item, moves, etc.). - Each stage ends in $fe (except the last one ends in $ff) so you cannot use it for individual DV values (unless you change the delimiter's value, of course). + +## 7. Add a trainer type flag for happiness + +Normally all enemy Pokémon have base happiness (70), including trainers, so in this step we'll be able to give trainer parties different happiness values for each Pokémon, so that one Pokémon can have max power Return and another max power Frustration. Let's edit [constants/trainer_data_constants.asm](../blob/master/constants/trainer_data_constants.asm) to add a new trainer type flag: + +```diff + ; TrainerTypes bits (see engine/battle/read_trainer_party.asm) + const_def + const TRAINERTYPE_MOVES_F ; 0 + const TRAINERTYPE_ITEM_F ; 1 + const TRAINERTYPE_NICKNAME_F ; 2 + const TRAINERTYPE_DVS_F ; 3 + const TRAINERTYPE_STAT_EXP_F ; 4 + const TRAINERTYPE_VARIABLE_F ; 5 + const TRAINERTYPE_HAPPINESS_F ; 6 + + ; Trainer party types (see data/trainers/parties.asm) + TRAINERTYPE_NORMAL EQU 0 + TRAINERTYPE_MOVES EQU 1 << TRAINERTYPE_MOVES_F + TRAINERTYPE_ITEM EQU 1 << TRAINERTYPE_ITEM_F + TRAINERTYPE_ITEM_MOVES EQU TRAINERTYPE_MOVES | TRAINERTYPE_ITEM + TRAINERTYPE_NICKNAME EQU 1 << TRAINERTYPE_NICKNAME_F + TRAINERTYPE_DVS EQU 1 << TRAINERTYPE_DVS_F + TRAINERTYPE_STAT_EXP EQU 1 << TRAINERTYPE_STAT_EXP_F + TRAINERTYPE_VARIABLE EQU 1 << TRAINERTYPE_VARIABLE_F ++TRAINERTYPE_HAPPINESS EQU 1 << TRAINERTYPE_HAPPINESS_F + + PERFECT_DV EQU $11 ; treated as $FF in enemy party data + PERFECT_STAT_EXP EQU $1337 ; treated as $FFFF in enemy party data ++MAX_HAPPINESS EQU $42 ; treated as $FF in enemy party data +``` + +Now let's edit [engine/battle/read_trainer_party.asm](../blob/master/engine/battle/read_trainer_party.asm): + +```diff + ... + .no_stat_exp ++; happpiness? ++ ld a, [wOtherTrainerType] ++ bit TRAINERTYPE_HAPPINESS_F, a ++ jr z, .no_happiness ++ ++ push hl ++ ld a, [wOTPartyCount] ++ dec a ++ ld hl, wOTPartyMon1Happiness ++ call GetPartyLocation ++ ld d, h ++ ld e, l ++ pop hl ++ ++ call GetNextTrainerDataByte ++ cp MAX_HAPPINESS ++ jr nz, .happiness_ok ++ ld a, $ff ++.happiness_ok ++ ld [de], a ++ ++.no_happiness + ; item? + ... + +``` + +Also edit [engine/battle/core.asm](../blob/master/engine/battle/core.asm): + +```diff + LoadEnemyMon: + ... + .Happiness: +; Set happiness ++ ld a, [wBattleMode] ++ dec a ++ ld a, BASE_HAPPINESS ++ jr z, .load_happiness ++ ++ ld a, [wCurPartyMon] ++ ld hl, wOTPartyMon1Happiness ++ call GetPartyLocation ++ ld a, [hl] ++.load_happiness + ld [wEnemyMonHappiness], a + ... +``` + +And then edit [engine/overworld/wildmons.asm](../blob/master/engine/overworld/wildmons.asm): + +```diff +RandomPhoneMon: + ... + .no_stat_exp ++; TRAINERTYPE_HAPPINESS uses 1 more byte ++ bit TRAINERTYPE_HAPPINESS_F, b ++ jr z, .no_happiness ++ inc c ++.no_happiness + ; TRAINERTYPE_ITEM uses 1 more byte + ... +``` + +We're technically done here, but it's also good to edit [data/trainers/parties.asm](../blob/master/data/trainers/parties.asm) to remember in which order to place the attributes for the `TRAINERTYPE_* flags`: + +```diff + ; Trainer data structure: + ; - db "NAME@", TRAINERTYPE_* constants |ed together + ; - 1 to 6 Pokémon: + ; * in all cases: db level, species + ; * with TRAINERTYPE_NICKNAME: db "NICKNAME@" + ; * with TRAINERTYPE_DVS: db atk|def dv, spd|spc dv + ; * with TRAINERTYPE_STAT_EXP: dw hp, atk, def, spd, spc ++; * with TRAINERTYPE_HAPPINESS db happiness + ; * with TRAINERTYPE_ITEM: db item + ; * with TRAINERTYPE_MOVES: db move 1, move 2, move 3, move 4 + ; (TRAINERTYPE_ITEM_MOVES is just TRAINERTYPE_ITEM | TRAINERTYPE_MOVES) + ; - db -1 ; end + ... +``` + +Some important notes: +- We created `MAX_HAPPINESS` since we can't directly use $ff (end-of-party marker). It's highly doubtful you're gonna use $42, but you can change it to $00 and use `and a` instead of `cp MAX_HAPPINESS` to slightly optimize your code. +- If you're gonna give Return to a Pokémon, setting its happiness to 0 will give the move 0 power, dealing no damage. The same goes for Frustration with 255 happiness, so if you want to change this behavior you should edit the move effects for these moves. |