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

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί SPIDER BOT CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	SpiBotTestSTATE
		StDEF	SpiBotSetHorzSTATE
		StDEF	SpiBotSetVertSTATE
		StDEF	SpiBotHorzSTATE
		StDEF	SpiBotVertSTATE
		StDEF	SpiBotTurnHSTATE
		StDEF	SpiBotTurnVSTATE
		StDEF	SpiBotTurnToHSTATE
		StDEF	SpiBotTurnToVSTATE
		StDEF	SpiBotTrans2WallSTATE
		StDEF	SpiBotTrans2FloorSTATE
		StDEF	SpiBotTrans2WallUpSTATE
		StDEF	SpiBotTrans2FloorUpSTATE
		StDEF	SpiBotFireHorzSTATE
		StDEF	SpiBotFireVertSTATE
		StDEF	SpiBotThrownSTATE
		StDEF	SpiBotThrownReleaseSTATE
		StDEF	SpiBotThrownFallSTATE
		StDEF	SpiBotThrownLandSTATE
		StDEF	SpiBotThrownRecoverSTATE
		StDEF	SpiBotSlammedSTATE
		StDEF	SpiBotFallSTATE


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

.y			btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			bsr	SetStartHeight
			
			cmp.w	#SpiBotSetHorzSTATE,OB_State(a0)
			bne.s	.2
			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.2
  			subq.w	#$8,OB_Ypos(a0)
.2			cmp.w	#SpiBotSetVertSTATE,OB_State(a0)
			bne.s	.3
			btst.b	#ob_xflp,OB_Flag1(a0)
			bne.s	.3
			add.w	#$10,OB_Xpos(a0)
.3			move.l	#SpiBotSetHits,OB_HitRoutine(a0)

.1			jsr	ObjectOffBottom
			bgt.s	.ob
			jmp	HandleEnemyKilled
.ob			jsr	HandleBeingHit				;Generic handle hit rout

			jsr	GetUnderFEET
			cmp.b	#SB_Grinder,d2
			beq	SpiBotSetAirExplode
			
			move.w	OB_State(a0),d1
			jmp	SpiBotLogicTable(pc,d1.w)		;jump table


SpiBotLogicTable	bra	SpiBotTestLOGIC
			bra	SpiBotSetHorzLOGIC
			bra	SpiBotSetVertLOGIC
			bra	SpiBotHorzLOGIC
			bra	SpiBotVertLOGIC
			bra	SpiBotTurnHorzLOGIC
			bra	SpiBotTurnVertLOGIC
			bra	SpiBotTurnToHorzLOGIC
			bra	SpiBotTurnToVertLOGIC
			bra	SpiBotTrans2WallLOGIC
			bra	SpiBotTrans2FloorLOGIC
			bra	SpiBotTrans2WallUpLOGIC
			bra	SpiBotTrans2FloorUpLOGIC
			bra	SpiBotFireHorzLOGIC
			bra	SpiBotFireVertLOGIC
			bra	SpiBotThrownLOGIC
			bra	SpiBotThrownReleaseLOGIC
			bra	SpiBotThrownFallLOGIC
			bra	SpiBotThrownLandLOGIC
			bra	SpiBotThrownRecovrLOGIC
			bra	SpiBotSlammedLOGIC
			bra	SpiBotFallLOGIC


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

SpiBotSetHits		move.b	OB_Flag6(a0),d2
			and.b	#%11000111,OB_Flag6(a0)
			jsr	ClrHitStuff

			btst.b	#ob_dead,OB_Flag2(a0)
			bne	SpiBotSetExplode

			tst.b	OB_Var6(a0)			;can't throw a vertical spider
			bne.s	.1
			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	SpiBotSetThrown

.1			btst	#ob_hit_small,d2
			bne	SpiBotSetExplode
			btst	#ob_hit_med,d2
			bne	SpiBotSetExplode
			btst	#ob_hit_big,d2
			bne	SpiBotSetExplode
			rts


SpiBotSetExplodeI	move.w	InteruptX,OB_Xpos(a0)	
			move.w	InteruptY,OB_Ypos(a0)	
			bra	SpiBotSetAirExplode
SpiBotSetExplode	cmp.w	#SpiBotHorzSTATE,OB_State(a0)
			beq.s	.hh
			cmp.w	#SpiBotTurnHSTATE,OB_State(a0)
			beq.s	.hh
			cmp.w	#SpiBotTurnToHSTATE,OB_State(a0)
			beq.s	.hh
			cmp.w	#SpiBotFireHorzSTATE,OB_State(a0)
			bne	SpiBotSetAirExplode
.hh			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	SpiBotSetFlrExplode
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
  			add.w	#$28,d2
			bra	SBSAE2
SpiBotSetAirExplode	move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
SBSAE2			bsr	SetBigAirExplode
			bmi.s	.1
			jmp	HandleEnemyKilled
.1			moveq	#2,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			bsr	SetRandomDebris
			jmp	HandleEnemyKilled
SpiBotSetFlrExplode	bsr	SetBigFlrExplodeAtOB_XY
			bmi.s	.1
			jmp	HandleEnemyKilled
.1			moveq	#3,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			bsr	SetRandomDebris
			jmp	HandleEnemyKilled
		

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

SpiBotSetThrown		move.w	#SpiBotThrownSTATE,OB_State(a0)
			;SFX	10
			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			bclr.b	#ob_yflp,OB_Flag1(a0)
			lea	SpiBotGrabbedANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


SpiBotThrownLOGIC	tst.b	GolThrowReleaseFLG
			bne	SpiBotSetThrownRelease
			tst.b	GolSlamFLG
			bne	SpiBotSetSlammed
			
			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)
			add.w	#8,OB_Ypos(a0)
.x			rts



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

SpiBotSetThrownRelease	move.w	#SpiBotThrownReleaseSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			move.w	#4,OB_Var2(a0)
			SFX	24
			lea	SpiBotThrownANM,a1			;set anim
			jsr	SetNewAnim

SpiBotThrownReleaseLOGIC	btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			jsr	GetUnder
			jsr	TestLevelWalls
			bmi	SpiBotSetAirExplode
			jsr	GetUnderLEFT
			jsr	TestLevelWalls
			bmi	SpiBotSetAirExplode
			jsr	GetUnderLEFTLEFT
			jsr	TestLevelWalls
			bmi	SpiBotSetAirExplode
			bra	.lr	
.r			jsr	GetUnder
			jsr	TestLevelWalls
			jsr	GetUnderRIGHT
			jsr	TestLevelWalls
			bmi	SpiBotSetAirExplode
			jsr	GetUnderRIGHTRIGHT
			jsr	TestLevelWalls
			bmi	SpiBotSetAirExplode
.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	SpiBotSetThrownFall
.3			move.w	OB_Var2(a0),d1				;get speed
			bra	MoveGolUp_Smooth			;move up


; - SpiderBot falls from thrown --------------------------------------------

SpiBotSetThrownFall	move.w	#SpiBotThrownFallSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			rts

SpiBotThrownFallLOGIC	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	SpiBotSetAirExplode
			
			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
			jsr	TestLand
			bmi	SpiBotSetThrownLand
			rts


; - SpiderBot lands from thrown --------------------------------------------

SpiBotSetThrownLand	move.w	#SpiBotThrownLandSTATE,OB_State(a0)
			move.w	#3,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			movem.l	a0/d0,-(sp)
			SPAWN_HI	Sparks_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,d0/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			movem.l	(sp)+,d0/a0
.2			;SFX 	1

SpiBotThrownLandLOGIC	move.w	OB_Var1(a0),d1				;x speed
			bne.s	.b
;  			jsr	Randy
;			and.w	#3,d6
;			beq	SpiBotSetExplode
			bra	SpiBotSetThrownRecover
.b			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
.aa			clr.w	OB_Var1(a0)
			bra	SpiBotSetExplode
.ok			jsr	HandleContours
			bpl.s	.aa
			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


; - SpiderBot Recovers after thrown ----------------------------------------

SpiBotSetThrownRecover	move.w	#SpiBotThrownRecoverSTATE,OB_State(a0)
			clr.b	OB_Var2(a0)
			lea	SpiBotThrownPRANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

SpiBotThrownRecovrLOGIC	tst.b	OB_Var2(a0)
			bne.s	.1
			tst.l	OB_AnSequence(a0)
			bne.s	.x
			st.b	OB_Var2(a0)
;			clr.b	RapBotThrownFLG
			jsr	ClrHitStuff
			lea	SpiBotThrownRecoverANM,a1
			jmp	SetNewAnim
.1			tst.l	OB_AnSequence(a0)
			beq	SpiBotSetHorzLOGIC
.x			rts


; - SpiderBot Slammed ------------------------------------------------------

SpiBotSetSlammed	move.w	#SpiBotSlammedSTATE,OB_State(a0)
;			;SFX	2
			clr.w	OB_Var1(a0)
			move.b	#4,OB_Var2(a0)
			lea	SpiBotSlammedANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
						
SpiBotSlammedLOGIC	tst.b	OB_Var1(a0)
			bne.s	.2

			bsr	WallInteruptThrow
			bmi	SpiBotSetExplodeI	
			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
			add.w	#8,OB_Ypos(a0)
			
			subq.b	#1,OB_Var2(a0)
			bne.s	.x
			jsr	GetUnderFEET
			bsr	PullContourUnder
			beq.s	.f1
			sub.w	#8,OB_Ypos(a0)
			jsr	Randy
			and.b	#1,d6
			beq	SpiBotSetThrownRecover
			st.b	OB_Var1(a0)
.x			rts
.f1			st.b	GolSlamOutFLG
			bra	SpiBotSetAirExplode
			
.2			addq.b	#1,OB_Var1a(a0)
			and.b	#$7,OB_Var1a(a0)
			bne	.o1

			move.w	OB_Xpos(a0),TempX
			move.w	OB_Ypos(a0),TempY
			bsr	SetupRandomStuff

.o1			tst.l	OB_AnSequence(a0)
			beq	SpiBotSetFlrExplode
			rts


WallInteruptThrow	move.l	Plr_Database,a6
			btst.b	#ob_xflp,OB_Flag1(a6)
			beq.s	.fr

.fl			move.b	UnderRIGHT,d2
			or.b	UnderRIGHTTOP,d2
			or.b	UnderRIGHTHEAD,d2
			bmi	.setr
			jsr	GetXYpos
			add.w	#$20,d1
			sub.w	#$30,d2
			jsr	GetUnderAddrs
			move.l	LevelFlr,a1		
			move.w	(a5),d1			
			lsr.w	#1,d1			
			move.b	2(a1,d1.w),d2
			add.w	map_wide,a5
			move.w	(a5),d1			
			lsr.w	#1,d1			
			or.b	2(a1,d1.w),d2
			add.w	map_wide,a5
			move.w	(a5),d1			
			lsr.w	#1,d1			
			or.b	2(a1,d1.w),d2
			bpl	FlagNOn
			bra	.setr

.fr			move.b	UnderLEFT,d2
			or.b	UnderLEFTBOT,d2
			or.b	UnderLEFTTOP,d2
			bmi.s	.setr
			jsr	GetXYpos
			sub.w	#$20,d1
			sub.w	#$30,d2
			jsr	GetUnderAddrs
			move.l	LevelFlr,a1		
			move.w	(a5),d1			
			lsr.w	#1,d1			
			move.b	2(a1,d1.w),d2
			add.w	map_wide,a5
			move.w	(a5),d1			
			lsr.w	#1,d1			
			or.b	2(a1,d1.w),d2
			add.w	map_wide,a5
			move.w	(a5),d1			
			lsr.w	#1,d1			
			or.b	2(a1,d1.w),d2
			bpl	FlagNOn

.setr			move.w	OB_Xpos(a6),d1
			move.w	d1,InteruptX
			move.w	OB_Ypos(a6),d1
			sub.w	#$28,d1
			move.w	d1,InteruptY
			bra	FlagYESn


GetInteruptXY		move.l	Plr_Database,a6
			btst.b	#ob_xflp,OB_Flag1(a6)
			beq.s	.fr
.fl			move.w	OB_Xpos(a6),d1
			add.w	#$18,d1
			bra	.setlr
.fr			move.w	OB_Xpos(a6),d1
			sub.w	#$18,d1
.setlr			move.w	d1,InteruptX
			move.w	OB_Ypos(a6),d1
			sub.w	#$20,d1
			move.w	d1,InteruptY
			rts
 
			
; - Testbed ----------------------------------------------------------------

SpiBotTestLOGIC		rts


; - SpiderBot transition to floor/ceiling up (edges) ------------------

SpiBotSetTrans2FloorUp	move.w	#SpiBotTrans2FloorUpSTATE,OB_State(a0)
			jsr	SnapXY
			lea	SpiBotTrans2FloorUpANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

SpiBotTrans2FloorUpLOGIC
			tst.l	OB_AnSequence(a0)
			bne.s	.x
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			sub.w	#$28,OB_Xpos(a0)
			bra	.lr
.r			add.w	#$28,OB_Xpos(a0)
.lr			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.1
			add.w	#$20,OB_Ypos(a0)
			bra	.2
.1			sub.w	#$20,OB_Ypos(a0)
.2			bra.s	SpiBotSetHorzLOGIC
.x			rts


; - SpiderBot transition to floor ------------------------------------

SpiBotSetTrans2Floor	move.w	#SpiBotTrans2FloorSTATE,OB_State(a0)
			jsr	SnapXY
			eor.b	#_ob_yflp,OB_Flag1(a0)
			lea	SpiBotTrans2FloorANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

SpiBotTrans2FloorLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.x
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			add.w	#$20,OB_Xpos(a0)
			bra	.lr
.r			sub.w	#$20,OB_Xpos(a0)
.lr			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.1
			sub.w	#$20,OB_Ypos(a0)
			bra	.2
.1			add.w	#$20,OB_Ypos(a0)
.2			eor.b	#_ob_xflp,OB_Flag1(a0)
			bra.s	SpiBotSetHorzLOGIC
.x			rts


; - SpiderBot on floor/ceiling ---------------------------------------------

SpiBotSetHorzLOGIC	move.w	#SpiBotHorzSTATE,OB_State(a0)
SpiBotSFTH1		clr.b	OB_Var6(a0)
			jsr	Randy
			and.w	#$1f,d6
			or.w	#$20,d6
			move.b	d6,OB_Var2(a0)
			lea	SpiBotWalkHorzANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

SpiBotHorzLOGIC		jsr	CheckScreenBoundsX			;turn at screen bounds	
			bmi	SpiBotSetTurnHorz
			
			move.w	Plr_YPos,d1				;simple line 'o sight
			sub.w	OB_Ypos(a0),d1				;doesn't account for walls
			bpl.s	.a
			neg.w	d1
.a			cmp.w	#$30,d1
			bgt.s	.n1
			move.w	Plr_XPos,d1
			sub.w	OB_Xpos(a0),d1
			bpl.s	.b
			neg.w	d1
.b			cmp.w	#$30,d1
			blt.s	.n1
			jsr	Randy
			and.w	#$f,d6
			beq	SpiBotSetFireHorz			;fire fire fire

.n1			tst.b	OB_Var2(a0)				;delay face plr check
			beq.s	.ok					;so robot walk past plr
			sub.b	#1,OB_Var2(a0)
			bra	.skp1

.ok			bsr	DoesNmeFacePlayer			;make robot face plr
			bpl	SpBSTTH1
			
.skp1			btst.b	#ob_xflp,OB_Flag1(a0)
			bne	.l

.r			moveq	#2,d1				
			bsr	MoveGolRight_NF_Smooth
			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.floor_r
.ceil_r			jsr	GetUnderRIGHTFEET			;pull under
			cmp.b	#SB_Climb,d2				;not a climbable		
			beq	SpiBotSetTrans2Wall			;then transition to wall
			cmp.b	#SB_ClimbR,d2				
			beq	SpiBotSetTrans2Wall			
			cmp.b	#SB_ForceTurn,d2
			beq	SpiBotSetTurnHorz
			jsr	TestLevelWalls				;turn at walls
			bmi	SpiBotSetTurnHorz
			jsr	GetUnderRIGHTBOT			;transition to wall up (over edge)
			cmp.b	#SB_CeilingClimb,d2
			bne	SpiBotSetTrans2WallUp			
			rts
.floor_r		jsr	GetUnderRIGHTBOT			;pull under
			cmp.b	#SB_Climb,d2				;not a climbable
			beq	SpiBotSetTrans2Wall			;then transition to wall
			cmp.b	#SB_ClimbR,d2				
			beq	SpiBotSetTrans2Wall			
			cmp.b	#SB_ForceTurn,d2 			;turn tiles?
			beq	SpiBotSetTurnHorz
			jsr	TestLevelWalls				;turn at walls
			bmi	SpiBotSetTurnHorz			
			jsr	GetUnderRIGHTFEET			;transition to wall down (over edge)
			cmp.b	#SB_ClimbL2StandL,d2
			beq	SpiBotSetTrans2WallUp			
			jsr	HandleContours				;do contouring
			bpl	SpiBotSetFall				;fall if no contour
			rts

.l			moveq	#2,d1					
			bsr	MoveGolLeft_NF_Smooth			
			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.floor_l
.ceil_l			jsr	GetUnderLEFTFEET			;pull under
			cmp.b	#SB_Climb,d2				;not a climbable		
			beq	SpiBotSetTrans2Wall			;then transition to wall
			cmp.b	#SB_ClimbL,d2				
			beq	SpiBotSetTrans2Wall			
			cmp.b	#SB_ForceTurn,d2
			beq	SpiBotSetTurnHorz
			jsr	TestLevelWalls				;turn at walls
			bmi	SpiBotSetTurnHorz
			jsr	GetUnderRIGHTBOT			;transition to wall up (over edge)
			cmp.b	#SB_CeilingClimb,d2
			bne	SpiBotSetTrans2WallUp			
			rts
.floor_l		jsr	GetUnderLEFTBOT				;pull under
			cmp.b	#SB_Climb,d2				;not a climbable
			beq	SpiBotSetTrans2Wall			;then transition to wall
			cmp.b	#SB_ClimbL,d2				
			beq	SpiBotSetTrans2Wall			
			cmp.b	#SB_ForceTurn,d2 			;turn tiles?
			beq	SpiBotSetTurnHorz
			jsr	TestLevelWalls				;turn at walls
			bmi	SpiBotSetTurnHorz			
			jsr	GetUnderLEFTFEET			;transition to wall down (over edge)
			cmp.b	#SB_ClimbR2StandR,d2
			beq	SpiBotSetTrans2WallUp			
			jsr	HandleContours				;do contouring
			bpl	SpiBotSetFall				;fall if no contour
			rts


; - SpiderBot falls when no contour -----------------------------------------

SpiBotSetFall		move.w	#SpiBotFallSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			rts

SpiBotFallLOGIC		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
			jsr	TestLand
			bmi	SpiBotSetHorzLOGIC
			rts


; - SpiderBot Turn Horizontal Logic ----------------------------------------

SpiBotSetTurnHorz	move.w	#SpiBotTurnHSTATE,OB_State(a0)
			lea	SpiBotTurnHorzANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

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

     				
; - SpiderBot Turn Vertical Logic ------------------------------------------

SpiBotSetTurnVert	move.w	#SpiBotTurnVSTATE,OB_State(a0)
			lea	SpiBotTurnVertANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

SpiBotTurnVertLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.1
			eor.b	#_ob_yflp,OB_Flag1(a0)
			bra	SpiBotSetVertLOGIC
.1			rts

     				
; - SpiderBot Turn to Face Player Horizontal Logic --------------------------

SpBSTTH2		PUSHADDRS SpiBotSFTH2
			bra	SpiBotSetTurnToHorz
SpBSTTH1		PUSHADDRS SpiBotSFTH1

SpiBotSetTurnToHorz	PUSHSTATE
			move.w	#SpiBotTurnToHSTATE,OB_State(a0)
			lea	SpiBotTurnHorzANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

SpiBotTurnToHorzLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.1
			eor.b	#_ob_xflp,OB_Flag1(a0)
			POPSTATE
			POPADDRS
			jmp	(a1)
.1			rts

     				
; - SpiderBot Turn to Face Player Vertical Logic --------------------------

SpBSTTV2		PUSHADDRS SpiBotSFTV2
		   	bra	SpiBotSetTurnToVert
SpBSTTV1		PUSHADDRS SpiBotSFTV1

SpiBotSetTurnToVert	PUSHSTATE
			move.w	#SpiBotTurnToVSTATE,OB_State(a0)
			lea	SpiBotTurnVertANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

SpiBotTurnToVertLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.1
			eor.b	#_ob_yflp,OB_Flag1(a0)
			POPSTATE
			POPADDRS
			jmp	(a1)
.1			rts


; - SpiderBot transition to wall up/down (over edge) ---------------------------

SpiBotSetTrans2WallUp	move.w	#SpiBotTrans2WallUpSTATE,OB_State(a0)
			jsr	SnapXY
			lea	SpiBotTrans2WallUpANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

SpiBotTrans2WallUpLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.x
			eor.b	#_ob_xflp!_ob_yflp,OB_Flag1(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			add.w	#$20,OB_Xpos(a0)
			bra	.lr
.r			sub.w	#$20,OB_Xpos(a0)

.lr			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.1
  			add.w	#$28,OB_Ypos(a0)
			bra	.2
.1			sub.w	#$28,OB_Ypos(a0)

.2			bra.s	SpiBotSetVertLOGIC
.x			rts


; - SpiderBot transition to wall ------------------------------------

SpiBotSetTrans2Wall	move.w	#SpiBotTrans2WallSTATE,OB_State(a0)
			jsr	SnapXY
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.1
 			add.w	#$10,OB_Xpos(a0)
.1			lea	SpiBotTrans2WallANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

SpiBotTrans2WallLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.x
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			sub.w	#$10,OB_Xpos(a0)
			bra	.lr
.r			add.w	#$10,OB_Xpos(a0)
.lr			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.1
			add.w	#$28,OB_Ypos(a0)
			bra	.2
.1			sub.w	#$20,OB_Ypos(a0)
.2			bra.s	SpiBotSetVertLOGIC
.x			rts


; - SpiderBot on wall ------------------------------------------------------

SpiBotSetVertLOGIC	move.w	#SpiBotVertSTATE,OB_State(a0)

SpiBotSFTV1		st.b	OB_Var6(a0)
			jsr	Randy
			and.w	#$1f,d6
			or.w	#$10,d6
			move.b	d6,OB_Var2(a0)
			jsr	GetUnderNME
			lea	SpiBotWalkVertANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

SpiBotVertLOGIC		jsr	CheckScreenBoundsY		;turn at screen bounds	
			bmi	SpiBotSetTurnVert
			
			move.w	Plr_XPos,d1			;simple line 'o sight
			sub.w	OB_Xpos(a0),d1			;doesn't account for walls
			bpl.s	.a
			neg.w	d1
.a			cmp.w	#$20,d1
			bgt.s	.n1
			jsr	Randy
			and.w	#$3f,d6
			beq	SpiBotSetFireVert		;fire fire fire

.n1			tst.b	OB_Var2(a0)			;delay face plr check
			beq.s	.ok				;so robot walk past plr
			sub.b	#1,OB_Var2(a0)
			bra	.skp1
								
.ok			bsr	DoesNmeFacePlayerY		;make robot face plr
			bpl	SpBSTTV1			
								
.skp1			btst.b	#ob_yflp,OB_Flag1(a0)
			beq	.u

.d			moveq	#2,d1				;move ob down
			bsr	MoveGolDown_Smooth
			bset.b	#ob_yflp,OB_Flag1(a0)		;set flip	
			
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.2
			jsr	GetXYpos			;get under
			sub.w	#$20,d1
			add.w	#$10,d2
			jsr	GetFlrData
			cmp.b	#SB_CeilingClimb,d2		;is there a ceiling to the left?
			beq	SpiBotSetTrans2FloorUp		;yes: trans to ceiling 
			jsr	GetXYpos
			add.w	#$2c,d2
			jsr	GetFlrData
			cmp.b	#SB_ForceTurn,d2
			beq	SpiBotSetTurnVert
			jsr	GetXYpos
			sub.w	#$10,d1
			add.w	#$28,d2
			jsr	GetFlrData
			cmp.b	#SB_ClimbL,d2
			bne	SpiBotSetTrans2Floor		;and trans to floor
			rts	    
.2			jsr	GetXYpos			;get under			
			add.w	#$10,d1
			add.w	#$10,d2
			jsr	GetFlrData
			cmp.b	#SB_CeilingClimb,d2		;is there a ceiling to the right?
			beq	SpiBotSetTrans2FloorUp		;yes: trans to ceiling 
			jsr	GetXYpos
			sub.w	#$10,d1
			add.w	#$2c,d2
			jsr	GetFlrData
			cmp.b	#SB_ForceTurn,d2
			beq	SpiBotSetTurnVert
			jsr	GetXYpos
			add.w	#$28,d2
			jsr	GetFlrData
			cmp.b	#SB_ClimbR,d2
			bne	SpiBotSetTrans2Floor		;and trans to floor
.dx			rts

.u			moveq	#2,d1
			bsr	MoveGolUp_Smooth
			bclr.b	#ob_yflp,OB_Flag1(a0)
			
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.1
			jsr	GetUnderBOT
			cmp.b	#SB_ForceTurn,d2
			beq	SpiBotSetTurnVert
			jsr	GetUnderLEFT
			cmp.b	#SB_ClimbL2StandL,d2
			beq	SpiBotSetTrans2FloorUp
			jsr	GetUnderLEFTTOP
			cmp.b	#SB_CeilingClimb,d2
			beq	SpiBotSetTrans2Floor
			rts	      
.1			jsr	GetUnderLEFT;TOP
			cmp.b	#SB_ForceTurn,d2
			beq	SpiBotSetTurnVert
			jsr	GetUnderTOP
			cmp.b	#SB_ClimbR2StandR,d2
			beq	SpiBotSetTrans2FloorUp
			cmp.b	#SB_CeilingClimb,d2
			beq	SpiBotSetTrans2Floor
			rts


; - SpiderBot Fire Horizontally ----------------------------------

SpiBotSetFireHorz	move.w	#SpiBotFireHorzSTATE,OB_State(a0)
			bsr	DoesNmeFacePlayer
			bpl	SpBSTTH2
SpiBotSFTH2		clr.b	OB_EventVar1(a0)
			lea	SpiBotFireHorzANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

SpiBotFireHorzLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.1
			clr.b	OB_EventVar1(a0)

			bsr	SetupHorzProj1
			bpl.s	.1
			SFX	110
			jsr	SetFlipFromMother
			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	.r
.l			sub.w	#$20,OB_Xpos(a1)
			bra	.lr
.r			add.w	#$20,OB_Xpos(a1)
.lr			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.u
.d			add.w	#$a,OB_Ypos(a1)
			bra	.ud
.u			sub.w	#8,OB_Ypos(a1)
.ud			move.b	#LaserHitPOWER,OB_HitPower(a1)
			move.w	#max_las-2,OB_Var1(a1)
			jsr	SetMediumAttackA1
			lea	SpiBotHorzProjANM,a2
			jsr	SetNewAnimA1
			
.1			tst.l	OB_AnSequence(a0)
			beq	SpiBotSetHorzLOGIC
			rts


; - SpiderBot Fire Vertically ----------------------------------

SpiBotSetFireVert	move.w	#SpiBotFireVertSTATE,OB_State(a0)
			bsr	DoesNmeFacePlayerY
			bpl	SpBSTTV2
SpiBotSFTV2		lea	SpiBotFireVertANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

SpiBotFireVertLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.1
			clr.b	OB_EventVar1(a0)
			
			bsr	SetupVertProj1
			bpl.s	.1
			SFX	110
			jsr	SetFlipFromMother
			eor.b	#_ob_yflp,OB_Flag1(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)			
			btst.b	#ob_yflp,OB_Flag1(a0)
			bne.s	.u
.d			sub.w	#$20,OB_Ypos(a1)
			bra	.ud
.u			add.w	#$20,OB_Ypos(a1)
.ud			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			add.w	#$c,OB_Xpos(a1)
			bra	.lr
.r			sub.w	#$c,OB_Xpos(a1)
.lr			move.b	#LaserHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			move.w	#max_las-2,OB_Var1(a1)
			lea	SpiBotVertProjANM,a2
			jsr	SetNewAnimA1
			
.1			tst.l	OB_AnSequence(a0)
			beq	SpiBotSetVertLOGIC
			rts
			


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT SPIDER BOSS CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	MutSpiBotGoSTATE
		StDEF	MutSpiBotStartupSTATE
		StDEF	MutSpiBotMutateSTATE
		StDEF	MutSpiBotZeroSTATE


MutantSpider_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.b	MutSpiBotPHASE
			sub.w	#$40,OB_Xpos(a0)
			subq.w	#8,OB_Ypos(a0)
			move.b	#$52/2,OB_Var2(a0)
			move.w	#MutSpiBotGoSTATE,OB_State(a0)
			lea	SpiBotWalkHorzANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
.ok			tst.b	EyeDeadFLG
			beq.s	.1ad
  			jmp	SwitchObjectOff

.1ad			move.w	OB_State(a0),d1
			jmp	MutSpiBotLogicTable(pc,d1.w)		;jump table

MutSpiBotLogicTable	bra	MutSpiBotGoLOGIC
			bra	MutSpiBotStartupLOGIC
			bra	MutSpiBotMutateLOGIC
			bra	MutSpiBotZeroLOGIC


; - Mutant Spiderbot BOSS Walk to center ---------------------------------

MutSpiBotGoLOGIC	tst.b	faded_flg
			beq.s	.x
			subq.b	#1,OB_Var2(a0)
			beq.s	MutSpiBotSetStartup
			addq.w	#2,OB_Xpos(a0)
.x			rts


; - Mutant Spiderbot BOSS Startup ----------------------------------------

MutSpiBotSetStartup	move.w	#MutSpiBotStartupSTATE,OB_State(a0)
			lea	SpiBotIdleANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim
			bsr	SpawnEyeOfOdin
			move.l	#-1,OB_HitRoutine(a1)
			move.w	#EyeOfOdinBoss2STATE,OB_State(a1)
			rts
			
MutSpiBotStartupLOGIC	tst.b	EyeFinishedFLG
			beq.s	.x
			clr.b	EyeFinishedFLG

			SFX	8

			bsr	MutSpiBotSetMutate
			jsr	WhitePalette
			
			move.b	#3,cyc_num			;switch on color cycling
					
			lea	ElevFXPal,a1			;set new palettes
			jsr	SetSinglePalette
			lea	Car2Pal,a1
			jsr	SetSinglePalette

			moveq	#$3,d1
			lea	GamePalette,a1
			move.w	#def_blkwhtin,d2
			jsr	set_whitein	
			move.l	#Lev34MapAb,__MapA
			bra	DownloadScrlA
.x			rts


; - Mutant Spider mutate Logic -----------------------------------------------

MutSpiBotSetMutate	movem.l	a0/d0,-(sp)
			SPAWN_LO	EyeOfOdin_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,a0/d0
			bsr	SEoO2
			move.w	#EyeOfOdinBoss2aSTATE,OB_State(a1)
			st.b	PlayingBOSS
			clr.b	BossDefeatedFLG
			move.l	a1,Boss_Database			;boss' database
			move.w	#RooftopBOSS_NRG,OB_Nrg(a1)
			move.w	OB_Nrg(a1),d1
			move.w	d1,BossEnergy
			lsr.w	#5,d1
			move.w	d1,BossPercentile
			st.b	BossFirstPass
			move.l	#EyeOfOdinSetHit,OB_HitRoutine(a1)
			subq.w	#8,OB_Xpos(a1)
			sub.w	#$15,OB_Ypos(a1)
			move.w	OB_Xpos(a1),OB_WXpos(a1)
			bra	.2
.1			movem.l	(sp)+,a0/d0

.2			bsr	SpawnMutSpiLegs
			move.w	#24,OB_Nrg(a1)
			clr.b	OB_Var1(a1)
			add.w	#$6c,OB_Xpos(a1)
			sub.w	#$35,OB_Ypos(a1)
			move.w	OB_Xpos(a1),OB_WXpos(a1)
			lea	MutSpiHorzLegANM,a2
			jsr	SetNewAnimA1
			jsr	ForceNewAnimA1
			
			bsr	SpawnMutSpiLegs
			move.w	#48,OB_Nrg(a1)
			st.b	OB_Var1(a1)
			add.w	#$47,OB_Xpos(a1)
			sub.w	#$61,OB_Ypos(a1)
			move.w	OB_Xpos(a1),OB_WXpos(a1)
			lea	MutSpiVertLegANM,a2
			jsr	SetNewAnimA1
			jsr	ForceNewAnimA1
			
			bsr	SpawnMutSpiLegs
			move.w	#24,OB_Nrg(a1)
			clr.b	OB_Var1(a1)
			sub.w	#$6c,OB_Xpos(a1)
			sub.w	#$35,OB_Ypos(a1)
			bset.b	#ob_xflp,OB_Flag1(a1)
			move.w	OB_Xpos(a1),OB_WXpos(a1)
			lea	MutSpiHorzLegANM,a2
			jsr	SetNewAnimA1
			jsr	ForceNewAnimA1
			
			bsr	SpawnMutSpiLegs
			move.w	#48,OB_Nrg(a1)
			st.b	OB_Var1(a1)
			sub.w	#$47,OB_Xpos(a1)
			sub.w	#$61,OB_Ypos(a1)
			bset.b	#ob_xflp,OB_Flag1(a1)
			move.w	OB_Xpos(a1),OB_WXpos(a1)
			lea	MutSpiVertLegANM,a2
			jsr	SetNewAnimA1
			jsr	ForceNewAnimA1

			bsr	SpawnMutSpiHead
			
			bset.b	#ob_tidy,OB_Flag5(a0)
			bra	MutSpiBotSetZero


MutSpiBotMutateLOGIC	rts
				
; - Mutant Spider Zero Logic -----------------------------------------------

MutSpiBotSetZero	move.w	#MutSpiBotZeroSTATE,OB_State(a0)
						
MutSpiBotZeroLOGIC	cmp.b	#4,MutSpiBotPHASE
			beq.s	MSBmain

			bsr	MSBmain

.x    			rts

MSBmain			tst.b	HeadFlameFLG
			bne.s	.x
			tst.b	MutSpiWorkingFLG
			bne.s	.x
			move.l	Plr_Database,a1
			btst.b	#grndmode,OB_MasterMode(a1)
			bne.s	.flrceil
			btst.b	#wallmode,OB_MasterMode(a1)
			bne.s	.wall
			btst.b	#ceilmode,OB_MasterMode(a1)
			bne.s	.flrceil
.x			rts
.flrceil		move.w	#$20,d1
			jsr	TestProxY
			bmi.s	.other
			jsr	Randy
			and.w	#$3f,d6
			beq	MutSpiSetElecVert
			rts
.wall			jsr	Randy
			and.w	#$3f,d6
			beq	MutSpiSetElecHorz
			rts

.other			cmp.b	#3,EyeHitCNT			;flame thrower after eye hit 3 times
			bne.s	.a
			clr.b	EyeHitCNT
			bra	SetupMutSpiFlameThrow

.a			tst.b	EyeHitFLG
			beq.s	.1
			subq.b	#1,EyeHitFLG
			bne.s	.x
;			jsr	Randy
;			and.w	#1,d6
;			beq	SetupMutSpiProjHead
			bra	SetupMutSpiProjSwirl
.1			jsr	Randy
			and.w	#$1ff,d6
;			beq	SetupMutSpiProjHead
;			cmp.w	#1,d6
			beq	SetupMutSpiProjSwirl
			cmp.w	#1,d6
			beq	SetupMutSpiFlameThrow
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT SPIDER BOSS LEGS CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	MutSpiLegsZeroSTATE
		StDEF	MutSpiLegsHitSTATE

			
SpawnMutSpiLegs		movem.l	a0/d0,-(sp)
			SPAWN_LO	MutSpiLegs_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#MutSpiLegs_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.l	#MutSpiLegSetHits,OB_HitRoutine(a1)
			move.b	#MutSpiLegsHitPOWER,OB_HitPower(a1)
			jsr	SetBigAttackA1
			rts
.1			movem.l	(sp)+,d0/a0
			rts


MutSpiLegs_Logic	tst.b	EyeDeadFLG
			beq.s	.1ad
  			jmp	SwitchObjectOff

.1ad			jsr	HandleBeingHit				;Generic handle hit rout

			move.w	OB_State(a0),d1
			jmp	MutSpiLegsLogicTable(pc,d1.w)		;jump table

MutSpiLegsLogicTable	bra	MutSpiLegsZeroLOGIC
			bra	MutSpiLegsHitLOGIC


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

MutSpiLegsZeroLOGIC	tst.b	OB_Var1(a0)
			bne.s	.vert

.horz			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jsr	Randy
			and.w	#$1f,d6
			bne.s	.x
			move.w	#$30,d1
			jsr	TestProxX
			bpl.s	.x
 			move.w	#$50,d1
			jsr	TestProxY
			bpl.s	.x
			SFX	56
			lea	MutSpiHorzLegAttkANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.x			rts

.vert			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jsr	Randy
			and.w	#$1f,d6
			bne.s	.x
			move.w	#$40,d1
			jsr	TestProxX
			bpl.s	.x
 			move.w	#$20,d1
			jsr	TestProxY
			bpl.s	.x
			SFX	56
			lea	MutSpiVertLegAttkANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim


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

MutSpiLegSetHits	btst.b	#ob_dead,OB_Flag2(a0)
			bne.s	.2
			jsr	ClrHitStuff
			bsr	RobotRandomHitSFX
			clr.w	OB_Var5(a0)
			move.b	#$18,OB_HitWait(a0)
			move.w	#MutSpiLegsHitSTATE,OB_State(a0)
.x			rts

.2			sub.w	#$20,BossEnergy

			SFX	95

			move.w	OB_Xpos(a0),d4
			move.w	OB_Ypos(a0),d5
			
			tst.b	OB_Var1(a0)
			bne	.v

.h			add.w	#8,d5
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r1
			bsr	SetSmallAirExplode			
			add.w	#8,d4
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			sub.w	#$a,d4
			sub.w	#8,d5		
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			sub.w	#$a,d4
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			sub.w	#$a,d4
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			sub.w	#$a,d4
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			sub.w	#$a,d4
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			bra	.o2

.r1			bsr	SetSmallAirExplode			
			sub.w	#8,d4
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			add.w	#$a,d4
			sub.w	#8,d5		
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			add.w	#$a,d4
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			add.w	#$a,d4
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			add.w	#$a,d4
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			add.w	#$a,d4
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			bra	.o2

.v			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
			bsr	SetSmallAirExplode			
			add.w	#4,d4
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			sub.w	#8,d4		
			bra	.o1
.r			bsr	SetSmallAirExplode			
			sub.w	#4,d4
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			add.w	#8,d4		
.o1			sub.w	#$a,d5
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			sub.w	#$a,d5
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			sub.w	#$a,d5
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			sub.w	#$a,d5
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)
			sub.w	#$a,d5
			bsr	SetSmallAirExplode			
			move.w	d4,OB_Xpos(a1)
			move.w	d5,OB_Ypos(a1)

.o2			jsr	SwitchObjectOff

			addq.b	#1,MutSpiLegsDeadCNT
			cmp.b	#4,MutSpiLegsDeadCNT
			bne	.x
			    
			SFX	12
			
			move.b	#4,MutSpiBotPHASE			;next phase
			
			lea	AMAP_LIFT0_START,a2
			jsr	SetupCharAnim
			
			move.b	#1,BFX_Var1				;flag scroll speedup
			move.l	#Lev34MapAc,__MapA
			bsr	DownloadScrlA
			move.w	#$100,d1
			move.w	#$70,d2
			bsr	SetBigAirExplode
			bpl	.x
			moveq	#3,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			bra	SetRandomDebris


MutSpiLegsHitLOGIC	lea	EyeHitWobbleTab,a1
			moveq	#0,d1
			move.b	OB_Var5(a0),d1
			addq.b	#2,OB_Var5(a0)
			lea	EyeHitWobbleTab,a1
			move.w	0(a1,d1.w),d1
			bpl.s	.1
			neg.w	d1
			sub.w	d1,OB_Xpos(a0)
			rts
.1			cmp.w	#$80,d1
			beq.s	.fin
			add.w	d1,OB_Xpos(a0)
			rts
.fin			move.w	OB_WXpos(a0),OB_Xpos(a0)
			move.w	#MutSpiLegsZeroSTATE,OB_State(a0)
			rts
			

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT SPIDER BOSS HEAD CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	MutSpiHeadIdleSTATE

SpawnMutSpiHead		movem.l	a0/d0,-(sp)
			SPAWN_LO	MutSpiHead_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#MutSpiHead_OB,OB_Type(a1)
			move.w	#MutSpiHeadIdleSTATE,OB_State(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			sub.w	#$58,OB_Ypos(a1)
			lea	MutSpiHead1ANM,a2
			jmp	SetNewAnimA1
.1			movem.l	(sp)+,d0/a0
			rts

MutSpiHead_Logic	tst.b	EyeDeadFLG
			beq.s	.1ad
  			jmp	SwitchObjectOff

.1ad			move.w	OB_State(a0),d1
			jmp	MutSpiHeadLogicTable(pc,d1.w)		;jump table

MutSpiHeadLogicTable	bra	MutSpiHeadIdleLOGIC



MutSpiHeadIdleLOGIC	cmp.b	#1,OB_Var1(a0)
			beq.s	.flame
			cmp.b	#2,OB_Var1(a0)
			beq.s	.look
			
			tst.b	HeadFlameFLG
			beq.s	.idle
			move.b	#1,OB_Var1(a0)
			move.b	#-1,OB_EventVar1(a0)
  			bclr.b	#ob_xflp,OB_Flag1(a0)
			lea	MutSpiHeadSweepANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.idle			jsr	Randy
			and.b	#$7f,d6
			bne.s	.x
			move.b	#2,OB_Var1(a0)
			jsr	MakeNmeFacePlayer
			lea	MutSpiHeadLookANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.look			tst.l	OB_AnSequence(a0)
			beq.s	.fin2
			rts

.flame			tst.l	OB_AnSequence(a0)
			beq.s	.fin

			move.b	OB_EventVar1(a0),d1
			tst.b	d1
			bmi.s	.x
			move.b	d1,HeadFlameVAL
			addq.b	#1,OB_Var2(a0)
			cmp.b	#7,OB_Var2(a0)
			bne.s	.x
			clr.b	OB_Var2(a0)
			bra	MutSpiSetHeadFlame

.fin			clr.b	HeadFlameFLG
.fin2			clr.b	OB_Var1(a0)
.x			rts
			

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT SPIDER BOSS FLAME THROWER CONTROL LOGIC			   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SetupMutSpiFlameThrow	st.b	HeadFlameFLG
			rts

HeadFlameAdd		dc.w	0,$a,$10,$16,$1e
			dc.w	-$a,-$10,-$16,-$1e

MutSpiSetHeadFlame	movem.l	a0/d0,-(sp)
			SPAWN_HI	MutSpiHeadFlm_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#MutSpiHeadFlame_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			moveq	#0,d1
			move.b	HeadFlameVAL,d1
			asl.b	#1,d1
			move.w	HeadFlameAdd(pc,d1.w),d1
			add.w	d1,OB_Xpos(a1)
;			lea	MutSpiHeadFlameANM,a2
			lea	MutSpiProjHeadANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
.1			movem.l	(sp)+,d0/a0
			rts


FlameXTab		dc.w	$104,$134,$154,$174,$184
			dc.w	$0d4,$0b4,$094,$084
FlameYTab		dc.w	$0d0,$0d0,$0d0,$0d0,$0b0
			dc.w	$0d0,$0d0,$0d0,$0b0

MutSpiHeadFlame_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			SFX	30
			moveq	#0,d1
			move.b	HeadFlameVAL,d1
			asl.w	#1,d1
			move.w	FlameXTab(pc,d1.w),TargetX
			move.w	FlameYTab(pc,d1.w),TargetY
			jsr	TrajectorySetup
			clr.w	OB_Var5(a0)
			clr.w	OB_Var6(a0)
			bset.b	#ob_nooff,OB_Flag2(a0)
			move.b	#MutSpiTrajHitPOWER,OB_HitPower(a0)
			jmp	SetMediumAttack

.ok			btst.b	#ob_hitting,OB_Flag1(a0)
			bne.s	.fin
			jsr	GetUnderFEET
			tst.b	d2
			bmi.s	.fin	
			tst.b	0(a1)
			bne.s	.fin

			moveq	#6,d1
			jmp	TrajectoryMove
.fin			jsr	SetSmallAirExplodeAtOB_XY
			jmp	SwitchObjectOff


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT SPIDER BOSS HEAD/TURRET PROJECTILE CONTROL LOGIC		   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	MutSpiProjHomerSTATE
		StDEF	MutSpiProjSwirlSTATE

SetupMutSpiProjHead	bsr	SetupHomingProj2
			bpl.s	.x
			move.b	#max_hxs,OB_Var2(a1)
			clr.b	OB_Var2a(a1)
			move.b	#$20,OB_Var1(a1)
			clr.b	OB_Var3a(a1)
			clr.b	OB_Var5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)			
			sub.w	#$48,OB_Ypos(a1)
			move.w	#MutSpiProjHomerSTATE,OB_State(a1)
			move.b	#MutSpiTrajHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttackA1
			st.b	MutSpiWorkingFLG
			bra	EyeOfOdinPowerUp
.x			rts

SetupMutSpiProjTail	bsr	SetupHomingProj2
			bpl.s	.x
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)			
			move.w	#MutSpiProjHomerSTATE,OB_State(a1)
			lea	MutSpiProjTailANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
.x			rts


SetupHomingProj2	movem.l	a0/d0,-(sp)
			SPAWN_HI	MutSpiProj_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			movem.l	(sp)+,a0/d0
			move.w	#MutSpiProj_OB,OB_Type(a1)				;object type
			bset.b	#ob_nooff,OB_Flag2(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bra	FlagYESn
.no			movem.l	(sp)+,a0/d0
			bra	FlagNOn
		

MutSpiProj_Logic	tst.b	EyeDeadFLG
			beq.s	.1
  			jmp	SwitchObjectOff

.1			move.w	OB_State(a0),d1
			jmp	MutSpiProjLogicTable(pc,d1.w)		;jump table

MutSpiProjLogicTable	bra	MutSpiProjHomerLOGIC
			bra	MutSpiProjSwirlLOGIC
			

MutSpiProjHomerLOGIC	tst.b	OB_Var3a(a0)
			beq.s	.head
			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jmp	SwitchObjectOff
.x			rts

.head			tst.b	OB_Var5(a0)
			bne.s	.11a

			tst.b	EyePoweredUpFLG
			beq.s	.x
			st.b	OB_Var5(a0)
			clr.b	EyePoweredUpFLG
			lea	MutSpiProjHeadANM,a1
			jsr	SetNewAnim 
			jsr	ForceNewAnim
			
.11a			bsr	TestProjHitting
			bmi	.fin
			
			addq.b	#1,OB_Var4(a0)
			and.b	#1,OB_Var4(a0)
			bne.s	.a1
			bsr	SetupMutSpiProjTail
			st.b	OB_Var3a(a1)
			
.a1			addq.b	#1,OB_Var1a(a0)
			and.b	#$3,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			subq.b	#1,OB_Var1(a0)			;time out
			beq	.fin

			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			clr.b	MutSpiWorkingFLG
			bra	ExplodeOBJECT


SetupMutSpiProjSwirl	moveq	#4,d6
.l1			move.l	d6,-(sp)
			
			bsr	SetupHomingProj2
			bpl	.x
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)			
			sub.w	#$38,OB_Ypos(a1)
			move.w	OB_Xpos(a1),OB_WXpos(a1)
			move.w	OB_Ypos(a1),OB_WYpos(a1)
			move.w	#MutSpiProjSwirlSTATE,OB_State(a1)
			move.b	#MutSpiSwirlHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			
			jsr	Randy
			and.w	#$fe,d6
			move.w	d6,OB_Var1(a1)
			jsr	Randy
			and.w	#$fe,d6
			move.w	d6,OB_Var2(a1)

			move.w	#256,OB_Var3(a1)
			move.w	#320,OB_Var4(a1)
			clr.w	OB_Var5(a1)
			move.w	#$1e0/2,OB_Var6(a1)
			clr.w	OB_Var7(a1)

			move.l	(sp)+,d6
			dbra	d6,.l1
			
			st.b	MutSpiWorkingFLG
			clr.b	SwirlSFX
			bra	EyeOfOdinPowerUp
.x			rts


MutSpiProjSwirlLOGIC	tst.b	OB_Var7a(a0)
			beq.s	.head
			tst.l	OB_AnSequence(a0)
			bne	.x
			jmp	SwitchObjectOff

.head			tst.b	OB_Var5a(a0)
			bne.s	.11a

			tst.b	EyePoweredUpFLG
			beq	.x
			tst.b	SwirlSFX
			bne.s	.oo1
			st.b	SwirlSFX
			SFX	79
.oo1			st.b	OB_Var5a(a0)
			lea	MutSpiProjHeadANM,a1
			jsr	SetNewAnim 
			jmp	ForceNewAnim
			
.11a			addq.b	#1,OB_Var7(a0)
			and.b	#3,OB_Var7(a0)
			bne.s	.a1
			bsr	SetupMutSpiProjTail
			move.w	#MutSpiProjSwirlSTATE,OB_State(a1)
			st.b	OB_Var7a(a1)

.a1			subq.w	#1,OB_Var6(a0)
			bne.s	.ok
			clr.b	MutSpiWorkingFLG
			clr.b	EyePoweredUpFLG
			jmp	SwitchObjectOff

.ok			lea	SinTable,a1
						
			move.w	OB_Var1(a0),d1		;x
			move.w	OB_Var2(a0),d2		;y
			
			move.w	OB_WXpos(a0),d4
			moveq	#0,d3
			move.w	0(a1,d1.w),d3		;sin x	
			bpl.s	.x1
   			neg.w	d3
			divu	OB_Var3(a0),d3
			sub.w	d3,d4
			bra	.xx
.x1			divu	OB_Var3(a0),d3
			add.w	d3,d4
.xx			move.w	d4,OB_Xpos(a0)			
			
			move.w	OB_WYpos(a0),d4
			moveq	#0,d3
			move.w	0(a1,d2.w),d3		;cos y
			bpl.s	.y1
   			neg.w	d3
			divu	OB_Var4(a0),d3
			sub.w	d3,d4
			bra	.yy
.y1			divu	OB_Var4(a0),d3
			add.w	d3,d4
.yy			move.w	d4,OB_Ypos(a0)			
			
			subq.w	#1,OB_Var3(a0)
			subq.w	#1,OB_Var4(a0)
			addq.w	#8,OB_Var1(a0)
			addq.w	#8,OB_Var2(a0)
			and.w	#$1ff,OB_Var1(a0)
			and.w	#$1ff,OB_Var2(a0)
.x			rts



; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT SPIDER BOSS VERTICAL ELECTRICITY CONTROL LOGIC		   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

MutSpiSetElecVert	movem.l	a0/d0,-(sp)
			SPAWN_LO	MutSpiElecV_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#MutSpiElecV_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			sub.w	#$40,OB_Ypos(a1)
			add.w	#$8,OB_Xpos(a1)
			move.b	#MutSpiElecHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			clr.b	OB_Var1(a1)
			st.b	MutSpiWorkingFLG
			bra	EyeOfOdinPowerUp
.1			movem.l	(sp)+,d0/a0
			rts		

MutSpiElecV_Logic	tst.b	OB_Var1(a0)
			bne.s	.1

			tst.b	EyePoweredUpFLG
			beq.s	.x
			st.b	OB_Var1(a0)
			clr.b	EyePoweredUpFLG
			SFX	93
			lea	MutSpiElecVertANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim
			
.1			tst.l	OB_AnSequence(a0)
			bne.s	.x
			clr.b	MutSpiWorkingFLG
			jmp	SwitchObjectOff
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT SPIDER BOSS HORIZONTAL ELECTRICITY CONTROL LOGIC		   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

MutSpiSetElecHorz	movem.l	a0/d0,-(sp)
			SPAWN_LO	MutSpiElecH_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#MutSpiElecH_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			sub.w	#$3c,OB_Ypos(a1)
			move.w	OB_Xpos(a0),d1
			sub.w	Plr_XPos,d1
			bpl.s	.r
.l			bset.b	#ob_xflp,OB_Flag1(a1)
			add.w	#$44,OB_Xpos(a1)
			bra	.o1
.r			bclr.b	#ob_xflp,OB_Flag1(a1)
			sub.w	#$44,OB_Xpos(a1)
			
.o1			cmp.w	#$a8,Plr_YPos
			bgt.s	.o2
			bset.b	#ob_yflp,OB_Flag1(a1)

.o2			move.b	#MutSpiElecHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			clr.b	OB_Var1(a1)
			st.b	MutSpiWorkingFLG
			bra	EyeOfOdinPowerUp

.1			movem.l	(sp)+,d0/a0
			rts		

MutSpiElecH_Logic	tst.b	OB_Var1(a0)
			bne.s	.1

			tst.b	EyePoweredUpFLG
			beq.s	.x
			st.b	OB_Var1(a0)
			clr.b	EyePoweredUpFLG
			SFX	93
			lea	MutSpiElecHorzANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim
			
.1			tst.l	OB_AnSequence(a0)
			bne.s	.x
			clr.b	MutSpiWorkingFLG
			jmp	SwitchObjectOff
.x			rts



; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί WASP ROBOT CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	WaspBotTestSTATE
		StDEF	WaspBotAirZeroSTATE
		StDEF	WaspBotFlyToSTATE
		StDEF	WaspBotFlyToOutSTATE
		StDEF	WaspBotTurnToSTATE
		StDEF	WaspBotTrackSTATE
		StDEF	WaspBotFireSTATE
		StDEF	WaspBotStrafeSTATE
		StDEF	WaspBotResetGunSTATE
		StDEF	WaspBotBackoffSTATE

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

.y			btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			move.w	#WaspBot_NRG,OB_Nrg(a0)
			move.l	#WaspBotSetHits,OB_HitRoutine(a0)
			bsr	WaspBotSetAirZero
			clr.w	OB_Var8(a0)
			
.1			jsr	HandleBeingHit				;Generic handle hit rout
			jsr	GetUnderNME
			
			move.w	OB_State(a0),d1
			jmp	WaspBotLogicTable(pc,d1.w)		;jump table

WaspBotLogicTable	bra	WaspBotTestLOGIC
			bra	WaspBotAirZeroLOGIC
			bra	WaspBotFlyToLOGIC
			bra	WaspBotFlyToOutLOGIC
			bra	WaspBotTurnToLOGIC
			bra	WaspBotTrackLOGIC
			bra	WaspBotFireLOGIC
			bra	WaspBotStrafeLOGIC
			bra	WaspBotResetGunLOGIC
			bra	WaspBotBackoffLOGIC

DoWaspBotAI		move.l	d1,AI_Exclude
			lea	WASP_AI,a1
			jsr	AI_Routine
			bpl.s	.1
			AddStack 4
			jmp	(a1)
.1			rts


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

WaspBotSetHits		move.b	OB_Flag6(a0),d2
			and.b	#%11000111,OB_Flag6(a0)
			jsr	ClrHitStuff
			
			btst.b	#ob_dead,OB_Flag2(a0)
			bne.s	WaspBotSetExplode

			btst	#ob_hit_small,d2
			bne.s	WaspBotSetExplode
			btst	#ob_hit_med,d2
			bne.s	WaspBotSetExplode
			btst	#ob_hit_big,d2
			bne.s	WaspBotSetExplode
			rts


WaspBotSetHit		move.w	#WaspBotBackoffSTATE,OB_State(a0)
			move.b	#3,OB_Var1(a0)
			clr.b	OB_Var1a(a0)
			lea	WaspBotHitANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim


WaspBotSetExplode	bsr	SetBigAirExplodeAtOB_XY
			moveq	#3,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			bsr	SetRandomDebris
			jmp	SwitchObjectOff
		

; - Testbed ----------------------------------------------------------------

WaspBotTestLOGIC	rts


; - Before Wasp Bot sees player --------------------------------------------
; - Air Zero ---------------------------------------------------------------

WaspBotSetAirZero	move.w	#WaspBotAirZeroSTATE,OB_State(a0)
			jsr	ClrHitStuff
			clr.b	OB_MasterMode(a0)
			clr.w	OB_Var1(a0)
			btst.b	#ob_generic1,OB_Flag6(a0)
			bne	WaspBotSetStrafe
			lea	WaspBotHoverANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

WaspBobTab		dc.b	-2,-1,0,0,1,2,2,1,0,0,-1,-2,$80
  			even


WaspBotAirZeroLOGIC	move.l	#WaspBotSetAirZero,d1
			bsr	DoWaspBotAI

WaspBotBob		addq.b	#1,OB_Var1(a0)
			and.b	#3,OB_Var1(a0)
			bne.s	.4
			addq.b	#1,OB_Var1a(a0)

.1			moveq	#0,d1
			moveq	#0,d2
			move.b	OB_Var1a(a0),d1
			move.b	WaspBobTab(pc,d1.w),d2
			bpl.s	.2
			cmp.b	#$80,d2
			bne.s	.3
			clr.b	OB_Var1a(a0)
			bra.s	.1
.3			neg.b	d2
			sub.w	d2,OB_Ypos(a0)
.4			rts
.2			add.w	d2,OB_Ypos(a0)
			rts

; - After Wasp Bot sees player ---------------------------------------------
; - Fly To -----------------------------------------------------------------

WBFTxm			equ	$40
WBFTym			equ	$50
WBFTxms			equ	4
WBFTyms			equ	3

WaspBotSetFlyTo		move.w	#WaspBotFlyToSTATE,OB_State(a0)
			tst.b	OB_Var8(a0)				;reset gun
			bne	WBSRG1
WaspBotSFT3		bsr	DoesNmeFacePlayer
			bpl	WBSTT1
WaspBotSFT1		bsr	WaspSetFlyToPos
			clr.w	OB_Var1(a0)
			move.w	#$0101,OB_Var2(a0)
			clr.w	OB_Var3(a0)
			lea	WaspBotFlyToANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
.x			rts

WaspBotFlyToLOGIC	addq.b	#1,OB_Var1(a0)
			and.b	#1,OB_Var1(a0)
			bne.s	.xy

.x  			tst.b	OB_Var3(a0)
			beq.s	.xacc
.xdec			tst.b	OB_Var2(a0)
			beq.s	.y
			subq.b	#1,OB_Var2(a0)
			bra	.y
.xacc			cmp.b	#WBFTxms,OB_Var2(a0)
			beq.s	.y
			addq.b	#1,OB_Var2(a0)

.y			tst.b	OB_Var3a(a0)
			beq.s	.yacc
.ydec			tst.b	OB_Var2a(a0)
			beq.s	.xy
			subq.b	#1,OB_Var2a(a0)
			bra	.xy
.yacc			cmp.b	#WBFTyms,OB_Var2a(a0)
			beq.s	.xy
			addq.b	#1,OB_Var2a(a0)

.xy			tst.b	OB_Var2(a0)
			bne.s	.n1
			tst.b	OB_Var2a(a0)
			beq	WaspBotSetFlyToOut
			
.n1			moveq	#0,d5
			move.b	OB_Var2(a0),d5
			move.w	OB_Var4(a0),d1
			tst.b	OB_Var6(a0)
			beq.s	.rte
.lft			move.b	NUnderLEFT,d2
			jsr	TestLevelWalls
			bpl.s	.l1
			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTFEET,d2
			btst	#7,d2
			bne	WaspBotSetBackoff
.l1			cmp.b	#SB_ForceTurn,NUnderLEFT
			beq	WaspBotSetBackoff
			cmp.b	#SB_ForceTurn,NUnderLEFTTOP
			beq	WaspBotSetBackoff
			cmp.b	#SB_ForceTurn,NUnderLEFTFEET
			beq	WaspBotSetBackoff
			sub.w	d5,OB_Xpos(a0)
			cmp.w	OB_Xpos(a0),d1
			blt.s	.o1
			bra.s	.n2
.rte			move.b	NUnderRIGHT,d2
			jsr	TestLevelWalls
			bpl.s	.r1
			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTFEET,d2
			btst	#7,d2
			bne	WaspBotSetBackoff
.r1			cmp.b	#SB_ForceTurn,NUnderRIGHT
			beq	WaspBotSetBackoff
			cmp.b	#SB_ForceTurn,NUnderRIGHTTOP
			beq	WaspBotSetBackoff
			cmp.b	#SB_ForceTurn,NUnderRIGHTFEET
			beq	WaspBotSetBackoff
			add.w	d5,OB_Xpos(a0)
			cmp.w	OB_Xpos(a0),d1
			bgt.s	.o1
.n2			tst.b	OB_Var3(a0)
			bne.s	.o1
   			st.b	OB_Var3(a0)

.o1			moveq	#0,d5
			move.b	OB_Var2a(a0),d5
			move.w	OB_Var5(a0),d1
			tst.b	OB_Var6a(a0)
			beq.s	.dn
.up			move.b	NUnderHEAD,d2
			or.b	NUnderLEFTHEAD,d2
			or.b	NUnderRIGHTHEAD,d2
			btst	#7,d2
			bne.s	.n3
			cmp.b	#SB_ForceTurn,NUnderHEAD
			beq.s	.n3
			cmp.b	#SB_ForceTurn,NUnderLEFTHEAD
			beq.s	.n3
			cmp.b	#SB_ForceTurn,NUnderRIGHTHEAD
			beq.s	.n3
			sub.w	d5,OB_Ypos(a0)
			cmp.w	OB_Ypos(a0),d1
			blt.s	.o2
			bra.s	.n3
.dn			move.b	NUnderFEET,d2
			or.b	NUnderLEFTFEET,d2
			or.b	NUnderRIGHTFEET,d2
			btst	#7,d2
			bne.s	.n3
			cmp.b	#SB_ForceTurn,NUnderFEET
			beq.s	.n3
			cmp.b	#SB_ForceTurn,NUnderLEFTFEET
			beq.s	.n3
			cmp.b	#SB_ForceTurn,NUnderRIGHTFEET
			beq.s	.n3
			add.w	d5,OB_Ypos(a0)
			cmp.w	OB_Ypos(a0),d1
			bgt.s	.o2
.n3			tst.b	OB_Var3a(a0)
			bne.s	.o2
   			st.b	OB_Var3a(a0)
.o2			rts

WaspSetFlyToPos		move.w	Plr_XPos,d1   				;set fly to point
			move.w	Plr_YPos,d2
			
			bclr.b	#ob_generic1,OB_Flag6(a0)
			jsr	Randy
			and.w	#$f,d6
			cmp.w	#4,d6
			blt.s	.RegularL
			cmp.w	#8,d6
			blt.s	.RegularR
			cmp.w	#10,d6
			blt.s	.StrafeL
			cmp.w	#12,d6
			blt.s	.StrafeR
			cmp.w	#14,d6
			blt.s	.LowL
			cmp.w	#16,d6
			blt.s	.LowR

.RegularL		sub.w	#WBFTxm,d1
			sub.w	#WBFTym,d2
			bra	.ok
.RegularR		add.w	#WBFTxm,d1
			sub.w	#WBFTym,d2
			bra	.ok
.StrafeL		sub.w	#WBFTxm+$40,d1
			sub.w	#WBFTym-$10,d2
			bset.b	#ob_generic1,OB_Flag6(a0)
			bra	.ok
.StrafeR		add.w	#WBFTxm+$40,d1
			sub.w	#WBFTym-$10,d2
			bset.b	#ob_generic1,OB_Flag6(a0)
			bra	.ok
.LowL			sub.w	#WBFTxm+$20,d1
			sub.w	#WBFTym-$30,d2
			bra	.ok
.LowR			add.w	#WBFTxm+$20,d1
			sub.w	#WBFTym-$30,d2

.ok			clr.w	OB_Var6(a0)
			move.w	d1,OB_Var4(a0)
			move.w	d2,OB_Var5(a0)
			cmp.w	OB_Xpos(a0),d1
			bgt.s	.a
			st.b	OB_Var6(a0)
.a			cmp.w	OB_Ypos(a0),d2
			bgt.s	.b
			st.b	OB_Var6a(a0)
.b			rts


WaspBotSetFlyToOut	move.w	#WaspBotFlyToOutSTATE,OB_State(a0)
			lea	WaspBotFlyToOutANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

WaspBotFlyToOutLOGIC	tst.l	OB_AnSequence(a0)
			beq	WaspBotSetAirZero
			rts


; - Wasp Bot turns to face player ------------------------------------------

WBSTT3			PUSHADDRS WaspBotSFT4
      			bra	WaspBotSetTurnTo
WBSTT2			PUSHADDRS WaspBotSFT2
      			bra	WaspBotSetTurnTo
WBSTT1			PUSHADDRS WaspBotSFT1

WaspBotSetTurnTo	PUSHSTATE
			move.w	#WaspBotTurnToSTATE,OB_State(a0)
			lea	WaspBotTurnANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

WaspBotTurnToLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.1
			eor.b	#_ob_xflp,OB_Flag1(a0)
			POPSTATE
			POPADDRS
			jmp	(a1)
.1			rts


; - Wasp Bot gun resets to horzontal ------------------------------------------

WBSRG1			PUSHADDRS WaspBotSFT3

WaspBotSetResetGun	PUSHSTATE
			move.w	#WaspBotResetGunSTATE,OB_State(a0)
			move.b	#0,OB_Var8a(a0)

WaspBotResetGunLOGIC	bsr	WaspBotAnimateGun
			tst.b	OB_Var8(a0)
			bne.s	.1
			POPSTATE
			POPADDRS
			jmp	(a1)
.1			rts


; - Track player Zero ---------------------------------------------------------------

WaspBotSetTrack		move.w	#WaspBotTrackSTATE,OB_State(a0)
WaspBotSFT2		lea	WaspBotTrack0ANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
WaspBotTrackLOGIC	move.l	#-1,AI_Exclude
			lea	WASP_AI2,a1
			jsr	AI_Routine
			bpl.s	.aa
			jmp	(a1)

.aa			bsr	WaspBotBob
 
			move.w	#$80,d1					;player moved away
			jsr	TestProxX
			bpl	WaspBotSetFlyTo
			
			bsr	DoesNmeFacePlayer
			bpl	WBSTT2

			jsr	Randy
			and.w	#$13f,d6
			beq	WaspBotSetFlyTo
			and.w	#$f,d6
			beq	WaspBotSetFire

			bsr	WaspBotAnimateGun
			jsr	AITestPlrIsAbove
			bmi	.b90
      
.below			move.w	#$70,d1
			jsr	TestProxX
			bmi.s	.bclose

.bfar			move.w	#$10,d1
			jsr	TestProxY_Below
			bmi.s	.b90
			move.w	#$30,d1
			jsr	TestProxY_Below
			bmi.s	.b65
			move.w	#$50,d1
			jsr	TestProxY_Below
			bmi.s	.b45
			move.w	#$70,d1
			jsr	TestProxY_Below
			bmi.s	.b25
			bra	.b0
.x			rts
.bclose			move.w	#$10,d1
			jsr	TestProxY_Below
			bmi.s	.b90
			move.w	#$20,d1
			jsr	TestProxY_Below
			bmi.s	.b65
			move.w	#$30,d1
			jsr	TestProxY_Below
			bmi.s	.b45
			move.w	#$40,d1
			jsr	TestProxY_Below
			bmi.s	.b25
			
.b0			move.b	#4,OB_Var8a(a0)
			rts
.b25			move.b	#3,OB_Var8a(a0)
			rts
.b45			move.b	#2,OB_Var8a(a0)
			rts
.b65			move.b	#1,OB_Var8a(a0)
			rts
.b90			move.b	#0,OB_Var8a(a0)
			rts

WBTrackAnmTab		dc.l	WaspBotTrack0ANM
			dc.l	WaspBotTrack1ANM,WaspBotTrack2ANM,WaspBotTrack3ANM,WaspBotTrack4ANM

WaspBotAnimateGun	move.b	OB_Var8a(a0),d1
			cmp.b	OB_Var8(a0),d1
			beq.s	.x
   			bgt.s	.up
.dn			subq.b	#1,OB_Var8(a0)
			bra	WBAG1
.x			rts
.up			addq.b	#1,OB_Var8(a0)

WBAG1			moveq	#0,d1
			move.b	OB_Var8(a0),d1
			asl.b	#2,d1
			move.l	WBTrackAnmTab(pc,d1.w),a1
			jsr	SetNewAnim
			jmp	ForceNewAnim


; - WaspBot fires projectile (tracking) ------------------------------------

WaspBotFireANMTab	dc.l	WaspBotFire0ANM	
			dc.l	WaspBotFire0ANM,WaspBotFire1ANM,WaspBotFire2ANM,WaspBotFire2ANM

WaspBotFireDIRTab	dc.b	4
			dc.b	4,5,6,6
			even
WaspBotFireDIRTabF	dc.b	12
			dc.b	12,11,10,10
			even

WaspBotSetFire		move.w	#WaspBotFireSTATE,OB_State(a0)
			moveq	#0,d1
			move.b	OB_Var8(a0),d1
			asl.b	#2,d1
			move.l	WaspBotFireANMTab(pc,d1.w),a1
			jsr	SetNewAnim
			jsr	ForceNewAnim
			bsr	RandomLaserSFX
			
			bsr	SetupDirectionalProj
			bpl.s	.x
			move.b	#WaspBoltHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			bset.b	#ob_hiprior,OB_Flag2(a1)
			subq.w	#4,OB_Ypos(a1)
			jsr	SetFlipFromMother
			moveq	#0,d1
			move.b	OB_Var8(a0),d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.1
			subq.w	#$8,OB_Xpos(a1)
			move.b	WaspBotFireDIRTabF(pc,d1.w),d1
			bra	.2
.1			addq.w	#$8,OB_Xpos(a1)
			move.b	WaspBotFireDIRTab(pc,d1.w),d1
.2			move.b	d1,OB_Var1(a1)
			move.w	#DirProj2_OB,OB_Type(a1)
			cmp.b	#4,d1
			beq.s	.a
			cmp.b	#12,d1
			beq.s	.a
			cmp.b	#5,d1
			beq.s	.b
			cmp.b	#11,d1
			beq.s	.b
.c			lea	WaspBotProj3ANM,a2
			bra	.d
.b			lea	WaspBotProj2ANM,a2
			bra	.d
.a			lea	WaspBotProj1ANM,a2
.d			jmp	SetNewAnimA1
.x			rts			
			
WaspBotFireLOGIC	bsr	WaspBotBob
 
			tst.l	OB_AnSequence(a0)
			bne.s	.x
			move.w	#WaspBotTrackSTATE,OB_State(a0)
.x			rts


; - WaspBot Strafes ---------------------------------------------------

WaspBotSetStrafe	move.w	#WaspBotStrafeSTATE,OB_State(a0)
			bsr	DoesNmeFacePlayer
			bpl	WBSTT3
WaspBotSFT4		move.b	#$48,OB_Var1(a0)
			bclr.b	#ob_generic1,OB_Flag6(a0)
			clr.w	OB_EventVar1(a0)
			lea	WaspBotStrafeANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
WaspBotStrafeLOGIC	tst.b	OB_EventVar1(a0)
			beq	.x
			
			subq.b	#1,OB_Var1(a0)
			beq	WaspBotSetAirZero
			
			moveq	#4,d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			move.b	NUnderLEFT,d2
			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTFEET,d2
			btst	#7,d2
			bne	WaspBotSetBackoff
			cmp.b	#SB_ForceTurn,NUnderLEFT
			beq	WaspBotSetBackoff		
			cmp.b	#SB_ForceTurn,NUnderLEFTFEET
			beq	WaspBotSetBackoff	    
			cmp.b	#SB_ForceTurn,NUnderLEFTTOP
			beq	WaspBotSetBackoff		
			bsr	MoveGolLeft_Smooth
			bra	.o1
.r			move.b	NUnderRIGHT,d2
			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTFEET,d2
			btst	#7,d2
			bne	WaspBotSetBackoff
			cmp.b	#SB_ForceTurn,NUnderRIGHT
			beq	WaspBotSetBackoff		
			cmp.b	#SB_ForceTurn,NUnderRIGHTFEET
			beq	WaspBotSetBackoff	    
			cmp.b	#SB_ForceTurn,NUnderRIGHTTOP
			beq	WaspBotSetBackoff		
			bsr	MoveGolRight_Smooth
			
.o1			tst.b	OB_EventVar2(a0)
			beq.s	.x
 			clr.b	OB_EventVar2(a0)
	
			SFX	110

			bsr	SetupDirectionalProj
			bpl.s	.x
			move.b	#WaspStrafeBoltHitPOWER,OB_HitPower(a1)
			jsr	SetBigAttackA1
			bset.b	#ob_hiprior,OB_Flag2(a1)
			sub.w	#$9,OB_Ypos(a1)
			jsr	SetFlipFromMother
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.1a
			move.b	#10,OB_Var1(a1)
			sub.w	#$10,OB_Xpos(a1)
			bra	.2a
.1a			move.b	#6,OB_Var1(a1)
			add.w	#$10,OB_Xpos(a1)
.2a			move.w	#DirProj2_OB,OB_Type(a1)
			lea	WaspBotProj4ANM,a2
			jmp	SetNewAnimA1
.x			rts


; - WaspBot backs off -------------------------------------------------

WaspBotSetBackoff	move.w	#WaspBotBackoffSTATE,OB_State(a0)
			move.b	#3,OB_Var1(a0)
			lea	WaspBotBackoffANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

WaspBotBackoffLOGIC	tst.b	OB_Var1(a0)
			beq	.2
			addq.b	#1,OB_Var1a(a0)
			and.b	#7,OB_Var1a(a0)
			bne.s	.1
 			sub.b	#1,OB_Var1(a0)
			
.1			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r  
.l			move.b	NUnderRIGHT,d2
			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTFEET,d2
			btst	#7,d2
			bne	.flp
			cmp.b	#SB_ForceTurn,NUnderRIGHT
			beq	.flp
			cmp.b	#SB_ForceTurn,NUnderRIGHTTOP
			beq	.flp
			cmp.b	#SB_ForceTurn,NUnderRIGHTFEET
			beq	.flp
			bsr	MoveGolRight_NF_Smooth
			bra	.o
.r			move.b	NUnderLEFT,d2
			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTFEET,d2
			btst	#7,d2
			bne.s	.flp
			cmp.b	#SB_ForceTurn,NUnderLEFT
			beq.s	.flp
			cmp.b	#SB_ForceTurn,NUnderLEFTTOP
			beq.s	.flp
			cmp.b	#SB_ForceTurn,NUnderLEFTFEET
			beq.s	.flp
			bsr	MoveGolLeft_NF_Smooth
.o			move.b	NUnderHEAD,d2
			or.b	NUnderLEFTHEAD,d2
			or.b	NUnderRIGHTHEAD,d2
			btst	#7,d2
			bne.s	.2
			cmp.b	#SB_ForceTurn,NUnderHEAD
			beq.s	.2
			cmp.b	#SB_ForceTurn,NUnderLEFTHEAD
			beq.s	.2
			cmp.b	#SB_ForceTurn,NUnderRIGHTHEAD
			beq.s	.2
			bsr	MoveGolUp_Smooth

.2			tst.l	OB_AnSequence(a0)
			beq	WaspBotSetAirZero
			rts
.flp			eor.b	#_ob_xflp,OB_Flag1(a0)
			bra	.o



; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί XANATOS/STEEL CLAN ROBOT CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnXanatos		bsr	XanatosSpawnBit
			clr.b	XanatosDeadCNT
			clr.b	XanatosMinionCNT
			clr.b	PlayingBOSS
			move.w	#$b8,OB_Xpos(a1)
			move.w	#$c0,OB_Ypos(a1)
			move.w	#Xanatos_OB,OB_Type(a1)
			clr.b	OB_Var1(a1)
			move.w	#$a0,TempX
			move.w	#$c0,TempY
			bsr	SpawnSteelClan
			move.w	#$d0,TempX
			move.w	#$c0,TempY

SpawnSteelClan		bsr	XanatosSpawnBit
			bpl.s	.x	
			move.w	TempX,OB_Xpos(a1)
			move.w	TempY,OB_Ypos(a1)
			move.w	#Xanatos_OB,OB_Type(a1)
			st.b	OB_Var1(a1) 
			move.w	#SteelClan_NRG,OB_Nrg(a1)	
			bset.b	#ob_newpal,OB_Flag1(a1)		;overide default palette
			move.w	#cp3,OB_Pal(a1)			;set new palette
.x			rts

XanatosSpawnBit		move.l	a0,-(sp)
			move.w	#Xanatos_MAX_Size,d3
			jsr	SpawnBasicOBJECT_HI
			bpl.s	.n
			move.l	a0,a1
			move.l	(sp)+,a0
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.b	#_ob_nooff+_ob_hiprior,OB_Flag2(a1)
			bra	FlagYESn			
.n			move.l	(sp)+,a0
			bra	FlagNOn


		StRESET
		StDEF	XanatosPassiveSTATE
		StDEF	XanatosAttackSTATE
		StDEF	XanatosFlyToSTATE
		StDEF	XanatosTurnToSTATE
		StDEF	XanatosBackoffSTATE
		StDEF	XanatosRocketAttackSTATE
		StDEF	XanatosRocketOutSTATE
		StDEF	XanatosStrikeAttackSTATE
		StDEF	XanatosFireHomerSTATE
		StDEF	XanatosDropMineSTATE

		StDEF	XanatosHitSTATE
		StDEF	XanatosDeadSTATE
		StDEF	XanatosBoomSTATE

Xanatos_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			move.l	#XanatosSetHits,OB_HitRoutine(a0)
			move.l	#XanatosOffRoutine,OB_OffRoutine(a0)
			SFX	57
			bra	XanatosSetStartup

.1			jsr	HandleBeingHit				;Generic handle hit rout

			move.w	OB_State(a0),d1
			jmp	XanatosLogicTable(pc,d1.w)		;jump table

XanatosLogicTable	bra	XanatosPassiveLOGIC
			bra	XanatosAttackLOGIC
			bra	XanatosFlyToLOGIC
			bra	XanatosTurnToLOGIC
			bra	XanatosBackoffLOGIC
			bra	XanatosRocketAttkLOGIC
			bra	XanatosRocketOutLOGIC
			bra	XanatosStrikeAttkLOGIC
			bra	XanatosFireHomerLOGIC
			bra	XanatosDropMineLOGIC

			bra	XanatosHitLOGIC
			bra	XanatosDeadLOGIC
			bra	XanatosBoomLOGIC


XanatosOffRoutine	tst.b	OB_Var1(a0)
			beq.s	.x

.steelclan		addq.b	#1,XanatosDeadCNT
			cmp.b	#2,XanatosDeadCNT
			bne.s	.x
			clr.b	XanatosDeadCNT
			addq.b	#1,XanatosMinionCNT
			move.b	#$40,XanatosNextFLG
.x			rts

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

XanatosSetHits		move.b	OB_Flag6(a0),d2
			jsr	ClrHitStuff
			
			btst.b	#ob_dead,OB_Flag2(a0)
			bne	XanatosSetDead
				       
XanatosSetHit		move.w	#XanatosHitSTATE,OB_State(a0)
			move.b	#3,OB_Var2(a0)
			clr.b	OB_Var2a(a0)
			jsr	Randy
			and.b	#1,d6
			beq.s	.1
			move.l	#107,sfx_poll
			bra	.a
.1			move.l	#104,sfx_poll
.a			jsr	SetSFX
			lea	XanatosHitANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosHitLOGIC		tst.b	OB_Var2(a0)
			beq.s	.1
			moveq	#0,d1
			btst.b	#ob_hitside,OB_Flag1(a0)
			beq.s	.2
			move.b	OB_Var2(a0),d1
			bsr	MoveGolLeft_NF_Smooth
			bra	.3
.2			move.b	OB_Var2(a0),d1
			bsr	MoveGolRight_NF_Smooth
.3			addq.b	#1,OB_Var2a(a0)
			and.b	#3,OB_Var2a(a0)
			bne.s	.1
  			subq.b	#1,OB_Var2(a0)
.1			tst.l	OB_AnSequence(a0)
			beq	XanatosSetAttack
.x			rts


; - Xanatos dead -----------------------------------------------

XanatosSetDead		move.w	#XanatosDeadSTATE,OB_State(a0)
			clr.w	OB_Var2(a0)
			clr.w	OB_Var3(a0)
			lea	XanatosIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosDeadLOGIC	tst.b	PlayingBOSS
			beq.s	.norm

			st.b	BossDefeatedFLG
			
			jsr	Randy
			and.w	#3,d6
			move.w	d6,d1
			jsr	MoveGolLeftRightXFLP2
			jsr	Randy
			and.w	#3,d6
			sub.w	d6,OB_Ypos(a0)
			cmp.w	#$90,OB_Ypos(a0)
			blt	XanatosSetBoom
			bra	XanExplodeBit

.norm			moveq	#1,d1
			jsr	MoveGolLeftRightXFLP2
			
			bsr	XanExplodeBit
			
			addq.b	#1,OB_Var2(a0)
			and.b	#7,OB_Var2(a0)
			bne.s	.1

			addq.b	#1,OB_Var2a(a0)
.1			moveq	#0,d1
			move.b	OB_Var2a(a0),d1
			add.w	d1,OB_Ypos(a0)
			cmp.w	#$110,OB_Ypos(a0)
			blt.s	.x

.fin			jsr	SwitchObjectOff
			jsr	SetBigAirExplodeAtOB_XY
			moveq	#2,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			jsr	SetRandomDebris
.x			rts	



XanExplodeBit		addq.b	#1,OB_Var3(a0)
			and.b	#3,OB_Var3(a0)
			bne.s	.1a
			move.w	OB_Xpos(a0),d1
			sub.w	#$10,d1
			jsr	Randy
			and.w	#$1f,d6
			add.w	d6,d1
			move.w	d1,TempX
			move.w	OB_Ypos(a0),d1
			sub.w	#$20,d1
			jsr	Randy
			and.w	#$1f,d6
			add.w	d6,d1
			move.w	d1,TempY
			jsr	SetSmallAirExplode
			bpl.s	.1a
			move.w	TempX,OB_Xpos(a1)
			move.w	TempY,OB_Ypos(a1)
			bset.b	#ob_hiprior,OB_Flag2(a1)
.1a			rts


; - Xanatos goes BOOM! -----------------------------------------------------

XanatosSetBoom		move.w	#XanatosBoomSTATE,OB_State(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			move.w	#$100,OB_Var1(a0)
			lea	EyeOfOdinBlankANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosBoomLOGIC	subq.w	#1,OB_Var1(a0)
			beq.s	.bye
			move.w	OB_Var1(a0),d1
			and.w	#$f,d1
			bne.s	.x
			
			jsr	Randy
			and.w	#$1f,d6
			and.w	#$1f,d7
			move.w	OB_Xpos(a0),d1
			sub.w	#$10,d1
			add.w	d6,d1
			move.w	OB_Ypos(a0),d2
			sub.w	#$20,d2
			add.w	d7,d2
			jsr	SetBigAirExplode
			bpl.s	.1
			bset.b	#ob_hiprior,OB_Flag2(a1)
.1			moveq	#2,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			jmp	SetRandomDebris

.bye			st.b	NextLevelFLG
.x			rts


; - Xanatos startup -----------------------------------------------

XanatosSetStartup	tst.b	OB_Var1(a0)
			beq.s	.xan
.sc			jsr	Randy
			and.w	#$7f,d6
			add.w	#$120,d6
			move.w	d6,d1
			bra	.o
.xan			move.w	#$60,d1
.o			move.w	#$70,d2
		
XanatosSetStartup2	clr.w	OB_Var6(a0)
			move.w	d1,OB_Var4(a0)
			move.w	d2,OB_Var5(a0)
			cmp.w	OB_Xpos(a0),d1
			bgt.s	.a
			st.b	OB_Var6(a0)
.a			cmp.w	OB_Ypos(a0),d2
			bgt.s	.b
			st.b	OB_Var6a(a0)
.b			clr.w	OB_Var7(a0)
			move.w	#$0101,OB_Var2(a0)
			clr.w	OB_Var3(a0)
			move.w	#XanatosFlyToSTATE,OB_State(a0)
			
			lea	XanatosIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


; - Xanatos passive -----------------------------------------------

XanatosSetPassive	move.w	#XanatosPassiveSTATE,OB_State(a0)
			bset.b	#ob_notect1,OB_Flag3(a0)		;disable sprt 2 sprt detection
			move.b	#$80,OB_Var6(a0)
			clr.b	OB_Var8(a0)
			lea	XanatosIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosPassiveLOGIC	bsr	XanatosCheckNext

			cmp.b	#3,XanatosMinionCNT
			bne.s	.1
			subq.b	#1,OB_Var6(a0)
			bne.s	.1

			movem.l	a0-a6/d0-d7,-(sp)
			jsr	SetupBossMeter
			movem.l	(sp)+,a0-a6/d0-d7

			move.b	#3,OB_Var8(a0)				;flag this clan can drop mines and fire homers
			
			st.b	PlayingBOSS
			clr.b	BossDefeatedFLG
			move.l	a0,Boss_Database			;boss' database
			move.w	#SubwayBOSS_NRG,OB_Nrg(a0)
			move.w	OB_Nrg(a0),d1
			move.w	d1,BossEnergy
			lsr.w	#5,d1
			move.w	d1,BossPercentile
			clr.b	OB_Var1(a0)
			bclr.b	#ob_notect1,OB_Flag3(a0)		;eneble sprt 2 sprt detection
			st.b	BossFirstPass
			bra	XanatosSetAttack

.1			bsr	DoesNmeFacePlayer
			bpl	XASTT3
			bra	Xan1
XanatosSFT3		lea	XanatosIdleANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim

Xan1			move.w	#$40,d1
			jsr	TestProxX
			bpl.s	.x
			move.w	#$30,d1
			jsr	TestProxY
			bpl.s	.x
			cmp.w	#$100,OB_Xpos(a0)
			blt.s	.1
			move.w	#$60,d1
			bra	.a
.1			move.w	#$240,d1
.a			move.w	#$70,d2
			bra	XanatosSetStartup2	
.x			rts

XanatosCheckNext	tst.b	XanatosNextFLG
			beq.s	.x
			sub.b	#1,XanatosNextFLG
			bne.s	.x

			SFX	57

;			jsr	Randy
;			and.l	#1,d6
;			add.l	#95,d6
;			move.l	d6,sfx_poll
;			jsr	SetSFX
			
			cmp.b	#1,XanatosMinionCNT
			beq.s	.p2
			cmp.b	#2,XanatosMinionCNT
			beq.s	.p3
.x			rts

.p2			move.w	#$100,TempX				;both steel clans have died
			move.w	#$c0,TempY				;so spawn some more
			bsr	SpawnSteelClan
			move.b	#1,OB_Var8(a1)				;flag this clan can drop mines
			move.w	#$120,TempX
			move.w	#$c0,TempY
			bsr	SpawnSteelClan
			move.b	#1,OB_Var8(a1)				;flag this clan can drop mines
			move.l	#Lev51MapAc,__MapA	
			bra	.bit
.p3			move.w	#$180,TempX				;both steel clans have died
			move.w	#$c0,TempY				;so spawn some more
			bsr	SpawnSteelClan
			move.b	#2,OB_Var8(a1)				;flag this clan can fire homers
			move.w	#$1a0,TempX
			move.w	#$c0,TempY
			bsr	SpawnSteelClan
			move.b	#2,OB_Var8(a1)				;flag this clan can fire homers
			move.l	#Lev51MapAd,__MapA	

.bit			move.w	TempX,OB_Var3(a0)
			move.w	TempY,OB_Var4(a0)
			sub.w	#$20,OB_Var3(a0)
			sub.w	#$20,OB_Var4(a0)
	
			moveq	#3,d1
.l1			move.l	d1,-(sp)
			move.w	OB_Var3(a0),TempX
			move.w	OB_Var4(a0),TempY
			jsr	Randy
			and.w	#$1f,d6
			add.w	#$20,d6
			and.w	#$1f,d7
			add.w	#$20,d7
			add.w	d6,TempX
			add.w	d7,TempY
			moveq	#2,d7
			moveq	#3,d3
			jsr	SetRandomDebris
			move.l	(sp)+,d1
			dbra	d1,.l1
			
			move.l	a0,-(sp)				;make plr fall
			move.l	Plr_Database,a0
			jsr	GolSetFall
			move.l	(sp)+,a0

			jsr	WhitePalette
			moveq	#$3,d1
			lea	GamePalette,a1
			move.w	#def_blkwhtin,d2
			jsr	set_whitein	
			;explosions
			;shrapnel
			jmp	DownloadScrlA




; - Xanatos attacking -----------------------------------------------

XanatosSetAttack	move.w	#XanatosAttackSTATE,OB_State(a0)
			bsr	DoesNmeFacePlayer
			bpl	XASTT2
XanatosSFT2		tst.b	OB_Var1a(a0)
			beq.s	.ok
   			cmp.w	#$50,Plr_XPos
			bgt.s	.1
			clr.b	OB_Var1a(a0)
			bra	.ok
.1			cmp.b	#XanROCK,OB_Var1a(a0)
			beq	XanatosSetRocketAttack
			cmp.b	#XanSTRIKE,OB_Var1a(a0)
			beq	XanatosSetStrikeAttack
.ok			lea	XanatosIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosAttackLOGIC	jsr	Randy
			tst.b	PlayingBOSS
			beq.s	.1
			and.b	#$f,d6
			beq	XanatosSetFlyTo
			bra	XanatosCheckBackoff
.1			and.b	#$17,d6
			beq	XanatosSetFlyTo
			bra	XanatosCheckBackoff


; - Xanatos backs off ---------------------------------------------------------

XanatosCheckBackoff	moveq	#$18,d1
			jsr	TestProxX
			bpl.s	.n
			moveq	#$20,d1
			jsr	TestProxY
			bmi	XanatosSetBackoff
.n			rts

XanatosSetBackoff	move.w	#XanatosBackoffSTATE,OB_State(a0)
			clr.b	OB_Var1a(a0)
			move.b	#4,OB_Var2(a0)
			clr.b	OB_Var2a(a0)
			lea	XanatosIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosBackoffLOGIC	addq.b	#1,OB_Var2a(a0)
			and.b	#7,OB_Var2a(a0)
			bne.s	.1
			subq.b	#1,OB_Var2(a0)
			bmi	XanatosSetAttack
			
.1			moveq	#0,d1
			move.b	OB_Var2(a0),d1
			jsr	MoveGolLeftRightXFLP2
			moveq	#1,d1
			jmp	MoveGolUp_Smooth


; - Xanatos Rocket Attack ---------------------------------------------------------

XanatosSetRocketAttack	move.w	#XanatosRocketAttackSTATE,OB_State(a0)
			clr.b	OB_Var1a(a0)
			clr.w	OB_Var2(a0)
			clr.b	OB_Var3(a0)
			clr.b	OB_EventVar1(a0)
			SFX	98
			move.b	#SteelRocketHitPOWER*2,OB_HitPower(a0)
			jsr	SetBigAttack
			lea	XanatosBigAttackANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosRocketAttkLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.x
			
			addq.b	#1,OB_Var2(a0)
			
			tst.b	OB_Var3(a0)
			beq.s	.acc
			
.dec			and.b	#1,OB_Var2(a0)
			bne.s	.1
			subq.b	#1,OB_Var2a(a0)
			beq	XanatosSetRocketOut
			bra	.1
.acc			move.w	Plr_XPos,d1
			sub.w	OB_Xpos(a0),d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			tst	d1
			bmi.s	.ac1
 			st.b	OB_Var3(a0)
			bra	.ac1
.r			tst	d1
			bpl.s	.ac1
 			st.b	OB_Var3(a0)
.ac1			tst.b	PlayingBOSS
			beq.s	.ac2
    			and.b	#1,OB_Var2(a0)
			bra	.ac3
.ac2			and.b	#3,OB_Var2(a0)
.ac3			bne.s	.1
			addq.b	#1,OB_Var2a(a0)

.1			moveq	#0,d1
			move.b	OB_Var2a(a0),d1
			jsr	MoveGolLeftRightFLP3
.x			rts

; - Xanatos Rocket Attack Out -----------------------------------------------------

XanatosSetRocketOut	move.w	#XanatosRocketOutSTATE,OB_State(a0)
			lea	XanatosBigAttackOutANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosRocketOutLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.x
			KILL	98
			bra	XanatosSetAttack
.x			rts


; - Xanatos Strike Attack ---------------------------------------------------------

XanatosSetStrikeAttack	move.w	#XanatosStrikeAttackSTATE,OB_State(a0)
			clr.b	OB_Var1a(a0)
			SFX	22
			move.b	#SteelSwipeHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			lea	XanatosSmallAttackANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosStrikeAttkLOGIC	tst.l	OB_AnSequence(a0)
			beq	XanatosSetAttack
			rts


; - Xanatos Fire homer -----------------------------------------------------

XanatosSetFireHomer	move.w	#XanatosFireHomerSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			SFX	98
			lea	XanatosFireHomerANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosFireHomerLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.1
			KILL	98
			bra	XanatosSetAttack
			
.1			tst.b	OB_EventVar1(a0)
			beq.s	.x
			clr.b	OB_EventVar1(a0)
			bsr	SetupOrbHead
			bpl.s	.x
			sub.w	#$30,OB_Ypos(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
			sub.w	#$20,OB_Xpos(a1)
			rts
.r			add.w	#$20,OB_Xpos(a1)
.x			rts


; - Xanatos Drop mine -----------------------------------------------------

XanatosSetDropMine	move.w	#XanatosDropMineSTATE,OB_State(a0)
			SFX	22
			clr.b	OB_EventVar1(a0)
			lea	XanatosDropMineANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosDropMineLOGIC	tst.l	OB_AnSequence(a0)
			beq	XanatosSetAttack

			tst.b	OB_EventVar1(a0)
			beq.s	.x
			clr.b	OB_EventVar1(a0)
			bsr	SetupDropMine
			bpl.s	.x
			sub.w	#$20,OB_Ypos(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
			sub.w	#$20,OB_Xpos(a1)
			rts
.r			add.w	#$20,OB_Xpos(a1)
.x			rts


; - Xanatos Fly To ---------------------------------------------------------

XAFTxm			equ	$50
XAFTym			equ	$40
XAFTxms			equ	4
XAFTyms			equ	3

XanatosSetFlyTo		move.w	#XanatosFlyToSTATE,OB_State(a0)
			bsr	DoesNmeFacePlayer
			bpl	XASTT1
XanatosSFT1		bsr	XanatosSetFlyToPos
			clr.w	OB_Var7(a0)
			move.w	#$0101,OB_Var2(a0)
			clr.w	OB_Var3(a0)
			lea	XanatosIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosFlyToLOGIC	addq.b	#1,OB_Var7(a0)
			and.b	#3,OB_Var7(a0)
			bne.s	.xy

.x  			tst.b	OB_Var3(a0)
			beq.s	.xacc
.xdec			tst.b	OB_Var2(a0)
			beq.s	.y
			subq.b	#1,OB_Var2(a0)
			bra	.y
.xacc			cmp.b	#XAFTxms,OB_Var2(a0)
			beq.s	.y
			addq.b	#1,OB_Var2(a0)

.y			tst.b	OB_Var3a(a0)
			beq.s	.yacc
.ydec			tst.b	OB_Var2a(a0)
			beq.s	.xy
			subq.b	#1,OB_Var2a(a0)
			bra	.xy
.yacc			cmp.b	#XAFTyms,OB_Var2a(a0)
			beq.s	.xy
			addq.b	#1,OB_Var2a(a0)

.xy			tst.b	OB_Var2(a0)
			bne	.n1
			tst.b	OB_Var2a(a0)
			bne.s	.n1
			
			tst.b	OB_Var8(a0)
			beq.s	.norm
			jsr	Randy
			cmp.b	#3,OB_Var8(a0)
			bne.s	.aaa
			cmp.b	#XanSTRIKE,OB_Var1a(a0)
			beq.s	.norm
			and.b	#$3,d7
			beq	XanatosSetFireHomer
			and.b	#$1,d6
			beq	XanatosSetDropMine
			bra	.norm
			
.aaa			cmp.b	#1,OB_Var8(a0)
			beq.s	.mine
			cmp.b	#2,OB_Var8(a0)
			bne.s	.norm
.homer			cmp.b	#XanSTRIKE,OB_Var1a(a0)
			beq.s	.norm
			and.b	#$7,d7
			beq	XanatosSetFireHomer
			bra	.norm
.mine			cmp.b	#XanREG,OB_Var1a(a0)
			bne.s	.norm
			and.b	#$1,d6
			beq	XanatosSetDropMine

.norm			tst.b	PlayingBOSS
			bne	XanatosSetAttack
			tst.b	OB_Var1(a0)
			beq	XanatosSetPassive
			bra	XanatosSetAttack
			
.n1			moveq	#0,d2
			move.b	OB_Var2(a0),d2
			move.w	OB_Var4(a0),d1
			tst.b	OB_Var6(a0)
			beq.s	.rte
.lft			sub.w	d2,OB_Xpos(a0)
			cmp.w	OB_Xpos(a0),d1
			blt.s	.o1
			bra.s	.n2
.rte			add.w	d2,OB_Xpos(a0)
			cmp.w	OB_Xpos(a0),d1
			bgt.s	.o1
.n2			tst.b	OB_Var3(a0)
			bne.s	.o1
   			st.b	OB_Var3(a0)

.o1			moveq	#0,d2
			move.b	OB_Var2a(a0),d2
			move.w	OB_Var5(a0),d1
			tst.b	OB_Var6a(a0)
			beq.s	.dn
.up			sub.w	d2,OB_Ypos(a0)
			cmp.w	OB_Ypos(a0),d1
			blt.s	.o2
			bra.s	.n3
.dn			add.w	d2,OB_Ypos(a0)
			cmp.w	OB_Ypos(a0),d1
			bgt.s	.o2
.n3			tst.b	OB_Var3a(a0)
			bne.s	.o2
   			st.b	OB_Var3a(a0)

.o2			tst.b	OB_Var1(a0)
			beq.s	.xx
			tst.b	OB_Var1a(a0)
			beq	XanatosCheckBackoff
.xx			rts


XanREG			equ	0
XanROCK			equ	1
XanSTRIKE		equ	2

XanatosSetFlyToPos	move.w	Plr_XPos,d1   				;set fly to point
			move.w	Plr_YPos,d2
			
			bclr.b	#ob_generic1,OB_Flag6(a0)

			tst.b	PlayingBOSS
			beq.s	.norm
.boss			jsr	Randy
			and.w	#$f,d6
			cmp.w	#2,d6
			blt.s	.RegularL
			cmp.w	#4,d6
			blt.s	.RegularR
			cmp.w	#7,d6
			blt.s	.RocketL
			cmp.w	#10,d6
			blt.s	.RocketR
			cmp.w	#13,d6
			blt.s	.StrikeL
			bra.s	.StrikeR
			rts
.norm			jsr	Randy
			and.w	#$f,d6
			cmp.w	#3,d6
			blt.s	.RegularL
			cmp.w	#6,d6
			blt.s	.RegularR
			cmp.w	#8,d6
			blt.s	.RocketL
			cmp.w	#10,d6
			blt.s	.RocketR
			cmp.w	#13,d6
			blt.s	.StrikeL
			bra.s	.StrikeR
			rts
			
.RegularL		sub.w	#XAFTxm,d1
			sub.w	#XAFTym,d2
			move.b	#XanREG,d3
			bra	.ok
.RegularR		add.w	#XAFTxm,d1
			sub.w	#XAFTym,d2
			move.b	#XanREG,d3
			bra	.ok
.RocketL		sub.w	#XAFTxm+$30,d1
			sub.w	#XAFTym-$40,d2
			move.b	#XanROCK,d3
			bra	.ok
.RocketR		add.w	#XAFTxm+$30,d1
			sub.w	#XAFTym-$40,d2
			move.b	#XanROCK,d3
			bra	.ok
.StrikeL		sub.w	#XAFTxm-$40,d1
			sub.w	#XAFTym-$40,d2
			move.b	#XanSTRIKE,d3
			bra	.ok
.StrikeR		add.w	#XAFTxm-$40,d1
			sub.w	#XAFTym-$40,d2
			move.b	#XanSTRIKE,d3

.ok			move.b	d3,OB_Var1a(a0)
			clr.w	OB_Var6(a0)
			move.w	d1,OB_Var4(a0)
			move.w	d2,OB_Var5(a0)
			cmp.w	OB_Xpos(a0),d1
			bgt.s	.a
			st.b	OB_Var6(a0)
.a			cmp.w	OB_Ypos(a0),d2
			bgt.s	.b
			st.b	OB_Var6a(a0)
.b			rts


; - Xanatos turns to face player ------------------------------------------

XASTT3			PUSHADDRS XanatosSFT3
      			bra	XanatosSetTurnTo
XASTT2			PUSHADDRS XanatosSFT2
      			bra	XanatosSetTurnTo
XASTT1			PUSHADDRS XanatosSFT1

XanatosSetTurnTo	PUSHSTATE
			move.w	#XanatosTurnToSTATE,OB_State(a0)
			lea	XanatosTurnANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

XanatosTurnToLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.1
			eor.b	#_ob_xflp,OB_Flag1(a0)
			POPSTATE
			POPADDRS
			jmp	(a1)
.1			rts



; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MORNING STAR VIKING CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	MornStarGroundZeroSTATE
  		StDEF	MornStarPatrolSTATE
		StDEF	MornStarTurnSTATE
		StDEF	MornStarTurnToSTATE
		StDEF	MornStarIdleSTATE
		StDEF	MornStarWalkToSTATE
		StDEF	MornStarAttackSTATE
		StDEF	MornStarHitSTATE
		StDEF	MornStarDeadSTATE
		StDEF	MornStarThrownSTATE
		StDEF	MornStarThrownReleaseSTATE
		StDEF	MornStarThrownFallSTATE
		StDEF	MornStarThrownLandSTATE
		StDEF	MornStarSlammedSTATE
		StDEF	MornStarRunAwaySTATE

MorningStar_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			bsr	SetStartHeight
			move.l	#MornStarSetHits,OB_HitRoutine(a0)
			move.b	#MorningStarHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			bsr	MornStarSetPatrol
			clr.w	OB_Var8(a0)
			
.1			jsr	ObjectOffBottom
			bgt.s	.ob
			jmp	HandleEnemyKilled
.ob			jsr	HandleBeingHit				;Generic handle hit rout
			jsr	HandleHitTally			
	   		
			btst.b	#ob_dead,OB_Flag2(a0)
			bne.s	.o1
			jsr	GetUnderFEET
			cmp.b	#SB_HotSpot,d2
			beq	MornStarSetDead
			
.o1			move.w	OB_State(a0),d1
			jmp	MornStarLogicTable(pc,d1.w)		;jump table

MornStarLogicTable	bra	MornStarGroundZeroLOGIC
			bra	MornStarPatrolLOGIC
			bra	MornStarTurnLOGIC
			bra	MornStarTurnToLOGIC
			bra	MornStarIdleLOGIC
			bra	MornStarWalkToLOGIC
			bra	MornStarAttackLOGIC
			bra	MornStarHitLOGIC
			bra	MornStarDeadLOGIC
			bra	MornStarThrownLOGIC
			bra	MornStarThrownReleaseLOGIC
			bra	MornStarThrownFallLOGIC
			bra	MornStarThrownLandLOGIC
			bra	MornStarSlammedLOGIC
			bra	MornStarRunAwayLOGIC



DoMornStarAI		move.l	d1,AI_Exclude
			lea	MORNSTAR_AI,a1
			jsr	AI_Routine
			bpl.s	.1
			AddStack 4
			jmp	(a1)
.1			rts


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

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

			btst.b	#ob_dead,OB_Flag2(a0)
			bne	MornStarSetDead
				       
			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	MornStarSetThrown

.1			SFX	16
			
			btst	#ob_hit_small,d2
			bne.s	MornStarSetHit
			btst	#ob_hit_med,d2
			bne.s	MornStarSetHit
			btst	#ob_hit_big,d2
			bne.s	MornStarSetHit
.x			rts

MornStarSetHit		move.w	#MornStarHitSTATE,OB_State(a0)
			move.w	#SmallHitSlideAMT,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			btst.b	#ob_hitside,OB_Flag1(a0)
			bne.s	.1
			bset.b	#ob_xflp,OB_Flag1(a0)
			bra	.2
.1			bclr.b	#ob_xflp,OB_Flag1(a0)
.2			lea	MornStarHitANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MornStarHitLOGIC	jsr	HitSlideObject
			jsr	HandleContours
			bpl	MornStarSetThrownFall
			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	MornStarSetRunAway
			bra	MornStarSetPatrol
.x			rts


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

MornStarSetThrown	move.w	#MornStarThrownSTATE,OB_State(a0)
			move.b	#14,OB_Var4(a0)
			st.b	RapBotThrownFLG
			btst.b	#ob_xflp,Plr_Flag1			;make sure enemy faces right way
			bne.s	.1
			bclr.b	#ob_xflp,OB_Flag1(a0)
			bra	.2
.1			bset.b	#ob_xflp,OB_Flag1(a0)
.2			lea	MornStarGrabANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


MornStarThrownLOGIC	tst.b	GolThrowReleaseFLG
			bne	MornStarSetThrownRelease
			tst.b	GolSlamFLG
			bne	MornStarSetSlammed
			
			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	MornStarSetBounce
.aa			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
			add.w	#8,OB_Ypos(a0)
			rts

MSSB2			move.w	OB_Xpos(a0),d1
			and.w	#$fff0,d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			bne.s	.r
			addq.w	#8,d1
			bra	.o1
.r			subq.w	#8,d1
.o1			move.w	d1,InteruptX	
			move.w	OB_Ypos(a0),InteruptY

MornStarSetBounce	move.w	InteruptX,OB_Xpos(a0)	
			move.w	InteruptY,OB_Ypos(a0)	
			eor.b	#_ob_xflp,OB_Flag1(a0)
			bra	MornStarSetThrownFall


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

MornStarSetThrownRelease	move.w	#MornStarThrownReleaseSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			move.w	#4,OB_Var2(a0)
			lea	MornStarThrownANM,a1			;set anim
			jsr	SetNewAnim

MornStarThrownReleaseLOGIC
			
			jsr	GetUnderNME
			move.b	NUnder,d2
;			or.b	NUnderTOP,d2
			or.b	NUnderBOT,d2
			bmi	MSSB2
			moveq	#0,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			bne.s	.r
.l			move.b	NUnderLEFT,d2
;			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTBOT,d2
			bmi	MSSB2
			bra	.lr	
.r			move.b	NUnderRIGHT,d2
;			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTBOT,d2
			bmi	MSSB2
.lr			moveq	#3,d1
			jsr	MoveGolLeftRightXFLP2
			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	MornStarSetThrownFall
.3			move.w	OB_Var2(a0),d1				;get speed
			jmp	MoveGolUp_Smooth			;move up


; - Morning Star falls from thrown --------------------------------------------

MornStarSetThrownFall	move.w	#MornStarThrownFallSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			rts

MornStarThrownFallLOGIC	jsr	GetUnderNME

			moveq	#0,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			bne.s	.r
.l			move.b	NUnderLEFT,d2
;			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTBOT,d2
			bmi	MSSB2
			bra	.lr	
.r			move.b	NUnderRIGHT,d2
;			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTBOT,d2
			bmi	MSSB2
.lr			moveq	#3,d1
			jsr	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
		
			jsr	MoveGolDown_Smooth
			jsr	TestLand
			bmi	MornStarSetThrownLand
			rts


; - Morning Star lands from thrown --------------------------------------------

MornStarSetThrownLand	move.w	#MornStarThrownLandSTATE,OB_State(a0)
			move.w	#3,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			move.w	#$20,d1
			jsr	MoveGolLeftRightFLP3		
			lea	MornStarThrownLandANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MornStarThrownLandLOGIC	move.w	OB_Var1(a0),d1				;x speed
			beq	MSSD2
			jsr	MoveGolLeftRightXFLP2			;move x
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			jsr	GetUnderLEFTLEFT
			bra	.lr	
.r			jsr	GetUnderRIGHTRIGHT
.lr			tst.b	d2
			bmi.s	.no
			jsr	HandleContours
			bpl.s	.no
			addq.b	#1,OB_Var2(a0)				;slow down x 
			and.b	#7,OB_Var2(a0)
			bne.s	.x
			subq.w	#1,OB_Var1(a0)
.x			rts
.no			clr.w	OB_Var1(a0)
			rts


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

MornStarSetSlammed	move.w	#MornStarSlammedSTATE,OB_State(a0)
			move.b	#4,OB_Var1(a0)
			lea	MornStarSlammedANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
						
MornStarSlammedLOGIC	tst.b	OB_Var1(a0)
			beq.s	.1
			subq.b	#1,OB_Var1(a0)
			bra	.2

.1			jsr	GetUnderFEET
			bsr	PullContourUnder
			bne.s	.aa
			st.b	GolSlamOutFLG
			bra	MornStarSetThrownFall
			
.aa			tst.l	OB_AnSequence(a0)
			bne.s	.2
			lea	MornStarThrownLandANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
			bra	MSSD2			
			
.2			bsr	WallInteruptThrow
			bmi	MornStarSetBounce
			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
			move.w	#$38,d1
			jsr	MoveGolLeftRightFLP3
.x			rts


; - Morning Star Dead -----------------------------------------------

MornStarSetDead		btst.b	#ob_hitside,OB_Flag1(a0)
			bne.s	.1
			bset.b	#ob_xflp,OB_Flag1(a0)
			bra	.2
.1			bclr.b	#ob_xflp,OB_Flag1(a0)
.2			bset.b	#ob_dead,OB_Flag2(a0)
			bsr	VikingDeathSFX
			lea	MornStarDeadANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
MSSD2			clr.b	OB_Var2(a0)
			move.w	#MornStarDeadSTATE,OB_State(a0)
			jmp	HandleEnemyKilled_NOFF
		

MornStarDeadLOGIC	tst.b	OB_Var2(a0)
			beq.s	.y1
   			subq.b	#1,OB_Var2(a0)
			rts

.y1			jsr	GetUnderFEET
			cmp.b	#SB_HotSpot,d2
			bne.s	.n1
			bsr	SpawnFlameLick
			bra	.ok

.n1			move.l	Plr_Database,a1
			cmp.w	#GolFallLandSTATE,OB_State(a1)
			bne.s	.1
			move.w	#$10,d1
			jsr	TestProxY
			bpl.s	.1
			move.w	#$20,d1
			jsr	TestProxX
			bpl.s	.1
			
.ok			move.b	#$18,OB_Var2(a0)
			lea	MornStarSlammedANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
.1			rts


; - Morning Star Ground Zero -----------------------------------------------

MornStarSetGroundZero	move.w	#MornStarGroundZeroSTATE,OB_State(a0)
			lea	MornStarGroundZeroANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MornStarGroundZeroLOGIC	rts


; - Morning Star Patrol -----------------------------------------------

MornStarSetPatrol	move.w	#MornStarPatrolSTATE,OB_State(a0)
			jsr	ClrHitStuff
			clr.b	OB_MasterMode(a0)
			lea	MornStarWalkANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MornStarPatrolLOGIC	move.l	#MornStarSetPatrol,d1
			bsr	DoMornStarAI
			
			jsr	Randy
			and.w	#$1ff,d6
			beq	MornStarSetIdle
			cmp.w	#1,d6
			beq	MornStarSetTurn

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

.lft			jsr	GetUnderLEFTLEFT
			bra	.lr
.rte			jsr	GetUnderRIGHTRIGHT		
.lr			cmp.b	#SB_ForceTurn,d2
			beq	MornStarSetTurn
			jsr	TestLevelWalls	
			bmi	MornStarSetTurn
			moveq	#1,d1
			jsr	MoveGolLeftRightFLP
			jsr	CheckScreenBoundsX		;turn at screen bounds	
			bmi	MornStarSetTurn
			jmp	HandleContours			;handle the contours


; - Morning Star turn ---------------------------------------------------------

MornStarSetTurn		move.w	#MornStarTurnSTATE,OB_State(a0)
			lea	MornStarTurnANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MornStarTurnLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.a
			eor.b	#_ob_xflp,OB_Flag1(a0)
			bra	MornStarSetPatrol
.a			rts


; - Morning Star idle ---------------------------------------------------------

MornStarSetIdle1	cmp.l	#ANM_MornStarIdle,OB_AnSequence(a0)
			beq.s	MSSI2
			lea	MornStarGroundZeroANM,a1			;set anim
			jsr	SetNewAnim
			bra	MSSI1
MornStarSetIdle		cmp.l	#ANM_MornStarIdle,OB_AnSequence(a0)
			beq.s	MSSI2
			jsr	Randy
			and.w	#$1,d6
			beq	MornStarSetRunAway
			lea	MornStarIdleANM,a1			;set anim
			jsr	SetNewAnim
MSSI1			jsr	ForceNewAnim
MSSI2			bsr	DoesNmeFacePlayer			;if nme doesn't face plr 
			bpl	MornStarSetTurn				;nme turns
			move.w	#$30,d1
			jsr	TestProxX
			bmi	MSSA2
			move.w	#MornStarIdleSTATE,OB_State(a0)
			jsr	Randy
			and.b	#$f,d6
			or.b	#$10,d6
			move.b	d6,OB_Var1(a0)
			clr.b	OB_MasterMode(a0)
			jmp	ClrHitStuff

MornStarIdleLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.x
			
			subq.b	#1,OB_Var1(a0)
			beq	MornStarSetWalkTo
			
			move.l	#-1,AI_Exclude
			lea	MORNSTAR_AI2,a1
			jsr	AI_Routine
			bpl.s	.x
			jmp	(a1)
.x			rts


; - After Morning Star sees Player --------------------------------------------
; - Morning Star Walk to player Logic -----------------------------------------

MornStarSetWalkTo	move.w	#MornStarWalkToSTATE,OB_State(a0)
			clr.b	OB_Var1(a0)
			bsr	DoesNmeFacePlayer
			bpl	MSSTT1
MornStarSWT1		jsr	ClrHitStuff
			lea	MornStarWalkANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim

MornStarWalkToLOGIC	move.l	#MornStarSetWalkTo,d1
			bsr	DoMornStarAI

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

.2			

MornStarWalk		btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte
.lft			jsr	GetUnderLEFTLEFT		;stop at wall	
			cmp.b	#SB_ForceTurn,d2
			beq	MornStarSetIdle
			jsr	TestLevelWalls	
			bmi	MornStarSetIdle
			moveq	#2,d1
			jsr	MoveGolLeft_Smooth
			jmp	HandleContours			;handle the contours
			
.rte			jsr	GetUnderRIGHTRIGHT		;stop at wall
			cmp.b	#SB_ForceTurn,d2
			beq	MornStarSetIdle
			jsr	TestLevelWalls	
			bmi	MornStarSetIdle
			moveq	#2,d1
			jsr	MoveGolRight_Smooth
			jmp	HandleContours			;handle the contours


; - Morning Star Turn to Face Player Logic --------------------------------------------------

MSSTT1			PUSHADDRS MornStarSWT1

MornStarSetTurnTo	PUSHSTATE
			move.w	#MornStarTurnToSTATE,OB_State(a0)
			lea	MornStarTurnANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

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


; - Morning Star Attack --------------------------------------------------

MornStarSetAttack	btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			jsr	GetUnderLEFTFEET
			bsr	PullContourUnder	
			beq	MornStarSetIdle
			jsr	GetUnderLEFTLEFTFEET
			bsr	PullContourUnder	
			beq	MornStarSetIdle
			jsr	GetUnderLEFT
			jsr	TestLevelWalls	
			bmi	MornStarSetIdle
			jsr	GetUnderLEFTLEFT
			jsr	TestLevelWalls	
			bmi	MornStarSetIdle
			bra	MSSA2
.r			jsr	GetUnderRIGHTFEET
			bsr	PullContourUnder	
			beq	MornStarSetIdle
			jsr	GetUnderRIGHTRIGHTFEET
			bsr	PullContourUnder	
			beq	MornStarSetIdle
			jsr	GetUnderRIGHT
			jsr	TestLevelWalls	
			bmi	MornStarSetIdle
			jsr	GetUnderRIGHTRIGHT
			jsr	TestLevelWalls	
			bmi	MornStarSetIdle

MSSA2			move.w	#MornStarAttackSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			clr.b	OB_EventVar2(a0)
			SFX	20
			lea	MornStarAttackANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MornStarAttackLOGIC	tst.b	OB_EventVar2(a0)
			beq.s	.11
			clr.b	OB_EventVar2(a0)
			KILL	33
			SFX	33

.11			tst.b	OB_EventVar1(a0)
			beq.s	.2
			clr.b	OB_EventVar1(a0)
			moveq	#$20,d1
			jsr	MoveGolLeftRightFLP3
			jsr	GetUnderFEET
			jsr	SetHeight
			eor.b	#_ob_xflp,OB_Flag1(a0)
.2			tst.l	OB_AnSequence(a0)
			bne.s	.1
			jsr	Randy
			and.w	#1,d6
			bne	MornStarSetIdle1
			bra	MornStarSetIdle
.1			rts


; - Morning Star Attack --------------------------------------------------

MornStarSetRunAway	move.w	#MornStarRunAwaySTATE,OB_State(a0)
			jsr	AITestPlrOnLeft
			bpl.s	.r
			bclr.b	#ob_xflp,OB_Flag1(a0)
			bra	.1
.r			bset.b	#ob_xflp,OB_Flag1(a0)
.1			move.b	#$20,OB_Var1(a0)
			lea	MornStarWalkANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
MornStarRunAwayLOGIC	subq.b	#1,OB_Var1(a0)	
			beq	MornStarSetIdle
			bra	MornStarWalk


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί ARCHER VIKING CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	ArcherIdleSTATE
		StDEF	ArcherShootSTATE
		StDEF	ArcherReloadSTATE
		StDEF	ArcherHitSTATE
		StDEF	ArcherDeadSTATE
		StDEF	ArcherThrownSTATE
		StDEF	ArcherThrownReleaseSTATE
		StDEF	ArcherThrownFallSTATE
		StDEF	ArcherThrownLandSTATE
		StDEF	ArcherSlammedSTATE
				       
Archer_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
			bsr	SetStartHeight
			bset.b	#ob_setup,OB_Flag2(a0)
			move.l	#ArcherSetHits,OB_HitRoutine(a0)
			jsr	SetMediumAttack
			bsr	ArcherSetIdle
			clr.w	OB_Var8(a0)
			
.1			jsr	ObjectOffBottom
			bgt.s	.ob
			jmp	HandleEnemyKilled
.ob			jsr	HandleBeingHit				;Generic handle hit rout
			
			move.w	OB_State(a0),d1
			jmp	ArcherLogicTable(pc,d1.w)		;jump table


ArcherLogicTable	bra	ArcherIdleLOGIC
			bra	ArcherShootLOGIC
			bra	ArcherReloadLOGIC
			bra	ArcherHitLOGIC
			bra	ArcherDeadLOGIC
			bra	ArcherThrownLOGIC
			bra	ArcherThrownReleaseLOGIC
			bra	ArcherThrownFallLOGIC
			bra	ArcherThrownLandLOGIC
			bra	ArcherSlammedLOGIC


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

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

			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	ArcherSetThrown

.1			SFX	16

			btst	#ob_hit_small,d2
			bne.s	ArcherSetHit
			btst	#ob_hit_med,d2
			bne.s	ArcherSetHit
			btst	#ob_hit_big,d2
			bne.s	ArcherSetHit
			rts

ArcherSetHit		move.w	#ArcherHitSTATE,OB_State(a0)
			move.w	#SmallHitSlideAMT,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			lea	ArcherHitANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ArcherHitLOGIC		jsr	HitSlideObject
    			jsr	HandleContours
			bpl	ArcherSetThrownFall
			tst.l	OB_AnSequence(a0)
			beq	ArcherSetDead
			rts


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

ArcherSetThrown		move.w	#ArcherThrownSTATE,OB_State(a0)
			move.b	#10,OB_Var4(a0)
			st.b	RapBotThrownFLG
			btst.b	#ob_xflp,Plr_Flag1			;make sure enemy faces right way
			beq.s	.1
			bclr.b	#ob_xflp,OB_Flag1(a0)
			bra	.2
.1			bset.b	#ob_xflp,OB_Flag1(a0)
.2			lea	ArcherGrabANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


ArcherThrownLOGIC	tst.b	GolThrowReleaseFLG
			bne	ArcherSetThrownRelease
			tst.b	GolSlamFLG
			bne	ArcherSetSlammed
			
			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	ArcherSetBounce
.aa			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
			add.w	#8,OB_Ypos(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			sub.w	#$10,OB_Xpos(a0)
			rts
.r			add.w	#$10,OB_Xpos(a0)
			rts

ASB2			move.w	OB_Xpos(a0),d1
			and.w	#$fff0,d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
			addq.w	#8,d1
			bra	.o1
.r			subq.w	#8,d1
.o1			move.w	d1,InteruptX	
			move.w	OB_Ypos(a0),InteruptY

ArcherSetBounce		move.w	InteruptX,OB_Xpos(a0)	
			move.w	InteruptY,OB_Ypos(a0)	
			eor.b	#_ob_xflp,OB_Flag1(a0)
			bra	ArcherSetThrownFall


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

ArcherSetThrownRelease	move.w	#ArcherThrownReleaseSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			move.w	#4,OB_Var2(a0)
			lea	ArcherThrownANM,a1			;set anim
			jmp	SetNewAnim
			
ArcherThrownReleaseLOGIC
			jsr	GetUnderNME
			move.b	NUnder,d2
;			or.b	NUnderTOP,d2
			or.b	NUnderBOT,d2
			bmi	ASB2
			moveq	#0,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			move.b	NUnderLEFT,d2
;			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTBOT,d2
			bmi	ASB2
			bra	.lr	
.r			move.b	NUnderRIGHT,d2
;			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTBOT,d2
			bmi	ASB2
.lr			moveq	#3,d1
			jsr	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	ArcherSetThrownFall
.3			move.w	OB_Var2(a0),d1				;get speed
			jmp	MoveGolUp_Smooth			;move up


; - Morning Star falls from thrown --------------------------------------------

ArcherSetThrownFall	move.w	#ArcherThrownFallSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			lea	ArcherThrownFallANM,a1			;set anim
			jmp	SetNewAnim

ArcherThrownFallLOGIC	jsr	GetUnderNME
			
			moveq	#0,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			move.b	NUnderLEFT,d2
;			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTBOT,d2
			bmi	ASB2
			bra	.lr	
.r			move.b	NUnderRIGHT,d2
;			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTBOT,d2
			bmi	ASB2
.lr			moveq	#3,d1
			jsr	MoveGolLeftRightFLP3		

			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
		
			jsr	MoveGolDown_Smooth
			jsr	TestLand
			bmi	ArcherSetThrownLand
			rts


; - Morning Star lands from thrown --------------------------------------------

ArcherSetThrownLand	move.w	#ArcherThrownLandSTATE,OB_State(a0)
			move.w	#3,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			lea	ArcherThrownLandANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ArcherThrownLandLOGIC	move.w	OB_Var1(a0),d1				;x speed
			beq	ASD2
			jsr	MoveGolLeftRightFLP3			;move x
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			jsr	GetUnderLEFT
			bra	.lr	
.r			jsr	GetUnderRIGHT
.lr			tst.b	d2
			bmi.s	.no
			jsr	HandleContours
			bpl.s	.no
			addq.b	#1,OB_Var2(a0)				;slow down x 
			and.b	#7,OB_Var2(a0)
			bne.s	.x
			subq.w	#1,OB_Var1(a0)
.x			rts
.no			clr.w	OB_Var1(a0)
			rts


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

ArcherSetSlammed	move.w	#ArcherSlammedSTATE,OB_State(a0)
			move.b	#4,OB_Var1(a0)
			lea	ArcherSlammedANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
						
ArcherSlammedLOGIC	tst.b	OB_Var1(a0)
			beq.s	.1
			subq.b	#1,OB_Var1(a0)
			bra	.2

.1			jsr	GetUnderFEET
			jsr	PullContourUnder
			bne.s	.aa
			st.b	GolSlamOutFLG
			bra	ArcherSetThrownFall
			
.aa			tst.l	OB_AnSequence(a0)
			bne.s	.2
			lea	ArcherThrownLandANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
			bra	ASD2			
			
.2			bsr	WallInteruptThrow
			bmi	ArcherSetBounce
			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
.x			rts


; - Morning Star Dead -----------------------------------------------

ArcherSetDead		bsr	VikingDeathSFX
			lea	ArcherDeadANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
ASD2			move.w	#ArcherDeadSTATE,OB_State(a0)
			jmp	HandleEnemyKilled_NOFF

ArcherDeadLOGIC		rts


; - Archer idle ---------------------------------------------------------

ArcherSetIdle		move.w	#ArcherIdleSTATE,OB_State(a0)
			jsr	MakeNmeFacePlayer
			lea	ArcherIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ArcherIdleLOGIC		tst.l	OB_AnSequence(a0)
			beq.s	.ok
			rts
.ok			move.l	#ArcherSetIdle,AI_Exclude
			lea	ARCHER_AI2,a1
			jsr	AI_Routine
			bpl.s	.1
			jmp	(a1)
.1			lea	ArcherIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


; - Archer shooting ---------------------------------------------------------

ArcherSetShootUp	move.w	#ArcherShootSTATE,OB_State(a0)
			clr.b	OB_Var1(a0)
			lea	ArcherShootUpANM,a1			;set anim
			bra	ASS1
ArcherSetShootStraight	move.w	#ArcherShootSTATE,OB_State(a0)
			move.b	#1,OB_Var1(a0)
			lea	ArcherShootStrANM,a1			;set anim
			bra	ASS1
ArcherSetShootDown	move.w	#ArcherShootSTATE,OB_State(a0)
			move.b	#2,OB_Var1(a0)
			lea	ArcherShootDownANM,a1			;set anim
ASS1			clr.b	OB_EventVar1(a0)
			jsr	SetNewAnim
			jmp	ForceNewAnim

ArcherShootLOGIC	tst.b	OB_EventVar1(a0)
			beq	.1
			clr.b	OB_EventVar1(a0)
			
			SFX	112
			
			move.l	a0,-(sp)				;setup arrow
			SPAWN_LO	Arrow_MAX_Size
			bpl.s	.no
			move.w	#Arrow_OB,OB_Type(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			move.l	a0,a1
			move.l	(sp)+,a0
			jsr	SetFlipFromMother
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.b	OB_Var1(a0),OB_Var1(a1)
			move.b	#8,OB_Var5(a1)
			move.b	#ArrowHitPOWER,OB_HitPower(a1)
			jsr	SetSmallAttackA1
			tst.b	OB_Var1(a0)
			beq.s	.a
			cmp.b	#1,OB_Var1(a0)
			beq.s	.b
.c			sub.w	#$24,OB_Ypos(a1)
			lea	ArrowDownANM,a2
			bra	.d
.b			sub.w	#$18,OB_Ypos(a1)
			lea	ArrowStraightANM,a2
			bra	.d
.a			sub.w	#$1c,OB_Ypos(a1)
			lea	ArrowUpANM,a2
.d			jsr	SetNewAnimA1			
			jmp	ForceNewAnimA1			
.no			move.l	(sp)+,a0
			rts

.1			tst.l	OB_AnSequence(a0)	
			beq	ArcherSetReload
			rts

; - Archer reloads ---------------------------------------------------------

ArcherSetReload		move.w	#ArcherReloadSTATE,OB_State(a0)
			lea	ArcherReloadANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ArcherReloadLOGIC	tst.l	OB_AnSequence(a0)
			beq	ArcherSetIdle
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί ARCHER VIKING ARROW CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Arrow_Logic		tst.b	OB_Var5(a0)
			beq.s	.tst
    			subq.b	#1,OB_Var5(a0)
			bra	.ok
.tst			btst.b	#ob_hitting,OB_Flag1(a0)
			bne.s	.off
			jsr	GetUnderFEET
			tst.b	d2
			bmi.s	.off
			bsr	PullContourUnder
			beq.s	.ok
.off			jmp	SwitchObjectOff

.ok			moveq	#6,d1
			jsr	MoveGolLeftRightFLP3
			tst.b	OB_Var1(a0)
			beq.s	.up
			cmp.b	#2,OB_Var1(a0)
			beq.s	.down
			rts
.up			moveq	#3,d1
			jmp	MoveGolUp_Smooth
.down			moveq	#3,d1
			jmp	MoveGolDown_Smooth


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί VALKYRIE CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	ValkIdleSTATE
		StDEF	ValkAxeThrowSTATE
		StDEF	ValkAxeCatchSTATE
		StDEF	ValkShieldSTATE
		StDEF	ValkShieldOutSTATE
		StDEF	ValkTurnSTATE
		StDEF	ValkIdleAttackSTATE
		StDEF	ValkShieldAttackSTATE
		StDEF	ValkHitSTATE
		StDEF	ValkDeadSTATE
		StDEF	ValkDeadWaitSTATE
		StDEF	ValkFallSTATE
		StDEF	ValkThrownSTATE
		StDEF	ValkThrownReleaseSTATE
		StDEF	ValkThrownFallSTATE
		StDEF	ValkThrownLandSTATE
		StDEF	ValkSlammedSTATE
				       

Valkyrie_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			bsr	SetStartHeight
			move.l	#ValkSetHits,OB_HitRoutine(a0)
			jsr	GetUnderFEET	
			bsr	SetHeight
			bsr	ValkSetIdle
			
.1			jsr	ObjectOffBottom
			bgt.s	.ob
			jmp	HandleEnemyKilled
.ob			jsr	HandleBeingHit				;Generic handle hit rout
			
			btst.b	#ob_dead,OB_Flag2(a0)
			bne.s	.o1
			cmp.w	#ValkDeadSTATE,OB_State(a0)
			beq.s	.o1
			cmp.w	#ValkDeadWaitSTATE,OB_State(a0)
			beq.s	.o1
			jsr	GetUnderFEET
			cmp.b	#SB_HotSpot,d2
			beq	ValkSetDead
			
.o1			move.w	OB_State(a0),d1
			jmp	ValkLogicTable(pc,d1.w)		;jump table


ValkLogicTable		bra	ValkIdleLOGIC
			bra	ValkAxeThrowLOGIC
			bra	ValkAxeCatchLOGIC
			bra	ValkShieldLOGIC
			bra	ValkShieldOutLOGIC
			bra	ValkTurnLOGIC
			bra	ValkIdleAttackLOGIC
			bra	ValkShieldAttackLOGIC
			bra	ValkHitLOGIC
			bra	ValkDeadLOGIC
			bra	ValkDeadWaitLOGIC
			bra	ValkFallLOGIC
			bra	ValkThrownLOGIC
			bra	ValkThrownReleaseLOGIC
			bra	ValkThrownFallLOGIC
			bra	ValkThrownLandLOGIC
			bra	ValkSlammedLOGIC

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

ValkSetHits		move.b	OB_Flag6(a0),d2
			jsr	ClrHitStuff
			
			btst.b	#ob_dead,OB_Flag2(a0)
			bne	ValkSetDead

			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	ValkSetThrown

.1			btst	#ob_hit_small,d2
			bne.s	ValkSetHit
			btst	#ob_hit_med,d2
			bne.s	ValkSetHit
			btst	#ob_hit_big,d2
			bne.s	ValkSetHit
			rts

ValkSetHit		cmp.w	#ValkShieldSTATE,OB_State(a0)
			beq	ValkSetHitByHawkDive
			
			SFX	23
			
			move.w	#ValkHitSTATE,OB_State(a0)
			move.w	#SmallHitSlideAMT,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			lea	ValkHitANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ValkHitLOGIC		jsr	HitSlideObject
			jsr	HandleContours
			bpl	ValkSetFall
			tst.l	OB_AnSequence(a0)
			beq	ValkSetIdle
			rts

ValkSetHitByHawkDive	move.w	#ValkHitSTATE,OB_State(a0)
			move.w	#4,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			SFX	104
			lea	ValkHitByHawkDiveANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


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

ValkSetThrown		move.w	#ValkThrownSTATE,OB_State(a0)
			SFX	23
			move.b	#10,OB_Var4(a0)
			st.b	RapBotThrownFLG
			btst.b	#ob_xflp,Plr_Flag1			;make sure enemy faces right way
			beq.s	.1
			bclr.b	#ob_xflp,OB_Flag1(a0)
			bra	.2
.1			bset.b	#ob_xflp,OB_Flag1(a0)
.2			lea	ValkGrabANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


ValkThrownLOGIC		tst.b	GolThrowReleaseFLG
			bne	ValkSetThrownRelease
			tst.b	GolSlamFLG
			bne	ValkSetSlammed
			
			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	ValkSetBounce
.aa			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
			add.w	#8,OB_Ypos(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			sub.w	#$10,OB_Xpos(a0)
			rts
.r			add.w	#$10,OB_Xpos(a0)
			rts

VSB2			move.w	OB_Xpos(a0),d1
			and.w	#$fff0,d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
			addq.w	#8,d1
			bra	.o1
.r			subq.w	#8,d1
.o1			move.w	d1,InteruptX	
			move.w	OB_Ypos(a0),InteruptY

ValkSetBounce		move.w	InteruptX,OB_Xpos(a0)	
			move.w	InteruptY,OB_Ypos(a0)	
			eor.b	#_ob_xflp,OB_Flag1(a0)
			bra	ValkSetThrownFall


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

ValkSetThrownRelease	move.w	#ValkThrownReleaseSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			move.w	#4,OB_Var2(a0)
			SFX	99
			lea	ValkThrownANM,a1			;set anim
			jmp	SetNewAnim
			
ValkThrownReleaseLOGIC	jsr	GetUnderNME
			move.b	NUnder,d2
;			or.b	NUnderTOP,d2
			or.b	NUnderBOT,d2
			bmi	VSB2
			moveq	#0,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			move.b	NUnderLEFT,d2
;			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTBOT,d2
			bmi	VSB2
			bra	.lr	
.r			move.b	NUnderRIGHT,d2
;			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTBOT,d2
			bmi	VSB2
.lr			moveq	#3,d1
			jsr	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	ValkSetThrownFall
.3			move.w	OB_Var2(a0),d1				;get speed
			jmp	MoveGolUp_Smooth			;move up


; - Morning Star falls from thrown --------------------------------------------

ValkSetThrownFall	move.w	#ValkThrownFallSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			lea	ValkThrownFallANM,a1			;set anim
			jmp	SetNewAnim

ValkThrownFallLOGIC	jsr	GetUnderNME
			
			moveq	#0,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			move.b	NUnderLEFT,d2
;			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTBOT,d2
			bmi	VSB2
			bra	.lr	
.r			move.b	NUnderRIGHT,d2
;			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTBOT,d2
			bmi	VSB2
.lr			moveq	#3,d1
			jsr	MoveGolLeftRightFLP3		

			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
		
			jsr	MoveGolDown_Smooth
			jsr	TestLand
			bmi	ValkSetThrownLand
			rts


; - Morning Star lands from thrown --------------------------------------------

ValkSetThrownLand	move.w	#ValkThrownLandSTATE,OB_State(a0)
			move.w	#3,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			lea	ValkThrownLandANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ValkThrownLandLOGIC	move.w	OB_Var1(a0),d1				;x speed
			beq	VSD2
			jsr	MoveGolLeftRightFLP3			;move x
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			jsr	GetUnderLEFT
			bra	.lr	
.r			jsr	GetUnderRIGHT
.lr			tst.b	d2
			bmi.s	.no
			jsr	HandleContours
			bpl.s	.no
			addq.b	#1,OB_Var2(a0)				;slow down x 
			and.b	#7,OB_Var2(a0)
			bne.s	.x
			subq.w	#1,OB_Var1(a0)
.x			rts
.no			clr.w	OB_Var1(a0)
			rts


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

ValkSetSlammed		move.w	#ValkSlammedSTATE,OB_State(a0)
			move.b	#4,OB_Var1(a0)
			SFX	99
			lea	ValkSlammedANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
						
ValkSlammedLOGIC	tst.b	OB_Var1(a0)
			beq.s	.1
			subq.b	#1,OB_Var1(a0)
			bra	.2

.1			jsr	GetUnderFEET
			jsr	PullContourUnder
			bne.s	.aa
			st.b	GolSlamOutFLG
			bra	ValkSetThrownFall
			
.aa			tst.l	OB_AnSequence(a0)
			bne.s	.2
			lea	ValkThrownLandANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
			bra	VSD2			
			
.2			bsr	WallInteruptThrow
			bmi	ValkSetBounce
			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
.x			rts


; - Valkyrie falls -----------------------------------------------

ValkSetFall		move.w	#ValkFallSTATE,OB_State(a0)
			clr.w	OB_Var2(a0)
			clr.w	OB_Yspd(a0)
			lea	ValkFallANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
						
ValkFallLOGIC		moveq	#2,d1
			jsr	MoveGolLeftRightXFLP2
			jsr	GolAccelerateDown
			jsr	TestLand
			bmi	ValkSetDead
			rts


; - Valkyrie Dead -----------------------------------------------

ValkSetDead		lea	ValkDeadANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
			SFX	99
			move.w	#SmallHitSlideAMT,OB_Var1(a0)
VSD2			move.w	#ValkDeadSTATE,OB_State(a0)
			rts

ValkDeadLOGIC		jsr	HitSlideObject
			jsr	HandleContours
			bpl	ValkSetFall
			tst.l	OB_AnSequence(a0)
			beq	ValkSetDeadWait
			rts


ValkSetDeadWait		move.w	#ValkDeadWaitSTATE,OB_State(a0)
			jmp	HandleEnemyKilled_NOFF

ValkDeadWaitLOGIC	addq.b	#1,OB_Var2(a0)
			and.b	#$1f,OB_Var2(a0)
			bne.s	.x
			jsr	GetUnderFEET
			cmp.b	#SB_HotSpot,d2
			bne.s	.x
			tst.l	OB_AnSequence(a0)
			bne	SpawnFlameLick
			lea	ValkBurnANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
			bra	SpawnFlameLick
.x			rts


; - Valk idle ---------------------------------------------------------

ValkSetIdle		move.w	#ValkIdleSTATE,OB_State(a0)
			bsr	DoesNmeFacePlayer
			bpl	VSTT1
ValkSWT1		lea	ValkIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ValkIdleLOGIC		move.l	#ValkSetIdle,AI_Exclude
			lea	VALK_AI2,a1
			jsr	AI_Routine
			bpl.s	.1
			jmp	(a1)
.1			rts
			lea	ValkIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


; - Valk throwing axe ---------------------------------------------------------

ValkSetAxeThrow		tst.b	OB_Var7(a0)
			bne	ValkSetIdle			
			move.w	#ValkAxeThrowSTATE,OB_State(a0)
			clr.b	OB_Var1(a0)
			clr.b	OB_EventVar1(a0)
			lea	ValkAxeThrowANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ValkAxeThrowLOGIC	tst.b	OB_EventVar1(a0)
			beq	.1
			clr.b	OB_EventVar1(a0)
			SFX	32
			move.l	a0,-(sp)				;setup arrow
			SPAWN_HI	Axe_MAX_Size
			bpl.s	.no
			move.w	#Axe_OB,OB_Type(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			move.l	a0,a1
			move.l	(sp)+,a0
			jsr	SetFlipFromMother
			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	.r
.l			st.b	OB_Var1(a1)
			sub.w	#$10,OB_Xpos(a1)
			bra	.o1
.r			clr.b	OB_Var1(a1)
			add.w	#$10,OB_Xpos(a1)
.o1			sub.w	#$10,OB_Ypos(a1)
;			move.w	Plr_XPos,d1
;			sub.w	OB_Xpos(a1),d1
;			bpl.s	.a
;			neg.w	d1
;.a			lsr.w	#5,d1
;			addq.w	#2,d1
;			move.w	d1,OB_Var3(a1)			;speed
			move.l	a0,OB_Task(a1)			;spawning objects number
			move.l	a1,OB_Task(a0)			;spawning objects number
			rts
.no			move.l	(sp)+,a0
			rts

.1			tst.l	OB_AnSequence(a0)	
			beq	ValkSetAxeCatch
			rts


; - Valk catch axe ---------------------------------------------------------

ValkSetAxeCatch		move.w	#ValkAxeCatchSTATE,OB_State(a0)
			st.b	OB_Var7(a0)
			clr.b	OB_Var7a(a0)			;flag axe thrown

ValkAxeCatchLOGIC	tst.b	OB_Var7a(a0)
			bne.s	.wait
			tst.b	OB_Var7(a0)
			bne.s	.x
			st.b	OB_Var7a(a0)
			lea	ValkAxeCatchANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
.wait			tst.l	OB_AnSequence(a0)
			beq	ValkSetIdle
.x			rts


; - Valkyrie shields up ----------------------------------------------------

ValkSetShield		move.w	#ValkShieldSTATE,OB_State(a0)
			bsr	DoesNmeFacePlayer
			bpl	VSTT2
ValkSWT2		lea	ValkShieldANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ValkShieldLOGIC		tst.l	OB_AnSequence(a0)
			beq.s	.ok
			rts
.ok			move.l	#ValkSetShield,AI_Exclude
			lea	VALK_AI3,a1
			jsr	AI_Routine
			bpl.s	.1
			jmp	(a1)
.1			rts


; - Valkyrie shields down ----------------------------------------------------

ValkSetShieldOut	move.w	#ValkShieldOutSTATE,OB_State(a0)
			lea	ValkShieldOutANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ValkShieldOutLOGIC	tst.l	OB_AnSequence(a0)
			beq	ValkSetIdle
			rts


; - Valkyrie turn ----------------------------------------------------
			   
VSTT2			PUSHADDRS ValkSWT2
     			bra	ValkSetTurn
VSTT1			PUSHADDRS ValkSWT1

ValkSetTurn		PUSHSTATE
			move.w	#ValkTurnSTATE,OB_State(a0)
			lea	ValkTurnANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ValkTurnLOGIC		tst.l	OB_AnSequence(a0)
			bne.s	.1
			eor.b	#_ob_xflp,OB_Flag1(a0)
			POPSTATE
			POPADDRS
			jmp	(a1)
.1			rts						


; - Valkyrie Attack from idle ----------------------------------------------------

ValkSetIdleAttack	move.w	#ValkIdleAttackSTATE,OB_State(a0)
			SFX	33
			move.b	#ValkAxeAttkHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			lea	ValkAttackFromIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ValkIdleAttackLOGIC	tst.l	OB_AnSequence(a0)
			beq	ValkSetIdle
			rts


; - Valkyrie attack with shield ----------------------------------------------------

ValkSetShieldAttack	move.w	#ValkShieldAttackSTATE,OB_State(a0)
			SFX	33
			move.b	#ValkShieldHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			lea	ValkShieldAttackANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

ValkShieldAttackLOGIC	tst.l	OB_AnSequence(a0)
			beq	ValkSetShield
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί VALKYRIE AXE CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Axe_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.l	#ValkAxeOffRoutine,OB_OffRoutine(a0)
			move.w	Plr_XPos,d1
			jsr	AITestPlrOnLeft
			bpl.s	.r
.l   			sub.w	#$10,d1
			bra	.lr
.r			add.w	#$10,d1
.lr			move.w	d1,TargetX
			move.w	Plr_YPos,d1
			sub.w	#$30,d1
			move.w	d1,TargetY
			jsr	TrajectorySetup
			clr.w	OB_Var5(a0)
			clr.w	OB_Var6(a0)
			move.b	#ValkAxeProjHitPOWER,OB_HitPower(a0)
			bset.b	#ob_nooff,OB_Flag2(a0)
			jsr	SetMediumAttack
			lea	ValkAxeANM,a1
			jsr	SetNewAnim			
			jmp	ForceNewAnim			
			
.ok			moveq	#5,d1
			jsr	TrajectoryMove

			jsr	GetUnder
			jsr	TestLevelWalls
			bpl.s	.y1
			tst.b	OB_Var6(a0)
			beq.s	.return
			bra.s	.fin
			
.y1			tst.b	OB_Var5(a0)
			beq.s	.1
			tst.b	OB_Var5a(a0)
			beq.s	.1
			tst.b	OB_Var6(a0)
			bne.s	.fin
.return			st.b	OB_Var6(a0)
			clr.w	OB_Var5(a0)
			move.l	OB_Task(a0),a1	
			move.w	OB_Xpos(a1),TargetX
			move.w	OB_Ypos(a1),d1
			sub.w	#$28,d1
			move.w	d1,TargetY
			jmp	TrajectorySetup
			
.1			jmp	TrajectoryHit
			
.fin			move.l	OB_Task(a0),a1	
			clr.b	OB_Var7(a1)
			jmp	SwitchObjectOff

ValkAxeOffRoutine	move.l	OB_Task(a0),a1	
			clr.b	OB_Var7(a1)
			rts

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί WEAPONS EXPERT VIKING CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	WeapExpIdleSTATE
		StDEF	WeapExpPourSTATE
		StDEF	WeapExpHitSTATE
		StDEF	WeapExpDeadSTATE
		StDEF	WeapExpThrownSTATE
		StDEF	WeapExpThrownReleaseSTATE
		StDEF	WeapExpThrownFallSTATE
		StDEF	WeapExpThrownLandSTATE
		StDEF	WeapExpSlammedSTATE
				       
WeapExp_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			bsr	SetStartHeight
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rr
.ll			addq.w	#6,OB_Xpos(a0)
  			bra.s	.llrr
.rr			subq.w	#6,OB_Xpos(a0)
.llrr			clr.w	OB_Var6(a0)
			move.l	#WeapExpSetHits,OB_HitRoutine(a0)
			bsr	WeapExpSetIdle

			movem.l	a0/d0,-(sp)
			SPAWN_HI	Couldron_MAX_Size
			bpl.s	.2
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			jsr	SetFlipFromMother
			move.w	#Couldron_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			sub.w	#$28,d1
			bra	.lr
.r			add.w	#$28,d1
.lr			move.w	d1,OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.l	a0,OB_Task(a1)
			move.l	a1,OB_Task(a0)
			rts
.2			movem.l	(sp)+,d0/a0
			rts

.1			jsr	ObjectOffBottom
			bgt.s	.ob
			jmp	HandleEnemyKilled
.ob			jsr	HandleBeingHit				;Generic handle hit rout
			
			move.w	OB_State(a0),d1
			jmp	WeapExpLogicTable(pc,d1.w)		;jump table


WeapExpLogicTable	bra	WeapExpIdleLOGIC
			bra	WeapExpPourLOGIC
			bra	WeapExpHitLOGIC
			bra	WeapExpDeadLOGIC
			bra	WeapExpThrownLOGIC
			bra	WeapExpThrownReleaseLOGIC
			bra	WeapExpThrownFallLOGIC
			bra	WeapExpThrownLandLOGIC
			bra	WeapExpSlammedLOGIC


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

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

			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	WeapExpSetThrown

.1			SFX	16
			btst	#ob_hit_small,d2
			bne.s	WeapExpSetHit
			btst	#ob_hit_med,d2
			bne.s	WeapExpSetHit
			btst	#ob_hit_big,d2
			bne.s	WeapExpSetHit
			rts

WeapExpSetHit		move.w	#WeapExpHitSTATE,OB_State(a0)
			move.w	#SmallHitSlideAMT,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			lea	WeapExpHitANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

WeapExpHitLOGIC		jsr	HitSlideObject
			tst.l	OB_AnSequence(a0)
			beq	WeapExpSetDead
			rts


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

WeapExpSetThrown	move.w	#WeapExpThrownSTATE,OB_State(a0)
			move.b	#10,OB_Var4(a0)
			st.b	RapBotThrownFLG
			btst.b	#ob_xflp,Plr_Flag1			;make sure enemy faces right way
			beq.s	.1
			bclr.b	#ob_xflp,OB_Flag1(a0)
			bra	.2
.1			bset.b	#ob_xflp,OB_Flag1(a0)
.2			lea	WeapExpGrabANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


WeapExpThrownLOGIC	tst.b	GolThrowReleaseFLG
			bne	WeapExpSetThrownRelease
			tst.b	GolSlamFLG
			bne	WeapExpSetSlammed
			
			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	WeapExpSetBounce
.aa			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
			add.w	#8,OB_Ypos(a0)
			rts

WESB2			move.w	OB_Xpos(a0),d1
			and.w	#$fff0,d1
			move.w	d1,InteruptX	
			move.w	OB_Ypos(a0),InteruptY

WeapExpSetBounce	move.w	InteruptX,OB_Xpos(a0)	
			move.w	InteruptY,OB_Ypos(a0)	
			eor.b	#_ob_xflp,OB_Flag1(a0)
			bra	WeapExpSetThrownFall


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

WeapExpSetThrownRelease	move.w	#WeapExpThrownReleaseSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			move.w	#4,OB_Var2(a0)
			lea	WeapExpThrownANM,a1			;set anim
			jsr	SetNewAnim

WeapExpThrownReleaseLOGIC
			jsr	GetUnderNME
			move.b	NUnder,d2
;			or.b	NUnderTOP,d2
			or.b	NUnderBOT,d2
			bmi	WESB2
			moveq	#0,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			move.b	NUnderLEFT,d2
;			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTBOT,d2
			bmi	WESB2
			bra	.lr	
.r			move.b	NUnderRIGHT,d2
;			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTBOT,d2
			bmi	WESB2
.lr			moveq	#3,d1
			jsr	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	WeapExpSetThrownFall
.3			move.w	OB_Var2(a0),d1				;get speed
			jmp	MoveGolUp_Smooth			;move up


; - Weapons expert falls from thrown --------------------------------------------

WeapExpSetThrownFall	move.w	#WeapExpThrownFallSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			lea	WeapExpThrownFallANM,a1			;set anim
			jmp	SetNewAnim

WeapExpThrownFallLOGIC	jsr	GetUnderNME
			
			moveq	#0,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			move.b	NUnderLEFT,d2
;			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTBOT,d2
			bmi	WESB2
			bra	.lr	
.r			move.b	NUnderRIGHT,d2
;			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTBOT,d2
			bmi	WESB2
.lr			moveq	#3,d1
			jsr	MoveGolLeftRightFLP3		

			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
		
			jsr	MoveGolDown_Smooth
			jsr	TestLand
			bmi	WeapExpSetThrownLand
			rts


; - Weapons expert lands from thrown --------------------------------------------

WeapExpSetThrownLand	move.w	#WeapExpThrownLandSTATE,OB_State(a0)
			move.w	#3,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			lea	WeapExpThrownLandANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

WeapExpThrownLandLOGIC	move.w	OB_Var1(a0),d1				;x speed
			beq	WESD2
			jsr	MoveGolLeftRightFLP3			;move x
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			bsr	GetUnderLEFT
			bra	.lr	
.r			jsr	GetUnderRIGHT
.lr			jsr	TestLevelWalls
			bpl.s	.ok
.aa			clr.w	OB_Var1(a0)
			rts
.ok			jsr	HandleContours
			bpl.s	.aa
			addq.b	#1,OB_Var2(a0)				;slow down x 
			and.b	#7,OB_Var2(a0)
			bne.s	.x
			subq.w	#1,OB_Var1(a0)
.x			rts


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

WeapExpSetSlammed	move.w	#WeapExpSlammedSTATE,OB_State(a0)
			move.b	#4,OB_Var1(a0)
			lea	WeapExpSlammedANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
						
WeapExpSlammedLOGIC	tst.b	OB_Var1(a0)
			beq.s	.1
			subq.b	#1,OB_Var1(a0)
			bra	.2

.1			bsr	GetUnderFEET
			jsr	PullContourUnder
			bne.s	.aa
			st.b	GolSlamOutFLG
			bra	WeapExpSetThrownFall
			
.aa			tst.l	OB_AnSequence(a0)
			bne.s	.2
			lea	WeapExpThrownLandANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
			bra	WESD2			
			
.2			bsr	WallInteruptThrow
			bmi	WeapExpSetBounce
			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
.x			rts


; - Weapons expert Dead -----------------------------------------------

WeapExpSetDead		bsr	VikingDeathSFX
			lea	WeapExpDeathANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
WESD2			move.w	#WeapExpDeadSTATE,OB_State(a0)
			jmp	HandleEnemyKilled_NOFF

WeapExpDeadLOGIC  	rts


; - WeapExp idle ---------------------------------------------------------

WeapExpSetIdle		move.w	#WeapExpIdleSTATE,OB_State(a0)
			lea	WeapExpZeroANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


WeapExpIdleLOGIC	subq.b	#1,OB_Var5(a0)
			bne.s	.a
			move.b	#$80,OB_Var5(a0)
			bra	WeapExpSetPour

.a			tst.l	OB_AnSequence(a0)
			beq.s	.ok
			rts
.ok			jsr	Randy
			and.w	#$1f,d6
			beq.s	.1
			lea	WeapExpZeroANM,a1			;set anim
			bra	.2
.1			lea	WeapExpIdleANM,a1			;set anim
.2			jsr	SetNewAnim
			jmp	ForceNewAnim


; - WeapExp pour ---------------------------------------------------------

WeapExpSetPour		move.w	#WeapExpPourSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			lea	WeapExpPourANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

WeapExpPourLOGIC	tst.l	OB_AnSequence(a0)
			beq	WeapExpSetIdle
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί COULDRON CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Couldron_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.w	OB_Var1(a0)
			lea	CouldronIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_Var1(a0)
			beq.s	.wait
			cmp.b	#1,OB_Var1(a0)
			beq.s	.tip
			cmp.b	#2,OB_Var1(a0)
			beq	.boom
.x			rts

.wait			move.l	OB_Task(a0),a1
			cmp.w	#WeapExpHitSTATE,OB_State(a1)
			blt.s	.w1
			move.b	#2,OB_Var1(a0)
			move.b	#$70,OB_Var2(a0)
			rts
.w1			tst.b	OB_EventVar1(a1)
			beq	.x
			move.b	#1,OB_Var1(a0)
			clr.b	OB_EventVar1(a1)
  			lea	CouldronTipANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.tip			tst.b	OB_EventVar1(a0)
			beq.s	.t1
   			clr.b	OB_EventVar1(a0)
			SFX	53
			movem.l	a0/d0,-(sp)
			SPAWN_HI	Oil_MAX_Size
			bpl.s	.2
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			jsr	SetFlipFromMother
			move.w	#Oil_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooffy,OB_Flag2(a1)
			move.w	OB_Xpos(a0),d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			sub.w	#$10,d1
			bra	.lr
.r			add.w	#$10,d1
.lr			move.w	d1,OB_Xpos(a1)
			move.w	OB_Ypos(a0),d1
			add.w	#$1c,d1
			move.w	d1,OB_Ypos(a1)
			rts
.2			movem.l	(sp)+,d0/a0
			rts

.t1			tst.l	OB_AnSequence(a0)
			bne.s	.xx
			bclr.b	#ob_setup,OB_Flag2(a0)
.xx			rts

.boom			cmp.w	#Level12,levnum
			bne.s	.n1
   			cmp.w	#$100,Plr_XPos
			bgt.s	.n1
			
			st.b	DoubleOilFLG

.n1			subq.b	#1,OB_Var2(a0)
			bne.s	.xx
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
;			sub.w	#8,d2
			jsr	SetBigFlrExplode
			jsr	SetupScreenShakeRand
			jmp	SwitchObjectOff


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί OIL GENERATOR CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

OilGenerator_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			move.b	#1,OB_Var2(a0)
			clr.b	OB_Var2a(a0)
			rts

.ok			subq.b	#1,OB_Var2(a0)
			bne.s	.x
			jsr	Randy
			and.b	#$1f,d6
			or.b	#$80,d6
			move.b	d6,OB_Var2(a0)

			move.w	#WeaponExp_OB,d2
			jsr	FindObject
			bmi.s	.x
			
			tst.b	OB_Var1(a0)
			beq.s	SpawnOil

.double			tst.b	DoubleOilFLG
			bne.s	.x
			jsr	AITestPlrIsBelow	
			bmi.s	.x
			bsr	SpawnOil
			moveq	#0,d1
			eor.b	#1,OB_Var2a(a0)
			tst.b	OB_Var2a(a0)
			beq.s	.r
.l			move.b	OB_Var3a(a0),d1
			sub.w	d1,OB_Xpos(a1)
			add.w	#$10,OB_Xpos(a1)
			rts
.r			move.b	OB_Var3(a0),d1
			add.w	d1,OB_Xpos(a1)
			addq.w	#8,OB_Xpos(a1)
.x			rts

SpawnOil		movem.l	a0/d0,-(sp)
			SPAWN_LO	Oil_MAX_Size
			bpl.s	.2
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#Oil_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooffy,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	map_y_p,d1
			move.w	d1,OB_Ypos(a1)
			rts
.2			movem.l	(sp)+,d0/a0
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί COULDRON OIL CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Oil_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	#OilHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			clr.w	OB_Var1(a0)
			lea	OilDripANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_Var1(a0)
			beq.s	.fall
     			cmp.b	#1,OB_Var1(a0)
			beq.s	.splash
			rts

.fall  			addq.b	#1,OB_Var1a(a0)
			and.b	#3,OB_Var1a(a0)
			bne.s	.f1
			cmp.b	#6,OB_Var2(a0)
			beq.s	.f1
			addq.b	#1,OB_Var2(a0)
			
.f1			moveq	#0,d1
			move.b	OB_Var2(a0),d1
			jsr	MoveGolDown_Smooth
			jsr	TestLand	
			bpl.s	.x
			SFX	54
			move.b	#1,OB_Var1(a0)
			lea	OilSplashANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
.x			rts

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


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί SPITTING COULDRON CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpittingCouldron_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			lea	CouldronIdleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			addq.b	#1,OB_Var1a(a0)
			move.b	OB_Var1a(a0),d1
			cmp.b	OB_Var1(a0),d1
			bne.s	.x
			clr.b	OB_Var1a(a0)
			jsr	Randy
			and.b	#3,d6
			beq.s	.1
			cmp.b	#1,d6
			beq.s	.2
			move.l	#42,sfx_poll
  			bra	.o
.2			move.l	#43,sfx_poll
  			bra	.o
.1			move.l	#41,sfx_poll
.o			jsr	SetSFX
			bra	SetupFireballHead
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί TRAILING FIREBALL CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SetupFireballHead	move.l	a0,-(sp)
   			SPAWN_HI	FireballTrail_MAX_Size
			bmi.s	.1
			move.l	(sp)+,a0
			bra	FlagNOn
.1			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#FireballHead_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),d1
			sub.w	#$10,d1
			move.w	d1,OB_Ypos(a1)
			move.b	#FireBallHeadHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			lea	FireBallHeadANM,a2
			jsr	SetNewAnimA1
			bsr	RandomParabolaSmallA1
			add.w	#$30,OB_Yacc(a1)
			add.w	#$200,OB_Yspd(a1)
			move.w	OB_Xspd(a1),OB_Var2(a1)
			clr.b	OB_Var3(a1)
			addq.b	#1,FireballHeadTOG
			and.b	#1,FireballHeadTOG
			bne.s	.1a
			move.b	#%00111110,OB_MoveFlags(a1)
			bra	FlagYESn
.1a			move.b	#%00111111,OB_MoveFlags(a1)
.1b			bra	FlagYESn

SetupFireballTrail	move.l	a0,-(sp)
   			SPAWN_HI	FireballTrail_MAX_Size
			bmi.s	.1
			move.l	(sp)+,a0
			rts
.1			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#FireballTrail_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			lea	FireBallTrailANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1


FireballHead_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			bsr	SetupFireballTrail
			
.ok			addq.b	#1,OB_Var3(a0)
			cmp.b	#4,OB_Var3(a0)
			bne.s	.n1
			clr.b	OB_Var3(a0)
			bsr	SetupFireballTrail

.n1			jsr	MoveGolUpDown
			move.w	OB_Var2(a0),d1
			lsr.w	#8,d1
			jsr	MGLRa
			
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			bne.s	.1
			bsr	GetXYpos
			bsr	GetUnderAddrs
			bsr	GetContour
			jsr	PullContourUnder
			beq.s	.n2			
			sub.w	#$180,OB_Yspd(a0)
			cmp.w	#$200,OB_Yspd(a0)
			bgt.s	.1a
			tst.b	OB_Var5(a0)
			beq.s	.off
			jsr	SetupEyeRaptorRaptor
.off			jmp	SwitchObjectOff
.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


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

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί BIG TRAILING FIREBALL CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SetupBigFireballHead	move.l	a0,-(sp)
   			SPAWN_HI	BigFireball_MAX_Size
			bmi.s	.1
			move.l	(sp)+,a0
			rts
.1			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#BigFireballHead_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),d1
			sub.w	#$10,d1
			move.w	d1,OB_Ypos(a1)
;			bset.b	#ob_newpal,OB_Flag1(a1)
;			move.w	#cp2,OB_Pal(a1)
			move.b	#DemBigFireBallHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			lea	BigFireBallHeadANM,a2
			jsr	SetNewAnimA1
			bsr	RandomParabolaSmallA1
			add.w	#$30,OB_Yacc(a1)
			add.w	#$200,OB_Yspd(a1)
			move.w	OB_Xspd(a1),OB_Var2(a1)
			clr.b	OB_Var3(a1)
			addq.b	#1,FireballHeadTOG
			and.b	#1,FireballHeadTOG
			bne.s	.1a
			move.b	#%00111110,OB_MoveFlags(a1)
			rts
.1a			move.b	#%00111111,OB_MoveFlags(a1)
.1b			rts

SetupBigFireballTrail	move.l	a0,-(sp)
   			SPAWN_HI	BigFireballTrail_MAX_Size
			bmi.s	.1
			move.l	(sp)+,a0
			rts
.1			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#BigFireballTrail_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
;			bset.b	#ob_newpal,OB_Flag1(a1)
;			move.w	#cp2,OB_Pal(a1)
			lea	BigFireBallTrailANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1


BigFireballHead_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			bsr	SetupBigFireballTrail
			
.ok			addq.b	#1,OB_Var3(a0)
			cmp.b	#4,OB_Var3(a0)
			bne.s	.n1
			clr.b	OB_Var3(a0)
			bsr	SetupBigFireballTrail

.n1			jsr	MoveGolUpDown
			move.w	OB_Var2(a0),d1
			lsr.w	#8,d1
			jsr	MGLRa
			
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			bne.s	.1
			bsr	GetXYpos
			subq.w	#8,d2
			bsr	GetUnderAddrs
			bsr	GetContour
			jsr	PullContourUnder
			beq.s	.n2			
			cmp.w	#Level77,levnum
			bne.s	.nn
   			st.b	HitDemonaFloorFLG
.nn			sub.w	#$180,OB_Yspd(a0)
			cmp.w	#$200,OB_Yspd(a0)
			bgt.s	.1a
			jmp	SwitchObjectOff
.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


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


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί CASTLE PIECES CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

CastlePieceAnimTAB	dc.l	CastlePiece1ANM,CastlePiece2ANM,CastlePiece3ANM,CastlePiece4ANM

CastlePiece_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelCastlePieces,a1
			tst.b	0(a1,d1.w)
			beq.s	.1
			jmp	SwitchObjectOff

.1			bset.b	#ob_setup,OB_Flag2(a0)
			sub.w	#8,OB_Ypos(a0)
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			asl.w	#2,d1
			move.l	CastlePieceAnimTAB(pc,d1.w),a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_Var7a(a0)
			bne	.boom

			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelCastlePieces,a1
			tst.b	0(a1,d1.w)
			beq.s	.x

			st.b	OB_Var7a(a0)

			SFX	1
			
			movem.l	a0/d0,-(sp)
			SPAWN_HI	FlameBoulder_MAX_Size
			bpl.s	.2
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#FlameBoulder_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			bset.b	#ob_hiprior,OB_Flag2(a1)
			move.w	OB_Xpos(a0),d1
;			add.w	#$10,d1
			move.w	d1,OB_Var2(a1)
			add.w	#$b0,d1
			move.w	d1,OB_Xpos(a1)
			move.w	OB_Ypos(a0),d1
			sub.w	#$20,d1
			move.w	d1,OB_Var3(a1)
			sub.w	#$90,d1
			move.w	d1,OB_Ypos(a1)
			move.l	a0,OB_Task(a1)
			move.l	a1,OB_Task(a0)
.x			rts
.2			movem.l	(sp)+,d0/a0
			rts

.boom			tst.b	OB_Var7(a0)
			beq.s	.x
			bsr	SetupFireballHead
			or.w	#$200,OB_Yspd(a1)
			add.w	#$200,OB_Yspd(a1)
			bsr	SetupFireballHead
			or.w	#$200,OB_Yspd(a1)
			add.w	#$200,OB_Yspd(a1)
			bsr	SetupFireballHead
			or.w	#$200,OB_Yspd(a1)
			add.w	#$200,OB_Yspd(a1)
			jmp	SwitchObjectOff


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί OPEN/CLOSE CLAW CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Claw_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	#ClawHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			add.w	#$10,OB_Xpos(a0)
			sub.w	#8,OB_Ypos(a0)
			clr.w	OB_Var1(a0)
			lea	ClawClosedANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.l	OB_AnSequence(a0)
			bne.s	.x
			tst.b	OB_Var1(a0)
			beq.s	.1
			subq.b	#1,OB_Var1(a0)
.x			rts

.1			tst.b	OB_Var1a(a0)
			beq.s	.open
.close			move.b	#$80,OB_Var1(a0)
			clr.b	OB_Var1a(a0)
			SFX	105
			lea	ClawClosingANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
.open			move.b	#$20,OB_Var1(a0)
			st.b	OB_Var1a(a0)
			SFX	106
			lea	ClawOpeningANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
			   

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί STUMP FIREBALL GENERATOR CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Stump_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			rts

.ok			tst.b	OB_Var1(a0)
			beq.s	.1
			subq.b	#1,OB_Var1(a0)
.x			rts

.1			move.b	#$c0,OB_Var1(a0)
					 
			movem.l	a0/d0,-(sp)
			SPAWN_LO	StumpBubble_MAX_Size
			bpl.s	.2
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#StumpBubble_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.l	#-1,OB_Task(a1)				;null spawners ob num
			rts
.2			movem.l	(sp)+,d0/a0
			rts
	

StumpBubble_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.b	OB_EventVar1(a0)
			sub.w	#$10,OB_Ypos(a0)
			add.w	#$10,OB_Xpos(a0)
			SFX	82
			lea	ColumnBubbleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_EventVar1(a0)
			beq.s	.1
 			clr.b	OB_EventVar1(a0)
			
			movem.l	a0/d0,-(sp)
			SPAWN_LO	StumpFire_MAX_Size
			bpl.s	.2
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#StumpFire_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
;			bset.b	#ob_hiprior,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.l	OB_Task(a0),OB_Task(a1)			;pass spawners on num on
			rts
.2			movem.l	(sp)+,d0/a0
.x			rts

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


StumpFire_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	#StumpFireBallHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			clr.b	OB_Var1(a0)
			lea	ColumnFireBallStartANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
.ok			tst.b	OB_Var1(a0)
			beq.s	.start
      			cmp.b	#1,OB_Var1(a0)
			beq.s	.up
			
.fin			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jmp	SwitchObjectOff

.up			move.l	OB_Task(a0),a1			;check for claw catching fireball
			cmp.l	#-1,a1
			bne.s	.z1
			bsr	GetUnderHEAD
			tst.b	d2
			bmi.s	.1
			bra.s	.3
.z1			bsr	GetUnderHEAD
			tst.b	d2
			bpl.s	.3
			move.l	OB_Task(a0),a1
			st.b	OB_Var3(a1)			;flag claw that fireball has finished
			bra	.1
			
.start			tst.l	OB_AnSequence(a0)
			beq.s	.2
.3			subq.w	#2,OB_Ypos(a0)
			rts
.1			lea	ColumnFireBallFinANM,a1
			bra	.nxt
.2			add.w	#$30,OB_Ypos(a0)
			lea	ColumnFireBallUpANM,a1
.nxt			jsr	SetNewAnim
			jsr	ForceNewAnim
			addq.b	#1,OB_Var1(a0)
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί STUMP FIREBALL GENERATOR CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

StumpFireGen_Logic	subq.w	#1,OB_Var1(a0)
			bmi.s	.y1
			rts

.y1			move.w	OB_Var2(a0),OB_Var1(a0)
			
			movem.l	a0/d0,-(sp)
			SPAWN_LO	StumpFire_MAX_Size
			bpl.s	.2
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#StumpFire_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	map_y_p,d1
			add.w	#$25*8,d1
			move.w	d1,OB_Ypos(a1)
			rts
.2			movem.l	(sp)+,d0/a0
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί LINKED CLAW STUMP COMBO CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

ClawStump_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			add.w	#$10,OB_Xpos(a0)
			sub.w	#8,OB_Ypos(a0)
			clr.w	OB_Var2(a0)
			clr.b	OB_Var3(a0)
			move.b	#ClawHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			lea	ClawClosedANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.l	OB_AnSequence(a0)
			bne.s	.x
			tst.b	OB_Var2a(a0)
			beq.s	.open

.close			tst.b	OB_Var3(a0)
			beq.s	.x
			clr.b	OB_Var3(a0)
			clr.b	OB_Var2a(a0)
			move.b	#$60,OB_Var2(a0)
			SFX	105
			lea	ClawClosingANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.open			tst.b	OB_Var2(a0)
			beq.s	.1
			subq.b	#1,OB_Var2(a0)
.x			rts
.1			st.b	OB_Var2a(a0)
			SFX	106
			lea	ClawOpeningANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim

.spawn			movem.l	a0/d0,-(sp)
			SPAWN_LO	StumpBubble_MAX_Size
			bpl.s	.2
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#StumpBubble_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),d1
			sub.w	#$10,d1
			move.w	d1,OB_Xpos(a1)
			move.w	OB_Ypos(a0),d1
			add.w	OB_Var1(a0),d1
			move.w	d1,OB_Ypos(a1)
			move.l	a0,OB_Task(a1)		;pass spawners ob num to spawnee
			rts
.2			movem.l	(sp)+,d0/a0
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί VENT EXHAUST CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Vent_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			bset.b	#ob_hiprior,OB_Flag2(a0)
			move.b	#VentHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r1
.l1			add.w	#$20,OB_Xpos(a0)
			lea	LevelVentsL,a1
  			bra	.o2
.r1			sub.w	#$10,OB_Xpos(a0)
			lea	LevelVentsR,a1
.o2			sub.w	#$28,OB_Ypos(a0)
			tst.b	0(a1,d1.w)
			beq.s	.closed
.open			st.b	OB_Var2(a0)
			bsr	SpawnVentSparks
			lea	VentOpenANM,a1
			bra	.ss
.closed			clr.b	OB_Var2(a0)
			lea	VentClosedANM,a1			;set anim
.ss			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.l	OB_AnSequence(a0)
			bne	.x
		
			moveq	#0,d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r2
.l2			lea	LevelVentsL,a1
  			lea	LevelVentsTimerL,a2
  			bra	.o1
.r2			lea	LevelVentsR,a1
  			lea	LevelVentsTimerR,a2
.o1			move.b	OB_Var1(a0),d1
			move.l	d1,d2
			asl.b	#1,d2
			
			tst.w	0(a2,d2.w)			;time out to have vents return
			beq.s	.o3				;to their default state
   			subq.w	#1,0(a2,d2.w)			
			bne.s	.o3
			btst	#0,d1				;odd or even
			beq.s	.even
.odd			move.b	#1,0(a1,d1.w)			;odds are default ON
			SFX	114
			bra	.o3
.even			clr.b	0(a1,d1.w)			;evens are default OFF
			SFX	114

.o3			tst.b	OB_Var2(a0)
			beq.s	.test4open
.test4close		tst.b	0(a1,d1.w)
			bne.s	.x
			clr.b	OB_Var2(a0)
			lea	VentClosingANM,a1
			bra	.1
.test4open		tst.b	0(a1,d1.w)
			beq.s	.x
			st.b	OB_Var2(a0)
			lea	VentOpeningANM,a1
.1			jsr	SetNewAnim
			jsr	ForceNewAnim
			bra	SpawnVentSparks
.x			rts


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

SpawnVentSparks		movem.l	a0/d0,-(sp)
			SPAWN_HI	VentSparks_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#VentSparks_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.l	a0,OB_Var5(a1)
			jsr	SetFlipFromMother
			move.b	OB_Var1(a0),OB_Var1(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			btst.b	#ob_xflp,OB_Flag1(a1)
			beq.s	.r
.l			sub.w	#$10,OB_Xpos(a1)
			bra	.lr
.r			add.w	#$10,OB_Xpos(a1)
.lr			lea	VentSparksANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
.1			movem.l	(sp)+,d0/a0
.2			rts

VentSparks_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			rts

.ok			moveq	#0,d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r1
.l1			lea	LevelVentsL,a1
  			bra	.o1
.r1			lea	LevelVentsR,a1
.o1			move.b	OB_Var1(a0),d1
			tst.b	0(a1,d1.w)
			bne.s	.x
			jmp	SwitchObjectOff
.x			rts


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

Chain_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			add.w	#$8,OB_Xpos(a0)
			lea	VentChainANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			move.l	Plr_Database,a6			
			
			tst.b	OB_Var2(a0)			
			bne.s	.1
			btst.b	#ob_hitting,OB_Flag1(a0)
			beq	.x
			jsr	ClrHitStuff
			cmp.w	#GolHangSwingSTATE,OB_State(a6)
			bne.s	.x
			st.b	OB_Var2(a0)		
			moveq	#0,d1
			
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			lea	LevelVentsL,a1
			lea	LevelVentsTimerL,a2
  			bra	.o1
.r			lea	LevelVentsR,a1
			lea	LevelVentsTimerR,a2
.o1			move.b	OB_Var1(a0),d1
			SFX	114
			eor.b	#1,0(a1,d1.w)
			asl.w	#1,d1
			move.w	#8*hz5060,0(a2,d1.w)			;set timer for this vent to 8 seconds
			add.w	#$a,OB_Ypos(a0)
			add.w	#$a,OB_Ypos(a6)	
			move.b	#$a,OB_Var3(a0)
			rts
.1			cmp.w	#GolHangSwingReleaseSTATE,OB_State(a6)
			bne.s	.x
			subq.w	#1,OB_Ypos(a0)
			subq.b	#1,OB_Var3(a0)
			bne.s	.x
			clr.b	OB_Var2(a0)
.x			rts		


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί OCCASIONAL LICK OF FLAME CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

FlameLick_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			sub.w	#$18,OB_Ypos(a0)		;mod ypos
			clr.b	OB_Var2(a0)			;flag map spawned
			cmp.w	#Level71,levnum
			blt.s	.a
.b			lea	L7FlameLickANM,a1      		;animate
			bra.s	.ab			
.a			lea	FireWispANM,a1	      		;animate
.ab			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.l	OB_AnSequence(a0)		;end of sequence
			bne.s	.x
			tst.b	OB_Var2(a0)			;was flame spawned by plr or map?
			beq.s	.ok2
			jmp	SwitchObjectOff			;plr: one shot so switch it off
.ok2			tst.w	OB_Var1(a0)			;map: delay before animating again
			beq.s	.1
			subq.w	#1,OB_Var1(a0)
.x			rts

.1			cmp.w	#Level71,levnum
			blt.s	.a1
.b1			lea	L7FlameLickANM,a1      		;animate
			bra.s	.ab1			
.a1			lea	FireWispANM,a1			;animate
.ab1			jsr	SetNewAnim
			jsr	ForceNewAnim
			jsr	Randy	  			;set random delay for next time
			and.w	#$ff,d6
			or.w	#$40,d6
			move.w	d6,OB_Var1(a0)
			rts



; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT VIKING BOSS CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	MutVikStartupSTATE
		StDEF	MutVikMutateSTATE
		StDEF	MutVikGroundZeroSTATE
		StDEF	MutVikIdleSTATE
		StDEF	MutVikHammerSmashSTATE
		StDEF	MutVikHammerThrowSTATE
		StDEF	MutVikHammerThrowCSTATE
		StDEF	MutVikHammerSparksSTATE
		StDEF	MutVikHammerSidesSTATE
		StDEF	MutVikHammerLedgeSTATE
		StDEF	MutVikHitSTATE
		StDEF	MutVikDeadSTATE
		StDEF	MutVikDeadFallSTATE


MutVikBody_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
			clr.b	LedgeFallingFLG
			st.b	PlayingBOSS
			clr.b	BossDefeatedFLG
			move.l	a0,Boss_Database			;boss' database
			move.w	#RookeryBOSS_NRG,OB_Nrg(a0)
			move.w	OB_Nrg(a0),d1
			move.w	d1,BossEnergy
			lsr.w	#5,d1
			move.w	d1,BossPercentile
			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	#MutVikHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			move.l	#MutVikSetHits,OB_HitRoutine(a0)
			add.w	#$10,OB_Xpos(a0)
			st.b	BossFirstPass
			bra	MutVikSetStartup
			
.1			jsr	HandleBeingHit				;Generic handle hit rout
			
			move.w	OB_State(a0),d1
			jmp	MutVikLogicTable(pc,d1.w)		;jump table


MutVikLogicTable	bra	MutVikStartupLOGIC
			bra	MutVikMutateLOGIC
			bra	MutVikGroundZeroLOGIC
			bra	MutVikIdleLOGIC
			bra	MutVikHammerSmashLOGIC
			bra	MutVikHammerThrowLOGIC
			bra	MutVikHammerThrowCLOGIC
			bra	MutVikHammerSparksLOGIC
			bra	MutVikHammerSidesLOGIC
			bra	MutVikHammerLedgeLOGIC
			bra	MutVikHitLOGIC
			bra	MutVikDeadLOGIC
			bra	MutVikDeadFallLOGIC


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

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

			btst.b	#ob_dead,OB_Flag2(a0)
			bne	MutVikSetDead

			btst	#ob_hit_small,d2
			bne.s	MutVikSetHit
			btst	#ob_hit_med,d2
			bne.s	MutVikSetHit
			btst	#ob_hit_big,d2
			bne.s	MutVikSetHit
			rts

MutVikSetHit		move.w	#MutVikHitSTATE,OB_State(a0)
			SFX	16
			lea	MutVikHitANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MutVikHitLOGIC		tst.l	OB_AnSequence(a0)
			bne.s	.x
			jsr	MakeNmeFacePlayer
			jsr	Randy
			and.b	#3,d6
			beq	MutVikSetHammerLedge
			cmp.b	#1,d6
			beq	MutVikSetHammerThrow
			bra	MutVikSetHammerSparks
.x			rts


; - Death logic ------------------------------------------------------------

MutVikSetDead		move.w	#MutVikDeadSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			st.b	BossDefeatedFLG
			bsr	SpawnEyeOfOdin
			move.w	#EyeOfOdinBoss1aSTATE,OB_State(a1)
			SFX	8
			lea	MutVikDeadANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MutVikDeadLOGIC		tst.b	OB_EventVar1(a0)
			beq.s	.1
			clr.b	OB_EventVar1(a0)
			cmp.b	#2,OB_EventVar1(a0)
			bne.s	.2
			lea	VikingPal2,a1
			jsr	SetSinglePalette
.2			move.w	#$444,d6
			jsr	LightenPalette2
			
.1			tst.l	OB_AnSequence(a0)
			beq	MutVikSetDeadFall
.x			rts


; - Death logic ------------------------------------------------------------

MutVikSetDeadFall	move.w	#MutVikDeadFallSTATE,OB_State(a0)
			move.b	#$40,OB_Var1(a0)
			lea	SorcerDeadANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MutVikDeadFallLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.x
  			subq.b	#1,OB_Var1(a0)
			bne.s	.x
			st.b	NextLevelFLG
.x			rts


; - Mutant Viking Startup --------------------------------------------------

MutVikSetStartup	move.w	#MutVikStartupSTATE,OB_State(a0)
			bsr	SpawnEyeOfOdin
			bset.b	#ob_notect1,OB_Flag3(a1)
			move.w	#EyeOfOdinBoss1STATE,OB_State(a1)
			lea	MutVikStartupANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


MutVikStartupLOGIC	tst.b	EyeFinishedFLG
			bne.s	MutVikSetMutate
			rts


; - Mutant Viking Startup --------------------------------------------------

MutVikSetMutate		move.w	#MutVikMutateSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			SFX	8
			lea	MutVikMutateANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MutVikMutateLOGIC	cmp.b	#6,OB_EventVar1(a0)
			bne.s	.2
			SFX	57
			clr.b	OB_EventVar1(a0)
			bsr	MutVikSetupSparks
			st.b	MutVikFloorFallFLG
			jmp	SetupScreenShake
			
.2			tst.b	OB_EventVar1(a0)
			beq.s	.1
			clr.b	OB_EventVar1(a0)
			jsr	WhitePalette
			lea	VikingPal4,a1
			jsr	SetSinglePalette
			moveq	#$3,d1
			lea	GamePalette,a1
			move.w	#def_blkwhtin,d2
			jmp	set_whitein	

.1			tst.l	OB_AnSequence(a0)
			beq	MutVikSetGroundZero
			rts


; - Mutant Viking Ground Zero ------------------------------------------------

MutVikSetGroundZero	move.w	#MutVikGroundZeroSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			lea	MutVikPauseANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


MutVikGroundZeroLOGIC	jsr	MakeNmeFacePlayer

			move.l	#MutVikSetGroundZero,AI_Exclude
			lea	MUTVIKING_AI,a1
			jsr	AI_Routine
			bpl.s	.si
			jmp	(a1)
.si			rts


; - Mutant Viking Idle -------------------------------------------

MutVikSetIdle		move.w	#MutVikIdleSTATE,OB_State(a0)
			bsr	SpawnMutVikHead
			st.b	OB_Var1a(a0)
			lea	MutVikBodyZeroANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MutVikIdleLOGIC		move.l	OB_Task(a0),a1
			tst.l	OB_AnSequence(a1)
			beq	MutVikSetGroundZero
			rts


; - Mutant Viking Hammer smash -------------------------------------------

MutVikSetHammerSmash2	lea	MutVikHammerSmash2ANM,a1			;set anim
			bra	MVHS2			
MutVikSetHammerSmash	lea	MutVikHammerSmashANM,a1			;set anim
MVHS2			move.w	#MutVikHammerSmashSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			SFX	20
			jsr	SetNewAnim
			jmp	ForceNewAnim

MutVikHammerSmashLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.1
			SFX	57
  			clr.b	OB_EventVar1(a0)
			bsr	MutVikSetupSparks
			bsr	MutVikSetupTinyRocks
			jmp	SetupScreenShake
	
.1			tst.l	OB_AnSequence(a0)
			beq	MutVikSetGroundZero
			rts


; - Mutant Viking Hammer throw -------------------------------------------

MutVikSetHammerThrow	move.w	#MutVikHammerThrowSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			lea	MutVikHammerThrowANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MutVikHammerThrowLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.1
			clr.b	OB_EventVar1(a0)
			jmp	SpawnMutVikHammer

.1			tst.l	OB_AnSequence(a0)
			beq	MutVikSetHammerThrowC
			rts


; - Mutant Viking Hammer throw catch -------------------------------------

MutVikSetHammerThrowC	move.w	#MutVikHammerThrowCSTATE,OB_State(a0)
			clr.w	OB_Var7(a0)
			rts

MutVikHammerThrowCLOGIC	tst.b	OB_Var7a(a0)
			bne.s	.1
			tst.b	OB_Var7(a0)
			beq.s	.x
			clr.b	OB_Var7(a0)
			st.b	OB_Var7a(a0)
			lea	MutVikHammerThrowCANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
.1			tst.l	OB_AnSequence(a0)
			beq	MutVikSetGroundZero
.x			rts


; - Mutant Viking Hammer sparks -------------------------------------------

MutVikSetHammerSparks	move.w	#MutVikHammerSparksSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			lea	MutVikHammerSmashANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MutVikHammerSparksLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.1
  			clr.b	OB_EventVar1(a0)
			SFX	57
			bsr	MutVikSetupSparks
			bsr	MutVikSetupTinyRocks
			bsr	MutVikSetupBigSparks
			jmp	SetupScreenShake
	
.1			tst.l	OB_AnSequence(a0)
			beq	MutVikSetGroundZero
			rts


MutVikSetupTinyRocks	move.l	a0,-(sp)
			SPAWN_HI	SmallRock_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0	
			move.w	#SmallRock_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_newpal,OB_Flag1(a1)
			move.w	#cp1,OB_Pal(a1)
			move.w	map_x_p,d1
			jsr	Randy
			and.w	#$ff,d6
			add.w	#$20,d6
			add.w	d6,d1
			move.w	d1,OB_Xpos(a1)
			move.w	map_y_p,OB_Ypos(a1)
			rts
.no			move.l	(sp)+,a0
			rts


MutVikSetupSparks	move.l	a0,-(sp)
			SPAWN_HI	Sparks_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0	
			jsr	SetFlipFromMother
			move.w	#Sparks_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_newpal,OB_Flag1(a1)
			move.w	#cp2,OB_Pal(a1)
			move.b	#2,OB_Var4(a1)
			move.b	#8,OB_Var2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			btst.b	#ob_xflp,OB_Flag1(a1)
			bne.s	.r
.l			add.w	#$40,OB_Xpos(a1)
			rts
.r			sub.w	#$40,OB_Xpos(a1)
			rts
.no			move.l	(sp)+,a0
			rts

MutVikSetupBigSparks	moveq	#5,d5
.l1			movem.l	a0/d5,-(sp)
			SPAWN_HI	Spark_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,d5/a0
			jsr	SetFlipFromMother
			move.w	#Spark2_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.b	#MutVikSparkHitPOWER,OB_HitPower(a1)
			jsr	SetSmallAttackA1
			bsr	RandomParabolaSmallA1
			add.w	#$0300,OB_Xspd(a1)
			btst.b	#ob_xflp,OB_Flag1(a1)
			bne.s	.r
.l			add.w	#$38,OB_Xpos(a1)
			move.b	#%00111110,OB_MoveFlags(a1)
			bra	.lr
.r			sub.w	#$38,OB_Xpos(a1)
			move.b	#%00111111,OB_MoveFlags(a1)
.lr			dbra	d5,.l1
			rts
.1			movem.l	(sp)+,d5/a0
			rts


; - Mutant Viking Hammer sides -------------------------------------------

MutVikSetHammerSides	move.w	#MutVikHammerSidesSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			clr.b	MutVikHammerSidesFLG
			clr.w	OB_Var1(a0)
			clr.w	OB_Var2(a0)
			SFX	20
			lea	MutVikHammerSidesANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MutVikHammerSidesLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.1
			SFX	57
  			clr.b	OB_EventVar1(a0)
			bsr	MutVikSetupSparks
			bsr	MutVikSetupTinyRocks
			jsr	SetupScreenShake
	
.1			addq.b	#1,OB_Var1(a0)
			and.b	#$1f,OB_Var1(a0)
			bne.s	.4
			bsr	MutVikSetupTinyRocks

.4			addq.w	#1,OB_Var2(a0)
			cmp.w	#$80,OB_Var2(a0)
			bge.s	.flg
			cmp.w	#$50,OB_Var2(a0)
			bne.s	.x
			tst.b	ScreenShakeRandFLG
			bne.s	.x
			move.b	#$60,ScreenShakeRandFLG
			clr.b	ScreenShakeRandDEL
.x			rts
.flg			clr.w	OB_Var2(a0)
			st.b	MutVikHammerSidesFLG
			bra	MutVikSetGroundZero


; - Mutant Viking Hammer ledge -------------------------------------------

MutVikSetHammerLedge	move.w	#MutVikHammerLedgeSTATE,OB_State(a0)
			jsr	MakeNmeFacePlayer
			clr.b	OB_EventVar1(a0)
			SFX	20
			lea	MutVikHammerSmashANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

MutVikHammerLedgeLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.1
			SFX	57
  			clr.b	OB_EventVar1(a0)
			bsr	MutVikSetupTinyRocks
			jsr	Randy
			and.w	#1,d6
			beq.s	.f1
			bsr	MutVikSetupBigSparks
			bra	.skp1
.f1			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte
.lft			tst.b	LeftLedgeFallenFLG
			bne.s	.skp1
			st.b	LeftLedgeFallenFLG
			bra	.o1
.rte			tst.b	RightLedgeFallenFLG
			bne.s	.skp1
			st.b	RightLedgeFallenFLG
.o1			bsr	MutVikSetupBigLedge
			st.b	LedgeFallingFLG
.skp1			bsr	MutVikSetupSparks
			jmp	SetupScreenShake
	
.1			tst.l	OB_AnSequence(a0)
			beq	MutVikSetGroundZero
			rts

MutVikSetupBigLedge	move.l	a0,-(sp)
			SPAWN_LOLO	Floor_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0	
			move.w	#Floor_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_newpal,OB_Flag1(a1)
			move.b	#$10,OB_Var1(a0)
			move.w	#cp1,OB_Pal(a1)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte
.lft			bclr.b	#ob_xflp,OB_Flag1(a1)
			move.w	#$30,OB_Xpos(a1)
			bra	.o1
.rte			bset.b	#ob_xflp,OB_Flag1(a1)
			move.w	#$1b0,OB_Xpos(a1)
.o1			move.w	#$108,OB_Ypos(a1)
			lea	MutVikFloorANM,a2			;set anim
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
.no			move.l	(sp)+,a0
			rts

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT VIKING BOSS (HEAD) CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnMutVikHead		movem.l	a0/d0,-(sp)
			SPAWN_HI	MutVikHead_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#MutVikHead_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.l	a0,OB_Task(a1)
			move.l	a1,OB_Task(a0)
			lea	MutVikHeadZeroANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
.1			movem.l	(sp)+,d0/a0
			rts

MutVikHead_Logic	move.l	OB_Task(a0),a1
			cmp.w	#MutVikIdleSTATE,OB_State(a1)
			beq.s	.ok
			jmp	SwitchObjectOff

.ok			tst.b	OB_Var1a(a1)
			beq.s	.x
  			clr.b	OB_Var1a(a1)
			lea	MutVikHeadIdleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT VIKING BOSS (HAMMER) CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnMutVikHammer	movem.l	a0/d0,-(sp)
			SPAWN_HI	MutVikHammer_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			jsr	SetFlipFromMother
			move.w	#MutVikHammer_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.l	a0,OB_Task(a1)
			move.l	a1,OB_Task(a0)
			clr.b	OB_Var7(a0)
			btst.b	#ob_xflp,OB_Flag1(a1)
			beq.s	.r
.l			sub.w	#$20,OB_Xpos(a1)
			bra	.lr
.r			add.w	#$20,OB_Xpos(a1)
.lr			sub.w	#$10,OB_Ypos(a1)
			lea	MutVikHammerANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
.1			movem.l	(sp)+,d0/a0
			rts


MutVikHammer_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			SFX	32
			move.b	#MutVikHammerHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.w	OB_Var5(a0)
			move.w	Plr_XPos,TargetX
			move.w	Plr_YPos,TargetY
			jmp	TrajectorySetup

.ok			moveq	#7,d1
			jsr	TrajectoryMove

			tst.b	OB_Var5(a0)
			beq.s	.1
			tst.b	OB_Var5a(a0)
			beq.s	.1
			tst.b	OB_Var6(a0)
			bne.s	.fin
			st.b	OB_Var6(a0)
			clr.w	OB_Var5(a0)
			move.l	OB_Task(a0),a1	
			move.w	OB_Xpos(a1),TargetX
			move.w	OB_Ypos(a1),d1
			sub.w	#$48,d1
			move.w	d1,TargetY
			KILL	32
			SFX	32
			jmp	TrajectorySetup
			
.1			jmp	TrajectoryHit
			
.fin			move.l	OB_Task(a0),a1	
			st.b	OB_Var7(a1)
			jmp	SwitchObjectOff


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT VIKING BOSS (ROOM FLOOR) CONTROL LOGIC			   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Floor_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			SFX	34
			add.w	#$10,OB_Xpos(a0)
			sub.w	#$8,OB_Ypos(a0)
			clr.w	OB_Var2(a0)
			move.b	#2,OB_Var3(a0)
			rts

.ok			tst.b	OB_Var3(a0)
			beq.s	.y2
			subq.b	#1,OB_Var3(a0)
			bne.s	.x
			btst.b	#ob_xflp,OB_Flag1(a0)
			bne.s	.rte
.lft			tst.b	RightLedgeFallenFLG
			bne.s	.lr
			move.l	#Lev24MapAb,__MapA
			bra	.o1
.rte			tst.b	LeftLedgeFallenFLG
			bne.s	.lr
			move.l	#Lev24MapAc,__MapA
			bra	.o1
.lr			move.l	#Lev24MapAd,__MapA
.o1			bsr	DownloadScrlA
			move.l	a0,-(sp)
			move.l	Plr_Database,a0
			jsr	GolSetFall
			clr.b	GolFlappedFLG
			move.l	(sp)+,a0
			rts

.y2			jsr	ObjectOffBottom
			bgt.s	.2
			clr.b	LedgeFallingFLG
			jmp	SwitchObjectOff
			
.2			tst.b	OB_Var1(a0)
			beq.s	.y1
			subq.b	#1,OB_Var1(a0)
.x			rts
.y1			addq.b	#1,OB_Var2(a0)
			and.b	#3,OB_Var2(a0)
			bne.s	.1
			addq.b	#1,OB_Var2a(a0)
.1			moveq	#0,d1
			move.b	OB_Var2a(a0),d1
			add.w	d1,OB_Ypos(a0)
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί EYE OF ODIN CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	EyeOfOdinBoss1STATE
		StDEF	EyeOfOdinBoss1aSTATE
		StDEF	EyeOfOdinBoss2STATE
		StDEF	EyeOfOdinBoss2aSTATE
		StDEF	EyeOfOdinPowerUpSTATE
		StDEF	EyeOfOdinHitSTATE
		StDEF	EyeOfOdinDeadSTATE
		StDEF	EyeOfOdinFinishSTATE
		
		StDEF	EyeOfOdinDemona1STATE
		StDEF	EyeOfOdinFly1STATE
		StDEF	EyeOfOdinRaptor1STATE
		StDEF	EyeOfOdinWait1STATE
		StDEF	EyeOfOdinFly2STATE
		StDEF	EyeOfOdinRaptor2STATE
		StDEF	EyeOfOdinWait2STATE
		StDEF	EyeOfOdinFly3STATE
		StDEF	EyeOfOdinRaptor3STATE
		StDEF	EyeOfOdinWait3STATE
		StDEF	EyeOfOdinFly4STATE
		StDEF	EyeOfOdinFly5STATE
		StDEF	EyeOfOdinFly6STATE
		StDEF	EyeOfOdinWait4STATE
		StDEF	EyeOfOdinWait5STATE
		StDEF	EyeOfOdinTentacleSTATE

		StDEF	EyeOfOdinDMain1STATE
		StDEF	EyeOfOdinHit2STATE
		StDEF	EyeOfOdinDemDeadSTATE

		StDEF	EyeOfOdinRooftopUpSTATE
		StDEF	EyeOfOdinRooftopDnSTATE
		StDEF	EyeOfOdinRaptorSTATE
	

EyeOfOdinPowerUp	clr.b	EyePoweredUpFLG
			move.l	EyeObjectNumber,a1
			move.w	#EyeOfOdinPowerUpSTATE,OB_State(a1)
			clr.b	OB_EventVar1(a1)
			lea	EyeOfOdinPupANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
			
SpawnEyeOfOdin		move.l	a0,-(sp)
			SPAWN_HI	EyeOfOdin_MAX_Size
			bpl.s	SEoO1
			move.l	a0,a1
			move.l	(sp)+,a0
SEoO2			move.w	#EyeOfOdin_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			bset.b	#ob_hiprior,OB_Flag2(a1)
			bset.b	#ob_newpal,OB_Flag1(a1)	
			move.w	#cp3,OB_Pal(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			sub.w	#$10,OB_Ypos(a1)
			addq.w	#8,OB_Xpos(a1)
			clr.b	EyeFinishedFLG
			clr.b	EyePoweredUpFLG
			move.l	a1,EyeObjectNumber
			lea	EyeOfOdinANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
SEoO1			move.l	(sp)+,a0
			rts


EyeOfOdin_Logic		jsr	HandleBeingHit

			move.w	OB_State(a0),d1
			jmp	EyeOfOdinLogicTable(pc,d1.w)		;jump table


EyeOfOdinLogicTable	bra	EyeOfOdinBoss1LOGIC
			bra	EyeOfOdinBoss1aLOGIC
			bra	EyeOfOdinBoss2LOGIC
			bra	EyeOfOdinBoss2aLOGIC
			bra	EyeOfOdinPowerUpLOGIC
			bra	EyeOfOdinHitLOGIC
			bra	EyeOfOdinDeadLOGIC
			bra	EyeOfOdinFinishLOGIC
 
			bra	EyeOfOdinDemona1LOGIC
			bra	EyeOfOdinFly1LOGIC
			bra	EyeOfOdinRaptor1LOGIC
			bra	EyeOfOdinWait1LOGIC
			bra	EyeOfOdinFly2LOGIC
			bra	EyeOfOdinRaptor2LOGIC
			bra	EyeOfOdinWait2LOGIC
			bra	EyeOfOdinFly3LOGIC
			bra	EyeOfOdinRaptor3LOGIC
			bra	EyeOfOdinWait3LOGIC
			bra	EyeOfOdinFly4LOGIC
			bra	EyeOfOdinFly5LOGIC
			bra	EyeOfOdinFly6LOGIC
			bra	EyeOfOdinWait4LOGIC
			bra	EyeOfOdinWait5LOGIC
			bra	EyeOfOdinTentacleLOGIC

			bra	EyeOfOdinDMain1LOGIC
			bra	EyeOfOdinHit2LOGIC
			bra	EyeOfOdinDemDeadLOGIC

			bra	EyeOfOdinRooftopUpLOGIC
			bra	EyeOfOdinRooftopDnLOGIC
			bra	EyeOfOdinRaptorLOGIC


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinBoss1LOGIC	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	EOOB1
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.w	OB_Var1(a0)
			move.w	#128,OB_Var2(a0)
			move.w	#1,OB_Var3(a0)
			move.w	#1,OB_Var4(a0)
			clr.b	OB_Var5(a0)
			move.w	#$142,OB_Var6(a0)
			move.w	OB_Xpos(a0),OB_WXpos(a0)
			move.w	OB_Ypos(a0),OB_WYpos(a0)
			SFX	55
			rts
			
EOOB1			subq.w	#1,OB_Var6(a0)
			bpl.s	.ok
   			st.b	EyeFinishedFLG
			KILL	55
			jmp	SwitchObjectOff

.ok			btst.b	#1,second
			bne.s	.n1	
			bsr	SetupEyeOfOdinTrail

.n1			lea	SinTable,a1
						
			move.w	OB_Var1(a0),d1		;x
			move.w	OB_Var2(a0),d2		;y
			
			move.w	OB_WXpos(a0),d4
			moveq	#0,d3
			move.w	0(a1,d1.w),d3		;sin x	
			bpl.s	.x1
   			neg.w	d3
			divu	OB_Var3(a0),d3
			sub.w	d3,d4
			bra	.xx
.x1			divu	OB_Var3(a0),d3
			add.w	d3,d4
.xx			move.w	d4,OB_Xpos(a0)			
			
			move.w	OB_WYpos(a0),d4
			moveq	#0,d3
			move.w	0(a1,d2.w),d3		;cos y
			bpl.s	.y1
   			neg.w	d3
			divu	OB_Var4(a0),d3
			sub.w	d3,d4
			bra	.yy
.y1			divu	OB_Var4(a0),d3
			add.w	d3,d4
.yy			move.w	d4,OB_Ypos(a0)			
			
			addq.b	#1,OB_Var5(a0)
			and.b	#1,OB_Var5(a0)
			bne.s	.o1
			addq.w	#1,OB_Var3(a0)
			addq.w	#1,OB_Var4(a0)

.o1			addq.w	#8,OB_Var1(a0)
			addq.w	#8,OB_Var2(a0)
			and.w	#$1ff,OB_Var1(a0)
			and.w	#$1ff,OB_Var2(a0)
			rts


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinBoss1aLOGIC	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.w	OB_Var1(a0)
			move.b	#$18,OB_Var2(a0)
			rts
			
.ok			tst.b	OB_Var1(a0)
			beq.s	.move
			cmp.b	#1,OB_Var1(a0)
			beq.s	.wait
.zip			btst.b	#2,second
			bne.s	.n1	
			bsr	SetupEyeOfOdinTrail
.n1			moveq	#0,d1
			addq.b	#1,OB_Var2(a0)
			and.b	#7,OB_Var3(a0)
			bne.s	.z1
			addq.b	#1,OB_Var1a(a0)
.z1			move.b	OB_Var1a(a0),d1
			add.w	d1,OB_Xpos(a0)
			sub.w	d1,OB_Ypos(a0)
.x			rts
.wait			subq.b	#1,OB_Var2(a0)
			bne.s	.x
  			bra	.nxt
.move			btst.b	#2,second
			bne.s	.n2	
			bsr	SetupEyeOfOdinTrail
.n2			subq.b	#1,OB_Var2(a0)
			bne.s	.m1
			bra	.nxt
.m1			addq.w	#2,OB_Xpos(a0)
			subq.w	#2,OB_Ypos(a0)
   			rts
.nxt			addq.b	#1,OB_Var1(a0)
			move.b	#$20,OB_Var2(a0)
			rts


; --------------------------------------------------------------------------
; - Eye of Odin Logic (Elevator) -------------------------------------------

EyeOfOdinBoss2LOGIC	btst.b	#ob_setup,OB_Flag2(a0)
			bne	EOOB1
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.w	OB_Var1(a0)
			add.w	#$10,OB_Ypos(a0)
			move.w	#128,OB_Var2(a0)
			move.w	#1,OB_Var3(a0)
			move.w	#1,OB_Var4(a0)
			clr.b	OB_Var5(a0)
			move.w	#$104,OB_Var6(a0)
			move.w	OB_Xpos(a0),OB_WXpos(a0)
			move.w	OB_Ypos(a0),OB_WYpos(a0)
			lea	EyeOfOdinZeroANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim
			SFX	55
			bra	EOOB1


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinBoss2aLOGIC	rts


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinPowerUpLOGIC	tst.l	OB_AnSequence(a0)
			beq.s	.fin
			tst.b	OB_EventVar1(a0)
			beq.s	.x
			clr.b	OB_EventVar1(a0)
			st.b	EyePoweredUpFLG
			rts
.fin			move.w	#EyeOfOdinBoss2aSTATE,OB_State(a0)
			lea	EyeOfOdinZeroANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
.x			rts


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetHit		jsr	ClrHitStuff
			SFX	29
			move.w	OB_State(a0),OB_LastState(a0)
			move.w	#EyeOfOdinHitSTATE,OB_State(a0)
			move.b	#$18,OB_HitWait(a0)
			addq.b	#1,EyeHitCNT
			clr.b	OB_Var1(a0)
.x			rts


EyeHitWobbleTab		dc.w	-3,-2,-1,0,1,2,3,2,1,0,-1,-2,-3
			dc.w	$80

EyeOfOdinHitLOGIC	btst.b	#ob_dead,OB_Flag2(a0)
			bne.s	.dead

			lea	EyeHitWobbleTab,a1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			addq.b	#2,OB_Var1(a0)
			move.w	EyeHitWobbleTab(pc,d1.w),d1
			bpl.s	.1
			neg.w	d1
			sub.w	d1,OB_Xpos(a0)
			rts
.1			cmp.w	#$80,d1
			beq.s	.fin
			add.w	d1,OB_Xpos(a0)
			rts
.fin			move.w	OB_WXpos(a0),OB_Xpos(a0)
			move.w	OB_LastState(a0),OB_State(a0)
;			move.w	#EyeOfOdinBoss2aSTATE,OB_State(a0)
			move.b	#4,EyeHitFLG
			jmp	ClrHitStuff
				
.dead			st.b	EyeDeadFLG
			move.l	#-1,OB_HitRoutine(a0)
			
			move.w	OB_WXpos(a0),OB_Xpos(a0)
			move.w	#EyeOfOdinDeadSTATE,OB_State(a0)
			
			clr.w	OB_Xspd(a0)
			clr.w	OB_Xacc(a0)
			move.w	#$0700,OB_Yspd(a0)
			move.w	#$0080,OB_Yacc(a0)
			move.b	#%00111110,OB_MoveFlags(a0)
			bclr.b	#ob_hiprior,OB_Flag2(a0)
			
			SFX	8

			move.w	#$3fa4,pix_x			;center everything (really cheezy but hohum)
			move.w	#$7c,map_x_p
			add.w	#$30,OB_Xpos(a0)
			move.l	Plr_Database,a1
			add.w	#$30,OB_Xpos(a1)
			move.w	#GolFinishElevSTATE,OB_State(a1)
			move.w	OB_Xpos(a0),OB_Var2(a1)
			clr.b	OB_Var1(a1)
			move.b	#$10,OB_Var1a(a1)
			lea	GolGroundIdle1ANM,a2
			jsr	SetNewAnimA1

			lea	Car1Pal,a1
			jsr	SetSinglePalette
			
			jsr	ClrHitStuff
			jsr	WhitePalette
			moveq	#$3,d1
			lea	GamePalette,a1
			move.w	#def_blkwhtin,d2
			jsr	set_whitein	
;			rts
			move.l	#Lev34MapAd,__MapA
			bra	DownloadScrlA
			

; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinDeadLOGIC	jsr	MoveGolUpDown
			
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			bne.s	.1
			bsr	GetXYpos
			bsr	GetUnderAddrs
			bsr	GetContour
			jsr	PullContourUnder
			beq.s	.x			
			sub.w	#$180,OB_Yspd(a0)
			bmi.s	.fin
			bset.b	#ob_movyacc,OB_MoveFlags(a0)
			bset.b	#ob_movydir,OB_MoveFlags(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

.fin			move.w	#EyeOfOdinFinishSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			rts
			move.l	Plr_Database,a1
			move.w	#GolFinishElevSTATE,OB_State(a1)
			move.w	OB_Xpos(a0),OB_Var2(a1)
			clr.b	OB_Var1(a1)
			move.b	#$10,OB_Var1a(a1)
			lea	GolGroundIdle1ANM,a2
			jmp	SetNewAnimA1


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinFinishLOGIC	cmp.b	#1,OB_Var1(a0)
			beq.s	.roll
			cmp.b	#2,OB_Var1(a0)
			beq.s	.fall
			tst.b	BFX_Var6
			beq.s	.x
			move.b	#1,OB_Var1(a0)
			move.b	#$60/4,OB_Var2(a0)

.roll			subq.b	#1,OB_Var2(a0)
			beq.s	.sfall
			addq.w	#4,OB_Xpos(a0)
			move.w	OB_Xpos(a0),d1
			and.w	#$7,d1
			bne.s	.x
			addq.w	#1,OB_Ypos(a0)
.x			rts

.sfall			move.b	#2,OB_Var1(a0)
			clr.w	OB_Xspd(a0)
			clr.w	OB_Xacc(a0)
			move.w	#$0500,OB_Yspd(a0)
			move.w	#$0080,OB_Yacc(a0)
			move.b	#%00111110,OB_MoveFlags(a0)
			bset.b	#ob_hiprior,OB_Flag2(a0)
			
.fall			addq.w	#1,OB_Xpos(a0)
			jsr	MoveGolUpDown
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			beq.s	.x
			tst.w	OB_Yspd(a0)
			bne.s	.x
			st.b	BFX_Var5a				;flag elevator fall
			st.b	BFX_Var6a
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)
			bclr.b	#ob_movydir,OB_MoveFlags(a0)
			rts

DownloadScrlA		move.l	a0,-(sp)
			move.w	#$2700,sr
			jsr	SetupScrlA				;setup scroll A
			move.w	#$2000,sr
			move.l	(sp)+,a0
			rts
			
DownloadScrlB		move.l	a0,-(sp)
			move.w	#$2700,sr
			jsr	SetupScrlB				;setup scroll B
			move.w	#$2000,sr
			move.l	(sp)+,a0
			rts
			

; --------------------------------------------------------------------------
; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinDemona1LOGIC	tst.b	NoFollowFLG
			beq.s	.ok
			rts

.ok			btst.b	#ob_beinghit,OB_Flag1(a0)
			bne	.dead

			subq.b	#1,OB_Var8a(a0)			;shoot
			bpl.s	.aa
   			move.b	#$60,OB_Var8a(a0)
			SFX	101	
			bsr	SpawnGenericTrajProj
			bpl.s	.aa
			lea	MutSpiProjHeadANM,a2
			jsr	SetNewAnimA1

.aa			tst.b	OB_Var7(a0)
			bne	.fly
			
.new			jsr	Randy
			and.w	#$3f,d6
			beq.s	.y1
			bra	EyeOfOdinBob
			
.y1			jsr	Randy
			and.w	#$3f,d6
			or.w	#$20,d6
			move.w	Plr_XPos,d1
			and.b	#1,d7
			beq.s	.l
.r			add.w	d6,d1
			bra	.1
.l			sub.w	d6,d1
.1			move.w	d1,TargetX
			jsr	Randy
			and.w	#$3f,d6
			or.w	#$30,d6
			move.w	Plr_YPos,d1
			sub.w	d6,d1
			move.w	d1,TargetY
			bra	EyeTrajectorySetup
			
.fly			bra	EyeTrajectory

.dead			bsr	EyeOfOdinSetFly1
			;bsr	EyeOfOdinSetFly5
			
			clr.b	FinalBossPHASE
					
			jsr	ClrHitStuff
			jsr	WhitePalette
			move.l	#Lev77MapAb,__MapA
			bsr	DownloadScrlA
			lea	Lev77Palb,a4				;palette
			jsr	SetupPalette
			lea	AMAP_FORGFLMA0_START,a2
			jsr	SetupCharAnim						
			lea	AMAP_FORGFLMB0_START,a2
			jsr	SetupCharAnim						
			move.b	#1,CH_AnCnt(a1)	
			
			moveq	#$3,d1
			lea	GamePalette,a1
			move.w	#def_blkwhtin,d2
			jsr	set_whitein	

			SFX	57
			SFX	95
			
			move.w	Plr_XPos,TempX
			move.w	Plr_YPos,TempY
			sub.w	#$60,TempX
			sub.w	#$60,TempY
			moveq	#3,d3				;bits of debris
			moveq	#2,d7		
			jsr	SetRandomDebris
			add.w	#$60,TempX
			moveq	#3,d3				;bits of debris
			moveq	#3,d7		
			jsr	SetRandomDebris
			add.w	#$60,TempY
			moveq	#3,d3				;bits of debris
			moveq	#4,d7		
			jsr	SetRandomDebris
			sub.w	#$60,TempX
			moveq	#3,d3				;bits of debris
			moveq	#5,d7		
			jsr	SetRandomDebris
			add.w	#$30,TempX
			add.w	#$30,TempY
			moveq	#3,d3				;bits of debris
			moveq	#6,d7		
			jmp	SetRandomDebris

					
; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetFly1	move.w	#EyeOfOdinFly1STATE,OB_State(a0)	
			move.w	d0,TrackObjectNumber			;scroll now track the eye
			move.l	a0,TrackObjectDatabase
			st.b	DemonaFLG1				;disable goliath
			move.w	#$68,TargetX 				;target the corner of the platform
			move.w	#$5e0,TargetY
			bsr	EyeTrajectorySetup
			bsr	DemonaEyeBit2				;hell hound
			bset.b	#ob_xflp,OB_Flag1(a1)
			move.w	#$160,OB_Xpos(a1)
			move.w	#$5ac,OB_Ypos(a1)
			move.b	#$40,OB_Var9(a0)			;pause
			bra	EyeTidyPlayer				;player


EyeOfOdinFly1LOGIC	tst.b	OB_Var9(a0)
			beq.s	.ok
			subq.b	#1,OB_Var9(a0)
.x			rts
.ok			bsr	EyeTrajectory
			tst.b	OB_Var7(a0)
			bne.s	.x
			st.b	EyeHitEdgeFLG


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetRaptor1	move.w	#EyeOfOdinRaptor1STATE,OB_State(a0)	
			jsr	DemonaEyeBit1a
			move.l	OB_Task(a0),a1			;target the rabtorbot
			move.w	OB_Xpos(a1),d1
			sub.w	#$30,d1
			move.w	d1,TargetX
			move.w	OB_Ypos(a1),TargetY
			bra	EyeTrajectorySetup
			
EyeOfOdinRaptor1LOGIC	bsr	EyeTrajectory			;eye flies towards raptor
			tst.b	OB_Var7(a0)
			beq.s	.fin
    			rts
.fin			st.b	DemonaFLG2			;flag eye hits raptor
			KILL	55
			lea	EyeOfOdinBlankANM,a1		;blank eye
			jsr	SetNewAnim
			jsr	ForceNewAnim
			move.b	#1,FinalBossPHASE


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetWait1	move.w	#EyeOfOdinWait1STATE,OB_State(a0)	
			move.b	#$20,OB_Var2(a0)
			
EyeOfOdinWait1LOGIC	tst.b	RabidDeadFLG
			bne.s	.ok
.x			rts
.ok			move.l	OB_Task(a0),a1
			move.w	OB_Xpos(a1),OB_Xpos(a0)
			move.w	OB_Ypos(a1),OB_Ypos(a0)
			subq.b	#1,OB_Var2(a0)
			bne.s	.x
			SFX	55
			lea	EyeOfOdinANM,a1
			jsr	SetNewAnim
			bra	EyeOfOdinSetFly2
	

; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetFly2	move.w	#EyeOfOdinFly2STATE,OB_State(a0)	
			move.w	d0,TrackObjectNumber			;scroll now track the eye
			move.l	a0,TrackObjectDatabase
			st.b	DemonaFLG1				;disable goliath
			move.w	#$200,TargetX 				;target the corner of the platform
			move.w	#$4e0,TargetY
			bsr	EyeTrajectorySetup
			bsr	DemonaEyeBit2				;hell hound
			bclr.b	#ob_xflp,OB_Flag1(a1)
			move.w	#$100,OB_Xpos(a1)
			move.w	#$4ac,OB_Ypos(a1)
			bra	EyeTidyPlayer				;player

EyeOfOdinFly2LOGIC	bsr	EyeTrajectory
			tst.b	OB_Var7(a0)
			beq.s	.1
			rts
.1			st.b	EyeHitEdgeFLG


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetRaptor2	move.w	#EyeOfOdinRaptor2STATE,OB_State(a0)	
			jsr	DemonaEyeBit1a
			move.l	OB_Task(a0),a1				;target the rabtorbot
			move.w	OB_Xpos(a1),d1
			add.w	#$60,d1
			move.w	d1,TargetX
			move.w	OB_Ypos(a1),TargetY
			bra	EyeTrajectorySetup
			
EyeOfOdinRaptor2LOGIC	bsr	EyeTrajectory				;eye flies towards raptor
			tst.b	OB_Var7(a0)
			beq.s	.fin
    			rts
.fin			st.b	DemonaFLG2				;flag eye hits raptor
			KILL	55
			lea	EyeOfOdinBlankANM,a1			;blank eye
			jsr	SetNewAnim
			jsr	ForceNewAnim
			move.b	#2,FinalBossPHASE


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetWait2	move.w	#EyeOfOdinWait2STATE,OB_State(a0)	
			move.b	#$20,OB_Var2(a0)
			
EyeOfOdinWait2LOGIC	tst.b	RabidDeadFLG
			bne.s	.ok
.x			rts
.ok			move.l	OB_Task(a0),a1
			move.w	OB_Xpos(a1),OB_Xpos(a0)
			move.w	OB_Ypos(a1),OB_Ypos(a0)
			subq.b	#1,OB_Var2(a0)
			bne.s	.x
			SFX	55
			lea	EyeOfOdinANM,a1
			jsr	SetNewAnim
	

; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetFly3	move.w	#EyeOfOdinFly3STATE,OB_State(a0)	
			move.w	d0,TrackObjectNumber			;scroll now track the eye
			move.l	a0,TrackObjectDatabase
			st.b	DemonaFLG1				;disable goliath
			move.w	#$90,TargetX 				;target the corner of the platform
			move.w	#$3f0,TargetY
			bsr	EyeTrajectorySetup
			bsr	DemonaEyeBit2				;hell hound
			bset.b	#ob_xflp,OB_Flag1(a1)
			move.w	#$168,OB_Xpos(a1)
			move.w	#$3ac,OB_Ypos(a1)
			bra	EyeTidyPlayer				;player

EyeOfOdinFly3LOGIC	bsr	EyeTrajectory
			tst.b	OB_Var7(a0)
			beq.s	.1
			rts
.1			st.b	EyeHitEdgeFLG


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetRaptor3	move.w	#EyeOfOdinRaptor3STATE,OB_State(a0)	
			jsr	DemonaEyeBit1
			move.l	OB_Task(a0),a1				;target the rabtorbot
			move.w	OB_Xpos(a1),d1
			sub.w	#$30,d1
			move.w	d1,TargetX
			move.w	OB_Ypos(a1),TargetY
			bra	EyeTrajectorySetup
			
EyeOfOdinRaptor3LOGIC	bsr	EyeTrajectory				;eye flies towards raptor
			tst.b	OB_Var7(a0)
			beq.s	.fin
    			rts
.fin			st.b	DemonaFLG2				;flag eye hits raptor
			KILL	55
			lea	EyeOfOdinBlankANM,a1			;blank eye
			jsr	SetNewAnim
			jsr	ForceNewAnim

			
; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetWait3	move.w	#EyeOfOdinWait3STATE,OB_State(a0)	
			move.b	#$20,OB_Var2(a0)
			move.b	#3,FinalBossPHASE
			
EyeOfOdinWait3LOGIC	tst.b	RabidDeadFLG				;is rabid dead?
			bne.s	.ok
.x			rts
.ok			move.l	OB_Task(a0),a1				;set eys x,y pos to rabids x,y
			move.w	OB_Xpos(a1),OB_Xpos(a0)
			move.w	OB_Ypos(a1),OB_Ypos(a0)
			subq.b	#1,OB_Var2(a0)
			bne.s	.x
			SFX	55
			lea	EyeOfOdinANM,a1				;animate eye
			jsr	SetNewAnim
	

; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetFly4	move.w	#EyeOfOdinFly4STATE,OB_State(a0)	
			move.w	d0,TrackObjectNumber			;scroll now track the eye
			move.l	a0,TrackObjectDatabase
			st.b	DemonaFLG1				;disable goliath
			move.w	#$1b0,TargetX 				;target the corner of the platform
			move.w	#$2f0,TargetY
			bsr	EyeTrajectorySetup		
			bra	EyeTidyPlayer				;player

EyeOfOdinFly4LOGIC	bsr	EyeTrajectory				;eye moves towards target
			tst.b	OB_Var7(a0)
			beq.s	.1
			rts
.1			jsr	DemonaEyeBit1				;explosion				;
			

; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetFly5	move.w	#EyeOfOdinFly5STATE,OB_State(a0)	
			   
			move.w	#$100,TargetX 				;target the corner of the platform
			move.w	#$1f0,TargetY
			bsr	EyeTrajectorySetup
			
			bsr	SpawnDemona				;spawn Demona
			st.b	DemonaFLG1
			move.w	#DemonaSetWait1STATE,OB_State(a1)
			bset.b	#ob_xflp,OB_Flag1(a1)
			move.w	#$140,OB_Xpos(a1)
			move.w	#$1ac,OB_Ypos(a1)
			clr.b	DemonaFLG2
			
			lea	Pal4,a1
			lea	GamePal4,a2
			lea	DemPAL,a3
			moveq	#$f,d1
.l1			move.w	(a3),(a1)+
			move.w	(a3)+,(a2)+
			dbra	d1,.l1
			rts


EyeOfOdinFly5LOGIC	bsr	EyeTrajectory				;eye flys towards target
			tst.b	OB_Var7(a0)
			beq.s	EyeOfOdinSetFly6
			rts


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetFly6	move.w	#EyeOfOdinFly6STATE,OB_State(a0)	
			move.w	#$128,TargetX 				;target the top of demona
			move.w	#$160,TargetY
			bra	EyeTrajectorySetup

EyeOfOdinFly6LOGIC	bsr	EyeTrajectory				;eye flys towards final target
			tst.b	OB_Var7(a0)
			beq.s	.1
			rts
.1			st.b	EyeHitEdgeFLG

			
; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetWait4	move.w	#EyeOfOdinWait4STATE,OB_State(a0)	
			move.b	#$60,OB_Var2(a0)
			move.b	#4,FinalBossPHASE

EyeOfOdinWait4LOGIC	subq.b	#1,OB_Var2(a0)
			beq.s	.ok
			cmp.b	#$40,OB_Var2(a0)
			bne.s	.1
			KILL	55
			move.w	#-1,TrackObjectNumber			;scroll track plr
.1			rts

.ok			move.w	#EyeOfOdinWait5STATE,OB_State(a0)	
			move.b	#8,OB_Var2(a0)			;delay goliath enable (allow scroll to catch up)
			rts

; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinWait5LOGIC	tst.b	OB_Var2(a0)
			beq.s	.1
			subq.b	#1,OB_Var2(a0)
			bne.s	.1
			clr.b	DemonaFLG1				;eneble goliath

.1			tst.b	DemonaFLG3
			bne.s	.ok
.x			rts
.ok			subq.w	#1,OB_Ypos(a0)
			cmp.w	#$f0,OB_Ypos(a0)
			bne.s	.x
    
			
; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetTentacle	move.w	#EyeOfOdinTentacleSTATE,OB_State(a0)	
			move.w	#$f0,OB_Ypos(a0)
			move.w	#$140,OB_Xpos(a0)
			bsr	SpawnTentacles
			clr.b	DemonaFLG3
			rts

EyeOfOdinTentacleLOGIC	tst.b	DemonaFLG3			;wait for control to be given back to plr
			bne.s	EyeOfOdinSetDMain1
			rts


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetDMain1	move.w	#EyeOfOdinDMain1STATE,OB_State(a0)	
			clr.w	OB_Var2(a0)
			clr.w	OB_Var1(a0)
			move.w	OB_Xpos(a0),OB_WXpos(a0)
			clr.b	PhoenixDemonaFLG
			rts

EyeOfOdinDMain1LOGIC	btst.b	#ob_beinghit,OB_Flag1(a0)
			beq.s	.ok
			SFX	29
			move.w	#EyeOfOdinHit2STATE,OB_State(a0)
			subq.w	#8,BossEnergy
			clr.b	OB_Var1(a0)
			st.b	DemonaAttackFLG
			jmp	ClrHitStuff

.ok			tst.b	DemonaAttackFLG
			beq.s	.n
			tst.b	GolOnWallLeftFLG
			bne.s	.ow
			tst.b	GolOnWallRightFLG
			beq.s	.x
.ow			move.b	second,d1
			and.b	#$f,d1
			bne.s	.x
			bsr	SpawnGenericTrajProj
			bpl.s	.x
			SFX	30
			move.b	#8,OB_Var8(a1)
			lea	MutSpiProjHeadANM,a2
			jsr	SetNewAnimA1

.n			cmp.b	#1,OB_Var1(a0)
			beq	.pup
			
			jsr	Randy
			and.b	#$7f,d6
			bne.s	.x
			move.b	#1,OB_Var1(a0)
			jmp	SpawnEnergyInfuser
.x			rts

.pup			move.l	OB_Task(a0),a1
			tst.b	OB_EventVar1(a1)
			beq.s	.x
			st.b	DemonaLookFLG
			clr.b	OB_Var1(a0)
			rts


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinHit2LOGIC	cmp.w	#DemonaBossMaxNRG/8,BossEnergy
			ble.s	EyeOfOdinSetDemonaDead

			lea	EyeHitWobbleTab,a1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			addq.b	#2,OB_Var1(a0)
			lea	EyeHitWobbleTab,a1
			move.w	0(a1,d1.w),d1
			bpl.s	.1
			neg.w	d1
			sub.w	d1,OB_Xpos(a0)
			rts
.1			cmp.w	#$80,d1
			beq.s	.fin
			add.w	d1,OB_Xpos(a0)
			rts
.fin			move.w	OB_WXpos(a0),OB_Xpos(a0)
			bra	EyeOfOdinSetDMain1
			

; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinSetDemonaDead	move.w	OB_WXpos(a0),OB_Xpos(a0)
			SFX	8
			move.w	#EyeOfOdinDemDeadSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			st.b	PhoenixDemonaFLG
			rts		

EyeOfOdinDemDeadLOGIC	addq.b	#1,OB_Var1(a0)
			and.b	#7,OB_Var1(a0)
			bne.s	.1
			addq.b	#1,OB_Var1a(a0)

.1			moveq	#0,d1
			move.b	OB_Var1a(a0),d1
			add.w	d1,OB_Ypos(a0)	
			subq.w	#1,OB_Xpos(a0)
			jsr	ObjectOffBottom
			bgt.s	.x
			jmp	SwitchObjectOff
.x			rts


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinRooftopUpLOGIC	tst.b	EyeRooftopUpFLG
			beq	.x

			tst.b	OB_Var1(a0)
			beq.s	.up
			cmp.b	#1,OB_Var1(a0)
			beq.s	.wait
.away			addq.w	#4,OB_Xpos(a0)
			bra.s	.t1
.wait			subq.b	#1,OB_Var2(a0)
			beq.s	.nxt
			rts
.up			cmp.b	#$1c,OB_Var2(a0)
			bne.s	.u1
  			st.b	EyeRooftopSmashFLG
.u1			subq.b	#1,OB_Var2(a0)
			bne.s	.t1
			move.b	#$30,OB_Var2(a0)
			bra	.nxt
.t1			subq.w	#4,OB_Ypos(a0)
			cmp.w	#$60,OB_Ypos(a0)
			bgt.s	.t2
   			KILL	55
			jmp	SwitchObjectOff
.t2			btst.b	#1,second
			bne.s	.x
			bra	SetupEyeOfOdinTrail
.nxt			addq.b	#1,OB_Var1(a0)
.x			rts


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinRooftopDnLOGIC	tst.b	EyeRooftopDnFLG
			bne.s	.1
			bra	EyeOfOdinBob

.1			subq.b	#1,OB_Var2(a0)
			bne.s	.y
			KILL	55
			jmp	SwitchObjectOff
.x			rts
.y			cmp.b	#$14,OB_Var2(a0)
			bne.s	.d1
  			st.b	EyeRooftopSmashFLG
.d1			addq.w	#4,OB_Ypos(a0)
			btst.b	#1,second
			bne.s	.x
			bra	SetupEyeOfOdinTrail


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinRaptorLOGIC	tst.b	OB_Var5(a0)
			beq.s	.wait

.away			tst.b	OB_Var1a(a0)
			beq.s	.a1
   			subq.b	#1,OB_Var1a(a0)
			rts
.a1			subq.w	#4,OB_Ypos(a0)
			btst.b	#1,second
			bne.s	.x
			bra	SetupEyeOfOdinTrail
.wait			bsr	EyeOfOdinBob
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelEyeRaptors,a1
			tst.b	0(a1,d1.w)
			beq.s	.x
			st.b	OB_Var5(a0)
			move.b	#$40,OB_Var1a(a0)	
			bsr	SetupFireballHead
			bpl.s	.x
			move.w	#$100,OB_Var2(a1)
			add.w	#$10,OB_Ypos(a1)
			st.b	OB_Var5(a1)
			bsr	SetupFireballHead
			bpl.s	.x
			move.w	#$100,OB_Var2(a1)
			add.w	#$10,OB_Ypos(a1)
			st.b	OB_Var5(a1)
.x			rts			


; - Eye of Odin Logic ------------------------------------------------------

EyeOfOdinBob		addq.b	#1,OB_Var9(a0)
			and.b	#3,OB_Var9(a0)
			bne.s	.x
			addq.b	#1,OB_Var9a(a0)

			moveq	#0,d1
			moveq	#0,d2
.b4			move.b	OB_Var9a(a0),d1
			lea	WaspBobTab,a1
			move.b	0(a1,d1.w),d2
			bpl.s	.b2
			cmp.b	#$80,d2
			bne.s	.b3
			clr.b	OB_Var9a(a0)
			bra.s	.b4
.b3			neg.b	d2
			sub.w	d2,OB_Ypos(a0)
.x			rts
.b2			add.w	d2,OB_Ypos(a0)
			rts


EyeTrajectorySetup	jsr	TrajectorySetup
			st.b	OB_Var7(a0)
			clr.b	OB_Var7a(a0)
			clr.w	OB_Var5(a0)
			clr.w	OB_Var6(a0)
			clr.b	OB_Var9a(a0)
			rts

DemonaEyeBit1		st.b	EyeHitEdgeFLG
DemonaEyeBit1a		jsr	SetBigAirExplodeAtOB_XY			;explosion
			moveq	#4,d3					;bits of debris
			moveq	#2,d7		
			jmp	SetRandomDebris

DemonaEyeBit2		bsr	SpawnEyeHellHound			;spawn a hell hound
			move.w	#RabidHHSetEye1STATE,OB_State(a1)
			clr.b	DemonaFLG2
			rts

EyeTidyPlayer		move.l	Plr_Database,a1	   			;make goliath wait
			move.w	#GolDemonaStartSTATE,OB_State(a1)
			move.b	#_DB_Fall,OB_Var1(a1)
	     		rts

EyeTrajectory		btst.b	#1,second
			bne.s	.n1	
			bsr	SetupEyeOfOdinTrail
.n1			moveq	#0,d1					;move the eye 
			move.b	OB_Var7a(a0),d1
			jsr	TrajectoryMove	

			addq.b	#1,OB_Var8(a0)
			and.b	#1,OB_Var8(a0)
			bne.s	.o1
			tst.b	OB_Var6(a0)
			beq.s	.spdup
			tst.b	OB_Var7a(a0)
			beq.s	.fin
			subq.b	#1,OB_Var7a(a0)
			rts
.spdup			cmp.b	#6,OB_Var7a(a0)
			beq.s	.o1
			addq.b	#1,OB_Var7a(a0)

.o1			tst.b	OB_Var5(a0)
			beq.s	.no
			tst.b	OB_Var5(a0)
			beq.s	.no
			st.b	OB_Var6(a0)
			rts
.no			jmp	TrajectoryHit
			
.fin			clr.b	OB_Var7(a0)
			rts

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί EYE OF ODIN TRAIL							   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SetupEyeOfOdinTrail	move.l	a0,-(sp)
			SPAWN_LOLO	EyeOfOdinTrail_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#EyeOfOdinTrail_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_newpal,OB_Flag1(a1)
			move.w	#cp2,OB_Pal(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			lea	EyeOfOdinTrailANM,a2
			jsr	SetNewAnimA1
 			jmp	ForceNewAnimA1
.1			move.l	(sp)+,a0
			rts

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


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί GENERIC TRAJECTORY PROJECTILE CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnEnergyInfuser	move.w	#Infuser_OB,d2
			jsr	FindObject
			bmi.s	.x
			move.l	a0,-(sp)
			SPAWN_LO	Infuser_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#Infuser_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			add.w	#$48,OB_Ypos(a1)
;			addq.w	#4,OB_Xpos(a1)
			clr.b	OB_EventVar1(a1)
			clr.b	OB_EventVar2(a0)
			move.l	a1,OB_Task(a0)
			SFX	80
			lea	InfuserANM,a2
			jsr	SetNewAnimA1
 			jmp	ForceNewAnimA1
.1			move.l	(sp)+,a0
.x			rts

Infuser_Logic		tst.b	OB_EventVar2(a0)
			beq.s	.1
			clr.b	OB_EventVar2(a0)
			SFX	83
.1			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jmp	SwitchObjectOff
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί GENERIC TRAJECTORY PROJECTILE CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnGenericTrajProj	move.l	a0,-(sp)
			SPAWN_HI	4*32
			bpl.s	.1
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#TrajectoryProj_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.b	#4,OB_Var8(a1)
			jmp	FlagYESn
.1			move.l	(sp)+,a0
			jmp	FlagNOn

TrajectoryProj_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.w	Plr_XPos,TargetX
			move.w	Plr_YPos,TargetY
			jsr	TrajectorySetup
			clr.w	OB_Var5(a0)
			clr.w	OB_Var6(a0)
			move.b	#DemEyeBoltsHitPOWER,OB_HitPower(a0)
			jmp	SetMediumAttack

.ok			btst.b	#ob_hitting,OB_Flag1(a0)
			bne.s	.fin
			bsr	GetUnder
			tst.b	d2
			bmi.s	.fin	
			tst.b	0(a1)
			bne.s	.fin

			moveq	#0,d1
			move.b	OB_Var8(a0),d1
			jmp	TrajectoryMove
.fin			jsr	SetSmallAirExplodeAtOB_XY
			jmp	SwitchObjectOff



; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί LEVEL #1 Mechanics/enemies						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ
; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί BREAKAWAY WALL CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

L1BreakWall_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelWalls,a1
			tst.b	0(a1,d1.w)
			beq.s	.ok
			jmp	SwitchObjectOff

.ok			btst	#0,d1
			beq.s	.2
			bset.b	#ob_xflp,OB_Flag1(a0)
			sub.w	#5,OB_Xpos(a0)
			bra	.3
.2			bclr.b	#ob_xflp,OB_Flag1(a0)
			add.w	#$14,OB_Xpos(a0)
.3			sub.w	#$11-5,OB_Ypos(a0)
			bset.b	#ob_setup,OB_Flag2(a0)
			bset.b	#ob_hiprior,OB_Flag2(a0)			
			lea	CastleWallOverANM,a1
			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
			jsr	WallDebris
			
			SFX 	34

			jmp	HandleEnemyKilled
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί CATAPULT WALL CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Catapult_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			sub.w	#$10,OB_Ypos(a0)
			
			btst.b	#0,OB_Var1(a0)
			bne.s	.l
.r			bclr.b	#ob_xflp,OB_Flag1(a0)
			add.w	#$30,OB_Xpos(a0)
			bra	.o1
.l			bset.b	#ob_xflp,OB_Flag1(a0)
			sub.w	#$20,OB_Xpos(a0)

.o1			clr.w	OB_Var2(a0)
			clr.b	OB_EventVar1(a0)
			clr.b	OB_EventVar2(a0)
			lea	CatapultANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_Var2(a0)
			bne.s	.pull
			
			move.l	Plr_Database,a1
			cmp.w	#GolFallSTATE,OB_State(a1)
			beq.s	.y1
			cmp.w	#GolJumpAttackSTATE,OB_State(a1)
			bne	.x
.y1			jsr	PlayerBody2EnemyBody
			bpl	.x
			move.w	#4,OB_Yspd(a1)
			st.b	OB_Var2(a0)
			lea	CatapultCockANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
.pull			tst.b	OB_EventVar2(a0)
			beq.s	.a
			SFX	11
			clr.b	OB_EventVar2(a0)
  			move.l	Plr_Database,a1
			move.w	#GolStunSTATE,OB_State(a1)
			move.w	#3,OB_Var1(a1)
			move.w	OB_Ypos(a0),d1
			sub.w	#$10,d1
			move.w	d1,OB_Ypos(a1)
			lea	GolGroundZeroANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1

.a			tst.b	OB_EventVar1(a0)
			beq.s	.no
			clr.b	OB_EventVar1(a0)
			st.b	SteamVentFLG
			moveq	#0,d1	
			move.b	OB_Var3(a0),d1
			ext.w	d1
			move.w	d1,GolThrownVelX
			moveq	#0,d1	
			move.b	OB_Var3a(a0),d1
			move.w	d1,GolThrownVelY
.x			rts
.no			tst.l	OB_AnSequence(a0)
			bne.s	.x
			clr.b	OB_Var2(a0)
			lea	CatapultANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

		
; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί BREAKAWAY FLOOR CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

BreakFloor_Logic   	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelSkylights,a1
			tst.b	0(a1,d1.w)
			beq.s	.2
  			jmp	SwitchObjectOff
			
.2			bset.b	#ob_setup,OB_Flag2(a0)
			sub.w	#16,OB_Ypos(a0)
			add.w	#$28-11,OB_Xpos(a0)
			clr.b	OB_Var1a(a0)
			lea	CollapseFloorANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.1			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelSkylights,a1
			tst.b	0(a1,d1.w)
			beq.s	.x
			SFX	34
			move.w	OB_Xpos(a0),TempX
			move.w	OB_Ypos(a0),d2
			addq.w	#8,d2
			move.w	d2,TempY
			moveq	#5,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			jsr	SetRandomDebris
			jmp	HandleEnemyKilled
.x			rts
			
	
; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί GATE CONTROL LOGIC							   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Gate_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.w	OB_Ypos(a0),d1
			subq.w	#8,d1
			move.w	d1,OB_WYpos(a0)
			lea	GateANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			bsr	HandleGatesDetect
			move.w	OB_Ypos(a0),d1
			cmp.w	OB_WYpos(a0),d1
			bge.s	.no
.yes			move.b	#GateHitPOWER,OB_HitPower(a0)	;gate detects
			jmp	SetBigAttack
.no			clr.b	OB_HitPower(a0)				;gate doesn't detects
			and.b	#%11111000,OB_Flag6(a0)
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί GATE CRUSHER CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

GateCrushSPD		equ	2

GateCrusher_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	#GateHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			add.w	#$c,OB_Xpos(a0)
			add.w	#$38,OB_Ypos(a0)
			clr.b	OB_Var1(a0)
			move.b	#(6*16)/GateCrushSPD,OB_Var1a(a0)
			move.w	OB_Ypos(a0),OB_WYpos(a0)	;save original y position
   			SFX	121
			lea	GateANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			bsr	HandleGatesDetect
			
			tst.b	OB_Var1(a0)
			beq.s	.up
			cmp.b	#1,OB_Var1(a0)
			beq.s	.down
			
.wait			sub.b	#1,OB_Var2(a0)
			bne.s	.x
   			SFX	121
			clr.b	OB_Var1(a0)
			move.b	#(6*16)/GateCrushSPD,OB_Var1a(a0)
			rts	

.down			addq.b	#1,OB_Var2(a0)			;speed up
			and.b	#3,OB_Var2(a0)
			bne.s	.d1
			addq.b	#1,OB_Var1a(a0)
.d1			moveq	#0,d1
			move.b	OB_Var1a(a0),d1
			add.w	d1,OB_Ypos(a0)

			move.w	OB_WYpos(a0),d1
			cmp.w	OB_Ypos(a0),d1
			bgt.s	.x
			SFX	57
			move.w	OB_WYpos(a0),OB_Ypos(a0)
			move.b	#2,OB_Var1(a0)
			move.b	#$20,OB_Var2(a0)
.x			rts

.up			subq.b	#1,OB_Var1a(a0)
			bne.s	.u1
   			SFX	122
			move.b	#1,OB_Var1(a0)
			rts
.u1			subq.w	#GateCrushSPD,OB_Ypos(a0)
			rts


GateHeights		dc.w	$4e8,$4e8,0,$be0,$890,$4d8,$4d8,$4d8

HandleGatesDetect	lea	LevelGates,a1
			lea	GateHeights,a2
			move.w	OB_ObNum(a0),d1	
			sub.w	#$58,d1
			bpl.s	.ok
			
			moveq	#2,d1			;gate crusher
			cmp.w	#$4e8,OB_Ypos(a0)
			bgt.s	.stop
			bra	.go

.ok			move.w	d1,d2			;regular gate
			asl.w	#1,d2
			move.w	0(a2,d2.w),d2
			cmp.w	OB_Ypos(a0),d2
			blt.s	.stop
.go			clr.b	0(a1,d1.w)
			rts
.stop			st.b	0(a1,d1.w)
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί COUNTER WEIGHT CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnWEIGHTS		move.w	#Weight_MAX_Size,d3
			jsr	VRamAlloc_BF			;allocate the VRAM
			bpl.s	.x
			move.w	d3,WEIGHT_VRAM_L		;save length of block
			move.w	d1,WEIGHT_VRAM_A		;save address of block
			lsr.w	#5,d1				;/32
			move.w	d1,WEIGHT_VRAM_Adiv32		;save address/32 of block

			lea	WeightANM,a1			;set anim
			move.w	WEIGHT_VRAM_A,d1		;address in VRAM to DMA to
			move.w	WEIGHT_VRAM_L,d2		;length  of DMA block
			jsr	ResidentObjectDMA		;do initial DMA

.x			rts


Weight_Logic	    	btst.b	#ob_setup,OB_Flag2(a0)
			bne	.ok
			bset.b	#ob_setup,OB_Flag2(a0)

			move.l	OB_RefAnRam(a0),a2			;get table for objects RAM info (a2)
			move.w	WEIGHT_VRAM_L,_VRAM_L(a2)		;save length of block
			move.w	WEIGHT_VRAM_A,_VRAM_A(a2)		;save address of block
			move.w	WEIGHT_VRAM_Adiv32,_VRAM_Adiv32(a2)	;save address/32 of block
			lea	WeightANM,a1				;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
		
			movem.l	a0/d0,-(sp)
			SPAWN_LO	Gate_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#Gate_OB,OB_Type(a1)
			move.w	OB_ObNum(a0),OB_ObNum(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.w	OB_Var1(a0),OB_Var1(a1)
			move.w	OB_Var4(a0),d1
			add.w	d1,OB_Xpos(a1)
			tst.w	d1
			bpl.s	.1aa
			bset.b	#ob_xflp,OB_Flag1(a1)
.1aa			move.w	OB_Var5(a0),d1
			add.w	d1,OB_Ypos(a1)
			move.l	a0,OB_Task(a1)
			move.l	a1,OB_Task(a0)
			bra	.nosp
.1			movem.l	(sp)+,d0/a0
			
.nosp			move.b	#WeightHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack

			add.w	#8,OB_Xpos(a0)
			moveq	#0,d1
			move.b	OB_Var2a(a0),d1
			asl.w	#1,d1
			sub.w	d1,OB_Ypos(a0)
			clr.w	OB_Var3(a0)
			rts
			
.ok			move.w	#$180,d1
			jsr	TestProxX
			bpl.s	.off
			cmp.w	#Level12,levnum
			beq.s	.l12
    			move.w	#$100,d1
			bra	.ll
.l12			move.w	#$60,d1
.ll			jsr	TestProxY_Above
			bpl.s	.off
			move.w	#$140,d1
			jsr	TestProxY_Below
			bmi.s	.1a
.off			move.l	OB_Task(a0),a1
			jsr	SwitchObjectOffA1
			jmp	SwitchObjectOff
			
.1a			move.l	Plr_Database,a1
			cmp.w	#GolJumpToWeightSTATE,OB_State(a1)
			bge	.down
			jsr	PlayerBody2EnemyBody
			bmi.s	.body
			jsr	PlayerFeet2EnemyBody
			bmi.s	.feet
			bclr.b	#ob_carry,OB_Flag3(a0)
			bra	.up

.body			move.w	OB_Ypos(a0),d1
			add.w	#92,d1
			cmp.w	Plr_YPos,d1
			blt	.up
			move.w	OB_Xpos(a0),d1
			sub.w	#$10,d1
			cmp.w	Plr_XPos,d1
			blt.s	.bs1
			btst.b	#ob_xflp,OB_Flag1(a1)
			beq.s	.b1
			bra	.up
.bs1			add.w	#$20,d1
			cmp.w	Plr_XPos,d1
			bgt	.up
			btst.b	#ob_xflp,OB_Flag1(a1)
			beq	.up
.b1			clr.b	PlrFallOnWeightFLG
			st.b	PlrJumpOnWeightFLG
			bra	.so

.feet			st.b	PlrFallOnWeightFLG
			clr.b	PlrJumpOnWeightFLG
			move.w	d2,OB_Ypos(a1)			;plrs y=top of weight

.so			bset.b	#ob_carry,OB_Flag3(a0)
			move.l	a0,DetectedWeightOB
			
.down			cmp.l	DetectedWeightOB,a0
			bne.s	.x
			move.b	OB_Var2a(a0),d1			;max 
			asl.b	#1,d1	
			cmp.b	OB_Var3(a0),d1
			bgt.s	.a
			move.b	d1,OB_Var3(a0)
			rts
.a			move.l	OB_Task(a0),a2
			addq.w	#2,OB_Ypos(a0)
			addq.w	#2,OB_Ypos(a1)				;without setting plrs y movement speed
			subq.w	#2,OB_Ypos(a2)
			addq.b	#2,OB_Var3(a0)
			SFX	36
			bclr.b	#ob_movupdn,OB_Flag5(a1)		;effectively smooths the scroll
.x			rts
			
.up			cmp.l	DetectedWeightOB,a0
			bne.s	.x
			bclr.b	#ob_carry,OB_Flag3(a0)
			btst.b	#0,second
			beq.s	.x
			tst.b	OB_Var3(a0)
			beq.s	.x
			move.l	OB_Task(a0),a2
			subq.w	#1,OB_Ypos(a0)
			addq.w	#1,OB_Ypos(a2)
			subq.b	#1,OB_Var3(a0)
			move.w	OB_Ypos(a0),d1
			and.w	#$7,d1
			bne.s	.x
			SFX	36
			rts
			

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί COUNTER WEIGHT CRUSHER CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

WeightCrusher_Logic    	btst.b	#ob_setup,OB_Flag2(a0)
			bne	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	#WeightHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			move.l	OB_RefAnRam(a0),a2			;get table for objects RAM info (a2)
			move.w	WEIGHT_VRAM_L,_VRAM_L(a2)		;save length of block
			move.w	WEIGHT_VRAM_A,_VRAM_A(a2)		;save address of block
			move.w	WEIGHT_VRAM_Adiv32,_VRAM_Adiv32(a2)	;save address/32 of block
			sub.w	#$8,OB_Ypos(a0)
			move.w	OB_Ypos(a0),OB_WYpos(a0)
			clr.w	OB_Var1(a0)
			clr.w	OB_Var2(a0)
			move.b	#3,OB_Var1(a0)
			jsr	Randy
			and.b	#$1f,d6
			or.b	#$10,d6
			move.b	d6,OB_Var2a(a0)
			addq.w	#8,OB_Xpos(a0)
			lea	WeightANM,a1				;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
.ok			move.l	Plr_Database,a1
			jsr	PlayerBody2EnemyBody
			bmi.s	.body
			jsr	PlayerFeet2EnemyBody
			bmi.s	.feet
			cmp.w	#GolJumpToWeightSTATE,OB_State(a1)
			bge	.cont
			bclr.b	#ob_carry,OB_Flag3(a0)
			bra	.cont

.body			btst.b	#grndmode,OB_MasterMode(a1)
			bne.s	.cont
			move.w	OB_Xpos(a0),d1
			sub.w	#$10,d1
			cmp.w	Plr_XPos,d1
			blt.s	.bs1
			btst.b	#ob_xflp,OB_Flag1(a1)
			beq.s	.b1
			bra	.cont
.bs1			add.w	#$20,d1
			cmp.w	Plr_XPos,d1
			bgt	.cont
			btst.b	#ob_xflp,OB_Flag1(a1)
			beq	.cont
.b1			clr.b	PlrFallOnWeightFLG
			st.b	PlrJumpOnWeightFLG
			bra	.so
.feet			st.b	PlrFallOnWeightFLG
			clr.b	PlrJumpOnWeightFLG
			move.w	d2,OB_Ypos(a1)			;plrs y=top of weight
.so			bset.b	#ob_carry,OB_Flag3(a0)
			move.l	a0,DetectedWeightOB
		
.cont			move.l	Plr_Database,a1
		
			tst.b	OB_Var1(a0)
			beq	.fall
			cmp.b	#1,OB_Var1(a0)
			beq.s	.wait1
			cmp.b	#2,OB_Var1(a0)
			beq.s	.up

.wait2			subq.b	#1,OB_Var2a(a0)
			bne.s	.xx
			clr.w	OB_Var1(a0)	
			clr.w	OB_Var2(a0)		
.xx			rts

.wait1			subq.b	#1,OB_Var2a(a0)
			bne.s	.xx
			addq.b	#1,OB_Var1(a0)
			rts

.up			subq.b	#1,OB_Var3(a0)
			bne.s	.u1
			addq.b	#1,OB_Var1(a0)
			jsr	Randy
			and.b	#$f,d6
			or.b	#$10,d6
			move.b	d6,OB_Var2a(a0)
			rts
.u1			SFX	36
			subq.w	#2,OB_Ypos(a0)
			btst.b	#ob_carry,OB_Flag3(a0)
			beq.s	.xx
			sub.w	#2,OB_Ypos(a1)				;without setting plrs y movement speed
			bset.b	#ob_movupdn,OB_Flag5(a1)		;effectively smooths the scroll
			rts

.fall			addq.b	#1,OB_Var1a(a0)	
			and.b	#1,OB_Var1a(a0)
			bne.s	.f1
			cmp.b	#8,OB_Var2(a0)
			beq.s	.f1
			addq.b	#1,OB_Var2(a0)

.f1			moveq	#0,d1
			move.b	OB_Var2(a0),d1
			add.w	d1,OB_Ypos(a0)
			btst.b	#ob_carry,OB_Flag3(a0)
			beq.s	.f2
			add.w	d1,OB_Ypos(a1)				;without setting plrs y movement speed
			bclr.b	#ob_movupdn,OB_Flag5(a1)		;effectively smooths the scroll

.f2			move.w	OB_WYpos(a0),d1
			cmp.w	OB_Ypos(a0),d1
			bgt.s	.x
			SFX	57
			addq.b	#1,OB_Var1(a0)
			jsr	Randy
			and.b	#$1f,d6
			or.b	#$10,d6
			move.b	d6,OB_Var2a(a0)
			move.b	#$30,OB_Var3(a0)
			move.w	d1,OB_Ypos(a0)
.x			rts
			

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί WALL FIRE CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

WallFire_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	#WallFireHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			btst.b	#ob_xflp,OB_Flag1(a0)
			bne.s	.r
.l			addq.w	#5,OB_Xpos(a0)
			bra	.lr
.r			addq.w	#4,OB_Xpos(a0)
.lr			lea	FireWallANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί BALISTA CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Balista_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			sub.w	#$11,OB_Ypos(a0)
			add.w	#$28,OB_Xpos(a0)
			move.l	#-1,OB_Task(a0)
			clr.w	OB_Var2(a0)
			move.l	#BalistaOffRoutine,OB_OffRoutine(a0)
			lea	BalistaANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_Var2(a0)
			beq.s	.idle
			cmp.b	#1,OB_Var2(a0)
			beq.s	.cock
			cmp.b	#2,OB_Var2(a0)
			beq.s	.gen
			cmp.b	#3,OB_Var2(a0)
			beq	.wait

.fire			tst.l	OB_AnSequence(a0)
			bne.s	.x
			clr.w	OB_Var2(a0)
			lea	BalistaANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
.idle			subq.b	#1,OB_Var1a(a0)
			bne.s	.x
			move.b	#$10,OB_Var1a(a0)
			move.b	#1,OB_Var2(a0)
			lea	BalistaCockANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.cock			tst.l	OB_AnSequence(a0)
			bne.s	.x
			clr.w	OB_Var7(a0)
			move.b	#2,OB_Var2(a0)
.x			rts

.gen			move.b	#$20,OB_Var3(a0)
			move.b	#3,OB_Var2(a0)
			
			move.l	a0,-(sp)
			SPAWN_LO	BalistaLog_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			move.l	(sp)+,a0
			jsr	SetFlipFromMother
			move.w	#BalistaLog_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),d1
			sub.w	#$48,d1
			move.w	d1,OB_Ypos(a1)
			clr.w	OB_Var7(a1)
			move.l	a0,OB_Task(a1)
			move.l	a1,OB_Task(a0)
			rts
.1			move.l	(sp)+,a0
.xx			rts

.wait			tst.b	OB_Var7a(a0)
			beq.s	.xx
			subq.b	#1,OB_Var3(a0)
			bne.s	.xx
			SFX	35
			move.l	OB_Task(a0),a1
			st.b	OB_Var7a(a1)
			move.l	#-1,OB_Task(a0)
			move.b	#4,OB_Var2(a0)
			lea	BalistaFireANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim


BalistaOffRoutine	move.l	OB_Task(a0),a1
			cmp.l	#-1,a1
			beq.s	.1
			st.b	OB_Var7a(a1)
.1			rts

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί BALISTA LOG CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

BalistaLog_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
   			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	#BalistaLogHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			clr.w	OB_Var1(a0)
			lea	BalistaLogANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_Var7a(a0)
			bne.s	.fire

.fall			addq.b	#1,OB_Var1(a0)
			and.b	#3,OB_Var1(a0)
			bne.s	.1
			addq.b	#1,OB_Var1a(a0)

.1			move.l	OB_Task(a0),a1
			tst.b	OB_Var7a(a1)
			bne.s	.x
			move.w	OB_Ypos(a1),d1
			sub.w	#9,d1
			cmp.w	OB_Ypos(a0),d1
			bgt.s	.aa
			move.w	d1,OB_Ypos(a0)
			st.b	OB_Var7a(a1)
.x			rts
.aa			moveq	#0,d1
			move.b	OB_Var1a(a0),d1
			jmp	MoveGolDown_Smooth

.fire			moveq	#8,d1
			jsr	MoveGolLeftRightFLP3
			btst.b	#ob_hitting,OB_Flag1(a0)
			bne.s	.yup
			bsr	GetUnderFEET
			bsr	TestLevelWalls
			bmi.s	.yup
			jsr	PullContourUnder
			beq.s	.x
.yup			cmp.b	#SB_Ceiling,d2
			beq.s	.x
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			add.w	#$10,d2
			jsr	SetBigAirExplode
			jsr	SetupScreenShakeRand
			jmp	SwitchObjectOff



; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί PASTEOVER WALL CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

PasteWall_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelPasteWalls,a1
			tst.b	0(a1,d1.w)
			beq.s	.1
  			jmp	SwitchObjectOff
.1			bset.b	#ob_setup,OB_Flag2(a0)
			clr.w	OB_Var7(a0)
			subq.w	#4,OB_Xpos(a0)
			bset.b	#ob_xflp,OB_Flag1(a0)
			lea	CastleWallOverANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_Var7a(a0)
			bne	.boom

			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelPasteWalls,a1
			tst.b	0(a1,d1.w)
			beq.s	.x
			st.b	OB_Var7a(a0)

			SFX	1
			
			movem.l	a0/d0,-(sp)
			SPAWN_HI	FlameBoulder_MAX_Size
			bpl.s	.2
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#FlameBoulder_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			bset.b	#ob_hiprior,OB_Flag2(a1)
			move.w	OB_Xpos(a0),d1
			move.w	d1,OB_Var2(a1)
			add.w	#$50,d1
			move.w	d1,OB_Xpos(a1)
			move.w	OB_Ypos(a0),d1
			sub.w	#$20,d1
			move.w	d1,OB_Var3(a1)
			sub.w	#$70,d1
			move.w	d1,OB_Ypos(a1)
			move.l	a0,OB_Task(a1)
			move.l	a1,OB_Task(a0)
.x			rts
.2			movem.l	(sp)+,d0/a0
			rts

.boom			tst.b	OB_Var7(a0)
			beq.s	.x
			jmp	SwitchObjectOff


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί FLAMING BOULDER CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

FlameBoulder_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.w	#FlamingBoulderHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			move.w	OB_Var2(a0),TargetX
			move.w	OB_Var3(a0),TargetY
			jsr	TrajectorySetup
			clr.w	OB_Var5(a0)
			lea	FlameBoulderANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			moveq	#6,d1
			jsr	TrajectoryMove

			tst.b	OB_Var5(a0)
			beq.s	.1
			tst.b	OB_Var5a(a0)
			bne.s	.fin
.1			jmp	TrajectoryHit
			
.fin			move.l	OB_Task(a0),a1
			st.b	OB_Var7(a1)
			
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			add.w	#$c,d1
			add.w	#$20,d2
			jsr	SetBigAirExplode
			moveq	#3,d7
			move.w	#2,d3	
			jsr	SetRandomDebris
			jsr	SetupScreenShakeRand
			jmp	SwitchObjectOff


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

VikingDeathSFX		SFX	45
			rts
;			jsr	Randy
;			and.l	#1,d6
;			add.l	#44,d6
;			move.l	d6,sfx_poll
;			jmp	SetSFX

