Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Helper routines for statistics calculations. All front-end routines always
- ;output their result in HL. The input is always character's base address in IX
- ;
- ;Page 0 routines
- ;Supporting routines output to BC
- ;
- ;item stats collection rely on stat pool 1 (statgetbuf1)
- ;
- GetMaxHP:
- ret ;ehh. Will do it later.
- ;+00 - CharID. b7: Set if in party
- ; b6: Set if monster
- ; b5-0: Character/monster ID
- ;+01 - Status. b0: TEMP : Increased Magick Defense
- ; b1: TEMP : Increased Physical Defense
- ; b2: TEMP : Increased Agility
- ; b3: TEMP : Quickening was used
- ; b4: PERM : Poisoned status
- ; b5: TEMP : Enchanted status
- ; b6: TEMP : Blinded
- ; b7: HASH : Dead
- ;+02 - ChrInv: Weapon
- ;+03 - ChrInv: Shield/Weapon
- ;+04 - ChrInv: Helm
- ;+05 - ChrInv: Armour
- ;+06 - ChrInv: Accessory
- ;+07 - ChrInv: Held Item 1
- ;+08 - ChrInv: Held Item 2
- ;+09 - ChrInv: Held Item 3
- ;+10 - CurHP LSB
- ;+11 - CurHP MSB (not used for characters)
- ;+12 - MaxHP LSB
- ;+13 - CurMANA (used as MaxHP MSB for enemies. They have infinite mana)
- ;+14 - BaseSTR
- ;+15 - BaseSTA
- ;+16 - BaseWIS
- ;+17 - BaseAGI
- ;+18 - Spellbook Spell 1
- ;+19 - Spellbook Spell 2
- ;+20 - Spellbook Spell 3
- ;+21 - Spellbook Spell 4
- ;+22 - Spellbook Spell 5
- ;+23 - Spellbook Spell 6
- ;+24 - Spellbook Spell 7
- ;+25 - Spellbook Spell 8
- ;+26 - Proficiency Experience : Sword
- ;+27 - Proficiency Experience : Axe
- ;+28 - Proficiency Experience : Bow
- ;+29 - Proficiency Experience : Staff
- ;+30 - Proficiency Experience : Shield
- ;+31 - Proficiency Experience : Armor
- ;+32 - Merits : Monk's Blood (Poisoned 32 times)
- ;+33 - Merits : Blind Fighting (Blinded 32 times)
- ;+34 - Merits : Headless Rage (Quickened 24 times)
- ;+35 - Merits : Alchemic Lore (48 points. Elixir=3,SomaDrop=2,LifeSprig=1)
- ;+36 - Merits : Elemental Might (32 points. AlgidLance/FaerieFire=1)
- ;+37 - Merits : Prestidigitation (48 points. Any spell = 1)
- ;+38 - Merits : Divine Favour (96 points. AngelTear=4, EVENT.RESSURECTION=3)
- ;+39 - RESERVED
- ;+40 - RESERVED
- ; ItemDescrip Dmg Def Wis Agi Hit Eva MHp Rdx M1 M2 M3 M4 ChrGain1 ChrGain2 ChrGain3
- ;db IP(1,1,1,00),016,000,000,000,070,000,000,000,33,-1,-1,-1,CG(2,01),CG(0,00),CG(3,-1) ;00 Ardent
- ItemStatCollect: ;IN: C=offset. OUT: statgetbuf1+0 to +4 filled
- push hl
- push de
- push ix
- pop hl
- inc L
- inc L ;get to the first item that the person holds.
- ld de,statgetbuf1
- ld b,5
- ItemStatCollectLoop:
- push hl
- ld a,(hl)
- inc a
- jr z,ItemStatCollectNoItem
- dec a
- cpcall(BufferItemStats)
- ld hl,itemstatcache
- ld a,c
- call AddAtoHL0
- ld a,(hl)
- ItemStatCollectNoItem:
- ld (de),a
- inc de
- pop hl
- inc L
- djnz ItemStatCollectLoop
- xor a
- bit 6,(ix+0) ;checking to see if it's an enemy being scanned
- jr nz,ItemStatsCollectNoProficiency
- ld hl,ItemStatsCollectionToProficiencyGainTypeTable
- ld a,c
- call AddAtoHL0
- ld a,(hl)
- call CollectProficiencyGains
- pop de
- pop hl
- ret
- ItemStatsCollectNoProficiency:
- ld a,23-7 ;So we are working on enemy side? Then add in enemy's own stats
- add a,c ;offset. Enemy stats are treated as though they were equipment
- call AddAtoHL0
- ld a,(hl)
- ld (statgetbuf1+5),a ;last byte being used to add in proficiency gains
- ld hl,statgetbuf2
- ld de,statgetbuf2+1
- ld (hl),$00
- ld bc,5
- ldir ;clear out the proficiency thinger.
- pop de
- pop hl
- ret
- ItemStatsCollectionToProficiencyGainTypeTable:
- ;indexed by type. Data in the table is gain type that corresponds to stat
- ;$0F = none.
- ;MSB code: 0=Hit+% 1=Dmg+ 2=Crit+ 3=+Hits 3=Wis+ 4=mgD+ 5=Abs+% 6=Eva+% 7=Def+
- ;+0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- ;Ids Dmg Def Wis Agi Hit Eva MHp Rdx M1 M2 M3 M4 CG1 CG2 CG3
- .db $0F,$01,$07,$03,$0F,$00,$06,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F
- CollectProficiencyGains: ;in: C=gaintype
- ld de,statgetbuf2
- push ix
- pop hl
- inc L
- inc L
- ld b,5
- CollectProficiencyGainsLoop:
- xor a
- ld (de),a ;clear out
- ld a,(hl) ;get item
- inc L
- cp $FE ;if no carry, then skip
- jr nc,CollectProficiencyGainsSkip
- push hl
- push bc
- ld b,c ;moving C to B for this cycle
- push bc ;so that we can pop the gaintype from A
- call GetItemType ;in: A=itemcode ;out: B=itemtype
- call GetProficiencyLevelFromItemCode ;OUT: A=EXP to nxt lvl, B=cur lvl
- ld a,b
- or a
- jr z,CollectProficiencyGainsPartialSkip
- pop af ;A=gaintype
- push af
- add a,a ;x2
- add a,a ;x4
- add a,a ;x8
- ld hl,ProfModTable
- call AddAtoHL0
- pop af
- ld c,a ;getting gaintype back to C. B=level for looping through all lvs.
- _: ld a,(hl) ;getting data from gain table
- rlca
- rlca
- rlca
- rlca
- and $0F
- cp c
- jr nz,_ ;did not match gain type. Just keep on looping.
- ld a,(hl) ;else add together that particular gain with what was at (DE)
- and $0F
- ex de,hl
- add a,(hl)
- ld (hl),a
- ex de,hl
- _: inc hl
- djnz --_
- CollectProficiencyGainsPartialSkip:
- pop bc
- pop hl
- CollectProficiencyGainsSkip:
- djnz CollectProficiencyGainsLoop
- ret
- GetProficiencyNullifier:
- ld a,$FF
- ld L,a
- ld h,a
- ld b,a
- inc b ;level zero
- ret
- GetProficiencyLevelFromItemCode:
- ;IN: IX=pointer to start of chardat. B=itemtype (from GetItemType, in:A=icode)
- ;OUT: A=EXP to next level, B=current level
- ld hl,GetProficiencyLevelOffsetTable
- ld a,b
- call AddAtoHL0
- ld a,(hl)
- GetProficiencyLevel: ;Alt IN:B=(0=Swrd,1=Axe,2=Bow,3=Staf,4=Shld,5=Arm,6=NULL)
- cp 6
- jr z,GetProficiencyNullifier
- ld b,a
- push ix
- pop hl
- add a,26
- call AddAtoHL0
- ld a,b
- add a,a
- add a,a
- add a,a ;x8
- add a,b ;x9
- ld c,(hl) ;current EXP level of that item
- ld hl,ProficiencyExperienceTable
- call AddAtoHL0
- ld b,-1
- GetProficiencyLoop:
- ld a,(hl)
- inc hl
- inc b
- cp c ;Need-Current. If carry, then exeeded level. Keep going.
- jr c,GetProficiencyLoop
- ld a,(hl)
- sub c ;to get exp needed for the next level
- ret
- GetProficiencyLevelOffsetTable:
- .db 0,0,1,2,3,4,4,5 ;L1Swd,L2Swd,Axe,Bow,St,L1Shd,L2Shd,L1Helm
- .db 5,5,5,6,6,6,6,6 ;L2Hlm,L1Arm,L2Arm,Acc,FAlc,Alc,BAlc,KItm
- ProficiencyExperienceTable:
- ; lv0 lv1 lv2 lv3 lv4 lv5 lv6 lv7 lv8
- .db 000,001,020,040,060,090,130,185,255 ;Sword
- .db 000,001,020,040,060,090,130,185,255 ;Axe
- .db 000,001,020,040,060,090,130,185,255 ;Bow
- .db 000,001,020,040,060,090,130,185,255 ;Staff
- .db 000,001,020,040,060,090,130,185,255 ;Shield
- .db 000,001,020,040,060,090,130,185,255 ;Armour
- ;MSB code: 0=Hit+% 1=Dmg+ 2=Crit+ 3=+Hits 3=Wis+ 4=mgD+ 5=Abs+% 6=Eva+% 7=Def+
- ;LSB code: Gain for that level
- ProfModTable:
- ; Lv1 Lv2 Lv3 Lv4 Lv5 Lv6 Lv7 Lv8
- .db $F0,$F0,$02,$31,$02,$14,$31,$04 ;Sword
- .db $F0,$12,$22,$12,$08,$31,$22,$14 ;Axe
- .db $F0,$22,$31,$04,$22,$31,$04,$24 ;Bow
- .db $F0,$42,$42,$04,$44,$52,$31,$48 ;Staff
- .db $F0,$F0,$62,$72,$82,$62,$52,$72 ;Shield
- .db $F0,$82,$52,$F0,$82,$64,$52,$82 ;Armour
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement