From c92626570de72ad7021234b3fdf4809844dd2b1d Mon Sep 17 00:00:00 2001 From: Engezerstorung <154867622+Engezerstorung@users.noreply.github.com> Date: Sun, 6 Oct 2024 18:38:16 +0200 Subject: [PATCH] Add function to force a mon gender 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. --- color/colorplus/mon_gender.asm | 52 ++++++++++++++++++++++++++++++++-- ram/wram.asm | 6 +++- scripts/PokemonTower6F.asm | 4 +++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/color/colorplus/mon_gender.asm b/color/colorplus/mon_gender.asm index cbe30f54..91803b10 100644 --- a/color/colorplus/mon_gender.asm +++ b/color/colorplus/mon_gender.asm @@ -1,4 +1,3 @@ -IF GEN_2_GRAPHICS ; Used to define gender ratios DEF MALE_ONLY EQU $00 DEF MALE_88_PERCENT EQU $1F @@ -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 @@ -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 @@ -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 diff --git a/ram/wram.asm b/ram/wram.asm index 16c2bd40..ef617a1a 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -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 diff --git a/scripts/PokemonTower6F.asm b/scripts/PokemonTower6F.asm index cf246c56..7139582c 100644 --- a/scripts/PokemonTower6F.asm +++ b/scripts/PokemonTower6F.asm @@ -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: