summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2013-03-01 12:22:09 -0800
committerBryan Bishop <kanzure@gmail.com>2013-03-01 12:22:09 -0800
commitcb1d7f812be0c392351a8ee7f1dd8b439d8d62bc (patch)
tree0d89672fd870289baf5fc2d51ebeeb3bc21f8d14
parentbcfac567ed5bb9e5254a41fc7ef20d325d5763b5 (diff)
parent767cc1376b076db56a6773d49a129d6acc6a5378 (diff)
Merge pull request #118 from yenatch/master
gender check & square root
-rw-r--r--main.asm156
1 files changed, 154 insertions, 2 deletions
diff --git a/main.asm b/main.asm
index af469920d..36047a514 100644
--- a/main.asm
+++ b/main.asm
@@ -4839,7 +4839,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]
@@ -7137,8 +7169,128 @@ 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"