Skip to content

Modify existing gender formula

Idain edited this page Jun 16, 2021 · 5 revisions

Starting in Generation 3, a Pokémon's gender is independent of its stats. However, that's not the case in Generation 2.

Gender Formula

In this generation a Pokémon's gender is dictated by its Attack DV (which became IVs in later generations). With this formula, a female Pokémon has worse stats than a male Pokémon. For 1:3 and Female Gender ratios, female Pokémon have a decent Attack DV, 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 the DVs needed to for a Pokémon to be female with the new formula:

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.

Contents

  1. Replace the existing formula with a new one

1. Replace the existing formula with a new one

Edit GetGender in engine/pokemon/mon_stats.asm:

 GetGender:
 ...

 .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
+	ld a, [hl]
+	cpl
+	and $10
+	swap a
+	add a     ; ~(Atk DV & 1) << 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      ; ~(Atk DV & 1) << 1 | (Def DV & 1) << 2
+	ld b, a   ; Store result in b.
+; Special DV
+	ld a, [hl]
+	cpl
+	and $1
+	add a     ; ~(Spc DV & 1) << 1
+	add a     ; ~(Spc DV & 1) << 2
+	add a     ; ~(Spc DV & 1) << 3
+	or b      ; ~(Atk DV & 1) << 1 | (Def DV & 1) << 2 | ~(Spc DV & 1) << 3
+	swap a
+	ld b, a   ; Again, stored in b.

-; Put our DVs together.
-	or b
-	ld b, a
 ...

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

Quilava

Snubbull with 1:3 Gender Ratio

Snubbull

Hoppip with 1:1 Gender Ratio

Hoppip

Venonat with 1:1 Gender Ratio

Venonat

Psyduck with 1:1 Gender Ratio

Psyduck

Growlithe with 3:1 Gender Ratio

Growlithe

Credits to Xavion for creating the gender formula and Idain and PikalaxALT for creating and optimizing the code.

Clone this wiki locally