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


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


Test2			bra	Orb_Logic
;			btst.b	#ob_setup,OB_Flag2(a0)
;			bne.s	.1
;			bset.b	#ob_setup,OB_Flag2(a0)
;			lea	TestBotANM,a1
;			bsr	SetNewAnim
			 
.1			rts



			bra	Orb_Logic
			rts



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


Health1_Logic		rts

Health2_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
   			rts

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

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

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

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

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

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


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

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

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



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

FlameIntensity		equ	1
FlameSpread		equ	1
FlameDecay		equ	$33

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


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

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


BurnOffRout		clr.b	BurnFirst
  			clr.b	BurnProcess
			rts

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


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

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

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

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

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

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


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



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


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


ConvertFlame		lea	FlameBuff1,a3
			move.l	a3,a4

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

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

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

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

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


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

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

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

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

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

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

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

ExpIntensity		equ	$3
ExpDecay		equ	$33


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


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

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



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

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

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

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

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


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί COMPOSITE STRAWMAN							   Ί
; ΜΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΉ
; Ί Composite Strawman logic.						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Strawman_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
			move.b	#_ob_setup+_ob_null,OB_Flag2(a0)	;mother is null
			move.b	#_ob_composite+_ob_mother,OB_Flag5(a0)		
			
			sub.w	#$60,OB_Ypos(a0)			;position it
			bsr	GetFreeCOBJECT				;find a free composite object
			bpl.s	.x					;ohoh
			move.w	d6,OB_Var1(a0)				;save vars
			move.l	a6,OB_Var2(a0)
			bsr	GetCobjectVECS				;setup important vecs
			lea	StrawmanANM,a1				;setup this new composite object
			bra	SetNewCompositeAnim

.1			move.w	OB_Var1(a0),d6
			move.l	OB_Var2(a0),a6
			bsr	AnimCob					;animate this composite object

.x			rts


; NOTES ON HOW COMPOSITE OBJECTS WORK :
;
;	Composite objects are made up of regular objects.  In every composite
;	object there is a MOTHER and a varying number of CHILDREN.  The MOTHER
;	object is a regular object and is NULL (that is invisible) and has over-
;	all control.  Each MOTHER object has a number assigned to it that is unique.
;	This Unique number is used as a pointer to a sub-database for the comp-
;	osite object.  The Composite objects world x,y position is taken from the
;	MOTHERS x,y position.  Unique and Non-Unique CHILDREN are de/allocated on
;	a frame basis.  Non-unique CHILDREN are still a regular object but they 
;	use the data (graphic) from the unique CHILD.
;

SetNewCompositeAnim	move.l	(a1)+,OB_AnSequence(a0)			;anim seq vec
			move.l	(a1)+,OB_AnChrData(a0)			;raw char data
			clr.w	OB_AnDex(a0)
			clr.b	OB_AnCnt(a0)
			clr.b	OB_AnCmp(a0)
			bclr.b	#cob_firstpass,COB_Flag1(a6)

			;Drop thru to animate first pass

AnimCob			move.b	OB_AnCnt(a0),d1
			cmp.b	OB_AnCmp(a0),d1
			beq.s	.ok
			addq.b	#1,OB_AnCnt(a0)			
			bra	UpdateCHILDREN_XY

.ok			clr.b	OB_AnCnt(a0)
			
			move.l	OB_AnSequence(a0),a1
.again			move.w	OB_AnDex(a0),d1
		
			move.w	8(a1,d1.w),d2
			beq.s	.anm

			cmp.w	#ARep,d2
			bne.s	*
			clr.w	OB_AnDex(a0)
			bra	.again

			;do all the other funky stuff here
			;like looping etc
			rts
			
			;multisprite
			;subsprite
			;strawmanframe001
			;strawmanset
			;STRWPRTS_0001
			
			
.anm			move.l	10(a1,d1.w),a5
			move.l	a5,OB_Var4(a0)
			move.b	14(a1,d1.w),OB_AnCmp(a0)			;next duration
			
			btst.b	#cob_firstpass,COB_Flag1(a6)
			bne.s	.1
			bset.b	#cob_firstpass,COB_Flag1(a6)
			
			move.w	(a5)+,d1	   			;spawn # of objects needed for this frame
			move.l	(a5)+,a3				;object set table
			move.b	d1,COB_ObCntOLD(a6)
			move.w	OB_Xpos(a0),COBX
			move.w	OB_Ypos(a0),COBY
			bsr	SpawnCHILDREN
			bra	cbump8

.1			move.w	(a5)+,d1	   			;spawn # of objects needed for this frame
			move.l	(a5)+,a3				;object set table
			move.b	d1,COB_ObCntOLD(a6)
			move.w	OB_Xpos(a0),COBX
			move.w	OB_Ypos(a0),COBY
			bsr	UpdateCHILDREN
			bra	cbump8

cbump8			addq.w	#8,OB_AnDex(a0)
			rts


			rsreset
_COBsetindex		rs.b	1	
_COBxyflpri		rs.b	1
_COBxoffset		rs.w	1
_COByoffset		rs.w	1	

sb1			=	1
sb2			=	_es

sizertab		rept	MaxSprs
			dc.w	sb1*sb2
sb1			=	sb1+1
			endr

SpawnCHILDREN		movem.l	d0-d7/a0-a6,-(sp)			;protect the registers	
			
			move.l	a0,a1

			subq.w	#1,d1
			moveq	#0,d7
			
.l1			movem.l	d1/a5,-(sp)
			
.a			bsr	GetFreeOBJECT_HI 			;get a free object
			bpl	.nxt					;no free objects
			
			moveq	#0,d3
			move.b	_COBsetindex(a5),d3			;get unique object index
			
			move.l	COB_UniqueVEC(a6),a2
			tst.b	0(a2,d3.w)				;is it setup?				
			bne	.clone					;yes: clone it
			
			st.b	0(a2,d3.w)				;spawn a new unique object. Flag its existance	
			move.l	COB_LinksVEC(a6),a2			;put object # & Addrs at ,index
			move.b	d0,0(a2,d3.w)				;put object number in link list
			move.w	d3,d7
			asl.w	#2,d7
			move.l	COB_Addrs2VEC(a6),a2
			move.l	a0,0(a2,d7.w)				;put object database address in address list
			
			move.l	COB_AgeVEC(a6),a2			
			move.b	#5,0(a2,d3.w)				;set the new unique objects age
			asl.w	#2,d3
			move.l	0(a3,d3.w),a2				;get vec to animdata for unique object	
			move.l	a2,OB_AnSeqLab(a0)			;frame (anm >>Label.l<<)

			moveq	#0,d1
			move.b	0(a2),d1				;get # of subsprites
			asl.w	#1,d1
			lea	sizertab,a4				;get add from sizer table 
			move.w	0(a4,d1.w),d1				
			lea	_Sub_bump(a2),a2
;			move.l	_Coff(a2),d4				;d4=source char data offset
			add.l	d1,a2
			move.w	(a2),d3					;this word should be the size of this frame (.b)
			
			bsr	VRamAlloc_BF				;allocate the VRAM
			bpl	FlagNOd
			bsr	GetObRAMTab				;set reference ram
			move.w	d3,_VRAM_L(a2)				;save length of block
			move.w	d1,_VRAM_A(a2)				;save address of block
			lsr.w	#5,d1					;/32
			move.w	d1,_VRAM_Adiv32(a2)			;save address/32 of block
			bsr	SetupObject				;set up a generic resident object 
			bset.b	#ob_flown,OB_Flag3(a0)			;set this object flown
			move.w	#Child_OB,OB_Type(a0)			;this is a child
			bset.b	#ob_nooff,OB_Flag2(a0)			;children can't be turned off by scroll
			move.b	#_ob_newdma+_ob_composite+_ob_child,OB_Flag5(a0)		
			move.l	OB_AnChrData(a1),OB_AnChrData(a0)	;copy mothers source charset vec
			bra	.cont1
	
.clone			bsr	CloneCHILD				;create a clone of a pre-existing unique object
			bset.b	#ob_active,OB_Flag1(a0)
	
.cont1			move.w	COBX,d2					;do x,y offsets	
			add.w	_COBxoffset(a5),d2
			move.w	d2,OB_Xpos(a0)
			move.w	COBY,d2
			add.w	_COByoffset(a5),d2
			move.w	d2,OB_Ypos(a0)
	   		
			move	#0,ccr		  			;clr ccr
			move.b	_COBxyflpri(a5),d2			;get x,y flip & priority flags
			lsr.b	d2		 			
			bcc.s	.1a					;xflipped?
			bset.b	#ob_xflp,OB_Flag1(a0)			;yup
			bra	.1b
.1a			bclr.b	#ob_xflp,OB_Flag1(a0)			;no
.1b			lsr.b	d2
			bcc.s	.2a		    			;yflipped?
			bset.b	#ob_yflp,OB_Flag1(a0)			;yup
			bra	.2b
.2a			bclr.b	#ob_yflp,OB_Flag1(a0)			;no
.2b			lsr.b	d2
			bcc.s	.3a					;hipriority?
			bset.b	#ob_hiprior,OB_Flag2(a0)		;yup
			bra	.nxt
.3a			bclr.b	#ob_hiprior,OB_Flag2(a0)		;no

.nxt			addq.w	#1,d7					;bump index	
			movem.l	(sp)+,d1/a5
			addq.l	#6,a5					;next comp object
			dbra	d1,.l1

.xit			movem.l	(sp)+,d0-d7/a0-a6
			rts


CloneCHILD		bsr	GetObRAMTab				;clone new object from pre-existing unique ob
			bsr	SetupObject				
			asl.w	#2,d3					;index					
			move.l	COB_AddrsVEC(a6),a2			;get existing objects address
			move.l	0(a2,d3.w),a2
			move.w	OB_Type(a2),OB_Type(a0)			;copy type and flags
			move.b	OB_Flag1(a2),OB_Flag1(a0)
			move.b	OB_Flag2(a2),OB_Flag2(a0)
			move.b	OB_Flag3(a2),OB_Flag3(a0)
			move.b	OB_Flag5(a2),OB_Flag5(a0)
			move.l	OB_RefAnRam(a2),OB_RefAnRam(a0)		;set anim RAM reference table
			move.l	OB_AnSeqLab(a2),OB_AnSeqLab(a0)		;frame (anm >>Label.l<<)
			move.l	OB_AnChrData(a2),OB_AnChrData(a0)	;source chr set
			rts


UpdateCHILDREN		rts
			movem.l	d0-d7/a0-a6,-(sp)			;protect the registers	
			
			move.l	COB_UniqueVEC(a6),a2			;free up all objects used in previous
			move.l	COB_LinksVEC(a6),a4			;frame.

			move.w	#MaxObsInCobs-1,d1			;max # ob obs in cob
			moveq	#0,d3
.l1			tst.b	0(a2,d3.w)				;is it setup?				
			beq.s	.1
			move.b	0(a4,d3.w),d2				;get object #
			lea	OBJECT_RAM,a1				;point to objects RAM
			asl.w	#7,d2
			add.w	d2,a1
			bclr.b	#ob_active,OB_Flag1(a1)			;flag this object usable
.1			addq.w	#1,d3
			dbra	d1,.l1

			move.l	a0,a1

			subq.w	#1,d1
			moveq	#0,d7
			
.l2			movem.l	d1/a5,-(sp)
			
.a			bsr	GetFreeOBJECT_HI 			;get a free object
			bpl	.nxt					;no free objects
			
			moveq	#0,d3
			move.b	_COBsetindex(a5),d3			;get unique object index
			
			move.l	COB_UniqueVEC(a6),a2
			tst.b	0(a2,d3.w)				;is it setup?				
			bne	.clone					;yes: clone it
			
			st.b	0(a2,d3.w)				;spawn a new unique object. Flag its existance	
			move.l	COB_LinksVEC(a6),a2			;put object # & Addrs at ,index
			move.b	d0,0(a2,d3.w)				;put object number in link list
			move.w	d3,d7
			asl.w	#2,d7
			move.l	COB_Addrs2VEC(a6),a2
			move.l	a0,0(a2,d7.w)				;put object database address in address list
			
			move.l	COB_AgeVEC(a6),a2			
			move.b	#5,0(a2,d3.w)				;set the new unique objects age
			asl.w	#2,d3
			move.l	0(a3,d3.w),a2				;get vec to animdata for unique object	
			move.l	a2,OB_AnSeqLab(a0)			;frame (anm >>Label.l<<)

			moveq	#0,d1
			move.b	0(a2),d1				;get # of subsprites
			asl.w	#1,d1
			lea	sizertab,a4				;get add from sizer table 
			move.w	0(a4,d1.w),d1				
			lea	_Sub_bump(a2),a2
;			move.l	_Coff(a2),d4				;d4=source char data offset
			add.l	d1,a2
			move.w	(a2),d3					;this word should be the size of this frame (.b)
			
			bsr	VRamAlloc_BF				;allocate the VRAM
			bpl	FlagNOd
			bsr	GetObRAMTab				;set reference ram
			move.w	d3,_VRAM_L(a2)				;save length of block
			move.w	d1,_VRAM_A(a2)				;save address of block
			lsr.w	#5,d1					;/32
			move.w	d1,_VRAM_Adiv32(a2)			;save address/32 of block
			bsr	SetupObject				;set up a generic resident object 
			bset.b	#ob_flown,OB_Flag3(a0)			;set this object flown
			move.w	#Child_OB,OB_Type(a0)			;this is a child
			bset.b	#ob_nooff,OB_Flag2(a0)			;children can't be turned off by scroll
			move.b	#_ob_newdma+_ob_composite+_ob_child,OB_Flag5(a0)		
			move.l	OB_AnChrData(a1),OB_AnChrData(a0)	;copy mothers source charset vec
			bra	.cont1
	
.clone			bsr	CloneCHILD				;create a clone of a pre-existing unique object
	
.cont1			move.w	COBX,d2					;do x,y offsets	
			add.w	_COBxoffset(a5),d2
			move.w	d2,OB_Xpos(a0)
			move.w	COBY,d2
			add.w	_COByoffset(a5),d2
			move.w	d2,OB_Ypos(a0)
	   		
			move	#0,ccr		  			;clr ccr
			move.b	_COBxyflpri(a5),d2			;get x,y flip & priority flags
			lsr.b	d2		 			
			bcc.s	.1a					;xflipped?
			bset.b	#ob_xflp,OB_Flag1(a0)			;yup
			bra	.1b
.1a			bclr.b	#ob_xflp,OB_Flag1(a0)			;no
.1b			lsr.b	d2
			bcc.s	.2a		    			;yflipped?
			bset.b	#ob_yflp,OB_Flag1(a0)			;yup
			bra	.2b
.2a			bclr.b	#ob_yflp,OB_Flag1(a0)			;no
.2b			lsr.b	d2
			bcc.s	.3a					;hipriority?
			bset.b	#ob_hiprior,OB_Flag2(a0)		;yup
			bra	.nxt
.3a			bclr.b	#ob_hiprior,OB_Flag2(a0)		;no

.nxt			addq.w	#1,d7					;bump index	
			movem.l	(sp)+,d1/a5
			addq.l	#6,a5					;next comp object
			dbra	d1,.l2

.xit			movem.l	(sp)+,d0-d7/a0-a6
			rts


UpdateCHILDREN_XY	move.l	OB_Var4(a0),a5				;get current frame
			move.l	OB_Var2(a0),a6
			move.w	(a5)+,d1	   			;# of objects in this frame
			move.l	(a5)+,a3				;table of unique objects
			move.b	d1,COB_ObCntOLD(a6)			;save it for next frame
			move.w	OB_Xpos(a0),COBX			;mothers x,y
			move.w	OB_Ypos(a0),COBY

			subq.w	#1,d1
			moveq	#0,d7
			
.l1			move.w	d7,d3
			asl.w	#2,d3
			move.l	COB_Addrs2VEC(a6),a2
			movea.l	0(a2,d3.w),a1				;put object number in link list

			move.w	COBX,d2					;do x,y offsets	
			add.w	_COBxoffset(a5),d2
			move.w	d2,OB_Xpos(a1)
			move.w	COBY,d2
			add.w	_COByoffset(a5),d2
			move.w	d2,OB_Ypos(a1)

			addq.w	#1,d7	
			addq.l	#6,a5					;next comp object
			dbra	d1,.l1

.xit			rts



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

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

RaptorBot_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			bsr	RapBotSetPatrol				;initial state
			subq.w	#8,OB_Ypos(a0)				;pos on ground
			move.l	#RapBotSetHits,OB_HitRoutine(a0)

.1			bsr	HandleBeingHit				;Generic handle hit rout
			bsr	ObjectOffBottom
			blt	SwitchObjectOff

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

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

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


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

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

RapBotTestLOGIC		bra	RapBotSetGroundZero


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

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

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

RapBotSmallHitLOGIC	rts

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

RapBotBigHitLOGIC	bsr	RapBotTectBit2
			bmi	RapBotSetHitOffEdge
			bsr	TestLevelWalls			;turn at wall
			bmi.s	.a
			bsr	HitSlideObject
			bsr	HandleContours
;			bpl	RBSF2
			
.a			tst.l	OB_AnSequence(a0)
			bne.s	.x
			btst.b	#ob_dead,OB_Flag2(a0)
			bne	RapBotSetFlrExplode
			bclr.b	#ob_beinghit,OB_Flag1(a0)
			bra	RapBotSetPatrol
.x			rts

RapBotTectBit2		btst.b	#ob_hitside,OB_Flag1(a0)
			beq.s	.rte
.lft			bsr	GetUnderFEET		;
			bsr	PullContourUnder
			beq	FlagYESd
			bsr	GetUnderLEFTLEFT
			bra	FlagNOd
.rte			bsr	GetUnderFEET		;
			bsr	PullContourUnder
			beq	FlagYESd
			bsr	GetUnderRIGHTRIGHT		
			bra	FlagNOd

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

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

RapBotThrownLOGIC	tst.b	OB_Var1(a0)
			bne	.2
			
			tst.b	GolThrowReleaseFLG
			bne.s	.1
			tst.b	GolSlamFLG
			bne	RapBotSetSlammed
			tst.b	OB_Var3(a0)
			beq.s	.x
			
			bsr	EnemyWallInterupt
			bmi	RapBotSetAirExplode
			bsr	SaveLastThrowXY
			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
.x			st.b	OB_Var3(a0)
			rts

.1			st.b	OB_Var1(a0)
			move.w	#4,OB_Var2(a0)
			lea	RapBotThrownANM,a1			;set anim
			bsr	SetNewAnim
.2			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			bsr	GetUnderLEFTLEFT
			bra	.lr	
.r			bsr	GetUnderRIGHTRIGHT
.lr			bsr	TestLevelWalls
			bmi	RapBotSetAirExplode
			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.s	.4
.3			move.w	OB_Var2(a0),d1				;get speed
			bra	MoveGolUp_Smooth			;move up
.4			lea	RapBotThrownANM,a1			;set anim
			bra	RBSF1


RapBotSetThrownLand	move.w	#RapBotThrownLandSTATE,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

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


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

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

			movem.l	d0/a0,-(sp)
			movem.l	d1-d3,-(sp)
			move.w	rndnum,d3
			and.w	#1,d3
			beq.s	.2a
			SPAWN_HI	Spark_MAX_Size
			bpl.s	.oo
			move.w	#Spark_OB,OB_Type(a0)
			bra	.2b		
.2a			SPAWN_HI	Spark_MAX_Size
			bpl.s	.oo
			move.w	#Fireball_OB,OB_Type(a0)
.2b			movem.l	(sp)+,d1-d3
			move.w	d1,OB_Xpos(a0)	
			move.w	d2,OB_Ypos(a0)	
			bset.b	#ob_tidy,OB_Flag5(a0)
			bsr	RandomParabolaSmall
			move.b	second,d3
			and.b	#1,d3
			bne.s	.1a
			move.b	#%00111110,OB_MoveFlags(a0)
			bra	.1b
.1a			move.b	#%00111111,OB_MoveFlags(a0)
.1b			movem.l	(sp)+,d0/a0
			bra	.o1

.oo			movem.l	(sp)+,d1-d3
			movem.l	(sp)+,d0/a0

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


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

RapBotSetGroundZero	

RapBotGroundZeroLOGIC	rts


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

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

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

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

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

RapBotSetStop		


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

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

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

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

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

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

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


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

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

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

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

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

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

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


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


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

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

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

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

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

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

			move.w	Plr_YPos,d1			;plr and nme on same line?
			sub.w	OB_Ypos(a0),d1
			bpl.s	.1
			neg.w	d1
.1			cmp.w	#$10,d1
			ble.s	.same
			cmp.w	#$50,d1				;within y bounds
			bgt.s	.same
;			move.w	Plr_XPos,d1
;			sub.w	OB_Xpos(a0),d1			;within x bounds
;			bpl.s	.1a
;			neg.w	d1
;.1a			cmp.w	#$100,d1
;			bgt	RapBotSetIdle
			bsr	AITestPlrIsAbove
			bmi	RapBotSetBigJumpAttack		;big jump if plr is above

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

RapBotSJA2		clr.w	OB_Var1(a0)
			move.w	#$4,OB_Var2(a0)
			clr.b	OB_EventVar1(a0)
			bset.b	#airmode,OB_MasterMode(a0)
			bsr	SetMediumAttack
			lea	RapBotJumpAttackANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

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

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


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

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

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

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

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



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

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

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

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

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


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

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

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


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

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

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

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


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

RapBotSetBackOff	move.w	#RapBotBackOffSTATE,OB_State(a0)
			lea	RapBotBackOffANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

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

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

.c			bsr	HandleContours

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


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

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

RapBotDefendLOGIC	tst.l	OB_AnSequence(a0)
			beq.s	RapBotSetDefendEnd
.x			rts


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

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

RapBotDefendEndLOGIC	tst.l	OB_AnSequence(a0)
			beq	RapBotSetPatrol
			rts


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

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

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

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

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

RapBotFaceHugRendLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.ok
			clr.b	OB_EventVar1(a0)		
			bsr	HitPlayer
			bmi	SetPlayerDead

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


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

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

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

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

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

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


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

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

RapBotLandOffLOGIC	tst.l	OB_AnSequence(a0)
			beq	RapBotSetIdle
			rts


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


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



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

		StRESET
		StDEF	SniBotGroundZeroSTATE
		StDEF	SniBotPatrolSTATE
		StDEF	SniBotTurnSTATE
		StDEF	SniBotTurnToSTATE
		StDEF	SniBotIdleSTATE
		StDEF	SniBotWalkToSTATE
		StDEF	SniBotBackOffSTATE
		StDEF	SniBotResetGunSTATE
		StDEF	SniBotTrackSTATE
		StDEF	SniBotFireSTATE
			

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

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

SniperBotLogicTable	bra	SniBotGroundZeroLOGIC
			bra	SniBotPatrolLOGIC
			bra	SniBotTurnLOGIC
			bra	SniBotTurnToLOGIC
			bra	SniBotIdleLOGIC
			bra	SniBotWalkToLOGIC
			bra	SniBotBackOffLOGIC
			bra	SniBotResetGunLOGIC
			bra	SniBotTrackLOGIC
			bra	SniBotFireLOGIC
			

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

SniBotSetHits		move.b	OB_Flag6(a0),d2
			and.b	#%11000111,OB_Flag6(a0)
			
			btst	#ob_hit_small,d2
			bne.s	SniBotSetExplode
			btst	#ob_hit_med,d2
			bne.s	SniBotSetExplode
			btst	#ob_hit_big,d2
			bne.s	SniBotSetExplode
			rts

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

; - SniperBot ground zero --------------------------------------------------

SniBotSetGroundZero	move.w	#SniBotGroundZeroSTATE,OB_State(a0)
			bsr	ClrHitStuff
			clr.b	OB_MasterMode(a0)
			lea	SniBotZeroANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

SniBotGroundZeroLOGIC	rts


; - SniperBot patrol -------------------------------------------------------

SniBotSetPatrol		move.w	#SniBotPatrolSTATE,OB_State(a0)
			bsr	ClrHitStuff
			clr.b	OB_MasterMode(a0)
			lea	SniBotWalkANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

SniBotPatrolLOGIC	move.l	#SniBotSetPatrol,d1
			bsr	DoSniBotAI
			
			jsr	Randy
			and.w	#$1ff,d6
			beq	SniBotSetIdle
			cmp.w	#1,d6
			beq	SniBotSetTurn
			
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte

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


; - SniperBot turn ---------------------------------------------------------

SniBotSetTurn		move.w	#SniBotTurnSTATE,OB_State(a0)
			lea	SniBotTurnANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

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


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

SniBotSetIdle		bsr	DoesNmeFacePlayer			;if nme doesn't face plr 
			bpl	SniBotSetTurn				;nme turns
			move.w	#SniBotIdleSTATE,OB_State(a0)
			jsr	Randy
			and.b	#$3f,d6
			or.b	#$10,d6
			move.b	d6,OB_Var1(a0)
			clr.b	OB_MasterMode(a0)
			bsr	ClrHitStuff
			cmp.l	#SniBotIdleANM,OB_AnSequence(a0)
			beq.s	.x
			lea	SniBotIdleANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim
.x			rts

SniBotIdleLOGIC		subq.b	#1,OB_Var1(a0)
			beq	SniBotSetWalkTo
			
			move.l	#-1,AI_Exclude
			lea	SNIPERBOT_AI2,a1
			bsr	AI_Routine
			bpl.s	.x
			jmp	(a1)
.x			rts


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

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

SniBotWalkToLOGIC	move.l	#SniBotSetWalkTo,d1
			bsr	DoSniBotAI

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

.2			bsr	GetUnderFEET		;stop at edge
			bsr	PullContourUnder
			beq	SniBotSetIdle
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte
.lft			bsr	GetUnderLEFTLEFT		;stop at wall	
			bsr	TestLevelWalls	
			bmi	SniBotSetIdle
			moveq	#2,d1
			bsr	MoveGolLeft_Smooth
			bra	HandleContours			;handle the contours

.rte			bsr	GetUnderRIGHTRIGHT		;stop at wall
			bsr	TestLevelWalls	
			bmi	SniBotSetIdle
			moveq	#2,d1
			bsr	MoveGolRight_Smooth
			bra	HandleContours			;handle the contours


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

SBSTT2			PUSHADDRS SniBotSWT1
			bra	SniBotSetTurnTo
SBSTT1			PUSHADDRS SniBotSWT2

SniBotSetTurnTo		PUSHSTATE
			move.w	#SniBotTurnToSTATE,OB_State(a0)
			lea	SniBotTurnANM,a1			;set anim
			bsr	SetNewAnim
			bra	ForceNewAnim

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


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

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

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

.lft			bsr	GetUnderRIGHTFEET		;stop at edge
			bsr	PullContourUnder
			beq	SniBotSetIdle
			bsr	GetUnderRIGHT			;stop at wall
			bsr	TestLevelWalls	
			bmi	SniBotSetIdle
			moveq	#2,d1
			bsr	MoveGolRight_NF_Smooth
			bra	.c
.rte			bsr	GetUnderLEFTFEET		;stop at edge
			bsr	PullContourUnder
			beq	SniBotSetIdle
			bsr	GetUnderLEFT			;stop at wall
			bsr	TestLevelWalls	
			bmi	SniBotSetIdle
			moveq	#2,d1
			bsr	MoveGolLeft_NF_Smooth

.c			bsr	HandleContours

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


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


			;check if sniperbots gun is straight
SniBotGunReady		cmp.b	#4,OB_Var5(a0)
			beq	FlagYESd
			bra	FlagNOd

SBGR1			PUSHADDRS SniBotSWT3
			bra	SniBotSetResetGun
SBGR2			PUSHADDRS SniBotSWT4
			bra	SniBotSetResetGun
SBGR3			PUSHADDRS SniBotSWT1

SniBotSetResetGun	PUSHSTATE
			move.w	#SniBotResetGunSTATE,OB_State(a0)
			move.b	#4,OB_Var5a(a0)				;new gun pos
			
SniBotResetGunLOGIC	bsr	SniBotAnimateGun
			tst.l	OB_AnSequence(a0)		;gun track by going thru all angles 
			bne	.x				;to reach new pos
 			cmp.b	#4,OB_Var5(a0)
			bne.s	.x
   			POPSTATE
			POPADDRS
			jmp	(a1)
.x			rts


SniBotSetTrack		move.w	#SniBotTrackSTATE,OB_State(a0)
SniBotSWT1		clr.l	OB_AnSequence(a0)
			move.b	#4,OB_Var5(a0)				;actual gun pos
			move.b	#4,OB_Var5a(a0)				;new gun pos
			bra	SBAG1
			
SniBotTrackLOGIC	bsr	SniBotGunReady
			bpl.s	.aaa
			bsr	DoesNmeFacePlayer
			bpl	SBSTT2

.aaa			move.l	#-1,AI_Exclude
			lea	SNIPERBOT_AI3,a1
			bsr	AI_Routine
			bpl.s	.aa
			jmp	(a1)
			
.aa			tst.l	OB_AnSequence(a0)
			bne.s	.1
			jsr	Randy
			and.w	#$f,d6
			beq	SniBotSetFire

.1			bsr	SniBotAnimateGun
			
			bsr	AITestPlrIsAbove
			bmi	.above
      
.below			move.w	#$70,d1
			bsr	TestProxX
			bmi.s	.bclose

.bfar			move.w	#$10,d1
			bsr	TestProxY_Below
			bmi.s	.b90
			move.w	#$30,d1
			bsr	TestProxY_Below
			bmi.s	.b65
			move.w	#$50,d1
			bsr	TestProxY_Below
			bmi.s	.b45
			move.w	#$70,d1
			bsr	TestProxY_Below
			bmi.s	.b25
			move.w	#$90,d1
			bsr	TestProxY_Below
			bmi.s	.b0
.x			rts
.bclose			move.w	#$10,d1
			bsr	TestProxY_Below
			bmi.s	.b90
			move.w	#$20,d1
			bsr	TestProxY_Below
			bmi.s	.b65
			move.w	#$30,d1
			bsr	TestProxY_Below
			bmi.s	.b45
			move.w	#$40,d1
			bsr	TestProxY_Below
			bmi.s	.b25
			move.w	#$50,d1
			bsr	TestProxY_Below
			bmi.s	.b0
			rts
.b0			move.b	#8,OB_Var5a(a0)
			rts
.b25			move.b	#7,OB_Var5a(a0)
			rts
.b45			move.b	#6,OB_Var5a(a0)
			rts
.b65			move.b	#5,OB_Var5a(a0)
			rts
.b90			move.b	#4,OB_Var5a(a0)
			rts

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

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


SBTrackAnmTab		dc.l	SniBotTrackU4ANM,SniBotTrackU3ANM,SniBotTrackU2ANM,SniBotTrackU1ANM
			dc.l	SniBotZeroANM
			dc.l	SniBotTrackD1ANM,SniBotTrackD2ANM,SniBotTrackD3ANM,SniBotTrackD4ANM

SniBotAnimateGun	tst.l	OB_AnSequence(a0)		;gun track by going thru all angles 
			bne	.x				;to reach new pos
 			move.b	OB_Var5a(a0),d1
			cmp.b	OB_Var5(a0),d1
			beq.s	.x
   			bgt.s	.up
.dn			subq.b	#1,OB_Var5(a0)
			bra	SBAG1
.x			rts
.up			addq.b	#1,OB_Var5(a0)

SBAG1			moveq	#0,d1
			move.b	OB_Var5(a0),d1
			asl.b	#2,d1
			move.l	SBTrackAnmTab(pc,d1.w),a1
			bsr	SetNewAnim
			bra	ForceNewAnim

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

SniBotFireANMTab	dc.l	SniBotFireU2ANM,SniBotFireU2ANM,SniBotFireU1ANM,SniBotFireU1ANM	
			dc.l	SniBotFireSANM	
			dc.l	SniBotFireD1ANM,SniBotFireD1ANM,SniBotFireD2ANM,SniBotFireD2ANM	

SniBotFireDIRTab	dc.b	2,2,3,3
			dc.b	4
			dc.b	5,5,6,6
			even
SniBotFireDIRTabF	dc.b	14,14,13,13
			dc.b	12
			dc.b	11,11,10,10
			even

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

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


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


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

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

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

SBFX1			movem.l	(sp)+,d1-d2
			move.l	(sp)+,a0
			SFX 	8
			bra	FlagNOd

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

SetBigAirExplode	move.l	a0,-(sp)
			movem.l	d1-d2,-(sp)
			SPAWN_HI	BigAirExplode_MAX_Size
			bpl.s	SBFX1
			movem.l	(sp)+,d1-d2
			move.b	#1,OB_Var1(a0)
SBE2			move.w	#BigExplode_OB,OB_Type(a0)
			move.w	d1,OB_Xpos(a0)
			move.w	d2,OB_Ypos(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			move.l	(sp)+,a0
			SFX 	8
			bra	FlagYESd



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


SetSmallAirExplodeAtOB_XY
			bsr	SetSmallAirExplode
			bpl.s	.x
			bsr	SetFlipFromMother
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
.x			rts

SetSmallAirExplode	movem.l	a0/d0,-(sp)
			SPAWN_HI	SmallAirExplode_MAX_Size
			bmi.s	.1
			movem.l	(sp)+,a0/d0
			bra	FlagNOd
.1			move.l	a0,a1
			movem.l	(sp)+,a0/d0
			move.w	#SmallExplode_OB,OB_Type(a1)
			move.b	#1,OB_Var1(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bra	FlagYESd


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

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


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

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

			
SetRandomDebris		;tst	d7
			;beq	.wall_r
			;cmp	#1,d7
			;beq	.wall_l
			cmp	#2,d7
			beq	AirDebris
			cmp	#3,d7
			beq	FlrDebris
			cmp	#4,d7
			beq	WallDebris
			cmp	#5,d7
			beq	WoodDebris
			cmp	#6,d7
			beq	GlassDebris
			rts


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

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

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


SetRandomDebrisS	movem.l	d0/a0,-(sp)

			sub.w	#$20,d2
.l1			movem.l	d1-d3,-(sp)
   			SPAWN_HI	32
			bmi.s	.1
			movem.l	(sp)+,d1-d3
			movem.l	(sp)+,d0/a0
			rts

.1			move.w	#GlassDebris_OB,OB_Type(a0)
			movem.l	(sp)+,d1-d3
			move.w	d1,OB_Xpos(a0)	
			move.w	d2,OB_Ypos(a0)	
			jsr	Randy
			and.w	#$f,d6
			move.w	d6,OB_Var1(a0)
			asl.w	#4,d6
			lea	SmallParabolaLIST,a1
			move.w	0(a1,d6.w),OB_Xspd(a0)
			move.w	2(a1,d6.w),OB_Yspd(a0)
			move.w	4(a1,d6.w),OB_Xacc(a0)
			move.w	6(a1,d6.w),OB_Yacc(a0)
			move.b	8(a1,d6.w),OB_MoveFlags(a0)
			dbra	d3,.l1
			movem.l	(sp)+,d0/a0
			rts

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

MetalDebris_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
  			bset.b	#ob_setup,OB_Flag2(a0)
			move.w	OB_Xspd(a0),OB_Var2(a0)
			lea	MetalANM_TAB,a1
			move.w	OB_Var4(a0),d1
			asl.w	#2,d1
			move.l	0(a1,d1.w),a1
			bsr	SetNewAnim
			btst.b	#ob_movydir,OB_MoveFlags(a0)		;if initial dir is down
			bne.s	.1					;make y accelerate rather
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)		;than decellerate (as in a parabola)

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


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

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

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


WoodANM_TAB		dc.l	Wood1ANM,Wood2ANM,Wood3ANM,Wood1ANM,Wood2ANM,Wood3ANM

WoodDebris_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
  			bset.b	#ob_setup,OB_Flag2(a0)
			move.w	OB_Xspd(a0),OB_Var2(a0)
			lea	WoodANM_TAB,a1
			move.w	OB_Var4(a0),d1
			asl.w	#2,d1
			move.l	0(a1,d1.w),a1
			bsr	SetNewAnim
			btst.b	#ob_movydir,OB_MoveFlags(a0)		;if initial dir is down
			bne.s	.1					;make y accelerate rather
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)		;than decellerate (as in a parabola)

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


WallDebris_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.1
  			bset.b	#ob_setup,OB_Flag2(a0)
			move.w	OB_Xspd(a0),OB_Var2(a0)
			lea	WallDebrisANM,a1
			bsr	SetNewAnim
			
			and.b	#%11111001,OB_Flag1(a0)
			jsr	Randy
			and.b	#3,d6
			asl.b	#1,d6
			or.b	d6,OB_Flag1(a0)

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

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


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


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

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

WallDebris2		movem.l	d0/a0,-(sp)
.l1			movem.l	d1-d4,-(sp)
   			SPAWN_HI	WallDebris_MAX_Size
			bmi.s	.1
			movem.l	(sp)+,d1-d4
			movem.l	(sp)+,d0/a0
			rts
.1			move.w	#WallDebris_OB,OB_Type(a0)
			movem.l	(sp)+,d1-d4
			move.w	d3,OB_Var4(a0)
			move.w	d1,OB_Xpos(a0)	
			move.w	d2,OB_Ypos(a0)	
			subq.w	#$8,d2
			bset.b	#ob_tidy,OB_Flag5(a0)
			bsr	RandomParabola
			tst.w	d4
			beq.s	.1a
			move.b	#%00111110,OB_MoveFlags(a0)
			bra	.1b
.1a			move.b	#%00111111,OB_MoveFlags(a0)
.1b			dbra	d3,.l1
			movem.l	(sp)+,d0/a0
			rts

WoodDebris		movem.l	d0/a0,-(sp)
.l1			movem.l	d1-d3,-(sp)
   			SPAWN_HI	WoodDebris_MAX_Size
			bmi.s	.1
			movem.l	(sp)+,d1-d3
			movem.l	(sp)+,d0/a0
			rts
.1			move.w	#WoodDebris_OB,OB_Type(a0)
			movem.l	(sp)+,d1-d3
			move.w	d3,OB_Var4(a0)
			move.w	d1,OB_Xpos(a0)	
			move.w	d2,OB_Ypos(a0)	
			bset.b	#ob_tidy,OB_Flag5(a0)
			bsr	RandomParabolaSmall
			add.w	#$0100,OB_Xspd(a0)
			add.w	#$0300,OB_Yspd(a0)
			add.w	#$0040,OB_Yacc(a0)
			move.w	d3,d6
			and.w	#1,d6
			bne.s	.1a
			move.b	#%00111110,OB_MoveFlags(a0)
			bra	.1b
.1a			move.b	#%00111111,OB_MoveFlags(a0)
.1b			dbra	d3,.l1
			movem.l	(sp)+,d0/a0
			rts

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



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

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



; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί SETTING SUN CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SunSet_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.b	SunSetFLG
			clr.w	OB_Var1(a0)
			lea	SunSetANM,a1
			bsr	SetNewAnim
			bsr	ForceNewAnim

.ok			tst.l	OB_AnSequence(a0)
			bne.s	.1
			st.b	SunSetFLG
			bra	SwitchObjectOff

.1			addq.w	#1,OB_Var1(a0)
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί VIKINGS								   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ




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

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

whichbox		=	attackbox	;hitbox1
whichobj		=	plrobj

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

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

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

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

			endif
			

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

PiecePaper_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			lea	PiecePaperANM,a1
			bsr	SetNewAnim

.1			rts			
			

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

BreakWall_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			lea	LevelWalls,a1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			tst.b	0(a1,d1.w)
			bne	SwitchObjectOff
			btst	#0,d1
			beq.s	.2
			lea	WallOverRANM,a1
			addq.w	#8,OB_Xpos(a0)
			bra	.3
.2			lea	WallOverLANM,a1
.3			subq.w	#1,OB_Xpos(a0)
			sub.w	#$20,OB_Ypos(a0)
			bset.b	#ob_setup,OB_Flag2(a0)
			bsr	SetNewAnim
			bra	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
			moveq	#3,d3
			bsr	WallDebris
			
			SFX 	8

			bra	SwitchObjectOff
.x			rts


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

SkyLight_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bsr	IsSkylightBroken
			bne	SwitchObjectOff
			bset.b	#ob_setup,OB_Flag2(a0)
			subq.w	#8,OB_Ypos(a0)
			add.w	#$38,OB_Xpos(a0)
			clr.b	OB_Var1a(a0)
			lea	SkyLightANM,a1
			bra	SetNewAnim
			
.1			tst.b	OB_Var1a(a0)
			beq.s	.2
			tst.l	OB_AnSequence(a0)
			beq	SwitchObjectOff
.x			rts
.2			bsr	IsSkylightBroken
			beq.s	.x
			st.b	OB_Var1a(a0)
			lea	SkyLightBrokenANM,a1
			bsr	SetNewAnim
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			add.w	#$10,d2
			moveq	#6,d7
			move.w	#5,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			bra	SetRandomDebris
			
IsSkylightBroken	moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelSkylights,a1
			tst.b	0(a1,d1.w)
			rts
 			
; - LOGIC ------------------------------------------------------------------

BreakLignt_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			lea	BreakLightANM,a1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelLights,a2
			tst.b	0(a2,d1.w)
			beq.s	.a
			lea	BreakLightBrokenANM,a1
.a			bsr	SetNewAnim
			
.1			btst.b	#ob_hitting,OB_Flag1(a0)
			beq.s	.x
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelLights,a1
			st.b	0(a1,d1.w)
			lea	BreakLightBrokenANM,a1
			bsr	SetNewAnim
			bra	ForceNewAnim
.x			rts


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

BreakPipe_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			lea	BreakPipeANM,a1
			bsr	SetNewAnim

.1			rts			
			

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

ThrowCrate_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelCrates,a1
			tst.b	0(a1,d1.w)
			bne	SwitchObjectOff
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.b	OB_Var1a(a0)
			lea	ThrowCrateANM,a1
			bra	SetNewAnim
			
.1			tst.b	OB_Var1a(a0)
			beq.s	.a
			tst.l	OB_AnSequence(a0)
			beq	HandleEnemyKilled
.x			rts

.a			btst.b	#ob_beinghit,OB_Flag1(a0)
			beq.s	.x
			
			moveq	#0,d1					;crate is destroyed
			move.b	OB_Var1(a0),d1
			lea	LevelCrates,a1
			st.b	0(a1,d1.w)
			
			st.b	OB_Var1a(a0)
			lea	ThrowCrateBrokenANM,a1
			bsr	SetNewAnim
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			moveq	#5,d7
			move.w	#5,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			bra	SetRandomDebris
			

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

PigeonCoop_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			lea	PigeonCoopANM,a1
			bsr	SetNewAnim

.1			rts			
			

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

Pigeon_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			lea	PigeonANM,a1
			bsr	SetNewAnim

.1			rts			
			

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

BreakEdgeLeft_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelEdgesLeft,a1
			tst.b	0(a1,d1.w)
			bne	SwitchObjectOff
			bset.b	#ob_setup,OB_Flag2(a0)
			add.w	#$17,OB_Xpos(a0)
			sub.w	#5,OB_Ypos(a0)
			lea	BreakEdgeLeftANM,a1
			bsr	SetNewAnim
			clr.b	OB_Var1a(a0)

.1			tst.b	OB_Var1a(a0)
			beq.s	.a
			tst.l	OB_AnSequence(a0)
			beq	SwitchObjectOff
.x			rts
.a			btst.b	#ob_hitting,OB_Flag1(a0)
			beq.s	.x
			st.b	OB_Var1a(a0)
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelEdgesLeft,a1
			st.b	0(a1,d1.w)
			lea	BreakEdgeLeftBrkANM,a1
			bsr	SetNewAnim
			bra	ForceNewAnim

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

BreakEdgeRight_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelEdgesRight,a1
			tst.b	0(a1,d1.w)
			bne	SwitchObjectOff
			bset.b	#ob_setup,OB_Flag2(a0)
			lea	BreakEdgeRightANM,a1
			bsr	SetNewAnim
			clr.b	OB_Var1a(a0)

.1			tst.b	OB_Var1a(a0)
			beq.s	.a
			tst.l	OB_AnSequence(a0)
			beq	SwitchObjectOff
.x			rts
.a			btst.b	#ob_hitting,OB_Flag1(a0)
			beq.s	.x
			st.b	OB_Var1a(a0)
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelEdgesRight,a1
			st.b	0(a1,d1.w)
			lea	BreakEdgeRightBrkANM,a1
			bsr	SetNewAnim
			bra	ForceNewAnim


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

Spark_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	#$20,OB_Var1(a0)
			move.w	OB_Xspd(a0),OB_Var2(a0)
			lea	SparkANM,a1
			bsr	SetNewAnim
			bsr	ForceNewAnim

.1			subq.b	#1,OB_Var1(a0)
			beq	SwitchObjectOff

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


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

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

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

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

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


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

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

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

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


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

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

.1			subq.b	#1,OB_Var1(a0)
			beq	SwitchObjectOff

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


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί TRILO BOT CONTROL LOGIC						   Ί
; ΜΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΉ
; Ί Trilo Bot BODY							   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	TriloStartSTATE
		StDEF	TriloGroundZeroSTATE
		StDEF	TriloRunSTATE
		StDEF	TriloThruWallSTATE
		StDEF	TriloHot1STATE
		StDEF	TriloHot2STATE
		StDEF	TriloHot3STATE
		StDEF	TriloHot4STATE
		StDEF	TriloHot5STATE
		StDEF	TriloHot6STATE
		StDEF	TriloHot7STATE
		StDEF	TriloHot8STATE
		StDEF	TriloHot9STATE
		StDEF	TriloHot10STATE
		StDEF	TriloHot11STATE
		StDEF	TriloHunkerUpSTATE
		StDEF	TriloHunkerDnSTATE
		StDEF	TriloJetSTATE
		StDEF	TriloLandSTATE
		StDEF	TriloTheEndSTATE


TriloBotBody_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			move.l	#TriloBotSetHits,OB_HitRoutine(a0)
			clr.b	TriloBotDeadFLG
			bsr	SetBigAttack
			bra	TriloSetStart

.1			move.w	TriloBotXpos,OB_Xpos(a0)
			move.w	TriloBotXoff,d2
			bpl.s	.a
			neg.w	d2
			sub.w	d2,OB_Xpos(a0)
			bra	.b
.a			add.w	d2,OB_Xpos(a0)
.b			move.w	TriloBotYpos,OB_Ypos(a0)
			move.w	TriloBotYoff,d2
			bpl.s	.a1
			neg.w	d2
			sub.w	d2,OB_Ypos(a0)
			bra	.b1
.a1			add.w	d2,OB_Ypos(a0)

.b1			move.l	TriloBotXoff,TriloBotXoffS
			clr.l	TriloBotXoff

			tst.b	TriloBotDeadFLG
			bne.s	.aa1

			btst.b	#ob_hitting,OB_Flag1(a0)
			beq.s	.aa1
			bclr.b	#ob_hitting,OB_Flag1(a0)
			movem.l	a0/d0,-(sp)
			SPAWN_HI	TriloBotShield_MAX_Size
			bmi.s	.1d
			movem.l	(sp)+,a0/d0
			bra	.aa1
.1d			move.l	a0,a1
			movem.l	(sp)+,a0/d0
     			move.w	#TriloBotShield_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.l	a0,OB_Var1(a1)
			move.w	OB_Xpos(a0),d1
			cmp.w	Plr_XPos,d1
			blt.s	.r
.l			bset.b	#ob_xflp,OB_Flag1(a1)
			bra	.lr
.r			bclr.b	#ob_xflp,OB_Flag1(a1)
.lr			lea	TriloBotShieldANM,a2
			bsr	SetNewAnimA1			
	
.aa1			bsr	HandleBeingHit				;Generic handle hit rout

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


TriloBotLogicTable	bra	TriloStartLOGIC
			bra	TriloGroundZeroLOGIC
			bra	TriloRunLOGIC
			bra	TriloThruWallLOGIC
			bra	TriloHot1LOGIC
			bra	TriloHot2LOGIC
			bra	TriloHot3LOGIC
			bra	TriloHot4LOGIC
			bra	TriloHot5LOGIC
			bra	TriloHot6LOGIC
			bra	TriloHot7LOGIC
			bra	TriloHot8LOGIC
			bra	TriloHot9LOGIC
			bra	TriloHot10LOGIC
			bra	TriloHot11LOGIC
			bra	TriloHunkerUpLOGIC
			bra	TriloHunkerDnLOGIC
			bra	TriloJetLOGIC
			bra	TriloLandLOGIC
			bra	TriloTheEndLOGIC


TriloBotSetHits		rts

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

TriloSetStart		move.w	#TriloStartSTATE,OB_State(a0)
			move.w	#TriloLegsWalkSTATE,TriloLegsState		;flag legs to stop
			move.b	#$88,OB_Var1(a0)
			lea	TriloBotBodyANM,a1
			bra	SetNewAnim

TriloStartLOGIC		subq.b	#1,OB_Var1(a0)
			beq	TriloSetHunkerDn
			moveq	#1,d1
			bra	MoveTriloRight


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

TriloSetGroundZero	move.w	#TriloGroundZeroSTATE,OB_State(a0)
			bsr	ClrHitStuff
			move.b	#TriloBodyHitPOWER,OB_HitPower(a0)
			bsr	GolSetGroundMODE_CLR			;ground mode

TriloGroundZeroLOGIC	move.w	Plr_XPos,d1
			sub.w	OB_Xpos(a0),d1
			bmi.s	TBattack
			cmp.w	#25*8,d1
			bgt	TriloSetRun

TBattack		jsr	Randy
			and.w	#1,d6
			bne.s	.laser

.homer			move.w	#HomingProj1_OB,d2			;already a homer on screen?
			bsr	FindObject
			bmi.s	.laser	  				;yes: skip setting up another
			jsr	Randy
			and.w	#$1f,d6
			bne	TBjetattack
			SFX	17
			bsr	SetupOrbHead				;no: set up a homer
			bpl.s	.x
			add.w	#$20,OB_Xpos(a1)
			sub.w	#$5b,OB_Ypos(a1)
			bra	.lh
.laser			move.w	Plr_YPos,d1				;is player in line with laser turret?
			add.w	#$28,d1
			sub.w	OB_Ypos(a0),d1
			bpl.s	.1
  			neg.w	d1
.1			cmp.w	#$20,d1
			bgt.s	TBjetattack				;no: skip laser
			move.w	#HorzProj1_OB,d2			;already a laser on screen?
			bsr	FindObject
			bmi.s	TBjetattack				;yes: skip setting up another
			jsr	Randy
			and.w	#$1f,d6
			bne.s	TBjetattack
			SFX	17
			bsr	SetupLaser				;set up a laser bolt
			bpl.s	.x
			add.w	#$18,OB_Xpos(a1)
			sub.w	#$42,OB_Ypos(a1)
.lh			move.w	TriloBotYoffS,d1
			add.w	d1,OB_Ypos(a1)
			move.w	TriloBotXoffS,d1
			add.w	d1,OB_Xpos(a1)
.x			rts

TBjetattack		move.l	Plr_Database,a1
			btst.b	#grndmode,OB_MasterMode(a1)
			beq	.x
			move.w	Plr_YPos,d1
			sub.w	OB_Ypos(a0),d1
			bpl	.x
			neg.w	d1
			cmp.w	#$80,d1
			blt.s	.x
			move.w	Plr_XPos,d1
			sub.w	OB_Xpos(a0),d1
			bpl.s	.2
			neg.w	d1
.2			cmp.w	#$40,d1
			bgt.s	.x
			
			clr.b	OB_Var1(a0)
			move.w	Plr_XPos,d1
			sub.w	OB_Xpos(a0),d1
			bpl.s	.r
			st.b	OB_Var1(a0)
			neg.w	d1
.r			lsr.w	#6,d1
			tst.b	OB_Var1(a0)			;left or right
			beq.s	.a1
 			neg.b	d1				
.a1			move.b	d1,OB_Var2(a0)			;hroz velocity
			clr.w	OB_Var1(a0)			;vert velocity
			move.w	Plr_YPos,d1
			sub.w	OB_Ypos(a0),d1
			bpl.s	.a2
			neg.w	d1
.a2			lsr.w	#3,d1
			move.b	d1,OB_Var2a(a0)			;jet duration

			movem.l	a0/d0,-(sp)
			SPAWN_HI	TriloBotJet_MAX_Size
			bmi.s	.1
			movem.l	(sp)+,a0/d0
.x			rts
.1			move.l	a0,a1
			movem.l	(sp)+,a0/d0
			move.w	#TriloBotJet_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			lea	TriloBotJetANM,a2
			bsr	SetNewAnimA1			
			bsr	ForceNewAnimA1
			bra	TriloSetJet


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

TriloSetRun		move.w	#TriloLegsRunSTATE,TriloLegsState		;flag legs to stop
	      		move.w	#TriloRunSTATE,OB_State(a0)
			
TriloRunLOGIC		move.w	Plr_XPos,d1
			sub.w	OB_Xpos(a0),d1
			bmi	TriloSetHunkerDn				;ohoh plr behind triloobot
			cmp.w	#25*8,d1
			blt	TriloSetHunkerDn

			bsr	HandleContoursTrilo
			move.l	TriloUnderFEET_c,a1
			bsr	PullContourUnder
			beq.s	.o1
			subq.w	#1,d1
			and.w	#$fff0,TriloBotYpos
			or.w	d1,TriloBotYpos

.o1			moveq	#3,d1
			bsr	MoveTriloRight

.o2			bsr	GetUnderTOP
			cmp.b	#$30,d2
			beq	TriloSetThruWall
			cmp.b	#$3f,d2
			beq	TriloSetTheEnd
			cmp.b	#$31,d2
			blt.s	.x
			cmp.b	#$3e,d2
			bgt.s	.x
	
			sub.w	#$31,d2
			asl.w	#2,d2
			jmp	TBactiontab(pc,d2.w)
.x			rts
				
TBactiontab		bra	TriloSetHot1
			bra	TriloSetHot2
			bra	TriloSetHot3
			bra	TriloSetHot4
			bra	TriloSetHot5
			bra	TriloSetHot6
			bra	TriloSetHot7
			bra	TriloSetHot8
			bra	TriloSetHot9
			bra	TriloSetHot10
			bra	TriloSetHot10
			bra	TriloSetHot10
			bra	TriloSetHot10


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

TriloSetThruWall	rts

TriloThruWallLOGIC	rts


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

TriloSetTheEnd		move.w	#TriloTheEndSTATE,OB_State(a0)
	    		move.w	#TriloLegsHunkerDnSTATE,TriloLegsState
			st.b	TriloBotDeadFLG
			clr.b	OB_Var1(a0)
			clr.b	OB_Var2(a0)
			move.b	#$50,OB_Var1a(a0)
			rts

TriloTheEndLOGIC	tst.b	OB_Var2(a0)
			beq.s	.bang
			bra	.boom

.bang			addq.b	#1,OB_Var1(a0)
			and.b	#$7,OB_Var1(a0)
			bne	.x
			subq.b	#1,OB_Var1a(a0)
			bne.s	.ok
			addq.b	#1,OB_Var2(a0)
			rts
			
.ok			jsr	Randy
			and.w	#$3f,d6
			move.w	d6,d4
			jsr	Randy
			and.w	#$7f,d6
			move.w	d6,d5
		
  			jsr	Randy
			and.w	#1,d6
			beq.s	.big
	
			move.l	a0,-(sp)
			movem.l	d1-d2,-(sp)
			SPAWN_HI	SmallAirExplode_MAX_Size
			bmi.s	.1
 			movem.l	(sp)+,d1-d2
			move.l	(sp)+,a0
			clr.b	TriloBigExp
			rts
.1			movem.l	(sp)+,d1-d2
			move.w	#SmallExplode_OB,OB_Type(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			move.l	a0,a1
			move.l	(sp)+,a0
			clr.b	TriloBigExp
			bra	.xy

.big			move.l	a0,-(sp)
			movem.l	d1-d2,-(sp)
			SPAWN_HI	BigAirExplode_MAX_Size
			bmi.s	.2
			movem.l	(sp)+,d1-d2
			move.l	(sp)+,a0
			st.b	TriloBigExp
			rts
.2			movem.l	(sp)+,d1-d2
			move.w	#BigExplode_OB,OB_Type(a0)
			move.b	#1,OB_Var1(a0)
			bset.b	#ob_tidy,OB_Flag5(a0)
			move.l	a0,a1
			move.l	(sp)+,a0
			st.b	TriloBigExp
			
.xy			move.w	OB_Xpos(a0),d1
			sub.w	#$30,d1
			move.w	OB_Ypos(a0),d2
			sub.w	#$60,d2
			add.w	d4,d1
			add.w	d5,d2
			move.w	d1,OB_Xpos(a1)
			move.w	d2,OB_Ypos(a1)

			tst.b	TriloBigExp
			beq.s	.x
			moveq	#2,d7
			move.w	#2,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			bsr	SetRandomDebris
.x			rts

.boom			jmp	ResetTheGame



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

TriloSetHot1		move.w	#TriloHot1STATE,OB_State(a0)
	    		bra	TriloSetHotBit1
TriloHot1LOGIC		move.b	#2,d1				;horz vel
			move.b	#$10,d2				;jet duration
			bra	TriloSetHotBit2

TriloSetHot2		move.w	#TriloHot2STATE,OB_State(a0)
	    		bra	TriloSetHotBit1
TriloHot2LOGIC		move.b	#4,d1				;horz vel
			move.b	#$12,d2				;jet duration
			bra	TriloSetHotBit2
		
TriloSetHot3		move.w	#TriloHot3STATE,OB_State(a0)
	    		bra	TriloSetHotBit1
TriloHot3LOGIC		move.b	#3,d1				;horz vel
			move.b	#$10,d2				;jet duration
			bra	TriloSetHotBit2
		
TriloSetHot4		move.w	#TriloHot4STATE,OB_State(a0)
	    		bra	TriloSetHotBit1
TriloHot4LOGIC		move.b	#5,d1				;horz vel
			move.b	#$13,d2				;jet duration
			bra	TriloSetHotBit2
		
TriloSetHot5		move.w	#TriloHot5STATE,OB_State(a0)
	    		bra	TriloSetHotBit1
TriloHot5LOGIC		move.b	#2,d1				;horz vel
			move.b	#$1e,d2				;jet duration
			bra	TriloSetHotBit2
		
TriloSetHot6		move.w	#TriloHot6STATE,OB_State(a0)
	    		bra	TriloSetHotBit1
TriloHot6LOGIC		move.b	#2,d1				;horz vel
			move.b	#$10,d2				;jet duration
			bra	TriloSetHotBit2
		
TriloSetHot7		move.w	#TriloHot7STATE,OB_State(a0)
	    		bra	TriloSetHotBit1
TriloHot7LOGIC		move.b	#3,d1				;horz vel
			move.b	#$12,d2				;jet duration
			bra	TriloSetHotBit2
		
TriloSetHot8		move.w	#TriloHot8STATE,OB_State(a0)
	    		bra	TriloSetHotBit1
TriloHot8LOGIC		move.b	#2,d1				;horz vel
			move.b	#$1c,d2				;jet duration
			bra	TriloSetHotBit2
		
TriloSetHot9		move.w	#TriloHot9STATE,OB_State(a0)
	    		bra	TriloSetHotBit1
TriloHot9LOGIC		move.b	#2,d1				;horz vel
			move.b	#$12,d2				;jet duration
			bra	TriloSetHotBit2
		
TriloSetHot10		move.w	#TriloHot10STATE,OB_State(a0)
	    		bra	TriloSetHotBit1
TriloHot10LOGIC		move.b	#1,d1				;horz vel
			move.b	#$12,d2				;jet duration
			bra	TriloSetHotBit2

TriloSetHot11		move.w	#TriloHot11STATE,OB_State(a0)
	    		bra	TriloSetHotBit1
TriloHot11LOGIC		move.b	#1,d1				;horz vel
			move.b	#$26,d2				;jet duration
			bra	TriloSetHotBit2

TriloSetHotBit1		move.w	#TriloLegsHunkerDnSTATE,TriloLegsState
			clr.b	TriloLegsFlag1
			clr.b	TriloLegsFlag2
			clr.b	OB_Var1(a0)
	       		rts

TriloSetHotBit2		bsr	WaitLegsFlag1
			bpl.s	.1
			clr.b	TriloLegsFlag1
			clr.b	TriloLegsFlag2
			clr.w	OB_Var1(a0)			;vert velocity
			move.b	d1,OB_Var2(a0)			;horz velocity
			move.b	d2,OB_Var2a(a0)			;jet duration
			movem.l	a0/d0,-(sp)
			SPAWN_HI	TriloBotJet_MAX_Size
			bmi.s	.ok
			movem.l	(sp)+,a0/d0
			bra	TriloSetJet
.ok			move.l	a0,a1
			movem.l	(sp)+,a0/d0
			move.w	#TriloBotJet_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			lea	TriloBotJetANM,a2
			bsr	SetNewAnimA1			
			bsr	ForceNewAnimA1
			bra	TriloSetJet
.1			tst.b	TriloLegsFlag2
			beq.s	.2
			rts
.2			moveq	#1,d1
			bra	MoveTriloRight


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

TriloSetHunkerUp	move.w	#TriloHunkerUpSTATE,OB_State(a0)
			move.w	#TriloLegsHunkerUpSTATE,TriloLegsState
			clr.b	TriloLegsFlag1	

TriloHunkerUpLOGIC	bsr	WaitLegsFlag1
			bmi	TriloSetGroundZero
			rts


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

TriloSetHunkerDn	move.w	#TriloHunkerDnSTATE,OB_State(a0)
			move.w	#TriloLegsHunkerDnSTATE,TriloLegsState
			clr.b	TriloLegsFlag1
			clr.b	TriloLegsFlag2

TriloHunkerDnLOGIC	bsr	WaitLegsFlag1
			bmi	TriloSetGroundZero
			tst.b	TriloLegsFlag2
			bne.s	.x
			moveq	#1,d1
			bra	MoveTriloRight
.x			rts


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

TriloSetLand		move.w	#TriloLandSTATE,OB_State(a0)
			move.w	#TriloLegsLandSTATE,TriloLegsState
			clr.b	TriloLegsFlag1
			SFX 	8
 
TriloLandLOGIC		bsr	WaitLegsFlag1
			bmi	TriloSetGroundZero
			rts

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

TriloSetJet		move.w	#TriloLegsJetSTATE,TriloLegsState
			move.w	#TriloJetSTATE,OB_State(a0)
			st.b	TriloJetOnFlag
			
TriloJetLOGIC		moveq	#0,d1
			move.b	OB_Var2(a0),d1
			bpl.s	.a1
			neg.b	d1
			bsr	MoveTriloLeft
			bra	.a2
.a1			bsr	MoveTriloRight
			
.a2			tst.b	OB_Var2a(a0)		;jet for set duration
			beq.s	.o1
			subq.b	#1,OB_Var2a(a0)
			add.w	#$0090,OB_Var1(a0)	;add jets
			bra	.o2
.o1			clr.b	TriloJetOnFlag
.o2			sub.w	#$0040,OB_Var1(a0)	;sub gravity

			move.w	OB_Var1(a0),d1
			lsr.w	#8,d1
			btst	#7,d1
			bne.s	.down
			bra	MoveTriloUp
.down			ext.w	d1
			neg.w	d1
			bsr	MoveTriloDown
						
			bsr	ObjectOffBottom
			blt	TriloSetHot11
			
			move.l	TriloUnderFEET_c,a1			;land
			bsr	PullContourUnder
			beq.s	.x
			subq.w	#1,d1
			and.w	#$fff0,TriloBotYpos
			or.w	d1,TriloBotYpos
			bra	TriloSetLand
.x			rts			


MoveTriloRight		add.w	d1,TriloBotXpos
			rts
MoveTriloLeft		sub.w	d1,TriloBotXpos
			rts
MoveTriloUp		sub.w	d1,TriloBotYpos
			rts
MoveTriloDown		add.w	d1,TriloBotYpos
			rts

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί Trilo Bot LEGS							   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	TriloLegsZeroSTATE
		StDEF	TriloLegsWalkSTATE
		StDEF	TriloLegsRunSTATE
		StDEF	TriloLegsHunkerDnSTATE
		StDEF	TriloLegsHunkerUpSTATE
		StDEF	TriloLegsJetSTATE
		StDEF	TriloLegsWait1STATE
		StDEF	TriloLegsLandSTATE


TriloBotLegs_Logic	btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			bra	TriloSetLegsZero

.1			move.b	OB_EventVar1(a0),d1
			ext.w	d1
			move.w	d1,TriloBotXoff	
			move.b	OB_EventVar2(a0),d1
			ext.w	d1
			move.w	d1,TriloBotYoff	
			move.w	TriloBotXpos,OB_Xpos(a0)
			move.w	TriloBotYpos,OB_Ypos(a0)
;			clr.w	OB_EventVar1(a0)
			
			bsr	GetUnderFEET
			move.b	d2,TriloUnderFEET
			move.l	a1,TriloUnderFEET_c
			moveq	#0,d3
			move.w	#-$10,d4
			bsr	GetUnderGENERIC
			move.b	d2,TriloUnderSLOPEUP
			move.l	a1,TriloUnderSLOPEUP_c
			moveq	#0,d3
			move.w	#$10,d4
			bsr	GetUnderGENERIC
			move.b	d2,TriloUnderSLOPEDN
			move.l	a1,TriloUnderSLOPEDN_c

			moveq	#0,d1					;get state var as index into ...
			move.w	TriloLegsState,d1
			jmp	TriloLegsLogicTable(pc,d1.w)		;jump table

TriloLegsLogicTable	bra	TriloLegsZeroLOGIC
			bra	TriloLegsWalkLOGIC
			bra	TriloLegsRunLOGIC
			bra	TriloLegsHunkerDnLOGIC
			bra	TriloLegsHunkerUpLOGIC
			bra	TriloLegsJetLOGIC
			bra	TriloLegsWaitAnimLOGIC
			bra	TriloLegsLandLOGIC


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

TriloSetLegsZero	move.w	#TriloLegsZeroSTATE,TriloLegsState
			
TriloLegsZeroLOGIC	rts
	

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

;			SFX	1
TriloLegsWalkLOGIC	lea	TriloBotWalkANM,a1
			bsr	SetNewAnim
			bsr	ForceNewAnim
			bra	TriloSetLegsZero


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

TriloLegsRunLOGIC	lea	TriloBotRunANM,a1
			bsr	SetNewAnim
			bsr	ForceNewAnim
			bra	TriloSetLegsZero


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

TriloLegsHunkerDnLOGIC	tst.l	OB_AnSequence(a0)
			beq.s	.1
			cmp.l	#GG97702_0014,OB_AnSeqLab(a0)
			beq.s	.1
			rts
.1			st.b	TriloLegsFlag2
			move.w	#TriloLegsWait1STATE,TriloLegsState
			lea	TriloBotHunkerDnANM,a1
			bsr	SetNewAnim
			bra	ForceNewAnim


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

TriloLegsLandLOGIC	move.w	#TriloLegsWait1STATE,TriloLegsState
			lea	TriloBotHunkerDnANM,a1
			bsr	SetNewAnim
			bra	ForceNewAnim


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

TriloLegsHunkerUpLOGIC	lea	TriloBotHunkerUpANM,a1
			bsr	SetNewAnim
			bsr	ForceNewAnim
			move.w	#TriloLegsWait1STATE,TriloLegsState
			rts



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

TriloLegsWaitAnimLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.x
			st.b	TriloLegsFlag1
.x			rts


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

TriloLegsJetLOGIC	lea	TriloBotLiftOffANM,a1
			bsr	SetNewAnim
			bsr	ForceNewAnim
			bra	TriloSetLegsZero


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


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

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

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

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


; - MISC ROUTINES ---------------------------------------------------------

WaitLegsFlag1		tst.b	TriloLegsFlag1
			beq	FlagNOd
			bra	FlagYESd


HandleContoursTrilo	move.l	TriloUnderFEET_c,a1
			bsr	PullContourUnder
			beq.s	.1
			subq.w	#1,d1
			and.w	#$fff0,TriloBotYpos
			or.w	d1,TriloBotYpos
			rts
			
.1			move.l	TriloUnderSLOPEUP_c,a1
			sub.w	#8,TriloBotYpos
			bsr	GetXInBlock
			move.b	0(a1,d7.w),d1	
			ext.w	d1
			bne.s	.sh
			add.w	#8,TriloBotYpos
			move.l	TriloUnderSLOPEDN_c,a1
			add.w	#8,TriloBotYpos
			bsr	GetXInBlock
			move.b	0(a1,d7.w),d1	
			ext.w	d1
			beq.s	.x
.sh			subq.w	#1,d1
			and.w	#$fff0,TriloBotYpos
			or.w	d1,TriloBotYpos
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί Trilo Bot JET EXHAUST						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

TriloBotJet_Logic	tst.b	TriloJetOnFlag
			beq	SwitchObjectOff
			
			move.w	TriloBotXpos,d1
			sub.w	#$18,d1
			move.w	d1,OB_Xpos(a0)
			move.w	TriloBotYpos,d1
			sub.w	#$18,d1
			move.w	d1,OB_Ypos(a0)

			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί Trilo Bot SHIELD 							   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

TriloBotShield_Logic	tst.l	OB_AnSequence(a0)
			beq	SwitchObjectOff
			
			move.l	OB_Var1(a0),a1

			move.w	OB_Xpos(a1),d1
			move.w	OB_Ypos(a1),d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			sub.w	#$40,d1
			bra	.lr
.r			add.w	#$40,d1
.lr			move.w	d1,OB_Xpos(a0)
			move.w	d2,OB_Ypos(a0)
			rts


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

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

SetupOrbHead		bsr	SetupHomingProj1
			bpl	FlagNOd
			clr.b	OB_Var3a(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)			
			move.b	#HomerHitPOWER,OB_HitPower(a1)
			bsr	SetMediumAttackA1
			lea	Orb1ANM,a2
			bsr	SetNewAnimA1
			bra	FlagYESd


SetupOrbTail		bsr	SetupHomingProj1
			bpl	FlagNOd
			st.b	OB_Var3a(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)			
			lea	Orb2ANM,a2
			bsr	SetNewAnimA1
			bsr	ForceNewAnimA1
			bra	FlagYESd


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

HomingProj1_Logic	tst.b	OB_Var3a(a0)
			beq.s	.head
			tst.l	OB_AnSequence(a0)
			beq	SwitchObjectOff
			rts

.head			bsr	TestProjHitting
			bmi	ExplodeOBJECT
			
			addq.b	#1,OB_Var4(a0)
			and.b	#1,OB_Var4(a0)
			bne.s	.a1
			bsr	SetupOrbTail
			
.a1			tst.b	OB_Var3(a0)
			beq.s	.ok
   			sub.b	#1,OB_Var3(a0)
			moveq	#max_hxs,d1
			bra	MoveGolRight_Smooth

.ok			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			bra	ExplodeOBJECT


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

max_las			equ	8

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

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


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


TestProjHitting		btst.b	#ob_hitting,OB_Flag1(a0)
			bne	FlagYESd
			bsr	GetUnderFEET
			bsr	TestLevelWalls
			bmi	FlagYESd
			bsr	PullContourUnder
			bne	FlagYESd
			bra	FlagNOd

			
ExplodeOBJECT		bsr	SwitchObjectOff
			bra	SetSmallAirExplodeAtOB_XY


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


SetupDirectionalProj	bsr	SetupGenericProjectile
			bpl	FlagNOd
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)			
			bra	FlagYESd


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

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


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

.1			bra	DirProjE1


MaxXps			equ	6
MaxYps			equ	6

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


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

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

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

.1			rts



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

ICN_Strength		equ	0
ICN_Invincible		equ	1
ICN_Continue		equ	2
ICN_Health		equ	3
ICN_Life		equ	4

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


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

Icon_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)			;initial setups
			
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			asl.b	#2,d1
			move.l	IconAnmTab(pc,d1.w),a1
			bsr	SetNewAnim
			bra	ForceNewAnim
			
.1			tst.b	OB_Var4(a0)
			beq.s	.x
			bpl.s	.norm
     			
			addq.b	#1,OB_Var4a(a0)
			and.b	#3,OB_Var4a(a0)
			bne.s	.a
			subq.w	#1,OB_Var3(a0)
.a			move.w	OB_Var3(a0),d1
			bsr	MoveGolUp_Smooth
			tst	d1
			bpl.s	.x
			bsr	GetUnderFEET
			bsr	SetHeight
			bmi.s	.b
			bsr	TestLevelFloors	
			bmi.s	.b
.x			rts
.b			eor.w	#-1,OB_Var3(a0)
			subq.w	#1,OB_Var3(a0)
			tst.w	OB_Var3(a0)
			bpl.s	.x
.fin			move.b	#1,OB_Var4(a0)
			bra	ClrHitStuff

.norm			btst.b	#ob_hitting,OB_Flag1(a0)
			beq.s	.x
			clr.b	OB_Var4(a0)
			moveq	#0,d1					;give attribute
			move.b	OB_Var1(a0),d1
			asl.b	#2,d1
			jsr	IconJmpTab(pc,d1.w)
			bra	SwitchObjectOff

IconJmpTab		bra	IconSTRENGTH
			bra	IconINVINCIBLE
			bra	IconCONTINUE
			bra	IconHEALTH
			bra	IconLIFE

IconSTRENGTH		st.b	GolStrongFLG
			rts

IconINVINCIBLE		move.w	#$1ff,GolInvincibleFLG
			rts

IconCONTINUE		addq.b	#1,continues
			rts

IconHEALTH		moveq	#0,d1
			move.b	OB_Var2(a0),d1
			add.w	d1,PlrEnergy
			cmp.w	#GolMaxNRG,PlrEnergy
			ble.s	.ok
			move.w	#GolMaxNRG,PlrEnergy
.ok			rts

IconLIFE		moveq	#0,d1
			move.b	OB_Var2(a0),d1
			add.b	d1,lives
			cmp.b	#GolMaxLives,lives
			ble.s	.ok
			move.b	#GolMaxLives,lives
.ok			st.b	UpdateLivesFLG
			rts








