;Gravity Suit Customization
;-------------------------------
;Pick and choose properties of Grav
;Applying as-is will give you a suit with 1/2 damage reduction (stacks with Varia for 3/4 reduction), HALF damage from heated rooms, and NO underwater properties.
;Includes patches for Scyzer's ending suit palette and Smiley's Suit Damage.
lorom

!8DFree = $8DB8E5	;overwrite some unused projectile spritemaps for the heated room damage reduction.

;All this stuff in $91 handles the physics exclusively. Space and Screw are still active underwater.  
;This top batch are all checks of Samus's equipment for #$0020                                        
org $90819B : BRA $05   ;Underwater Animation delay                                                   ;\
org $9081DB : NOP #5    ;Gravity Suit under lava damage prevention                                    ;|
org $9082D3 : BRA $05   ;Under lava/acid animation delay                                              ;|
org $908420 : NOP #5    ;Underwater animation delay for wall jumps                                    ;|
org $909744 : NOP #5    ;Handle Samus "extra run speed" from holding dash; allow underwater if grav   ;|
org $9098C5 : NOP #5    ;Underwater jumping physics                                                   ;|
org $909952 : NOP #5    ;Underwater walljump physics                                                  ;|
org $9099DF : NOP #5    ;Samus Y speed for knockback                                                  ;|
org $909A32 : NOP #5    ;Underwater bomb jumping                                                      ;|-Disable Grav's underwater properties
org $909BD7 : NOP #5    ;"Determine Samus X speed table Entry Pointer"                                ;|
org $909C27 : NOP #5    ;Grapple swing speed                                                          ;|
org $909C5E : NOP #5    ;Determining Samus Y acceleration                                             ;|
																									  ;|
;This block is for when it checks Samus's palette index instead for Grav?????                         ;|
org $90A43C : NOP #5	;space jump/screw attack ability check                                        ;|
																									  ;|
;These handle Samus's transitions: stay in spinjump pose                                              ;|
org $91F68D : NOP #5                                                                                  ;|
org $91F6EE : NOP #5                                                                                  ;|
org $91FB11 : NOP #5                                                                                  ;|
;This block is for when it checks Samus's palette index instead for Grav?????                         ;|
org $91D9B5 : NOP #5	;screw attack palette handling                                                ;/


;---------------------------------------------

org $8DE37D : DB $01				;Gravity Suit no longer nullfies heat damage
org $8DE381 : JSR gravheat : NOP #4	;have it deal half damage instead.

org !8DFree
gravheat:
;[A] input is equip AND #$0021
;return damage to deal due to heat; [A] stored to env. subdamage after the RTS
CMP #$0020 : BNE +
LDA #$2000 : BRA $03
+
LDA #$4000
CLC : ADC $0A4E
RTS

;---------------------------------------------
;;;Modified suit damage division;;;
;makes each suit reduce damage by half and also remove Grav heat protection
SmileySuitDamage:
org $A0A45E ;Enemies
	STA $12
	LDA $09A2 ;A = equipped items
	BIT #$0001 : BEQ + : LSR $12 ;If Varia equipped, damage /= 2
+	BIT #$0020 : BEQ + : LSR $12 ;If Gravity equipped, damage /= 2
+	LDA $12				;A = final damage
	RTL
	
org $90E9D9 ;Periodic (heat, lava, acid) and environmental (spikes, samus eaters) damage
  LDA $09A2 : BIT #$0020 : BEQ + ;If Gravity equipped
    LDA $0A4F : LSR A : PHA : XBA : AND #$FF00 : STA $0A4E ;Subunit damage /= 2
    PLA : XBA : AND #$00FF : STA $0A50 ;Damage /= 2
+ LDA $09A2 : BIT #$0001 : BEQ + ;If Varia equipped
    LDA $0A4F : LSR A : PHA : XBA : AND #$FF00 : STA $0A4E ;Subunit damage /= 2
    PLA : XBA : AND #$00FF : STA $0A50 ;Damage /= 2
+

org $A3EED8 ;Metroid damage
  LDA #$C000 : STA $12 ;Base
  LDA $09A2 : BIT #$0020 : BEQ + : LSR $12 	;If gravity equipped, damage /= 2
+ BIT #$0001 : BEQ + : LSR $12 				;If Varia equipped, damage /= 2
+ JMP $EEF2
	
print pc, " - scyzersuits"
org $8BF71B : JSL ScyzerSuitCheck
org $8BF900
ScyzerSuitCheck:
	LDA $09A2 : BIT #$0020 : BNE .G : BIT #$0001 : BNE .V
	.P	LDX #$941E : BRA .D
	.V	LDX #$953E : BRA .D
	.G	LDX #$981E
	.D	LDA #$9B00 : STA $13 : STX $12
	LDX #$001E
	-	LDA [$12] : STA $7EC040,X : STA $7EC1C0,X
		DEC $12 : DEC $12 : DEX #2 : BPL -
	SEP #$20 : STZ $69 : RTL
