Skip to content

Commit

Permalink
Add function to force a mon gender
Browse files Browse the repository at this point in the history
Add a function to force a mon gender, like for Cubone Mother in the Pokemon Tower.
Only bi-gendered mons can have their gender forced.
Roll a random attack DV that satisfy the mon gender ratio condition.
  • Loading branch information
Engezerstorung committed Oct 6, 2024
1 parent 421d948 commit c926265
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
52 changes: 50 additions & 2 deletions color/colorplus/mon_gender.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
IF GEN_2_GRAPHICS
; Used to define gender ratios
DEF MALE_ONLY EQU $00
DEF MALE_88_PERCENT EQU $1F
Expand All @@ -7,7 +6,6 @@ IF GEN_2_GRAPHICS
DEF FEMALE_75_PERCENT EQU $BF
DEF FEMALE_ONLY EQU $FE
DEF NO_GENDER EQU $FF
ENDC

; Determine a Pokémon's gender based on its DVs
; This uses the same formula as Gen 2, so gender should match if you trade them forward via Time Capsule
Expand All @@ -24,6 +22,8 @@ GetMonGender::
ld hl, MonGenderRatios
add hl, bc ; hl now points to the species gender ratio

call CheckForcedGender

; Attack DV
ld a, [de]
and $f0
Expand Down Expand Up @@ -66,6 +66,54 @@ GetMonGender::
ld [wPokedexNum], a
ret

CheckForcedGender:
ld a, [hl]
and a ; cp MALE_ONLY
ret z
cp FEMALE_ONLY
ret nc

push hl
ld hl, wGenderFlags
bit 0, [hl] ; check if force male
res 0, [hl]
jr nz, .forceMale
bit 1, [hl] ; check if force female
res 1, [hl]
jr z, .done

ld hl, .checkFemaleDV
jr .forceCommon
.forceMale
ld hl, .checkMaleDV
.forceCommon
and $0F
inc a
ld b, a

.rerollAttackDV
call Random
and $0F
cp b
jp hl

.checkMaleDV
jr c, .rerollAttackDV
jr .gotAttackDV
.checkFemaleDV
jr nc, .rerollAttackDV

.gotAttackDV
ld b, a
swap b
ld a, [de]
and $0F
or b
ld [de], a
.done
pop hl
ret

MonGenderRatios:
db MALE_88_PERCENT ; Bulbasaur
db MALE_88_PERCENT ; Ivysaur
Expand Down
6 changes: 5 additions & 1 deletion ram/wram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,11 @@ wPlayerCoins:: dw ; BCD
wMissableObjectFlags:: flag_array $100
wMissableObjectFlagsEnd::

ds 2
ds 1

;; bit 0 - force male gender
;; bit 1 - force female gender
wGenderFlags:: db

wAnimationStatus:: db

Expand Down
4 changes: 4 additions & 0 deletions scripts/PokemonTower6F.asm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ PokemonTower6FDefaultScript:
ld a, SCRIPT_POKEMONTOWER6F_MAROWAK_BATTLE
ld [wPokemonTower6FCurScript], a
ld [wCurMapScript], a

ld hl, wGenderFlags
set 1, [hl] ; set flag to force female gender for Cubone mother

ret

PokemonTower6FMarowakCoords:
Expand Down

0 comments on commit c926265

Please sign in to comment.