; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί OBLOGIC2.68K : OBJECT LOGIC CONTROL ROUTINES ...			   Ί
; ΜΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΉ
; Ί This file contains the CONTROL LOGIC routines for			   Ί
; Ί the following Objects ;						   Ί
; Ί 									   Ί
; Ί 									   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SmallHitSlideAMT	equ	2
MediumHitSlideAMT	equ	4
BigHitSlideAMT		equ	6

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί TEST LOGIC								   Ί
; ΜΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΉ
; Ί Test bed for new objects ...					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Test2			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί HEALTH METER LOGIC (PLAYER)						   Ί
; ΜΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΉ
; Ί Health meter control logic ...					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Health1PLR_Logic	rts

Health2PLR_Logic	move.l	Plr_Database,a1				;plrs database
			tst.b	faded_flg				;no color change when fading
			beq.s	.o1
			tst.w	GolInvincibleFLG
			beq.s	.o1a
			move.w	Pal3+30,d2				;funky effect for invincible
			add.w	#$222,d2
			and.w	#$fff,d2
			move.w	d2,Pal3+30
    			bra	.o1
.o1a			cmp.w	#170,OB_Nrg(a1)				;check to see if bar should be		
			bge.s	.grn					;green
			cmp.w	#85,OB_Nrg(a1)
			bge.s	.yel					;yellow
			addq.b	#1,GolFlashCNT 				;or flashing red
			and.b	#$7,GolFlashCNT
			bne.s	.r1
			eor.b	#1,GolFlashTOG
.r1			tst.b	GolFlashTOG
			beq.s	.red
.blk			move.w	#$000,Pal3+30				;flash black/red			
			bra	.o1
.red			move.w	#$00e,Pal3+30
			bra	.o1
.yel			move.w	#$0ee,Pal3+30				;yellow
			bra	.o1
.grn			move.w	#$0e0,Pal3+30				;green

.o1			;addq.b	#1,OB_Var7(a1)				;** TEST **
			;and.b	#$f,OB_Var7(a1)				;** TEST **
			;bne.s	.xx					;** TEST **
			move.w	PlrEnergy,d1				;compare real plr health
			cmp.w	OB_Nrg(a1),d1				;against virtual plr health
			beq.s	.x					;= skip
			blt.s	.down					
.up			addq.w	#1,OB_Nrg(a1)				;> slide bar up
			bra	DMA_HealthPLR				;build bar and set DMA
.down			subq.w	#1,OB_Nrg(a1)				;< slide bar down
			bra	DMA_HealthPLR				;build bar and set DMA
.x 			;eor.w	#GolMaxNRG,PlrEnergy			;** TEST **
.xx			rts
  			
Mask1			dc.l	%00000000000000000000000000000000	;bit masks
			dc.l	%11110000000000000000000000000000
			dc.l	%11111111000000000000000000000000
			dc.l	%11111111111100000000000000000000
			dc.l	%11111111111111110000000000000000
			dc.l	%11111111111111111111000000000000
			dc.l	%11111111111111111111111100000000
			dc.l	%11111111111111111111111111110000 
			
DMA_HealthPLR		lea	HealthBufferPLR,a2				;clr build buffer
			move.l	a2,a3
			moveq	#3,d1
.l1			clr.l	(a2)+					;1 char (32 bytes)
			clr.l	(a2)+
			clr.l	(a2)+
			clr.l	(a2)+
			clr.l	(a2)+
			clr.l	(a2)+
			clr.l	(a2)+
			clr.l	(a2)+
			dbra	d1,.l1

			move.w	OB_Nrg(a1),d1				;get virtual energy value
			lsr.w	#3,d1					;/8 to get range 0-31
			move.w	d1,d2					;copy
			lsr.w	#3,d1					;/8 to get chr #
			and.w	#7,d2					;&7 to get pix #
			asl.w	#2,d2					;*4 to get index into mask table

			lea	Health2Chr,a4				;point to health bar raw char data

			tst.w	d1					;0 chars?
			beq.s	.frac					;do fractional only
			subq.w	#1,d1
.char			move.l	(a4)+,(a3)+				;transfer a full char
			move.l	(a4)+,(a3)+
			move.l	(a4)+,(a3)+
			move.l	(a4)+,(a3)+
			move.l	(a4)+,(a3)+
			move.l	(a4)+,(a3)+
			move.l	(a4)+,(a3)+
			move.l	(a4)+,(a3)+
			dbra	d1,.char

.frac			tst.w	d2					;0 bits?
			beq.s	.skp					;skip to DMA
			lea	Mask1,a5				;point to mask table
			move.l	0(a5,d2.w),d2				;get mask
			
			move.l	(a4)+,d1				;transfer a fractional char
			and.l	d2,d1					;masking from right to left
			move.l	d1,(a3)+
			move.l	(a4)+,d1				
			and.l	d2,d1
			move.l	d1,(a3)+
			move.l	(a4)+,d1				
			and.l	d2,d1
			move.l	d1,(a3)+
			move.l	(a4)+,d1				
			and.l	d2,d1
			move.l	d1,(a3)+
			move.l	(a4)+,d1				
			and.l	d2,d1
			move.l	d1,(a3)+
			move.l	(a4)+,d1				
			and.l	d2,d1
			move.l	d1,(a3)+
			move.l	(a4)+,d1				
			and.l	d2,d1
			move.l	d1,(a3)+
			move.l	(a4),d1				
			and.l	d2,d1
			move.l	d1,(a3)
	
.skp			cmp.w	#Level51,levnum
			bne.s	.norm
			move.l	DMA_Stack,a6				;set DMA packet
			move.w	#L5Health2_VRAM,-(a6)			;destination
			bra.s	.n1
.norm			move.l	DMA_Stack,a6				;set DMA packet
			move.w	#Health2_VRAM,-(a6)			;destination
.n1			move.l	#(HealthBufferPLR/2),-(a6)		;source/2
			move.w	#(4*32)/2,-(a6)				;length/2
			move.w	#_DMATransfer,-(a6)			;flag this data package is a dma transfer
			move.l	a6,DMA_Stack
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί HEALTH METER LOGIC (ENEMY/BOSS)					   Ί
; ΜΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΉ
; Ί Health meter control logic ...					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ


SetupBossMeter		SPAWN_HI	Health2NME_MAX_Size
			move.w	#Health2NME_OB,OB_Type(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			move.b	#_ob_hiprior+_ob_nooff,OB_Flag2(a0)
			bset.b	#ob_noclip,OB_Flag1(a0)			;clipping off
			bset.b	#ob_noscroll,OB_Flag5(a0)		
			clr.b	OB_Var1(a0)
			move.w	#$125,OB_Xpos(a0)
			move.w	#$db,OB_Ypos(a0)
			lea	BHealth1ANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim

			SPAWN_HI	Health2NME_MAX_Size
			move.w	#Health2NME_OB,OB_Type(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			move.b	#_ob_hiprior+_ob_nooff,OB_Flag2(a0)
			bset.b	#ob_noclip,OB_Flag1(a0)			;clipping off
			bset.b	#ob_noscroll,OB_Flag5(a0)		
			move.b	#1,OB_Var1(a0)
			move.w	#$125+8,OB_Xpos(a0)
			move.w	#$db,OB_Ypos(a0)
			lea	BHealth1ANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim

			SPAWN_HI	Health2NME_MAX_Size
			move.w	#Health2NME_OB,OB_Type(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			move.b	#_ob_hiprior+_ob_nooff,OB_Flag2(a0)
			bset.b	#ob_noclip,OB_Flag1(a0)			;clipping off
			bset.b	#ob_noscroll,OB_Flag5(a0)		
			move.b	#2,OB_Var1(a0)
			move.w	#$125+16,OB_Xpos(a0)
			move.w	#$db,OB_Ypos(a0)
			lea	BHealth1ANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim

			SPAWN_HI	Health2NME_MAX_Size
			move.w	#Health2NME_OB,OB_Type(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			move.b	#_ob_hiprior+_ob_nooff,OB_Flag2(a0)
			bset.b	#ob_noclip,OB_Flag1(a0)			;clipping off
			bset.b	#ob_noscroll,OB_Flag5(a0)		
			move.b	#3,OB_Var1(a0)
			move.w	#$125+24,OB_Xpos(a0)
			move.w	#$db,OB_Ypos(a0)
			lea	BHealth1ANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim
			
			SPAWN_HI	Health1NME_MAX_Size
			move.w	#Health1NME_OB,OB_Type(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			move.b	#_ob_hiprior+_ob_nooff,OB_Flag2(a0)
			bset.b	#ob_noclip,OB_Flag1(a0)			;clipping off
			bset.b	#ob_noscroll,OB_Flag5(a0)		
			move.w	#$130,OB_Xpos(a0)
			move.w	#$e6,OB_Ypos(a0)
			lea	BHealth0ANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim

			lea	HealthBufferNME,a2
			move.l	#$8888,0(a2)
			lea	HealthBufferFlagsNME,a3
			clr.l	0(a3)
			clr.b	BossFirstPass
			rts
	

Health1NME_Logic	tst.b	BossFirstPass
			beq.s	.x
			move.l	Boss_Database,a1			;boss' database
			move.w	BossEnergy,d1				;compare real boss health
			cmp.w	OB_Nrg(a1),d1				;against virtual boss health
			beq.s	.x					;= skip
			blt.s	.down					
.up			addq.w	#1,OB_Nrg(a1)				;> slide bar up
			bra	DMA_HealthBOSS				;build bar and set DMA
.down			subq.w	#1,OB_Nrg(a1)				;< slide bar down
			bra	DMA_HealthBOSS				;build bar and set DMA
.x			rts
	
DMA_HealthBOSS		moveq	#0,d1
			moveq	#0,d2
			move.w	OB_Nrg(a1),d1				;boss' nrg
			move.w	BossPercentile,d2
			divu	d2,d1					;devide by percentile to get range 0-31
			move.w	d1,d2					;copy
			lsr.w	#3,d1					;/8 to get chr #
			and.w	#7,d2					;&7 to get pix #
			
			lea	HealthBufferFlagsNME,a3
			move.l	#-1,0(a3)
			
			lea	HealthBufferNME,a2
			tst	d1
			beq.s	.frac1
			move.b	#8,0(a2)
			subq.b	#1,d1
			tst	d1
			beq.s	.frac2
			move.b	#8,1(a2)
			subq.b	#1,d1
			tst	d1
			beq.s	.frac3
			move.b	#8,2(a2)
			subq.b	#1,d1
			tst	d1
			beq.s	.frac4
			move.b	#8,3(a2)
			rts
.frac1			move.b	d2,0(a2)
			clr.b	1(a2)	
			clr.b	2(a2)	
			clr.b	3(a2)	
			rts
.frac2			move.b	d2,1(a2)
			clr.b	2(a2)	
			clr.b	3(a2)	
			rts
.frac3			move.b	d2,2(a2)
			clr.b	3(a2)	
			rts
.frac4			move.b	d2,3(a2)
			rts


NMEMeterAnmTab		dc.l	BHealth9ANM,BHealth8ANM,BHealth7ANM,BHealth6ANM,BHealth5ANM,BHealth4ANM,BHealth3ANM,BHealth2ANM
			dc.l	BHealth1ANM

Health2NME_Logic	tst.b	BossFirstPass
			beq.s	.x
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	HealthBufferNME,a2
			lea	HealthBufferFlagsNME,a3
			tst.b	0(a3,d1.w)
			beq.s	.x
			clr.b	0(a3,d1.w)
			move.b	0(a2,d1.w),d1
			asl.w	#2,d1
			move.l	NMEMeterAnmTab(pc,d1.w),a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
.x			rts

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί NUMERAL LIFE COUNTER						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

NumeralANM_TAB		dc.l	Numeral0ANM,Numeral1ANM,Numeral2ANM,Numeral3ANM,Numeral4ANM,Numeral5ANM
			dc.l	Numeral6ANM,Numeral7ANM,Numeral8ANM,Numeral9ANM,Numeral10ANM

Numeral_Logic		tst.b	UpdateLivesFLG
			beq.s	.x
			clr.b	UpdateLivesFLG
			moveq	#0,d1
			move.b	lives,d1
			asl.w	#2,d1
			lea	NumeralANM_TAB,a1
			move.l	0(a1,d1.w),a1
			bsr	SetNewAnim
			bra	ForceNewAnim
.x			rts



			if	1=0
; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί FIRE FIRE FIRE							   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

FlameIntensity		equ	1
FlameSpread		equ	1
FlameDecay		equ	$33

FlameByteMod		dc.b	$00,$11,$22,$33,$44,$55,$66,$77,$88,$99,$aa,$bb,$cc,$dd,$ee,$ff

			
Burn_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.2
			bset.b	#ob_setup,OB_Flag2(a0)
			move.l	#BurnOffRout,OB_OffRoutine(a0)		;set off routine
			tst.b	BurnFirst
			bne.s	.1
			st.b	BurnFirst
			sub.w	#$1f,OB_Ypos(a0)
			move.l	a0,BurnDatabase
			st.b	BurnProcess
			lea	BurnANM,a1
			bsr	SetNewAnim
			bra	SmoothFlame

.1			;move.l	BurnDatabase,a1
			;move.l	OB_RefAnRam(a1),OB_RefAnRam(a0)		;a3=RAM reference table
			sub.w	#$1f,OB_Ypos(a0)
			lea	BurnANM,a1
			bra	SetNewAnim
.2			rts
			
;			move.b	#$ff,FlameBuff1+((FlameBuffWide*(FlameBuffDeep-1))+(FlameBuffWide/2))
;.1			rts


BurnOffRout		clr.b	BurnFirst
  			clr.b	BurnProcess
			rts

DoBurnLogic		move.l	BurnDatabase,a0
			bsr	DoFlame
			bsr	ConvertFlame
			bra	DMAFlame


DoFlame			lea	FlameBuff1,a1
			lea	FlameByteMod,a2
			jsr	Randy
			
			moveq	#FlameBuffDeep-1,d1			;y
.l2			moveq	#FlameBuffWide-1,d2			;x

.l1			move.b	0(a1,d2.w),d3
			beq.s	.0
			cmp.b	#FlameDecay,d3
			bge.s	.0

			move.w	d6,d7
			and.w	#FlameIntensity,d7
			move.b	0(a2,d7.w),d7
			sub.b	d7,d3
			rol.w	d6
			move.w	d2,d4
			move.w	d6,d5
			and.w	#FlameSpread,d5
			rol.w	d6
			move.w	d6,d7
			and.w	#1,d7
			beq.s	.2
			add.w	d5,d4
			bra	.3			
.2			sub.w	d5,d4
.3			move.b	d3,-FlameBuffWide(a1,d4.w)
			bra	.4

.0			tst.b	-FlameBuffWide(a1,d2.w)
			beq	.4
			sub.b	#$11,-FlameBuffWide(a1,d2.w)

.4			dbra	d2,.l1
			
			lea	FlameBuffWide(a1),a1
			rol.w	d6
			
			dbra	d1,.l2
			rts

flame12			dc.b	$66,$77,$88,$99,$99,$aa,$aa,$bb,$bb,$cc,$cc,$dd,$dd,$ee,$ee,$ff
			dc.b	$ff,$ee,$ee,$dd,$dd,$cc,$cc,$bb,$bb,$aa,$aa,$99,$99,$88,$77,$66


SmoothFlame		lea	FlameBuff1+((FlameBuffWide*(FlameBuffDeep-1))),a1
			lea	flame12,a2
			moveq	#FlameBuffWide-1,d2			;x
.l1			move.b	(a2)+,(a1)+
			dbra	d2,.l1
			rts



ConvTAB			dc.l	FlameBuff2+$00*32,FlameBuff2+$02*32,FlameBuff2+$04*32,FlameBuff2+$06*32
			dc.l	FlameBuff2+$01*32,FlameBuff2+$03*32,FlameBuff2+$05*32,FlameBuff2+$07*32
			dc.l	FlameBuff2+$08*32,FlameBuff2+$0c*32,FlameBuff2+$10*32,FlameBuff2+$14*32
			dc.l	FlameBuff2+$09*32,FlameBuff2+$0d*32,FlameBuff2+$11*32,FlameBuff2+$15*32
			dc.l	FlameBuff2+$0a*32,FlameBuff2+$0e*32,FlameBuff2+$12*32,FlameBuff2+$16*32
			dc.l	FlameBuff2+$0b*32,FlameBuff2+$0f*32,FlameBuff2+$13*32,FlameBuff2+$17*32


BPPccA			=	0
BPPTabA			rept	256
			dc.b	(((BPPccA&$F0)>>5)<<4)!((BPPccA&$0F)>>1)
BPPccA			=	BPPccA+1
			endr


ConvertFlame		lea	FlameBuff1,a3
			move.l	a3,a4

			lea	BPPTabA,a6
			lea	ConvTAB,a5
			moveq	#0,d4

			moveq	#CDepth-1,d5			;depth (in chars)
.l3			moveq	#CWidth-1,d1			;width (in chars)
.l2			move.l	a3,a1
		
			move.l	0(a5,d4.w),a2

			moveq	#7,d2				;Transfer Char (8 rows)
.l1			move.w	0(a1),d3			;pixels 1&2
			and.w	#$0ff0,d3
			lsr.w	#4,d3  
;			move.b	d3,(a2)+
			move.b	0(a6,d3.w),(a2)+	
			move.w	2(a1),d3			;pixels 3&4
			and.w	#$0ff0,d3
			lsr.w	#4,d3  
;			move.b	d3,(a2)+
			move.b	0(a6,d3.w),(a2)+	
			move.w	4(a1),d3			;pixels 5&6
			and.w	#$0ff0,d3
			lsr.w	#4,d3  
;			move.b	d3,(a2)+
			move.b	0(a6,d3.w),(a2)+
			move.w	6(a1),d3			;pixels 7&8
			and.w	#$0ff0,d3
			lsr.w	#4,d3  
;			move.b	d3,(a2)+
			move.b	0(a6,d3.w),(a2)+
			lea	FlameBuffWide(a1),a1
			dbra	d2,.l1
			
			addq.l	#8,a3
			addq.w	#4,d4
			dbra	d1,.l2

			lea	(CWidth*2)*FlameBuffWide(a4),a4
			move.l	a4,a3
			dbra	d5,.l3
			rts
			

DMAFlame		move.l	OB_RefAnRam(a0),a3		;a3=RAM reference table
			move.l	DMA_Stack,a6			;place entry in DMA Stack
			move.w	_VRAM_A(a3),-(a6)		;destination of DMA data	
			move.l	#FlameBuff2/2,-(a6)		;source of data to DMA / 2
			move.w	#((FlameBuffWide/2)*FlameBuffDeep)/2,-(a6)		;length of data to DMA (.w)
			move.w	#_DMATransfer,-(a6)		;flag this data package is a dma transfer
			move.l	a6,DMA_Stack
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί FIRE FIRE FIRE EXPLOSION						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		
CenterExp		equ	FlameBuff1+((FlameBuffWide*(FlameBuffDeep/2))+(FlameBuffWide/2))
ce			equ	CenterExp
cey			equ	FlameBuffWide

cexy			macro
			dc.l	(ce-(cey*\1)),((ce+\1)-(cey*\1)),(ce+\1),((ce+\1)+(cey*\1)),(ce+(cey*\1)),((ce-\1)+(cey*\1)),(ce-\1),((ce-\1)-(cey*\1))
			endm

cexyadd			dc.l	1,-1
			dc.l	cey+1,-cey-1
			dc.l	cey,-cey
			dc.l	cey-1,-cey+1
			dc.l	-1,1
			dc.l	-cey+1,cey-1
			dc.l	-cey,cey
			dc.l	-cey-1,cey+1

	
cexya1			dc.l	-cey,-cey+1,1,cey+1,cey,cey-1,-1,-cey-1

XYSCAN			cexy	0
			cexy	1
			cexy	2
			cexy	3
			cexy	4
			cexy	5
			cexy	6
			cexy	7
			cexy	8
			cexy	9
			cexy	10
			cexy	11
			cexy	12
			cexy	13
			cexy	14
			cexy	15

ExpPattern		hex	00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 00 ff 00 00 00 00 00 00 00 00
			hex	00 00 00 00 00 00 00 ff 00 00 00 00 ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00
			hex	00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 00
			hex	00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 00
			hex	00 00 00 00 00 00 00 00 00 ff ff ee ee ee ff ff ff ff ee ee ee ff ff 00 00 00 00 00 00 00 00 00
			hex	00 00 00 00 00 ff 00 00 00 ff ff ee dd ee ff ff ff ff ee dd ee ff ff 00 00 ff 00 00 00 00 00 00
			hex	00 00 00 00 00 00 00 00 ff ff ff ee ee ee ff ff ff ff ee ee ee ff ff ff 00 00 00 00 00 00 00 00
			hex	00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00
			hex	00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ee ee ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00
			hex	00 00 00 00 00 00 00 00 ff ff ee ff ff ff ff ff ff ff ff ff ff ee ff ff 00 00 00 ff 00 00 00 00
			hex	00 00 00 00 00 00 00 00 00 ff ee ee ff ff ff ff ff ff ff ff ee ee ff 00 00 00 00 00 00 00 00 00
			hex	00 00 00 00 00 00 00 00 00 ff ff ee ee ff ff ff ff ff ff ee ee ff ff 00 00 00 00 00 00 00 00 00
			hex	00 00 00 00 ff 00 00 00 00 00 ff ee ee ee ee ee ee ee ee ee ee ff 00 00 00 00 00 00 00 00 00 00
			hex	00 00 00 00 00 00 00 00 ff 00 ff ff ff ee ee ee ee ee ee ff ff ff 00 00 ff 00 00 00 00 00 00 00
			hex	00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ee ee ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00
			hex	00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00

ExpIntensity		equ	$3
ExpDecay		equ	$33


SetExpUp		lea	FlameBuff1+(FlameBuffWide*16),a1
			lea	ExpPattern,a2
			move.w	#(16*32)-1,d1
.l1			move.b	(a2)+,(a1)+
			dbra	d1,.l1
			rts


Exp_Logic		btst.b	#but_a,d_joy1
			beq.s	.1
			bsr	SetExpUp

.1			move.l	d0,-(sp)
			bsr	DoExp
			bsr	ConvertFlame
			bsr	DMAFlame
			move.l	(sp)+,d0
			rts



DoExp			lea	FlameBuff1,a1
			lea	FlameByteMod,a2
			jsr	Randy
			lea	cexya1,a4
										
			moveq	#FlameBuffDeep-1,d1			;y
.l2			moveq	#FlameBuffWide-1,d2			;x
			
.l1			jsr	Randy
			move.l	a1,a5
			add.l	d2,a5
			move.w	d6,d7
			and.w	#7,d7
			asl.w	#2,d7
			move.l	0(a4,d7.w),d5
			tst.l	d5
			bmi.s	.2
			add.l	d5,a5
			bra	.3			
.2			neg.l	d5
			sub.l	d5,a5

.3			move.b	0(a1,d2.w),d3
			beq.s	.0
			cmp.b	#ExpDecay,d3
			bge.s	.0

			move.w	d6,d7
			and.w	#ExpIntensity,d7
			move.b	0(a2,d7.w),d7
			cmp.b	d7,d3
			bgt.s	.5
			move.b	#$11,d7
.5			sub.b	d7,d3
			move.b	d3,(a5)
			bra	.4

.0			tst.b	(a5)
			beq	.4
			sub.b	#$11,(a5)

.4			dbra	d2,.l1
			
			lea	FlameBuffWide(a1),a1
			
			dbra	d1,.l2
			rts
			endif


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί RAPTOR BOT CONTROL LOGIC						   Ί
; ΜΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΉ
; Ί Raptor Bot.								   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	RapBotTestSTATE
		StDEF	RapBotGroundZeroSTATE
		StDEF	RapBotPatrolSTATE
		StDEF	RapBotTurnSTATE
		StDEF	RapBotIdleSTATE
		StDEF	RapBotWalkToSTATE
		StDEF	RapBotTurnToSTATE
		StDEF	RapBotJumpAttackSTATE
		StDEF	RapBotBigJumpAttackSTATE
		StDEF	RapBotFallSTATE
		StDEF	RapBotLandSTATE
		StDEF	RapBotEdgeFallSTATE
		StDEF	RapBotSnakeAttackSTATE
		StDEF	RapBotBackOffSTATE
		StDEF	RapBotDefendSTATE
		StDEF	RapBotDefendEndSTATE
		StDEF	RapBotSmallHitSTATE
		StDEF	RapBotBigHitSTATE
		StDEF	RapBotThrownSTATE
		StDEF	RapBotThrownReleaseSTATE
		StDEF	RapBotThrownFallSTATE
		StDEF	RapBotThrownLandSTATE
		StDEF	RapBotSlammedSTATE
		StDEF	RapBotFaceHugSTATE
		StDEF	RapBotFaceHugRendSTATE
		StDEF	RapBotFaceHugOffSTATE
		StDEF	RapBotLandOffSTATE
		StDEF	RapBotHitOffEdgeSTATE
		StDEF	RapBotSubwaySTATE
		StDEF	RapBotRooftopSTATE
		StDEF	RapBotMutateSTATE
			

RaptorBot_Logic		tst.b	TunnelFLG
			beq.s	.y
			cmp.b	#3,TunnelFLG
			bgt.s	.y
			rts

.y			btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			move.l	#RapBotSetHits,OB_HitRoutine(a0)
			cmp.b	#-1,OB_Var1(a0)
			beq	RapBotSetSubway
			cmp.b	#-2,OB_Var1(a0)
			beq	RapBotSetRooftop
			cmp.b	#-3,OB_Var1(a0)
			beq	RapBotSetMutate
			bsr	SetStartHeight
			bra	RapBotSetPatrol				;initial state
			
.1			bsr	HandleBeingHit				;Generic handle hit rout
			bsr	HandleHitTally			
			bsr	ObjectOffBottom
			blt	HandleEnemyKilled
    
			jsr	GetUnderFEET
			cmp.b	#SB_Grinder,d2
			beq	RapBotSetAirExplode

			move.w	#$300,d1
			bsr	TestProxX
			bpl	SwitchObjectOff
			move.w	#$180,d1
			bsr	TestProxY
			bpl	SwitchObjectOff
			
			move.w	OB_State(a0),d1
			jmp	RaptorBotLogicTable(pc,d1.w)		;jump table

RaptorBotLogicTable	bra	RapBotTestLOGIC
			bra	RapBotGroundZeroLOGIC
			bra	RapBotPatrolLOGIC
			bra	RapBotTurnLOGIC
			bra	RapBotIdleLOGIC
			bra	RapBotWalkToLOGIC
			bra	RapBotTurnToLOGIC
			bra	RapBotJumpAttackLOGIC
			bra	RapBotBigJumpAttackLOGIC
			bra	RapBotFallLOGIC
			bra	RapBotLandLOGIC
			bra	RapBotEdgeFallLOGIC
			bra	RapBotSnakeAttackLOGIC
			bra	RapBotBackOffLOGIC
			bra	RapBotDefendLOGIC
			bra	RapBotDefendEndLOGIC
			bra	RapBotSmallHitLOGIC
			bra	RapBotBigHitLOGIC
			bra	RapBotThrownLOGIC
			bra	RapBotThrownReleaseLOGIC
			bra	RapBotThrownFallLOGIC
			bra	RapBotThrownLandLOGIC
			bra	RapBotSlammedLOGIC
			bra	RapBotFaceHugLOGIC
			bra	RapBotFaceHugRendLOGIC
			bra	RapBotFaceHugOffLOGIC
			bra	RapBotLandOffLOGIC
			bra	RapBotHitOffEdgeLOGIC
			bra	RapBotSubwayLOGIC
			bra	RapBotRooftopLOGIC
			bra	RapBotMutateLOGIC

DoRapBotAI		move.l	d1,AI_Exclude
			lea	RAPTOR_AI,a1
			bsr	AI_Routine
			bpl.s	.1
			AddStack 4
			jmp	(a1)
.1			rts


; - RaptorBot Testbed ------------------------------------------------------

RapBotSetTest		move.w	#RapBotTestSTATE,OB_State(a0)
			lea	RapBotTestANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotTestLOGIC		bra	RapBotSetGroundZero


; - RaptorBot Hit/throw Routines -------------------------------------------------

RapBotSetHits		move.b	OB_Flag6(a0),d2
			and.b	#%11000111,OB_Flag6(a0)
			
			move.l	Plr_Database,a1
			cmp.w	#GolGroundGrabSTATE,OB_State(a1)
			bne.s	.1
			tst.b	RapBotThrownFLG
			bne.s	.2
			btst.b	#grabmode,OB_MasterMode(a1)
			bne	RapBotSetThrown
.1			btst.b	#airmode,OB_MasterMode(a0)
			bne	RapBotSetFaceHugOff
				
.2			bsr	RobotRandomHitSFX
			
			btst	#ob_hit_small,d2
			bne.s	RapBotSetSmallHit
			btst	#ob_hit_med,d2
			bne.s	RapBotSetBigHit
			btst	#ob_hit_big,d2
			bne.s	RapBotSetBigHit
			rts


RobotRandomHitSFX	jsr	Randy
			and.b	#1,d6
			beq.s	.a
			move.l	#107,sfx_poll
			bra	.b
.a			move.l	#104,sfx_poll
.b			jmp	SetSFX
			

RapBotSetSmallHit	move.w	#RapBotBigHitSTATE,OB_State(a0)
			move.w	#$2,OB_Var1(a0)
			lea	RapBotBigHitANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotSmallHitLOGIC	rts

RapBotSetBigHit		move.w	#RapBotBigHitSTATE,OB_State(a0)
			move.w	#MediumHitSlideAMT-1,OB_Var1(a0)
			bsr	MakeNmeFacePlayer
			lea	RapBotBigHitANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotBigHitLOGIC	bsr	RapBotTectBit2
			bmi	RapBotSetHitOffEdge
			jsr	TestLevelWalls			;turn at wall
			bmi.s	.a
			bsr	HitSlideObject
			bsr	HandleContours
;			bpl	RBSF2
			
.a			tst.l	OB_AnSequence(a0)
			bne.s	.x
			btst.b	#ob_dead,OB_Flag2(a0)
			bne	RapBotSetFlrExplode
			bclr.b	#ob_beinghit,OB_Flag1(a0)
			move.b	#$28,OB_Var9a(a0)
			addq.b	#1,OB_Var9(a0)
			cmp.b	#2,OB_Var9(a0)
			bge	RapBotSetBackOff
			bra	RapBotSetPatrol
.x			rts

RapBotTectBit2		btst.b	#ob_hitside,OB_Flag1(a0)
			beq.s	.rte
.lft			jsr	GetUnderFEET		;
			bsr	PullContourUnder
			beq	FlagYESn
			jsr	GetUnderLEFTLEFTBOT
			bra	FlagNOn
.rte			jsr	GetUnderFEET		;
			bsr	PullContourUnder
			beq	FlagYESn
			jsr	GetUnderRIGHTRIGHTBOT		
		
FlagNOn			tas	no
			rts
FlagYESn		tas	yes
			rts	

; - Throw Routines ---------------------------------------------------------

RapBotSetThrown		move.w	#RapBotThrownSTATE,OB_State(a0)
			move.b	#10,OB_Var4(a0)
			st.b	RapBotThrownFLG
			btst.b	#ob_xflp,Plr_Flag1			;make sure enemy faces right way
			bne.s	.1
			bset.b	#ob_xflp,OB_Flag1(a0)
			bra	.2
.1			bclr.b	#ob_xflp,OB_Flag1(a0)
.2			lea	RapBotGrabANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim


RapBotThrownLOGIC	tst.b	GolThrowReleaseFLG
			bne	RapBotSetThrownRelease
			tst.b	GolSlamFLG
			bne	RapBotSetSlammed
			
			tst.b	OB_Var4(a0)
			beq.s	.tt
   			subq.b	#1,OB_Var4(a0)
			cmp.b	#9,OB_Var4(a0)
			blt.s	.aa
			rts
.tt			bsr	WallInteruptThrow
			bmi	SpiBotSetExplodeI
.aa			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
.x			rts


; - Logic ------------------------------------------------------------------

RapBotSetThrownRelease	move.w	#RapBotThrownReleaseSTATE,OB_State(a0)
			SFX	24
			clr.w	OB_Var1(a0)
			move.w	#4,OB_Var2(a0)
			lea	RapBotThrownANM,a1			;set anim
			bsr	SetNewAnim

RapBotThrownReleaseLOGIC	btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			jsr	GetUnder
			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			jsr	GetUnderLEFT
			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			jsr	GetUnderLEFTLEFT
			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			bra	.lr	
.r			jsr	GetUnder
			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			jsr	GetUnderRIGHT
			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			jsr	GetUnderRIGHTRIGHT
			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
.lr			moveq	#3,d1
			bsr	MoveGolLeftRightFLP3
			addq.b	#1,OB_Var1a(a0)				
			and.b	#3,OB_Var1a(a0)				
			bne.s	.3					
			subq.w	#1,OB_Var2(a0)				;decrease upward velocity				
			beq	RapBotSetThrownFall
.3			move.w	OB_Var2(a0),d1				;get speed
			bra	MoveGolUp_Smooth			;move up


; - RaptorBot falls from thrown --------------------------------------------

RapBotSetThrownFall	move.w	#RapBotThrownFallSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			rts

RapBotThrownFallLOGIC	moveq	#3,d1
			bsr	MoveGolLeftRightFLP		

			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			jsr	GetUnderLEFTLEFT
			bra	.lr	
.r			jsr	GetUnderRIGHTRIGHT
.lr			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			
			addq.b	#1,OB_Var1(a0)
			and.b	#3,OB_Var1(a0)
			bne.s	.1
			addq.b	#1,OB_Var1a(a0)
.1			moveq	#0,d1
			move.b	OB_Var1a(a0),d1
		
			bsr	MoveGolDown_Smooth
			bsr	TestLand
			bmi	RapBotSetThrownLand
			rts


; - RaptorBot lands from thrown --------------------------------------------

RapBotSetThrownLand	move.w	#RapBotThrownLandSTATE,OB_State(a0)
			move.w	#3,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			move.l	a0,-(sp)
			SPAWN_HI	Sparks_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#Sparks_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.b	#1,OB_Var4(a1)
			move.l	a0,OB_Var5(a1)
			bra	.2
.1			move.l	(sp)+,a0

.2			;SFX 	1

RapBotThrownLandLOGIC	move.w	OB_Var1(a0),d1				;x speed
			beq	RapBotSetFlrExplode
			bsr	MoveGolLeftRightFLP			;move x
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			jsr	GetUnderLEFTLEFT
			bra	.lr	
.r			jsr	GetUnderRIGHTRIGHT
.lr			jsr	TestLevelWalls
			bpl.s	.ok
			clr.w	OB_Var1(a0)
			bra	RapBotSetFlrExplode
.ok			bsr	HandleContours
			bpl	RBSF2
			addq.b	#1,OB_Var2(a0)				;slow down x 
			and.b	#$f,OB_Var2(a0)
			bne.s	.x
			subq.w	#1,OB_Var1(a0)
.x			rts


; - Body Slam Routines -----------------------------------------------------

RapBotSetSlammed	move.w	#RapBotSlammedSTATE,OB_State(a0)
			SFX	57
			lea	RapBotSlammedANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim
			
						
RapBotSlammedLOGIC	addq.b	#1,OB_Var1a(a0)
			and.b	#$7,OB_Var1a(a0)
			bne	.o1
			
			jsr	GetUnderFEET
			bsr	PullContourUnder
			bne.s	.aa
			st.b	GolSlamOutFLG
			bra	RBSF2
			
.aa			move.w	OB_Xpos(a0),TempX
			move.w	OB_Ypos(a0),TempY
			bsr	SetupRandomStuff

.o1			tst.l	OB_AnSequence(a0)
			beq	RapBotSetFlrExplode
			
			bsr	WallInteruptThrow
			bmi	RapBotSetAirExplode
			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
.x			rts


; - RaptorBot Zero ---------------------------------------------------------

RapBotSetGroundZero	

RapBotGroundZeroLOGIC	rts


; - Before RaptorBot sees Player --------------------------------------------
; - RaptorBot Patrol Logic --------------------------------------------------

RapBotSetPatrol		move.w	#RapBotPatrolSTATE,OB_State(a0)
			bsr	ClrHitStuff
			clr.b	OB_MasterMode(a0)
			lea	RapBotWalkANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotPatrolLOGIC	move.l	#RapBotSetPatrol,d1
			bsr	DoRapBotAI
			
			jsr	Randy
			and.w	#$1ff,d6
			beq	RapBotSetIdle
			cmp.w	#1,d6
			beq	RapBotSetTurn
			
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte

.lft			jsr	GetUnderLEFTFEET		;turn at edge
			bsr	PullContourUnder
			beq	RapBotSetTurn
			jsr	GetUnderLEFTLEFT
			bra	.lr
.rte			jsr	GetUnderRIGHTFEET		;turn at edge	
			bsr	PullContourUnder
			beq	RapBotSetTurn
			jsr	GetUnderRIGHTRIGHT		
.lr			jsr	TestLevelWalls			;turn at wall
			bmi	RapBotSetTurn
			moveq	#1,d1
			bsr	MoveGolLeftRightFLP
			bsr	CheckScreenBoundsX		;turn at screen bounds	
			bmi	RapBotSetTurn
			bra	HandleContours			;handle the contours
			

; - RaptorBot Stop and wait Logic ------------------------------------------

RapBotSetStop		


; - RaptorBot Patrol Turn Logic --------------------------------------------

RapBotSetTurn		move.w	#RapBotTurnSTATE,OB_State(a0)
			lea	RapBotTurnANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotTurnLOGIC		tst.l	OB_AnSequence(a0)
			bne.s	.1
			eor.b	#_ob_xflp,OB_Flag1(a0)
			bra	RapBotSetPatrol
.1			rts

; - RaptorBot Idle Logic --------------------------------------------------

RapBotSetIdle		bsr	DoesNmeFacePlayer			;if nme doesn't face plr 
			bpl	RapBotSetTurn				;nme turns
			move.w	#RapBotIdleSTATE,OB_State(a0)
			jsr	Randy
			and.b	#$3f,d6
			or.b	#$10,d6
			move.b	d6,OB_Var1(a0)
			clr.b	OB_MasterMode(a0)
			bsr	ClrHitStuff
			lea	RapBotIdleANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotIdleLOGIC		move.l	Plr_Database,a1				;don't time out if plr being face hugged
			cmp.w	#GolFaceHugSTATE,OB_State(a1)
			beq.s	.x
			
			subq.b	#1,OB_Var1(a0)
			beq.s	.ok
			
			lea	RAPTOR_AI2,a1
			bsr	AI_Routine
			bpl.s	.x
			jmp	(a1)

.ok			lea	RAPTOR_AI3,a1
			bsr	AI_Routine
			bpl.s	.1
			jmp	(a1)
			
.1			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte
.lft			jsr	GetUnderLEFTFEET
			bsr	PullContourUnder
			beq	RapBotSetBackOff
			jsr	GetUnderLEFTLEFT		;wall to left?	
			bra	.lr
.rte			jsr	GetUnderRIGHTFEET
			bsr	PullContourUnder
			beq	RapBotSetBackOff
			jsr	GetUnderRIGHTRIGHT		;wall to right?
.lr			jsr	TestLevelWalls	
			bmi	RapBotSetBackOff		;yes then backoff
			bra	RapBotSetPatrol
.x			rts


; - After RaptorBot sees Player --------------------------------------------
; - RaptorBot Walk to player Logic -----------------------------------------
			
RapBotSetWalkTo		move.w	#RapBotWalkToSTATE,OB_State(a0)
			clr.b	OB_Var1(a0)
			bsr	DoesNmeFacePlayer
			bpl	RBSTT1
RapBotSWT2		bsr	ClrHitStuff
			lea	RapBotWalkToANM,a1			;set anim
			bsr	SetNewAnim
  			bra	ForceNewAnim

RapBotWalkToLOGIC	move.l	#RapBotSetWalkTo,AI_Exclude
			lea	RAPTOR_AI,a1
			bsr	AI_Routine
			bpl.s	.a1
			cmp.l	#RapBotSetJumpAttack,a1
			bne.s	.a2
			jsr	Randy
			and.w	#$f,d6
			bne.s	.a1
.a2			jmp	(a1)

.a1			tst.b	OB_Var1(a0)
			beq.s	.1
			subq.b	#1,OB_Var1(a0)
			bra	.2						
.1			bsr	DoesNmeFacePlayer
			bpl	RBSTT1

.2			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte

.lft			jsr	GetUnderLEFTFEET		;stop at edge
			bsr	PullContourUnder
			beq	RapBotSetIdle
			jsr	GetUnderLEFTLEFT		;stop at wall	
			jsr	TestLevelWalls	
			bmi	RapBotSetIdle
			moveq	#2,d1
			bsr	MoveGolLeft_Smooth
			bra	HandleContours			;handle the contours

.rte			jsr	GetUnderRIGHTFEET		;stop at edge
			bsr	PullContourUnder
			beq	RapBotSetIdle
			jsr	GetUnderRIGHTRIGHT		;stop at wall
			jsr	TestLevelWalls	
			bmi	RapBotSetIdle
			moveq	#2,d1
			bsr	MoveGolRight_Smooth
			bra	HandleContours			;handle the contours

DoesNmeFacePlayer	move.w	OB_Xpos(a0),d1
			cmp.w	Plr_XPos,d1
			blt.s	.r
.l			btst.b	#ob_xflp,OB_Flag1(a0)
			bne	FlagYESn
			bra	FlagNOn
.r			btst.b	#ob_xflp,OB_Flag1(a0)
			beq	FlagYESn
			bra	FlagNOn


DoesNmeFacePlayerY	move.w	OB_Ypos(a0),d1
			cmp.w	Plr_YPos,d1
			blt.s	.r
.l			btst.b	#ob_yflp,OB_Flag1(a0)
			beq	FlagYESn
			bra	FlagNOn
.r			btst.b	#ob_yflp,OB_Flag1(a0)
			bne	FlagYESn
			bra	FlagNOn


; - RaptorBot Turn to Face Player Logic --------------------------------------------------

RBSTT3			PUSHADDRS RapBotSJA3
			bra	RapBotSetTurnTo
RBSTT2			PUSHADDRS RapBotSJA2
			bra	RapBotSetTurnTo
RBSTT1			PUSHADDRS RapBotSWT2

RapBotSetTurnTo		PUSHSTATE
			move.w	#RapBotTurnToSTATE,OB_State(a0)
			lea	RapBotTurnANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotTurnToLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.1
			eor.b	#_ob_xflp,OB_Flag1(a0)
			move.b	#$30,OB_Var1(a0)
			POPSTATE
			POPADDRS
			jmp	(a1)
.1			rts

; - RaptorBot Jump Attack --------------------------------------------------

RapBotSetJumpAttack	move.l	Plr_Database,a1				;don't attack if pr being face hugged
			cmp.w	#GolFaceHugSTATE,OB_State(a1)
			beq	RapBotSetIdle
			
			move.w	Plr_YPos,d1			;plr and nme on same line?
			sub.w	OB_Ypos(a0),d1
			bpl.s	.1
			neg.w	d1
.1			cmp.w	#$10,d1
			ble.s	.same
			cmp.w	#$50,d1				;within y bounds
			bgt.s	.same
;			move.w	Plr_XPos,d1
;			sub.w	OB_Xpos(a0),d1			;within x bounds
;			bpl.s	.1a
;			neg.w	d1
;.1a			cmp.w	#$100,d1
;			bgt	RapBotSetIdle
			bsr	AITestPlrIsAbove
			bmi	RapBotSetBigJumpAttack		;big jump if plr is above

.same			move.w	#RapBotJumpAttackSTATE,OB_State(a0)
			bsr	DoesNmeFacePlayer
			bpl	RBSTT2

RapBotSJA2		clr.w	OB_Var1(a0)
			cmp.w	#Level51,levnum
			bne.s	.1
			move.w	#$3,OB_Var2(a0)
			bra.s	.2			
.1			move.w	#$4,OB_Var2(a0)
.2			clr.b	OB_EventVar1(a0)
			bset.b	#airmode,OB_MasterMode(a0)
			bsr	SetMediumAttack
			SFX	22
			lea	RapBotJumpAttackANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotJumpAttackLOGIC	move.l	Plr_Database,a1
			btst.b	#grndmode,OB_MasterMode(a1)
			beq.s	.1
			bsr	CheckIfHitSomething
			bmi	RapBotSetFaceHug

.1			tst.b	OB_EventVar1(a0)			;don't do anything until anim script flags ok
			beq.s	.x
			
			bsr	RapBotTectBit1
			bmi	RapBotSetHitOffEdge
			moveq	#4,d1
			bsr	MoveGolLeftRightFLP
			bsr	UpParabola
			bmi	RapBotSetFall
.x			rts


RapBotTectBit1		btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte
.lft			jsr	GetUnderLEFTLEFT		;stop at wall	
			jmp	TestLevelWalls	
.rte			jsr	GetUnderRIGHTRIGHT		;stop at wall	
			jmp	TestLevelWalls	

		
; - RaptorBot Big Jump Attack --------------------------------------------------

RapBotSetBigJumpAttack	move.w	#RapBotBigJumpAttackSTATE,OB_State(a0)
			bsr	DoesNmeFacePlayer
			bpl	RBSTT3
RapBotSJA3		clr.w	OB_Var1(a0)
			move.w	#$6,OB_Var2(a0)
			clr.b	OB_EventVar1(a0)
			bset.b	#airmode,OB_MasterMode(a0)
			bsr	SetMediumAttack
			SFX	22
			lea	RapBotJumpAttackANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotBigJumpAttackLOGIC
			move.l	Plr_Database,a1
			btst.b	#grndmode,OB_MasterMode(a1)
			beq.s	.1
			bsr	CheckIfHitSomething
			bmi	RapBotSetFaceHug

.1			tst.b	OB_EventVar1(a0)			;don't do anything until anim script flags ok
			beq.s	.x
				
			bsr	RapBotTectBit1
			bmi	RapBotSetHitOffEdge
			moveq	#4,d1
			bsr	MoveGolLeftRightFLP
			bsr	UpParabola
			bmi.s	RapBotSetFall
.x			rts



; - RaptorBot Fall Logic ---------------------------------------------------

RapBotSetFall		lea	RapBotFallANM,a1			;set anim
RBSF1			bsr	SetNewAnim
			bsr	ForceNewAnim
RBSF2			move.w	#RapBotFallSTATE,OB_State(a0)
			bset.b	#airmode,OB_MasterMode(a0)
			clr.w	OB_Var2(a0)				;decrease upward velocity				
			
RapBotFallLOGIC		move.l	Plr_Database,a1
			btst.b	#grndmode,OB_MasterMode(a1)
			beq.s	.1
			bsr	CheckIfHitSomething
			bmi	RapBotSetFaceHug

.1			bsr	TestLand			
			bmi.s	RapBotSetLand
	       		
			bsr	RapBotTectBit1
			bpl.s	.3
			btst.b	#ob_beinghit,OB_Flag1(a0)
			bne	RapBotSetAirExplode
			bra	RapBotSetHitOffEdge
.3			moveq	#4,d1
			bsr	MoveGolLeftRightFLP
			
			addq.b	#1,OB_Var1a(a0)				;delay
			and.b	#3,OB_Var1a(a0)				
			bne.s	.2					
			addq.w	#1,OB_Var2(a0)				;decrease upward velocity				
.2			move.w	OB_Var2(a0),d1				;get speed
			bra	MoveGolDown_Smooth			;move up
.x			rts
			
; - RaptorBot Land from Jump --------------------------------------------

RapBotSetLand		btst.b	#ob_beinghit,OB_Flag1(a0)
			bne	RapBotSetThrownLand
RBSL2			bclr.b	#airmode,OB_MasterMode(a0)
			move.w	#RapBotLandSTATE,OB_State(a0)
			lea	RapBotLandANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotLandLOGIC		tst.l	OB_AnSequence(a0)			;wait for anim to finish
			beq	RapBotSetPatrol
			rts


; - RaptorBot Edge Fall Logic -------------------------------------------

RapBotSetEdgeFall	lea	RapBotFaceHugOffANM,a1			;set anim
			bsr	SetNewAnim
			bsr	ForceNewAnim
			move.w	#RapBotEdgeFallSTATE,OB_State(a0)
			bset.b	#airmode,OB_MasterMode(a0)
			clr.w	OB_Var2(a0)				;decrease upward velocity				
			move.b	#$10,OB_Var1(a0)
			
RapBotEdgeFallLOGIC	tst.b	OB_Var1(a0)
			beq.s	.1
  			subq.b	#1,OB_Var1(a0)
			bra	.3

.1			bsr	TestLand			
			bmi	RapBotSetLandOff
	       		
.3			moveq	#3,d1
			bsr	MoveGolLeftRightXFLP2
			
			addq.b	#1,OB_Var1a(a0)				;do variable height jumping
			and.b	#3,OB_Var1a(a0)				;depending on length of jump button
			bne.s	.2					;depression
			addq.w	#1,OB_Var2(a0)				;decrease upward velocity				
.2			move.w	OB_Var2(a0),d1				;get speed
			bra	MoveGolDown_Smooth			;move up


; - RaptorBot Snake Strike Attack --------------------------------------

RapBotSetSnakeAttack	move.l	Plr_Database,a1				;don't attack if pr being face hugged
			cmp.w	#GolFaceHugSTATE,OB_State(a1)
			beq	RapBotSetBackOff

			move.w	#RapBotSnakeAttackSTATE,OB_State(a0)
			move.b	#RapBotSnakeAttackPOWER,OB_HitPower(a0)
			bsr	SetMediumAttack
			clr.b	OB_EventVar1(a0)
			lea	RapBotSnakeAttackANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotSnakeAttackLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.1
			clr.b	OB_EventVar1(a0)
;			SFX	56
			SFX	88
.1			tst.l	OB_AnSequence(a0)			;wait for anim to finish
			beq	RapBotSetPatrol
			rts


; - RaptorBot Back Off -----------------------------------------------

RapBotSetBackOff	move.w	#RapBotBackOffSTATE,OB_State(a0)
			clr.w	OB_Var9(a0)
			move.b	#$a,OB_HitWait(a0)
			lea	RapBotBackOffANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotBackOffLOGIC	btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte

.lft			jsr	GetUnderRIGHTFEET		;stop at edge
			bsr	PullContourUnder
			beq	RapBotSetIdle
			jsr	GetUnderRIGHTRIGHTBOT		;stop at wall
			jsr	TestLevelWalls	
			bmi	RapBotSetIdle
			moveq	#2,d1
			bsr	MoveGolRight_NF_Smooth
			bra	.c
.rte			jsr	GetUnderLEFTFEET		;stop at edge
			bsr	PullContourUnder
			beq	RapBotSetIdle
			jsr	GetUnderLEFTLEFTBOT		;stop at wall
			jsr	TestLevelWalls	
			bmi	RapBotSetIdle
			moveq	#2,d1
			bsr	MoveGolLeft_NF_Smooth

.c			bsr	HandleContours

			tst.l	OB_AnSequence(a0)			;wait for anim to finish
			beq	RapBotSetIdle
			rts


; - RaptorBot Defend -------------------------------------------------------

RapBotSetDefend		move.w	#RapBotDefendSTATE,OB_State(a0)
			move.b	#RapBotDefencePOWER,OB_HitPower(a0)
			bsr	SetMediumAttack
			SFX	83
			lea	RapBotDefendANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotDefendLOGIC	jsr	Randy
			and.b	#$7,d6
			bne.s	.1
			SFX	83
.1			tst.l	OB_AnSequence(a0)
			beq.s	RapBotSetDefendEnd
.x			rts


; - RaptorBot Defend End ---------------------------------------------------

RapBotSetDefendEnd	move.w	#RapBotDefendEndSTATE,OB_State(a0)
;			KILL	14
			lea	RapBotDefendEndANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotDefendEndLOGIC	tst.l	OB_AnSequence(a0)
			beq	RapBotSetPatrol
			rts


; - RaptorBot Face Hug Latch -----------------------------------------------

RapBotSetFaceHug	move.w	#RapBotFaceHugSTATE,OB_State(a0)
			lea	RapBotFaceHugANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotFaceHugLOGIC	move.l	Plr_Database,a1				;don't time out if plr being face hugged
			cmp.w	#GolFaceHugSTATE,OB_State(a1)
			bne	RapBotSetFaceHugOff
			
			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
			tst.l	OB_AnSequence(a0)
			beq	RapBotSetFaceHugRend
			rts

; - RaptorBot Face Hug Rend Player -----------------------------------------

RapBotSetFaceHugRend	move.w	#RapBotFaceHugRendSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			lea	RapBotFaceHugRendANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotFaceHugRendLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.ok
			clr.b	OB_EventVar1(a0)		
			SFX	101
			moveq	#RapBotRendPOWER,d1
			bsr	GenericHitPlayer
			bmi	SetPlayerDead

.ok			move.l	Plr_Database,a1				;face hug off if plr ever drops out of face hug
			cmp.w	#GolGroundZeroSTATE,OB_State(a1)
			beq	RapBotSetFaceHugOff		
			btst.b	#ob_xflp,OB_Flag1(a1)			;sync flips
			beq.s	.1
			bclr.b	#ob_xflp,OB_Flag1(a0)
			bra	.2
.1			bset.b	#ob_xflp,OB_Flag1(a0)
.2			tst.b	GolThrowFLG				;plr flags throw off
			bne.s	RapBotSetFaceHugOff
			rts


; - RaptorBot Face Hug thrown off Player -----------------------------------

RapBotSetFaceHugOff	btst.b	#ob_dead,OB_Flag2(a0)
			bne	RapBotSetAirExplode
			move.w	#RapBotFaceHugOffSTATE,OB_State(a0)
			bclr.b	#airmode,OB_MasterMode(a0)
			clr.b	GolThrowFLG
			move.w	#3,OB_Var2(a0)
			move.b	#4,OB_Var4(a0)
			lea	RapBotFaceHugOffANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotFaceHugOffLOGIC	moveq	#3,d1
			bsr	MoveGolLeftRightXFLP2
			bsr	UpParabola
			tst.b	OB_Var4(a0)
			beq.s	.1
			subq.b	#1,OB_Var4(a0)
			rts
.1			bsr	TestLand
			bmi	RapBotSetLandOff
			rts

; - RaptorBot Hit of Edge -------------------------------------------------

RapBotSetHitOffEdge	move.w	#RapBotHitOffEdgeSTATE,OB_State(a0)
			bclr.b	#airmode,OB_MasterMode(a0)
			clr.b	GolThrowFLG
			move.w	#2,OB_Var2(a0)
			lea	RapBotFaceHugOffANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotHitOffEdgeLOGIC	moveq	#2,d1
			bsr	MoveGolLeftRightXFLP2
			bsr	UpParabola
			bsr	TestLand
			bpl.s	.x
			btst.b	#ob_dead,OB_Flag2(a0)
			bne	RapBotSetFlrExplode
			bra	RapBotSetLandOff
.x			rts



; - RaptorBot Land From Throw Off ------------------------------------------

RapBotSetLandOff	move.w	#RapBotLandOffSTATE,OB_State(a0)
			lea	RapBotLandOffANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotLandOffLOGIC	tst.l	OB_AnSequence(a0)
			beq	RapBotSetIdle
			rts


; - RaptorBot jumps up thru subway floor -----------------------------------

RapBotSetSubway		move.w	#RapBotSubwaySTATE,OB_State(a0)
			add.w	#$10,OB_Xpos(a0)
			clr.w	OB_Var1(a0)
			move.w	#3,OB_Var2(a0)
			clr.b	OB_EventVar1(a0)
			bset.b	#ob_xflp,OB_Flag1(a0)
			move.w	OB_Xpos(a0),TempX
			move.w	OB_Ypos(a0),TempY
			jsr	LightenPalette
			moveq	#4,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			moveq	#0,d4
			jsr	SetRandomDebris
			lea	RapBotJumpAttackANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

RapBotSubwayLOGIC	moveq	#2,d1
			bsr	MoveGolLeft
			bsr	UpParabola
			bmi	RapBotSetFall
.x			rts


; - RaptorBot jumps up thru rooftop -----------------------------------

RapBotSetRooftop	move.w	#RapBotRooftopSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			add.w	#$10,OB_Xpos(a0)
			rts
			
RapBotRooftopLOGIC	tst.b	OB_Var1(a0)
			beq.s	.wait

.leap			moveq	#2,d1
			bsr	MoveGolLeft
			bsr	UpParabola
			bmi	RapBotSetFall
.x			rts

.wait			moveq	#0,d1
			move.b	OB_Var2(a0),d1
			lea	LevelRaptors,a1
			lea	LevelRaptorsON,a2
			tst.b	0(a1,d1.w)
			beq.s	.x
			tst.b	0(a2,d1.w)
			bne.s	.x
			st.b	0(a2,d1.w)
			st.b	OB_Var1(a0)
			move.w	#4,OB_Var2(a0)
			clr.b	OB_EventVar1(a0)
			bset.b	#ob_xflp,OB_Flag1(a0)
			move.w	OB_Xpos(a0),TempX
			move.w	OB_Ypos(a0),TempY
			SFX	24;108
			jsr	LightenPalette
			moveq	#4,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			moveq	#0,d4
			jsr	SetRandomDebris
			lea	RapBotJumpAttackANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim


; - RaptorBot mutates from eye fireballs ---------------------------------

RapBotSetMutate		move.w	#RapBotMutateSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			add.w	#$10,OB_Ypos(a0)
			jsr	SetStartHeight
			lea	RapBotMutateANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

RapBotMutateLOGIC	tst.l	OB_AnSequence(a0)
			beq	RapBotSetPatrol				;initial state
			rts


; - RaptorBot Explodes and dies Logic --------------------------------------


RapBotSetWallExplodeR	bsr	SetBigAirExplodeAtOB_XY
			moveq	#0,d7
			bra	RBSE1
RapBotSetWallExplodeL	bsr	SetBigAirExplodeAtOB_XY
			moveq	#1,d7
			bra	RBSE1
RapBotSetAirExplode	bsr	SetBigAirExplodeAtOB_XY
			moveq	#2,d7
			bra	RBSE1
RapBotSetFlrExplode	bsr	SetBigFlrExplodeAtOB_XY
			moveq	#3,d7
RBSE1			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			bsr	SetRandomDebris
RBSE2			bra	HandleEnemyKilled



; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί SNIPER BOT CONTROL LOGIC						   Ί
; ΜΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΉ
; Ί Sniper Bot.								   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

; You probable don't want to use this, coz I still have to re-write it ...

		StRESET
		StDEF	SniBotGroundZeroSTATE
		StDEF	SniBotIdleSTATE
		StDEF	SniBotTurnToSTATE
		StDEF	SniBotWalkToSTATE
		StDEF	SniBotBackOffSTATE
		StDEF	SniBotTrackSTATE
		StDEF	SniBotFireSTATE
		StDEF	SniBotHitSTATE
		StDEF	SniBotThrownSTATE
		StDEF	SniBotThrownReleaseSTATE
		StDEF	SniBotThrownFallSTATE
		StDEF	SniBotEdgeFallSTATE
		StDEF	SniBotThrownLandSTATE
		StDEF	SniBotSlammedSTATE
					

SniperBot_Logic		tst.b	TunnelFLG
			beq.s	.y
			cmp.b	#3,TunnelFLG
			bgt.s	.y
			rts

.y			btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			bsr	SetStartHeight
;			subq.w	#8,OB_Ypos(a0)				;pos on ground
			bsr	SniBotSetGroundZero
			move.l	#SniBotSetHits,OB_HitRoutine(a0)
			move.b	#4,OB_Var5(a0)				;actual gun pos
			move.b	#4,OB_Var5a(a0)				;new gun pos
			
.1			bsr	ObjectOffBottom
			blt	HandleEnemyKilled
			bsr	HandleBeingHit				;Generic handle hit rout

			jsr	GetUnderFEET
			cmp.b	#SB_Grinder,d2
			beq	SpiBotSetAirExplode

			moveq	#0,d1					;get state var as index into ...
			move.w	OB_State(a0),d1
			move.w	d1,DebugArea
			jmp	SniperBotLogicTable(pc,d1.w)		;jump table

SniperBotLogicTable	bra	SniBotGroundZeroLOGIC
			bra	SniBotIdleLOGIC
			bra	SniBotTurnToLOGIC
			bra	SniBotWalkToLOGIC
			bra	SniBotBackOffLOGIC
			bra	SniBotTrackLOGIC
			bra	SniBotFireLOGIC
			bra	SniBotHitLOGIC
			bra	SniBotThrownLOGIC
			bra	SniBotThrownReleaseLOGIC
			bra	SniBotThrownFallLOGIC
			bra	SniBotEdgeFallLOGIC
			bra	SniBotThrownLandLOGIC
			bra	SniBotSlammedLOGIC
		

; - Hit Routines -----------------------------------------------------------

SniBotSetHits		move.b	OB_Flag6(a0),d2
			jsr	ClrHitStuff

			btst.b	#ob_dead,OB_Flag2(a0)
			bne	SniBotSetExplode
				       
			move.l	Plr_Database,a1
			cmp.w	#GolGroundGrabSTATE,OB_State(a1)
			bne.s	.1
			tst.b	RapBotThrownFLG
			bne.s	.1
			btst.b	#grabmode,OB_MasterMode(a1)
			bne	SniBotSetThrown

.1			bsr	RobotRandomHitSFX
			
			btst	#ob_hit_small,d2
			bne.s	SniBotSetHit
			btst	#ob_hit_med,d2
			bne.s	SniBotSetHit
			btst	#ob_hit_big,d2
			bne.s	SniBotSetHit
			rts

SniBotSetExplode	bsr	SetBigFlrExplodeAtOB_XY
			bpl.s	.1
			moveq	#3,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			bsr	SetRandomDebris
.1			bra	HandleEnemyKilled

; - SniperBot Hit ---------------------------------------------------------
		
SniBotSetHit		move.w	#SniBotHitSTATE,OB_State(a0)
			move.w	#SmallHitSlideAMT,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			bsr	MakeNmeFacePlayer
			lea	SniBotHitANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

SniBotHitLOGIC		jsr	HitSlideObject
			bmi	SniBotSetEdgeFall
			jsr	HandleContours
			tst.l	OB_AnSequence(a0)
			bne.s	.x
			move.b	#$28,OB_Var9a(a0)
			addq.b	#1,OB_Var9(a0)
			cmp.b	#3,OB_Var9(a0)
			beq	SniBotSetBackOff
			bra	SniBotSetIdle
.x			rts


; - Throw Routines ---------------------------------------------------------

SniBotSetThrown		move.w	#SniBotThrownSTATE,OB_State(a0)
			move.b	#10,OB_Var4(a0)
			st.b	RapBotThrownFLG
			btst.b	#ob_xflp,Plr_Flag1			;make sure enemy faces right way
			bne.s	.1
			bset.b	#ob_xflp,OB_Flag1(a0)
			bra	.2
.1			bclr.b	#ob_xflp,OB_Flag1(a0)
.2			lea	SniBotGrabANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim


SniBotThrownLOGIC	tst.b	GolThrowReleaseFLG
			bne	SniBotSetThrownRelease
			tst.b	GolSlamFLG
			bne	SniBotSetSlammed
			
			tst.b	OB_Var4(a0)
			beq.s	.tt
   			subq.b	#1,OB_Var4(a0)
			cmp.b	#9,OB_Var4(a0)
			blt.s	.aa
			rts
.tt			bsr	WallInteruptThrow
			bmi	SpiBotSetExplodeI
.aa			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
.x			rts


; - Logic ------------------------------------------------------------------

SniBotSetThrownRelease	move.w	#SniBotThrownReleaseSTATE,OB_State(a0)
			SFX	24
			clr.w	OB_Var1(a0)
			move.w	#4,OB_Var2(a0)
			lea	SniBotThrownANM,a1			;set anim
			bsr	SetNewAnim

SniBotThrownReleaseLOGIC	btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			jsr	GetUnder
			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			jsr	GetUnderLEFT
			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			jsr	GetUnderLEFTLEFT
			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			bra	.lr	
.r			jsr	GetUnder
			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			jsr	GetUnderRIGHT
			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			jsr	GetUnderRIGHTRIGHT
			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
.lr			moveq	#3,d1
			bsr	MoveGolLeftRightFLP3
			addq.b	#1,OB_Var1a(a0)				
			and.b	#3,OB_Var1a(a0)				
			bne.s	.3					
			subq.w	#1,OB_Var2(a0)				;decrease upward velocity				
			beq	SniBotSetThrownFall
.3			move.w	OB_Var2(a0),d1				;get speed
			bra	MoveGolUp_Smooth			;move up


; - RaptorBot falls from thrown --------------------------------------------

SniBotSetThrownFall	move.w	#SniBotThrownFallSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			lea	SniBotThrownANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

SniBotThrownFallLOGIC	moveq	#3,d1
			bsr	MoveGolLeftRightFLP		

			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			jsr	GetUnderLEFTLEFT
			bra	.lr	
.r			jsr	GetUnderRIGHTRIGHT
.lr			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			
			addq.b	#1,OB_Var1(a0)
			and.b	#3,OB_Var1(a0)
			bne.s	.1
			addq.b	#1,OB_Var1a(a0)
.1			moveq	#0,d1
			move.b	OB_Var1a(a0),d1
		
			bsr	MoveGolDown_Smooth
			bsr	TestLand
			bmi	SniBotSetThrownLand
			rts


; - RaptorBot falls from edge --------------------------------------------

SniBotSetEdgeFall	move.w	#SniBotEdgeFallSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			move.b	#$18,OB_Var2(a0)
			lea	SniBotGrabANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

SniBotEdgeFallLOGIC	tst.b	OB_Var2(a0)
			beq.s	.tect
			subq.b	#1,OB_Var2(a0)
			bra	.fall
			
.tect			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			jsr	GetUnderLEFTLEFT
			bra	.lr	
.r			jsr	GetUnderRIGHTRIGHT
.lr			jsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			bsr	TestLand
			bmi	RapBotSetAirExplode
			
.fall			moveq	#2,d1
			bsr	MoveGolLeftRightXFLP2		

			addq.b	#1,OB_Var1(a0)
			and.b	#3,OB_Var1(a0)
			bne.s	.1
			addq.b	#1,OB_Var1a(a0)
.1			moveq	#0,d1
			move.b	OB_Var1a(a0),d1
			bra	MoveGolDown_Smooth


; - RaptorBot lands from thrown --------------------------------------------

SniBotSetThrownLand	move.w	#SniBotThrownLandSTATE,OB_State(a0)
			move.w	#3,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			move.l	a0,-(sp)
			SPAWN_HI	Sparks_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#Sparks_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.b	#1,OB_Var4(a1)
			move.l	a0,OB_Var5(a1)
			bra	.2
.1			move.l	(sp)+,a0

.2			;SFX 	1

SniBotThrownLandLOGIC	move.w	OB_Var1(a0),d1				;x speed
			beq	RapBotSetFlrExplode
			bsr	MoveGolLeftRightFLP			;move x
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			jsr	GetUnderLEFTLEFT
			bra	.lr	
.r			jsr	GetUnderRIGHTRIGHT
.lr			jsr	TestLevelWalls
			bpl.s	.ok
			clr.w	OB_Var1(a0)
			bra	RapBotSetFlrExplode
.ok			bsr	HandleContours
			bpl	RBSF2
			addq.b	#1,OB_Var2(a0)				;slow down x 
			and.b	#$f,OB_Var2(a0)
			bne.s	.x
			subq.w	#1,OB_Var1(a0)
.x			rts


; - Body Slam Routines -----------------------------------------------------

SniBotSetSlammed	move.w	#SniBotSlammedSTATE,OB_State(a0)
			SFX	57
			lea	SniBotSlammedANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim
			
						
SniBotSlammedLOGIC	addq.b	#1,OB_Var1a(a0)
			and.b	#$7,OB_Var1a(a0)
			bne	.o1
			
			jsr	GetUnderFEET
			bsr	PullContourUnder
			bne.s	.aa
			st.b	GolSlamOutFLG
			bra	RBSF2
			
.aa			move.w	OB_Xpos(a0),TempX
			move.w	OB_Ypos(a0),TempY
			bsr	SetupRandomStuff

.o1			tst.l	OB_AnSequence(a0)
			beq	RapBotSetFlrExplode
			
			bsr	WallInteruptThrow
			bmi	RapBotSetAirExplode
			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
.x			rts


; - SniperBot Zero ---------------------------------------------------------

SniBotSetGroundZero	move.w	#SniBotGroundZeroSTATE,OB_State(a0)
			jsr	MakeNmeFacePlayerNOT
			lea	SniBotZeroANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

SniBotGroundZeroLOGIC	move.w	#$120,d1
			jsr	TestProxX
			bpl.s	.x
			move.w	#$80,d1
			jsr	TestProxX
			bmi.s	SniBotSetIdle
.x			rts


; - SniperBot idle ---------------------------------------------------------

SniBotSetIdle		move.w	#SniBotIdleSTATE,OB_State(a0)
			bsr	ClrHitStuff
			clr.b	OB_MasterMode(a0)
			cmp.l	#ANM_SniBotIdle,OB_AnSequence(a0)
			beq.s	.x
			lea	SniBotIdleANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim
.x			rts

SniBotIdleLOGIC		move.l	#-1,AI_Exclude
			lea	SNIPERBOT_AI,a1
			bsr	AI_Routine
			bpl.s	.x
			jmp	(a1)
.x			rts


; - After SniperBot sees Player --------------------------------------------
; - SniperBot Walk to player Logic -----------------------------------------

SniBotSetWalkTo		move.w	#SniBotWalkToSTATE,OB_State(a0)
			bsr	DoesNmeFacePlayer
			bpl	SBSTT1
SniBotSWT2		clr.b	OB_Var1(a0)
			bsr	ClrHitStuff
			lea	SniBotWalkANM,a1			;set anim
			bsr	SetNewAnim
  			bra	ForceNewAnim

SniBotWalkToLOGIC	move.l	#SniBotSetWalkTo,d1
			bsr	DoSniBotAI
		
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte
.lft			jsr	GetUnderLEFTLEFTFEET			;stop at edge
			bsr	PullContourUnder
			beq	SniBotSetIdle
			jsr	GetUnderLEFTLEFT		;stop at wall	
			jsr	TestLevelWalls	
			bmi	SniBotSetIdle
			moveq	#2,d1
			bsr	MoveGolLeft_Smooth
			bra	HandleContours			;handle the contours
.rte			jsr	GetUnderRIGHTRIGHTFEET			;stop at edge
			bsr	PullContourUnder
			beq	SniBotSetIdle
			jsr	GetUnderRIGHTRIGHT		;stop at wall
			jsr	TestLevelWalls	
			bmi	SniBotSetIdle
			moveq	#2,d1
			bsr	MoveGolRight_Smooth
			bra	HandleContours			;handle the contours


; - SniperBot Turn to Face Player Logic --------------------------------------------------

SBSTT2			PUSHADDRS SniBotSWT1
			bra	SniBotSetTurnTo
SBSTT1			PUSHADDRS SniBotSWT2

SniBotSetTurnTo		PUSHSTATE
			move.w	#SniBotTurnToSTATE,OB_State(a0)
			clr.l	OB_AnSequence(a0)
			clr.w	OB_Var2(a0)
			clr.b	OB_Var5a(a0)				;new gun pos
			rts

SniBotTurnToLOGIC	tst.b	OB_Var2(a0)
			bne.s	.y1
			bsr	SniBotGunReady
			bmi.s	.ok
			bra	SniBotAnimateGun
.ok			lea	SniBotTurnANM,a1			;set anim
			bsr	SetNewAnim
			bsr	ForceNewAnim
			st.b	OB_Var2(a0)
			
.y1			tst.l	OB_AnSequence(a0)
			bne.s	.1
			eor.b	#_ob_xflp,OB_Flag1(a0)
			POPSTATE
			POPADDRS
			jmp	(a1)
.1			rts


; - SniperBot Back Off -----------------------------------------------

SniBotSetBackOff	move.w	#SniBotBackOffSTATE,OB_State(a0)
			lea	SniBotBackOffANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

SniBotBackOffLOGIC	move.l	#-1,AI_Exclude
			lea	SNIPERBOT_AI2,a1
			bsr	AI_Routine
			bpl.s	.a
			jmp	(a1)

.a			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte

.lft			jsr	GetUnderRIGHTRIGHTFEET		;stop at edge
			bsr	PullContourUnder
			beq	SniBotSetTrack
			jsr	GetUnderRIGHT			;stop at wall
			jsr	TestLevelWalls	
			bmi	SniBotSetTrack
			moveq	#2,d1
			bsr	MoveGolRight_NF_Smooth
			bra	.c
.rte			jsr	GetUnderLEFTLEFTFEET		;stop at edge
			bsr	PullContourUnder
			beq	SniBotSetTrack
			jsr	GetUnderLEFT			;stop at wall
			jsr	TestLevelWalls	
			bmi	SniBotSetTrack
			moveq	#2,d1
			bsr	MoveGolLeft_NF_Smooth

.c			bsr	HandleContours

			tst.l	OB_AnSequence(a0)			;wait for anim to finish
			beq	SniBotSetIdle
			rts


; - SniperBot Track --------------------------------------------------------

			;check if sniperbots gun is straight
SniBotGunReady		tst.b	OB_Var5(a0)
			beq	FlagYESn
			bra	FlagNOn

SniBotSetTrack		move.w	#SniBotTrackSTATE,OB_State(a0)
SniBotSWT1		clr.l	OB_AnSequence(a0)
			clr.w	OB_Var5(a0)				;real gun pos/virtual gun pos				
			bra	SBAG1
			
SniBotTrackLOGIC	bsr	DoesNmeFacePlayer
			bpl	SBSTT2

.aaa			move.l	#SniBotSetTrack,d1
			bsr	DoSniBotAI
		
			tst.l	OB_AnSequence(a0)
			bne.s	.1
			
			jsr	Randy
			and.w	#$3f,d6
			beq	SniBotSetFire

.1			bsr	SniBotAnimateGun
			
			bsr	AITestPlrIsAbove
			bpl	.a0

.above			move.w	#$70,d1
			bsr	TestProxX
			bmi.s	.aclose

.afar			move.w	#$10,d1
			bsr	TestProxY_Above
			bmi.s	.a0
			move.w	#$30,d1
			bsr	TestProxY_Above
			bmi.s	.a25
			move.w	#$50,d1
			bsr	TestProxY_Above
			bmi.s	.a45
			move.w	#$70,d1
			bsr	TestProxY_Above
			bmi.s	.a65
			move.w	#$90,d1
			bsr	TestProxY_Above
			bmi.s	.a90
			rts
.aclose			move.w	#$10,d1
			bsr	TestProxY_Above
			bmi.s	.a0
			move.w	#$20,d1
			bsr	TestProxY_Above
			bmi.s	.a25
			move.w	#$30,d1
			bsr	TestProxY_Above
			bmi.s	.a45
			move.w	#$40,d1
			bsr	TestProxY_Above
			bmi.s	.a65
			move.w	#$50,d1
			bsr	TestProxY_Above
			bmi.s	.a90
			rts
.a0			clr.b	OB_Var5a(a0)
			rts
.a25			move.b	#1,OB_Var5a(a0)
			rts
.a45			move.b	#2,OB_Var5a(a0)
			rts
.a65			move.b	#3,OB_Var5a(a0)
			rts
.a90			move.b	#4,OB_Var5a(a0)
			rts


SBTrackAnmTab		dc.l	SniBotZeroANM
			dc.l	SniBotTrackU1ANM,SniBotTrackU2ANM,SniBotTrackU3ANM,SniBotTrackU4ANM
			
SniBotAnimateGun	tst.l	OB_AnSequence(a0)		;gun track by going thru all angles 
			bne	.x				;to reach new pos
 			move.b	OB_Var5a(a0),d1
			cmp.b	OB_Var5(a0),d1
			beq.s	.x
   			bgt.s	.up
.dn			subq.b	#1,OB_Var5(a0)
			bra	SBAG1
.x			rts
.up			addq.b	#1,OB_Var5(a0)
SBAG1			moveq	#0,d1
			move.b	OB_Var5(a0),d1
			asl.b	#2,d1
			move.l	SBTrackAnmTab(pc,d1.w),a1
			bsr	SetNewAnim
			bra	ForceNewAnim

			
; - SniperBot fire ---------------------------------------------------------

SniBotFireANMTab	dc.l	SniBotFireSANM	
			dc.l	SniBotFireU1ANM,SniBotFireU1ANM,SniBotFireU2ANM,SniBotFireU2ANM	
			
SniBotFireDIRTab	dc.b	4
			dc.b	3,3,2,2
			even
SniBotFireDIRTabF	dc.b	12
			dc.b	13,13,14,14
			even

SniBotSetFire		move.w	#SniBotFireSTATE,OB_State(a0)
			moveq	#0,d1
			move.b	OB_Var5(a0),d1
			asl.b	#2,d1
			move.l	SniBotFireANMTab(pc,d1.w),a1
			bsr	SetNewAnim
			bsr	ForceNewAnim
			bsr	RandomLaserSFX
			
			bsr	SetupDirectionalProj
			bpl.s	.x
			move.b	#SniperBoltHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			sub.w	#$18,OB_Ypos(a1)
			moveq	#0,d1
			move.b	OB_Var5(a0),d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.1
			move.b	SniBotFireDIRTabF(pc,d1.w),d1
			bra	.2
.1			move.b	SniBotFireDIRTab(pc,d1.w),d1
.2			move.b	d1,OB_Var1(a1)
			move.w	#DirProj1_OB,OB_Type(a1)
			lea	SniBotProj1ANM,a2
			bra	SetNewAnimA1
.x			rts			
						

SniBotFireLOGIC		tst.l	OB_AnSequence(a0)
			bne.s	.x
			move.w	#SniBotTrackSTATE,OB_State(a0)
.x			rts


DoSniBotAI		move.l	d1,AI_Exclude
			lea	SNIPERBOT_AI,a1
			bsr	AI_Routine
			bpl.s	.1
			AddStack 4
			jmp	(a1)
.1			rts


RandomLaserSFX		move.l	#47,sfx_poll
			jmp	SetSFX


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί EXPLOSIONS and DEBRIS CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SetBigFlrExplodeAtOB_XY	move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2

SetBigFlrExplode	move.w	d1,TempX
			move.w	d2,TempY

			move.l	a0,-(sp)
			SPAWN_HI	BigFlrExplode_MAX_Size
			bpl.s	SBFX1
			clr.b	OB_Var1(a0)
			bra	SBE2
SBFX1			move.l	(sp)+,a0
			bra	FlagNOn

SetBigAirExplodeAtOB_XY	move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
  			
SetBigAirExplode	move.w	d1,TempX
			move.w	d2,TempY

SetBigAirExplode2	move.l	a0,-(sp)
			SPAWN_HI	BigAirExplode_MAX_Size
			bpl.s	SBFX1
			move.b	#1,OB_Var1(a0)
SBE2			move.w	#BigExplode_OB,OB_Type(a0)
			move.w	TempX,OB_Xpos(a0)
			move.w	TempY,OB_Ypos(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
;			bset.b	#ob_hiprior,OB_Flag2(a0)
			move.l	a0,a1
			move.l	(sp)+,a0
			jsr	Randy
			and.w	#3,d6
			asl.w	#2,d6
			moveq	#0,d1
			move.l	expsfx(pc,d6.w),sfx_poll
			jsr	SetSFX
			bra	FlagYESn

expsfx			dc.l	95,96,97,97


BigExplode_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
  			bset.b	#ob_setup,OB_Flag2(a0)
			tst.b	OB_Var1(a0)
			beq.s	.flr
.air			lea	BigAirExplodeANM,a1			;set anim
			bra	.2
.flr			lea	BigFlrExplodeANM,a1			;set anim
.2			bsr	SetNewAnim
			bsr	ForceNewAnim
			jmp	LightenPalette
			
.1			tst.l	OB_AnSequence(a0)
			bne.s	.a
			jmp	SwitchObjectOff
.a			rts


SetSmallAirExplodeAtOB_XY
			bsr	SetSmallAirExplode
			bpl	FlagNOn
			jsr	SetFlipFromMother
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			bra	FlagYESn

SetSmallAirExplode	move.l	a0,-(sp)
			SPAWN_HI	SmallAirExplode_MAX_Size
			bmi.s	.1
			move.l	(sp)+,a0
			bra	FlagNOn
.1			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#SmallExplode_OB,OB_Type(a1)
			move.b	#1,OB_Var1(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bra	FlagYESn


SmallExplode_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
  			bset.b	#ob_setup,OB_Flag2(a0)
			SFX	95
			lea	SmallAirExplodeANM,a1			;set anim
			bra	SetNewAnim

.1			tst.l	OB_AnSequence(a0)
			bne.s	.2
			jmp	SwitchObjectOff
.2			rts


; --------------------------------------------------------------------------
; --------------------------------------------------------------------------

BigParabolaLIST		dc.w	$0700,$0100,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0600,$0200,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0500,$0300,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0400,$0400,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0300,$0500,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0200,$0600,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0100,$0700,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			
			dc.w	$0000,$0800,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0000,$0700,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	

			dc.w	$0100,$0700,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0200,$0600,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0300,$0500,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0400,$0400,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0500,$0300,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0600,$0200,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0700,$0100,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	



SmallParabolaLIST	dc.w	$0400,$0100,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0400,$0200,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0300,$0300,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0100,$0400,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0000,$0500,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0400,$0100,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0300,$0400,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			
			dc.w	$0200,$0200,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0200,$0100,$0030,$0030
			dc.b	%00111111,pad,pad,pad,pad,pad,pad,pad	

			dc.w	$0300,$0400,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0400,$0100,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0000,$0500,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0100,$0400,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0200,$0300,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0300,$0200,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			dc.w	$0400,$0100,$0030,$0030
			dc.b	%00111110,pad,pad,pad,pad,pad,pad,pad	
			
;ob_movxdir	equ	0	;0=right>:1=left<
;ob_movydir	equ	1	;0=down\/:1=up/\
;ob_movxacc	equ	2	;0=acc:1=decc
;ob_movyacc	equ	3	;0=acc:1=decc
;ob_noxmove	equ	4	;dont store new x in objects xpos (0=store:1=dont store)
;ob_noymove	equ	5	;dont store new y in objects ypos (0=store:1=dont store)


SetRandomDebris		cmp	#2,d7
			beq	AirDebris
			cmp	#3,d7
			beq	FlrDebris
			cmp	#4,d7
			beq	WallDebris
			cmp	#5,d7
			beq	WoodDebris
			cmp	#6,d7
			beq	GlassDebris
			rts


AirDebris		move.l	a0,-(sp)
.l1			move.l	d3,-(sp)
   			SPAWN_HI	Debris_MAX_Size
			bmi.s	.1
			move.l	(sp)+,d3
			move.l	(sp)+,a0
			rts
.1			move.l	(sp)+,d3
			move.w	#MetalDebris_OB,OB_Type(a0)
			move.w	d3,OB_Var4(a0)
			move.w	TempX,OB_Xpos(a0)	
			move.w	TempY,OB_Ypos(a0)	
			bset.b	#ob_tidy,OB_Flag5(a0)
			bsr	RandomParabola
			jsr	Randy
			and.w	#3,d6
			beq.s	.a
			cmp.w	#1,d6
			beq.s	.b
			cmp.w	#2,d6
			beq.s	.c
.d			move.b	#%00111100,OB_MoveFlags(a0)
			bra	.1b
.a			move.b	#%00111101,OB_MoveFlags(a0)
			bra	.1b
.b			move.b	#%00111110,OB_MoveFlags(a0)
			bra	.1b
.c			move.b	#%00111111,OB_MoveFlags(a0)
.1b			dbra	d3,.l1
			move.l	(sp)+,a0
			rts

FlrDebris		move.l	a0,-(sp)
.l1			move.l	d3,-(sp)
   			SPAWN_HI	Debris_MAX_Size
			bmi.s	.1
			move.l	(sp)+,d3
			move.l	(sp)+,a0
			rts
.1			move.w	#MetalDebris_OB,OB_Type(a0)
			move.l	(sp)+,d3
			move.w	d3,OB_Var4(a0)
			move.w	TempX,OB_Xpos(a0)	
			move.w	TempY,OB_Ypos(a0)	
			bset.b	#ob_tidy,OB_Flag5(a0)
			bsr	RandomParabola
			move.w	d3,d6
			and.w	#1,d6
			bne.s	.1a
			move.b	#%00111110,OB_MoveFlags(a0)
			bra	.1b
.1a			move.b	#%00111111,OB_MoveFlags(a0)
.1b			dbra	d3,.l1
			move.l	(sp)+,a0
			rts


; --------------------------------------------------------------------------

MetalANM_TAB		dc.l	Metal1ANM,Metal2ANM,Metal3ANM,Metal4ANM,Metal5ANM,Metal6ANM
			dc.l	Metal1ANM,Metal2ANM,Metal3ANM,Metal4ANM,Metal5ANM,Metal6ANM


MetalDebris_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
  			bset.b	#ob_setup,OB_Flag2(a0)
			move.w	OB_Xspd(a0),d1
			lsr.w	#8,d1
			move.w	d1,OB_Var2(a0)
			btst.b	#ob_movydir,OB_MoveFlags(a0)		;if initial dir is down
			bne.s	.1					;make y accelerate rather
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)		;than decellerate (as in a parabola)
.1			cmp.w	#ShellVBLANK,VBLANKPhase
			beq.s	.y1
			cmp.w	#Level11,levnum
			blt.s	.y1
			cmp.w	#Level14,levnum
			bgt.s	.y1
			lea	CastleWallDebrisANM,a1
			bra	.o1
.y1			lea	MetalANM_TAB,a1
			move.w	OB_Var4(a0),d1
			asl.w	#2,d1
			move.l	0(a1,d1.w),a1
.o1			bsr	SetNewAnim
			bra	ForceNewAnim
	
.ok			bsr	SubwayAccelerator
			bsr	MoveGolUpDown_Smooth
			move.w	OB_Var2(a0),d1
			bsr	MGLRa
			
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			beq.s	.x
			tst.w	OB_Yspd(a0)
			bne.s	.x
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)
			bclr.b	#ob_movydir,OB_MoveFlags(a0)
.x			rts


; --------------------------------------------------------------------------

GlassANM_TAB		dc.l	Glass1ANM,Glass2ANM,Glass3ANM,Glass1ANM,Glass2ANM,Glass3ANM

GlassDebris		move.l	a0,-(sp)
.l1			move.l	d3,-(sp)
   			SPAWN_HI	GlassDebris_MAX_Size
			bmi.s	.1
			move.l	(sp)+,d3
			move.l	(sp)+,a0
			rts
.1			move.w	#GlassDebris_OB,OB_Type(a0)
			move.l	(sp)+,d3
			move.w	d3,OB_Var4(a0)
			move.w	TempX,OB_Xpos(a0)	
			move.w	TempY,OB_Ypos(a0)	
			bset.b	#ob_tidy,OB_Flag5(a0)
			bsr	RandomParabolaSmall
			add.w	#$0100,OB_Xspd(a0)
			add.w	#$0300,OB_Yspd(a0)
			add.w	#$0040,OB_Yacc(a0)
			move.w	d3,d6
			and.w	#1,d6
			bne.s	.1a
			move.b	#%00111110,OB_MoveFlags(a0)
			bra	.1b
.1a			move.b	#%00111111,OB_MoveFlags(a0)
.1b			dbra	d3,.l1
			move.l	(sp)+,a0
			rts

GlassDebris_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
  			bset.b	#ob_setup,OB_Flag2(a0)
			move.w	OB_Xspd(a0),OB_Var2(a0)
			lea	GlassANM_TAB,a1
			move.w	OB_Var4(a0),d1
			asl.w	#2,d1
			move.l	0(a1,d1.w),a1
			bsr	SetNewAnim
			bra	ForceNewAnim

.1			bsr	SubwayAccelerator
			bsr	MoveGolUpDown_Smooth
			move.w	OB_Var2(a0),d1
			lsr.w	#8,d1
			bsr	MGLRa
			
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			beq.s	.x
			tst.w	OB_Yspd(a0)
			bne.s	.x
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)
			bclr.b	#ob_movydir,OB_MoveFlags(a0)
.x			rts


; --------------------------------------------------------------------------

WoodDebris		move.l	a0,-(sp)
.l1			move.l	d3,-(sp)
			cmp.w	#Level51,levnum
			bne.s	.n1
			SPAWN_HI	HighSignPiece_MAX_Size
			bmi.s	.1
			bra	.n2
.n1   			SPAWN_HI	WoodDebris_MAX_Size
			bmi.s	.1
.n2			move.l	(sp)+,d3
			move.l	(sp)+,a0
			rts
.1			move.w	#WoodDebris_OB,OB_Type(a0)
			move.l	(sp)+,d3
			move.w	d3,OB_Var4(a0)
			move.w	TempX,OB_Xpos(a0)	
			move.w	TempY,OB_Ypos(a0)	
			bset.b	#ob_tidy,OB_Flag5(a0)
			bsr	RandomParabolaSmall
			add.w	#$0100,OB_Xspd(a0)
			add.w	#$0300,OB_Yspd(a0)
			add.w	#$0040,OB_Yacc(a0)
			move.w	d3,d6
			and.w	#1,d6
			bne.s	.1a
			move.b	#%00111110,OB_MoveFlags(a0)
			bra	.1b
.1a			move.b	#%00111111,OB_MoveFlags(a0)
.1b			dbra	d3,.l1
			move.l	(sp)+,a0
			rts

WoodDebris_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
  			bset.b	#ob_setup,OB_Flag2(a0)
			move.w	OB_Xspd(a0),OB_Var2(a0)
			cmp.w	#Level51,levnum
			bne.s	.a
			lea	L5SignPieceANM,a1
			bra	.b
.a			lea	CastleWallDebrisANM,a1
.b			bsr	SetNewAnim
			btst.b	#ob_movydir,OB_MoveFlags(a0)		;if initial dir is down
			bne.s	.1					;make y accelerate rather
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)		;than decellerate (as in a parabola)

.1			bsr	SubwayAccelerator
			bsr	MoveGolUpDown_Smooth
			move.w	OB_Var2(a0),d1
			lsr.w	#8,d1
			bsr	MGLRa
			
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			beq.s	.x
			tst.w	OB_Yspd(a0)
			bne.s	.x
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)
			bclr.b	#ob_movydir,OB_MoveFlags(a0)
.x			rts


; --------------------------------------------------------------------------

WallDebris		move.l	a0,-(sp)
.l1			movem.l	d3/d4,-(sp)
   			SPAWN_HI	WallDebris_MAX_Size
			bmi.s	.1
			movem.l	(sp)+,d3/d4
			move.l	(sp)+,a0
			rts
.1			move.w	#WallDebris_OB,OB_Type(a0)
			movem.l	(sp)+,d3/d4
			move.w	d3,OB_Var4(a0)
			move.w	TempX,OB_Xpos(a0)	
			move.w	TempY,OB_Ypos(a0)	
			bset.b	#ob_tidy,OB_Flag5(a0)
			bsr	RandomParabolaSmall
			add.w	#$0100,OB_Xspd(a0)
			add.w	#$0400,OB_Yspd(a0)
			add.w	#$0050,OB_Yacc(a0)
			tst.w	d4
			beq.s	.1a
			move.b	#%00111110,OB_MoveFlags(a0)
			bra	.1b
.1a			move.b	#%00111111,OB_MoveFlags(a0)
.1b			dbra	d3,.l1
			move.l	(sp)+,a0
			rts

WallDebris_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne	.1
  			bset.b	#ob_setup,OB_Flag2(a0)
			move.w	OB_Xspd(a0),OB_Var2(a0)
			cmp.w	#Level11,levnum
			blt.s	.n1
			cmp.w	#Level14,levnum
			bgt.s	.n1
			lea	CastleWallDebrisANM,a1
			bra	.o1
.n1			cmp.w	#Level51,levnum
			bne.s	.n2
			lea	L5DebrisANM,a1
			bra	.o1
.n2			cmp.w	#Level31,levnum
			blt.s	.n3
			cmp.w	#Level34,levnum
			bgt.s	.n3
			lea	Wood1ANM,a1
			bra	.o1
.n3			lea	WallDebrisANM,a1
.o1			bsr	SetNewAnim
						
			and.b	#%11111001,OB_Flag1(a0)
			jsr	Randy
			and.b	#3,d6
			asl.b	#1,d6
			or.b	d6,OB_Flag1(a0)

			btst.b	#ob_movydir,OB_MoveFlags(a0)		;if initial dir is down
			bne.s	.1					;make y accelerate rather
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)		;than decellerate (as in a parabola)

.1			bsr	SubwayAccelerator
			bsr	MoveGolUpDown_Smooth
			move.w	OB_Var2(a0),d1
			lsr.w	#8,d1
			bsr	MGLRa
			
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			beq.s	.x
			tst.w	OB_Yspd(a0)
			bne.s	.x
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)
			bclr.b	#ob_movydir,OB_MoveFlags(a0)
.x			rts


SubwayAccelerator	cmp.w	#Level51,levnum
			bne.s	.x
			cmp.w	#$a0,OB_Ypos(a0)
			bgt.s	.x
			bset.b	#ob_hiprior,OB_Flag2(a0)
			addq.b	#1,OB_Var9(a0)
			and.b	#3,OB_Var9(a0)
			bne.s	.1
			addq.b	#1,OB_Var9a(a0)
.1			moveq	#0,d1
			move.b	OB_Var9a(a0),d1
			sub.w	d1,OB_Xpos(a0)
.x			rts


; --------------------------------------------------------------------------

SetupRandomStuff	move.l	a0,-(sp)
			move.w	rndnum,d3
			and.w	#1,d3
			beq.s	.2a
.2b			SPAWN_LO	Spark_MAX_Size
			bpl.s	.no
			move.w	#Spark_OB,OB_Type(a0)
			bra	.yup
.2a			SPAWN_LO	Spark_MAX_Size
			bpl.s	.no
			move.w	#Fireball_OB,OB_Type(a0)
			bra	.yup
.no			move.l	(sp)+,a0
.x			rts
.yup			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	TempX,OB_Xpos(a1)	
			move.w	TempY,OB_Ypos(a1)	
			bset.b	#ob_tidy,OB_Flag5(a1)
			bsr	RandomParabolaSmallA1
			move.b	second,d3
			and.b	#1,d3
			bne.s	.1a
			move.b	#%00111110,OB_MoveFlags(a1)
			rts
.1a			move.b	#%00111111,OB_MoveFlags(a1)
			rts
			
; --------------------------------------------------------------------------

RandomParabola		jsr	Randy
			and.w	#3,d6
			addq.w	#2,d6
			asl.w	#8,d6
			move.w	d6,OB_Xspd(a0)
			clr.w	OB_Xacc(a0)
			jsr	Randy
			and.w	#3,d6
			addq.w	#3,d6
			asl.w	#8,d6
			move.w	d6,OB_Yspd(a0)
			jsr	Randy
			and.w	#3,d6
			addq.w	#2,d6
			asl.w	#4,d6
			move.w	d6,OB_Yacc(a0)
			rts

RandomParabolaA1	jsr	Randy
			and.w	#3,d6
			addq.w	#2,d6
			asl.w	#8,d6
			move.w	d6,OB_Xspd(a1)
			clr.w	OB_Xacc(a1)
			jsr	Randy
			and.w	#3,d6
			addq.w	#3,d6
			asl.w	#8,d6
			move.w	d6,OB_Yspd(a1)
			jsr	Randy
			and.w	#3,d6
			addq.w	#2,d6
			asl.w	#4,d6
			move.w	d6,OB_Yacc(a1)
			rts

RandomParabolaSmall	jsr	Randy
			and.w	#1,d6
			add.w	#1,d6
			asl.w	#8,d6
			move.w	d6,OB_Xspd(a0)
			clr.w	OB_Xacc(a0)
RPS_Yonly		jsr	Randy
			and.w	#3,d6
			addq.w	#2,d6
			asl.w	#8,d6
			move.w	d6,OB_Yspd(a0)
			jsr	Randy
			and.w	#3,d6
			addq.w	#1,d6
			asl.w	#4,d6
			move.w	d6,OB_Yacc(a0)
			rts

RandomParabolaSmallA1	jsr	Randy
			and.w	#1,d6
			add.w	#1,d6
			asl.w	#8,d6
			move.w	d6,OB_Xspd(a1)
			clr.w	OB_Xacc(a1)
RPS_YonlyA1		jsr	Randy
			and.w	#3,d6
			addq.w	#2,d6
			asl.w	#8,d6
			move.w	d6,OB_Yspd(a1)
			jsr	Randy
			and.w	#3,d6
			addq.w	#1,d6
			asl.w	#4,d6
			move.w	d6,OB_Yacc(a1)
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί CORNERS								   Ί
; ΜΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΉ
; Ί Debug corners							   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

			if	show_tect
			
hitbox1			=	0
hitbox2			=	1
attackbox		=	2
plrobj			=	0
nmeobj			=	1

whichbox		=	attackbox	;hitbox1
whichobj		=	plrobj

SetupCorners		SPAWN_HI	32
     			move.w	#Corner_OB,OB_Type(a0)
			clr.w	OB_Var1(a0)
			bset.b	#ob_noclip,OB_Flag1(a0)
			move.b	#_ob_hiprior+_ob_nooff,OB_Flag2(a0)
			SPAWN_HI	32
     			move.w	#Corner_OB,OB_Type(a0)
     			move.w	#1,OB_Var1(a0)
			bset.b	#ob_noclip,OB_Flag1(a0)
			move.b	#_ob_hiprior+_ob_nooff,OB_Flag2(a0)
			SPAWN_HI	32
     			move.w	#Corner_OB,OB_Type(a0)
     			move.w	#2,OB_Var1(a0)
			bset.b	#ob_noclip,OB_Flag1(a0)
			move.b	#_ob_hiprior+_ob_nooff,OB_Flag2(a0)
			SPAWN_HI	32
     			move.w	#Corner_OB,OB_Type(a0)
     			move.w	#3,OB_Var1(a0)
			bset.b	#ob_noclip,OB_Flag1(a0)
			move.b	#_ob_hiprior+_ob_nooff,OB_Flag2(a0)
			rts

Corner_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	corl1
			bset.b	#ob_setup,OB_Flag2(a0)
			
			move.w	OB_Var1(a0),d1
			asl.w	#2,d1
			jmp	corna(pc,d1.w)
corna			bra	setcorn1
			bra	setcorn2
			bra	setcorn3
			bra	setcorn4
			
setcorn1		lea	Corner1ANM,a1
			bsr	SetNewAnim
			bra	ForceNewAnim
setcorn2		lea	Corner2ANM,a1
			bsr	SetNewAnim
			bra	ForceNewAnim
setcorn3		lea	Corner3ANM,a1
			bsr	SetNewAnim
			bra	ForceNewAnim
setcorn4		lea	Corner4ANM,a1
			bsr	SetNewAnim
			bra	ForceNewAnim

corl1			move.l	Plr_Database,a1
			move.l	OB_CollisionRAM(a1),a1
			move.w	OB_Var1(a0),d1
			asl.w	#2,d1
			jmp	cornl(pc,d1.w)
cornl
			if	whichbox=hitbox1
			bra	docorn1a
			bra	docorn2a
			bra	docorn3a
			bra	docorn4a
			elseif	whichbox=hitbox2
			bra	docorn1b
			bra	docorn2b
			bra	docorn3b
			bra	docorn4b
			elseif	whichbox=attackbox
			bra	docorn1c
			bra	docorn2c
			bra	docorn3c
			bra	docorn4c
			endif
		
docorn1a		move.w	OB_CBox1X1(a1),OB_Xpos(a0)
			move.w	OB_CBox1Y1(a1),OB_Ypos(a0)
			rts
docorn2a		move.w	OB_CBox1X2(a1),OB_Xpos(a0)
			move.w	OB_CBox1Y1(a1),OB_Ypos(a0)
			rts
docorn3a		move.w	OB_CBox1X2(a1),OB_Xpos(a0)
			move.w	OB_CBox1Y2(a1),OB_Ypos(a0)
			rts
docorn4a		move.w	OB_CBox1X1(a1),OB_Xpos(a0)
			move.w	OB_CBox1Y2(a1),OB_Ypos(a0)
			rts
docorn1b		move.w	OB_CBox2X1(a1),OB_Xpos(a0)
			move.w	OB_CBox2Y1(a1),OB_Ypos(a0)
			rts
docorn2b		move.w	OB_CBox2X2(a1),OB_Xpos(a0)
			move.w	OB_CBox2Y1(a1),OB_Ypos(a0)
			rts
docorn3b		move.w	OB_CBox2X2(a1),OB_Xpos(a0)
			move.w	OB_CBox2Y2(a1),OB_Ypos(a0)
			rts
docorn4b		move.w	OB_CBox2X1(a1),OB_Xpos(a0)
			move.w	OB_CBox2Y2(a1),OB_Ypos(a0)
			rts
docorn1c		move.w	OB_CBox3X1(a1),OB_Xpos(a0)
			move.w	OB_CBox3Y1(a1),OB_Ypos(a0)
			rts
docorn2c		move.w	OB_CBox3X2(a1),OB_Xpos(a0)
			move.w	OB_CBox3Y1(a1),OB_Ypos(a0)
			rts
docorn3c		move.w	OB_CBox3X2(a1),OB_Xpos(a0)
			move.w	OB_CBox3Y2(a1),OB_Ypos(a0)
			rts
docorn4c		move.w	OB_CBox3X1(a1),OB_Xpos(a0)
			move.w	OB_CBox3Y2(a1),OB_Ypos(a0)
			rts

;RBTL_btab		dc.b	-4,-3,-3,-2,-2,-1,-1,-1,0,0,0,1,1,1,2,2,3,3,4
;			dc.b	-3,-2,-2,-1,-1,0,0,1,1,2,2,3
;			dc.b	-2,-1,-1,0,1,1,2,$80
;			even
;.1			lea	RBTL_btab,a1  				;bounce table
;			moveq	#0,d1
;			move.b	OB_Var2a(a0),d1				;get/bump table index
;			addq.b	#1,OB_Var2a(a0)
;			move.b	0(a1,d1.w),d1
;			cmp.b	#$80,d1	     				;eot?
;			beq	RapBotSetIdle				;set idle
;			ext.w	d1					
;			add.w	d1,OB_Ypos(a0)				;move y	
;			rts

			endif
			

; - LOGIC ------------------------------------------------------------------

SignPieceANM_Tab	dc.l	Sign1ANM,Sign2ANM,Sign3ANM,Sign4ANM,Sign5ANM,Sign6ANM,Sign7ANM,Sign8ANM
			dc.l	Sign9ANM,Sign10ANM,Sign11ANM,Sign12ANM,Sign13ANM,Sign14ANM,Sign15ANM,Sign16ANM

SignPiece_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			add.w	#$c,OB_Xpos(a0)
			subq.w	#8,OB_Ypos(a0)
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			asl.b	#2,d1
			move.l	SignPieceANM_Tab(pc,d1.w),a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.1			btst.b	#ob_hitting,OB_Flag1(a0)
			beq	.x
			jsr	HandleEnemyKilled

			SFX	83

			bsr	SetSmallAirExplodeAtOB_XY
			bset.b	#ob_hiprior,OB_Flag2(a1)
			subq.w	#2,OB_Xpos(a1)

			move.w	OB_Xpos(a0),TempX
			move.w	OB_Ypos(a0),TempY
			
			move.l	a0,-(sp)
	
			moveq	#4,d3
.l1			move.l	d3,-(sp)
			SPAWN_HI	Spark_MAX_Size
			bpl.s	.n1
			move.w	TempX,OB_Xpos(a0)
			move.w	TempY,OB_Ypos(a0)
			move.w	#Spark_OB,OB_Type(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			bset.b	#ob_hiprior,OB_Flag2(a0)
			bsr	RandomParabolaSmall
			move.l	(sp)+,d3
			btst	#0,d3
			bne.s	.1a
			move.b	#%00111110,OB_MoveFlags(a0)
			bra.s	.nxt
.1a			move.b	#%00111111,OB_MoveFlags(a0)
.nxt			dbra	d3,.l1
			move.l	(sp)+,a0
.x			rts
.n1			move.l	(sp)+,d3
			move.l	(sp)+,a0
			rts



; - LOGIC ------------------------------------------------------------------

SteamVent_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			jsr	SetStartHeight
			addq.w	#$8,OB_Ypos(a0)
			clr.w	OB_Var3(a0)
			clr.b	SteamVentFLG
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelVentsL,a2
			tst.b	0(a2,d1.w)
			bne.s	.a
			clr.b	OB_Var2(a0)
			lea	SteamVentANM,a1
			bra	.b			
.a			st.b	OB_Var2(a0)
			lea	SteamVentBrokenANM,a1			
.b			jsr	SetNewAnim
			jmp	ForceNewAnim

.1			tst.b	OB_Var2(a0)
			bne	.blow
			
			btst.b	#ob_beinghit,OB_Flag1(a0)
			beq	.x
			jsr	ClrHitStuff
			st.b	OB_Var2(a0)
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelVentsL,a1
			st.b	0(a1,d1.w)
			lea	SteamVentBrokenANM,a1			
			jsr	SetNewAnim
	
			bsr	SetBigAirExplodeAtOB_XY
			bset.b	#ob_hiprior,OB_Flag2(a1)

			move.l	a0,-(sp)
			
			moveq	#6,d3
.l1			move.l	d3,-(sp)
			SPAWN_HI	Spark_MAX_Size
			bpl.s	.n1
			move.w	TempX,OB_Xpos(a0)
			move.w	TempY,OB_Ypos(a0)
			move.w	#Spark_OB,OB_Type(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			bset.b	#ob_hiprior,OB_Flag2(a0)
			bsr	RandomParabolaSmall
			move.l	(sp)+,d3
			btst	#0,d3
			bne.s	.1a
			move.b	#%00111110,OB_MoveFlags(a0)
			bra.s	.nxt
.1a			move.b	#%00111111,OB_MoveFlags(a0)
.nxt			dbra	d3,.l1
			move.l	(sp)+,a0
.x			rts
.n1			move.l	(sp)+,d3
			move.l	(sp)+,a0
			rts

.blow			move.l	Plr_Database,a1
			cmp.w	#GolThrownSTATE,OB_State(a1)
			beq.s	.no
			move.w	#$20,d1
			jsr	TestProxX
			bpl.s	.no
  			move.w	#$30,d1
			jsr	TestProxY_Above
			bpl.s	.no
			move.w	#$a,d1
			jsr	TestProxY_Below
			bpl.s	.no
			st.b	SteamVentFLG
			clr.w	GolThrownVelX
			move.w	#11,GolThrownVelY
.no			rts


; - LOGIC ------------------------------------------------------------------

BreakWall_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			btst	#0,OB_Var1(a0)
			beq.s	.2
			lea	WallOverRANM,a1
			addq.w	#8,OB_Xpos(a0)
			bra	.3
.2			lea	WallOverLANM,a1
.3			subq.w	#1,OB_Xpos(a0)
			sub.w	#$20,OB_Ypos(a0)
			bset.b	#ob_setup,OB_Flag2(a0)
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
.1			lea	LevelWalls,a1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			tst.b	0(a1,d1.w)
			beq.s	.x
			
			move.w	d1,d4
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			add.w	#$8,d2
			move.w	d1,TempX
			move.w	d2,TempY
			moveq	#3,d3
			bsr	WallDebris
			
			SFX 	34

			jmp	HandleEnemyKilled
.x			rts


; - LOGIC ------------------------------------------------------------------

SkyLight_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			subq.w	#8,OB_Ypos(a0)
			add.w	#$37,OB_Xpos(a0)
			clr.b	OB_Var1a(a0)
			clr.b	OB_Var4(a0)
			lea	SkyLightANM,a1
			jmp	SetNewAnim
			
.1			tst.b	OB_Var4(a0)
			beq.s	.norm

.eye			tst.b	EyeRooftopSmashFLG
			beq.s	.x
			clr.b	EyeRooftopSmashFLG
			clr.b	OB_Var4(a0)
			bra	.smash

.norm			tst.b	OB_Var1a(a0)
			beq.s	.2
			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jmp	HandleEnemyKilled
.x			rts
.2			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelSkylights,a1
			tst.b	0(a1,d1.w)
			beq.s	.x
.smash			st.b	OB_Var1a(a0)
			lea	SkyLightBrokenANM,a1
			jsr	SetNewAnim
			SFX	49
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			add.w	#$10,d2
			move.w	d1,TempX
			move.w	d2,TempY
			moveq	#6,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			bra	SetRandomDebris
 			
; - LOGIC ------------------------------------------------------------------

BreakLignt_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			bne.s	.aaa
			addq.w	#3,OB_Xpos(a0)
.aaa			addq.w	#4,OB_Xpos(a0)
			clr.b	OB_Var2(a0)
			lea	BreakLightANM,a1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelLights,a2
			tst.b	0(a2,d1.w)
			beq.s	.a
			st.b	OB_Var2(a0)
			lea	BreakLightBrokenANM,a1
.a			jsr	SetNewAnim
			
.1			tst.b	OB_Var2(a0)
			bne.s	.x
			btst.b	#ob_hitting,OB_Flag1(a0)
			beq.s	.x
			st.b	OB_Var2(a0)
			bsr	SetSmallAirExplodeAtOB_XY
			sub.w	#$18,OB_Ypos(a1)
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelLights,a1
			st.b	0(a1,d1.w)
			lea	BreakLightBrokenANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
.x			rts


; - LOGIC ------------------------------------------------------------------

ThrowCrate_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.b	OB_Var1a(a0)
			lea	ThrowCrateANM,a1
			jmp	SetNewAnim
			
.1			tst.b	OB_Var1a(a0)
			beq.s	.a
			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jmp	HandleEnemyKilled
.x			rts

.a			btst.b	#ob_beinghit,OB_Flag1(a0)
			beq.s	.x
			st.b	OB_Var1a(a0)
			move.w	OB_Xpos(a0),TempX
			move.w	OB_Ypos(a0),TempY
			moveq	#5,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			bra	SetRandomDebris
			

; - LOGIC ------------------------------------------------------------------

BreakEdgeLeft_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelEdgesLeft,a1
			tst.b	0(a1,d1.w)
			beq.s	.aaa
			jmp	SwitchObjectOff
.aaa			bset.b	#ob_setup,OB_Flag2(a0)
			btst	#0,d1
			beq.s	.w2
			lea	BreakEdgeLeft1ANM,a1
			add.w	#$15,OB_Xpos(a0)
			sub.w	#5,OB_Ypos(a0)
			bra	.w1
.w2			lea	BreakEdgeLeft2ANM,a1
			add.w	#$d,OB_Xpos(a0)
			sub.w	#7,OB_Ypos(a0)
.w1			jsr	SetNewAnim
			jsr	ForceNewAnim
			clr.b	OB_Var1a(a0)

.1			tst.b	OB_Var1a(a0)
			beq.s	.a
			tst.l	OB_AnSequence(a0)
			bne.s	.x
			moveq	#4,d1
			bra	MoveGolDown_Smooth
.x			rts
.a			btst.b	#ob_hitting,OB_Flag1(a0)
			beq.s	.x
			st.b	OB_Var1a(a0)
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelEdgesLeft,a1
			st.b	0(a1,d1.w)
			btst	#0,d1
			bne.s	.w3
			lea	BreakEdgeLeft2BrkANM,a1
			bra	.w4
.w3			lea	BreakEdgeLeft1BrkANM,a1
.w4			jsr	SetNewAnim
			jmp	ForceNewAnim

			
; - LOGIC ------------------------------------------------------------------

BreakEdgeRight_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelEdgesRight,a1
			tst.b	0(a1,d1.w)
			beq.s	.aaa
			jmp	SwitchObjectOff
.aaa			bset.b	#ob_setup,OB_Flag2(a0)
			sub.w	#9,OB_Ypos(a0)
			btst	#0,d1
			beq.s	.w2
			lea	BreakEdgeRight1ANM,a1
			add.w	#16,OB_Xpos(a0)
			bra	.w1
.w2			lea	BreakEdgeRight2ANM,a1
			add.w	#5,OB_Xpos(a0)
.w1			jsr	SetNewAnim
			clr.b	OB_Var1a(a0)

.1			tst.b	OB_Var1a(a0)
			beq.s	.a
			tst.l	OB_AnSequence(a0)
			bne.s	.x
			moveq	#4,d1
			bra	MoveGolDown_Smooth
.x			rts
.a			btst.b	#ob_hitting,OB_Flag1(a0)
			beq.s	.x
			st.b	OB_Var1a(a0)
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelEdgesRight,a1
			st.b	0(a1,d1.w)
			btst	#0,d1
			bne.s	.w3
			lea	BreakEdgeRight2BrkANM,a1
			bra	.w4
.w3			lea	BreakEdgeRight1BrkANM,a1
.w4			jsr	SetNewAnim
			jmp	ForceNewAnim


; - LOGIC ------------------------------------------------------------------

Spark_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			jsr	Randy
			and.w	#$1f,d6
			or.w	#$20,d6
			move.b	d6,OB_Var1(a0)
			move.w	OB_Xspd(a0),d1
			lsr.w	#8,d1
			move.w	d1,OB_Var2(a0)
			lea	SparkANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.1			subq.b	#1,OB_Var1(a0)
			bne.s	.aaa
			jmp	SwitchObjectOff

.aaa			bsr	SubwayAccelerator
			bsr	MoveGolUpDown_Smooth
			move.w	OB_Var2(a0),d1
			bsr	MGLRa
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			beq.s	.x
			tst.w	OB_Yspd(a0)
			bne.s	.x
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)
			bclr.b	#ob_movydir,OB_MoveFlags(a0)
.x			rts


; - LOGIC ------------------------------------------------------------------

Spark2_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			move.w	OB_Xspd(a0),OB_Var2(a0)
			lea	MutVikHammerSparkANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.1			btst.b	#ob_hitting,OB_Flag1(a0)
			beq.s	.aa
			jmp	SwitchObjectOff
			
.aa			bsr	SubwayAccelerator
			bsr	MoveGolUpDown_Smooth
			move.w	OB_Var2(a0),d1
			lsr.w	#8,d1
			bsr	MGLRa
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			beq.s	.x
			tst.w	OB_Yspd(a0)
			bne.s	.x
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)
			bclr.b	#ob_movydir,OB_MoveFlags(a0)
.x			rts


; - LOGIC ------------------------------------------------------------------

Sparks_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			lea	SparksANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.1			tst.b	OB_Var4(a0)
			beq.s	.plrsldwall
			cmp.b	#1,OB_Var4(a0)
			beq.s	.rapsldflr
			cmp.b	#2,OB_Var4(a0)
			beq.s	.generic
			jmp	SwitchObjectOff

.generic		subq.b	#1,OB_Var2(a0)
			bne.s	.gx
			jmp	SwitchObjectOff
.gx			rts

.rapsldflr		move.l	OB_Var5(a0),a1
			move.w	OB_Xpos(a1),d1
			move.w	OB_Ypos(a1),d2
			btst.b	#ob_xflp,OB_Flag1(a1)
			beq.s	.2a
			add.w	#$18,d1
			bclr.b	#ob_xflp,OB_Flag1(a0)
			bra	.3a
.2a			sub.w	#$18,d1
			bset.b	#ob_xflp,OB_Flag1(a0)
.3a			subq.w	#6,d2
			move.w	d1,OB_Xpos(a0)
			move.w	d2,OB_Ypos(a0)
			tst.w	OB_Var1(a1)
			bne.s	.gx
			jmp	SwitchObjectOff

.plrsldwall		move.l	Plr_Database,a1
			move.w	OB_Xpos(a1),d1
			move.w	OB_Ypos(a1),d2
			btst.b	#ob_xflp,OB_Flag1(a1)
			bne.s	.2
			add.w	#$8,d1
			bset.b	#ob_xflp,OB_Flag1(a0)
			bra	.3
.2			sub.w	#$8,d1
			bclr.b	#ob_xflp,OB_Flag1(a0)
.3			sub.w	#$36,d2			
			move.w	d1,OB_Xpos(a0)
			move.w	d2,OB_Ypos(a0)
			
			cmp.w	#GolWallClimbSTATE,OB_State(a1)
			bne.s	.aa
			btst.b	#down,joy1
			beq.s	.aa
			rts
.aa			jmp	SwitchObjectOff


; - LOGIC ------------------------------------------------------------------

SetSparks2		move.l	OB_Interact2(a0),a1
			cmp.w	#RaptorBot_OB,OB_Type(a1)
			blt.s	.x
			cmp.w	#Xanatos_OB,OB_Type(a1)
			bgt.s	.x
			
			movem.l	a0/d0-d2,-(sp)
			SPAWN_HI	Sparks2_MAX_Size
			bmi.s	.1
			movem.l	(sp)+,a0/d0-d2
			rts
.1			move.l	a0,a1
			movem.l	(sp)+,a0/d0-d2
     			move.w	#Sparks2_OB,OB_Type(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			btst.b	#ob_xflp,OB_Flag1(a0)			
			beq.s	.a
			sub.w	d1,OB_Xpos(a1)
			add.w	d2,OB_Ypos(a1)
			bset.b	#ob_xflp,OB_Flag1(a1)
			rts
.a			add.w	d1,OB_Xpos(a1)
			add.w	d2,OB_Ypos(a1)
			bclr.b	#ob_xflp,OB_Flag1(a1)
.x			rts
		

Sparks2_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			lea	Sparks2ANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.1			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jmp	SwitchObjectOff
.x			rts


; - LOGIC ------------------------------------------------------------------

Fireball_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	#$20,OB_Var1(a0)
			move.w	OB_Xspd(a0),d1
			lsr.w	#8,d1
			move.w	d1,OB_Var2(a0)
			lea	FireBall1ANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.1			subq.b	#1,OB_Var1(a0)
			bne.s	.2
			jmp	SwitchObjectOff

.2			bsr	SubwayAccelerator
			bsr	MoveGolUpDown_Smooth
			move.w	OB_Var2(a0),d1
			bsr	MGLRa
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			beq.s	.x
			tst.w	OB_Yspd(a0)
			bne.s	.x
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)
			bclr.b	#ob_movydir,OB_MoveFlags(a0)
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί HOMING DIRECTIONAL PROJECTILE					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

max_hxs			equ	3
min_hxs			equ	-3
max_hys			equ	3
min_hys			equ	-3

SetupOrbHead		bsr	SetupHomingProj1
			bpl	FlagNOn
			clr.b	OB_Var3a(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)			
			move.b	#SteelHomerHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			lea	XanatosHomerHeadANM,a2
			jsr	SetNewAnimA1
			bra	FlagYESn


SetupOrbTail		bsr	SetupHomingProj1
			bpl	FlagNOn
			st.b	OB_Var3a(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)			
			lea	XanatosHomerTrailANM,a2
			jsr	SetNewAnimA1
			jsr	ForceNewAnimA1
			bra	FlagYESn


SetupHomingProj1	move.l	a0,-(sp)
			SPAWN_HI	HomingProj1_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#HomingProj1_OB,OB_Type(a1)				;object type
			bset.b	#ob_nooff,OB_Flag2(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.b	#$f0,OB_Var1(a1)
			move.b	#8,OB_Var3(a1)
			move.b	#max_hxs,OB_Var2(a1)
			clr.b	OB_Var2a(a1)
			bra	FlagYESn
.no			move.l	(sp)+,a0
			bra	FlagNOn
		

HomingProj1_Logic	tst.b	OB_Var3a(a0)
			beq.s	.head
			subq.w	#2,OB_Xpos(a0)
			tst.l	OB_AnSequence(a0)
			bne	.e
			jmp	SwitchObjectOff

.head			subq.b	#1,OB_Var1(a0)
			beq	ExplodeOBJECT

			subq.w	#1,OB_Xpos(a0)

			btst.b	#ob_hitting,OB_Flag1(a0)
			bne	ExplodeOBJECT
			
			addq.b	#1,OB_Var4(a0)
			and.b	#3,OB_Var4(a0)
			bne.s	.a1
			bsr	SetupOrbTail
			
.a1			addq.b	#1,OB_Var1a(a0)
			and.b	#$7,OB_Var1a(a0)
			bne	.a

			move.w	Plr_XPos,d2			;plrs x
			move.w	Plr_YPos,d3			; "   y
			sub.w	#$18,d3
			move.w	OB_Xpos(a0),d4			;projectiles x
			move.w	OB_Ypos(a0),d5			; "       "  y

.dx			cmp.w	d4,d2
			blt.s	.lft
.rte			cmp.b	#max_hxs,OB_Var2(a0)
			beq.s	.dy
			addq.b	#1,OB_Var2(a0)
			bra	.dy
.lft			cmp.b	#min_hxs,OB_Var2(a0)
			beq.s	.dy
			subq.b	#1,OB_Var2(a0)

.dy			cmp.w	d5,d3
			blt.s	.dn
.up			cmp.b	#max_hys,OB_Var2a(a0)
			beq.s	.a
			addq.b	#1,OB_Var2a(a0)
			bra	.a
.dn			cmp.b	#min_hys,OB_Var2a(a0)
			beq.s	.a
			subq.b	#1,OB_Var2a(a0)

.a			moveq	#0,d1
			move.b	OB_Var2(a0),d1
			bpl.s	.b
			neg.b	d1
			sub.w	d1,OB_Xpos(a0)
			bra	.c
.b			add.w	d1,OB_Xpos(a0)

.c			move.b	OB_Var2a(a0),d1
			bpl.s	.d
			neg.b	d1
			sub.w	d1,OB_Ypos(a0)
			rts
.d			add.w	d1,OB_Ypos(a0)
.e			rts

.fin			bra	ExplodeOBJECT


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί DROPPED TIMED MINE							   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SetupDropMine		move.l	a0,-(sp)
   			SPAWN_LO	FireballTrail_MAX_Size
			bmi.s	.1
			move.l	(sp)+,a0
			bra	FlagNOn
.1			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#DropMine_OB,OB_Type(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.b	#SteelMinesHitPOWER,OB_HitPower(a1)
			jsr	SetBigAttackA1	
			lea	XanatosMineANM,a2
			jsr	SetNewAnimA1
			jsr	ForceNewAnimA1
			move.w	#$0300,OB_Yspd(a1)
			move.w	#$50,OB_Yacc(a1)
			move.b	#%00110000,OB_MoveFlags(a1)
			SFX	9
			bra	FlagYESn


DropMine_Logic		tst.b	OB_Var1(a0)
			beq.s	.fall
			btst.b	#ob_hitting,OB_Flag1(a0)	
			bne.s	.w1
			subq.b	#1,OB_Var3(a0)
			bne	.x
.w1			KILL	9
			jsr	SetBigFlrExplodeAtOB_XY
			jmp	SwitchObjectOff

.fall			jsr	MoveGolUpDown
			
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			bne.s	.1
			jsr	GetXYpos
			jsr	GetUnderAddrs
			jsr	GetContour
			jsr	PullContourUnder
			beq.s	.n2			
			sub.w	#$180,OB_Yspd(a0)
			cmp.w	#$100,OB_Yspd(a0)
			bgt.s	.1a
			jsr	SetHeight
			st.b	OB_Var1(a0)
			move.b	#4*hz5060,OB_Var3(a0)
			rts
.1a			bset.b	#ob_movyacc,OB_MoveFlags(a0)
			bset.b	#ob_movydir,OB_MoveFlags(a0)
.n2			cmp.w	#$0600,OB_Yspd(a0)			;max speed
			blt.s	.x
			move.w	#$0600,OB_Yspd(a0)
			rts
.1			tst.w	OB_Yspd(a0)
			bne.s	.x
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)
			bclr.b	#ob_movydir,OB_MoveFlags(a0)
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί LASER (HORIZONTAL) 							   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

max_las			equ	8

SetupLaser		bsr	SetupHorzProj1
			bpl	FlagNOn
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)			
			move.b	#LaserHitPOWER,OB_HitPower(a1)
			move.w	#max_las,OB_Var1(a1)
			jsr	SetMediumAttackA1
;			lea	LaserANM,a2
;			bsr	SetNewAnimA1
			bra	FlagYESn

SetupHorzProj1		move.l	a0,-(sp)
			SPAWN_HI	HorzProj1_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#HorzProj1_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bra	FlagYESn
.no			move.l	(sp)+,a0
			bra	FlagNOn
		
HorzProj1_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			rts
			
.1			bsr	TestProjHitting
			bmi	ExplodeOBJECT
			move.w	OB_Var1(a0),d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
			bra	MoveGolLeft_Smooth
.r			bra	MoveGolRight_Smooth


SetupVertProj1		move.l	a0,-(sp)
			SPAWN_HI	VertProj1_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#VertProj1_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bra	FlagYESn
.no			move.l	(sp)+,a0
			bra	FlagNOn
		
VertProj1_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			rts
			
.1			bsr	TestProjHitting
			bmi	ExplodeOBJECT
			move.w	OB_Var1(a0),d1
			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.r
			bra	MoveGolUp_Smooth
.r			bra	MoveGolDown_Smooth


TestProjHitting		btst.b	#ob_hitting,OB_Flag1(a0)
			bne	FlagYESn
			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.1
			jsr	GetUnderFEET
			bra	.2
.1			jsr	GetUnderBOT
.2			jsr	TestLevelWalls
			bmi	FlagYESn
			bsr	PullContourUnder
			bne	FlagYESn
			bra	FlagNOn

			
ExplodeOBJECT		jsr	SwitchObjectOff
			bra	SetSmallAirExplodeAtOB_XY


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί Directional Projectile						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ


SetupDirectionalProj	bsr	SetupGenericProjectile
			bpl	FlagNOn
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)			
			move.b	#LaserHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			bra	FlagYESn


DirProj1_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	DirProjE1
			move.b	#4,OB_Var2(a0)
			bset.b	#ob_setup,OB_Flag2(a0)
			rts
			
DirProjE1		tst.b	OB_Var2(a0)			;delay detection
			beq.s	.ok
			subq.b	#1,OB_Var2(a0)
			bne.s	.1
.ok			bsr	TestProjHitting
			bmi	ExplodeOBJECT
			
.1			moveq	#0,d2
			move.b	OB_Var1(a0),d2
			asl.b	#2,d2
			move.w	DirProjXYadd(pc,d2.w),d1
			bpl.s	.r
.l			neg.w	d1
			bsr	MoveGolLeft_Smooth
			bra	.a
.r			bsr	MoveGolRight_Smooth

.a			move.w	DirProjXYadd+2(pc,d2.w),d1
			bpl.s	.d
.u			neg.w	d1
			bra	MoveGolUp_Smooth
.d			bra	MoveGolDown_Smooth


DirProj2_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	#LaserHitPOWER,OB_HitPower(a0)
			jmp	SetMediumAttack

.1			bra	DirProjE1


MaxXps			equ	6
MaxYps			equ	6

DirProjXYadd		dc.w	0,-MaxYps			;0
			dc.w	MaxXps/2,-MaxYps		;22.5
			dc.w	MaxXps,-MaxYps			;45
			dc.w	MaxXps,-MaxYps/2		;67.5			
			dc.w	MaxXps,0			;90
			dc.w	MaxXps,MaxYps/2			;112.5	
			dc.w	MaxXps,MaxYps			;135
			dc.w	MaxXps/2,MaxYps			;157.5
			dc.w	0,MaxYps			;180
			dc.w	-MaxXps/2,MaxYps		;202.5
			dc.w	-MaxXps,MaxYps			;225
			dc.w	-MaxXps,MaxYps/2		;247.5
			dc.w	-MaxXps,0			;270
			dc.w	-MaxXps,-MaxYps/2		;292.5
			dc.w	-MaxXps,-MaxYps			;315
			dc.w	-MaxXps/2,-MaxYps		;337.5


SetupGenericProjectile	movem.l	a0/d0-d1,-(sp)
			SPAWN_HI	DirProj1_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			movem.l	(sp)+,a0/d0-d1
			bset.b	#ob_tidy,OB_Flag5(a1)
			bra	FlagYESn
.no			movem.l	(sp)+,a0/d0-d1
			bra	FlagNOn
		

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί TITLEPAGE SCRQATCH MARKS						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Scratch_Logic		rts
;			btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
;			bne.s	.1
;			bset.b	#ob_setup,OB_Flag2(a0)			;initial setups
;			tst.b	OB_Var1(a0)
;			beq.s	.a
;			cmp.b	#1,OB_Var1(a0)
;			beq.s	.b
;			cmp.b	#2,OB_Var1(a0)
;			beq.s	.c
;.d			lea	Scratch4ANM,a1
;			bra	.f
;.c			lea	Scratch3ANM,a1
;			bra	.f
;.b			lea	Scratch2ANM,a1
;			bra	.f
;.a			lea	Scratch1ANM,a1
;.f			bra	SetNewAnim
;
;.1			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί ICON PICKUPS							   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

ICN_Continue		equ	0
ICN_Life		equ	1
ICN_FullHealth		equ	2
ICN_PartHealth		equ	3
ICN_Strength		equ	4
ICN_Invincible		equ	5

SetupDroppedIcon	movem.l	a0/d0-d1,-(sp)
			SPAWN_HI	Icon_MAX_Size
			bmi.s	.ok
			movem.l	(sp)+,a0/d0-d1
			bra	FlagNOn
.ok			move.l	a0,a1
			movem.l	(sp)+,a0/d0-d1
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.w	#Icon_OB,OB_Type(a1)				;object type
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.b	d1,OB_Var1(a1)
			move.w	#5,OB_Var3(a1)
			move.b	OB_Var7a(a0),OB_Var2(a1)			;how many to give
			st.b	OB_Var4(a1)
			clr.b	OB_Var4a(a1)
			bra	FlagYESn


IconAnmTab		dc.l	Icon1ANM,Icon2ANM,Icon3ANM,Icon4ANM,Icon5ANM,Icon6ANM	

Icon_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.b	OB_Var5(a0)
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			asl.b	#2,d1
			move.l	IconAnmTab(pc,d1.w),a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
.1			tst.b	OB_Var4(a0)
			beq.s	.x
			bpl.s	.norm
     			
			tst.b	OB_Var5(a0)
			beq.s	.o1

			btst.b	#ob_hitting,OB_Flag1(a0)
			bne.s	.pickup

.o1			addq.b	#1,OB_Var4a(a0)
			and.b	#3,OB_Var4a(a0)
			bne.s	.a
			subq.w	#1,OB_Var3(a0)
			bne.s	.a
			st.b	OB_Var5(a0)
.a			move.w	OB_Var3(a0),d1
			bsr	MoveGolUp_Smooth
			tst	d1
			bpl.s	.x
			jsr	GetUnderFEET
			bsr	SetHeight
			bmi.s	.b
			jsr	TestLevelFloors	
			bmi.s	.b
.x			rts
.b			eor.w	#-1,OB_Var3(a0)
			subq.w	#1,OB_Var3(a0)
			tst.w	OB_Var3(a0)
			bpl.s	.x
.fin			move.b	#1,OB_Var4(a0)
			bsr	SetHeight
			jmp	ClrHitStuff

.norm			btst.b	#ob_hitting,OB_Flag1(a0)
			beq.s	.x
.pickup			SFX	81
			move.l	Plr_Database,a1
			clr.b	OB_HitWait(a1)
			clr.b	OB_Var4(a0)
			moveq	#0,d1					;give attribute
			move.b	OB_Var1(a0),d1
			asl.b	#2,d1
			jsr	IconJmpTab(pc,d1.w)
			jmp	HandleEnemyKilled


IconJmpTab		bra	IconCONTINUE
			bra	IconLIFE
			bra	IconFULLHEALTH
			bra	IconPARTHEALTH
			bra	IconSTRENGTH
			bra	IconINVINCIBLE


IconCONTINUE		addq.b	#1,continues
			rts

IconLIFE		addq.b	#1,lives
			cmp.b	#GolMaxLives,lives
			ble.s	.ok
			move.b	#GolMaxLives,lives
.ok			st.b	UpdateLivesFLG
			rts

IconFULLHEALTH		move.w	#GolMaxNRG,PlrEnergy
			rts

IconPARTHEALTH		tst.b	difficulty
			bne.s	.normalhard
.easy			add.w	#GolMaxNRG/20,PlrEnergy
	   		bra	.dd
.normalhard		add.w	#GolMaxNRG/40,PlrEnergy
.dd			cmp.w	#GolMaxNRG,PlrEnergy
			ble.s	.ok
			move.w	#GolMaxNRG,PlrEnergy
.ok			rts

IconSTRENGTH		tst.w	GolStrongFLG
			bne.s	.x
			move.w	#$1ff,GolStrongFLG
			tst.b	MusicFLG
			beq.s	.x
			movem.l	a0/d0,-(sp)
			jsr	gemsstopall
			movem.l	(sp)+,a0/d0
			move.l	#-1,last_music
			move.l	#_MUS_Hammer,d0
			jmp	GoMusic
.x			rts

IconINVINCIBLE		move.w	#$1ff,GolInvincibleFLG
			rts








