include BloodTC/blcons/enemy_param.con

// Monsters codes

state facingstate
  	getactor[THISACTOR].x mx
	getactor[THISACTOR].y my
	getactor[PLAYERID].x x
	getactor[PLAYERID].y y
	getplayer[THISACTOR].kickback_pic perplayer
	ifvare perplayer 0
	{
		ifvarg akimboshotgunalt 0 { setvarvar perplayer akimboshotgunalt }
		ifvarg tommysweep 0 { setvarvar perplayer tommysweep } 
		ifvarg akimbotommysweep 0 { setvarvar perplayer akimbotommysweep } 
		ifvarg voodooalt 0 { setvarvar perplayer voodooalt }
		ifvarg tntalt 0 { setvarvar perplayer tntalt }
		ifvarg sprayalt 0 { setvarvar perplayer sprayalt }
		ifvarg akimboteslaalt 0 { setvarvar perplayer akimboteslaalt }
		ifvarg teslaalt 0 { setvarvar perplayer teslaalt }
		ifvarg voodoocount1 0 { setvarvar perplayer voodoocount1 }
		ifvarg voodoocount2 0 { setvarvar perplayer voodoocount2 }
		ifvarg voodoocount3 0 { setvarvar perplayer voodoocount3 }
		ifvarg voodoocount4 0 { setvarvar perplayer voodoocount4 }
		ifvarg voodoocount5 0 { setvarvar perplayer voodoocount5 }
		
	}
	subvarvar mx x
	subvarvar my y
	getangle mang mx my
	getactor[THISACTOR].ang ang
	getincangle mang mang ang
	ifvarg mang -384 ifvarl mang 384
	{
		ifpdistl 8192 ifvarg perplayer 0 { setvar set 1 } else 
		ifpdistl 1536 setvar set 1 else { setvar set 0 }
	} else setvar set 1
ends

state enemyeffects
ifvare VISION 1
{ setactor[THISACTOR].shade -127 }

	getactorvar[THISACTOR].flamedamage peractor
	ifvarg peractor 0 { addvar COUNTER 1 state newfirestate } 
	ifinwater { setvar COUNTER 0 }
	ifvarvare COUNTER peractor { setactorvar[THISACTOR].flamedamage 0 setvar COUNTER 0 }
	
/*
	// Thanks to KLIMaka for this code
	
getactor[THISACTOR].htextra htextra
getactor[THISACTOR].htang htang
cos x htang
sin y htang
ifvarn htextra -1 { setvarvar k_damage htextra addvar peractor2 4 } // damage				     
iffloordistl 10	// deaccelerate on ground

subvarvar k_damage peractor2

ifvarl k_damage 0 { setvar k_damage 0 setactor[THISACTOR].htextra -1 setvar peractor2 0 }     // clamping multiplier

mulvarvar x k_damage                // roll force = damage - deacceleration
mulvarvar y k_damage
shiftvarr x 10
shiftvarr y 10
setvar z 0
movesprite THISACTOR x y z CLIPMASK0 RETURN
*/
ends

state ifnotmovingstate
ifnotmoving { getactor[THISACTOR].ang ang randvar mang 1024 addvarvar ang mang setactor[THISACTOR].ang ang }
ends

//------------------------------FAT RAT CODE

action AFATRATWALK  0  4  5  1  6
action AFATRATWSTAYPUT  0  1  5  1 
action AFATRATBITE 5 2 5 1 7
action AFATRATDYING 20 5 1 1 14
action AFATRATDEAD 25 1 1 1 10
action AFATRATBURNING -9 4 1 1 15
action AFATRATBURN -4 4 1 1 40
action AFATRATBURNED -1 1 1 1 10

move FATRATWALK 120
move FATRATSTOP 

ai AIFATRATWALK AFATRATWALK FATRATWALK faceplayer
ai AIFATRATRANDOM AFATRATWALK FATRATWALK randomangle
ai AIFATRATWSTAYPUT AFATRATWSTAYPUT FATRATSTOP
ai AIFATRATSEEK AFATRATWALK FATRATWALK seekplayer
ai AIFATRATBITE AFATRATBITE FATRATSTOP faceplayer
ai AIFATRATBURNING AFATRATBURNING FATRATSTOP
ai AIFATRATBURNED AFATRATBURNED FATRATSTOP
ai AIFATRATBURN AFATRATBURN FATRATSTOP
ai AIFATRATDYING AFATRATDYING FATRATSTOP
ai AIFATRATDEAD AFATRATDEAD FATRATSTOP

eventloadactor FATRAT 
setactor[THISACTOR].cstat 0
getactor[THISACTOR].z z
subvar z 256
setactor[THISACTOR].z z
setactor[THISACTOR].xrepeat 20
setactor[THISACTOR].yrepeat 20
enda

state fatrathurt
ifwasweapon RPG { addkills 1 state squishcode killit } else 
ifwasweapon RADIUSEXPLOSION { addkills 1 state squishcode killit } else 
ifdead { addkills 1 guts JIBS6 10 ifrnd 96 { soundonce RATDIE1 } else ifrnd 96 { soundonce RATDIE2 } else { soundonce RATDIE3 } ai AIFATRATDYING } else { soundonce RATPAIN guts JIBS6 3 ai AIFATRATSEEK }
ends

spritenoshade FATRAT
spriteshadow FATRAT
useractor notenemy FATRAT fall 
ifvare VISION 1 { setactor[THISACTOR].shade -127 } else
{
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade enemyshade
	setactor[THISACTOR].shade enemyshade
}
getplayer[THISACTOR].i PLAYERID
getactor[PLAYERID].extra HEALTHAMOUNT
getactor[THISACTOR].extra extra
ifp phigher ifpdistl 600 { addkills 1 guts JIBS6 10 ifrnd 96 { soundonce RATDIE1 } else ifrnd 96 { soundonce RATDIE2 } else { soundonce RATDIE3 } ai AIFATRATDYING }  
ifhitweapon { state fatrathurt }

ifai NO { addvar TOTALKILLS 1 strength FATRATSTREGTH sizeat 20 20 cstat 257 ai AIFATRATWSTAYPUT }

getactorvar[PLAYERID].invisible invisible
ifp pdead setvar invisible 1
ifvarn invisible 1 
{	
	ifai AIFATRATWSTAYPUT ifp palive ifcansee { state facingstate ifvare set 1 { soundonce RATSPOT ai AIFATRATSEEK } }
	ifai AIFATRATWALK 
	{
		ifp palive
		{ 
			ifrnd 1 ifcansee soundonce RATSPOT 
			state ifnotmovingstate
			ifp phigher { ai AIFATRATSEEK } else { ifpdistl 850 ai AIFATRATBITE }
		} else ai AIFATRATRANDOM
	}
	ifai AIFATRATBITE 
	{ 
		addvar peractor2 1
		ifvarg peractor2 26 { ai AIFATRATWALK setvar peractor2 0 }
				
		getactorvar[PLAYERID].reflective reflective
		ifpdistl 850 ifcansee ifvare peractor2 1
		{
			ifvare reflective 1
			{ 
				subvarvar extra FATRATHIT
				setactor[THISACTOR].extra extra
				ifvarg extra 0 { soundonce RATPAIN } else { addkills 1 guts JIBS6 10 ifrnd 96 { soundonce RATDIE1 } else ifrnd 96 { soundonce RATDIE2 } else { soundonce RATDIE3 } ai AIFATRATDYING }
			} 
			else
			{ 
				soundonce PFLESH 
				setactor[PLAYERID].htextra FATRATHIT
				getactor[PLAYERID].htextra paextra
				state checkb_armor
				palfrom 32 1 1 1 
			}
		}
	} 
	ifai AIFATRATSEEK { ifrnd 1 ifcansee soundonce RATSPOT state ifnotmovingstate ifcansee { ifp phigher nullop else ai AIFATRATWALK } }
	ifai AIFATRATRANDOM ifp palive ifcansee { soundonce RATSPOT ai AIFATRATSEEK }
}
else
{ 
	ifai AIFATRATWALK { ai AIFATRATRANDOM }
	ifai AIFATRATSEEK { ai AIFATRATRANDOM }
	ifai AIFATRATBITE { ai AIFATRATRANDOM }
}
getactorvar[THISACTOR].voodoohitenemy voodoohitenemy
ifvare voodoohitenemy 1 
{ 
	setactor[THISACTOR].extra 0
	state fatrathurt
	setactorvar[THISACTOR].voodoohitenemy 0
}

ifai AIFATRATRANDOM { state ifnotmovingstate ifrnd 4 { randvar ang 2048 setactor[THISACTOR].ang ang } ifcount 390 { ai AIFATRATWSTAYPUT resetcount break } }
getactorvar[THISACTOR].flamedamage flamedamage
ifvarg flamedamage 0 ifvare peractor 0 { ai AIFATRATBURNING addkills 1 setvar peractor 1 }
ifai AIFATRATBURNING { strength 0 setactor[THISACTOR].shade -127 cstat 0 sizeat 20 20 ifactioncount 12 { ifrnd 128 cstat 4 else cstat 0 ai AIFATRATBURN } }
ifai AIFATRATBURN { ifactioncount 4 { ai AIFATRATBURNED } }
ifai AIFATRATDYING { cstat 128 sizeat 20 20 cstat 128 ifactioncount 5 { cstat 0 ai AIFATRATDEAD } } 
enda

//------------------------------CHOKING HAND CODE

action AHANDWALK  0  4  5  1  10
action AHANDSTOP  0  1  5  1  1
action AHANDATTACK 29 2 1 1 5
action AHANDDYING 34 5 1 1 10
action AHANDDEAD 39 1 1 1 10
action AHANDBURNING -287 6 1 1 15
action AHANDBURNED -280 1 1 1 1

move HANDWALK 150
move HANDSTOP 

ai AIHANDWALK AHANDWALK HANDWALK faceplayer
ai AIHANDSEEK AHANDWALK HANDWALK seekplayer
ai AIHANDSTOP AHANDSTOP HANDSTOP
ai AIHANDATTACK AHANDATTACK HANDSTOP 
ai AIHANDDYING AHANDDYING HANDSTOP
ai AIHANDDEAD AHANDDEAD HANDSTOP
ai AIHANDBURNING AHANDBURNING HANDSTOP
ai AIHANDBURNED AHANDBURNED HANDSTOP

state handhurt
ifdead { guts JIBS6 10 soundonce HEADSQ addkills 1 ai AIHANDDYING } else { soundonce HANDPAIN guts JIBS6 3 }
ends

eventloadactor EVILHAND 
setactor[THISACTOR].xrepeat 30
setactor[THISACTOR].yrepeat 30
enda

spritenoshade EVILHAND
spriteshadow EVILHAND
useractor notenemy EVILHAND fall
getplayer[THISACTOR].i PLAYERID
getactor[THISACTOR].extra extra
getactor[PLAYERID].x mx
getactor[PLAYERID].y my
getactor[PLAYERID].z mz
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z
ifvare VISION 1 { setactor[THISACTOR].shade -127 } else
{
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade enemyshade
	setactor[THISACTOR].shade enemyshade
}
ifhitweapon { state handhurt }

getactorvar[PLAYERID].invisible invisible
ifvare invisible 1 { setactorvar[THISACTOR].handshock 1 ifvare peractor2 0 ifvarg extra 0 { ai AIHANDSEEK setvar peractor2 1 } } else { ifvare peractor2 1 { setactorvar[THISACTOR].handshock 0 setvar peractor2 0 } }

getactorvar[THISACTOR].handshock active
ifai NO { addvar TOTALKILLS 1 strength EVILHANDSTRANGTH sizeat 30 30 cstator 257 ai AIHANDSTOP }
ifvare active 0
{
	ifai AIHANDSEEK { ifcansee { ifp palive ai AIHANDWALK else ifcount 130 ai AIHANDSTOP } else ai AIHANDSTOP }
	ifai AIHANDWALK 
	{ 
		ifp pdead ai AIHANDSEEK 
		else 
		{
			ifcansee { ifrnd 1 ifcansee soundonce HANDROAM else ifrnd 1 ifcansee soundonce HANDSPOT }
			getactorvar[PLAYERID].handattack tmp3
			subvarvar mx x
			subvarvar my y
			getangle mang mx my
			getactor[THISACTOR].ang ang
			getincangle mang mang ang
			ifvarg mang -256 ifvarl mang 256
			ifvarn tmp3 1
			{ ifpdistl 850 ai AIHANDATTACK }
		}
	}
	ifai AIHANDATTACK 
	{ 
		setactorvar[PLAYERID].handattack 1
		killit
	}
} 
else
{
	ifai AIHANDSEEK { ifcansee { ifrnd 1 soundonce HANDROAM } ifnotmoving { getactor[THISACTOR].ang ang randvar mang 1024 addvarvar ang mang setactor[THISACTOR].ang ang } randvar peractor 64 ifvare invisible 0 { ifvare peractor 64 { setactorvar[THISACTOR].handshock 0 } } else ifcount 130 { ai AIHANDSTOP setvar peractor 0 } }
}
getactorvar[THISACTOR].voodoohitenemy voodoohitenemy
ifvare voodoohitenemy 1 
{ 
	setactor[THISACTOR].extra 0
	state handhurt
	setactorvar[THISACTOR].voodoohitenemy 0
}
ifp phigher ifpdistl 600 ifvarg extra 0 { ai AIHANDDYING }
ifai AIHANDSTOP ifcansee ifp palive ifvare invisible 0 { state facingstate ifvare set 1 ai AIHANDSEEK }
getactorvar[THISACTOR].flamedamage flamedamage
ifvarg flamedamage 0 ifvare peractor3 0 { ai AIHANDBURNING setvar peractor3 1 }
ifai AIHANDBURNING { strength 0 setactor[THISACTOR].shade -127 addkills 1 cstat 128 ifrnd 128 soundonce HANDDIE1 else soundonce HANDDIE2 sizeat 40 40 ifactioncount 6 { ai AIHANDBURNED } }
ifai AIHANDDYING { strength 0 cstat 128 ifrnd 128 soundonce HANDDIE1 else soundonce HANDDIE2 sizeat 40 40 ifactioncount 5 { ai AIHANDDEAD } }
enda

//------------------------------ZOMBIE CODE

action AZR1 1 0 1 1 0
action AZR2 -8 10 1 1 14
action AZRDYING -1849 4 1 1 15
action AZRDEAD -1845 0 1 1 0

move AZRSTOP 0

ai AIZR1 AZR1 AZRSTOP faceplayer
ai AIZR2 AZR2 AZRSTOP faceplayer
ai AIZRDYING AZRDYING AZRSTOP faceplayer
ai AIZRDEAD AZRDEAD AZRSTOP

eventloadactor ZOMBIERISE 
setactor[THISACTOR].xrepeat 24
setactor[THISACTOR].yrepeat 24
enda

useractor notenemy ZOMBIERISE 0 AZR1 fall

getplayer[THISACTOR].i PLAYERID
ifai NO { addvar TOTALKILLS 1 cstat 384 sizeat 24 24 ai AIZR1 }
getactorvar[PLAYERID].invisible perplayer
ifai AIZR1 ifcansee ifvare perplayer 0 ifpdistl 4096 { sizeat 24 24 cstator 257 ai AIZR2 }
getactorvar[THISACTOR].flamedamage tmp
ifvarg tmp 0 ifvare peractor 0 { sizeat 24 24 cstat 0 ai AIZRDYING ifrnd 85 soundonce AZOMDIE1 else ifrnd 85 soundonce AZOMDIE2 else ifrnd 85 soundonce AZOMDIE3 state bloodspraystate addkills 1 setvar peractor 1 } 
ifai AIZRDYING ifactioncount 4 { ai AIZRDEAD }
ifai AIZR2 ifactioncount 8 { espawn ZOMBIE setactorvar[RETURN].settotalkill 1 killit }

getactor[THISACTOR].htextra htextra
getactor[THISACTOR].htang htang
cos x htang
sin y htang
ifvarn htextra -1 { setvarvar k_damage htextra addvar peractor2 4 } // damage				     
iffloordistl 10	// deaccelerate on ground

subvarvar k_damage peractor2
ifvarl k_damage 0 { setvar k_damage 0 setactor[THISACTOR].htextra -1 setvar peractor2 0 }     // clamping multiplier

mulvarvar x k_damage                // roll force = damage - deacceleration
mulvarvar y k_damage
shiftvarr x 10
shiftvarr y 10
setvar z 0
movesprite THISACTOR x y z CLIPMASK0 RETURN

enda

action AZOMBIEWALK  0 4 5 1 16
action AZOMBIESTAYPUT  0 1 5 1 1
action AZOMBIESHOOT 54 7 5 1 12
action AZOMBIEGOTHIT 30 1 5 1 10
action AZOMBIEJIB 46 6 1 1 20
action AZOMBIEGUTS 158 6 1 1 20
action AZOMBIEFALLING 35 4 1 1 12
action AZOMBIEGETUP 40 2 1 1 12
action AZOMBIEVOODOO1 2484 7 1 1 12
action AZOMBIEVOODOO2 2492 1 1 1 1
action AZOMBIETESLA 2493 1 5 1 1
action AZOMBIEDEAD 53 1 1 1 1
action AZOMBIEDEAD2 39 1 1 1 1
action AZOMBIEGUTS2 165 1 1 1 1


move ZOMBIEWALK 80
move ZOMBIESTOP

ai AIZOMBIEWALK AZOMBIEWALK ZOMBIEWALK faceplayer
ai AIZOMBIESTAYPUT AZOMBIESTAYPUT ZOMBIESTOP
ai AIZOMBIEVOODOO1 AZOMBIEVOODOO1 ZOMBIESTOP faceplayer
ai AIZOMBIEVOODOO2 AZOMBIEVOODOO2 ZOMBIESTOP faceplayer
ai AIZOMBIETESLA AZOMBIETESLA ZOMBIESTOP faceplayer
ai AIZOMBIESHOOT AZOMBIESHOOT ZOMBIESTOP faceplayer 
ai AIZOMBIERANDOM AZOMBIEWALK ZOMBIEWALK randomangle
ai AIZOMBIEGOTHIT AZOMBIEGOTHIT ZOMBIESTOP faceplayer
ai AIZOMBIEDYING AZOMBIEJIB ZOMBIESTOP faceplayer
ai AIZOMBIEFALLING AZOMBIEFALLING ZOMBIESTOP faceplayer
ai AIZOMBIEGETUP AZOMBIEGETUP ZOMBIESTOP faceplayer
ai AIZOMBIEGUTS AZOMBIEGUTS ZOMBIESTOP faceplayer
ai AIZOMBIEDEAD AZOMBIEDEAD ZOMBIESTOP faceplayer
ai AIZOMBIEDEAD2 AZOMBIEDEAD2 ZOMBIESTOP faceplayer 
ai AIZOMBIEGUTS2 AZOMBIEGUTS2 ZOMBIESTOP faceplayer

state checkzombiehitstate
getactor[THISACTOR].extra extra
ifwasweapon PR_NAPALM { addkills 1 ifrnd 85 soundonce AZOMDIE1 else ifrnd 85 soundonce AZOMDIE2 else ifrnd 85 soundonce AZOMDIE3 ai AIZOMBIEGUTS } 
else ifwasweapon RADIUSEXPLOSION { addkills 1 ai AIZOMBIEGUTS }
else { ifvarg extra 0 { state bloodspraystate soundonce AZOMPAIN ifrnd 6 ai AIZOMBIEGOTHIT else ifvarg htextra 12 ai AIZOMBIEFALLING else ai AIZOMBIEGOTHIT }
else { setactorvar[THISACTOR].w_enemyhitag 0 addkills 1 state bloodsprayshit ifrnd 85 soundonce AZOMDIE1 else ifrnd 85 soundonce AZOMDIE2 else soundonce AZOMDIE3 ifrnd 64 { state bloodspraystate ai AIZOMBIEDYING setprojectile[ZOMBIEHEAD].vel 60 ezshoot 256 ZOMBIEHEAD getactor[RETURN].z z addvar z -3800 setactor[RETURN].z z } else ai AIZOMBIEFALLING } }
ends

eventloadactor ZOMBIE
getactor[THISACTOR].hitag HITAGSET
setactorvar[THISACTOR].w_enemyhitag HITAGSET
setactor[THISACTOR].xrepeat 24
setactor[THISACTOR].yrepeat 24
enda

spriteshadow ZOMBIE
spritenoshade ZOMBIE
useractor notenemy ZOMBIE fall 
setactor[THISACTOR].clipdist 80
getactor[THISACTOR].extra extra
getactor[THISACTOR].htextra htextra
getplayer[THISACTOR].i PLAYERID
randvar enemyroam 512

ifvare VISION 1 { setactor[THISACTOR].shade -127 } else
{
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade enemyshade
	setactor[THISACTOR].shade enemyshade
}
getactorvar[THISACTOR].settotalkill settotalkill
ifai NO { ifvarn settotalkill 1 { addvar TOTALKILLS 1 } strength ZOMBIESTRENGTH sizeat 24 24 cstat 257 ai AIZOMBIESTAYPUT }
  
getactorvar[PLAYERID].invisible invisible
ifp pdead setvar invisible 1
ifvarn invisible 1
{
	ifhitweapon { state checkzombiehitstate }
	ifai AIZOMBIEWALK { ifcansee ifp palive { ifpdistl 1300 ai AIZOMBIESHOOT } else ai AIZOMBIERANDOM state ifnotmovingstate ifcansee { ifvare enemyroam 1 soundonce AZOMROAM else ifvare enemyroam 2 soundonce AZOMSPOT else ifvare enemyroam 3 soundonce AZOMMOAN } } 

	ifai AIZOMBIESHOOT 
	{ 
		addvar peractor3 1
		ifvarg peractor3 27 { setvar peractor3 0 }
		
		getactorvar[PLAYERID].reflective reflective
		
			ifpdistl 1300
			ifp palive
			{
				ifvare peractor3 18 
				{ 
					ifvare reflective 1
					{
						soundonce AZOMSWIP 
						setvar peractor3 0
						state bloodspraystate 
						subvarvar extra ZOMBIEHIT
						setactor[THISACTOR].extra extra
						ifvarg extra 0 { soundonce AZOMPAIN ai AIZOMBIEFALLING } else 
						{ setactor[THISACTOR].extra -1 addkills 1 state bloodsprayshit ifrnd 85 soundonce AZOMDIE1 else ifrnd 85 soundonce AZOMDIE2 else soundonce AZOMDIE3 
						ifrnd 64 { state bloodspraystate ai AIZOMBIEDYING setprojectile[ZOMBIEHEAD].vel 60 ezshoot 256 ZOMBIEHEAD getactor[RETURN].z z addvar z -3800 setactor[RETURN].z z } else ai AIZOMBIEFALLING }
					} 
					else
					{
						soundonce AZOMSWIP 
						getactor[THISACTOR].ang ang
						setactor[PLAYERID].htang ang
						setactor[PLAYERID].htextra ZOMBIEHIT 
						getactor[PLAYERID].htextra paextra
						state checkb_armor
						palfrom 32 0 0 0
					}
				}
			} else { ifvare peractor3 18 { soundonce AZOMSWIP } ifvare peractor3 27 { setvar peractor3 0 ai AIZOMBIEWALK } }
	} 
	
	ifai AIZOMBIESTAYPUT ifp palive ifcansee { state facingstate ifvare set 1 { soundonce AZOMROAM ai AIZOMBIEWALK } }
	ifai AIZOMBIERANDOM ifp palive ifcansee { soundonce AZOMROAM ai AIZOMBIEWALK }
} 
else
{
	ifhitweapon { state checkzombiehitstate }
	ifai AIZOMBIESHOOT { ifcount 26 ai AIZOMBIERANDOM }
	ifai AIZOMBIEWALK { ai AIZOMBIERANDOM }
	ifai AIZOMBIERANDOM { ifrnd 2 soundonce AZOMMOAN state ifnotmovingstate ifrnd 4 { randvar ang 2048 setactor[THISACTOR].ang ang } ifcount 390 { ai AIZOMBIESTAYPUT resetcount break } } 
}
ifai AIZOMBIEGOTHIT { ifcount 5 ai AIZOMBIERANDOM }
ifai AIZOMBIEGETUP { cstat 257 ifactioncount 2 ai AIZOMBIEWALK }
ifai AIZOMBIEDYING { cstat 0 ifactioncount 6 ai AIZOMBIEDEAD }
ifai AIZOMBIEFALLING { cstat 0 ifactioncount 4 ai AIZOMBIEDEAD2 }
ifai AIZOMBIEDEAD2 { ifvarg extra 0 { cstat 0 ifcount 45 ai AIZOMBIEGETUP } }
ifai AIZOMBIEGUTS { cstat 128 ifactioncount 6 { cstat 128 ai AIZOMBIEGUTS2 } }

getactorvar[THISACTOR].voodoohitenemy voodoohitenemy
ifvare voodoohitenemy 1 
{ 
    addkills 1
	setactor[THISACTOR].extra 0
	cstat 0
	ai AIZOMBIEVOODOO1
	ifrnd 85 soundonce AZOMDIE1 else ifrnd 85 soundonce AZOMDIE2 else soundonce AZOMDIE3
	setactorvar[THISACTOR].voodoohitenemy 0
}
ifai AIZOMBIEVOODOO1 ifactioncount 7 ai AIZOMBIEVOODOO2

getactorvar[THISACTOR].teslahitenable teslahitenable
ifvare teslahitenable 1 { getactor[THISACTOR].extra extra ifvarg extra 0 { cstat 257 ai AIZOMBIETESLA } else { addkills 1 ifrnd 85 soundonce AZOMDIE1 else ifrnd 85 soundonce AZOMDIE2 else soundonce AZOMDIE3 ai AIZOMBIEFALLING } setactorvar[THISACTOR].teslahitenable 0 }
ifai AIZOMBIETESLA { randvar enemyshade 64 setactor[THISACTOR].shade enemyshade ifcount 10 { ai AIZOMBIEWALK }  }


getactorvar[THISACTOR].flamedamage flamedamage
ifvarg flamedamage 0 { addvar COUNTER 1 state newfirestate } 
ifinwater { setvar COUNTER 0 }
ifvarvare COUNTER flamedamage { setactorvar[THISACTOR].flamedamage 0 setvar COUNTER 0 }
	
getactorvar[THISACTOR].burningguyactive tmp
ifvare tmp 1 
{ 
	espawn BURNINGGUY 
	setactor[RETURN].xrepeat 22
	setactor[RETURN].yrepeat 22
	setactorvar[RETURN].bguy_id 1 
	addkills 1 
	setactorvar[THISACTOR].burningguyactive 0 
	killit 
}
	
enda

action ZBURNEDACT1 0 4 1 1 15
action ZBURNEDACT2 4 1 1 1 1

useractor notenemy ZBURNED
sizeat 24 24 fall
ifaction 0 { cstat 128 action ZBURNEDACT1 }
ifaction ZBURNEDACT1 { ifactioncount 4 { cstat 0 action ZBURNEDACT2 } }
enda

action ABURNINGGUYDEAD 0 3 1 1 7
spritenoshade BURNINGGUYDEAD
useractor notenemy BURNINGGUYDEAD 1 ABURNINGGUYDEAD soundonce FLESH_BURNING fall cstat 128 sizeat 30 30
setactorvar[THISACTOR].active 1
ifvare peractor 0
{
	espawn SMALLSMOKE
	setvar light_radius 2048
	setvar red 255
	setvar green 144
	setvar blue 0
	state spawnlight
	setvar peractor 1
}
ifpdistl 800 ifcansee { ifrnd 32 { addphealth -1 palfrom 32 32 } palfrom 32 32 }
ifactioncount 10 sizeat 30 30 ifactioncount 20 sizeat 30 25 ifactioncount 30 sizeat 30 20 ifactioncount 40 sizeat 30 15 ifactioncount 50 { sizeat 30 10 cstator 258 } ifactioncount 60 sizeat 30 5 ifactioncount 70 sizeat 30 1 ifactioncount 80 { setactorvar[THISACTOR].active 0 killit }
enda 

useractor notenemy BURNINGSMOKE cstat 642 sizeat 32 32 
getactorvar[THISACTOR].spriteid tmp
getactor[tmp].x x
getactor[tmp].y y
getactor[tmp].z z
addvar z -12000
setactor[THISACTOR].x x
setactor[THISACTOR].y y
setactor[THISACTOR].z z
ifcount 52 killit
enda

action ABURNINGGUYWALK  0 4 5 1 15
action ABURNINGGUYDYING -383 3 1 1 25

move BURNINGGUYWALK 140
move BURNINGGUYSTOP 

ai AIBURNINGGUYWALK ABURNINGGUYWALK BURNINGGUYWALK faceplayer seekplayer
ai AIBURNINGGUYDYING ABURNINGGUYDYING BURNINGGUYSTOP

spritenoshade BURNINGGUY
useractor notenemy BURNINGGUY fall
getactorvar[THISACTOR].bguy_id peractor2
ifai NO { cstator 257 ai AIBURNINGGUYWALK ifvare peractor2 2 { ifrnd 85 { soundonce CULTFIR1 } else ifrnd 85 { soundonce CULTFIR2 } else soundonce CULTFIR3 } else ifvare peractor2 1 { soundonce AZOMPAIN } else ifvare peractor2 3 { soundonce FZOMPAIN } }
ifai AIBURNINGGUYWALK 
{ 
	ifvare peractor 0
	{
		espawn BURNINGSMOKE
		setactorvar[RETURN].spriteid THISACTOR
		setvar peractor 1
	}
	ifpdistl 800 ifactioncount 2 { addphealth -5 palfrom 32 32 resetactioncount } else 
	ifcount 52 
	{ 
		ifvare peractor2 1 { soundonce AZOMDIE1 } 
		ifvare peractor2 2 { guts JIBS3 10 ifrnd 64 { soundonce CULTDIE1 } else ifrnd 64 { soundonce CULTDIE2 } else { soundonce CULTDIE3 } } 
		ai AIBURNINGGUYDYING { state bloodspraystate  state bloodspraystate state bloodspraystate }
		ifvare peractor2 3 { ifrnd 85 soundonce FZOMDIE1 else ifrnd 85 soundonce FZOMDIE2 else soundonce FZOMDIE3 } 
	} 
} 
ifai AIBURNINGGUYDYING 
{ 
	ifactioncount 3 
	{ 
		ifvare peractor2 1 { spawn ZBURNED }
		ifvare peractor2 3 { spawn ZBURNED }
		spawn BURNINGGUYDEAD 
		killit 
	} 
}
enda

//------------------------------BONE EEL CODE

action AFISHWALK  0  3  5  1  20
action AFISHBITE 5 3 5 1 20
action AFISHDYING -413 4 1 1 10
action AFISHDEAD -411 1 1 1 10
action AFISHTESLA 1859 1 5 1 1

move FISHWALK 130
move FISHSTOP 
move FISHUP 130 -70
move FISHDOWN 130

ai AIFISHWALK AFISHWALK FISHWALK faceplayer
ai AIFISHBITE AFISHBITE FISHSTOP faceplayer 
ai AIFISHRANDOM AFISHWALK FISHWALK randomangle 
ai AIFISHSTAY AFISHWALK FISHSTOP 
ai AIFISHTESLA AFISHTESLA FISHSTOP
ai AIFISHDYING AFISHDYING FISHSTOP
ai AIFISHDEAD AFISHDEAD FISHSTOP

state fishhurt
ifdead { addkills 1 state bloodsprayshit state bloodsprayshit ifrnd 92 soundonce EELDIE1 else ifrnd 92 soundonce EELDIE2 else soundonce EELDIE3 ai AIFISHDYING } else { state bloodsprayshit soundonce EELPAIN ai AIFISHWALK }
ends

eventloadactor FISH 
setactor[THISACTOR].xrepeat 25
setactor[THISACTOR].yrepeat 25
enda

spriteshadow FISH
spritenoshade FISH
useractor notenemy FISH
setactor[THISACTOR].clipdist 50
ifvare VISION 1 { setactor[THISACTOR].shade -127 } else
{
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade enemyshade
	setactor[THISACTOR].shade enemyshade
}
getplayer[THISACTOR].i PLAYERID
ifhitweapon { state fishhurt }
getactorvar[PLAYERID].invisible invisible
ifp pdead setvar invisible 1

ifai NO { addvar TOTALKILLS 1 strength FISHSTRENGTH sizeat 25 25 cstator 257 ai AIFISHSTAY }
ifvarn invisible 1
{
ifai AIFISHWALK 
{ 
	fall
	ifmove FISHUP { ifp phigher nullop else { move FISHDOWN faceplayer }  }
	else ifp phigher { move FISHUP faceplayer }
	ifpdistl 1000 ai AIFISHBITE ifrnd 1 ifcansee soundonce EELROAM 
} 
ifai AIFISHBITE 
{ 
	ifpdistl 1000 ifcansee 
	{ 
		ifactioncount 3 
		{ 
			getactorvar[PLAYERID].reflective tmp
			ifvare tmp 1 
			{
				state bloodspraystate 
				soundonce EELPAIN
				getactor[THISACTOR].extra extra
				ifvarg extra 0 { subvar extra 12 setactor[THISACTOR].extra extra } else { addkills 1 state bloodsprayshit ifrnd 64 { soundonce EELDIE1 } else ifrnd 64 { soundonce EELDIE2 } else { soundonce EELDIE3 } ai AIFISHDYING }
			} 
			else 
			{
				soundonce PFLESH 
				addphealth -12 
				palfrom 32 32 
			}
			resetactioncount 
			
		} 
	} 
		else ai AIFISHWALK 
} 
getactorvar[THISACTOR].voodoohitenemy voodoohitenemy
ifvare voodoohitenemy 1 
{ 
	setactor[THISACTOR].extra 0
	state fishhurt
	setactorvar[THISACTOR].voodoohitenemy 0
}

getactorvar[THISACTOR].teslahitenable teslahitenable
ifvare teslahitenable 1 { getactor[THISACTOR].extra extra ifvarg extra 0 { cstat 257 ai AIFISHTESLA } else { addkills 1 ai AIFISHDYING } setactorvar[THISACTOR].teslahitenable 0 }
ifai AIFISHTESLA { randvar enemyshade 64 setactor[THISACTOR].shade enemyshade ifcount 10 { ai AIFISHWALK }  }


ifai AIFISHSTAY ifp palive ifcansee { state facingstate ifvare set 1 { ai AIFISHWALK } }
ifai AIFISHRANDOM ifp palive ifcansee { ai AIFISHWALK } 
} else
{
ifai AIFISHWALK { ai AIFISHRANDOM } 
ifai AIFISHRANDOM { ifrnd 1 ifcansee soundonce EELROAM state ifnotmovingstate ifcount 200 ai AIFISHSTAY } 
}
ifai AIFISHDEAD fall
ifai AIFISHDYING { cstat 0 fall ifactioncount 7 { ai AIFISHDEAD } }
enda

//------------------------------BAT CODE

action BATSLEEPDYING 27 4 1 1 10
action BATSLEEPBURNING -264 8 1 1 10
action BATSLEEPBURNED -256 1 1 1 1

eventloadactor BATSLEEP 
setactor[THISACTOR].xrepeat 35
setactor[THISACTOR].yrepeat 35
enda

spriteshadow BATSLEEP
spritenoshade BATSLEEP
useractor notenemy BATSLEEP WEAK sizeat 35 35
setactor[THISACTOR].clipdist 40
ifvare VISION 1 { setactor[THISACTOR].shade -127 } else
{
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade enemyshade
	setactor[THISACTOR].shade enemyshade
}
getplayer[THISACTOR].i PLAYERID
getactorvar[PLAYERID].invisible invisible
ifvarn invisible 1 
{
ifvare peractor2 0 { addvar TOTALKILLS 1 setvar peractor2 1 }
ifaction NO { ifcansee ifpdistl 8192 ifcount 16 { soundonce BATSPOT espawn BAT setactorvar[RETURN].settotalkill 1 killit } } }
ifhitweapon 
{ 
	action BATSLEEPDYING
	ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3 
}
getactorvar[THISACTOR].voodoohitenemy voodoohitenemy
ifvare voodoohitenemy 1 
{ 
	setactor[THISACTOR].extra 0
	action BATSLEEPDYING
	ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3 
	setactorvar[THISACTOR].voodoohitenemy 0
}
ifaction BATSLEEPDYING { fall ifactioncount 4 { addkills 1 killit } }
getactorvar[THISACTOR].flamedamage flamedamage
ifvarg flamedamage 0 ifvare peractor 0 { action BATSLEEPBURNING setvar peractor 1 }
ifaction BATSLEEPBURNING { fall ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3 ifactioncount 8 { addkills 1 action BATSLEEPBURNED break } }
enda

action ABAT   0  4  5  1  8
action ABATDYING 25 4 1 1 10
action ABATBURNING -266 8 1 1 10
action ABATBURNED -258 1 1 1 1

move BATFOWARD 150
move BATFIND 80
move BATDOWN 150 80
move BATUP 150 -100

ai AIBATFOWARD ABAT BATFOWARD faceplayer
ai AIBATFIND ABAT BATFIND randomangle
ai AIBATDOWN ABAT BATDOWN seekplayer getv
ai AIBATUP ABAT BATUP seekplayer getv
ai AIBATDYING ABATDYING BATFOWARD faceplayer
ai AIBATBURNING ABATBURNING BATFOWARD faceplayer
ai AIBATBURNED ABATBURNED BATFOWARD

spriteshadow BAT
spritenoshade BAT
useractor notenemy BAT BATSTRENGTH
setactor[THISACTOR].clipdist 40
ifvare VISION 1 { setactor[THISACTOR].shade -127 } else
{
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade enemyshade
	setactor[THISACTOR].shade enemyshade
}
getplayer[THISACTOR].i PLAYERID

getactorvar[THISACTOR].settotalkill settotalkill
ifai NO { ifvarn settotalkill 1 { addvar TOTALKILLS 1 } cstat 257 sizeat 30 30 strength BATSTRENGTH ai AIBATFOWARD }
ifhitweapon { ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3  ai AIBATDYING }
getactorvar[PLAYERID].invisible invisible
ifp pdead setvar invisible 1
ifvarn invisible 1 
{
	ifp palive
	{
		ifai AIBATFOWARD ifcansee { state ifnotmovingstate ifrnd 16 ai AIBATDOWN else ifrnd 16 { soundonce BATSPOT ai AIBATUP } }
		ifai AIBATDOWN { state ifnotmovingstate iffloordistl 8 { ai AIBATUP } ifpdistl 1024 { ai AIBATDOWN } else ifrnd 16 ai AIBATFOWARD }
		ifai AIBATUP { state ifnotmovingstate ifceilingdistl 8 { ai AIBATDOWN } ifpdistl 1024 { ai AIBATDOWN } else { ifp phigher ai AIBATUP else ifrnd 16 ai AIBATFOWARD } }
	} else ai AIBATFIND
	ifai AIBATFIND ifcansee ifp palive { soundonce BATSPOT ai AIBATFOWARD }
} else { ifai AIBATFOWARD { ai AIBATFIND } }
ifai AIBATFIND { state ifnotmovingstate }
ifai AIBATDYING { fall ifactioncount 4 { addkills 1 killit } }

getactorvar[THISACTOR].flamedamage tmp
ifvarg tmp 0 { ifvare peractor 0 { ai AIBATBURNING setvar peractor 1 } }
ifai AIBATBURNING { fall ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3 ifactioncount 8 { cstat 0 addkills 1 ai AIBATBURNED break } }

getactorvar[THISACTOR].voodoohitenemy voodoohitenemy
ifvare voodoohitenemy 1 
{ 
	setactor[THISACTOR].extra 0
	ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3  ai AIBATDYING
	setactorvar[THISACTOR].voodoohitenemy 0
}

enda


//------------------------------GARGOYLE

spriteshadow GABGBONE
defineprojectile GABGBONE PROJ_WORKSLIKE 32770
defineprojectile GABGBONE PROJ_HITRADIUS 0
defineprojectile GABGBONE PROJ_VEL 700
defineprojectile GABGBONE PROJ_DROP -60
defineprojectile GABGBONE PROJ_XREPEAT 32
defineprojectile GABGBONE PROJ_YREPEAT 32
defineprojectile GABGBONE PROJ_OFFSET -2048
defineprojectile GABGBONE PROJ_ISOUND DUKE_CRACK_FIRST
defineprojectile GABGBONE PROJ_EXTRA 20
defineprojectile GABGBONE PROJ_SPAWNS GARGBONEHIT

action ABONE 0 4 1 1 6
actor GARGBONEHIT 0 ABONE
sizeat 40 40 ifactioncount 4 killit enda

useractor notenemy STATSTUB
fall sizeat 30 30 cstat 257
getactor[THISACTOR].htextra htextra
getactor[THISACTOR].htang htang
cos x htang
sin y htang
ifvarn htextra -1 { setvarvar k_damage htextra addvar peractor3 8 } // damage				     
iffloordistl 10	// deaccelerate on ground

subvarvar k_damage peractor3
ifvarl k_damage 0 { setvar k_damage 0 setactor[THISACTOR].htextra -1 setvar peractor3 0 }     // clamping multiplier

mulvarvar x k_damage                // roll force = damage - deacceleration
mulvarvar y k_damage
shiftvarr x 15
shiftvarr y 15
setvar z 0
movesprite THISACTOR x y z CLIPMASK0 RETURN
enda

action ASTATWAKEUP 5 3 1 1 25

eventloadactor GARBSTATUE 
setactor[THISACTOR].xrepeat 30
setactor[THISACTOR].yrepeat 30
whilevarn spriteid 16384
{
	getactor[spriteid].hitag HITAG
	getactor[spriteid].pal pal
	ifvare HITAG 200 ifvare pal 30 { setvarvar itemprotection spriteid }
	addvar spriteid 1
}
enda

state gargaction 
ifaction NO { ifcansee ifpdistl 4096 ifvarn peractor 1 { cstat 257 sizeat 30 30 action ASTATWAKEUP } }
ends

useractor notenemy GARBSTATUE fall 
sizeat 30 30 getplayer[THISACTOR].i PLAYERID	
getactorvar[PLAYERID].invisible peractor
getactor[THISACTOR].htextra htextra
getactor[THISACTOR].htang htang
getactor[THISACTOR].hitag HITAG
ifvarn HITAG 200 // Not protection Gargoyle
{
	ifvare peractor2 0 { addvar TOTALKILLS 1 setvar peractor2 1 }
	ifp pducking nullop else { ifp pstanding nullop else { state gargaction } }
	ifvarg htextra 0 { state gargaction }
} 
else
{
	ifvare peractor2 0 { addvar TOTALKILLS 1 setvar peractor2 1 }
	getactorvar[itemprotection].skillit skillit
	ifvare skillit 1 { state gargaction }
}
ifaction ASTATWAKEUP { ifactioncount 3 { espawn GARGOYLE setactorvar[RETURN].settotalkill 1 getactor[THISACTOR].z z addvar z -8192 setactor[RETURN].z z spawn STATSTUB killit } }

cos x htang
sin y htang
ifvarn htextra -1 { setvarvar k_damage htextra addvar peractor3 8 } // damage				     
iffloordistl 10	// deaccelerate on ground

subvarvar k_damage peractor3
ifvarl k_damage 0 { setvar k_damage 0 setactor[THISACTOR].htextra -1 setvar peractor3 0 }     // clamping multiplier

mulvarvar x k_damage                // roll force = damage - deacceleration
mulvarvar y k_damage
shiftvarr x 15
shiftvarr y 15
setvar z 0
movesprite THISACTOR x y z CLIPMASK0 RETURN

enda

action AGARGWALK 0 4 5 1 15
action AGARGSHOOT 20 6 5 1 15
action AGARGBONESHOOT 20 6 5 1 15
action AGARGHURT 55 1 5 1 1
action AGARGDYING 69 5 1 1 15
action AGARGDEAD1 74 1 1 1 1
action AGARGTESLA 2249 1 5 1 1

move GARGWALK 250
move GARGUP 250 -70
move GARGDOWN 250
move GARGSTOP

ai AIGARGWALK AGARGWALK GARGWALK faceplayer
ai AIGARGHURT AGARGHURT GARGSTOP faceplayer
ai AIGARGRANDOM AGARGWALK GARGWALK randomangle
ai AIGARGTESLA AGARGTESLA GARGSTOP
ai AIGARGSTOP AGARGWALK GARGSTOP
ai AIGARGSHOOT AGARGSHOOT GARGSTOP faceplayer
ai AIGARGBONESHOOT AGARGBONESHOOT GARGSTOP faceplayer
ai AIGARGDYING AGARGDYING GARGSTOP faceplayer
ai AIGARGDEAD1 AGARGDEAD1 GARGSTOP

action AGARGBURNING 0 3 1 1 15
action AGARGBURN 4 5 1 1 15
action AGARGBURNED 10 1 1 1 1

ai AIGARGBURNING AGARGBURNING GARGSTOP faceplayer
ai AIGARGBURN AGARGBURN GARGSTOP faceplayer
ai AIGARGBURNED AGARGBURNED GARGSTOP

spriteshadow GARGBURNING
spritenoshade GARGBURNING
useractor notenemy GARGBURNING
ifai NO { sizeat 30 30 cstat 1 ai AIGARGBURNING }
ifai AIGARGBURNING { ifcount 100 { fall ai AIGARGBURN } }
ifai AIGARGBURN { fall ifactioncount 5 ai AIGARGBURNED }
ifai AIGARGBURNED { cstat 0 fall }
enda

action AGARGSQUISH 0 5 1 1 15
action AGARGSQUISHED 5 1 1 1 1

ai AIGARGSQUISH AGARGSQUISH GARGSTOP faceplayer
ai AIGARGSQUISHED AGARGSQUISHED GARGSTOP

useractor notenemy GARGHEAD fall sizeat 30 30 
cstat 256 ifhitweapon {  qspawn BLOODPOOL2 killit } 
enda

useractor notenemy GARGWINGFLOOR fall sizeat 30 30 
cstat 0
enda

useractor notenemy GARGSQUISH
fall
ifai NO 
{ 
	sizeat 30 30 cstat 1 ai AIGARGSQUISH 
	randvar zdist 1024
	ifrnd 128 mulvar zdist -1
	subvar zdist 512
	ezshootvar zdist JIBS7
	getprojectile[JIBS7].vel tmp
	randvar tmp2 32
	addvarvar tmp tmp2
	setprojectile[JIBS7].vel tmp
	getactor[RETURN].ang ang
	randvar tmp 2048
	ifrnd 128 mulvar tmp -1
	addvarvar ang tmp
	setactor[RETURN].ang ang
	
	randvar zdist 1024
	ifrnd 128 mulvar zdist -1
	subvar zdist 512
	ezshootvar zdist GARGHEAD
	getprojectile[GARGHEAD].vel tmp
	randvar tmp2 32
	addvarvar tmp tmp2
	setprojectile[GARGHEAD].vel tmp
	getactor[RETURN].ang ang
	randvar tmp 2048
	ifrnd 128 mulvar tmp -1
	addvarvar ang tmp
	setactor[RETURN].ang ang
	
	randvar zdist 1024
	ifrnd 128 mulvar zdist -1
	subvar zdist 512
	ezshootvar zdist GARGWING
	getprojectile[GARGWING].vel tmp
	randvar tmp2 32
	addvarvar tmp tmp2
	setprojectile[GARGWING].vel tmp
	getactor[RETURN].ang ang
	randvar tmp 2048
	ifrnd 128 mulvar tmp -1
	addvarvar ang tmp
	setactor[RETURN].ang ang
	
	getactorvar[THISACTOR].peractor htang
	getactorvar[THISACTOR].peractor2 htextra
}
ifai AIGARGSQUISH ifactioncount 5 { cstat 0 ai AIGARGSQUISHED }
cos x htang
sin y htang
ifvarn htextra -1 { setvarvar k_damage htextra addvar peractor3 8 } // damage				     
iffloordistl 10	// deaccelerate on ground

subvarvar k_damage peractor3
ifvarl k_damage 0 { setvar k_damage 0 setactor[THISACTOR].htextra -1 setvar peractor3 0 }     // clamping multiplier

mulvarvar x k_damage                // roll force = damage - deacceleration
mulvarvar y k_damage
shiftvarr x 12
shiftvarr y 12
setvar z 0
movesprite THISACTOR x y z CLIPMASK0 RETURN
enda

state garghurtstate
ifwasweapon RPG { addkills 1 espawn GARGSQUISH setactorvar[RETURN].peractor htang setactorvar[RETURN].peractor2 htextra killit } else 
ifwasweapon RADIUSEXPLOSION { addkills 1 espawn GARGSQUISH setactorvar[RETURN].peractor htang setactorvar[RETURN].peractor2 htextra killit } else 
ifdead { addkills 1 state bloodsprayshit ifrnd 96 { soundonce GARGDIE1 } else ifrnd 96 { soundonce GARGDIE2 } else { soundonce GARGDIE3 } ai AIGARGDYING } else { soundonce GARGPAIN state bloodspraystate ifvare perplayer 1 { ai AIGARGHURT } else { ifrnd 64 ai AIGARGHURT } }
ends

eventloadactor GARGOYLE 
setactor[THISACTOR].xrepeat 30
setactor[THISACTOR].yrepeat 30
enda

spriteshadow GARGOYLE
spritenoshade GARGOYLE
useractor notenemy GARGOYLE
setactor[THISACTOR].clipdist 80
ifvare VISION 1 { setactor[THISACTOR].shade -127 } else
{
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade enemyshade
	setactor[THISACTOR].shade enemyshade
}
getplayer[THISACTOR].i PLAYERID	
getactor[THISACTOR].htextra htextra
getactor[THISACTOR].htang htang
getactorvar[PLAYERID].invisible invisible
ifp pdead setvar invisible 1

getactorvar[THISACTOR].settotalkill settotalkill
ifai NO { ifvarn settotalkill 1 { addvar TOTALKILLS 1 } strength GARGSTRENGTH sizeat 30 30 cstat 257 ai AIGARGSTOP }
ifhitweapon { state garghurtstate }
ifvarn invisible 1
{
	ifai AIGARGWALK	ifcansee 
	{ 
		fall
		ifmove GARGUP { ifp phigher nullop else ifcount 12 { move GARGDOWN faceplayer }  }
		else ifp phigher ifcount 12 { move GARGUP faceplayer }
		ifpdistg 3092 ifpdistl 8192 { ifp pstanding ifcount 5 { ai AIGARGBONESHOOT } else ifrnd 16 ai AIGARGBONESHOOT } else ifpdistl 1280 { ai AIGARGSHOOT } 
	}

	ifai AIGARGSHOOT 
	{ 
		ifpdistl 1280 ifcansee
		{ 
			getactorvar[PLAYERID].reflective reflective
			ifactioncount 6 
			{
				ifvare reflective 1
				{
					soundonce PFLESH  
					subvar extra 2
					setactor[THISACTOR].extra extra
					state garghurtstate
				} else
				{
					soundonce PFLESH 
					setactor[PLAYERID].htextra 2
					getactor[PLAYERID].htextra paextra
					state checkb_armor
					palfrom 32 1 1 1 
				}
				resetactioncount 
			}
		} else ifcount 30 ai AIGARGWALK
	}
	ifai AIGARGBONESHOOT 
	{ 
		ifcansee
		{
			ifactioncount 6 
			{
				soundonce GARGCLAW 
				shoot GABGBONE
				ai AIGARGWALK
				resetactioncount 
			}
		} else ifcount 30 ai AIGARGWALK
	}
	ifai AIGARGSTOP ifp palive ifcansee { state facingstate ifvare set 1 { soundonce GARGSPOT ai AIGARGWALK } }
	ifai AIGARGRANDOM { ifp palive ifcansee ai AIGARGWALK }
} 
else
{
	ifai AIGARGBONESHOOT { ai AIGARGRANDOM }
	ifmove GARGUP { ai AIGARGRANDOM }
	ifmove GARGDOWN { ai AIGARGRANDOM }
	ifai AIGARGSHOOT { ai AIGARGRANDOM }
	ifai AIGARGWALK { ai AIGARGRANDOM }
	ifai AIGARGRANDOM 
	{ 
		state ifnotmovingstate ifcount 390 { ai AIGARGSTOP resetcount break } 
	}
}
ifai AIGARGHURT { ifcount 10 ai AIGARGWALK }
ifai AIGARGDYING { cstat 0 fall ifactioncount 5 { ai AIGARGDEAD1 } }
ifai AIGARGDEAD1 { cstat 0 fall }

getactorvar[THISACTOR].flamedamage flamedamage
ifvarg flamedamage 0 { addvar COUNTER 1 state newfirestate } 
ifinwater { setvar COUNTER 0 }
ifvarvare COUNTER flamedamage { setactorvar[THISACTOR].flamedamage 0 setvar COUNTER 0 }

getactorvar[THISACTOR].burningguyactive burningguyactive
ifvare burningguyactive 1 
{ 
	addkills 1 
	spawn GARGBURNING 
	killit
	setactorvar[THISACTOR].burningguyactive 0 
}

getactorvar[THISACTOR].voodoohitenemy voodoohitenemy
ifvare voodoohitenemy 1 
{ 
	setactor[THISACTOR].extra 0
	state garghurtstate
	setactorvar[THISACTOR].voodoohitenemy 0
}

getactorvar[THISACTOR].teslahitenable teslahitenable
ifvare teslahitenable 1 { getactor[THISACTOR].extra extra ifvarg extra 0 { cstat 257 ai AIGARGTESLA } else { addkills 1 ai AIGARGDYING } setactorvar[THISACTOR].teslahitenable 0 }
ifai AIGARGTESLA { randvar enemyshade 64 setactor[THISACTOR].shade enemyshade ifcount 10 { ai AIGARGWALK }  }

enda



//------------------------------BLOATED BUTCHER CODE

action ABUTCHERWALK  0  4  5  1  20
action ABUTCHERSTAY  0  1  5  1  1
action ABUTCHERATTACK1 48 5 5 1 20
action ABUTCHERATTACK2 48 5 5 1 20
action ABUTCHERATTACK3 2234 4 5 1 25
action ABUTCHERDYING 30 6 1 1 20
action ABUTCHERDEAD 35 1 1 1 20
action ABUTCHERGUTS 73 7 1 1 20
action ABUTCHERTESLA 2298 1 5 1 1
action ABUTCHERVOODOO1 -34 5 1 1 15
action ABUTCHERVOODOO2 -28 1 1 1 1
action ABUTCHERVOODOO3 -28 4 1 1 15
action ABUTCHERVOODOO4 -23 1 1 1 1

move BUTCHERWALK 70
move BUTCHERSTOP 

ai AIBUTCHERWALK ABUTCHERWALK BUTCHERWALK faceplayer
ai AIBUTCHERWALKLEFT ABUTCHERWALK BUTCHERWALK faceplayer
ai AIBUTCHERWALKRIGHT ABUTCHERWALK BUTCHERWALK faceplayer
ai AIBUTCHERRANDOM ABUTCHERWALK BUTCHERWALK randomangle
ai AIBUTCHERATTACK1 ABUTCHERATTACK1 BUTCHERSTOP faceplayer 
ai AIBUTCHERATTACK2 ABUTCHERATTACK2 BUTCHERSTOP faceplayer 
ai AIBUTCHERATTACK3 ABUTCHERATTACK3 BUTCHERSTOP faceplayer
ai AIBUTCHERGUTS ABUTCHERGUTS BUTCHERSTOP
ai AIBUTCHERSTAYPUT ABUTCHERSTAY BUTCHERSTOP
ai AIBUTCHERDYING ABUTCHERDYING BUTCHERSTOP
ai AIBUTCHERDEAD ABUTCHERDEAD BUTCHERSTOP
ai AIBUTCHERTESLA ABUTCHERTESLA BUTCHERSTOP
ai AIBUTCHERVOODOO1 ABUTCHERVOODOO1 BUTCHERSTOP
ai AIBUTCHERVOODOO2 ABUTCHERVOODOO2 BUTCHERSTOP
ai AIBUTCHERVOODOO3 ABUTCHERVOODOO3 BUTCHERSTOP
ai AIBUTCHERVOODOO4 ABUTCHERVOODOO4 BUTCHERSTOP

state checkbutcherhitstate
getactor[THISACTOR].extra extra
ifwasweapon PR_NAPALM { addkills 1 ai AIBUTCHERGUTS } 
else ifwasweapon RADIUSEXPLOSION { addkills 1 ai AIBUTCHERGUTS }
else { ifvarg extra 0 { state bloodspraystate soundonce FZOMPAIN }
else { addkills 1 state bloodsprayshit ifrnd 128 cstat 0 else cstat 4 ai AIBUTCHERDYING } }
ends

state bucherslimeshoot
soundonce FZOMPUKE
ezshoot 0 BUCHERSLIME
getactor[RETURN].z z
subvar z 4096
setactor[RETURN].z z
ends

eventloadactor BUTCHER 
setactor[THISACTOR].xrepeat 24
setactor[THISACTOR].yrepeat 24
enda

spriteshadow BUTCHER
spritenoshade BUTCHER
useractor notenemy BUTCHER
fall
setactor[THISACTOR].clipdist 80
ifvare VISION 1 { setactor[THISACTOR].shade -127 } else
{
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade enemyshade
	setactor[THISACTOR].shade enemyshade
}
randvar enemyroam 512

getactor[THISACTOR].extra extra
getactor[THISACTOR].htextra htextra
getplayer[THISACTOR].i PLAYERID

getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[PLAYERID].x px
getactor[PLAYERID].y py
subvarvar px x
subvarvar py y
getangle ang px py
setvarvar esaveang ang

getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z
subvar z 4096
ifp phigher subvar z 16384
getactor[THISACTOR].sectnum sectorid
cos mycos ang
sin mysin ang
hitscan x y z sectorid mycos mysin 0 RETURN RETURN spriteid RETURN RETURN RETURN 4294901808
  
ifai NO { addvar TOTALKILLS 1 strength BUTCHERSTRENGTH sizeat 24 24 cstat 257 ai AIBUTCHERSTAYPUT }
getactorvar[PLAYERID].invisible invisible
ifp pdead setvar invisible 1
ifvarn invisible 1
{
	ifhitweapon { state checkbutcherhitstate }
	ifai AIBUTCHERWALK 
	{ 
		ifcansee ifp palive { ifpdistl 1280 { ai AIBUTCHERATTACK1 } else ifpdistg 2048 ifpdistl 3092 { ifcount 2 { ai AIBUTCHERATTACK3 } } else ifpdistg 3092 ifpdistl 4096 { ifcount 2 { ai AIBUTCHERATTACK2 } } } 
		else ai AIBUTCHERRANDOM 
		state ifnotmovingstate 
		ifcansee
		{
		ifvare enemyroam 8 { soundonce FZOMROAM }
		ifvare enemyroam 16 { soundonce FZOMSPOT }
		}
	} 

	ifai AIBUTCHERATTACK2 // Axe fly
	{
		addvar peractor3 1
		ifvarg peractor3 29 { setvar peractor3 0 }
		
		ifp pjumping nullop else ifp pfalling nullop else
		{		
			ifvarn spriteid -1
			ifcansee 
			{	
				ifvarvarn spriteid PLAYERID 
				{ 
					ifvare peractor 0 
					{ 
						ifrnd 128 ai AIBUTCHERWALKLEFT else ai AIBUTCHERWALKRIGHT
						setvar peractor 1 
					}
				} else setvar peractor 0
			} else ai AIBUTCHERWALK	
		}	
		
		ifpdistg 4096 { ifvare peractor3 12 { shoot BUCHERAXE } ifvare peractor3 29 { setvar peractor3 0 ai AIBUTCHERWALK } } else ifpdistl 3092 { ifvare peractor3 12 { shoot BUCHERAXE } ifvare peractor3 29 { setvar peractor3 0 ai AIBUTCHERATTACK3 } } else
		ifvare peractor3 12
		{
			shoot BUCHERAXE
		}
	}
	ifai AIBUTCHERATTACK3 //Green slime
	{
		ifp pjumping nullop else ifp pfalling nullop else
		{		
			ifvarn spriteid -1
			ifcansee 
			{	
				ifvarvarn spriteid PLAYERID 
				{ 
					ifvare peractor 0 
					{ 
						ifrnd 128 ai AIBUTCHERWALKLEFT else ai AIBUTCHERWALKRIGHT
						setvar peractor 1 
					}
				} else setvar peractor 0
			} else ai AIBUTCHERWALK	
		}	
		ifpdistg 3092 ifactioncount 4 { state bucherslimeshoot ai AIBUTCHERATTACK2 } else ifpdistl 2048 ifactioncount 4 { state bucherslimeshoot ai AIBUTCHERWALK } else
		ifactioncount 4
		{
			state bucherslimeshoot
			resetactioncount
		}
	}
	ifai AIBUTCHERATTACK1 
	{ 
		addvar peractor3 1
		ifvarg peractor3 29 { setvar peractor3 0 }
		
		getactorvar[PLAYERID].reflective reflective
		
			ifpdistl 1300
			ifp palive
			{
				ifvare peractor3 12 
				{ 
					ifvare reflective 1
					{
						soundonce PFLESH  
						subvar extra 10
						setactor[THISACTOR].extra extra
						state checkbutcherhitstate
					} 
					else
					{
						soundonce PFLESH  
						getactor[THISACTOR].ang ang
						setactor[PLAYERID].htang ang
						setactor[PLAYERID].htextra 10 
						getactor[PLAYERID].htextra paextra
						state checkb_armor
						palfrom 32 0 0 0
					}
				}
			} else { ifvare peractor3 12 { soundonce AZOMSWIP } ifvare peractor3 29 { setvar peractor3 0 ai AIBUTCHERWALK } }
	} 
	
	ifai AIBUTCHERWALKLEFT
	{	
		setvar peractor3 0
		addvar esaveang 512
		setactor[THISACTOR].ang esaveang
		ifp palive { ifvarvare spriteid PLAYERID { setvar peractor 0 ai AIBUTCHERWALK } } else ai AIBUTCHERSTAYPUT
	}
	ifai AIBUTCHERWALKRIGHT
	{
		setvar peractor3 0
		subvar esaveang 512
		setactor[THISACTOR].ang esaveang
		ifp palive { ifvarvare spriteid PLAYERID  { setvar peractor 0 ai AIBUTCHERWALK } } else ai AIBUTCHERSTAYPUT
	}
	ifai AIBUTCHERSTAYPUT ifp palive ifcansee { state facingstate ifvare set 1 { soundonce FZOMSPOT ai AIBUTCHERWALK } }
	ifai AIBUTCHERRANDOM ifp palive ifcansee { soundonce FZOMSPOT ai AIBUTCHERWALK }
} 
else
{
	ifhitweapon { state checkbutcherhitstate }
	ifai AIBUTCHERATTACK1 { ifcount 29 ai AIBUTCHERRANDOM }
	ifai AIBUTCHERATTACK2 { ifcount 29 ai AIBUTCHERRANDOM }
	ifai AIBUTCHERATTACK3 { ifcount 29 ai AIBUTCHERRANDOM }
	ifai AIBUTCHERWALK { ai AIBUTCHERRANDOM }
	ifai AIBUTCHERRANDOM { ifvare enemyroam 16 ifcansee { soundonce FZOMSPOT } state ifnotmovingstate ifrnd 4 { randvar ang 2048 setactor[THISACTOR].ang ang } ifcount 390 { ai AIBUTCHERSTAYPUT resetcount break } } 
}
ifai AIBUTCHERDYING { ifrnd 85 soundonce FZOMDIE1 else ifrnd 85 soundonce FZOMDIE2 else soundonce FZOMDIE3  ifactioncount 6 { ai AIBUTCHERDEAD } }
ifai AIBUTCHERGUTS { ifactioncount 7 { cstat 0 cactor 6572 } }

getactorvar[THISACTOR].voodoohitenemy voodoohitenemy
ifvare voodoohitenemy 1 
{ 
    addkills 1
	setactor[THISACTOR].extra 0
	cstat 0
	ai AIBUTCHERVOODOO1
	ifrnd 85 soundonce FZOMDIE1 else ifrnd 85 soundonce FZOMDIE2 else soundonce FZOMDIE3
	setactorvar[THISACTOR].voodoohitenemy 0
}
ifai AIBUTCHERVOODOO1 ifactioncount 5 { ai AIBUTCHERVOODOO2 }
ifai AIBUTCHERVOODOO2 { ifcount 26 ai AIBUTCHERVOODOO3 }
ifai AIBUTCHERVOODOO3 { ifactioncount 4 ai AIBUTCHERVOODOO4 }

getactorvar[THISACTOR].teslahitenable teslahitenable
ifvare teslahitenable 1 { getactor[THISACTOR].extra extra ifvarg extra 0 { cstat 257 ai AIBUTCHERTESLA } else { addkills 1 ai AIBUTCHERDYING } setactorvar[THISACTOR].teslahitenable 0 }
ifai AIBUTCHERTESLA { randvar enemyshade 64 setactor[THISACTOR].shade enemyshade ifcount 10 { ai AIBUTCHERWALK }  }

getactorvar[THISACTOR].flamedamage flamedamage
ifvarg flamedamage 0 { addvar COUNTER 1 state newfirestate } 
ifinwater { setvar COUNTER 0 }
ifvarvare COUNTER flamedamage { setactorvar[THISACTOR].flamedamage 0 setvar COUNTER 0 }

getactorvar[THISACTOR].burningguyactive tmp
ifvare tmp 1 
{ 
	espawn BURNINGGUY 
	setactor[RETURN].xrepeat 22
	setactor[RETURN].yrepeat 22
	setactorvar[RETURN].bguy_id 3 
	addkills 1 
	setactorvar[THISACTOR].burningguyactive 0 
	killit 
}
	


/*
getactor[PLAYERID].x mx
getactor[PLAYERID].y my
getactor[PLAYERID].z mz
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z

ifai AIBUTCHERWALK
{
	getactor[THISACTOR].htowner spriteid
	getactor[spriteid].owner ENEMYID
			
	ifvarvarn ENEMYID THISACTOR
	{
		getactor[ENEMYID].x mx
		getactor[ENEMYID].y my
		getactor[ENEMYID].z mz
		getactor[ENEMYID].extra extra
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		getactor[THISACTOR].z z
		subvarvar mx x
		subvarvar my y
		getangle mang mx my
		setactor[THISACTOR].ang mang
	}
			
}

*/
enda

//------------------------------GILL BEAST CODE

action AGBEASTWALK 0 4  5  1  15
action AGBEASTSTAY 0 1  5  1  1
action AGBEASTWATERSTAY 25 1  5  1  1
action AGBEASTSWIM 25 4  5  1  15
action AGBEASTATTACK 50 3  5  1  20
action AGBEASTSWIMATTACK 65 3  5  1  20
action AGBEASTHIT 80 1  1  1  20
//action AGBEASTHIT2 85 1  1  1  20
//action AGBEASTDYING 90 5  1  1  20
action AGBEASTDYING -6 5  1  1  15
action AGBEASTDEAD -1 1 1 1 1
action AGBEASTGUTS -12 5  1  1 15
action AGBEASTTESLA 2164 1 5 1 1

move GBEASTWALK 90
move GBEASTSWIM 200
move GBEASTSWIMAT 0 -8
move GBEASTSWIMUP 200 -50
move GBEASTSWIMDOWN 200 30
move GBEASTSTOP 

ai AIGBEASTWALK AGBEASTWALK GBEASTWALK faceplayer
ai AIGBEASTSWIM AGBEASTSWIM GBEASTSWIM faceplayer
ai AIGBEASTRANDOM AGBEASTWALK GBEASTWALK randomangle
ai AIGBEASTSWIMRANDOM AGBEASTSWIM GBEASTSWIM randomangle
ai AIGBEASTHIT AGBEASTHIT GBEASTSTOP faceplayer
ai AIGBEASTATTACK AGBEASTATTACK GBEASTSTOP faceplayer
ai AIGBEASTSWIMATTACK AGBEASTSWIMATTACK GBEASTSWIMAT faceplayer
ai AIGBEASTSTAY AGBEASTSTAY GBEASTSTOP
ai AIGBEASTWATERSTAY AGBEASTWATERSTAY GBEASTSTOP
ai AIGBEASTDYING AGBEASTDYING GBEASTSTOP faceplayer
ai AIGBEASTGUTS AGBEASTGUTS GBEASTSTOP faceplayer
ai AIGBEASTDEAD AGBEASTDEAD GBEASTSTOP
ai AIGBEASTTESLA AGBEASTTESLA GBEASTSTOP

state checkgbeasthitstate
getactor[THISACTOR].extra extra
ifwasweapon PR_NAPALM { addkills 1 ai AIGBEASTGUTS } 
else ifwasweapon RADIUSEXPLOSION { addkills 1 ai AIGBEASTGUTS }
else { ifvarg extra 0 { state bloodspraystate soundonce GILLPAIN ai AIGBEASTHIT }
else { addkills 1 state bloodsprayshit ifrnd 85 soundonce GILLDIE1 else ifrnd 85 soundonce GILLDIE2 else soundonce GILLDIE3 ai AIGBEASTDYING } }
ends

eventloadactor GILLBEAST 
setactor[THISACTOR].xrepeat 30
setactor[THISACTOR].yrepeat 30
enda

spritenoshade GILLBEAST
spriteshadow GILLBEAST
useractor notenemy GILLBEAST 
fall
setactor[THISACTOR].clipdist 80
ifvare VISION 1 { setactor[THISACTOR].shade -127 } else
{
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade enemyshade
	setactor[THISACTOR].shade enemyshade
}

getactor[THISACTOR].extra extra
getplayer[THISACTOR].i PLAYERID	

randvar enemyroam 512
getactorvar[PLAYERID].invisible invisible
ifp pdead setvar invisible 1

ifai NO { addvar TOTALKILLS 1 strength GILLBEASTSTRENGTH sizeat 30 30 cstat 257 ifinwater ai AIGBEASTWATERSTAY else { ai AIGBEASTSTAY } }

ifvarn invisible 1
{
	ifhitweapon { state checkgbeasthitstate }
	
	ifinwater
	{
		ifvarg extra 0
		{
		ifmove GBEASTSWIMUP { ifp phigher nullop else move GBEASTSWIMDOWN faceplayer  }
			   else
				  ifp phigher ifcount 10 { move GBEASTSWIMUP faceplayer }
		}
				  
		ifai AIGBEASTSWIM 
		{ 
			ifcansee ifp palive 
			{ 
			  ifpdistl 1024 ai AIGBEASTSWIMATTACK 
			} else ai AIGBEASTSWIMRANDOM 
			state ifnotmovingstate ifcansee ifp palive ifpdistl 16384 soundonce GILLSPOT 
		} 
		
		ifai AIGBEASTSWIMATTACK 
		{ 
			getactorvar[PLAYERID].reflective tmp
			
				ifpdistl 1024
				ifp palive
				{
					ifactioncount 3 
					{ 
						ifvare tmp 1
						{
							soundonce PFLESH  
							subvar extra 10
							setactor[THISACTOR].extra extra
							state checkgbeasthitstate
							
						} 
						else
						{
							soundonce PFLESH  
							getactor[THISACTOR].ang ang
							setactor[PLAYERID].htang ang
							setactor[PLAYERID].htextra 10 
							getactor[PLAYERID].htextra paextra
							state checkb_armor
							palfrom 32 0 0 0
						}
						resetactioncount
					}
				} else { ifactioncount 3 { ai AIGBEASTSWIM } }
		}
		ifai AIGBEASTWALK { ai AIGBEASTSWIM }
	} 
	else
	{
		ifai AIGBEASTWALK { ifcansee ifp palive { ifpdistl 1024 ai AIGBEASTATTACK } else ai AIGBEASTRANDOM ifvare enemyroam 1 ifcansee soundonce GILLROAM } 
		ifai AIGBEASTATTACK 
		{ 
			getactorvar[PLAYERID].reflective tmp
			
				ifpdistl 1024
				ifp palive
				{
					ifactioncount 3 
					{ 
						ifvare tmp 1
						{
							soundonce PFLESH  
							subvar extra 10
							setactor[THISACTOR].extra extra
							state checkgbeasthitstate
							
						} 
						else
						{
							soundonce PFLESH  
							getactor[THISACTOR].ang ang
							setactor[PLAYERID].htang ang
							setactor[PLAYERID].htextra 10 
							getactor[PLAYERID].htextra paextra
							state checkb_armor
							palfrom 32 0 0 0
						}
						resetactioncount
					}
				} else { ifactioncount 3 { ai AIGBEASTWALK } }
		}
	}
	ifai AIGBEASTSTAY ifp palive ifcansee { state facingstate ifvare set 1 { soundonce GILLSPOT ai AIGBEASTWALK } }
	ifai AIGBEASTWATERSTAY ifp palive ifcansee { state facingstate ifvare set 1 { soundonce GILLSPOT ai AIGBEASTSWIM } }
	ifai AIGBEASTRANDOM ifp palive ifcansee { ai AIGBEASTWALK }
	ifai AIGBEASTSWIMRANDOM ifp palive ifcansee { ai AIGBEASTSWIM } 
} 
else
{
	ifhitweapon { state checkgbeasthitstate }
	ifai NO { strength 280 sizeat 30 30 cstat 257 ifinwater ai AIGBEASTWATERSTAY else ai AIGBEASTSTAY }
	
	ifinwater
	{
		ifai AIGBEASTSWIMATTACK { ifcount 26 ai AIGBEASTSWIMRANDOM }
		ifmove GBEASTSWIMUP { ai AIGBEASTSWIMRANDOM }
		ifmove GBEASTSWIMDOWN { ai AIGBEASTSWIMRANDOM }
		ifai AIGBEASTSWIM { soundonce 8 ai AIGBEASTSWIMRANDOM }
		ifai AIGBEASTRANDOM { ai AIGBEASTSWIMRANDOM }
		ifai AIGBEASTSWIMRANDOM { state ifnotmovingstate ifcount 390 { ai AIGBEASTWATERSTAY resetcount break } } 
	} 
	else
	{
		ifai AIGBEASTATTACK { ifcount 26 ai AIGBEASTRANDOM }
		ifai AIGBEASTWALK { ai AIGBEASTRANDOM }
		ifai AIGBEASTRANDOM { state ifnotmovingstate ifcount 390 { ai AIGBEASTSTAY resetcount break } } 
	}
}
ifai AIGBEASTHIT { ifcount 5 { ifinwater ai AIGBEASTSWIMRANDOM else ai AIGBEASTRANDOM } }
ifai AIGBEASTDYING { cstat 0 ifactioncount 5 { fall ai AIGBEASTDEAD } }
ifai AIGBEASTGUTS { cstat 128 ifactioncount 5 { cactor 6683 } }

getactorvar[THISACTOR].flamedamage flamedamage
ifvarg flamedamage 0 { addvar COUNTER 1 state newfirestate } 
ifinwater { setvar COUNTER 0 }
ifvarvare COUNTER flamedamage { setactorvar[THISACTOR].flamedamage 0 setvar COUNTER 0 }

getactorvar[THISACTOR].burningguyactive tmp
ifvare tmp 1 
{ 
	addkills 1
	setactor[THISACTOR].extra 0
	state checkgbeasthitstate
	setactorvar[THISACTOR].burningguyactive 0
}

getactorvar[THISACTOR].voodoohitenemy tmp
ifvare tmp 1 
{ 
	setactor[THISACTOR].extra 0
	state checkgbeasthitstate
	setactorvar[THISACTOR].voodoohitenemy 0
}

getactorvar[THISACTOR].teslahitenable teslahitenable
ifvare teslahitenable 1 { getactor[THISACTOR].extra extra ifvarg extra 0 { cstat 257 ai AIGBEASTTESLA } else { addkills 1 ai AIGBEASTDYING } setactorvar[THISACTOR].teslahitenable 0 }
ifai AIGBEASTTESLA { randvar enemyshade 64 setactor[THISACTOR].shade enemyshade ifcount 10 { ifinwater { ai AIGBEASTSWIM } else ai AIGBEASTWALK }  }

enda

//------------------------------PHANTASM CODE

action APANTWALK 0 5  5  1  15
action APANTSTAY 0 1  5  1  1
action APANTATTACK 25 5  5  1  20
action APANTPAIN 50 1  5  1  1

action APANTDYING 61 7 1 1  15
action APANTDEAD 67 1 1 1 1
action APANTTESLA 679 1 5 1 1

move PANTWALK 300
move PANTUP 300 -70
move PANTDOWN 300 -30
move PANTSTOP 

ai AIPANTWALK APANTWALK PANTWALK faceplayer
ai AIPANTRANDOM APANTWALK PANTWALK randomangle
ai AIPANTPAIN APANTPAIN PANTSTOP faceplayer
ai AIPANTATTACK APANTATTACK PANTSTOP faceplayer
ai AIPANTATTACK2 APANTATTACK PANTSTOP faceplayer
ai AIPANTSTAY APANTSTAY PANTSTOP
ai AIPANTDYING APANTDYING PANTSTOP
ai AIPANTDEAD APANTDEAD PANTSTOP
ai AIPANTTESLA APANTTESLA PANTSTOP

state checkphanthitstate
getactor[THISACTOR].extra extra
ifvarg extra 0 { state bloodspraystate soundonce PHANPAIN ai AIPANTPAIN }
else { cstat 0 addkills 1 state bloodsprayshit soundonce PHANDIE1 ai AIPANTDYING }
ends

eventloadactor PHANTASM 
setactor[THISACTOR].xrepeat 30
setactor[THISACTOR].yrepeat 30
enda

spriteshadow PHANTASM
spritenoshade PHANTASM
useractor notenemy PHANTASM PHANTASMSTRENGTH
fall 
ifvare VISION 1 { setactor[THISACTOR].shade -127 } else
{
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade enemyshade
	setactor[THISACTOR].shade enemyshade
}
setactor[THISACTOR].clipdist 80
getplayer[THISACTOR].i PLAYERID	
getactorvar[PLAYERID].invisible invisible
ifp pdead setvar invisible 1

getactor[THISACTOR].cstat acstat
ifhitweapon ifcansee { ifvare acstat 514 nullop else { cstat 514 state checkphanthitstate } }

ifai NO { addvar TOTALKILLS 1 sizeat 30 30 cstat 514 ai AIPANTSTAY  } else
ifvarn invisible 1
{
	ifai AIPANTSTAY { ifcansee ifp palive { state facingstate ifvare set 1 { ifrnd 32 ai AIPANTRANDOM else ai AIPANTWALK } }  }
	ifai AIPANTRANDOM
	{
		ifrnd 1 ifcansee soundonce PHANROAM
		ifcansee 
		ifp palive
		{ 
			state ifnotmovingstate 
			ifrnd 1 ifvare peractor 0 { setvar peractor 1 }
			ifvarg peractor 0 
			{
				getactor[THISACTOR].ang ang 
				addvar ang 128
				setactor[THISACTOR].ang ang 
				addvar peractor 1
				ifvare peractor 100 { setvar peractor 0 }
			}
			ifcount 96 ai AIPANTWALK
		} else { getactor[THISACTOR].ang ang addvar ang 128 setactor[THISACTOR].ang ang ifcount 390 { ai AIPANTSTAY resetcount break } }
	}
	
	ifai AIPANTWALK 
	{ 
		 ifpdistl 16384 ifcansee soundonce PHANSPOT
		ifmove PANTUP { ifp phigher nullop else { ifcount 32 move PANTDOWN faceplayer }  }
		else ifp phigher { move PANTUP faceplayer }
	
		ifcansee 
		ifp palive 
		{ 
			randvar enemycount 1024 
			ifpdistl 1200 { cstat 257 ai AIPANTATTACK  } else
			ifrnd 32 { ifpdistg 3092 ifpdistl 6144 { ifcount 5 { cstat 257 ai AIPANTATTACK2 } } }
			else { ifvare enemycount 1 ai AIPANTRANDOM } 
		} else ai AIPANTRANDOM
	}
	
	ifai AIPANTATTACK 
	{ 
		getactorvar[PLAYERID].reflective reflective
		ifactioncount 3 
		ifpdistl 1200
		ifp palive
		{ 
			ifvare peractor3 0 
			{ 
				ifvare reflective 1
				{
					soundonce PFLESH  
					getactor[THISACTOR].extra extra
					subvar extra 10
					setactor[THISACTOR].extra extra
					state checkphanthitstate		
				} 
				else
				{
					soundonce PFLESH  
					getactor[THISACTOR].ang ang
					setactor[PLAYERID].htang ang
					setactor[PLAYERID].htextra 10 
					getactor[PLAYERID].htextra paextra
					state checkb_armor
					palfrom 32 0 0 0
				}
				setvar peractor3 1 
			}  
		}
		ifactioncount 5 { cstat 514 setvar peractor3 0 ai AIPANTWALK } 
	}
	ifai AIPANTATTACK2 
	{ 
		ifactioncount 3 { ifvare peractor3 0 { shoot PHANTOMSKULL setvar peractor3 1 }  }
		ifhitweapon { cstat 514 state checkphanthitstate }
		ifactioncount 5 { cstat 514 setvar peractor3 0 ai AIPANTWALK } 
	}
	ifai AIPANTPAIN ifcount 14 ai AIPANTWALK
} else
{
	ifai AIPANTATTACK { ifactioncount 5 { cstat 514 setvar peractor3 0 ai AIPANTRANDOM } }
	ifai AIPANTWALK { ai AIPANTRANDOM }
	ifai AIPANTRANDOM { ifrnd 1 ifcansee soundonce PHANROAM state ifnotmovingstate ifcount 390 { ai AIPANTSTAY resetcount break } } 
}
ifai AIPANTDYING ifactioncount 7 killit

getactorvar[THISACTOR].flamedamage flamedamage
ifvarg flamedamage 0 
{ 
	addvar COUNTER 1 
	ifinwater { setactorvar[THISACTOR].flamedamage 0 }
	else
	{
		eshoot NEWFIRE
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		setvarvar x2 x
		addvarvar x2 256
		randvar ang 2048
		ifrnd 128 mulvar ang -1
		rotatepoint x y x2 y ang x3 y3
		setactor[RETURN].x x3
		setactor[RETURN].y y3
		
		getactor[RETURN].z z
		addvarvar z 5120
		randvar tmp 8192
		ifrnd 128 mulvar tmp -1
		addvarvar z tmp
		setactor[RETURN].z z
	}
} 
ifinwater { setvar COUNTER 0 }
ifvarvare COUNTER flamedamage { setactorvar[THISACTOR].flamedamage 0 setvar COUNTER 0 }

getactorvar[THISACTOR].teslahitenable teslahitenable
ifvare teslahitenable 1 { getactor[THISACTOR].extra extra ifvarg extra 0 { cstat 257 ai AIPANTTESLA } else { addkills 1 ai AIPANTDYING } setactorvar[THISACTOR].teslahitenable 0 }
ifai AIPANTTESLA { cstat 514 setvar peractor3 0 randvar enemyshade 64 setactor[THISACTOR].shade enemyshade ifcount 10 { ai AIPANTWALK } }

enda

//------------------------------HELL HOUND CODE

eventloadactor HELLDOG 
setactor[THISACTOR].xrepeat 30
setactor[THISACTOR].yrepeat 30
enda

action AHELLDOGWALK  0  7  5  1  8
action AHELLDOGSTAY  0  1  5  1  8
action AHELLDOGATTACK 35 3 5 1 22
action AHELLDOGBITE 40 1 5 1 10
action AHELLDOGGUTS 50 5 1 1 20
action AHELLDOGDYING 405 7 1 1 15
action AHELLDOGDEAD 412 1 1 1 1
action AHELLDOGTESLA 2454 1 5 1 1

move HELLDOGWALK 280
move HELLDOGSTOP 

ai AIHELLDOGWALK AHELLDOGWALK HELLDOGWALK faceplayer
ai AIHELLDOGSTAY AHELLDOGSTAY HELLDOGSTOP
ai AIHELLDOGRANDOM AHELLDOGWALK HELLDOGWALK randomangle
ai AIHELLDOGBITE AHELLDOGBITE HELLDOGSTOP 
ai AIHELLDOGATTACK AHELLDOGATTACK HELLDOGSTOP faceplayer
ai AIHELLDOGDYING AHELLDOGDYING HELLDOGSTOP
ai AIHELLDOGGUTS AHELLDOGGUTS HELLDOGSTOP faceplayer
ai AIHELLDOGDEAD AHELLDOGDEAD HELLDOGSTOP
ai AIHELLDOGTESLA AHELLDOGTESLA HELLDOGSTOP

state helldoghurt
getactor[THISACTOR].extra extra
ifvarg extra 0 { spawn BLOOD soundonce CERBPAIN ai AIHELLDOGWALK } else 
{ ifwasweapon RADIUSEXPLOSION { addkills 1 cstat 128 ai AIHELLDOGGUTS } else { addkills 1 ifrnd 128 cstat 4 else cstat 0 ifrnd 85 soundonce CERBDIE1 else ifrnd 85 soundonce CERBDIE2 else soundonce CERBDIE3 ai AIHELLDOGDYING } }
ends

spriteshadow HELLDOG
spritenoshade HELLDOG
useractor notenemy HELLDOG HELLDOGSTRENGTH 
ifvare VISION 1 { setactor[THISACTOR].shade -127 } else
{
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade enemyshade
	setactor[THISACTOR].shade enemyshade
}
setactor[THISACTOR].clipdist 80
getplayer[THISACTOR].i PLAYERID	
getactorvar[PLAYERID].invisible invisible
ifp pdead setvar invisible 1
ifhitweapon { state helldoghurt }
ifai NO { addvar TOTALKILLS 1 sizeat 30 30 cstator 257 ai AIHELLDOGSTAY }
ifvarn invisible 1
{
ifai AIHELLDOGSTAY ifcansee ifp palive { state facingstate ifvare set 1 { soundonce CERBSPOT ai AIHELLDOGWALK } }
ifai AIHELLDOGWALK { ifrnd 1 ifcansee soundonce CERBSPOT ifpdistg 1536 ifpdistl 4096 ifcount 8 ai AIHELLDOGBITE else ifpdistl 1200 ai AIHELLDOGATTACK }
 
ifai AIHELLDOGBITE 
{ 
	randvar peractor 32
	randvar zvel 1024
	getactor[THISACTOR].ang saveang
	{ 
		getactor[THISACTOR].ang ang 
		ifrnd 128 
		addvarvar ang peractor else 
		{ subvarvar ang peractor ifrnd 128 mulvar zvel -1 }
		setactor[THISACTOR].ang ang 
		ezshootvar zvel HELLFLAME 
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		setvarvar x2 x
		addvar x2 256
		rotatepoint x y x2 y ang x3 y3
		setactor[RETURN].x x3
		setactor[RETURN].y y3
		setactor[THISACTOR].ang saveang 
	} 
	ifcount 26 ai AIHELLDOGWALK
} 
ifai AIHELLDOGATTACK 
{ 
	getactorvar[PLAYERID].reflective reflective
	ifactioncount 2 
	ifpdistl 1200
	ifp palive
	ifvare peractor 0 
	{ 
		ifvare reflective 1
		{
			soundonce PFLESH  
			getactor[THISACTOR].extra extra
			subvar extra 10
			setactor[THISACTOR].extra extra
			state helldoghurt
		} 
		else
		{
			soundonce PFLESH  
			getactor[THISACTOR].ang ang
			setactor[PLAYERID].htang ang
			setactor[PLAYERID].htextra 10 
			getactor[PLAYERID].htextra paextra
			state checkb_armor
			palfrom 32 0 0 0
		}
		setvar peractor 1
	}
	ifactioncount 3 { ifpdistg 1200 { ai AIHELLDOGWALK } setvar peractor 0 resetactioncount } 
}
ifai AIHELLDOGRANDOM ifcansee ifp palive { ai AIHELLDOGSTAY } 
}
else
{
ifai AIHELLDOGATTACK ifactioncount 3 {  setvar peractor 0 ai AIHELLDOGRANDOM }
ifai AIHELLDOGBITE { ai AIHELLDOGRANDOM }
ifai AIHELLDOGWALK { ai AIHELLDOGRANDOM }
ifai AIHELLDOGRANDOM { ifrnd 1 ifcansee soundonce CERBSPOT state ifnotmovingstate ifcount 390 { ai AIHELLDOGSTAY resetcount break } }
}
ifai AIHELLDOGDYING { ifactioncount 7 { ai AIHELLDOGDEAD } }
ifai AIHELLDOGGUTS ifactioncount 5 { cactor 6445 }
getactorvar[THISACTOR].teslahitenable teslahitenable
ifvare teslahitenable 1 { getactor[THISACTOR].extra extra ifvarg extra 0 { ai AIHELLDOGTESLA } else { addkills 1 ifrnd 128 cstat 4 else cstat 0 ifrnd 85 soundonce CERBDIE1 else ifrnd 85 soundonce CERBDIE2 else soundonce CERBDIE3 ai AIHELLDOGDYING } setactorvar[THISACTOR].teslahitenable 0 }
ifai AIHELLDOGTESLA { randvar enemyshade 64 setactor[THISACTOR].shade enemyshade ifcount 10 { ai AIHELLDOGWALK }  }

getactorvar[THISACTOR].flamedamage flamedamage
ifvarg flamedamage 0 
{ 
	addvar COUNTER 1 
	ifinwater { setactorvar[THISACTOR].flamedamage 0 }
	else
	{
		eshoot NEWFIRE
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		setvarvar x2 x
		addvarvar x2 256
		randvar ang 2048
		ifrnd 128 mulvar ang -1
		rotatepoint x y x2 y ang x3 y3
		setactor[RETURN].x x3
		setactor[RETURN].y y3
		
		getactor[RETURN].z z
		addvarvar z 5120
		randvar tmp 8192
		ifrnd 128 mulvar tmp -1
		addvarvar z tmp
		setactor[RETURN].z z
	}
} 
ifinwater 
ifvare peractor2 0
{ 
	setvar COUNTER 0
	addkills 1
	setactor[THISACTOR].extra 0
	state helldoghurt
	setvar peractor2 1
}
ifvarvare COUNTER flamedamage { setactorvar[THISACTOR].flamedamage 0 setvar COUNTER 0 }

getactorvar[THISACTOR].voodoohitenemy voodoohitenemy
ifvare voodoohitenemy 1 
{ 
	setactor[THISACTOR].extra 0
	state helldoghurt
	setactorvar[THISACTOR].voodoohitenemy 0
}
getactorvar[THISACTOR].burningguyactive burningguyactive
ifvare burningguyactive 1
{
    addkills 1
	setactor[THISACTOR].extra 0
	state helldoghurt
	setactorvar[THISACTOR].burningguyactive 0
}
enda

//---------------------------SPIDER CODE 

action ASPIDERWALK  0  3  5  1  6
action ASPIDERJUMP  -5 1  5  1  6
action ASPIDERWSTAYPUT  0  1  5  1 
action ASPIDERBITE 23 1 5 1 1
action ASPIDERDYING -153 4 1 1 20
action ASPIDERDEAD -150 1 1 1 1
action ASPIDERBURNING -23 4 1 1 15
action ASPIDERBURN -30 5 1 1 40
action ASPIDERBURNED -24 1 1 1 1

move SPIDERWALK 150
move SPIDERSTOP 

ai AISPIDERWALK ASPIDERWALK SPIDERWALK faceplayer
ai AISPIDERJUMP ASPIDERJUMP SPIDERWALK faceplayer
ai AISPIDERRANDOM ASPIDERWALK SPIDERWALK randomangle
ai AISPIDERWSTAYPUT ASPIDERWSTAYPUT SPIDERSTOP
ai AISPIDERSEEK ASPIDERWALK SPIDERWALK seekplayer
ai AISPIDERBITE ASPIDERBITE SPIDERSTOP faceplayer
ai AISPIDERBURNING ASPIDERBURNING SPIDERSTOP
ai AISPIDERBURNED ASPIDERBURNED SPIDERSTOP
ai AISPIDERBURN ASPIDERBURN SPIDERSTOP
ai AISPIDERDYING ASPIDERDYING SPIDERSTOP
ai AISPIDERDEAD ASPIDERDEAD SPIDERSTOP

state spiderhurt
ifwasweapon RADIUSEXPLOSION { addkills 1 state bloodsprayshit killit } else 
ifdead { addkills 1 ifrnd 128 cstat 4 else cstat 0 state bloodsprayshit ifrnd 96 { soundonce SPIDDIE1 } else ifrnd 96 { soundonce SPIDDIE2 } else { soundonce SPIDDIE3 } ai AISPIDERDYING } else { soundonce SPIDPAIN state bloodspraystate ai AISPIDERSEEK }
ends

eventloadactor SPIDER 
setactor[THISACTOR].xrepeat 20
setactor[THISACTOR].yrepeat 20
enda

spritenoshade SPIDER
spriteshadow SPIDER
useractor notenemy SPIDER fall

ifvare VISION 1 { setactor[THISACTOR].shade -127 } else
{
	getactor[THISACTOR].sectnum sectnum
	getsector[sectnum].floorshade enemyshade
	setactor[THISACTOR].shade enemyshade
}

setactor[THISACTOR].clipdist 40
getplayer[THISACTOR].i PLAYERID
getactor[THISACTOR].extra extra
ifp phigher ifpdistl 600 { addkills 1 state bloodsprayshit ifrnd 96 { soundonce SPIDDIE1 } else ifrnd 96 { soundonce SPIDDIE2 } else { soundonce SPIDDIE3 } ai AISPIDERDYING }  
ifhitweapon { state spiderhurt }

getactorvar[PLAYERID].invisible invisible
ifp pdead setvar invisible 1

ifai NO { addvar TOTALKILLS 1 ifspritepal 4 { strength GREENSPIDERSTRENGTH } else strength REDSPIDERSTRENGTH sizeat 20 20 cstator 257 ai AISPIDERWSTAYPUT }

ifvarn invisible 1 
{
	ifai AISPIDERWSTAYPUT ifcansee ifp palive { state facingstate ifvare set 1 { soundonce SPIDSPOT ai AISPIDERWALK } }
	
	ifai AISPIDERWALK 
	{
		ifp palive
		{ 
			ifrnd 1 ifcansee soundonce SPIDSPOT 
			ifpdistl 2048 ifcount 6 ai AISPIDERJUMP
			state ifnotmovingstate
			ifp phigher { ai AISPIDERSEEK } else { ifpdistl 850 ai AISPIDERBITE }
		} else ai AISPIDERRANDOM
	}
	ifai AISPIDERJUMP { ifcount 12 ai AISPIDERWALK }
	ifai AISPIDERBITE 
	{ 
		getactorvar[PLAYERID].reflective reflective
		addvar peractor 1
		ifpdistl 1200
		ifp palive ifcansee ifvare peractor 1 
		{ 
			ifspritepal 7
			{
				ifvare reflective 1
				{ 
					subvarvar extra REDSPIDERHIT
					setactor[THISACTOR].extra extra
					ifvarg extra 0 { soundonce SPIDPAIN } else { addkills 1 state bloodsprayshit ifrnd 96 { soundonce SPIDDIE1 } else ifrnd 96 { soundonce SPIDDIE2 } else { soundonce SPIDDIE3 } ai AISPIDERDYING }
				} 
				else
				{ 
					soundonce PFLESH 
					setactor[PLAYERID].htextra REDSPIDERHIT
					getactor[PLAYERID].htextra paextra
					ifrnd 64 { soundonce POWERUP randvar peractor2 150 addvar peractor2 50 setactorvar[PLAYERID].playerdrunk peractor2 }
					state checkb_armor
				}
			} 
			else
			{
				ifvare reflective 1
				{ 
					subvarvar extra GREENSPIDERHIT
					setactor[THISACTOR].extra extra
					ifvarg extra 0 { soundonce SPIDPAIN } else { addkills 1 state bloodsprayshit ifrnd 96 { soundonce SPIDDIE1 } else ifrnd 96 { soundonce SPIDDIE2 } else { soundonce SPIDDIE3 } ai AISPIDERDYING }
				} 
				else
				{ 
					soundonce PFLESH 
					setactor[PLAYERID].htextra GREENSPIDERHIT
					getactor[PLAYERID].htextra paextra
					ifrnd 64 { soundonce POWERUP randvar peractor2 150 addvar peractor2 50 setactorvar[PLAYERID].playerdrunk peractor2 }
					state checkb_armor
				}
			}
		}
		ifvare peractor 26 { ai AISPIDERWALK setvar peractor 0 }
	} 
	ifai AISPIDERSEEK { ifrnd 1 ifcansee soundonce SPIDSPOT state ifnotmovingstate ifcansee { ifp phigher nullop else ai AISPIDERWALK } }
	ifai AISPIDERRANDOM ifp palive ifcansee { soundonce SPIDSPOT ai AISPIDERWSTAYPUT }
}
else
{ 
	ifai AISPIDERWALK { ai AISPIDERRANDOM }
	ifai AISPIDERBITE { ai AISPIDERRANDOM }
	ifai AISPIDERSEEK { ai AISPIDERRANDOM }
	ifai AISPIDERRANDOM { state ifnotmovingstate ifcount 390 { ai AISPIDERWSTAYPUT resetcount break } }
}
ifai AISPIDERBURNING { strength 0 addkills 1 cstat 0 sizeat 20 20 ifactioncount 12 { ai AISPIDERBURN } }
ifai AISPIDERBURN { cstat 128 ifactioncount 4 ai AISPIDERBURNED }
ifai AISPIDERDYING { spritepal 0 cstat 128 sizeat 20 20 ifactioncount 4 { cstat 0 ai AISPIDERDEAD } }

getactorvar[THISACTOR].flamedamage flamedamage
ifvarg flamedamage 0 ifvare peractor 0 { ai AISPIDERBURNING setvar peractor 1 } 

enda





















//------------------------------CULTIST CODE

actor HERETICSTOPED1 
sizeat 24 24
{ addvar TOTALKILLS 1 espawn HERETIC setactorvar[RETURN].settotalkill 1 setactor[RETURN].pal 3 killit }
enda

actor HERETICSTOPED2 
sizeat 24 24
{ addvar TOTALKILLS 1 espawn HERETIC setactorvar[RETURN].settotalkill 1 killit }
enda

action AHERETICWALK  0 4 5 1 15
action AHERETICSTAYPUT  0 1 5 1 1
action AHERETICSHOOTGUN -35 2 5 -1 28
action AHERETICTOMMYSHOOT -35 2 5 -1 7
action AHERETICSHOOTGUNDUCK 535 2 5 1 28
action AHERETICTOMMYSHOOTDUCK 535 2 5 1 7
action AHERETICGRENADE -30 5 5 1 15
action AHERETICSWIM 381 4 5 1 20
action AHERETICTESLA  813 1 5 1 1
action AHERETICDYING 70 7 1 1 15
action AHERETICDEAD 77 1 1 1 10
action AHERETICGUTS 88 6 1 1 10
action AHERETICDEAD2 94 1 1 1 10
action AHERETICDUCK 515 3 5 1 22

move HERETICWALK 90
move HERETICSWIMUP 70 -70
move HERETICSWIMDOWN 70 40
move HERETICDUCK 80
move HERETICSTOP 

ai AIHERETICWALK AHERETICWALK HERETICWALK randomangle
ai AIHERETICSWIM AHERETICSWIM HERETICSWIMUP randomangle
ai AIHERETICSTEPLEFT AHERETICWALK HERETICWALK faceplayer
ai AIHERETICSTEPRIGHT AHERETICWALK HERETICWALK faceplayer
ai AIHERETICDUCKLEFT AHERETICDUCK HERETICDUCK faceplayer
ai AIHERETICDUCKRIGHT AHERETICDUCK HERETICDUCK faceplayer
ai AIHERETICRANDOMSTEP AHERETICWALK HERETICWALK randomangle 

ai AIHERETICSTAYPUT AHERETICSTAYPUT HERETICSTOP
ai AIHERETICSHOOTGUN AHERETICSHOOTGUN HERETICSTOP faceplayer  
ai AIHERETICTOMMYSHOOT AHERETICTOMMYSHOOT HERETICSTOP faceplayer  
ai AIHERETICGRENADE AHERETICGRENADE HERETICSTOP faceplayer 
ai AIHERETICSHOOTGUNDUCK AHERETICSHOOTGUNDUCK HERETICSTOP faceplayer
ai AIHERETICTOMMYSHOOTDUCK AHERETICTOMMYSHOOTDUCK HERETICSTOP faceplayer
ai AIHERETICDYING AHERETICDYING HERETICSTOP 
ai AIHERETICDEAD AHERETICDEAD HERETICSTOP 
ai AIHERETICTESLA AHERETICTESLA HERETICSTOP 
ai AIHERETICGUTS AHERETICGUTS HERETICSTOP faceplayer
ai AIHERETICDEAD2 AHERETICDEAD2 HERETICSTOP 

state heretichurt
getactor[THISACTOR].extra extra
ifwasweapon RADIUSEXPLOSION 
{ 
	addkills 1 state bloodsprayshit ifrnd 64 { soundonce CULTDIE1 } 
	else ifrnd 64 { soundonce CULTDIE2 } else { soundonce CULTDIE3 } ai AIHERETICGUTS 
} 
else  
ifvarg extra 0 
{ 
setvar peractor 0 ifrnd 128 { soundonce CULTPAN1 } else { soundonce CULTPAN2 }
state bloodspraystate state bloodspraystate ifrnd 128 ai AIHERETICDUCKLEFT else ai AIHERETICDUCKRIGHT 
} else
{ 
	addkills 1 ifrnd 128 cstat 4 else cstat 0 state bloodsprayshit ifrnd 64 { soundonce CULTDIE1 } 
	else ifrnd 64 { soundonce CULTDIE2 } else { soundonce CULTDIE3 } ai AIHERETICDYING 
} 
ends

state hereticshootgun
getactorvar[PLAYERID].reflective reflective
ifvare reflective 1 
{
	state bloodspraystate 
	ifrnd 128 { soundonce CULTPAN1 } else { soundonce CULTPAN2 }
	getactor[THISACTOR].extra extra
	ifvarg extra 0 
	{ 
		subvar extra 11 
		setactor[THISACTOR].extra extra 
	} else 
	{ 
		ifrnd 128 { soundonce CULTATT1 } else { soundonce CULTATT2 } 
		addkills 1 
		state bloodsprayshit 
		ifrnd 64 { soundonce CULTDIE1 } else 
		ifrnd 64 { soundonce CULTDIE2 } else { soundonce CULTDIE3 } 
		ai AIHERETICDYING 
	}
} 
else 
{
	shoot SHOTSPARK1 
	shoot SHOTSPARK1 
	shoot SHOTSPARK1 
	shoot SHOTSPARK1 
	shoot SHOTSPARK1 
}			
ifrnd 128 { soundonce CULTATT1 } else 
{ soundonce CULTATT2 }
ends

state heretictommyshoot
getactorvar[PLAYERID].reflective reflective
ifvare reflective 1 
{
	state bloodspraystate 
	ifrnd 128 { soundonce CULTPAN1 } else { soundonce CULTPAN2 }
	getactor[THISACTOR].extra extra
	ifvarg extra 0 
	{ 
		subvar extra 11 
		setactor[THISACTOR].extra extra 
	} else 
	{ 
		soundonce TOM
		addkills 1 
		state bloodsprayshit 
		ifrnd 64 { soundonce CULTDIE1 } else 
		ifrnd 64 { soundonce CULTDIE2 } else { soundonce CULTDIE3 } 
		ai AIHERETICDYING 
	}
} 
else 
{
	shoot TOMMYFIRST  
}			
soundonce TOM
ends

state hereticteslashoot
eshoot PLASMAPROJ  			
soundonce TESLAZ1
ends

useractor enemy HERETIC fall
setactor[THISACTOR].clipdist 80
ifvare VISION 1 { setactor[THISACTOR].shade -127 }

getplayer[THISACTOR].i PLAYERID	
getactorvar[THISACTOR].settotalkill settotalkill
ifai NO { ifvarn settotalkill 1 { addvar TOTALKILLS 1 } strength HERETICSTRENGTH sizeat 24 24 cstator 257 ai AIHERETICSTAYPUT }

getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[PLAYERID].x px
getactor[PLAYERID].y py
subvarvar px x
subvarvar py y
getangle ang px py
setvarvar esaveang ang

getactor[THISACTOR].x x
getactor[THISACTOR].y y
getplayer[THISACTOR].posz z

getactor[THISACTOR].sectnum sectorid
cos mycos ang
sin mysin ang
hitscan x y z sectorid mycos mysin 0 RETURN RETURN spriteid RETURN RETURN RETURN 4294901808

ifhitweapon { state heretichurt }

getactorvar[PLAYERID].invisible invisible
ifp pdead setvar invisible 1
ifvarn invisible 1
{
	ifai AIHERETICSTAYPUT ifcansee ifp palive 
	{ 
		state facingstate
		ifvare set 1 
		{
		ifrnd 48 { soundonce CULTROM1 } else ifrnd 48 { soundonce CULTROM2 } else 
		ifrnd 48 { soundonce CULTROM3 } else ifrnd 48 { soundonce CULTROM4 } else 
		{ soundonce CULTROM5 } 		
		ai AIHERETICWALK 
		}
	}
	
	ifai AIHERETICSHOOTGUN
	{
	ifspritepal 0
	{	
		addvar peractor3 1
		ifvarg peractor3 15 { setvar peractor3 0 }
		
		{		
			ifvarn spriteid -1
			ifcansee 
			{	
				ifvarvarn spriteid PLAYERID 
				{ 
					ifvare peractor 0 
					{ 
						ifrnd 128 ai AIHERETICSTEPLEFT else ai AIHERETICSTEPRIGHT
						setvar peractor 1 
					}
				} else setvar peractor 0
			} else ai AIHERETICWALK	
		}
		
		ifp palive 
		{ 
			randvar tmp 512
			ifvare peractor3 5
			{ 	
				state hereticshootgun
			} else ifvare tmp 1 ifpdistl 7168 { ai AIHERETICGRENADE }
		}
	} else ai AIHERETICTOMMYSHOOT
	}
	ifai AIHERETICTOMMYSHOOT
	{
		addvar peractor3 1
		ifvarg peractor3 2 { setvar peractor3 0 }
		
		{		
			ifvarn spriteid -1
			ifcansee 
			{	
				ifvarvarn spriteid PLAYERID 
				{ 
					ifvare peractor 0 
					{ 
						ifrnd 128 ai AIHERETICSTEPLEFT else ai AIHERETICSTEPRIGHT
						setvar peractor 1 
					}
				} else setvar peractor 0
			} else ai AIHERETICWALK	
		}
		
		ifp palive 
		{ 
			randvar tmp 512
			ifvare peractor3 1
			{ 	
			  ifspritepal 3 state heretictommyshoot else ifspritepal 11 state hereticteslashoot
			} else ifvare tmp 1 ifpdistl 7168 { ai AIHERETICGRENADE }
		} else ai AIHERETICWALK	
	}
	ifai AIHERETICSHOOTGUNDUCK
	{
		ifinwater
		{
			ifmove HERETICSWIMUP { ifp phigher nullop else { move HERETICSWIMDOWN faceplayer }  }
			else ifp phigher { move HERETICSWIMUP faceplayer }
		}
		
	ifspritepal 0
	{
		addvar peractor3 1
		ifvarg peractor3 15 { setvar peractor3 0 }
		
		ifvarn spriteid -1
		ifcansee 
		{	
			ifvarvarn spriteid PLAYERID 
			{ 
				ifvare peractor 0 
				{ 
					ifrnd 128 ai AIHERETICDUCKLEFT else ai AIHERETICDUCKRIGHT
					setvar peractor 1 
				}
			} else setvar peractor 0
		} else ai AIHERETICWALK
		
		ifp palive 
		{ 
			ifvare peractor3 5
			{ state hereticshootgun }
		}
	} else ai AIHERETICTOMMYSHOOTDUCK
	}
	ifai AIHERETICTOMMYSHOOTDUCK
	{
		ifinwater
		{
			ifmove HERETICSWIMUP { ifp phigher nullop else { move HERETICSWIMDOWN faceplayer }  }
			else ifp phigher { move HERETICSWIMUP faceplayer }
		}
		addvar peractor3 1
		ifvarg peractor3 2 { setvar peractor3 0 }
		
		ifvarn spriteid -1
		ifcansee 
		{	
			ifvarvarn spriteid PLAYERID 
			{ 
				ifvare peractor 0 
				{ 
					ifrnd 128 ai AIHERETICDUCKLEFT else ai AIHERETICDUCKRIGHT
					setvar peractor 1 
				}
			} else setvar peractor 0
		} else ai AIHERETICWALK
		
		ifp palive 
		{ 
			ifvare peractor3 1
			{ 	
				ifspritepal 3 state heretictommyshoot else ifspritepal 11 state hereticteslashoot
			}
		}
	}
	ifai AIHERETICSTEPLEFT
	{	
		setvar peractor3 0
		addvar esaveang 512
		setactor[THISACTOR].ang esaveang
		ifnotmoving { setvar peractor 0 ai AIHERETICRANDOMSTEP }
		ifp palive { ifvarvare spriteid PLAYERID { setvar peractor 0 ai AIHERETICSHOOTGUN } }
	}
	ifai AIHERETICSTEPRIGHT
	{
		setvar peractor3 0
		subvar esaveang 512
		setactor[THISACTOR].ang esaveang
		ifnotmoving { setvar peractor 0 ai AIHERETICRANDOMSTEP }
		ifp palive { ifvarvare spriteid PLAYERID  { setvar peractor 0 ai AIHERETICSHOOTGUN } } 
	}
	ifai AIHERETICRANDOMSTEP ifcansee { setvar peractor3 0 ifp palive { ifcount 15 ifpdistl 16384 ifp palive ai AIHERETICSHOOTGUN } }
	ifai AIHERETICDUCKLEFT 
	{  
		setvar peractor3 0
		addvar esaveang 512
		setactor[THISACTOR].ang esaveang
		ifp palive { ifvarvare spriteid PLAYERID ifcount 15 { ifinwater ifcount 10 { ai AIHERETICSWIM } else { ifrnd 128 ai AIHERETICSHOOTGUN else ai AIHERETICSHOOTGUNDUCK }  } }
	}
	ifai AIHERETICDUCKRIGHT
	{  
		setvar peractor3 0
		subvar esaveang 512
		setactor[THISACTOR].ang esaveang
		ifp palive { ifvarvare spriteid PLAYERID ifcount 15 { ifinwater ifcount 10 { ai AIHERETICSWIM } else { ifrnd 128 ai AIHERETICSHOOTGUN else ai AIHERETICSHOOTGUNDUCK }  } }
	}

	ifai AIHERETICWALK 
	{ 
		setvar peractor3 0
		randvar tmp 512
		ifcansee
		{
		ifvare tmp 1 { soundonce CULTGLO1 } else ifvare tmp 2 { soundonce CULTGLO2 } else 
		ifvare tmp 3 { soundonce CULTGLO3 } else ifvare tmp 4 { soundonce CULTGLO4 } 
		}
		state ifnotmovingstate
		ifp palive { ifcansee ifvarvare spriteid PLAYERID ai AIHERETICSHOOTGUN }
		ifinwater ai AIHERETICDUCKLEFT
	}
	ifai AIHERETICSWIM
	{			
		setvar peractor3 0
		
		ifmove HERETICSWIMUP { ifp phigher nullop else { move HERETICSWIMDOWN faceplayer }  }
		else ifp phigher { move HERETICSWIMUP faceplayer }
		
		state ifnotmovingstate
		ifp palive { ifcansee ifvarvare spriteid PLAYERID ifcount 15 ai AIHERETICSHOOTGUNDUCK }
	}
	ifai AIHERETICGRENADE 
	{
		ifpdistg 4092 ifpdistl 7168 setvar zvel -4256 else { ifpdistl 4092 { setvar zvel -2048 } else setvar zvel -4512 }
		ifpdistg 2048 { ifactioncount 5 { soundonce CULTTOSS ezshootvar zvel ENEMYTNTBUNDLE ai AIHERETICSHOOTGUN } } else ai AIHERETICSHOOTGUN
	}
} 
else
{
	ifai AIHERETICSHOOTGUN { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICSHOOTGUNDUCK { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICTOMMYSHOOTDUCK { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICTOMMYSHOOT { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICSTEPLEFT { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICSTEPRIGHT { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICDUCKLEFT { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICDUCKRIGHT { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICWALK { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICRANDOMSTEP { ifinwater { ai AIHERETICSWIM } state ifnotmovingstate ifcount 390 { ai AIHERETICSTAYPUT resetcount break } } 
	ifai AIHERETICSWIM { state ifnotmovingstate /*ifceilingdistl 10 { move HERETICSWIMDOWN }*/ ifcount 390 { ai AIHERETICSTAYPUT resetcount break } }
}
	getactorvar[THISACTOR].flamedamage peractor
	ifvarg peractor 0 { addvar COUNTER 1 state newfirestate } 
	ifinwater { setvar COUNTER 0 }
	ifvarvare COUNTER peractor { setactorvar[THISACTOR].flamedamage 0 setvar COUNTER 0 }
	
getactorvar[THISACTOR].burningguyactive tmp
ifvare tmp 1 
{ 
	espawn BURNINGGUY 
	setactor[RETURN].xrepeat 22
	setactor[RETURN].yrepeat 22
	setactorvar[RETURN].bguy_id 2
	addkills 1 
	setactorvar[THISACTOR].burningguyactive 0 
	killit 
}

getactorvar[THISACTOR].voodoohitenemy voodoohitenemy
ifvare voodoohitenemy 1 
{ 
	setactor[THISACTOR].extra 0
	state heretichurt
	setactorvar[THISACTOR].voodoohitenemy 0
}

getactorvar[THISACTOR].teslahitenable teslahitenable
ifvare teslahitenable 1 { getactor[THISACTOR].extra extra ifvarg extra 0 { ai AIHERETICTESLA } else { addkills 1 ifrnd 128 cstat 4 else cstat 0 ai AIHERETICDYING } setactorvar[THISACTOR].teslahitenable 0 }
ifai AIHERETICTESLA { randvar enemyshade 64 setactor[THISACTOR].shade enemyshade ifcount 10 { ai AIHERETICRANDOMSTEP }  }

ifai AIHERETICDYING { setactorvar[THISACTOR].flamedamage 0 ifactioncount 7 { ai AIHERETICDEAD } }
ifai AIHERETICGUTS { cstat 0 setactorvar[THISACTOR].flamedamage 0 ifactioncount 6 { ai AIHERETICDEAD2 } }
enda














//---------------------------INNOCENT CODE 

actor CIVILIANSTOPED 
sizeat 24 24
ifcansee { spawn CIVILIAN killit }
enda

action ACIVILIANSTAND 44 2 5 1 40
action ACIVILIANWALK 0 4 5 1 12
action ACIVILIANDYING 30 8 1 1 12
action ACIVILIANDEAD 38 1 1 1 12

move CIVILIANWALK 180
move CIVILIANSTOP 0

ai AICIVILIANWALKING ACIVILIANWALK CIVILIANWALK randomangle
ai AICIVILIANSTOP ACIVILIANSTAND CIVILIANSTOP
ai AICIVILIANDYING ACIVILIANDYING CIVILIANSTOP
ai AICIVILIANDEAD ACIVILIANDEAD CIVILIANSTOP

state civilianhurt
ifwasweapon RPG { addkills 1 spawn BURNINGGUY killit } else ifwasweapon RADIUSEXPLOSION { addkills 1 spawn BURNINGGUY killit }
else ifdead { addkills 1 guts JIBS6 10 soundonce ISCREAM2 ai AICIVILIANDYING } else { spawn BLOOD soundonce DUKE_LONGTERM_PAIN5 guts JIBS6 3 ai AICIVILIANWALKING break }
ends

actor CIVILIAN TOUGH state enemyeffects
fall 
ifaction 0 ifcansee { sizeat 24 24 cstat 257 ai AICIVILIANWALKING }
ifhitweapon { state civilianhurt break }
ifai AICIVILIANWALKING { ifrnd 1 { ai AICIVILIANSTOP break } }
ifai AICIVILIANSTOP { ifrnd 128 { ifcount 50 { ai AICIVILIANWALKING resetcount break } }
else { ifcount 150 { ai AICIVILIANWALKING resetcount break } } }
ifai AICIVILIANDYING { cstat 0 ifactioncount 8 { soundonce THUD ai AICIVILIANDEAD } }
enda

