;*************************************************************
;***                                                       ***
;***                 EGURIN'S  PATHDATA                    ***
;***                                                       ***
;*************************************************************

	incpublics	pathdata.ext



;--------------- Ground turret, aim and fire at a player -----

	START_PATH	houdai1

	P_SPAWN		0,0,0,0,0,0,hou_0_1,houdai_head,10,10,1
	P_SET		hp,12
	P_SET		ap,2
	P_END

	START_PATH	houdai_head
	P_SET		hp,12
	P_SET		ap,2

	P_WEAPON	laser2

.loop
	P_IFNOTSAME	pbyte1,0,.dontcheck
	P_PLAYER	1
	P_GOSUB		.checkfire
	P_PLAYER	2
	P_GOSUB		.checkfire
	P_IGOTO		.dontadd
.dontcheck
	P_ADD		pbyte1,-1
.dontadd
	P_ADD	childroty,deg5

	P_GOTO		.loop
.checkfire
	P_DISTMORE	2000,.dontfire
	P_PLAYERINCONE	deg5,.fire
.dontfire
	P_RETURN
.fire
	P_ADD		worldy,-50
	P_FIRE
	P_ADD		worldy,50
	P_SET		pbyte1,10
	P_RETURN


randomplayer
	P_RANDOMGOTO	.setp2
	P_PLAYER	1
	P_RETURN
.setp2	P_PLAYER	2
	P_RETURN



;--------------- Fake player.. attacks either of the players -----

	START_PATH	fakeplayer

	P_SET		hp,20
	P_SET		ap,1
	P_GOSUB		randomplayer
	P_WEAPON	laser2

.loopuntilnear
	P_WAIT		1
	P_DISTMORE	1000,.loopuntilnear

	P_SETVEL	0
	P_LOCKPLAYER	ON

	P_DO		8
	  P_DO		20
	    P_CHASE		childy,0
	    P_FACEPLAYER

rotaccel	=	$20
rotaccel_limit =	$100

	    P_LEFTOFPLAYER	.dontdo
	    P_ADD		pword1,-rotaccel
.dontdo
	    P_RIGHTOFPLAYER	.dontdo2
	    P_ADD		pword1,rotaccel
.dontdo2

	    P_IFBETWEEN		-rotaccel_limit,pword1,rotaccel_limit,.noclamp

	    P_IFBETWEEN		0,pword1,$1000,.posclamp
.negclamp
	    P_SET		pword1,-rotaccel_limit
	    P_IGOTO		.noclamp
.posclamp
	    P_SET		pword1,rotaccel_limit
.noclamp
	    P_CIRCLE		pword1

	    P_DISTMORE		800,.nomore
	    P_MOVEIN		-30
.nomore

	  P_NEXT
	  P_FIRE
	P_INEXT

	P_LOCKPLAYER	OFF
	P_SETVEL	30

	P_DO		100
	P_ADD		rotz,deg22
	P_NEXT

	P_WAITCHASE	rotz,deg0
	P_GOTO		.loopuntilnear

	P_ALWAYSGENVECS	ON
	P_WEAPON	laser1
	P_TRIGGER	.hit,WHENHIT

.loop
	P_ACCEL		20,10

	P_DO		10
	P_FACEPLAYER
	P_NEXT

	P_ACCEL		70,20
	P_ADD		roty,-5

	P_DO		30
	P_NEXT

	P_DO		20
	P_ADD		roty,1
	P_NEXT

	P_GOTO		.loop

	IFEQ	1

	P_SET		hp,20
	P_SET		ap,2
	P_PLAYER	1
	P_ALWAYSGENVECS	ON
	P_WEAPON	laser1
	P_TRIGGER	.hit,WHENHIT

.loop
	P_TRIGGER	.home,ALWAYS
	P_ACCEL		20,2
	P_DO		50
	P_NEXT

	P_FIRE

	P_TRIGGER	.home,OFF

	P_ACCEL		60,10
	P_DO		30
	P_NEXT


	P_FIRE

	P_GOTO		.loop

	ENDC

.hit
	P_ACCEL		5,10	; if hit, slow almost to a stop
	P_RETURN
.home
	P_FACEPLAYER
	P_RETURN


;-------------------------------------------------------------------
; KAME_0 land octopus boss.

	START_PATH	kame0

	P_SPAWN		(0<<kame0_scale),(0<<kame0_scale),(-40<<kame0_scale),0,0,0,kame_0_3,kame0leg,10,10,1
	  P_BECOME
	  P_SET		pbyte1,-deg90-deg45
	  P_SET		pbyte2,2	; how many pieces
	  P_UNBECOME
	P_SPAWN		(30<<kame0_scale),(0<<kame0_scale),(20<<kame0_scale),0,deg120,0,kame_0_3,kame0leg,10,10,2
	  P_BECOME
	  P_SET		pbyte1,-deg90-deg45
	  P_SET		pbyte2,2	; how many pieces
	  P_UNBECOME
	P_SPAWN		(-30<<kame0_scale),(0<<kame0_scale),(20<<kame0_scale),0,-deg120,0,kame_0_3,kame0leg,10,10,3
	  P_BECOME
	  P_SET		pbyte1,-deg90-deg45
	  P_SET		pbyte2,2	; how many pieces
	  P_UNBECOME
	P_INVINCIBLE	ON
	P_SET		ap,4

;	P_TRIGGER	setview_sub,ALWAYS

	P_SETANIM	0

.loop

	P_CHASE		worldy,-200
	P_ADD		roty,-2
	P_GOTO		.loop

	P_END


;--------------------------------------------------------------
	START_PATH	kame0leg
	P_INVINCIBLE	ON

	P_SETANIM	0
	P_TRIGGER	.leggrow,4

.loop
	P_CHASE		childrotx,pbyte1

	P_SETRANDOM	sbyte2,255
	P_IFSAME	sbyte2,0,.raiseleg
	P_GOTO		.loop
.raiseleg
	P_ADD		childrotx,2
	P_IFBETWEEN	-deg45,childrotx,0,.loop
	P_GOTO		.raiseleg


.leggrow	P_IFSAME	animframe,128+8,.dontgrow
	P_ADDANIM	1,10
	P_IFNOTSAME	animframe,128+8,.dontgrow
	P_DEC		pbyte2
	P_IFSAME	pbyte2,0,.dontgrow
	P_IFSAME	pbyte2,1,.growhead
	P_SPAWN		0,-70,0,0,0,0,kame_0_3,kame0leg,10,10,1
	P_GOSUB		.setcreator
.dontgrow	P_RETURN
.growhead
	P_SPAWN		0,-80,0,0,0,0,kame_0_4,kame0foot,10,10,1
	P_GOSUB		.setcreator
	P_RETURN

.setcreator
	P_START65816
	stx	gword1
	P_END65816
	P_EXPORT	gbyte1,pbyte2
	P_BECOME
	  P_IMPORT	childrotobj,gword1
	  P_SET		pbyte1,-deg5
	  P_IMPORT	pbyte2,gbyte1
	P_UNBECOME
	P_RETURN

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

	START_PATH	kame0foot

	P_INVINCIBLE	ON
	P_SETANIM	0
	P_ADD		childrotx,deg90

.animit1
	P_ADDANIM	1,20
	P_IFSAME	animframe,128+5,.nxtbitchk
	P_GOTO		.animit1
.nxtbitchk
	P_SETRANDOM	pbyte1,15
	P_IFNOTSAME	pbyte1,0,.nxtbit
	P_WAIT		1
.openfully
	P_ADDANIM	1,20
	P_IFSAME	animframe,128+16,.nxtbit
	P_GOTO		.openfully
.nxtbit
	P_ADDANIM	-1,20
	P_IFSAME	animframe,128+0,.animit1
	P_GOTO		.nxtbit
	P_END
	

;---------------------------------------------------------------
setview_sub
	P_START65816
	ldy	#viewblk1
	s_copy_pos	y,x
	s_set_alvar	W,y,al_rotx,#0
	s_set_alvar	W,y,al_roty,#0
	s_set_alvar	W,y,al_rotz,#0
	s_set_alvar	W,y,al_sword1,#500
	s_set_alvar	W,y,al_sword2,#0
	s_set_alvar	B,y,al_sbyte4,#0
	P_END65816
	P_RETURN
;-------------------------------------------------------------------
; tables:
backforth_tab
	db	0,0,1,1,1,2,2,3,4,6,9,6,4,3,2,2,1,1,1,0
	db	0,0,-1,-1,-1,-2,-2,-4,-5,-7,-10,-7,-5,-4,-2,-2,-1,-1,-1,0

