diff options
-rw-r--r-- | Modify-Existing-Gender-Formula.md | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/Modify-Existing-Gender-Formula.md b/Modify-Existing-Gender-Formula.md new file mode 100644 index 0000000..b54538a --- /dev/null +++ b/Modify-Existing-Gender-Formula.md @@ -0,0 +1,155 @@ +Starting in Generation 3, a Pokémon's gender is independent of its stats. That's not the case, however, in Generation 2. + + + +In Generation 2, the gender of a Pokémon is dictated by its Attack DVs (which become IVs in later generations). With this formula, a female Pokémon has worse stats than male Pokémon. For 1:3 and Female Gender ratios, female Pokémon have decent DVs, and the only way to get a perfect DV female Pokémon is if the gender ratio is Female. + +This tutorial teaches how to modify the existing gender ratio formula to make females have decent stats as their male counterparts. We will use the following formula instead of relying solely on the Attack DV (Note that Spc = Special): +`~(Atk DV & 1) << 1 + (Def DV & 1) << 2 + ~(Spc DV & 1) << 3` + +Here's a chart showing what are the stats of female Pokémon in each of the gender ratios: +``` +M:F +7:1 : Female = Odd Atk, Even Def, and Odd Spc +3:1 : Female = Even Def and Odd Spc +1:1 : Female = Odd Spc +1:3 : Female = Even Def or Odd Spc +``` +This means that perfect DV Pokémon are always male for 7M:1F and 3M:1F gender ratios and female for 1M:1F and 1M:3F gender ratios. + +With that out of the way, here's how to edit the gender formula. Edit `GetGender` in [engine/pokemon/mon_stats.asm](https://github.com/pret/pokecrystal/blob/master/engine/pokemon/mon_stats.asm): + +```diff +GetGender: +; Return the gender of a given monster (wCurPartyMon/wCurOTMon/wCurWildMon). +; When calling this function, a should be set to an appropriate wMonType value. + +; return values: +; a = 1: f = nc|nz; male +; a = 0: f = nc|z; female +; f = c: genderless + +; This is determined by comparing the Attack and Speed DVs +; with the species' gender ratio. + +; Figure out what type of monster struct we're looking at. + +; 0: PartyMon + ld hl, wPartyMon1DVs + ld bc, PARTYMON_STRUCT_LENGTH + ld a, [wMonType] + and a + jr z, .PartyMon + +; 1: OTPartyMon + ld hl, wOTPartyMon1DVs + dec a + jr z, .PartyMon + +; 2: sBoxMon + ld hl, sBoxMon1DVs + ld bc, BOXMON_STRUCT_LENGTH + dec a + jr z, .sBoxMon + +; 3: Unknown + ld hl, wTempMonDVs + dec a + jr z, .DVs + +; else: WildMon + ld hl, wEnemyMonDVs + jr .DVs + +; Get our place in the party/box. + +.PartyMon: +.sBoxMon + ld a, [wCurPartyMon] + call AddNTimes + +.DVs: +; sBoxMon data is read directly from SRAM. + ld a, [wMonType] + cp BOXMON + ld a, BANK(sBox) + call z, OpenSRAM + +; Attack DV + ld a, [hli] +- and $f0 +- ld b, a +-; Speed DV +- ld a, [hl] +- and $f0 +- swap a ++ cpl ++ and $10 ++ swap a ++ add a ; Atk DV << 1 ++ ld b, a ; Store it in register b ++; Defense DV ++ ld a, [hli] ++ and $1 ++ add a ; Def DV << 1 ++ add a ; Def DV << 2 ++ or b ; Add (Atk DV << 1) + (Def DV << 2) ++ ld b, a ; Store result in b. ++; Special DV ++ ld a, [hl] ++ cpl ++ and $1 ++ add a ; Spec DV << 1 ++ add a ; Spec DV << 2 ++ add a ; Spec DV << 3 ++ or b ; Add (Spec DV << 3) ++ swap a ++ ld b, a ; Again, stored in b. + +-; Put our DVs together. +- or b +- ld b, a + +; Close SRAM if we were dealing with a sBoxMon. + ld a, [wMonType] + cp BOXMON + call z, CloseSRAM + +; We need the gender ratio to do anything with this. + push bc + ld a, [wCurPartySpecies] + dec a + ld hl, BaseData + BASE_GENDER + ld bc, BASE_DATA_SIZE + call AddNTimes + pop bc + + ld a, BANK(BaseData) + call GetFarByte +``` + +And that's it! Here are some screenshots of the Pokémon. DVs are displayed for reference and for verifying that they have the correct gender. + +Quilava with 7:1 Gender Ratio + + + +Snubbull with 1:3 Gender Ratio + + + +Hoppip with 1:1 Gender Ratio + + + +Venonat with 1:1 Gender Ratio + + + +Psyduck with 1:1 Gender Ratio + + + +Growlithe with 3:1 Gender Ratio + +
\ No newline at end of file |