Smart Cover (True Knight improvement) - seibaby - 12-04-2016
This is a hack to make True Knight users a little smarter. I made this for Brave New World, and now @"Gi Nattak" requested to use it in RotDS, so I'm making it publicly available here.
With this hack, characters or monsters using True Knight will only cover incoming attacks from the opposing team, never from within their own ranks. This should help people who like using the Heal Rod, or who like smacking their teammates around to rouse them from Sleep or Muddle.
Furthermore, there are a bunch of statuses that, if set on the target, prevent True Knight from kicking in; Clear is one such status. I've added a few more: Image, Death, Zombie, and Petrify. The last three all remove Near Fatal status, so would prevent True Knight anyway. If you remove or replace the Near Fatal requirement via hacks, then they are necessary to prevent your bodyguard from Covering Zombied/Petrified team members.
There are also a bunch of statuses that, if set on the bodyguard, also disable True Knight: Clear, Death, Zombie, Petrify, Sleep, and Muddle. I've added Berserk, Image and Dark here, plus Magitek.
It's pretty simple to edit the status restrictions. I've added a bit reference in the code comments to help you out.
Below are two variants of the code: the original, which applies the new True Knight functionality to both Characters and Monsters, and the one used in BNW, where space restrictions necessitated stripping out Smart Cover for Monsters.
If you don't have monsters using True Knight in your hack, you can use the BNW patch. They're functionally the same.
Original Smart Cover:
Code: ;Prevent Cover if Attacker and Target are on the same team
;(and some other stuff regarding statuses that disable Cover)
;patch with xkas 0.06
hirom ;don't change this
;header ;uncomment for headered ROM
!freespace = $C2A65A ;change this to an where you have 25 bytes of free space
;(in C2 bank)
org $C212D6
;Prevent Cover if bodyguard has any of these statuses:
;Default = #$A0D2 (Death, Petrify, Clear, Zombie, Sleep, Muddled)
;Low byte: High byte:
;$01 = Dark $10 = Clear $01 = Condemned $10 = Berserk
;$02 = Zombie $20 = Imp $02 = Near Fatal $20 = Muddle
;$04 = Poison $40 = Petrify $04 = Image $40 = Seizure
;$08 = Magitek $80 = Death $08 = Mute $80 = Sleep
BIT #$B4DB ;Death, Petrify, Clear, Zombie, Sleep, Muddled, Dark, Magitek,
;Image, Berserk
org $C21268
;Prevent Cover if Target has any of these statuses:
;Default = #$0010 (Clear)
;Low byte: High byte:
;$01 = Dark $10 = Clear $01 = Condemned $10 = Berserk
;$02 = Zombie $20 = Imp $02 = Near Fatal $20 = Muddle
;$04 = Poison $40 = Petrify $04 = Image $40 = Seizure
;$08 = Magitek $80 = Death $08 = Mute $80 = Sleep
BIT #$04D2 ;Death, Clear, Zombie, Petrify, Image
org $C21260
;Prevent Cover if Attacker and Target are on the same team
JMP friendly_fire
;Activate Cover if Attacker and Target are on opposing teams
cover:
org !freespace
;(Y = Target, X = Attacker)
friendly_fire:
CPX #$08 ;Check which team Attacker is on
BCS .mon_att ;Branch if Attacker is a Monster
CPY #$08 ;Attacker is a Character; check Target:
BCS .cover ;Branch if Target is a Monster
CPX #$08 ;Target is a Character; check Attacker again:
BCC .nocover ;Branch if Attacker is a Character
.mon_att
CPY #$08 ;Attacker is a Monster; check Target
BCC .cover ;Branch if Target is a Character
.nocover
JMP $12A5 ;Attacker and Target are on the same team;
;exit function without activating Cover
.cover
LDA $3EE4,Y ;(Moved from C2/1260)
JMP cover ;Attacker and Target are on opposing teams;
;return and continue to activate Cover
BNW Smart Cover:
Code: ;Prevent Cover if Attacker and Target are on the same team
;(and some other stuff regarding statuses that disable Cover)
;patch with xkas 0.06
hirom
;header
!freespace = $C26580 ;Requires 17 bytes of free space in C2
org $C212D6
;Prevent Cover if bodyguard has any of these statuses:
;Default = #$A0D2 (Death, Petrify, Clear, Zombie, Sleep, Muddled)
;Low byte: High byte:
;$01 = Dark $10 = Clear $01 = Condemned $10 = Berserk
;$02 = Zombie $20 = Imp $02 = Near Fatal $20 = Muddle
;$04 = Poison $40 = Petrify $04 = Image $40 = Seizure
;$08 = Magitek $80 = Death $08 = Mute $80 = Sleep
BIT #$B4DB ;Death, Petrify, Clear, Zombie, Sleep, Muddled, Dark, Magitek,
;Image, Berserk
org $C21268
;Prevent Cover if Target has any of these statuses:
;Default = #$0010 (Clear)
;Low byte: High byte:
;$01 = Dark $10 = Clear $01 = Condemned $10 = Berserk
;$02 = Zombie $20 = Imp $02 = Near Fatal $20 = Muddle
;$04 = Poison $40 = Petrify $04 = Image $40 = Seizure
;$08 = Magitek $80 = Death $08 = Mute $80 = Sleep
BIT #$04DA ;Death, Petrify, Clear, Zombie, Magitek, Image
org $C21260
;Prevent Cover if Attacker and Target are on the same team
JMP friendly_fire
;Activate Cover if Attacker and Target are on opposing teams
cover:
org !freespace
reset bytes
;(Y = Target, X = Attacker)
friendly_fire:
CPX #$08
BCS .cover ;Branch if Attacker is a Monster
CPY #$08 ;Attacker is a Character
BCS .cover ;Branch if Target is a Monster
JMP $12A5 ;Exit function without activating Cover
.cover
LDA $3EE4,Y ;(Moved from C2/1260)
JMP cover ;Activate Cover
print bytes
|