Files
alttpr-baserom/variable_ganon_vulnerability.asm
2023-03-19 03:07:47 -05:00

189 lines
5.6 KiB
NASM

;--------------------------------------------------------------------------------
!ANCILLA_DAMAGE = "$06EC84"
; start with X = sprite index, A = ancilla type index
;--------------------------------------------------------------------------------
Ganon_CheckAncillaVulnerability:
PHA
LDA $0EE0, X : BNE .not_vulnerable_pla
PLA
PHX : PHA
LDA.l GanonVulnerabilityItem
TAX : PLA
CMP.l Ganon_CheckByAncilla, X : BNE +
PLX : BRA .vulnerable
+
PLX : PHA
LDA.l GanonVulnerabilityItem
CMP #$01 : BEQ .silver_arrows
CMP #$11 : BEQ .somaria
BRA .not_vulnerable_pla
.silver_arrows
PLA : CMP #$09 : BNE .not_vulnerable
LDA BowEquipment : CMP.b #$03 : !BGE +
LDA #$09 : BRA .not_vulnerable
+
BRA .vulnerable
.hammer
BRA .not_vulnerable_pla ; NYI
.golden_bee
BRA .not_vulnerable_pla ; NYI
.somaria
PLA : CMP #$01 : BEQ .vulnerable
CMP #$2C : BEQ .vulnerable
BRA .vulnerable
.vulnerable
PHX
LDA.l GanonVulnerabilityItem
TAX
LDA.l Ganon_IFrameDuration, X
PLX
STA $0EE0, X ; give the poor pig some iframes
LDA #$20 : STA $0F10, X
LDA #$09
RTL
.not_vulnerable_pla
PLA
.not_vulnerable
PHX : TAX
LDA.l !ANCILLA_DAMAGE, X
PLX
RTL
; end with X = sprite index, A = damage class
;--------------------------------------------------------------------------------
!ANCILLA_CHECK_SPRITE_DAMAGE_PRESET_CLASS = "$06ECE6"
;--------------------------------------------------------------------------------
Ganon_CheckPowderVulnerability: ; we know it's powder
LDA.l GanonVulnerabilityItem : CMP #$05 : BNE .normal ; ganon not vulnerable to powder
LDA $0E20, X : CMP #$D7 : BNE .normal ; not stunned ganon
LDA $0EE0, X : BNE .normal ; ganon has iframes
LDA.l Ganon_IFrameDuration+$05
STA $0EE0, X ; give the poor pig some iframes
LDA #$20 : STA $0F10, X
LDA #$09
BRA .done
.normal
LDA.b #$0A
.done
JSL.l !ANCILLA_CHECK_SPRITE_DAMAGE_PRESET_CLASS
RTL
;--------------------------------------------------------------------------------
Ganon_CheckBeeVulnerability: ; we know it's a bee
; X is bee sprite index
; Y is target sprite index
LDA.l GanonVulnerabilityItem : CMP #$10 : BNE .normal ; ganon not vulnerable to bee
LDA $0E20, Y : CMP #$D7 : BNE .normal ; not stunned ganon
LDA $0EE0, Y : BNE .normal ; ganon has iframes
LDA.l Ganon_IFrameDuration+$10
STA $0EE0, Y ; give the poor pig some iframes
LDA #$20 : STA $0F10, Y
LDA #$09
BRA .done
.normal
LDA.l SpecialWeapons : CMP.b #$06 : BNE .regular_bee
LDA.w $0ED0, X
BRA .done
.regular_bee
LDA.b #$01
.done
TYX
JSL.l !ANCILLA_CHECK_SPRITE_DAMAGE_PRESET_CLASS
RTL
;--------------------------------------------------------------------------------
Ganon_CheckInvincible:
LDA $04C5 : CMP.b #$02 : BEQ .not_transparent
LDA $0E20, X : CMP #$D7 : BNE .transparent ; non-stunned ganon
LDA $0301 : AND.b #$0A : BEQ .transparent ; normal behavior if not hammer
LDA.l GanonVulnerabilityItem : CMP #$0C : BNE .transparent ; ganon not vulnerable to hammer
.not_transparent
LDA #$00 : RTL
.transparent
LDA #$01 : RTL
; return non-zero A if ganon should be invincible
;--------------------------------------------------------------------------------
Ganon_CheckHammerVulnerability: ; we know it's hammer
LDA.l GanonVulnerabilityItem : CMP #$0C : BNE .normal ; ganon not vulnerable to hammer
LDA $0E20, X : CMP #$D7 : BNE .normal ; not stunned ganon
LDA $0EE0, X : BNE .normal ; ganon has iframes
LDA.l Ganon_IFrameDuration+$0C
STA $0EE0, X ; give the poor pig some iframes
LDA #$20 : STA $0F10, X
LDA #$09 : STA $0CF2 ; set damage class to silver
SEC : RTL
.normal
CLC : RTL
; return carry set bit if stunned Ganon and Ganon vulnerable to hammer
;--------------------------------------------------------------------------------
CheckBeeBoss:
; Y is sprite index
LDA.l SpecialWeapons : CMP #$06 : BNE .not_bee_mode
LDA #$00 : RTL
.not_bee_mode
LDA.l GanonVulnerabilityItem : CMP #$10 : BNE .normal ; ganon not vulnerable to bee
LDA $0E20, Y : CMP #$D7 : BNE .normal ; not stunned ganon
LDA #$00 : RTL
.normal
LDA $0B6B, Y : AND.b #$02
RTL
; return non-zero A if entity is a boss (and bee should not attack)
;--------------------------------------------------------------------------------
StunGanon:
JSL GetRandomInt
BIT.b #$30
BEQ .non_magic
.magic
AND.b #$0E
LSR
BRA .chosen
.non_magic
AND.b #$0C
LSR #2
ORA.b #$08
.chosen
PHX
TAX
LDA.l Ganon_RandomizeItem, X
STA.l GanonVulnerabilityItem
PLX
JSL DialogItem
LDA.b #$D7
STA.w $0E20, X
RTL
;--------------------------------------------------------------------------------
DialogItem:
PHX : PHY
LDA.l GanonVulnerabilityItem
ASL
TAX
LDA.l Ganon_TextBox+1, X
TAY
LDA.l Ganon_TextBox, X
JSL Sprite_ShowMessageUnconditional
PLY : PLX
RTL
;--------------------------------------------------------------------------------
Ganon_RandomizeItem:
db #$05, #$06, #$07, #$08
db #$09, #$0A, #$11, #$12
db #$01, #$02, #$03, #$0C
;--------------------------------------------------------------------------------
Ganon_TextBox:
dw #$0000 ; default behavior--assume silvers
dw #$0199, #$019A, #$019B, #$019C, #$019D
dw #$019E, #$019F, #$01A0, #$01A1, #$01A2
dw #$0000, #$01A3, #$0000, #$0000, #$0000
dw #$01A4, #$01A5, #$01A6, #$0000, #$0000
;--------------------------------------------------------------------------------
Ganon_CheckByAncilla:
db #$00 ; default behavior--we shouldn't be checking the table here anyway
db #$00, #$05, #$1F, #$07, #$00
db #$02, #$0B, #$19, #$18, #$1C
db #$00, #$00, #$00, #$00, #$00
db #$00, #$00, #$31, #$00, #$00
Ganon_IFrameDuration:
db #$00 ; default behavior--we shouldn't be here anyway
db #$00, #$00, #$00, #$34, #$00
db #$00, #$00, #$00, #$00, #$00
db #$00, #$00, #$00, #$00, #$00
db #$00, #$00, #$00, #$00, #$00
;--------------------------------------------------------------------------------