action TENTIDLE 17 1 1 1 1
action TENTUP 16 5 1 -1 10
action TENTDOWN 12 5 1 1 10
action TENTCHASE 0 11 1 1 10
action TENTDYING 24 4 1 1 10
action TENTDEAD 28 1 1 1 1

eventloadactor TENTACLE 
	
enda

spriteshadow TENTACLE
spritenoshade TENTACLE

gamevar burntime 0 2

state distancedamage
	setvarvar se_x sprite[PLAYERID].x
	subvarvar se_x sprite[THISACTOR].x
	setvarvar se_y sprite[PLAYERID].y
	subvarvar se_y sprite[THISACTOR].y
	setvarvar se_z sprite[PLAYERID].z
	subvarvar se_z sprite[THISACTOR].z
	
	mulvarvar se_x se_x
	mulvarvar se_y se_y
	shiftvarr se_z 4
	mulvarvar se_z se_z
	addvarvar se_x se_y
	addvarvar se_x se_z
	sqrt se_x targetdist

	shiftvarl DIST 4
	ifvarvarl targetdist DIST {
		setvarvar damagez DIST
		subvarvar damagez targetdist
		mulvarvar damagez 15 //damageHit
		divvarvar damagez DIST

		setactor[PLAYERID].htextra damagez
		setactor[PLAYERID].htowner THISACTOR
			
		setvarvar paextra damagez
		ifvare sprite[THISACTOR].pal 2
			state checkf_armor
		else
			state checkb_armor
		
		ifvarg burntime 0 {
			getactorvar[PLAYERID].flamedamage tmp 
			addvarvar tmp burntime 
			setactorvar[PLAYERID].flamedamage tmp 
		}
	}
ends

useractor notenemy TENTACLE
sizeat 32 32

ifaction NO {
	ifvare sprite[THISACTOR].pal 0
		setactor[THISACTOR].extra 20
	else ifvare sprite[THISACTOR].pal 2
		setactor[THISACTOR].extra 40
	action TENTIDLE
}



ifvare VISION 1 { setactor[THISACTOR].shade -127 } 
getplayer[THISACTOR].i PLAYERID

setvar width 64

ifvarg flamedamage 0 { subvar flamedamage 1 state newfirestate } 
ifinwater setvar flamedamage 0

getzrange sprite[THISACTOR].x sprite[THISACTOR].y sprite[THISACTOR].z sprite[THISACTOR].sectnum ceilz ceilhit floorz floorhit 64 CLIPMASK0

ifvarg sprite[THISACTOR].extra 0
ifp phigher {
	setvarvar tmp ceilhit
	andvar tmp 0xE000
	ifvare tmp 0xC000 {
		setvarvar spriteid ceilhit
		andvar spriteid 0x1FFF
		ifvarvare spriteid PLAYERID {
		
			setactor[THISACTOR].htextra 1
		}
	}
}

getactorvar[PLAYERID].invisible invisible
ifvarn invisible 1 
{
	ifaction TENTIDLE {
		cstat 0
		ifpdistl 5120 {
			ifcanseetarget { 
				action TENTUP
			}
		}
	}
	
	ifaction TENTUP {
		soundonce TENTUP3
		ifactioncount 5 { cstat 257 action TENTCHASE }
	}
	
	ifaction TENTCHASE {
		ifcanseetarget ifpdistl 5120 {
			addvar COUNTER 1
			ifvarg COUNTER 120 setvar COUNTER 0
			
			soundonce TENTSWP4
			ifvare sprite[THISACTOR].pal 0 {
				setvar DIST 50
				setvar burntime 0
			}
			else ifvare sprite[THISACTOR].pal 2 {
				setvar DIST 75
				setvar burntime 7
			}

			ifvare COUNTER 15 
				state distancedamage
			ifvare COUNTER 20 
				state distancedamage
			
		} else ifcount 400 { action TENTDOWN soundonce TENTDWN3 resetcount }
	}
	
	ifaction TENTDOWN ifactioncount 5 action TENTIDLE

	ifvarg sprite[THISACTOR].extra 0
	ifvarg sprite[THISACTOR].htextra 0 {
		getactor[THISACTOR].extra extra
		subvarvar extra sprite[THISACTOR].htextra
		setactor[THISACTOR].extra extra
		
		ifvarl sprite[THISACTOR].extra 1 {
			soundonce TENTEXP
			action TENTDYING
		}
		setactor[THISACTOR].htextra -1
	}
	
	ifvare burningguyactive 1 ifvare sprite[THISACTOR].pal 0 { 
		killit
	}

	ifaction TENTDYING ifactioncount 4 { action TENTDEAD cstat 0 }
}
enda