
// Monsters codes

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

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

useractor notenemy FATRAT fall 
ifvare VISION 1
{ setactor[THISACTOR].shade -127 }
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 }

getactorvar[PLAYERID].invisible tmp2
ifvarn tmp2 1 
{
	ifai NO ifcansee { strength 8 sizeat 20 20 cstator 257 ai AIFATRATWALK sound RATSPOT }
	
	ifai AIFATRATWALK 
	{
		ifp palive
		{ 
			ifrnd 1 soundonce RATSPOT 
			state ifnotmovingstate
			ifp phigher { ai AIFATRATSEEK } else { ifpdistl 850 ai AIFATRATBITE }
		} else ai AIFATRATRANDOM
	}
	ifai AIFATRATBITE 
	{ 
		addvar peractor2 1
		ifvarg peractor2 26 { setvar peractor2 0 }
				
		getactorvar[PLAYERID].reflective tmp
		ifp pdead { ai AIFATRATSEEK } else	
		{
			ifpdistl 850 ifcansee ifvare peractor2 1
			{
				ifvare tmp 1
				{ 
					subvar extra 2
					setactor[THISACTOR].extra extra
					ifvarg extra 0 { sound 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 2
					getactor[PLAYERID].htextra paextra
					state checkb_armor
					palfrom 32 1 1 1 
				}
			} else ai AIFATRATWALK 
		}
	} 
	ifai AIFATRATSEEK { ifrnd 1 soundonce RATSPOT state ifnotmovingstate ifcansee { ifp phigher nullop else ai AIFATRATWALK } }
	ifai AIFATRATRANDOM ifp palive ifcansee { sound RATSPOT ai AIFATRATSEEK }
	ifai AIFATRATWSTAYPUT ifp palive ifcansee { sound RATSPOT ai AIFATRATSEEK }
}
else
{ 
	ifai NO { strength 8 sizeat 20 20 cstator 257 ai AIFATRATRANDOM }
	ifai AIFATRATSEEK { ai AIFATRATRANDOM }
}
ifai AIFATRATRANDOM { state ifnotmovingstate ifrnd 4 { randvar ang 2048 setactor[THISACTOR].ang ang } ifcount 390 { ai AIFATRATWSTAYPUT resetcount break } }
getactorvar[THISACTOR].flamedamage tmp
ifvarg tmp 0 ifvare peractor 0 { ai AIFATRATBURNING setvar peractor 1 }
ifai AIFATRATBURNING { strength 0 addkills 1 cstat 0 sizeat 20 20 ifactioncount 12 { 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

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 }
ifhitweapon { state handhurt }

getactorvar[PLAYERID].invisible perplayer
ifvare perplayer 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 ifcanseetarget { strength 10 sizeat 30 30 cstator 257 ai AIHANDSEEK }
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 
		{
			ifrnd 1 soundonce HANDROAM else ifrnd 1 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 { ifrnd 1 soundonce HANDROAM ifnotmoving { getactor[THISACTOR].ang ang randvar mang 1024 addvarvar ang mang setactor[THISACTOR].ang ang } randvar peractor 64 ifvare perplayer 0 { ifvare peractor 64 { setactorvar[THISACTOR].handshock 0 } } else ifcount 130 { ai AIHANDSTOP setvar peractor 0 } }
}
ifp phigher ifpdistl 600 ifvarg extra 0 { ai AIHANDDYING }
ifai AIHANDSTOP ifcansee ifp palive ifvare perplayer 0 ai AIHANDSEEK 
getactorvar[THISACTOR].flamedamage tmp
ifvarg tmp 0 ifvare peractor3 0 { ai AIHANDBURNING setvar peractor3 1 }
ifai AIHANDBURNING { strength 0 addkills 1 cstat 128 ifrnd 128 soundonce HANDDIE1 else soundonce HANDDIE2 sizeat 40 40 ifactioncount 6 { ai AIHANDBURNED } }
ifai AIHANDDYING { strength 0 addkills 1 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 enemy ZOMBIERISE 0 AZR1 fall

getplayer[THISACTOR].i PLAYERID
ifai NO ifcansee { cstat 384 sizeat 24 24 ai AIZR1 }
getactorvar[PLAYERID].invisible perplayer
ifai AIZR1 ifcansee ifvare perplayer 0 ifpdistl 4096 { sizeat 24 24 cstator 257 soundonce AZOMROAM ai AIZR2 }
getactorvar[THISACTOR].flamedamage tmp
ifvarg tmp 0 ifvare peractor 0 { sizeat 24 24 cstat 256 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 { spawn ZOMBIE 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 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 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 sound 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

useractor notenemy ZOMBIE fall 
state enemyeffects
getactor[THISACTOR].extra extra
getactor[THISACTOR].htextra htextra
getplayer[THISACTOR].i PLAYERID

getactor[PLAYERID].x mx
getactor[PLAYERID].y my
getactor[PLAYERID].z mz
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z
  
getactorvar[PLAYERID].invisible tmp2
ifvarn tmp2 1
{
	ifhitweapon { state checkzombiehitstate }
	ifai NO ifcansee { strength 40 sizeat 24 24 cstat 257 ai AIZOMBIEWALK }
	ifai AIZOMBIEWALK { ifcansee ifp palive { ifpdistl 1300 ai AIZOMBIESHOOT } else ai AIZOMBIERANDOM state ifnotmovingstate ifrnd 2 soundonce AZOMROAM else ifrnd 1 soundonce AZOMSPOT else ifrnd 2 soundonce AZOMMOAN } 

	ifai AIZOMBIESHOOT 
	{ 
		addvar peractor3 1
		ifvarg peractor3 27 { setvar peractor3 0 }
		
		getactorvar[PLAYERID].reflective tmp
		
			ifpdistl 1300
			ifp palive
			{
				ifvare peractor3 18 
				{ 
					ifvare tmp 1
					{
						sound AZOMSWIP 
						setvar peractor3 0
						state bloodspraystate 
						subvar extra 10
						setactor[THISACTOR].extra extra
						ifvarg extra 0 { sound 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
					{
						sound AZOMSWIP 
						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 18 { sound AZOMSWIP } ifvare peractor3 27 { ai AIZOMBIEWALK } }
	} 
	
	ifai AIZOMBIESTAYPUT ifp palive ifcansee { soundonce AZOMROAM ai AIZOMBIERANDOM }
	ifai AIZOMBIERANDOM ifp palive ifcansee { soundonce AZOMROAM ai AIZOMBIEWALK }
} 
else
{
	ifhitweapon { state checkzombiehitstate }
	ifai NO { strength 40 sizeat 24 24 cstat 257 ai AIZOMBIESTAYPUT }
	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 256 ifactioncount 6 ai AIZOMBIEDEAD }
ifai AIZOMBIEFALLING { cstat 0 ifactioncount 4 ai AIZOMBIEDEAD2 }
ifai AIZOMBIEDEAD2 { ifvarg extra 0 { cstat 0 ifcount 45 ai AIZOMBIEGETUP } else cstat 256 }
ifai AIZOMBIEGUTS { cstat 128 ifactioncount 6 { cstat 128 ai AIZOMBIEGUTS2 } }

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 -24000
setactor[THISACTOR].x x
setactor[THISACTOR].y y
setactor[THISACTOR].z z
ifcount 100 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

state burningguyhurt
ifwasweapon RPG { spawn BURNING2 ai AIBURNINGGUYDYING } else ifwasweapon RADIUSEXPLOSION { spawn BURNING2 ai AIBURNINGGUYDYING }
else { spawn BURNING spawn SMALLSMOKE strength WEAK }
ends

spritenoshade BURNINGGUY
useractor notenemy BURNINGGUY fall
getactorvar[THISACTOR].bguy_id peractor2
ifhitweapon { state burningguyhurt }
ifai NO { cstator 257 ai AIBURNINGGUYWALK ifvare peractor2 2 { ifrnd 85 { soundonce CULTFIR1 } else ifrnd 85 { soundonce CULTFIR2 } else soundonce CULTFIR3 } else soundonce AZOMPAIN }
ifai AIBURNINGGUYWALK 
{ 
	ifpdistl 800 ifactioncount 2 { addphealth -5 palfrom 32 32 resetactioncount } else 
	ifcount 26 
	{ 
		ifvare peractor2 1 { soundonce AZOMDIE1 } 
		ifvare peractor2 2 { ifrnd 85 { soundonce CULTFIR1 } else ifrnd 85 { soundonce CULTFIR2 } else soundonce CULTFIR3 } 
		ai AIBURNINGGUYDYING state bloodspraystate 
	} 
} 
ifai AIBURNINGGUYDYING 
{ 
	ifactioncount 3 
	{ 
		ifvare peractor2 1 { spawn ZBURNED }
		spawn BURNINGGUYDEAD 
		killit 
	} 
}
enda


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

actor HERETICSTOPED1 
sizeat 24 24
ifcansee { spawn HERETIC killit }
enda

actor HERETICSTOPED2 
sizeat 24 24
ifcansee { spawn HERETIC killit }
enda

action AHERETICWALK  0 4 5 1 15
action AHERETICSTAYPUT  0 1 5 1 1
action AHERETICSHOOT -35 2 5 -1 28
action AHERETICSHOOTDUCK 535 2 5 1 28
action AHERETICGRENADE -30 5 5 1 15
action AHERETICSWIM 381 4 5 1 20
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 HERETICDUCK 80
move HERETICSTOP 

ai AIHERETICWALK AHERETICWALK HERETICWALK 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 AIHERETICSHOOT AHERETICSHOOT HERETICSTOP faceplayer  
ai AIHERETICGRENADE AHERETICGRENADE HERETICSTOP faceplayer 
ai AIHERETICSHOOTDUCK AHERETICSHOOTDUCK HERETICSTOP faceplayer
ai AIHERETICDYING AHERETICDYING HERETICSTOP 
ai AIHERETICDEAD AHERETICDEAD HERETICSTOP 
ai AIHERETICGUTS AHERETICGUTS HERETICSTOP faceplayer
ai AIHERETICDEAD2 AHERETICDEAD2 HERETICSTOP 

useractor notenemy HERETIC fall

getplayer[THISACTOR].i PLAYERID	
state enemyeffects
ifai NO 
{ 
	strength 80 sizeat 24 24 cstator 257 
	ifrnd 48 { soundonce CULTROM1 } else ifrnd 48 { soundonce CULTROM2 } else 
	ifrnd 48 { soundonce CULTROM3 } else ifrnd 48 { soundonce CULTROM4 } else 
	{ soundonce CULTROM5 } ai AIHERETICWALK
}

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

ifhitweapon 
{  
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 ifvarl extra 0 { addkills 1 state bloodsprayshit ifrnd 64 { soundonce CULTDIE1 } 
else ifrnd 64 { soundonce CULTDIE2 } else { soundonce CULTDIE3 } ai AIHERETICDYING } 
else { setvar peractor 0 ifrnd 128 { sound CULTPAN1 } else { sound CULTPAN2 }
state bloodspraystate state bloodspraystate ifrnd 128 ai AIHERETICDUCKLEFT else ai AIHERETICDUCKRIGHT }
}

getactorvar[PLAYERID].invisible tmp2
ifvarn tmp2 1
{
	ifai AIHERETICSHOOT
	{	
		addvar peractor3 1
		ifvarg peractor3 15 { setvar peractor3 0 }
		
		ifp pjumping nullop else ifp pfalling nullop else
		{		
			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 15
			{ 	
				getactorvar[PLAYERID].reflective tmp
				ifvare tmp 1 
				{
					state bloodspraystate 
					ifrnd 128 { sound CULTPAN1 } else { sound CULTPAN2 }
					getactor[THISACTOR].extra extra
					ifvarg extra 0 { subvar extra 11 setactor[THISACTOR].extra extra } else { ifrnd 128 { sound CULTATT1 } else { sound 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 { sound CULTATT1 } else 
				{ sound CULTATT2 } 
			} else ifvare tmp 1 ifpdistl 7168 { ai AIHERETICGRENADE }
		} else ai AIHERETICSTAYPUT
	}
	ifai AIHERETICSHOOTDUCK
	{
		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 15 
			{ 	
				getactorvar[PLAYERID].reflective tmp
				ifvare tmp 1 
				{
					state bloodspraystate 
					ifrnd 128 { sound CULTPAN1 } else { sound CULTPAN2 }
					getactor[THISACTOR].extra extra
					ifvarg extra 0 { subvar extra 11 setactor[THISACTOR].extra extra } else { ifrnd 128 { sound CULTATT1 } else { sound 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 { sound CULTATT1 } else 
				{ sound CULTATT2 }
			}
		} else ai AIHERETICSTAYPUT
	}
	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 AIHERETICSHOOT } } else ai AIHERETICSTAYPUT
	}
	ifai AIHERETICSTEPRIGHT
	{
		setvar peractor3 0
		subvar esaveang 512
		setactor[THISACTOR].ang esaveang
		ifnotmoving { setvar peractor 0 ai AIHERETICRANDOMSTEP }
		ifp palive { ifvarvare spriteid PLAYERID  { ai AIHERETICSHOOT } } else ai AIHERETICSTAYPUT
	}
	ifai AIHERETICRANDOMSTEP ifcansee { setvar peractor3 0 ifp palive { ifcount 15 ifpdistl 16384 ifp palive ai AIHERETICSHOOT } else ai AIHERETICSTAYPUT }
	ifai AIHERETICDUCKLEFT 
	{  
		setvar peractor3 0
		addvar esaveang 512
		setactor[THISACTOR].ang esaveang
		ifp palive { ifvarvare spriteid PLAYERID ifcount 15 { ifrnd 128 ai AIHERETICSHOOT else ai AIHERETICSHOOTDUCK } } else ai AIHERETICSTAYPUT
	}
	ifai AIHERETICDUCKRIGHT
	{  
		setvar peractor3 0
		subvar esaveang 512
		setactor[THISACTOR].ang esaveang
		ifp palive { ifvarvare spriteid PLAYERID ifcount 15 { ifrnd 128 ai AIHERETICSHOOT else ai AIHERETICSHOOTDUCK } } else ai AIHERETICSTAYPUT
	}

	ifai AIHERETICWALK 
	{ 
		setvar peractor3 0
		randvar tmp 512
		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 AIHERETICSHOOT } else ai AIHERETICSTAYPUT
	}
	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 AIHERETICSHOOT } } else ai AIHERETICSHOOT
	}
} 
else
{
	ifai NO { strength 40 sizeat 24 24 cstat 257 ai AIHERETICSTAYPUT }
	ifai AIHERETICSHOOT { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICSHOOTDUCK { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICSTEPLEFT { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICSTEPRIGHT { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICDUCKLEFT { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICDUCKRIGHT { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICWALK { ai AIHERETICRANDOMSTEP }
	ifai AIHERETICRANDOMSTEP { state ifnotmovingstate ifrnd 4 { randvar ang 2048 setactor[THISACTOR].ang ang } ifcount 390 { ai AIHERETICSTAYPUT resetcount break } } 
}
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 
}
ifai AIHERETICSTAYPUT 
{ 
	getactorvar[PLAYERID].invisible tmp2
	setvar peractor3 0 
	ifp palive ifcansee ifvarn tmp2 1 ai AIHERETICWALK  
}
ifai AIHERETICDYING { cstat 256 ifactioncount 7 { sound THUD ai AIHERETICDEAD } }
ifai AIHERETICGUTS { cstat 0 ifactioncount 6 { ai AIHERETICDEAD2 } }
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

move FISHWALK 130
move FISHSTOP 

ai AIFISHWALK AFISHWALK FISHWALK faceplayer
ai AIFISHBITE AFISHBITE FISHSTOP faceplayer 
ai AIFISHRANDOM AFISHWALK FISHWALK randomangle 
ai AIFISHSTAY AFISHWALK 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

useractor notenemy FISH state enemyeffects
getplayer[THISACTOR].i PLAYERID
ifhitweapon { state fishhurt }
getactorvar[PLAYERID].invisible tmp2
ifvarn tmp2 1
{
ifai NO ifcansee { strength 40 sizeat 25 25 cstator 257 ai AIFISHWALK soundonce EELSPOT }
ifai AIFISHWALK { ifpdistl 1000 ai AIFISHBITE ifrnd 1 soundonce EELROAM } 
ifai AIFISHBITE 
{ 
	ifpdistl 1000 ifcansee 
	{ 
		ifactioncount 3 
		{ 
			getactorvar[PLAYERID].reflective tmp
			ifvare tmp 1 
			{
				state bloodspraystate 
				sound 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 
			{
				sound PFLESH 
				addphealth -12 
				palfrom 32 32 
			}
			resetactioncount 
			
		} 
	} 
		else ai AIFISHWALK 
} 
ifai AIFISHSTAY ifp palive ifcansee { ai AIFISHWALK }
ifai AIFISHRANDOM ifp palive ifcansee { ai AIFISHWALK } 
} else
{
ifai NO ifcansee { strength TOUGH sizeat 25 25 cstator 257 ai AIFISHSTAY }
ifai AIFISHWALK { ai AIFISHRANDOM } 
ifai AIFISHRANDOM { ifrnd 1 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

useractor notenemy BATSLEEP WEAK sizeat 35 35
ifvare VISION 1
{ setactor[THISACTOR].shade -127 }
getplayer[THISACTOR].i PLAYERID
getactorvar[PLAYERID].invisible tmp2
ifvarn tmp2 1 
{
ifaction NO ifcansee ifpdistl 8192 ifcount 16 { soundonce BATSPOT spawn BAT killit } }
ifhitweapon 
{ 
	action BATSLEEPDYING
	ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3 
}
ifaction BATSLEEPDYING { fall ifactioncount 4 { addkills 1 killit } }
getactorvar[THISACTOR].flamedamage tmp
ifvarg tmp 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 seekplayer
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


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

ifai NO { cstat 257 sizeat 30 30 strength WEAK ai AIBATFOWARD }
getactorvar[PLAYERID].invisible tmp2
ifvarn tmp2 1 
{
ifp palive
{
ifai AIBATFOWARD ifcansee { state ifnotmovingstate ifrnd 16 ai AIBATDOWN else ifrnd 16 { soundonce BATSPOT ai AIBATUP } }
ifai AIBATDOWN { state ifnotmovingstate iffloordistl 10 { ai AIBATUP } ifpdistl 1024 { ai AIBATDOWN } else { ifp phigher { soundonce BATSPOT ai AIBATUP } else ifrnd 16 ai AIBATFOWARD } }
ifai AIBATUP { state ifnotmovingstate ifceilingdistl 10 { ai AIBATDOWN } ifpdistl 1024 { ai AIBATDOWN } else { ifp phigher ai AIBATDOWN else ifrnd 16 ai AIBATFOWARD } }
} else ai AIBATFIND
ifai AIBATFIND ifp palive ifcansee { soundonce BATSPOT ai AIBATFOWARD }
} else
{ ifai AIBATFOWARD { ai AIBATFIND } }
ifai AIBATFIND { state ifnotmovingstate }
ifhitweapon { ifrnd 64 soundonce BATDIE1 else ifrnd 64 soundonce BATDIE2 else soundonce BATDIE3  ai AIBATDYING }
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 } }
enda


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

spriteshadow GABGBONE
defineprojectile GABGBONE PROJ_WORKSLIKE 32770
defineprojectile GABGBONE PROJ_HITRADIUS 0
defineprojectile GABGBONE PROJ_VEL 700
defineprojectile GABGBONE PROJ_DROP -20
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
{
	ifp pducking nullop else { ifp pstanding nullop else { state gargaction } }
	ifvarg htextra 0 { state gargaction }
} 
else
{
	getactorvar[itemprotection].skillit peractor2
	ifvare peractor2 1 { state gargaction }
}
ifaction ASTATWAKEUP { ifactioncount 3 { espawn GARGOYLE 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

move GARGWALK 250
move GARGSTOP

ai AIGARGWALK AGARGWALK GARGWALK faceplayer
ai AIGARGHURT AGARGHURT GARGSTOP faceplayer
ai AIGARGRANDOM AGARGWALK GARGWALK randomangle
ai AIGARGSTOP AGARGWALK GARGSTOP
ai AIGARGUP AGARGWALK GARGWALK faceplayer
ai AIGARGDOWN AGARGWALK GARGWALK faceplayer
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

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 gargnavigation
ifvarg z3 6144 { ai AIGARGUP } else 
ifvarl z3 -6144 { ai AIGARGDOWN }
ends

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 guts JIBS6 10 ifrnd 96 { soundonce GARGDIE1 } else ifrnd 96 { soundonce GARGDIE2 } else { soundonce GARGDIE3 } ai AIGARGDYING } else { soundonce GARGPAIN guts JIBS6 3 ifvare perplayer 1 { ai AIGARGHURT } else { ifrnd 64 ai AIGARGHURT } }
ends

useractor notenemy GARGOYLE
state enemyeffects
getplayer[THISACTOR].i PLAYERID	
getactorvar[PLAYERID].invisible perplayer
getactor[PLAYERID].z pz

getactor[THISACTOR].htextra htextra
getactor[THISACTOR].htang htang

getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z3
updatesector x y temp
getflorzofslope temp x y z2
getceilzofslope temp x y mz
subvarvar z2 z3 //THISACTOR and FLOOR
subvarvar mz z3 //THISACTOR and CEILING
subvarvar z3 pz //PLAYERID and THISACTOR
ifhitweapon { state garghurtstate }
ifvarn perplayer 1
{	
	ifai NO ifcansee { soundonce GARGSPOT strength 280 sizeat 30 30 cstat 385 ai AIGARGWALK }
	ifai AIGARGWALK 
	{ 
		ifvarl z2 5120 { getactor[THISACTOR].z z addvar z -2800 setactor[THISACTOR].z z } 
		ifvarg mz -5120 { getactor[THISACTOR].z z addvar z 2800 setactor[THISACTOR].z z } 
		ifvarl z3 6144 ifvarg z3 -6144 ifcansee { ifpdistg 3092 ifpdistl 8192 { ifcount 5 { ai AIGARGBONESHOOT } } else ifpdistl 1280 { ai AIGARGSHOOT } }
		state gargnavigation
		ifp pdead ai AIGARGSTOP
	}
	ifai AIGARGUP { ifvarl z3 6144 ai AIGARGWALK else ifvarl mz -6144 { getactor[THISACTOR].z z addvar z -1400 setactor[THISACTOR].z z } }
	ifai AIGARGDOWN { ifvarg z3 -6144 ai AIGARGWALK else ifvarg z2 6144 { getactor[THISACTOR].z z addvar z 1400 setactor[THISACTOR].z z } }
	ifai AIGARGSHOOT 
	{ 
		ifpdistl 1280 ifcansee
		{ 
			ifactioncount 6 
			{
				soundonce PFLESH 
				setactor[PLAYERID].htextra 2
				getactor[PLAYERID].htextra paextra
				state checkb_armor
				palfrom 32 1 1 1 
				resetactioncount 
			}
		} else ifcount 30 ai AIGARGWALK
		ifp pdead ai AIGARGSTOP
	}
	ifai AIGARGBONESHOOT 
	{ 
		ifcansee
		{
			ifactioncount 6 
			{
				soundonce GARGCLAW 
				eshoot GABGBONE
				getactor[THISACTOR].z z
				addvar z 1024
				setactor[RETURN].z z
				ai AIGARGWALK
				resetactioncount 
			}
		} 
		ifp pdead ai AIGARGSTOP
	}
	ifai AIGARGSTOP { ifp palive ifcansee ai AIGARGWALK }
	ifai AIGARGRANDOM { ifp palive ifcansee ai AIGARGWALK }
} 
else
{
	ifai NO ifcansee { strength 280 sizeat 30 30 cstat 385 ai AIGARGSTOP }
	ifai AIGARGBONESHOOT { ai AIGARGRANDOM }
	ifai AIGARGSHOOT { ai AIGARGRANDOM }
	ifai AIGARGWALK { ai AIGARGRANDOM }
	ifai AIGARGUP { ai AIGARGRANDOM }
	ifai AIGARGDOWN { ai AIGARGRANDOM }
	ifai AIGARGRANDOM 
	{ 
		ifvarl z2 5120 { getactor[THISACTOR].z z addvar z -2800 setactor[THISACTOR].z z } 
		ifvarg mz -5120 { getactor[THISACTOR].z z addvar z 2800 setactor[THISACTOR].z z } 
		state ifnotmovingstate ifrnd 4 { randvar ang 2048 setactor[THISACTOR].ang ang } 
		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].burningguyactive tmp
ifvare tmp 1 
{ 
	addkills 1 
	spawn GARGBURNING 
	killit
	setactorvar[THISACTOR].burningguyactive 0 
}
enda














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

actor CIVILIANSTOPED 
sizeat 50 50
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 sound DUKE_LONGTERM_PAIN5 guts JIBS6 3 ai AICIVILIANWALKING break }
ends

actor CIVILIAN TOUGH state enemyeffects
fall 
//ifmove 0 { sound 8 }
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 { sound THUD ai AICIVILIANDEAD } }
enda

//------------------------------HELL DOG CODE

action AHELLDOGWALK  0  7  5  1  7
action AHELLDOGBITE 35 3 5 1 10
action AHELLDOGDYING 405 7 1 1 10
action AHELLDOGDEAD 412 1 1 1 10

move HELLDOGWALK 200
move HELLDOGSTOP 

ai AIHELLDOGWALK AHELLDOGWALK HELLDOGWALK faceplayer seekplayer
ai AIHELLDOGASS AHELLDOGWALK HELLDOGWALK randomangle
ai AIHELLDOGRANDOM AHELLDOGWALK HELLDOGWALK randomangle
ai AIHELLDOGBITE AHELLDOGBITE HELLDOGSTOP faceplayer 
ai AIHELLDOGDYING AHELLDOGDYING HELLDOGSTOP
ai AIHELLDOGDEAD AHELLDOGDEAD HELLDOGSTOP

state helldoghurt
ifwasweapon RPG { addkills 1 state squishcode killit } else ifwasweapon RADIUSEXPLOSION { addkills 1 state squishcode killit }
else ifdead { addkills 1 guts JIBS6 10 soundonce DRON_DYING ai AIHELLDOGDYING } else { spawn BLOOD sound PIG_PAIN guts JIBS6 5 }
ends

actor HELLDOG fall state enemyeffects
ifhitweapon { state helldoghurt }
ifai NO ifcansee { strength 60 sizeat 30 30 cstator 257 ai AIHELLDOGWALK sound BOS2_ROAM }
ifai AIHELLDOGWALK { ifrnd 3 sound COMM_RECOG else ifpdistl 1000 ai AIHELLDOGBITE else ifrnd 4 ai AIHELLDOGRANDOM else ifp pdead { ai AIHELLDOGASS } }
ifai AIHELLDOGASS { ifp palive ai AIHELLDOGWALK }
ifai AIHELLDOGRANDOM { ifpdistl 1000 ai AIHELLDOGBITE else ifrnd 6 ai AIHELLDOGWALK else ifnotmoving ai AIHELLDOGWALK }  
ifai AIHELLDOGBITE { ifpdistl 1000 ifcansee ifrnd 96 { sound OCTA_ATTACK2 addphealth -5 palfrom 32 32 } else ifrnd 64 ai AIHELLDOGWALK } 
ifai AIHELLDOGDYING { cstat 0 ifactioncount 7 { sound THUD ai AIHELLDOGDEAD } }
enda

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

action ABUTCHERWALK  0  4  5  1  20
action ABUTCHERATTACK1 48 5 5 1 10
action ABUTCHERATTACK2 48 2 5 1 25
action ABUTCHERATTACK3 2234 3 5 1 15
action ABUTCHERDYING 30 6 1 1 10
action ABUTCHERDEAD 35 1 1 1 20

move BUTCHERWALK 70
move BUTCHERSTOP 

ai AIBUTCHERWALK ABUTCHERWALK BUTCHERWALK faceplayer seekplayer
ai AIBUTCHERASS ABUTCHERWALK BUTCHERWALK randomangle
ai AIBUTCHERRANDOM ABUTCHERWALK BUTCHERWALK randomangle
ai AIBUTCHERATTACK1 ABUTCHERATTACK1 BUTCHERSTOP faceplayer 
ai AIBUTCHERATTACK2 ABUTCHERATTACK2 BUTCHERSTOP faceplayer 
ai AIBUTCHERATTACK3 ABUTCHERATTACK3 BUTCHERSTOP faceplayer 
ai AIBUTCHERDYING ABUTCHERDYING BUTCHERSTOP
ai AIBUTCHERDEAD ABUTCHERDEAD BUTCHERSTOP

state butcherhurt
ifwasweapon RPG { addkills 1 spawn BURNINGGUY killit } else ifwasweapon RADIUSEXPLOSION { addkills 1 spawn BURNINGGUY killit }
else ifdead { addkills 1 guts JIBS6 10 soundonce STEPNIT ai AIBUTCHERDYING } else { sound DUKE_LAND_HURT spawn BLOOD guts JIBS6 3 }
ends

useractor enemy BUTCHER fall state enemyeffects
ifhitweapon { state butcherhurt }
ifai NO { strength 100 sizeat 30 30 cstator 257 ai AIBUTCHERWALK }
ifai AIBUTCHERWALK { ifrnd 2 ai AIBUTCHERRANDOM else ifpdistl 1000 ai AIBUTCHERATTACK1 else ifpdistl 5000 ifrnd 3 ai AIBUTCHERATTACK3 else ifrnd 6 ifcansee ai AIBUTCHERATTACK2 else ifp pdead { ai AIBUTCHERASS } }
ifai AIBUTCHERASS { ifp palive ai AIBUTCHERWALK }
ifai AIBUTCHERRANDOM { ifrnd 2 ai AIBUTCHERWALK else ifpdistl 1000 ai AIBUTCHERATTACK1 else ifpdistl 5000 ifrnd 3 ai AIBUTCHERATTACK3 else ifrnd 8 ifcansee ai AIBUTCHERATTACK2 } 
ifai AIBUTCHERATTACK1 { ifpdistl 1000 ifcansee ifactioncount 2 { sound SQUISHED addphealth -5 palfrom 32 32 resetactioncount } else ifcount 20 ai AIBUTCHERWALK } 
ifai AIBUTCHERATTACK2 { ifcansee ifactioncount 2 { shoot FIRELASER resetactioncount } else ifcount 25 ai AIBUTCHERWALK } 
ifai AIBUTCHERATTACK3 { ifpdistl 7000 ifcansee ifactioncount 1 { soundonce STEPNIT sound VOL4ENDSND2 sound DUKE_GRUNT shoot SPIT resetactioncount } else ifcount 30 ai AIBUTCHERWALK } 
ifai AIBUTCHERDYING { cstat 0 ifactioncount 6 { sound VOL4ENDSND2 ai AIBUTCHERDEAD } }
enda
