From 37355aef99a0172fe3cf260b2368af8fac8cc60a Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 28 Feb 2013 15:03:52 -0500 Subject: [PATCH 1/2] Gender check --- main.asm | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) diff --git a/main.asm b/main.asm index cec9fe52e..a90f66e81 100644 --- a/main.asm +++ b/main.asm @@ -7103,9 +7103,129 @@ Dragon: Dark: db "DARK@" -INCBIN "baserom.gbc",$50A28, $51424 - $50A28 +INCBIN "baserom.gbc", $50a28, $50bdd - $50a28 +GetGender: ; 50bdd +; Return the gender of a given monster in a. + +; 1: male +; 0: female +; 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, PartyMon1DVs + ld bc, PartyMon2 - PartyMon1 + ld a, [MonType] + and a + jr z, .PartyMon + +; 1: OTPartyMon + ld hl, OTPartyMon1DVs + dec a + jr z, .PartyMon + +; 2: BoxMon + ld hl, $ad26 + $15 ; BoxMon1DVs + ld bc, $20 ; BoxMon2 - BoxMon1 + dec a + jr z, .BoxMon + +; 3: Unknown + ld hl, $d123 ; DVBuffer + dec a + jr z, .DVs + +; else: WildMon + ld hl, EnemyMonDVs + jr .DVs + + +; Get our place in the party/box. + +.PartyMon +.BoxMon + ld a, [CurPartyMon] + call AddNTimes + + +.DVs + +; BoxMon data is read directly from SRAM. + ld a, [MonType] + cp 2 + ld a, 1 + call z, GetSRAMBank + +; Attack DV + ld a, [hli] + and $f0 + ld b, a +; Speed DV + ld a, [hl] + and $f0 + swap a + +; Put our DVs together. + or b + ld b, a + +; Close SRAM if we were dealing with a BoxMon. + ld a, [MonType] ; MonType + cp 2 ; BOXMON + call z, CloseSRAM + + +; We need the gender ratio to do anything with this. + push bc + ld a, [CurPartySpecies] + dec a + ld hl, BaseStats + 13 ; BASE_GENDER + ld bc, BaseStats1 - BaseStats + call AddNTimes + pop bc + + ld a, BANK(BaseStats) + call GetFarByte + + +; The higher the ratio, the more likely the monster is to be female. + + cp $ff + jr z, .Genderless + + and a + jr z, .Male + + cp $fe + jr z, .Female + +; Values below the ratio are male, and vice versa. + cp b + jr c, .Male + +.Female + xor a + ret + +.Male + ld a, 1 + and a + ret + +.Genderless + scf + ret +; 50c50 + +INCBIN "baserom.gbc", $50c50, $51424 - $50c50 + BaseStats: INCLUDE "stats/base_stats.asm" From 767cc1376b076db56a6773d49a129d6acc6a5378 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 28 Feb 2013 17:28:35 -0500 Subject: [PATCH 2/2] GetSquareRoot --- main.asm | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/main.asm b/main.asm index a90f66e81..a42a499a6 100644 --- a/main.asm +++ b/main.asm @@ -4805,7 +4805,39 @@ OpenPartyStats: ; 12e00 ret ; 0x12e1b -INCBIN "baserom.gbc",$12e1b,$13d96 - $12e1b +INCBIN "baserom.gbc",$12e1b,$13b87 - $12e1b + +GetSquareRoot: ; 13b87 +; Return the square root of de in b. + +; Rather than calculating the result, we take the index of the +; first value in a table of squares that isn't lower than de. + + ld hl, Squares + ld b, 0 +.loop +; Make sure we don't go past the end of the table. + inc b + ld a, b + cp $ff + ret z + +; Iterate over the table until b**2 >= de. + ld a, [hli] + sub e + ld a, [hli] + sbc d + + jr c, .loop + ret + +Squares: ; 13b98 +root set 1 + rept $ff + dw root*root +root set root+1 + endr +; 13d96 SECTION "bank5",DATA,BANK[$5]