Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. ;Helper routines for statistics calculations. All front-end routines always
  2. ;output their result in HL. The input is always character's base address in IX
  3. ;
  4. ;Page 0 routines
  5. ;Supporting routines output to BC
  6. ;
  7. ;item stats collection rely on stat pool 1 (statgetbuf1)
  8. ;
  9.  
  10. GetMaxHP:
  11. ret ;ehh. Will do it later.
  12.  
  13.  
  14. ;+00 - CharID. b7: Set if in party
  15. ; b6: Set if monster
  16. ; b5-0: Character/monster ID
  17. ;+01 - Status. b0: TEMP : Increased Magick Defense
  18. ; b1: TEMP : Increased Physical Defense
  19. ; b2: TEMP : Increased Agility
  20. ; b3: TEMP : Quickening was used
  21. ; b4: PERM : Poisoned status
  22. ; b5: TEMP : Enchanted status
  23. ; b6: TEMP : Blinded
  24. ; b7: HASH : Dead
  25. ;+02 - ChrInv: Weapon
  26. ;+03 - ChrInv: Shield/Weapon
  27. ;+04 - ChrInv: Helm
  28. ;+05 - ChrInv: Armour
  29. ;+06 - ChrInv: Accessory
  30. ;+07 - ChrInv: Held Item 1
  31. ;+08 - ChrInv: Held Item 2
  32. ;+09 - ChrInv: Held Item 3
  33. ;+10 - CurHP LSB
  34. ;+11 - CurHP MSB (not used for characters)
  35. ;+12 - MaxHP LSB
  36. ;+13 - CurMANA (used as MaxHP MSB for enemies. They have infinite mana)
  37. ;+14 - BaseSTR
  38. ;+15 - BaseSTA
  39. ;+16 - BaseWIS
  40. ;+17 - BaseAGI
  41. ;+18 - Spellbook Spell 1
  42. ;+19 - Spellbook Spell 2
  43. ;+20 - Spellbook Spell 3
  44. ;+21 - Spellbook Spell 4
  45. ;+22 - Spellbook Spell 5
  46. ;+23 - Spellbook Spell 6
  47. ;+24 - Spellbook Spell 7
  48. ;+25 - Spellbook Spell 8
  49. ;+26 - Proficiency Experience : Sword
  50. ;+27 - Proficiency Experience : Axe
  51. ;+28 - Proficiency Experience : Bow
  52. ;+29 - Proficiency Experience : Staff
  53. ;+30 - Proficiency Experience : Shield
  54. ;+31 - Proficiency Experience : Armor
  55. ;+32 - Merits : Monk's Blood (Poisoned 32 times)
  56. ;+33 - Merits : Blind Fighting (Blinded 32 times)
  57. ;+34 - Merits : Headless Rage (Quickened 24 times)
  58. ;+35 - Merits : Alchemic Lore (48 points. Elixir=3,SomaDrop=2,LifeSprig=1)
  59. ;+36 - Merits : Elemental Might (32 points. AlgidLance/FaerieFire=1)
  60. ;+37 - Merits : Prestidigitation (48 points. Any spell = 1)
  61. ;+38 - Merits : Divine Favour (96 points. AngelTear=4, EVENT.RESSURECTION=3)
  62. ;+39 - RESERVED
  63. ;+40 - RESERVED
  64.  
  65. ; ItemDescrip Dmg Def Wis Agi Hit Eva MHp Rdx M1 M2 M3 M4 ChrGain1 ChrGain2 ChrGain3
  66. ;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
  67. ItemStatCollect: ;IN: C=offset. OUT: statgetbuf1+0 to +4 filled
  68. push hl
  69. push de
  70. push ix
  71. pop hl
  72. inc L
  73. inc L ;get to the first item that the person holds.
  74. ld de,statgetbuf1
  75. ld b,5
  76. ItemStatCollectLoop:
  77. push hl
  78. ld a,(hl)
  79. inc a
  80. jr z,ItemStatCollectNoItem
  81. dec a
  82. cpcall(BufferItemStats)
  83. ld hl,itemstatcache
  84. ld a,c
  85. call AddAtoHL0
  86. ld a,(hl)
  87. ItemStatCollectNoItem:
  88. ld (de),a
  89. inc de
  90. pop hl
  91. inc L
  92. djnz ItemStatCollectLoop
  93. xor a
  94. bit 6,(ix+0) ;checking to see if it's an enemy being scanned
  95. jr nz,ItemStatsCollectNoProficiency
  96. ld hl,ItemStatsCollectionToProficiencyGainTypeTable
  97. ld a,c
  98. call AddAtoHL0
  99. ld a,(hl)
  100. call CollectProficiencyGains
  101. pop de
  102. pop hl
  103. ret
  104. ItemStatsCollectNoProficiency:
  105. ld a,23-7 ;So we are working on enemy side? Then add in enemy's own stats
  106. add a,c ;offset. Enemy stats are treated as though they were equipment
  107. call AddAtoHL0
  108. ld a,(hl)
  109. ld (statgetbuf1+5),a ;last byte being used to add in proficiency gains
  110. ld hl,statgetbuf2
  111. ld de,statgetbuf2+1
  112. ld (hl),$00
  113. ld bc,5
  114. ldir ;clear out the proficiency thinger.
  115. pop de
  116. pop hl
  117. ret
  118.  
  119. ItemStatsCollectionToProficiencyGainTypeTable:
  120. ;indexed by type. Data in the table is gain type that corresponds to stat
  121. ;$0F = none.
  122. ;MSB code: 0=Hit+% 1=Dmg+ 2=Crit+ 3=+Hits 3=Wis+ 4=mgD+ 5=Abs+% 6=Eva+% 7=Def+
  123. ;+0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  124. ;Ids Dmg Def Wis Agi Hit Eva MHp Rdx M1 M2 M3 M4 CG1 CG2 CG3
  125. .db $0F,$01,$07,$03,$0F,$00,$06,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F
  126.  
  127.  
  128.  
  129.  
  130. CollectProficiencyGains: ;in: C=gaintype
  131. ld de,statgetbuf2
  132. push ix
  133. pop hl
  134. inc L
  135. inc L
  136. ld b,5
  137. CollectProficiencyGainsLoop:
  138. xor a
  139. ld (de),a ;clear out
  140. ld a,(hl) ;get item
  141. inc L
  142. cp $FE ;if no carry, then skip
  143. jr nc,CollectProficiencyGainsSkip
  144. push hl
  145. push bc
  146. ld b,c ;moving C to B for this cycle
  147. push bc ;so that we can pop the gaintype from A
  148. call GetItemType ;in: A=itemcode ;out: B=itemtype
  149. call GetProficiencyLevelFromItemCode ;OUT: A=EXP to nxt lvl, B=cur lvl
  150. ld a,b
  151. or a
  152. jr z,CollectProficiencyGainsPartialSkip
  153. pop af ;A=gaintype
  154. push af
  155. add a,a ;x2
  156. add a,a ;x4
  157. add a,a ;x8
  158. ld hl,ProfModTable
  159. call AddAtoHL0
  160. pop af
  161. ld c,a ;getting gaintype back to C. B=level for looping through all lvs.
  162. _: ld a,(hl) ;getting data from gain table
  163. rlca
  164. rlca
  165. rlca
  166. rlca
  167. and $0F
  168. cp c
  169. jr nz,_ ;did not match gain type. Just keep on looping.
  170. ld a,(hl) ;else add together that particular gain with what was at (DE)
  171. and $0F
  172. ex de,hl
  173. add a,(hl)
  174. ld (hl),a
  175. ex de,hl
  176. _: inc hl
  177. djnz --_
  178. CollectProficiencyGainsPartialSkip:
  179. pop bc
  180. pop hl
  181. CollectProficiencyGainsSkip:
  182. djnz CollectProficiencyGainsLoop
  183. ret
  184.  
  185.  
  186.  
  187. GetProficiencyNullifier:
  188. ld a,$FF
  189. ld L,a
  190. ld h,a
  191. ld b,a
  192. inc b ;level zero
  193. ret
  194. GetProficiencyLevelFromItemCode:
  195. ;IN: IX=pointer to start of chardat. B=itemtype (from GetItemType, in:A=icode)
  196. ;OUT: A=EXP to next level, B=current level
  197. ld hl,GetProficiencyLevelOffsetTable
  198. ld a,b
  199. call AddAtoHL0
  200. ld a,(hl)
  201. GetProficiencyLevel: ;Alt IN:B=(0=Swrd,1=Axe,2=Bow,3=Staf,4=Shld,5=Arm,6=NULL)
  202. cp 6
  203. jr z,GetProficiencyNullifier
  204. ld b,a
  205. push ix
  206. pop hl
  207. add a,26
  208. call AddAtoHL0
  209. ld a,b
  210. add a,a
  211. add a,a
  212. add a,a ;x8
  213. add a,b ;x9
  214. ld c,(hl) ;current EXP level of that item
  215. ld hl,ProficiencyExperienceTable
  216. call AddAtoHL0
  217. ld b,-1
  218. GetProficiencyLoop:
  219. ld a,(hl)
  220. inc hl
  221. inc b
  222. cp c ;Need-Current. If carry, then exeeded level. Keep going.
  223. jr c,GetProficiencyLoop
  224. ld a,(hl)
  225. sub c ;to get exp needed for the next level
  226. ret
  227.  
  228. GetProficiencyLevelOffsetTable:
  229. .db 0,0,1,2,3,4,4,5 ;L1Swd,L2Swd,Axe,Bow,St,L1Shd,L2Shd,L1Helm
  230. .db 5,5,5,6,6,6,6,6 ;L2Hlm,L1Arm,L2Arm,Acc,FAlc,Alc,BAlc,KItm
  231.  
  232. ProficiencyExperienceTable:
  233. ; lv0 lv1 lv2 lv3 lv4 lv5 lv6 lv7 lv8
  234. .db 000,001,020,040,060,090,130,185,255 ;Sword
  235. .db 000,001,020,040,060,090,130,185,255 ;Axe
  236. .db 000,001,020,040,060,090,130,185,255 ;Bow
  237. .db 000,001,020,040,060,090,130,185,255 ;Staff
  238. .db 000,001,020,040,060,090,130,185,255 ;Shield
  239. .db 000,001,020,040,060,090,130,185,255 ;Armour
  240.  
  241.  
  242. ;MSB code: 0=Hit+% 1=Dmg+ 2=Crit+ 3=+Hits 3=Wis+ 4=mgD+ 5=Abs+% 6=Eva+% 7=Def+
  243. ;LSB code: Gain for that level
  244. ProfModTable:
  245. ; Lv1 Lv2 Lv3 Lv4 Lv5 Lv6 Lv7 Lv8
  246. .db $F0,$F0,$02,$31,$02,$14,$31,$04 ;Sword
  247. .db $F0,$12,$22,$12,$08,$31,$22,$14 ;Axe
  248. .db $F0,$22,$31,$04,$22,$31,$04,$24 ;Bow
  249. .db $F0,$42,$42,$04,$44,$52,$31,$48 ;Staff
  250. .db $F0,$F0,$62,$72,$82,$62,$52,$72 ;Shield
  251. .db $F0,$82,$52,$F0,$82,$64,$52,$82 ;Armour
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement