
setdefname dukeplus.def
setcfgname dp.cfg
setgamename Duke Plus 2.0

include DEFS.CON

include USER.CON

// to change QSIZE to 768           
gamestartup     DEFAULTVISIBILITY GENERICIMPACTDAMAGE MAXPLAYERHEALTH
                STARTARMORHEALTH  RESPAWNACTORTIME RESPAWNITEMTIME
                RUNNINGSPEED GRAVITATIONALCONSTANT RPGBLASTRADIUS
                PIPEBOMBRADIUS SHRINKERBLASTRADIUS TRIPBOMBBLASTRADIUS
                MORTERBLASTRADIUS BOUNCEMINEBLASTRADIUS SEENINEBLASTRADIUS
                MAXPISTOLAMMO MAXSHOTGUNAMMO MAXCHAINGUNAMMO
                MAXRPGAMMO MAXHANDBOMBAMMO MAXSHRINKERAMMO
                MAXDEVISTATORAMMO MAXTRIPBOMBAMMO MAXFREEZEAMMO
                MAXGROWAMMO CAMERASDESTRUCTABLE NUMFREEZEBOUNCES
                FREEZERHURTOWNER 768 TRIPBOMBLASERMODE

                
include DukePlus/dpcons/DEFSPLUS.CON
include DukePlus/dpcons/USERPLUS.CON
include DukePlus/dpcons/LIGHTS.CON
include DukePlus/dukebike/DUKEBIKE.CON
include DukePlus/dpcons/HUDPLUS.CON
include DukePlus/dpcons/PLAYERPLUS.CON
include DukePlus/dpcons/MONSTERPLUS.CON
include DukePlus/dpcons/CIVILIANS.CON


state randomizestate

ifactor RESPAWN break

randvar temp 100
ifvare monstflags -1 setvar monstflags 0
ifvarvarl temp randomize orvar monstflags 1
randvar temp 100
ifvarvarl temp randomize orvar monstflags 2
randvar temp 100
ifvarvarl temp randomize orvar monstflags 4
randvar temp 100
ifvarvarl temp randomize orvar monstflags 8
randvar temp 100
ifvarvarl temp randomize orvar monstflags 16
randvar temp 100
ifvarvarl temp randomize orvar monstflags 32
randvar temp 100
ifvarvarl temp randomize orvar monstflags 64
randvar temp 100
ifactor ROTATEGUN nullop else
ifvarvarl temp randomize orvar monstflags 128
randvar temp 100
ifvarvarl temp randomize orvar monstflags 256
randvar temp 100
ifvarvarl temp randomize orvar monstflags 1024
randvar temp 100
ifvarvarl temp randomize orvar monstflags 2048
randvar temp 75
ifvarvarl temp randomize orvar monstflags 4096

getactor[THISACTOR].picnum picnum
switch picnum
case BOSS1
case BOSS1STAYPUT
	getactor[THISACTOR].pal pal
	ifvarn pal 0 
	ifrnd 64 { cactor BOSS2 spritepal 3 setvar pal 3 }
break

case PIGCOP
case PIGCOPDIVE
case LIZMAN
case LIZMANJUMP
case NEWBEAST
case NEWBEASTJUMP
ifspawnedby RESPAWN nullop else
{
	ifrnd 1 { cactor BOSS2 spritepal 3 setvar pal 3 } else
	ifrnd 1 { cactor BOSS3 spritepal 3 setvar pal 3 } 
	else
	ifrnd 1 { cactor BOSS4 spritepal 3 setvar pal 3 }
}
break
default break
endswitch

ifvare picnum RECON ifrnd 128 { cactor RECONDP setvar picnum RECONDP }

ifspritepal 66 nullop else
{
	ifvarn picnum BOSS1 ifvarn picnum BOSS1STAYPUT
	ifvarn picnum BOSS2 ifvarn picnum BOSS3 ifvarn picnum BOSS4 
	ifvarn picnum BOSS4STAYPUT 
	ifvarn picnum RECON
	{
		ifvarl monstflags 2 setvar pal 3 else
		{
			randvar temp 8
			ifvare temp 0 setvar pal 2 else
			ifvare temp 1 setvar pal 7 else
			ifvare temp 2 setvar pal 8 else
			ifvare temp 3 setvar pal 10 else
			ifvare temp 4 setvar pal 12 else
			ifvare temp 5 setvar pal 17 else
			ifvare temp 6 setvar pal 19 else
			ifvare temp 7 setvar pal 21 else
			ifvare temp 8 setvar pal 24
		}
		setactor[THISACTOR].pal pal
	}
}
ends

state eventloadactorstate
getactor[THISACTOR].xvel droptile
setactor[THISACTOR].xvel 0
getactor[THISACTOR].yvel activator
setactor[THISACTOR].yvel 0
getactor[THISACTOR].zvel group
getactor[THISACTOR].extra monstflags



readgamevar played
ifvarn played 0 readgamevar randomize

ifvarn randomize 0 ifvare monstflags -1 state randomizestate
ifvarl monstflags 1
{
	ifactor RESPAWN getactor[THISACTOR].hitag picnum else
	getactor[THISACTOR].picnum picnum
	switch picnum
	case EGG
	setvar monstflags EGG_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case LIZTROOP
	case LIZTROOPSTAYPUT
	case LIZTROOPSHOOT
	case LIZTROOPJETPACK
	case LIZTROOPONTOILET
	case LIZTROOPJUSTSIT
	case LIZTROOPDUCKING
	setvar monstflags LIZTROOP_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case OCTABRAIN
	case OCTABRAINSTAYPUT 
	setvar monstflags OCTABRAIN_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case DRONE
	setvar monstflags DRONE_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case COMMANDER
	case COMMANDERSTAYPUT
	setvar monstflags COMMANDER_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case TANK
	setvar monstflags TANK_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case PIGCOP
	case PIGCOPSTAYPUT
	case PIGCOPDIVE
	setvar monstflags PIGCOP_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case LIZMAN
	case LIZMANSTAYPUT
	case LIZMANJUMP
	setvar monstflags LIZMAN_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case ROTATEGUN
	setvar monstflags ROTATEGUN_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case BOSS1
	case BOSS1STAYPUT
	setvar monstflags BOSS1_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case BOSS2
	setvar monstflags BOSS2_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case BOSS3
	setvar monstflags BOSS3_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case NEWBEAST
	case NEWBEASTSTAYPUT
	case NEWBEASTHANG
	case NEWBEASTJUMP
	case MINIBEAST
	setvar monstflags NEWBEAST_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case BOSS4
	case BOSS4STAYPUT
	setvar monstflags BOSS4_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case SHARK
	setvar monstflags SHARK_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case RECONDP
	case RECON
	setvar monstflags RECONDP_FLAGS
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	case FEM1
	case FEM2
	case FEM3
	case FEM4
	case FEM5
	case FEM6
	case FEM7
	case FEM8
	case FEM9
	case FEM10
	case TOUGHGAL
	case NAKED1
	case PODFEM1
	case BLOODYPOLE
	case FEM6PAD
	ifvarand morefx 32 setactor[THISACTOR].mdflags 1
	break
	default
	setvar monstflags 0
	break
	endswitch
}
ifvare droptile 0
{
	ifactor RESPAWN getactor[THISACTOR].hitag picnum else
	getactor[THISACTOR].picnum picnum
	switch picnum
	case EGG
	setvar droptile EGG_DROPS
	break
	case LIZTROOP
	case LIZTROOPSTAYPUT
	case LIZTROOPSHOOT
	case LIZTROOPJETPACK
	case LIZTROOPONTOILET
	case LIZTROOPJUSTSIT
	case LIZTROOPDUCKING
	setvar droptile LIZTROOP_DROPS
	break
	case OCTABRAIN
	case OCTABRAINSTAYPUT 
	setvar droptile OCTABRAIN_DROPS
	break
	case DRONE
	setvar droptile DRONE_DROPS
	break
	case COMMANDER
	case COMMANDERSTAYPUT
	setvar droptile COMMANDER_DROPS
	break
	case TANK
	setvar droptile TANK_DROPS
	break
	case PIGCOP
	case PIGCOPSTAYPUT
	case PIGCOPDIVE
	setvar droptile PIGCOP_DROPS
	break
	case LIZMAN
	case LIZMANSTAYPUT
	case LIZMANJUMP
	setvar droptile LIZMAN_DROPS
	break
	case ROTATEGUN
	setvar droptile ROTATEGUN_DROPS
	break
	case BOSS1
	setvar droptile BOSS1_DROPS
	break
	case BOSS1STAYPUT
	setvar droptile BOSS1_DROPS
	break
	case BOSS2
	setvar droptile BOSS2_DROPS
	break
	case BOSS3
	setvar droptile BOSS3_DROPS
	break
	case NEWBEAST
	case NEWBEASTSTAYPUT
	case NEWBEASTHANG
	case NEWBEASTJUMP
	setvar droptile NEWBEAST_DROPS
	break
	case BOSS4
	setvar droptile BOSS4_DROPS
	break
	case BOSS4STAYPUT
	setvar droptile BOSS4_DROPS
	break
	case SHARK
	setvar droptile SHARK_DROPS
	break
	case RECONDP
	setvar droptile RECONDP_DROPS
	break
	default break
	endswitch
}
setactor[THISACTOR].extra -1
ends




state dpbloodstate
ifvarn sector[THISACTOR].floorslope 0 killit
ifp ponground ifpdistl 844
{
	setplayer[THISACTOR].footprintcount 3
	setplayer[THISACTOR].footprintshade sprite[THISACTOR].shade
	getactor[THISACTOR].pal pal
	ifvare pal 0 setvar pal 2
	ifvare pal 22 setvar pal 2
	setplayer[THISACTOR].footprintpal pal
}
ends

state wakemon
	getactor[spriteid].picnum picnum
	switch picnum
	case LIZTROOP  
	case LIZTROOPDUCKING
	case LIZTROOPJETPACK
	case LIZTROOPSHOOT
	case LIZTROOPONTOILET
	case LIZTROOPJUSTSIT
	case LIZTROOPRUNNING
	case OCTABRAIN  
	case OCTABRAINSTAYPUT
	case DRONE  
	case COMMANDER  
	case COMMANDERSTAYPUT
	case TANK  
	case PIGCOP  
	case PIGCOPDIVE  
	case PIGCOPSTAYPUT
	case LIZMAN  
	case LIZMANSTAYPUT
	case LIZMANSPITTING
	case LIZMANJUMP
	case ROTATEGUN   
	case BOSS1 
	case BOSS1STAYPUT 
	case BOSS2  
	case BOSS3  
	case NEWBEAST
	case BOSS4
	case BOSS4STAYPUT
	canseespr THISACTOR spriteid temp
	ifvare temp 1
	{
		changespritestat spriteid 1
		setactor[spriteid].httimetosleep 780		
	}
	break
	default break
	endswitch
ends

state startfires

ifvarand ppowers 2 nullop else break

headspritestat spriteid 1
whilevarn spriteid -1
{
	getactor[THISACTOR].z z
	getactor[spriteid].z mz
	subvarvar mz z
	ifvarl mz 32768 ifvarg mz -32768
	{
		ldist xydist THISACTOR spriteid
		ifvarl xydist 3072
		{
			getactorvar[spriteid].burning tempb
			setvar tempc 3072
			subvarvar tempc xydist
			shiftvarr tempc 3
			addvarvar tempb tempc
			setactorvar[spriteid].burning tempb
// 			ifvarn actorvar[spriteid].monstatus 0
// 			{
// 				ifrnd 128 espawn BURNING else espawn BURNING2
// 				setsprite RETURN sprite[spriteid].x sprite[spriteid].y sprite[spriteid].z
// 			}
		}
	}
	nextspritestat spriteid spriteid
}
ifrnd 128 spawn BURNING else spawn BURNING2

ends

state wakeupmonsters

headspritestat spriteid 2
whilevarn spriteid -1
{
	state wakemon
	nextspritestat spriteid spriteid
}

ends

state tripbomb2blow

spawn EXPLOSION2
sound LASERTRIP_EXPLODE
ifvare effects YES
{
	setvar countvar 0
	getactor[THISACTOR].ang position
	whilevarn countvar 16
	{
		addvar countvar 1
		randvar zdist 8192 subvar zdist 6144 
		ifrnd 128 ezshoot zdist NEWSCRAP3 else 
		ezshoot zdist NEWSCRAP6
		ifrnd 160 setthisprojectile[RETURN].trail SMALLSMOKE
		randvar temp 128
		addvar temp 160
		setthisprojectile[RETURN].vel temp
		randvar temp 128
		addvar position 64
		addvarvar position temp
		setactor[THISACTOR].ang position
	}
}
hitradius TRIPBOMBBLASTRADIUS 30 60 90 120
ifvare actorvar[myspawner].monstatus 1
{
	setactor[myspawner].htpicnum RPG
	setactor[myspawner].htextra 180
	setactor[myspawner].htowner player[THISACTOR].i
}
ifvarand ppowers 2
state startfires

killit

ends

action TRIPBOMBFRAME -3701 1 1 1 1
useractor notenemy TRIPBOMB2 0 TRIPBOMBFRAME

ifmove 0
{
	sizeat 4 5
	move INIT
	cstat 16
	setactor[THISACTOR].angoff 1024
}

ifvarg sprite[myspawner].statnum 2 state tripbomb2blow else
ifvarn actorvar[myspawner].monstatus 1 state tripbomb2blow


// mtype = distance
// ammo = angle offset for rotatepoint
// initz = z distance from wounded actor's base

getactor[myspawner].x x
getactor[myspawner].y y
getactor[myspawner].ang angvar
subvarvar angvar ammo
setvarvar mx x
addvarvar mx mtype
rotatepoint x y mx y angvar x y
setactor[THISACTOR].x x
setactor[THISACTOR].y y

getactor[myspawner].ang angvar
subvarvar angvar peractor1
setactor[THISACTOR].ang angvar
getactor[myspawner].z z
subvarvar z initz
ifvarvarn peractor5 sprite[myspawner].picnum
ifvarg initz 4096
{
	ifvare peractor5 PIGCOP addvar z 4096
	ifvare peractor5 LIZTROOP addvar z 2560
}
setactor[THISACTOR].z z

ifcount 60
{
	ifspritepal 0 spritepal 6 else spritepal 0
	soundonce LASERTRIP_ARMING
	ifcount 90 state tripbomb2blow
}

enda

useractor notenemy NEWBLOODP1 state dpbloodstate enda
useractor notenemy NEWBLOODP2 state dpbloodstate enda

useractor notenemy BULLETWOUND 0

ifvarg sprite[myspawner].statnum 2 killit
ifvarn actorvar[myspawner].monstatus 1 killit
ifvarl sprite[myspawner].cstat 0
{
	getactor[THISACTOR].cstat peractor1
	cstat 32768
}
else
ifvarg sprite[THISACTOR].cstat 32000
setactor[THISACTOR].cstat peractor1

// mtype = distance
// ammo = angle offset for rotatepoint
// initz = z distance from wounded actor's base

sizeat 4 4
getactor[myspawner].x x
getactor[myspawner].y y
getactor[myspawner].ang angvar
subvarvar angvar ammo
setvarvar mx x
addvarvar mx mtype
rotatepoint x y mx y angvar x y
setactor[THISACTOR].x x
setactor[THISACTOR].y y

getactor[myspawner].ang angvar
subvarvar angvar peractor1
setactor[THISACTOR].ang angvar
getactor[myspawner].z z
subvarvar z initz
ifvarvarn peractor5 sprite[myspawner].picnum
ifvarg initz 4096
{
	ifvare peractor5 PIGCOP addvar z 4096
	ifvare peractor5 LIZTROOP addvar z 2560
}
setactor[THISACTOR].z z

ifrnd 8
{
	addvar countvar 1
	espawn JIBS6
	setactor[RETURN].zvel 0
	setactor[RETURN].xvel 0
	setactor[RETURN].xrepeat 24
	setactor[RETURN].yrepeat 24
	setactor[RETURN].pal sprite[myspawner].pal
	getactor[myspawner].htextra temp
	ifvarl temp 6 setactor[myspawner].htpicnum BULLETWOUND
	addvar temp 1
	ifvarl temp 1 setvar temp 1
	setactor[myspawner].htextra temp
	
	setactor[myspawner].htowner player[THISACTOR].i
	setactor[myspawner].htang sprite[THISACTOR].ang
	ifvarvarg countvar countvarb killit
}

// ifcount 390 killit
enda

eventloadactor GUSTSPAWNER
{
	getactor[THISACTOR].lotag lotag
	ifvare lotag 1
	{
		setactor[THISACTOR].lotag 0
		cstat 32768
		getactor[THISACTOR].xrepeat initx
		getactor[THISACTOR].yrepeat inity
		getactor[THISACTOR].hitag hitag // the number of ticks between gusts
		getactor[THISACTOR].xvel peractor1 // this determines speed of gusts
		getactor[THISACTOR].yvel countvarb // the max duration of spawned gust
		setvar temp 100
		subvarvar temp peractor1
		ifvarl temp 1 setvar temp 1
		setvarvar peractor1 temp
		getactor[THISACTOR].pal pal
		// pal is applied to spawned gusts
		// so is the size
		getactor[THISACTOR].shade initshade
		// and the shade
		getactor[THISACTOR].ang initz
		
	}
}
enda

useractor notenemy GUSTSPAWNER 0
ifvarn lotag 1 break

setactor[THISACTOR].ang initz

addvar countvar 1
ifvarvarg countvar hitag
{
	setvar countvar 0
	espawn SMOKEGUST
	setactor[RETURN].xrepeat initx
	setactor[RETURN].yrepeat inity
	setactor[RETURN].pal pal
	setactor[RETURN].shade initshade
	setactorvar[RETURN].initz initz
	setactorvar[RETURN].countvarb countvarb
	setactorvar[RETURN].peractor1 peractor1
}

enda

move GUSTMOVE
useractor notenemy SMOKEGUST 0

ifmove 0
{
	move GUSTMOVE faceplayer
	setactor[THISACTOR].mdflags 16
	getactor[THISACTOR].roll temp
	randvar temp 512
	setactor[THISACTOR].roll temp
	randvar mtype 4
	addvar mtype 4
	ifrnd 128 mulvar mtype -1 // roll variation
}
getactor[THISACTOR].roll temp
addvarvar temp mtype
setactor[THISACTOR].roll temp

// initz is the angle to move at

cos xvel initz
sin yvel initz
divvarvar xvel peractor1
divvarvar yvel peractor1
setvar zvel 0
movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN
ifvarn RETURN 0 killit
updatesectorz sprite[THISACTOR].x sprite[THISACTOR].y sprite[THISACTOR].z mysector
ifvare mysector -1 killit
ifnotmoving killit
ifvarg countvarb 0 ifvarvarg countvar countvarb killit
addvar countvar 1
enda

eventloadactor HEIGHTSPRITE
{
	getactor[THISACTOR].lotag lotag
	ifvare lotag 1
	{
		setactor[THISACTOR].lotag 0
		getactor[THISACTOR].hitag fallflag
		shiftvarl fallflag 3
		setactor[THISACTOR].hitag 0
		getactor[THISACTOR].zvel peractor1
		cstat 32768
	}
}
enda

eventloadactor 508
ifvare sprite[THISACTOR].lotag 1
{
	cstator 32768
	setactor[THISACTOR].lotag 0
}
enda

spritenopal LIGHTBUG2
eventloadactor LIGHTBUG
getactor[THISACTOR].lotag lotag
enda

eventloadactor 2361 // turret that keeps its size
state eventloadactorstate
getactor[THISACTOR].lotag lotag
ifvare lotag 1
{
	getactor[THISACTOR].xrepeat hitx
	getactor[THISACTOR].yrepeat hity
	setvar mtype 1
	cactor ROTATEGUN
}
enda

// eventloadactor LIGHTLOADER
// {
// 	getactor[THISACTOR].lotag lotag
// 	ifvare lotag 1
// 	ifvarn rendmode 4
// 	{
// 		setactor[THISACTOR].lotag 0
// 		setvar lotag 0
// 		getactor[THISACTOR].extra temp
// 		ifvarn temp -1 setvarvar monstflags temp
// 		getactor[THISACTOR].xvel droptile
// 		getactor[THISACTOR].yvel intensity
// 		getactor[THISACTOR].zvel flicker
// 		getactor[THISACTOR].hitag picnum
// 		setactor[THISACTOR].picnum picnum
// 		ifvare picnum LIGHTBUG { setactor[THISACTOR].picnum LIGHTBUG2 setvar lotag 1 sizeat 3 3 }
// 		setactor[THISACTOR].hitag 0
// 	}
// }
// enda

eventloadactor SECTOREFFECTOR 

	getactor[THISACTOR].extra monstflags
	ifvare monstflags -1 setvar monstflags 0
	getactor[THISACTOR].lotag lotag
	getactor[THISACTOR].hitag hitag
	getactor[THISACTOR].xvel initx 
	ifvarg lotag 115 ifvarl lotag 120 
	{
		shiftvarl initx 6
		ifvare scaled YES shiftvarl initx 1
	}
	getactor[THISACTOR].yvel activator
	getactor[THISACTOR].z initz
	ifvare lotag 102 nullop
	else
	getactor[THISACTOR].zvel topladder
	ifvarg lotag 115 ifvarl lotag 120
	ifvare scaled YES mulvar topladder 2
	setvarvar peractor2 topladder // saves value for elevators
	getactor[THISACTOR].shade initshade
	getactor[THISACTOR].pal playerally // for storing fog pal in water sectors
	getactor[THISACTOR].sectnum mysector
	ifvarg mysector -1 ifvarl mysector 4095
	{
		getsector[mysector].floorpal pal
		getsector[mysector].ceilingpal peractor7
		// search for light models with glow maps
		ifspritepal 1 ifvare lotag 49 
		{
			headspritesect spriteid mysector
		   	whilevarn spriteid -1
		   	{
			   	ifvare sprite[spriteid].extra 4911
			   	{
				   	getactor[spriteid].hitag mtype
				   	setactor[spriteid].hitag 0
				   	setactor[THISACTOR].hitag 0 // light starts OFF
				   	setactor[spriteid].extra 0
				   	setvarvar target2 spriteid
				   	setvar spriteid -1
			   	}
			   	else
			   	nextspritesect spriteid spriteid
	   		}
		}
		ifvarg lotag 48 ifvarl lotag 51 // light
		{
			setvarvar intensity hitag
			headspritesect spriteid mysector
		   	whilevarn spriteid -1
		   	{
			   	ifvare sprite[spriteid].picnum SECTOREFFECTOR
			   	ifvare sprite[spriteid].lotag 150
			   	{
				   	getactor[spriteid].hitag activator
				   	ifvare activator 0 getactor[spriteid].yvel activator
				   	getactor[spriteid].extra temp
				   	ifvare temp 1 // light starts off
				   	{
					   	setvar hitag -1
					   	setactor[THISACTOR].hitag 0
				   	}
				   	setvar spriteid -1
			   	}
			   	else
			   	nextspritesect spriteid spriteid
	   		}
	   		ifvarn activator 0 // search for light models with glow maps
	   		ifvare target2 -1
	   		{
		   		headspritesect spriteid mysector
			   	whilevarn spriteid -1
			   	{
				   	ifvare sprite[spriteid].extra 4911
				   	{
					   	getactor[spriteid].hitag mtype
					   	setactor[spriteid].hitag 0
					   	ifvare sprite[spriteid].lotag 1
					   	{
						   	setactor[spriteid].lotag 0
						   	setactor[THISACTOR].hitag intensity
						   	setvarvar hitag intensity // light starts ON
					   	} else
					   	{
					   		setactor[THISACTOR].hitag 0 // light starts OFF
					   		setvar hitag -1
				   		}
					   	setactor[spriteid].extra 0
					   	setvarvar target2 spriteid
					   	setvar spriteid -1
				   	}
				   	else
				   	nextspritesect spriteid spriteid
		   		}
	   		}
		}
	}

	ifvarg lotag 115 ifvarl lotag 120
	  ifvarl topladder 0 mulvar initshade -1 // correctly sets destination position of elevator
	  
	ifvarg lotag 87 ifvarl lotag 90 // portal cam; find other cam
	{
		getactor[THISACTOR].extra countvar
	
		setvar spriteid 0
		whilevarn spriteid 16384
		{
			ifvarn sprite[spriteid].statnum 1024
			ifvare sprite[spriteid].picnum SECTOREFFECTOR
			ifvarvare sprite[spriteid].lotag lotag
			ifvarvare sprite[spriteid].hitag hitag
			ifvarvarn spriteid THISACTOR
			{
				setvarvar myspawner spriteid
				setvar spriteid 16383
			}
			addvar spriteid 1
		}
		ifvare myspawner -1 killit
		ifvare activator 0 setvar peractor1 1
	}

enda

// eventloadactor CYCLER
// {
// 	ifvarn rendmode 4
// 	ifvare lighting NO
// 	{
// 		setvar spriteid 0
// 		whilevarn spriteid 16384
// 		{
// 			getactor[spriteid].picnum picnum
// 			ifvare picnum LIGHTLOADER
// 			{
// 				getactor[spriteid].lotag temp
// 				ifvare temp 1
// 				{
// 					setvar lighting YES
// 					setvar spriteid 16383
// 				}
// 			}
// 			addvar spriteid 1
// 		}
// 	}
// 	ifvare rendmode 4 setvar lighting NO
// 	ifvare lighting YES
// 	{
// 		setactor[THISACTOR].lotag 109
// 		setvar lotag 109
// 		setactor[THISACTOR].picnum SECTOREFFECTOR
// 	}
// }
// enda
	


eventloadactor LOCATORS
{
	ifvarn clearlocators 0 { setvar clearlocators 0 setvar locators -1 }
	getactor[THISACTOR].lotag lotag
	ifvarvarg lotag locators { setvarvar locators lotag }
	setactorvar[lotag].locatorids THISACTOR
}

enda

eventloadactor TOUCHPLATE
{
	getactor[THISACTOR].lotag lotag
	getactor[THISACTOR].hitag hitag
	getactor[THISACTOR].sectnum mysector
}
enda

eventloadactor CAMERA1 
{
	getactor[THISACTOR].extra monstflags
	ifvare monstflags -1 setvar monstflags 0
	setactor[THISACTOR].extra -1
} 
enda


eventloadactor WATERDRIP 
{
	getactor[THISACTOR].extra monstflags 
	setactor[THISACTOR].extra -1
	ifvarn monstflags 0 ifvarn monstflags -1
	{
		setvarvar rainstart monstflags
		getactor[THISACTOR].cstat raincstat
		getactor[THISACTOR].pal rainpal
		getactor[THISACTOR].xvel rainradius
		ifvarl rainradius 0 mulvar rainradius -1
		shiftvarl rainradius 1
		ifvare rainradius 0 setvar rainradius 12288
		ifvarl rainradius 2048 setvar rainradius 2048
		getactor[THISACTOR].zvel snowceiling
		ifvarl snowceiling 0 mulvar snowceiling -1
		shiftvarl snowceiling 4
		ifvare snowceiling 0 setvar snowceiling 65536
		ifvarl snowceiling 16384 setvar snowceiling 16384
		killit
	}
} 
enda

state mapitemload
getactor[THISACTOR].extra monstflags
ifvare monstflags -1 setvar monstflags 0
getactor[THISACTOR].lotag lotag
getactor[THISACTOR].pal pal
ifvarg pal 65
	setactor[THISACTOR].pal 0

ifactor FIRSTGUNSPRITE 
{
	getactor[THISACTOR].extra temp
	ifvare temp 1
	setactor[THISACTOR].pitch 1536
}
ifactor DBSPRITE sizeat 40 40
ifactor GROWSPRITEICON sizeat 36 36

getactor[THISACTOR].xvel peractor1
getactor[THISACTOR].yvel activator

getactor[THISACTOR].picnum command
ends

state itemquote

// ifvare quotestyle 0
// {
// 	setplayer[THISACTOR].fta 0
// 	setvarvar temp RETURN
// 	state enterquotearray
// 	break
// }

ifvare quotestyle 2 { userquote RETURN break }
ifvare quotestyle 1 { setplayer[THISACTOR].fta 100 setplayer[THISACTOR].ftq RETURN break }
setvar fta 130
setvarvar ftq RETURN

ends

action HELIFRAMES -1 2 1 1 1

eventloadactor HELICOPTER
getactor[THISACTOR].lotag lotag // the number of things it spawns
setactor[THISACTOR].lotag 0
ifvarn lotag 0
{
	setvarvar countvarb lotag
	getactor[THISACTOR].hitag hitag // the number of ticks after starting that it spawns
	getactor[THISACTOR].extra monstflags // flags of what it spawns
	ifvare monstflags -1 setvar monstflags 0
	getactor[THISACTOR].xvel droptile // the tile number that it spawns
	getactor[THISACTOR].yvel activator // tag that activates it
	getactor[THISACTOR].zvel initz // the quote number it plays, if any
	getactor[THISACTOR].cstat initcstat
	cstat 32768
}
enda

eventloadactor BLACKHAWK
getactor[THISACTOR].lotag lotag // the number of things it spawns
setactor[THISACTOR].lotag 0
ifvarn lotag 0
{
	setvarvar countvarb lotag
	getactor[THISACTOR].hitag hitag // the number of ticks after starting that it spawns
	getactor[THISACTOR].extra monstflags // flags of what it spawns
	ifvare monstflags -1 setvar monstflags 0
	getactor[THISACTOR].xvel droptile // the tile number that it spawns
	getactor[THISACTOR].yvel activator // tag that activates it
	getactor[THISACTOR].zvel initz // the quote number it plays, if any
	getactor[THISACTOR].cstat initcstat
	cstat 32768
}
enda

move HELIMOVE

state choppacode

ifvare lotag 0 break

ifmove 0
{
	ifvare hitag 0 setvar hitag 1
	ifvare myspawner -1 
	{
		getactor[THISACTOR].ang myspawner 
		ifvare myspawner -1 addvar myspawner 1
	}
	checkactivatormotion activator
	ifvare RETURN 1
	{
		setactor[THISACTOR].cstat initcstat
		cstator 257
		setactor[THISACTOR].ang myspawner
		move INIT
		
	}
	ifvare peractor1 1
	{
		setactor[THISACTOR].cstat initcstat
		cstator 257
		move INIT
	}
	break
}

soundonce HELICOP_IDLE
ifmove INIT
{
	ifcansee move HELIMOVE
	break
}
setactor[THISACTOR].ang myspawner
setvarvar angvar myspawner
ifactor HELICOPTER
addvar angvar 512
cos xvel angvar
sin yvel angvar
shiftvarr xvel 7
shiftvarr yvel 7 
setvar zvel 0
movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN
ifvare mtype 1 
{
	ifvarn RETURN 0 { stopsound HELICOP_IDLE killit  }
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].z z
	updatesectorz x y z mysector
	ifvare mysector -1 { stopsound HELICOP_IDLE killit  }
}
	
addvar countvar 1
ifvarvare countvar hitag
{
	ifvarg droptile 10
	{
		ifvarn initz 0
		{
			//setplayer[THISACTOR].ftq initz
			//setplayer[THISACTOR].fta 100
			setvarvar RETURN initz
			state itemquote
		}
		whilevarn countvarb 0
		{
			espawnvar droptile
			setactorvar[RETURN].monstflags monstflags
			getactor[THISACTOR].pal pal
			setactor[RETURN].pal pal
			subvar countvarb 1
		}
	}
	setvar mtype 1
}



ifhitweapon
{
	debris SCRAP1 1
	debris SCRAP6 1
	debris SCRAP5 1
	spawn SMALLSMOKE
	randvar temp 4
	switch temp
	case 0 sound HITMETAL break
	case 1 sound HITMETAL2 break
	case 2 sound HITMETAL3 break
	case 3 sound HITMETAL4 break
	case 4 sound HITMETAL5 break
	default break
	endswitch
}

ends

useractor notenemy HELICOPTER 0 HELIFRAMES
state choppacode
enda

useractor notenemy BLACKHAWK 0 ANULLACTION
state choppacode
enda

eventloadactor DPTOUCHPLATE
getactor[THISACTOR].lotag lotag
ifvarn lotag 0
{
	cstat 32768
	getactor[THISACTOR].hitag hitag
	getactor[THISACTOR].extra monstflags
	ifvare monstflags -1 setvar monstflags 0
	getactor[THISACTOR].xvel droptile
	getactor[THISACTOR].yvel activator
	getactor[THISACTOR].z initz
	getactor[THISACTOR].sectnum mysector
}
enda

eventloadactor BLOCKMENU
getactor[THISACTOR].lotag lotag
ifvare lotag 66 { setvar nomenu YES setvar menunag NO killit }
enda

eventloadactor CHECKPOINT
getactor[THISACTOR].lotag lotag
ifvarn lotag 0
{
	cstat 32768
	getactor[THISACTOR].hitag hitag // save slot
	ifvarg hitag 9 setvar hitag 9
	ifvarl hitag 0 setvar hitag 0
	getactor[THISACTOR].extra monstflags // sound
	ifvare monstflags -1 setvar monstflags 0
	setactor[THISACTOR].lotag 0
	setactor[THISACTOR].hitag 0
}
enda

useractor notenemy CHECKPOINT
ifvare lotag 0 break
ifvare countvar 1 break
ifvarvare player[THISACTOR].cursectnum sprite[THISACTOR].sectnum
{
	setvar countvar 1
	ifvarn monstflags 0 globalsoundvar monstflags
	switch hitag
	case 0 save 0 break
	case 1 save 1 break
	case 2 save 2 break
	case 3 save 3 break
	case 4 save 4 break
	case 5 save 5 break
	case 6 save 6 break
	case 7 save 7 break
	case 8 save 8 break
	case 9 save 9 break
	default save 9 break
	endswitch
	quote 1178
	userquote 1178
}
enda

move ON

eventloadactor DNSWITCH 
state mapitemload getactor[THISACTOR].lotag lotag setactor[THISACTOR].lotag 0
getactor[THISACTOR].sectnum mysector
getsector[mysector].floorz mz
getactor[THISACTOR].z initz
subvarvar initz mz // distance to be added to floorz
enda
eventloadactor UPSWITCH 
state mapitemload getactor[THISACTOR].lotag lotag setactor[THISACTOR].lotag 0
getactor[THISACTOR].sectnum mysector
getsector[mysector].floorz mz
getactor[THISACTOR].z initz
subvarvar initz mz // distance to be added to floorz
enda

state liftswitchcode

setactor[THISACTOR].sectnum mysector
getsector[mysector].floorz z
addvarvar z initz
setactor[THISACTOR].z z

ifmove ON ifcount 26 { getlastpal move INIT }

ifcount 26
  ifp palive
    ifpdistl 1816
      ifhitspace
         ifvarvare scannedsprite THISACTOR
{
	resetcount
	sound SWITCH_ON
	state activatorstate
	move ON
	spritepal 6
}
ends

action SWITCH_FRAMES 0 5 1 1 3

useractor notenemy UPSWITCH 0 SWITCH_FRAMES state liftswitchcode enda

useractor notenemy DNSWITCH 0 SWITCH_FRAMES state liftswitchcode enda

state loadwaypoint

cactor WAYPOINT

ifvare clearwaypoints 1 
{
	setvar clearwaypoints 0 
	
	setarray waypoints[0] -1
	setarray waypoints[1] -1
	ifvarg numwaypoints 1
	{
		setvar temp 1
		whilevarvarn temp numwaypoints
		{
			setarray waypoints[temp] -1
			addvar temp 1
		}
	}
	setvar numwaypoints 0 
}
getactor[THISACTOR].lotag lotag // lotag is the number of the waypoint and must be > 0
getactor[THISACTOR].hitag hitag // the lotag of a neighbor waypoint; 0 if empty
getactor[THISACTOR].extra monstflags // used for special properties such as jumping
ifvare monstflags -1 setvar monstflags 0
getactor[THISACTOR].xvel target // the lotag of a neighbor waypoint; 0 if empty
getactor[THISACTOR].yvel activator // the lotag a bot activates when it reaches this waypoint, if applicable
getactor[THISACTOR].zvel target2 // the tag that the waypoint waits on before allowing bot to proceed
// getactor[THISACTOR].shade ?
getactor[THISACTOR].pal pal
ifvarvarg lotag numwaypoints setvarvar numwaypoints lotag
setarray waypoints[lotag] THISACTOR
cstat 0
getactor[THISACTOR].x initx
getactor[THISACTOR].y inity
getactor[THISACTOR].z initz
cstat 32768
spriteflags 16

ends

eventloadactor WAYPOINTOLD state loadwaypoint enda

eventloadactor WAYPOINT state loadwaypoint enda

eventloadactor LADDER
{
	getactor[THISACTOR].extra monstflags
	ifvare monstflags 1 setactor[THISACTOR].cstat 32768
	setactor[THISACTOR].extra -1
	getactor[THISACTOR].hitag hitag
	getactor[THISACTOR].lotag lotag
}
enda

eventloadactor MOVEMENT
{
	getactor[THISACTOR].lotag lotag
	ifvare lotag 1
	{
		getactor[THISACTOR].extra playermoves
		killit
	}
}
enda

state turnoffmodels

setvar spriteid 0
whilevarn spriteid 16384
{
	ifvarvare sprite[spriteid].picnum picnum
		setactor[spriteid].mdflags 1
	addvar spriteid 1
}
ends

state turnoffanim

setvar spriteid 0
whilevarn spriteid 16384
{
	ifvarvare sprite[spriteid].picnum picnum 
		setactor[spriteid].mdflags 2
	addvar spriteid 1
}
ends

eventloadactor NOMODEL
	getactor[THISACTOR].lotag lotag
	ifvare lotag 1
	{
		getactor[THISACTOR].hitag picnum
		ifspritepal 1 state turnoffanim else state turnoffmodels
		getactor[THISACTOR].xvel picnum
		ifvarn picnum 0 { ifspritepal 1 state turnoffanim else state turnoffmodels }
		getactor[THISACTOR].yvel picnum
		ifvarn picnum 0 { ifspritepal 1 state turnoffanim else state turnoffmodels }
		getactor[THISACTOR].zvel picnum
		ifvarn picnum 0 { ifspritepal 1 state turnoffanim else state turnoffmodels }
		getactor[THISACTOR].extra picnum
		ifvarn picnum 0 { ifspritepal 1 state turnoffanim else state turnoffmodels }
		killit
	}


enda

eventloadactor NOISESPRITE
getactor[THISACTOR].lotag lotag
ifvare lotag 1
{
	setactor[THISACTOR].lotag 0
	getactor[THISACTOR].hitag hitag
	setactor[THISACTOR].hitag 0
	getactor[THISACTOR].sectnum mysector
	getactor[THISACTOR].extra countvar
	ifvare countvar -1 setvar countvar 0
	getactor[THISACTOR].yvel activator
	cstat 32768
}
enda

useractor notenemy NOISESPRITE 0

ifvarn lotag 1 break

ifvare mtype 0 ifvare activator 0
{
	getplayer[THISACTOR].cursectnum temp
	ifvarvare temp mysector setvar mtype 1
}

ifvare mtype 1
{
	addvar countvarb 1
	ifvarvarg countvarb countvar
	{
		soundvar hitag
		setvar mtype 2
	}
} else 
ifvarg mtype 1
{
	addvar mtype 1
	ifvarg mtype 780 
	killit
}

enda

eventloadactor TEMPSPRITE
ifvarn sprite[THISACTOR].lotag 0
{
	getactor[THISACTOR].lotag lotag // turns it off
	getactor[THISACTOR].hitag hitag // turns it on
	getactor[THISACTOR].cstat initcstat
	getactor[THISACTOR].extra monstflags
	ifvare monstflags -1 setvar monstflags 0
	cstat 32768
}
enda

eventloadactor QUOTER
getactor[THISACTOR].lotag lotag
// lotag 1 = quoter, lotag 2 = picture
// lotag > 2 = activation number
ifvarn lotag 0
{
	setactor[THISACTOR].lotag 0
	getactor[THISACTOR].hitag hitag // the quote number
	setactor[THISACTOR].hitag 0
	getactor[THISACTOR].sectnum mysector
	getactor[THISACTOR].extra countvar // number of ticks that quote displays
	ifvare countvar -1 setvar countvar 130
	getactor[THISACTOR].xvel initx
	getactor[THISACTOR].yvel inity
	getactor[THISACTOR].zvel initz // zoom
	shiftvarl initz 8
	setvar temp 65535
	addvarvar temp initz
	ifvarl temp 512 setvar temp 512
	ifvarg temp 524288 setvar temp 524288
	setvarvar initz temp
	// pal is the text color
	cstat 32768
	setvar NOCODE 1
}
enda

useractor notenemy QUOTER 0

ifvare lotag 0 break

ifvare mtype 0
{
	ifvarl lotag 4
	{
		getplayer[THISACTOR].cursectnum temp
		ifvarvare temp mysector 
		{
			setvar mtype 1
			ifvare lotag 3
			{
				setplayer[THISACTOR].ftq hitag
				setplayer[THISACTOR].fta countvar
				killit
			} else
			ifvare lotag 2 setvarvar quoteridpic THISACTOR else
			setvarvar quoterid THISACTOR
		}
	}
	else ifvare peractor1 1 // was triggered remotely
	{
		setvar mtype 1
		ifvarg hitag 10000
		{
			subvar hitag 10000
			setvar lotag 2
			setvarvar quoteridpic THISACTOR
		}
		else
		{
			setvarvar quoterid THISACTOR
			setvar lotag 1
		}
	}
}

ifvare mtype 1
{
	addvar countvarb 1
	ifvarvarg countvarb countvar
	{
		ifvare lotag 2
		setvar quoteridpic -1 else
		setvar quoterid -1
		killit
	}
}

enda

eventloadactor SHOOTER

getactor[THISACTOR].lotag lotag
ifvarn lotag 0 // lotag -1 or 1 = activate on sight, 2 or > = activated remotely
{
	getactor[THISACTOR].extra monstflags 
	ifvare monstflags -1 setvar monstflags 0
	// bitfield:  -1, 0 = no aiming, 2 = aims at player and friends, 4 = aims at bad guys, 8 = randomized aiming
	// 16 = randomized shot timing, 32 = makes sound when firing, 64 = can be destroyed by explosives
	// 256 = projectiles are not polymer lights
	setactor[THISACTOR].lotag 0
	getactor[THISACTOR].hitag hitag // the tilenum of the projectile it shoots
	ifvarand monstflags 32
	{
		switch hitag // to determine firing sound
		case FIRELASER
		setvar bouncesound PRED_ATTACK2
		// case COOLEXPLOSION1
		// break
		
		case SHRINKER
		setvar bouncesound SHRINKER_FIRE
		break
		// case ELECTROPROJ
		// break
		case STARPROJ
		setvar bouncesound PISTOL_LOW
		break
		
		case RPG
		case RPGNOAIM
		setvar bouncesound RPG_SHOOT
		break
		
		case FREEZEBLAST
		case FREEZENOAIM
		setvar bouncesound CAT_FIRE
		break
		
		case ICESHARD
		case SAWBLADEPROJ
		setvar bouncesound SHARDSHOOTSND
		break
		
		case SHOTSPARK1
		setvar bouncesound PISTOL_FIRE
		break
		case SHOTGUN
		setvar bouncesound DPPISTOLFIRE
		break
		case CHAINGUN
		setvar bouncesound DPCHAINGUNFIRE
		break
		case MP5BULLET
		setvar bouncesound MP5FIRE
		break
		case GROWSPARK
		setvar bouncesound EXPANDERSHOOT
		break
		case FIREBULLET
		setvar bouncesound RPG_SHOOT
		break
		case RAILSLUG_WEAK
		setvar bouncesound SHOTTY2
		break
		case FIREBALLPROJ
		setvar bouncesound BLASTERSND
		break
		case GRAVPROJ2
		setvar bouncesound GRAVSHOOTSND
		break
		case DPCANNONBALL
		setvar bouncesound CANNONSND
		break
		default break
		endswitch
	}
	
	
	getactor[THISACTOR].shade monstatus // number of projectiles it shoots
	ifvare monstatus 0 setvar monstatus 1
	// negative monstatus makes it shoot forever
	getactor[THISACTOR].xvel droptile // the speed of the projectiles
	setactor[THISACTOR].xvel 0
	getactor[THISACTOR].yvel peractor1 // vertical aiming
	setactor[THISACTOR].yvel 0
	setactor[THISACTOR].extra -1
	getactor[THISACTOR].zvel countvarb // the number of ticks between shots
	ifvarl countvarb 1 setvar countvarb 1

	getactor[THISACTOR].sectnum mysector
	getactor[THISACTOR].pal pal // applied to projectiles
	getactor[THISACTOR].z initz
	subvar initz 8192
	cstator 32768
	getactor[THISACTOR].ang position
}

enda

eventloadactor OUTDOORLIGHTING
ifvarn sprite[THISACTOR].lotag 0
{
	getactor[THISACTOR].hitag outsideradius
	getactor[THISACTOR].xvel outsidered
	getactor[THISACTOR].yvel outsidegreen
	getactor[THISACTOR].zvel outsideblue
	getactor[THISACTOR].cstat outsidepriority
	killit
}
enda

eventloadactor INDOORLIGHTING
ifvarn sprite[THISACTOR].lotag 0
{
	getactor[THISACTOR].hitag insideradius
	getactor[THISACTOR].xvel insidered
	getactor[THISACTOR].yvel insidegreen
	getactor[THISACTOR].zvel insideblue
	getactor[THISACTOR].cstat insidepriority
	killit
}
enda

eventloadactor XIT
getactor[THISACTOR].lotag lotag
setactor[THISACTOR].lotag 0
getactor[THISACTOR].hitag hitag
setactor[THISACTOR].hitag 0
getactor[THISACTOR].sectnum mysector
ifvarn lotag 0 ifvarn hitag 0 { setvar HUBEXITS YES cstat 32768 }

enda

useractor notenemy XIT 0

ifvare lotag 0 break
getplayer[THISACTOR].cursectnum temp
ifvarvare temp mysector
{
	// setvar lighting USE_FLARES
	// ifvare rendmode 4 setvar lighting NO
	startlevel VOLUME hitag
}

enda

state decalcode

ifmove 0
{
	move INIT
	insertspriteq
}

ends

state fitsector

ifvare mysector -1 break

getsector[mysector].wallptr wallpoint // get the firstwall of the sector
getsector[mysector].wallnum numwalls // get the number of walls in the sector
setvar currwall 0
ifvarl numwalls 1 break
   		
whilevarvarn currwall numwalls
{
	getwall[wallpoint].x hitx
	getwall[wallpoint].y hity
	state pythagoras
	ifvare currwall 0 setvarvar xydist2 xydist else
	ifvarvarl xydist xydist2 setvarvar xydist2 xydist
	addvar wallpoint 1 // next wall in sector
	addvar currwall 1
}
// xydist is now the shortest distance between decal and any wall point in the sector

ifvarl xydist2 768
{
	divvar xydist2 36
	getactor[THISACTOR].xrepeat digx
	ifvarvarl xydist2 digx
	setactor[THISACTOR].xrepeat xydist2
	setactor[THISACTOR].yrepeat xydist2
	ifvarl xydist2 3 killit
}

setvar botclip 0
setvarvar mx x
addvar mx 128
getactor[THISACTOR].ang angvar
getactor[THISACTOR].z z
setvar mtype 0
whilevarn botclip 8
{
	rotatepoint x y mx y angvar hitx hity
	state pythagoras
	updatesectorz hitx hity z temp
	ifvarvarn temp mysector ifvarn temp -1
	{
		getflorzofslope temp hitx hity mz
		subvarvar mz z
		ifvarg mz 256
		{
			setvar botclip 7 
			setvar mtype 1
		}	
	}
	
	addvar mx 256 // checking further out
	rotatepoint x y mx y angvar hitx hity
	subvar mx 256
	state pythagoras
	updatesectorz hitx hity z temp
	ifvarvarn temp mysector ifvarn temp -1
	{
		getflorzofslope temp hitx hity mz
		subvarvar mz z
		ifvarg mz 256
		{
			setvar botclip 7 
			setvar mtype 2
		}
	}
		
	addvar angvar 256
	addvar botclip 1
}

ifvare mtype 1 killit
ifvare mtype 2
{
	getactor[THISACTOR].xrepeat x
	ifvarg x 4 { divvar x 2 ifvarl x 3 setvar x 3 setactor[THISACTOR].xrepeat x }
	getactor[THISACTOR].yrepeat y
	ifvarg y 4 { divvar y 2 ifvarl y 3 setvar y 3 setactor[THISACTOR].yrepeat y }
}

ends


spritenoshade SCORCH

useractor notenemy SCORCH 0

ifspritepal 3 break

ifmove 0
{
	ifspawnedby SHOTSPARK1 
	{
		//sizeat 8 8 
		sizeat 4 4
		cstator 128
		spritepal 3
		break
	}
	// ifspawnedby EXPLOSION2 insertspriteq
	move INIT

	ifvarn initx 0 sizeat 4 4 else
	sizeat 16 16

	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].sectnum mysector
	ifvare lotag 1 
	{
		ifonwater killit else
		state fitsector 
		break 
	}
	ifvare hitag 1 { state fitsector break }
	ifvarn target -1
	getwall[target].nextsector target2
	
	ifvarn target2 -1
	{
		setvar tempb 0
    	getsector[target2].lotag temp
    	switch temp
    	case 3
    	case 16    // ELEVATOR PLATFORM DOWN
		case 17    // ELEVATOR PLATFORM UP
		case 18    // ELEVATOR DOWN
		case 19    // ELEVATOR UP
    	case 20    // CEILING DOOR
	    case 21    // FLOOR DOOR
	    case 22    // SPLIT DOOR
	    case 23    // SWING DOOR
	    case 26    // SPLIT STAR TREK DOOR
	    case 28    // DROP FLOOR
	    case 29    // TEETH DOOR
	    case  9    // STAR TREK DOORS
	    case 25    // SLIDE DOOR
	    case 27    // BRIDGE
	    case 30    // ROTATE RISE BRIDGE
	    case 31    // 2 WAY TRAIN
	    setvar tempb 1
	    break
	    default break
	    endswitch
	    ifvare tempb 1 killit
	    
	   	headspritesect spriteid target2
	   	whilevarn spriteid -1
	   	{
		   	ifvare sprite[spriteid].picnum SECTOREFFECTOR
		   	{
			   	getactor[spriteid].lotag tempc
			   	switch tempc
			   	case 11
			   	case 13
			   	case 15
			   	case 19
			   	case 21
			   	case 22
			   	case 25
			   	case 31
			   	case 32
			   	setvar tempb 1
			   	break
			   	endswitch
		   	}
	   		nextspritesect spriteid spriteid
	   		ifvare tempb 1 setvar spriteid -1
   		}
   		ifvare tempb 1 killit
	}
	
	
	getactor[THISACTOR].ang angvar
	cos mycos angvar
	sin mysin angvar
	subvar angvar 512
	setvarvar mx x
	addvar mx 512
	rotatepoint x y mx y angvar digx digy
	updatesectorz digx digy sprite[THISACTOR].z tempd
	ifvare tempd -1 setvar xydist 1 else
	{
		hitscan digx digy sprite[THISACTOR].z tempd mycos mysin 0 hitsector hitwall hitsprite hitx hity hitz clipmask
		state pythagoras
	}
	ifvarl xydist 896
	{
		ifvare target -1 ifvarn xydist 1 ifvarn hitwall -1 
		{
			setvarvar target hitwall
			getwall[target].nextsector target2
		}
		addvar angvar 1024
		rotatepoint x y mx y angvar digx digy
		updatesectorz digx digy sprite[THISACTOR].z tempd
		ifvare tempd -1 setvar xydist 1 else
		{
			hitscan digx digy sprite[THISACTOR].z tempd mycos mysin 0 hitsector hitwall hitsprite hitx hity hitz clipmask
			state pythagoras
		}
	}
	
	ifvare target -1 break
	ifvarg xydist 896
	{
		// calculate distance to wallpoint
		// calculate distance to wallpoint2
		// if either ditance is short, shrink accordingly
		setvar xydist2 8192
		getwall[target].x hitx
		getwall[target].y hity
		state pythagoras	
		setvarvar xydist2 xydist
		getwall[target].point2 currwall
		getwall[currwall].x hitx
		getwall[currwall].y hity
		state pythagoras   
	 	ifvarvarl xydist2 xydist setvarvar xydist xydist2
		
		ifvarl xydist 768
		{
			divvar xydist 28
			getactor[THISACTOR].xrepeat digx
			ifvarvarl xydist digx
			setactor[THISACTOR].xrepeat xydist
			ifvarl xydist 3 killit
		}
	}
	
	
	getwall[target].nextsector temp
	ifvarn temp -1
	{
		getsector[temp].floorz mz
		getactor[THISACTOR].z z
		ifvarvarl mz z
		{
			subvarvar z mz
			ifvarl z 6144
			{
				shiftvarr z 28
				getactor[THISACTOR].yrepeat y
				ifvarvarl z y
				setactor[THISACTOR].yrepeat z
				ifvarl z 3 killit
			}
		}
		getsector[temp].ceilingz mz
		ifvarvarg mz z
		{
			subvarvar mz z
			shiftvarr mz 9
			getactor[THISACTOR].yrepeat y
			ifvarvarl mz y
			setactor[THISACTOR].yrepeat mz
		}
				
	}
	ifvarn target -1
	{
		getwall[target].shade shade
		ifvarl shade 0 setvar shade 0
		addvar shade 5
		setactor[THISACTOR].shade shade
	}
	
	ifvare lotag 0 ifvare hitag 0 
		ifawayfromwall killit
	
}

ifvare lotag 1
{
	getsector[mysector].floorshade shade
	setactor[THISACTOR].shade shade
} else
ifvare hitag 1
{
	getsector[mysector].ceilingshade shade
	setactor[THISACTOR].shade shade
}

ifcount 1800 killit
ifcount 1500 cstator 512
ifcount 1200 cstator 2

enda

useractor notenemy CONCRETEHOLE2 0
ifmove 0
{
	sizeat 3 3
	cstator 2
	move INIT
	insertspriteq
}
enda

useractor notenemy ELECTRONICHOLE 0
ifmove 0
{
	sizeat 3 3
	cstator 2
	move INIT
	insertspriteq
}
enda

action STICKYBURN -30 14 1 1 2
action STICKYBURN2 -70 14 1 1 2

spritenoshade STICKYFIRE
useractor notenemy STICKYFIRE 0

ifcount 1 nullop
  else 
    ifcount 0
	{
		setactor[THISACTOR].shade -127
		ifrnd 128 action STICKYBURN else action STICKYBURN2
    	ifrnd 128 soundonce FIRE_CRACKLE
    	cstat 130
    	ifrnd 128 cstator 4
		randvar temp 10
		switch temp
		case 0 sizeat 2 5 break
    	case 1 sizeat 2 4 break
		case 2 sizeat 4 4 break
		case 3 sizeat 3 6 break
		case 4 sizeat 5 6 break
		case 5 sizeat 4 8 break
		case 6 sizeat 7 8 break
		case 7 sizeat 5 10 break
		case 8 sizeat 8 10 break
		case 9 sizeat 12 12 break
		case 10 sizeat 10 12 break
		default break
    	endswitch
    	
    	
    	ifrnd 96
    	{
	    	getactor[THISACTOR].xrepeat x
	    	mulvar x 2
	    	setactor[THISACTOR].xrepeat x
	    	getactor[THISACTOR].yrepeat y
	    	mulvar y 2
	    	setactor[THISACTOR].yrepeat y
    	}

		ifvarn myspawner -1
		{
			getactor[myspawner].yrepeat y
			switch monstatus
			
			case PIGCOP
			case PIGCOPDIVE
			case LIZTROOP
			case LIZTROOPDUCKING
			case LIZMAN
			case NEWBEAST
			case OCTABRAIN
			mulvar y 230
			break
			
			case TANK
			// case MECH2
			case COMMANDER
			mulvar y 256
			break
			
			case BOSS1
			case BOSS2
			case BOSS3
			case BOSS4
			mulvar y 300
			break
					
			case DRONE
			case ROTATEGUN
			case EGG
			mulvar y 128
			break
				
			default
			mulvar y 230
			break
			endswitch
			
			randvarvar tempb y
			addvarvar tempb mtype
		  	getactor[myspawner].z mz
		  	ifvare sprite[myspawner].picnum COMMANDER subvar mz 3072
		   	subvarvar mz tempb
		  	setactor[THISACTOR].z mz
	  	}
	}

ifvarn myspawner -1 ifvarg countvar 5
{
	setvar countvar 0
	getactor[myspawner].statnum temp
	ifvare temp 1024 setvar myspawner -1 else
	{
		getactor[myspawner].xrepeat tempb
		switch monstatus
		case BOSS1
		case BOSS2
		case BOSS3
		case BOSS4
		mulvar tempb 7
		break
		
		case PIGCOP
		case PIGCOPDIVE
		case OCTABRAIN
		mulvar tempb 5
		break
		
		case TANK
		// case MECH2
		mulvar tempb 6
		break
		
		case LIZTROOP
		case LIZTROOPDUCKING
		case LIZMAN
		case NEWBEAST
		mulvar tempb 4
		break
		
		case ROTATEGUN
		case DRONE
		mulvar tempb 3
		break
		
		default mulvar tempb 4
		break
		
		endswitch
		getactor[myspawner].x mx
		getactor[myspawner].y my
		randvarvar temp tempb
	    ifrnd 128 addvarvar mx temp else subvarvar mx temp
	    randvarvar temp tempb
		ifrnd 128 addvarvar my temp else subvarvar my temp
		setactor[THISACTOR].x mx
		setactor[THISACTOR].y my
	}
}
addvar countvar 1

ifcount 14 nullop else ifcount 13 ifrnd 48 spawn NEWSMOKE
ifcount 14 sizeto 0 0
enda

action SCANKILL -1 1 1 1
useractor notenemy SCANTRAIL 0 
ifcount 1 killit 
ifvarvare sprite[THISACTOR].x scanx ifvarvare sprite[THISACTOR].y scany ifvarvare sprite[THISACTOR].z scanz sizeat 96 96 
else 
sizeat 32 32
ifvare player[THISACTOR].rapid_fire_hold YES cstat 32768 else
cstator 146
ifvarn playertarg -1 
	action SCANKILL
enda

useractor notenemy LOBTRAIL 0 
ifcount 1 killit
ifvare countvar 0 killit 
sizeat 6 6
cstator 658
ifvarand countvar 1 cstator 4
enda


useractor notenemy METALHOLE 0
ifmove 0
{
	sizeat 3 3
	cstator 2
	move INIT
	insertspriteq
	eqspawn INNERHOLE
	{
		getactor[THISACTOR].cstat temp
		subvar temp 2
		setactor[RETURN].cstat temp
		setactor[RETURN].xrepeat 3
		setactor[RETURN].yrepeat 3
		setactor[RETURN].ang sprite[THISACTOR].ang
	}
}
enda

useractor notenemy ORGANICHOLE 0
ifmove 0
{
	sizeat 8 8
	move INIT
	insertspriteq
}
enda

useractor notenemy WOODHOLE 0
ifmove 0
{
	iffloordistl 2 sizeat 6 3 else
	sizeat 4 4
	cstator 2
	move INIT
	insertspriteq
	eqspawn 6281
	{
		getactor[THISACTOR].cstat temp
		subvar temp 2
		setactor[RETURN].cstat temp
		setactor[RETURN].xrepeat 4
		setactor[RETURN].yrepeat 4
		setactor[RETURN].ang sprite[THISACTOR].ang
	}
}
enda

useractor notenemy SAWBLADEGROUND 0

ifmove 0 
{
	cstat 256
	sizeat 40 40 move INIT 
	setvar bouncesound BOUNCEMETALSND
	setvar weight WEIGHT2
}

ifvare mtype 1 killit

state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 
	{
		ifvarvare gravitysprite THISACTOR killit else
		state throwitem
	}
	break
}
else ifmove PHOLDING move INIT geth 
state pickupcode

fall
strength 0
ifhitweapon
{
state HITMETALSOUND
	state sparkstate 
}


enda

eventloadactor SPAWNER
{
	getactor[THISACTOR].lotag lotag
	ifvarn lotag 0 // lotag -1 = activate on sight, lotag 1 = activates when player enters sector; 2 or > = activated remotely
	{
		setactor[THISACTOR].lotag 0
		getactor[THISACTOR].hitag hitag // the tilenum of the monster it spawns
		// pal is applied to spawned monsters
		getactor[THISACTOR].shade monstatus // number of monsters it spawns
		ifvare monstatus 0 setvar monstatus 1
		// negative monstatus makes it spawn forever
		getactor[THISACTOR].xvel droptile // what the monsters drop
		setactor[THISACTOR].xvel 0
		getactor[THISACTOR].yvel activator // what is activated when last monster spawns
		setactor[THISACTOR].yvel 0
		getactor[THISACTOR].extra monstflags // flags of monsters
		ifvare monstflags -1 setvar monstflags 0
		setactor[THISACTOR].extra -1
		getactor[THISACTOR].zvel countvarb // the number of ticks between spawns
		ifvarl countvarb 1 setvar countvarb 1
		getactor[THISACTOR].sectnum mysector
		getactor[THISACTOR].pal pal
		getactor[THISACTOR].z initz
		subvar initz 8192
		setactor[THISACTOR].cstat 32768
	}
}
enda


useractor notenemy SPAWNER 0
ifvare lotag 0 break

ifvare lotag 1 // activates when player in sector
{
	getplayer[THISACTOR].cursectnum temp
	ifvarvare temp mysector setvar mtype 1
} 
else ifvare lotag -1 setvar mtype 1

else ifvare mtype 0
{
	setvarvar temp lotag
	checkactivatormotion temp
	ifvare RETURN 1 setvar mtype 1
}

ifvare mtype 1
{
	ifvare countvar 0
	{
		ifvarg pal 25
		{
			setvarvar countvar pal
			setvar pal 0
			spritepal 0
			break
		}
		ifvare monstatus 0 
		{
			ifvarn activator 0 state activatorstate
			setvar activator 0
			killit
			break
		}
		ifvarg hitag 2245 ifvarl hitag 2267
		{
			state aimjib
			ezshootvar zdist hitag
			state setjib
		}
		else
		{
			ifvarg droptile -1 
			{
				espawn TRANSPORTERSTAR
				ifvare hitag NEWBEAST setactor[RETURN].pal 6 else
				setactor[RETURN].pal pal
				setactor[RETURN].z initz
				setactor[RETURN].xrepeat 64
				setactor[RETURN].yrepeat 64
			}
			espawnvar hitag
			setactorvar[RETURN].droptile droptile
			setactor[RETURN].pal pal
			setactorvar[RETURN].monstflags monstflags
		}
		ifvarand morefx 32 setactor[RETURN].mdflags 1
		setvarvar countvar countvarb
		subvar monstatus 1
	}
	subvar countvar 1
}
enda

eventloadactor WEAPONS

getactor[THISACTOR].lotag lotag
ifvare lotag 1
{
	getactor[THISACTOR].extra startweapons
	setactor[THISACTOR].lotag 0
	killit
}

enda

eventloadactor INVENTORYOPTIONS

ifvare sprite[THISACTOR].lotag 1
{
	getactor[THISACTOR].extra startinventory
	setactor[THISACTOR].lotag 0
	killit
}

enda

state guideit
// assumes that target is set
	
state gradualturn
getactor[THISACTOR].z z
getactor[target].z mz
setvarvar zdist mz
subvarvar zdist z
getactor[target].extra hp
ifvarg hp 0 subvar zdist 8192 // seek down to feet if dead to dispose of body
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1
shiftvarl zdist 9 // multiplies zdist by 512
divvarvar zdist xydist // zdist now holds the desired z vel
//ifactor FIREBALLPROJ mulvar zdist -1
setactor[THISACTOR].zvel zdist
// z angle now set		
ends

state randtraj // randomize the trajectory of a projectile

randvar tempb 16
getactor[THISACTOR].ang angvar
ifrnd 128 addvarvar angvar tempb else subvarvar angvar tempb
setactor[THISACTOR].ang angvar
randvar tempb 512
getactor[THISACTOR].zvel zdist
ifrnd 128 addvarvar zdist tempb else subvarvar zdist tempb
setactor[THISACTOR].zvel zdist
ends

gamearray glassarray 2048
action GLASS4 -305 1 1 1 1

eventloadactor GLASS
getactor[THISACTOR].lotag lotag
setactor[THISACTOR].lotag 0
getactor[THISACTOR].hitag hitag
setactor[THISACTOR].hitag 0

ifvare clearglassarray 1
{
	setvar clearglassarray 0
	setvar spriteid 0
	whilevarn spriteid 2048
	{
		setarray glassarray[spriteid] -1
		addvar spriteid 1
	}
}

ifvarn lotag 0
{
	setvar spriteid 0
	whilevarn spriteid 2048 // max number of breakable glass sprites
	{
		setvarvar temp glassarray[spriteid]
		ifvare temp -1
		{
			setvarvar position spriteid
			setarray glassarray[spriteid] THISACTOR
			ifvarvarg position highglass setvarvar highglass position
			setvar spriteid 2047
		}
		addvar spriteid 1
	}
}
enda

action GLASSBREAK 2 5 1 1 3
action GLASSCRACK 2 1 1 1 1

useractor notenemy GLASS 50

ifvare lotag 0 break

ifaction 0 ifvare lotag 2 action GLASS4

ifaction GLASSBREAK
{
	ifactioncount 5 
	{
		lotsofglass 10
		setarray glassarray[position] -1
		ifvarvare position highglass subvar highglass 1
		killit
	}
	break
}

ifvarg sprite[THISACTOR].htextra 0 ifvarg hitag 0 ifvare mtype 0
{
	getactor[THISACTOR].htpicnum picnum
	getactor[THISACTOR].htowner myspawner
	setvar spriteid 0
	setvarvar tempb highglass
	addvar tempb 1
	whilevarvarn spriteid tempb
	{
		setvarvar tempc glassarray[spriteid]
		ifvarn tempc -1 ifvarvarn tempc THISACTOR
		{
			getactorvar[tempc].hitag tempd
			ifvarvare hitag tempd
			{
				getactor[tempc].htextra digx
				ifvarl digx 1
				{
					setactor[tempc].htextra sprite[THISACTOR].htextra
					setactor[tempc].htpicnum picnum
					setactor[tempc].htowner myspawner
					setactorvar[tempc].mtype 1
				}
			}
		}
		addvar spriteid 1
	}
	
}

ifaction GLASSCRACK strength 0

ifhitweapon
{
	setvar mtype 0
	ifaction GLASS4 { action GLASSCRACK soundonce GLASSCRACKSND } else
	ifaction 0 { action GLASSCRACK soundonce GLASSCRACKSND } else
	ifaction GLASSCRACK { action GLASSBREAK soundonce GLASS_BREAKING } //else
	ifdead { action GLASSBREAK soundonce GLASS_BREAKING }
	ifaction GLASSBREAK
	{
		getactor[THISACTOR].cstat temp
		ifvarand temp 1 xorvar temp 1
		ifvarand temp 256 xorvar temp 256
		setactor[THISACTOR].cstat temp
	}
}
	

enda

eventloadactor DPCHAIN

getactor[THISACTOR].yvel activator
setactor[THISACTOR].yvel 0
getactor[THISACTOR].lotag lotag
setactor[THISACTOR].lotag 0
enda

useractor notenemy DPCHAIN 0

ifvare lotag 0 break
cstator 256
strength 0

ifhitweapon ifwasweapon SHOTSPARK1
{
	state HITMETALSOUND
  	state sparkstate
  	debris SCRAP3 2
  	ifvarn activator 0 state activatorstate
  	killit
}
enda


eventloadactor FUSE
getactor[THISACTOR].extra monstflags
getactor[THISACTOR].cstat initcstat
ifvare monstflags 1 cstator 32768
getactor[THISACTOR].hitag hitag
setactor[THISACTOR].hitag 0
getactor[THISACTOR].lotag lotag
setactor[THISACTOR].lotag 0
getactor[THISACTOR].xvel peractor1
getactor[THISACTOR].yvel activator
getactor[THISACTOR].zvel topladder
setvar bouncesound GENERICBOUNCE
setactor[THISACTOR].pitch 512
enda

useractor notenemy FUSE 0

ifspawnedby APLAYER sizeat 12 12

ifvare lotag 0 break

ifmove 0
{
	move INIT
	setvar weight WEIGHT1
	setactor[THISACTOR].pitch 512
}

ifvarn topladder 0 // topladder can be set to 0 by an activation, making the fuse useable
	break


ifvare monstflags 1 // destination fuse
{
	ifpdistl 1024 ifcansee 
	ifp pfacing
	{
		ifvarn holding -1 
		ifvare mtype 0
		{
			getactor[holding].picnum picnum
			ifvare picnum FUSE
			{
				getactorvar[holding].hitag temp
				ifvarvare temp hitag ifvarl hitag 11
				{
					setactorvar[holding].mtype 1
					setactor[THISACTOR].cstat initcstat
					sound LASERTRIP_ONWALL
					setvar mtype 1
					setvarvar tempb fusegroups[hitag]
					addvar tempb 1
					setarray fusegroups[hitag] tempb
					ifvarvare fusegroups[hitag] peractor1
					state activatorstate
				}
				
			}
		}
		else ifhitspace quote 1086
	}
	break
}


ifvare mtype 1
{
	ifvarvare holding THISACTOR state throwitem
	killit
}

state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvare gravitysprite -1 ifhitspace state throwitem
	break
}

ifmove PHOLDING move INIT geth

fall
setactor[THISACTOR].pitch 512
state pickupcode

enda

// action ANULLACTION 0

action SHELLROLLING -1 2 1 1 6
action SHELLSTOPPED -1 1 1 1 1

move SHELLROLL1 48
move SHELLBOUNCE 48 -20
move SHELLBOUNCE2 48
move SHELLROLL2	32
move SHELLROLL3 16
move SHELLSTOP

state shellcode
fall

setvar temp 0
ifvarg underwater 0 setvar temp 1
ifinwater setvar temp 1
ifvare temp 1
{
	ifmove SHELLSTOP nullop else
	{
		ifmove SHELLROLL3 nullop else
		move SHELLROLL3 geth
	}
}

ifvare countvar 0
{
  setactor[THISACTOR].pitch 512
  clipdist 8
  setvar countvar 1
  getactor[THISACTOR].ang angvar
  randvar temp 256
  ifrnd 128 mulvar temp -1
  addvarvar angvar temp
  setactor[THISACTOR].ang angvar
  move SHELLBOUNCE geth getv
  ifactor 2534 // bullet shell
  {
	  action SHELLROLLING
	  ifrnd 128 sound SHELLFALL1 else sound SHELLFALL2
  }
  else // shotgun shell
  {
	  ifrnd 128 sound SHELLFALL3 else sound SHELLFALL4
  }
  resetcount
  cstat 384
}

ifmove SHELLBOUNCE ifcount 6
{
	move SHELLBOUNCE2 geth
	resetcount
}

ifmove SHELLBOUNCE2
{
	getactor[THISACTOR].zvel temp
	ifvarg temp 96 setactor[THISACTOR].zvel 96
	setvar tempb 0
	iffloordistl 1 setvar tempb 1
	ifcount 8 setvar tempb 1
	ifvare tempb 1
	{
		ifrnd 128 move SHELLROLL2 geth else
	  	move SHELLROLL1 geth
	  	ifactor 3509 { ifmove SHELLROLL1 move SHELLROLL2 geth else move SHELLROLL3 geth }
	    resetcount
    }
}


ifmove SHELLROLL1 ifcount 22 { move SHELLROLL2 geth resetcount }
ifmove SHELLROLL2 ifcount 16 { move SHELLROLL3 geth resetcount }
ifmove SHELLROLL3 
  ifcount 12
    ifrnd 32 
{
	 setactor[THISACTOR].mdflags 2
     move SHELLSTOP
     ifactor 2534 action SHELLSTOPPED
     ifrnd 128 cstat 388
     
     getflorzofslope sprite[THISACTOR].sectnum sprite[THISACTOR].x sprite[THISACTOR].y z // z is the return var
     setactor[THISACTOR].z z
}

ifnotmoving
{
	getactor[THISACTOR].ang angvar
	addvar angvar 1024
	randvar temp 256
	ifrnd 128 mulvar temp -1
	addvarvar angvar temp
	setactor[THISACTOR].ang angvar
}

ifhitweapon
{
	getactor[THISACTOR].htang angvar
	ifactor 2534 espawn SHELL else
	espawn SHOTGUNSHELL
	setactor[RETURN].ang angvar
	randvar temp 32
	addvar temp 96
	setactor[RETURN].xvel temp
	killit
}

ifspawnedby APLAYER { ifcount 1560 killit }
else
ifcount 260 killit

ends


move CANROLL

state canrollingcode

ifmove CANROLL
{
	getactor[THISACTOR].ang angvar
	cos xvel angvar
	sin yvel angvar
	mulvarvar xvel weap
	mulvarvar yvel weap
	divvarvar xvel initx
	divvarvar yvel inity
	setvar temp 0
	ifvarg underwater 0 setvar temp 1
	ifinwater setvar temp 1
	ifvare temp 1
	{
		shiftvarr xvel 2
		shiftvarr yvel 2
	}
	addvar initx 2
	addvar inity 2
	setvar zvel 0
	movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN
	ifvare RETURN 0
	{
		ifvarg initx 1024 move SHELLSTOP
		ifvarl xvel 0 mulvar xvel -1
		ifvarl yvel 0 mulvar yvel -1
		addvarvar xvel yvel
		shiftvarl xvel 2
		getactor[THISACTOR].pitch temp
		mulvarvar xvel weap
		addvarvar temp xvel
		setactor[THISACTOR].pitch temp
	}
	else 
	{
		mulvar weap -1
		shiftvarl initx 2
		shiftvarl inity 2
	}

}

ends

action CANSQUISHED 0 1 1
action CANCRUSHED 2 1 1
action CANCRUSHED2 1 1 1
// action CANFRAG 2 1 1


useractor notenemy COLACANSTAND 5
ifmove 0
{
	cstator 257
	sizeat 20 20
	clipdist 8
	move INIT
}

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 { state throwitem break }
	ifhitspace ifcount 26 ifaction 0
	{
		getactor[THISACTOR].pal pal
		ifvarn pal 40 ifvarn pal 50
		ifvare drinksoda 0
		{
			sound SODA_OPEN
			setvar drinksoda 1
		}
		
	}
	ifvarg drinksoda 0
	{
		ifspritepal 0 spritepal 40
		ifspritepal 10 spritepal 50
		ifvarg drinksoda 20 ifvarl drinksoda 52
		{
			getactor[THISACTOR].pitch temp
			addvar temp 24
			setactor[THISACTOR].pitch temp
		}
	}
	ifcansee nullop else setvar holding -1
	break
}
else ifmove PHOLDING move INIT geth 
state moveitem
fall
getactor[THISACTOR].pal pal
ifaction CANSQUISHED nullop else
ifvarg pal 39
  iffloordistl 2
	ifp palive
	 ifcansee
	   ifpdistl 640
	   {
		 cactor COLACANSTAND
	     pstomp
	     action CANSQUISHED
	     break
       }
state pickupcode

ifhitweapon
{
	ifaction 0
	{
		action CANCRUSHED
		setvar bouncesound SODACANLAND
		espawn BLOODPOOL
		setactorvar[RETURN].mtype 1
		espawn NEWSPLASH
		setactor[RETURN].pal 2
		setvar bouncesound SODACANLAND
	}
	else
	{
		debris SCRAP1 1
		killit
	}
}
enda


useractor notenemy COLACANSIDE 5
ifmove 0
{
	cstator 257
	sizeat 20 20
	clipdist 8
	setactor[THISACTOR].roll 512
	move INIT
	ifspawnedby COLACANSIDE nullop else move CANROLL geth
	setvar initx 64
	setvar inity 64
	ifrnd 128 setvar weap 1 else
	{
		getactor[THISACTOR].ang angvar
		addvar angvar 1024
		setactor[THISACTOR].ang angvar
		setvar weap -1
	}
}

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 { state throwitem break }
	ifhitspace ifcount 26 ifaction 0
	{
		getactor[THISACTOR].pal pal
		ifvarn pal 40 ifvarn pal 50
		ifvare drinksoda 0
		{
			sound SODA_OPEN
			setvar drinksoda 1
		}
		
	}
	ifvarg drinksoda 0
	{
		ifspritepal 0 spritepal 40
		ifspritepal 10 spritepal 50
		ifvarg drinksoda 20 ifvarl drinksoda 52
		{
			getactor[THISACTOR].pitch temp
			addvar temp 24
			setactor[THISACTOR].pitch temp
		}
	}
	ifcansee nullop else setvar holding -1
	break
}
else ifmove PHOLDING move INIT geth 
state moveitem
fall
getactor[THISACTOR].pal pal
ifaction CANSQUISHED nullop else
ifvarg pal 39
  iffloordistl 2
	ifp palive
	 ifcansee
	   ifpdistl 640
	   {
		 cactor COLACANSTAND
	     pstomp
	     action CANSQUISHED
	     break
       }
state pickupcode


getactor[THISACTOR].xvel xvel

ifhitweapon
{
	ifaction 0
	{
		cactor COLACANSTAND
		setactor[THISACTOR].roll 0
		setactor[THISACTOR].pitch 0
		action CANCRUSHED
		setvar bouncesound SODACANLAND
		espawn BLOODPOOL
		setactorvar[RETURN].mtype 1
		espawn NEWSPLASH
		setactor[RETURN].pal 2
	} else
	{
		debris SCRAP1 1
		killit
	}
}

state canrollingcode

enda

action WOODCRATE 1 1 1 1 1

move CRATEPUSH 128
move CRATEPUSHSLOW 64

useractor notenemy CRATE1 0
ifmove 0
{
	//sizeat 64 64
	sizeat 16 16
	cstat 257
	setvar initcstat 257
	setvar weight WEIGHT3
	ifspritepal 30 action WOODCRATE
}
clipdist 64

ifhitweapon
{
	strength 0
	ifwasweapon SHOTSPARK1
	{
		ifspritepal 0
		{
  			state HITMETALSOUND
  			state sparkstate
		}
 		else
 		ifspritepal 30
 			state WOODHITSOUND
	}
}

state moveitem

ifvarvare holding THISACTOR
{
	cstator 2
	ifvarn pickup 0 break
	ifvare gravitysprite -1 ifhitspace state throwitem
	break
}

ifmove PHOLDING move INIT geth
cstat 257
getactor[THISACTOR].zvel temp
ifvarg temp 0 setvar mtype 1 // falling
ifvare mtype 1 ifvare temp 0 
{ 
	ifspritepal 30 sound ENDSEQVOL2SND4 else sound METALTHUD
	setvar mtype 0
}


fall
state pickupcode

enda

useractor notenemy CRATE2 0
ifmove 0
{
	//sizeat 112 112
	sizeat 32 32
	cstat 257
	setvar initcstat 257
	setvar weight WEIGHT4
	ifspritepal 30 action WOODCRATE
}

clipdist 128

ifhitweapon
{
	strength 0
	ifwasweapon SHOTSPARK1
	{
		ifspritepal 0
		{
  			state HITMETALSOUND
  			state sparkstate
		}
 		else
 		ifspritepal 30
 			state WOODHITSOUND
	}
}

state moveitem

getactor[THISACTOR].zvel temp
ifvarg temp 0 setvar mtype 1 // falling
ifvare mtype 1 ifvare temp 0 
{ 
	ifspritepal 30 nullop else sound METALTHUD
	setvar mtype 0
}


fall
state gravpickupcode

ifp phigher nullop else
ifp pfacing 
    ifp palive
       ifvarand extbits 1
         ifpdistl 1280
           ifp ponground
             ifhitspace
{

	setvar temp 0
	ifp pducking setvar temp 1
	ifp pwalking setvar temp 1
	ifvare temp 1
	{
		ifmove CRATEPUSHSLOW nullop else
		move CRATEPUSHSLOW geth
	} else
	{
		ifmove CRATEPUSH nullop else
		move CRATEPUSH geth
	}
	getplayer[THISACTOR].ang angvar
	setactor[THISACTOR].ang angvar
	cstator 2
	soundonce 148
	
}
else ifcount 3
{
	cstat 257
	ifmove CRATEPUSH move INIT
	ifmove CRATEPUSHSLOW move INIT
}

enda


state EJECTCOLA

espawn COLACANSIDE
getactor[RETURN].z mz
subvarvar mz initz
setactor[RETURN].z mz
setvar countvar 0
getactor[THISACTOR].ang angvar
randvar temp 48
ifrnd 128 mulvar temp -1
addvarvar angvar temp
setactor[RETURN].ang angvar
ifrnd 128 setactor[RETURN].pal 10
addvar countvarb 1 // how many cans have spawned
ifvarg countvarb 20 killit
ends

useractor notenemy COLAMACHINE 0

ifvarn lotag 1 break

ifmove 0
{
	cstator 16
	move INIT
	ifvarg initz 0 divvar initz  4 else setvar initz 4096
}

ifpdistl 1280
  ifp pfacing
    ifhitspace
      ifcount 12
        ifvarl countvar 2
          ifvare holding -1
{
	resetcount
	addvar countvar 1
	sound COINSLOT
}

ifvarg countvar 1
{
	stopsound DUKE_GRUNT
	addvar countvar 1
	ifvare countvar 26 sound DISPENSE_CAN
	ifvare countvar 52 
		state EJECTCOLA
}

getwall[myspawner].picnum picnum
ifvarn picnum COLAMACHINE // if the wall has changed picnum, the machine is broken
{
	ifcount 12
	{
		addvar countvarb 1
		state EJECTCOLA 
		resetcount
		ifrnd 8 killit
		ifvarg countvarb 20 killit
	}
	ifrnd 16 stopsound DISPENSE_CAN
	soundonce DISPENSE_CAN
}
	
enda

useractor notenemy 2534 0 state shellcode enda // SHELL +1

useractor notenemy SSHELLGROUND 0 state shellcode enda // shotgunshell

action JIBSTILL3 -2 1 1 1 1
action JIBSTILL2 0 1 1 1 1
action JIBSTILL -1 1 1 1 1

spritenoshade BLOODPOOL

state jibcode

ifvare countvar 0
{
	cstat 256
	ifrnd 128 cstator 4
	action JIBSTILL
	setvar countvar 1
	espawn BLOODPOOL
	ifspritepal 6 // prevent spawned pool from causing damage
	{
		setactor[RETURN].pal 0 
		setactorvar[RETURN].mtype 6 
		setactor[RETURN].mdflags 16 
	}
	setactorvar[RETURN].monstatus 1
	ifactor 1770 strength 50
	ifactor 2203 strength 50
}

ifactor PIGHEADG
{
	getactor[THISACTOR].zvel temp
	ifvarg temp 0 setvar mtype 1 // falling
	ifvare mtype 1 ifvare temp 0 ifvare peractor4 0
	{
		ifrnd 128 sound JIBLAND else sound JIBLAND2
		setvar mtype 0
	}
	state moveitem
	
	state pickupcode
	ifvarvare holding THISACTOR
	{
		ifvarn pickup 0 break
		ifvarand bits 4 { state throwitem break }
		ifhitspace setvar holding -1
		ifcansee nullop else setvar holding -1
		break
	}
	else ifmove PHOLDING move INIT geth 
}

fall

ifactor PIGHEADG nullop else
strength 0
ifhitweapon 
	ifdead { guts JIBS6 2 killit }
	
ends

action JIBMODELFRAME1 4026 1 1 1 1

state jibcode2
ifvare countvar 0
{
	setvar countvar 1
	//ifactor 2264 ifvare effects YES action JIBMODELFRAME1
	//else
	ifactor 1770 action JIBSTILL3 else
	ifactor 1774 action JIBSTILL3 else
	ifactor 1778 action JIBSTILL3 else
	ifactor 2203 action JIBSTILL3 else
	ifactor 2207 action JIBSTILL3 else
	ifactor 2211 action JIBSTILL3 else
	action JIBSTILL2
	cstat 256
	ifrnd 128 cstator 4
	ifvarn mtype -1
	{
		ifspritepal 6 // prevent spawned pool from causing damage
		{
			spritepal 0
			espawn BLOODPOOL
			getlastpal
			setactorvar[RETURN].mtype 6 
			setactor[RETURN].mdflags 16
		}
		else
		{
			espawn BLOODPOOL
			setactorvar[RETURN].monstatus 1
		}
	}
	ifactor 1770 strength 50 else
	ifactor 2203 strength 50 else
	strength 0
}
ifvare peractor1 0 ifvarl sprite[THISACTOR].zvel 1
{
	setvar peractor1 1 // has landed
	ifvarn sprite[THISACTOR].picnum 2259
	{
		ifspritepal 1 sound GLASSCRACKSND else
		ifrnd 128 sound JIBLAND else sound JIBLAND2
	}
}
ifvare peractor1 1 ifvarg sprite[THISACTOR].zvel 0 setvar peractor1 0


setvar temp 0
ifactor 1770 setvar temp 1
ifactor 2203 setvar temp 1
ifvare temp 1
{
	state moveitem
	state pickupcode
	ifvarvare holding THISACTOR
	{
		ifvarn pickup 0 break
		ifvarand bits 4 { state throwitem break }
		ifhitspace setvar holding -1
		ifcansee nullop else setvar holding -1
		break
	}
	else ifmove PHOLDING move INIT geth
}
else
{
	addvar countvar 1
	ifvare countvar 208 cstator 2
	ifvare countvar 234 cstator 512
	ifvarg countvar 260 killit
}
fall

ifhitweapon ifdead
{
	guts JIBS6 2 
	killit 
}


ends

useractor notenemy 2203 ifvare command 1 state jibcode2 enda // LIZMANHEAD
useractor notenemy 2207 ifvare command 1 state jibcode2 enda // LIZMANARM
useractor notenemy 2211 ifvare command 1 state jibcode2 enda // LIZMANLEG


useractor notenemy 2249 ifvare command 1 state jibcode2 enda // JIBS1 = spine
useractor notenemy 2254 ifvare command 1 state jibcode2 enda // JIBS2 = eyeball
useractor notenemy 2259 ifvare command 1 state jibcode2 enda // JIBS3 = heart
useractor notenemy 2264 ifvare command 1 state jibcode2 enda // JIBS4 = guts
useractor notenemy 2269 ifvare command 1 state jibcode2 enda // JIBS5 = ribcage

useractor notenemy 1770 ifvare command 1 state jibcode2 enda // TROOPHEAD
useractor notenemy 1774 ifvare command 1 state jibcode2 enda // TROOPARM
useractor notenemy 1778 ifvare command 1 state jibcode2 enda // TROOPLEG

useractor notenemy  PIGHEADG state jibcode action ANULLACTION enda
useractor notenemy  PIGUPPERG state jibcode action ANULLACTION cstat 256 enda
useractor notenemy  PIGUPPER2G state jibcode action ANULLACTION cstat 256 enda
useractor notenemy  PIGLOWERG state jibcode action ANULLACTION cstat 256 enda
useractor notenemy  PIGLOWER2G state jibcode action ANULLACTION cstat 256 enda

eventloadactor CORONA1

	getactor[THISACTOR].hitag hitag
	getactor[THISACTOR].lotag lotag
	setactor[THISACTOR].lotag 0

enda

eventloadactor CORONA2

	getactor[THISACTOR].hitag hitag
	getactor[THISACTOR].lotag lotag
	setactor[THISACTOR].lotag 0

enda

eventloadactor CORONA3

	getactor[THISACTOR].hitag hitag
	getactor[THISACTOR].lotag lotag
	setactor[THISACTOR].lotag 0

enda

eventloadactor MAPSTAR

	getactor[THISACTOR].lotag lotag
	getactor[THISACTOR].hitag hitag
	ifvarn lotag 0 ifvarn hitag 0
	{
		setactor[THISACTOR].lotag 0
		setactor[THISACTOR].hitag 0
		setvar temp 1
		setvar tempb 0
		whilevarvarn tempb hitag
		{
			mulvar temp 2
			addvar tempb 1
		}
		readgamevar completed
		ifvarvarand temp completed nullop else cstat 32768	
	}
enda
	


state coronacode

ifvarn lotag 1 break
sleeptime -1
ifmove 0
{
	move INIT
	spriteflags 4
	getactor[THISACTOR].shade shade
	subvar shade 100
	ifvarl shade -127 setvar shade -127
	setactor[THISACTOR].shade shade
	getactor[THISACTOR].z z
	subvar z 3072
	setactor[THISACTOR].z z
	ifvarn hitag 0 setvarvar initx hitag else
	setvar initx 12 // initx is the minimum size of the sprite
	getactor[THISACTOR].cstat peractor1
}
setactor[THISACTOR].cstat peractor1
cstator 642
getplayer[THISACTOR].i target
dist xydist THISACTOR target
shiftvarr xydist 8
ifvarl xydist 0 setvar xydist 0
addvarvar xydist initx
ifvarg xydist 255 setvar xydist 255
ifpdistl 1280 cstat 32768
setactor[THISACTOR].xrepeat xydist
setactor[THISACTOR].yrepeat xydist

ends

useractor notenemy CORONA1 0 state coronacode enda
useractor notenemy CORONA2 0 state coronacode enda
useractor notenemy CORONA3 0 state coronacode enda

eventloadactor JUMPAD
	readgamevar scaled
	getactor[THISACTOR].extra monstflags
	ifvare monstflags -1 setvar monstflags 0
	getactor[THISACTOR].lotag lotag
	getactor[THISACTOR].hitag hitag
	ifvare hitag 0 setvar hitag 640
	getactor[THISACTOR].xvel initx
	getactor[THISACTOR].yvel inity
	ifvare inity 0 setvar inity 26
	getactor[THISACTOR].zvel initz
	mulvar initz -8
	ifvare scaled YES
	{
		mulvar initx 2
		mulvar initz 3
		divvar initz 2
	}

enda

eventloadactor SPARKER

getactor[THISACTOR].lotag lotag
setactor[THISACTOR].lotag 0
ifvare lotag 1 cstat 32768
getactor[THISACTOR].hitag hitag
setactor[THISACTOR].hitag 0

enda

useractor notenemy SPARKER 0

//ifspawnedby APLAYER { cstat 32768 setvar lotag 1 sizeat 32 32 setvar hitag 20 }
ifspawnedby SHOTSPARK1 { sound SPARKING2 state sparkstate state sparkstate killit }
ifvare lotag 0 break

addvar countvar 1
ifvarvarg countvar hitag ifrnd 32
{
	move INIT randomangle
	spawn SPARKFALL
	setvar countvar 0
	ifrnd 128 sound SPARKING1 else sound SPARKING2
}

enda

useractor notenemy JUMPAD 0
ifvarn lotag 1 break

ifcount 18 ifvarand monstflags 1
{
	resetcount
	setvarvar temp initz
	subvar temp 2048
	ezshoot temp SPARKPROJ2
	setactor[RETURN].xvel initx
	setthisprojectile[RETURN].vel initx
	setvarvar temp inity
	addvar temp 13
	setthisprojectile[RETURN].range temp
}

cstat 32768
getplayer[THISACTOR].i spriteid
ldist xydist THISACTOR spriteid
ifvarvarl xydist hitag
{
	getplayer[THISACTOR].falling_counter temp
	ifvarg temp 8
	{
	    ifpdistg 1560 setvar temp 0
    }
    else
    {
	    ifpdistl 1024 setvar temp 1
	    else ifpdistl 1560 ifvarn dodge 0 setvar temp 1
	    else setvar temp 0
    }
	ifvarn temp 0
	{
		getplayer[THISACTOR].i spriteid
		getactor[spriteid].z mz
		subvar mz 4096
		setactor[spriteid].z mz
		getplayer[THISACTOR].posz z
		subvar z 4096
		setplayer[THISACTOR].posz z
		setplayer[THISACTOR].jumping_counter 0
		setplayer[THISACTOR].jumping_toggle 0
		setplayer[THISACTOR].poszv initz
		getactor[THISACTOR].ang dodgeang
		setvarvar dodge inity
		setvarvar jumpadxvel initx
		setplayer[THISACTOR].falling_counter 0
		setvar nofalldamage 1
		soundonce LAUNCHSND
	}
}
	
enda

action LIGHTBUGFRAME 21 1 1 1 1
action LIGHTHALOFRAME  3 1 1 1 1
spritenoshade LIGHTBUG2
spritenoshade LIGHTHALO

move BUGMOVE1 16 -16
move BUGMOVE2 16 16

useractor notenemy LIGHTBUG2 0
ifmove 0
{
	ifvare lotag 2
	{
		getactor[THISACTOR].sectnum mysector
		setactor[THISACTOR].htactorstayput mysector
	}
	action LIGHTBUGFRAME
	cstat 0
	sizeat 3 3
	move BUGMOVE1 geth getv
	espawn LIGHTHALO
	setactorvar[RETURN].myspawner THISACTOR
	getactor[THISACTOR].pal pal
	setactor[RETURN].pal pal
	setvarvar myspawner RETURN
	setvar tempd 2
	// ifvare rendmode 4 
	// { 
		setvar intensity 2560 
		state spawnpointlight 
	// }
}


ifcount 52 ifrnd 64
{
	ifpdistl 1560 move BUGMOVE1 geth getv furthestdir
	else
	iffloordistl 8 move BUGMOVE1 geth getv randomangle else
	ifceilingdistl 16 move BUGMOVE2 geth getv randomangle
	else
	ifrnd 128 move BUGMOVE1 geth getv randomangle 
	else
	move BUGMOVE2 geth getv randomangle
	ifrnd 128 setvar mtype 1 else setvar mtype 0
}

getactor[THISACTOR].ang angvar
ifvare mtype 0 addvar angvar 16 else subvar angvar 16
setactor[THISACTOR].ang angvar
enda


useractor notenemy LIGHTHALO 0 LIGHTHALOFRAME

ifmove 0
{
	move INIT
	sizeat 10 10
	cstat 514
	cstator 128
	getactor[THISACTOR].cstat initcstat
}


getactor[myspawner].zvel zvel
ifvarl zvel 0 subvar z 256
setsprite THISACTOR sprite[myspawner].x sprite[myspawner].y sprite[myspawner].z

enda

action RAINFRAME 0 1 1 1 1
action SNOWFRAME 71 1 1 1 1

action RAINSPLASH -3821 9 1 1 3

move SNOWFALL 16 16
move SNOWFALL2 16 20

spritenopal RAINSPRITE
useractor notenemy RAINSPRITE 0
fall

ifvarg underwater 0 killit else
ifinwater killit else
ifvare raining 0 killit

ifaction RAINFRAME
{
	sizeto 8 42
	iffloordistl 2 action RAINSPLASH else
	ifnotmoving action RAINSPLASH
} else
ifaction RAINSPLASH 
{
	sizeat 16 16
	ifactioncount 9 killit
}
else
ifaction 0
{
	cstator 8192
	setactor[THISACTOR].mdflags 1
	spriteflags 16
	ifoutside nullop else killit
	ifvarl framerate 6 killit
	ifvarg raining 0
	{
		action RAINFRAME
		sizeat 8 15
		setactor[THISACTOR].zvel 2048
		
	}
	else
	{
		action SNOWFRAME
		ifrnd 128
		move SNOWFALL geth getv randomangle
		else move SNOWFALL2 geth getv randomangle
		ifrnd 128 cstator 4
		ifrnd 128 cstator 8
		randvar x 3 addvar x 3
		randvar y 3 addvar y 3
		setactor[THISACTOR].xrepeat x
		setactor[THISACTOR].yrepeat y
	}

	setactor[THISACTOR].pal rainpal
	ifvarand raincstat 512 cstator 514 else
	ifvarand raincstat 2 cstator 2
}
else
{
	ifnotmoving killit
	iffloordistl 4 killit
	ifvarvarg sprite[THISACTOR].z player[THISACTOR].posz
	ifpdistg 16384 killit
}

enda

action WATERSPLASH3FRAMES -165 5 1 1 9

useractor notenemy WATERSPLASH3 0 WATERSPLASH3FRAMES
ifmove 0
{
	move INIT
	sizeat 12 12
	cstator 128
	ifrnd 128 cstator 4
}
	

ifactioncount 5 killit

enda

move INKMOVE 644


useractor notenemy INKBLAST 0
ifmove 0
{
	getactor[THISACTOR].owner myspawner
	move INKMOVE geth
	sizeat 45 160
	cstat 514
	ifrnd 128 cstator 4
	ifrnd 128 cstator 8
	spritepal 4
	getplayer[THISACTOR].i spriteid
	getactor[spriteid].z peractor1
	subvarvar peractor1 sprite[THISACTOR].z
	
	ldist xydist THISACTOR spriteid
	ifvare xydist 0 setvar xydist 1
	mulvar peractor1 644
	divvarvar peractor1 xydist
	shiftvarr peractor1 1
}
getactor[THISACTOR].z z
addvarvar z peractor1
randvar temp 768
ifrnd 128 mulvar temp -1
addvarvar z temp
setactor[THISACTOR].z z

getactor[THISACTOR].ang angvar
randvar temp 16
ifrnd 128 mulvar temp -1
addvarvar angvar temp
setactor[THISACTOR].ang angvar

getactor[THISACTOR].htmovflag spriteid
ifvarn spriteid 0
{
	// hit something
	addvar spriteid 16384
    ifvarl spriteid 16384 ifvarg spriteid -1
    {
	    getactor[spriteid].htextra temp
	    addvar temp 2
	    setactor[spriteid].htextra temp
	    setactor[spriteid].htpicnum INKBLAST
	    setactor[spriteid].htowner myspawner
    }
    killit
}
ifactioncount 15 killit

enda

action BOTMARKERFRAME -5 1 1 1 1

useractor notenemy BOTMARKER 0 BOTMARKERFRAME

spritepal 4
cstat 2
sizeat 42 36
ifcount 1 killit

enda

spritenoshade BOMBTARG

useractor notenemy BOMBTARG 0

setactor[THISACTOR].shade -100
cstat 32
sizeat 64 64
ifcount 1 killit

enda

action TARGHEAD -1845 1 1
useractor notenemy SHOOTME 0
ifmove 0
{
	move INIT
	sizeat 32 32
	cstat 32768
	sleeptime -1
}

ifvare sprite[myspawner].statnum 1024 killit else
setsprite THISACTOR sprite[myspawner].x sprite[myspawner].y sprite[myspawner].z

getactorvar[myspawner].playerally playerally
ifvarvare playertarg THISACTOR 
{
	ifaction TARGHEAD cstat 0
	ifp pfacing nullop else setvar playertarg -1
	ifvarn playertarg -1
	{
		getactorvar[myspawner].monstatus monstatus
		ifvarl sprite[myspawner].extra 1 setvar playertarg -1 
		else ifvarn monstatus 1 setvar playertarg -1
		//else ifvarn actorvar[myspawner].monstatus 1 setvar playertarg -1
		else ifvarn sprite[myspawner].statnum 1 setvar playertarg -1 
		else ifhitspace setvar playertarg -1
		ifvarn playertarg -1
		{
			subvar z 12288
			setactor[THISACTOR].z z
			action TARGHEAD
			spritepal 10
			sizeat 16 16
		}
	}
	break
}
ifcount 26 killit

enda

useractor notenemy SHOOTMEALLY 0

ifvarn lotag 1 break
ifmove 0
{
	cstat 32768
	move INIT
	sizeat 12 12
}

getactor[myspawner].x x
getactor[myspawner].y y
getactor[myspawner].z z
getactor[myspawner].yrepeat temp
mulvar temp 360 //384
getactor[myspawner].picnum picnum
switch picnum
case BOSS1
case BOSS2
case BOSS3
case BOSS4
mulvar temp 3 divvar temp 2
break
default break
endswitch
subvarvar z temp
subvar z 1560
setactor[THISACTOR].z z
setactor[THISACTOR].y y
setactor[THISACTOR].x x
ifcount 27 killit
ifvarn sprite[myspawner].statnum 1 break
ifvarg picnum 6499 break // spawned by civilian
ifcount 1 cstat 2
enda

eventloadactor BOTALLY

getactor[THISACTOR].lotag lotag
setactor[THISACTOR].lotag 0
ifvare lotag 1
{
	getactor[THISACTOR].extra monstflags
	ifvare monstflags -1 setvar monstflags 0
	// 1 = awake at start
	// 2 = double strength
	// 4 = quadruple strength
	// 8 = Medic
	// 16 = has shotgun
	// 32 = has chaingun
	// 64 = has RPG
	// 128 = has freezer
	sizeat 42 36
	getactor[THISACTOR].xvel droptile
}

enda

eventloadactor BOTALLYSTAYPUT

getactor[THISACTOR].lotag lotag
setactor[THISACTOR].lotag 0
ifvare lotag 1
{
	getactor[THISACTOR].extra monstflags
	ifvare monstflags -1 setvar monstflags 0
	sizeat 42 36
	getactor[THISACTOR].xvel droptile
	getactor[THISACTOR].sectnum mywall
	setactor[THISACTOR].htactorstayput mywall
	cactor BOTALLY
}

enda


action ALLYPGROWING   -26
action ALLYPSTAND     -26   1   5   1  1
action ALLYPEXPLODE   87   5   1   1   10
action ALLYPEXPLODEAD   87   1   1
action ALLYPJPHOUVER  -11   1   5   1
action ALLYPWALK    -6   4   5   1   16
action ALLYPRUN     -6   4   5   1   10
action ALLYPWALKBACK  19   4   5  -1   16
action ALLYPRUNBACK   19   4   5  -1   10
action ALLYPJUMPING   24   4   5   1   18 //26
action ALLYPFALLING   34   1   5
// separate actor for ducking
action ALLYPDUCKING   0   1   5
action ALLYPCRAWLING  0   3   5   1   20

action ALLYPAKICKING  14   2   5   1   25

action ALLYPFLINTCHING  80  1   1   1   10
action ALLYPTHROWNBACK  35  5   1   1   18
action ALLYPFROZEN     -6  1   5
action ALLYPLYINGDEAD   48  1   1

action ALLYPSWIMMINGGO   349   1   5   1   10
action ALLYPSWIMMING   349   4   5   1   13
action ALLYPSWIMMINGWAIT 369   1   5   1   13
action ALLYPTREDWATER  369   2   5   1   17

move ALLYJUMPVEL 180 -80
move ALLYJUMPBACKVEL -180 -80
move ALLYRUNVEL 256 0
move ALLYRUNVEL2 256 0 // used for nonfollowing bots
move ALLYWALKVEL 160 0
move ALLYSWIMUP 128 -48
move ALLYSWIMDOWN 128 48
move ALLYJETUP 192 -48
move ALLYJET 192 -8
move ALLYJETDOWN 192 48
move ALLYRUNBACKVEL -192 0
move BOTSHRUNKVELS 48
move ALLYSTOP

ai AIBOTPATH ALLYPWALK ALLYWALKVEL geth
ai AIBOTSEEKPLAYER ALLYPRUN ALLYRUNVEL seekplayer
ai AIBOTSTOPPED ALLYPSTAND ALLYSTOP geth
ai AIBOTWANDER ALLYPWALK ALLYWALKVEL randomangle
ai AIBOTFACEPLAYER ALLYPRUN ALLYRUNVEL faceplayer
ai AIBOTDODGE ALLYPRUN ALLYSTOP geth
ai AIBOTDYING ALLYPTHROWNBACK ALLYSTOP geth
ai AIBOTSWIM ALLYPSWIMMING ALLYWALKVEL seekplayer
ai AIBOTJET ALLYPJPHOUVER ALLYJETUP faceplayerslow getv
ai AIBOTMEDIC ALLYPRUN ALLYRUNVEL geth
ai AIBOTFLINTCH ALLYPFLINTCHING ALLYSTOP geth
ai AIBOTCHARGE ALLYPRUN ALLYRUNVEL geth // allies only
ai AIBOTFROZEN ALLYPFROZEN ALLYSTOP geth
ai AIBOTSHRUNK ALLYPRUN BOTSHRUNKVELS randomangle

state botchecksight

ifvarvare target THISACTOR { setvar target -1 break }

getactor[THISACTOR].z z
subvar z 8192
setactor[THISACTOR].z z
getactor[target].z mz
subvar mz 8192
setactor[target].z mz
canseespr THISACTOR target tempc
addvar z 8192
setactor[THISACTOR].z z
addvar mz 8192
setactor[target].z mz
ifvare tempc 0 setvar target -1

ifvarn target -1
{
	getactorvar[target].monstatus temp
	ifvare temp 2 setvar target -1
}
ifvarn target -1
{
	getactor[target].cstat temp
	ifvarand temp 256 nullop else setvar target -1
	ifvarand temp 32768 setvar target -1
}

ends

state getceilz
  getactor[THISACTOR].x x
  getactor[THISACTOR].y y
  updatesector x y mysector
  ifvare mysector -1 getsector[THISACTOR].ceilingz z
  else
  getceilzofslope mysector x y z
ends

useractor notenemy SHOOTER 0
ifvare lotag 0 
break

ifvare lotag 1 setvar lotag -1
ifvare lotag -1 setvar mtype 1

else ifvare mtype 0
{
	setvarvar temp lotag
	checkactivatormotion temp
	ifvare RETURN 1 setvar mtype 1
}

ifvare mtype 1
{
	strength 0
	ifvarand monstflags 64 { cstator 256 ifhitweapon killit }
	ifvare countvar 0
	{
		ifvarg pal 25
		{
			setvarvar countvar pal
			setvar pal 0
			spritepal 0
			break
		}
		ifvare monstatus 0 
		{
			ifvarn activator 0 state activatorstate
			setvar activator 0
			killit
			break
		}
		setvar target -1
		ifvarand monstflags 2
		{
			// aim at player and friends
			ifcansee getplayer[THISACTOR].i target
			ifvare target -1
			ifvarg numallies 0
			{
				findnearactorz BOTALLY 16384 65536 target
				ifvarn target -1 state checksight
			}
			ifvare target -1
			ifvarg monallies 0
			{
				findnearactorz SHOOTMEALLY 16384 65536 target
				ifvarn target -1 
				{
					getactorvar[target].myspawner target
					state botchecksight
				}
			}
		}
		ifvare target -1
		ifvarand monstflags 4
		{
			// aim at bad guys
			findnearactorz SHOOTME 16384 65536 target
			ifvarn target -1 
			{
				getactorvar[target].myspawner target
				state botchecksight
			}
		}
		setvarvar countvar countvarb
		ifvare target -1
		{
			ifvarand monstflags 2 break
			ifvarand monstflags 4 break
		}
		setvar zvel 0
		ifvarn target -1
		{
			getactor[target].x mx
			getactor[target].y my
			getactor[THISACTOR].x x
			getactor[THISACTOR].y y
			subvarvar mx x
			subvarvar my y
			getangle angvar mx my
			setactor[THISACTOR].ang angvar
			
			state calczdist
			ldist xydist THISACTOR target
			ifvare xydist 0 setvar xydist 1
			
			// multiply zvel by the speed of the projectile
			switch hitag
			case FIRELASER
			case COOLEXPLOSION1
			case SHRINKER
			case ELECTROPROJ
			case STARPROJ
			case SAWBLADEPROJ
			setvar xvel 768
			break
			
			case RPG
			case RPGNOAIM
			case FREEZEBLAST
			case FREEZENOAIM
			setvar xvel 644
			break
			
			case SHOTSPARK1
			case SHOTGUN
			case CHAINGUN
			case MP5BULLET
			case GROWSPARK
			case GRAVPROJ2
			setvar xvel 256
			break
			
			case ICESHARD
			setvar xvel 1024
			break
			
			case FIREBULLET
			case RAILSLUG_WEAK
			case DPCANNONBALL
			setvar xvel 844
			break
			
			case FIREBALLPROJ
			setvar xvel 384
			break
			
			default
			setvar xvel 768
			break
			
			endswitch
	
			mulvarvar zdist xvel
			divvarvar zdist xydist
			
			ezshootvar zdist hitag
			ifvarand monstflags 256
			{
				getactor[RETURN].htflags temp
				orvar temp 256
				setactor[RETURN].htflags temp
			}
			ifvarn bouncesound -1 soundvar bouncesound
		}
		else 
		{
			setactor[THISACTOR].ang position
			ezshootvar peractor1 hitag
			ifvarn hitag SHOTSPARK1
			ifvarn hitag SHOTGUN
			ifvarn hitag CHAINGUN
			ifvarn hitag MP5BULLET
			ifvarn hitag GROWSPARK
			ifvarn hitag GRAVPROJ2
			{
				setactor[RETURN].ang position
				ifvarand monstflags 256
				{
					getactor[RETURN].htflags temp
					orvar temp 256
					setactor[RETURN].htflags temp
				}
			}
		}
		
		ifvarand monstflags 8
		ifvarn hitag SHOTSPARK1
		ifvarn hitag SHOTGUN
		ifvarn hitag CHAINGUN
		ifvarn hitag MP5BULLET
		ifvarn hitag GROWSPARK
		ifvarn hitag GRAVPROJ2
		{
			// randomized trajectory
			randvar tempb 16
			getactor[RETURN].ang angvar
			ifrnd 128 addvarvar angvar tempb else subvarvar angvar tempb
			setactor[RETURN].ang angvar
			randvar tempb 512
			getactor[RETURN].zvel digz
			ifrnd 128 addvarvar digz tempb else subvarvar digz tempb
			setactor[RETURN].zvel digz
		}
		subvar monstatus 1
		
	}
	subvar countvar 1
	ifvarg targetlock 0 subvar targetlock 1
	ifvarand monstflags 16 ifrnd 32 addvar countvar 1
}
enda

state botexitarray

// exit array
setarray botallies[position] -1
subvar numallies 1
ifvarvare highally position ifvarg position 0
{
	subvar highally 1
	ifvarg highally 0
	{
		setvarvar temp botallies[highally]
		ifvare temp -1 subvar highally 1
	}
}
ends

state botfindtarget

setvar target -1

findnearactorz SHOOTME 4096 32768 spriteid
ifvarn spriteid -1 getactorvar[spriteid].myspawner target
ifvarn target -1 state validatetarget
ifvarn target -1 break

findnearactorz SHOOTME 8192 65536 spriteid
ifvarn spriteid -1 getactorvar[spriteid].myspawner target
ifvarn target -1 state validatetarget
ifvarn target -1 break

findnearactorz SHOOTME 12288 98304 spriteid
ifvarn spriteid -1 getactorvar[spriteid].myspawner target
ifvarn target -1 state validatetarget
ifvarn target -1 break

findnearactorz SHOOTME 18432 147456 spriteid
ifvarn spriteid -1 getactorvar[spriteid].myspawner target
ifvarn target -1 state validatetarget

findnearactorz SHOOTME 32768 262144 spriteid
ifvarn spriteid -1 getactorvar[spriteid].myspawner target
ifvarn target -1 state validatetarget

ends

state botdrop

ifvarn droptile 0
{
	ifvarl droptile 11 nullop else
	ifvare droptile 62 { espawn ACCESSCARD setactor[RETURN].pal 21 } else
	ifvare droptile 63 { espawn ACCESSCARD setactor[RETURN].pal 23 } else
	espawnvar droptile
	setvar droptile 0
	break
}
ifvarand monstflags 128 spawn FREEZESPRITE else
ifvarand monstflags 64 spawn RPGSPRITE else
ifvarand monstflags 32 spawn CHAINGUNSPRITE else
ifvarand monstflags 16 spawn SHOTGUNSPRITE else
spawn FIRSTGUNSPRITE

ends

state botfrozenstate
 
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick

    ifcount THAWTIME
    {
      ai AIBOTSTOPPED
      strength 1
      getlastpal
      setactor[THISACTOR].htextra -1
      setactor[THISACTOR].htpicnum -1
      break
    }
    else
      ifcount FROZENDRIPTIME
        ifactioncount 26
          resetactioncount

    ifhitweapon
    {
	    ifwasweapon FREEZEBLAST break
	    ifwasweapon FREEZENOAIM break
	    lotsofglass 30
	    state standard_pjibs
        sound GLASS_BREAKING

		 state botdrop
		 userquote 1002
		 state botexitarray
		 ifrnd 84
		          spawn BLOODPOOL
		
		 killit
	 }
	    

ends

state botshrunkstate
  setactor[THISACTOR].htextra -1
  ifcount SHRUNKDONECOUNT
  {
    ai AIBOTSTOPPED
    cstat 257
  }
  else
    ifcount SHRUNKCOUNT
      sizeto 42 36
  else
  {
    state genericshrunkcode
    findnearactor3d SHOOTME SQUISHABLEDISTANCE spriteid
    ifvarn spriteid -1
    {
	    sound SQUISHED
	    state standard_pjibs
	    spawn BLOODPOOL
	    sound DUKE_DEAD
	    userquote 1008
	    state botexitarray
	    killit
    }
  }
    
ends

state botdyingstate

setvar command 0
ifvarvare botselected THISACTOR setvar botselected -1

ifaction ALLYPTHROWNBACK ifactioncount 5 
{
	action ALLYPLYINGDEAD
	cstat 256
}
strength 0
ifhitweapon
{
	ifwasweapon RADIUSEXPLOSION
	{
		state standard_pjibs
		killit
	}
}


ends

state botjumpcode

setvar temp 0
ifaction ALLYPRUN setvar temp 1
ifaction ALLYPWALK setvar temp 1

ifnotmoving 
  ifcount 8 
    ifrnd 64
      ifvare temp 1
{
	ifrnd 128 operate
	else
	{
		// either jump or move backwards
		getactor[THISACTOR].ang angvar
		cos xvel angvar
		sin yvel angvar
		shiftvarr xvel 11
		shiftvarr yvel 11   
		setvar zvel 0
		movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN
		ifvarn RETURN 0
		{
			// peractor6 is the last value of RETURN when movesprite bumped into something
			ifvarvare RETURN peractor6
			{
				// dodge in random backwards direction
				setvar bouncesound -1
				setvar temp 640
				randvar tempb 640
				addvarvar temp tempb
				ifrnd 128 mulvar temp -1
				addvarvar angvar temp
				setvarvar peractor1 angvar
				setvar botdodge 8
				cactor BOTALLY
				ai AIBOTDODGE
				setvar peractor6 -1
				break
			}
			else
			{
				getactor[THISACTOR].htmovflag spriteid
				addvar spriteid 16384
		    	ifvarl spriteid 16384 ifvarg spriteid -1 ifvare sprite[spriteid].statnum 1 nullop else // don't jump on actor contact
			    {
					cactor BOTALLY
					action ALLYPJUMPING
					move ALLYJUMPVEL geth getv
				}
			}
		}
		else
		{
			getactor[THISACTOR].htmovflag spriteid
			addvar spriteid 16384
	    	ifvarl spriteid 16384 ifvarg spriteid -1 ifvare sprite[spriteid].statnum 1 nullop else // don't jump on actor contact
		    {
				cactor BOTALLY
				action ALLYPJUMPING
				move ALLYJUMPVEL geth getv
				setvarvar peractor6 RETURN
			}
		}
	}
}
ifaction ALLYPJUMPING
{
	ifceilingdistl 48
	{
		action ALLYPFALLING
		move ALLYRUNVEL geth
	} else
	ifactioncount 2
	{
		action ALLYPFALLING
		move ALLYRUNVEL geth
	} else
	ifcount 18
	{
		ifcansee
		{
			action ALLYPFALLING
			move ALLYRUNVEL geth
		}
		else ifcount 26 // cheat to jump higher when player not watching
		{
			action ALLYPFALLING
			move ALLYRUNVEL geth
		}
	}
}
ifaction ALLYPFALLING iffloordistl 2
{
	ai AIBOTSEEKPLAYER
// 	action ALLYPRUN
// 	ifai AIBOTSEEKPLAYER move ALLYRUNVEL seekplayer else
// 	ifai AIBOTFACEPLAYER move ALLYRUNVEL faceplayer else
// 	ifai AIBOTWANDER move ALLYWALKVEL geth
	state landsounds
}
ends


state pistolfire

state shelleject
ifvare dpsounds NO
sound PISTOL_FIRE
else
sound DPPISTOLFIRE
state calczdist
// ifvarg zdist -2048 ifvarl zdist 2048
// {
// 	shoot SHOTSPARK1
// 	break
// }
shiftvarl zdist 8
divvarvar zdist xydist
zshoot zdist SHOTSPARK1
zshoot zdist SHOTSPARK1

ends

state shotgunfire
sound SHOTGUN_FIRE
subvar ammo 5
state calczdist
ifvarg zdist -2048 ifvarl zdist 2048
{
	addvar z 3072
	setactor[THISACTOR].z z
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	subvar z 3072
	setactor[THISACTOR].z z
	break
}
shiftvarl zdist 8
divvarvar zdist xydist
zshoot zdist SHOTGUN
zshoot zdist SHOTGUN
zshoot zdist SHOTGUN
zshoot zdist SHOTGUN
zshoot zdist SHOTGUN
zshoot zdist SHOTGUN
zshoot zdist SHOTGUN

ends

state chaingunfire
sound CHAINGUN_FIRE
state shelleject
subvar ammo 1
state calczdist
// ifvarg zdist -2048 ifvarl zdist 2048
// {
// 	shoot CHAINGUN
// 	break
// }
shiftvarl zdist 8
divvarvar zdist xydist
zshoot zdist CHAINGUN

ends

state rpgfire
state calczdist
mulvar zdist 644 // multiplies zdist the speed of the projectile
divvarvar zdist xydist // zdist now holds the desired z velocity
sound RPG_SHOOT
zshoot zdist RPGNOAIM
subvar ammo 10
ends

state freezerfire
state calczdist
mulvar zdist 644
divvarvar zdist xydist
sound CAT_FIRE
zshoot zdist FREEZENOAIM
subvar ammo 2
ends


state switchweapon
ifvarl ammo 1 
{
	setvar weap 2 break
}
ifvarand monstflags 64
{
	dist xydist2 THISACTOR target
	subvar xydist2 384
	ifvarg xydist2 RPGBLASTRADIUS { setvar weap 5 break }
}

ifvarand monstflags 128 ifrnd 160 { setvar weap 10 break }
ifvarand monstflags 32
{
	ifvarand monstflags 16
	{
		ifrnd 160 { setvar weap 4 break }
	}
	else { setvar weap 4 break }
}
ifvarand monstflags 16 { setvar weap 3 break }
ifvarand monstflags 128 { setvar weap 10 break }
setvar weap 2

ends


state botfiringcode

state visibilitycheck
ifvare target -1 break

    ifvare weap 0 state switchweapon

	switch weap

	case 2:  // pistol
		ifvarl botclip 1
		{
		   ifvare weapcount 3 sound EJECT_CLIP
		   ifvare weapcount 12 sound INSERT_CLIP
		   ifvarg weapcount 27 
		   {
		   		setvar botclip 12
				state switchweapon
		   }
		}
		else
		{
		   ifvare weapcount 2 state pistolfire	
		   ifvarg weapcount 4 
			{
				subvar botclip 1
				setvar weapcount 0     
			}
		 }
		break

	case 3:  // shotgun

		ifvare weapcount 4 state shotgunfire
		ifvare weapcount 15 sound SHOTGUN_COCK
		ifvare weapcount 20 state shelleject2
		ifvarg weapcount 30 
		{ 
		    setvar weapcount 0
		}
		break

	case 4:   // chaingun
	case 14 // flak
		ifvarg weapcount 2 
		{
			ifvare weap 4 state chaingunfire // else state flakfire
			setvar weapcount 0
		}
		
		break	
		
	case 5:   // RPG
	case 15   // railgun
		
		ifvare weapcount 4 
		{
			ifvare weap 5 state rpgfire 
			//else state railgunfire 
		}
		ifvarg weapcount 19
		{ 
		  setvar weapcount 0 
		}
		break


	
	 case 10:  // freezer
	 case 20:  // lightning gun
	 
	 	ifvare weapcount 2
	 	 { 
		 	  ifvare weap 10 state freezerfire
		 	  // else state lightningfire
		 }
	
		ifvarg weapcount 4 
			{ 
				setvar weapcount 0 
				ifvare weap 10
				{
					  getactor[target].pal temp
					  ifvare temp 1 setvar weap 2
				}
			 }
	break
	default break
	endswitch
	
addvar weapcount 1	

ends

state botdodgestate

ifvare command 1
{
	ifawayfromwall nullop else
	{
		setvar botdodge 0
		ai AIBOTSTOPPED
		break
	}
}
cos xvel peractor1
sin yvel peractor1
shiftvarr xvel 6
shiftvarr yvel 6
setvar zvel 0
movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN

ifvare botdodge 0 
{
//ifaction ALLYPJPHOUVER ai AIBOTJET else 
ai AIBOTSTOPPED
}

ends

state checkbotdodge

ifvarand monstflags 1024 break

	ifvare botdodge 0
	{
		getactor[THISACTOR].picnum picnum
		cactor PIGCOP
		findnearactorz BOTALLY 4096 16384 spriteid
		ifvare spriteid -1 findnearactor SHOOTME 4096 spriteid
		ifvare spriteid -1 ifvare CURRWEAP 10 findnearspritez HEAVYHBOMB 4096 10240 spriteid
		setactor[THISACTOR].picnum picnum
		ifvarn spriteid -1
		{
			getactor[spriteid].x mx
			getactor[spriteid].y my
			getactor[THISACTOR].x x
			getactor[THISACTOR].y y
			subvarvar mx x
			subvarvar my y
			getangle peractor1 mx my
			addvar peractor1 896
			randvar temp 256
			addvarvar peractor1 temp
			setvar botdodge 10
			cactor BOTALLY
			ai AIBOTDODGE
			//ifp pjetpack action ALLYPJPHOUVER
		}
		ifvare botdodge 0
		{
			getactor[THISACTOR].ang angvar
			ifbulletnear
			{
				setactor[THISACTOR].ang angvar
				setvar temp 384
				randvar tempb 256
				addvarvar temp tempb
				ifrnd 128 mulvar temp -1
				addvarvar angvar temp
				setvarvar peractor1 angvar
				setvar botdodge 10
				cactor BOTALLY
				ai AIBOTDODGE
				//ifp pjetpack action ALLYPJPHOUVER
			}
		}
		
	}

ends

state startdodge

setvar temp 384
randvar tempb 256
addvarvar temp tempb
ifrnd 128 mulvar temp -1
getactor[THISACTOR].ang angvar
addvarvar angvar temp
setvarvar peractor1 angvar
setvar botdodge 6
cactor BOTALLY
ai AIBOTDODGE

ends

state botstoppedstate

	ifvarn target -1
	{
		state checkbotdodge
		ifvare botdodge 0
		ifvarn command 1
		ifvarvare scannedsprite THISACTOR
		ifrnd 32
		state startdodge
		else
		{
			ldist xydist THISACTOR target
			ifvarg xydist 5120 { cactor BOTALLY ai AIBOTCHARGE }
		}
		
	}
	else
	{
		ifvare CURRWEAP 10 { state checkbotdodge ifai AIBOTDODGE break }
		ifvare command 2
		{
			ifpdistl 2816
			{
				getactorvar[myspawner].target2 temp
				ifvarn temp 0 // waypoint is waiting on an activation
				{
					ldist xydist THISACTOR myspawner
					ifvarl xydist 256 break
				}
				ifcount 20
				{
					cactor BOTALLY
					ai AIBOTPATH
				}
			} 

			break
		}
		else
		ifpdistg 1560 ifvarn command 1 // not patrolling
		{
			getplayer[THISACTOR].cursectnum temp
			getactor[THISACTOR].sectnum mysector
			ifvarvarn temp mysector
			{
				cactor BOTALLY
				ai AIBOTSEEKPLAYER
				break
			}
			ifpdistg 4096 ifcansee
			{
				cactor BOTALLY
				ai AIBOTFACEPLAYER
				break
			}
		}
		ifpdistl 896 ifvare botdodge 0
		{
			getplayer[THISACTOR].posx mx
			getplayer[THISACTOR].posy my
			getactor[THISACTOR].x x
			getactor[THISACTOR].y y
			subvarvar mx x
			subvarvar my y
			getangle peractor1 mx my
			addvar peractor1 896
			randvar temp 256
			addvarvar peractor1 temp
			setvar botdodge 6
			cactor BOTALLY
			ai AIBOTDODGE
			break
		}
		ifrnd 16
		{
			cactor BOTALLY
			ai AIBOTWANDER
		}
	}
ends

state botseekplayerstate

	ifaction ALLYPJUMPING nullop else ifaction ALLYPFALLING nullop else
	{
		ifvare CURRWEAP 10 { state checkbotdodge ifai AIBOTDODGE break }
		ifvarn target -1 
		{
			setvar bouncesound -1
			ai AIBOTSTOPPED 
			ifrnd 184 
			{ 
				cactor BOTALLYCROUCH 
				action ALLYPDUCKING 
			}
			break 
		}
		ifpdistl 1560 ifcansee ifvarn command 2 // command 2 == following waypoints
		{
			setvar bouncesound -1
			ai AIBOTSTOPPED 
			ifrnd 160 
			{ 
				cactor BOTALLYCROUCH 
				action ALLYPDUCKING 
			}
			break 
		}
	}
	
	ifactornotstayput
	state botjumpcode
	
	ifvare command 2 break
	
	// player trail code

	ifvarn bouncesound -1
	{
		setvarvar spriteid ptrails[bouncesound]
		ifvare spriteid -1 { setvar bouncesound -1 move ALLYRUNVEL seekplayer }
		else
		{
			ldist tempd THISACTOR spriteid
			ifvarl tempd 512 
			{
				addvar bouncesound 1
				setvarvar tempb bouncesound
				whilevarn tempb 100
				{
					setvarvar spriteid ptrails[tempb]
					ifvare spriteid -1 { setvar bouncesound -1 setvar tempb 100 } else
					{
						ldist tempd THISACTOR spriteid
						ifvarl tempd 384 
						{ 
							addvar tempb 1 
							ifvare tempb 100 setvar bouncesound -1
							getactorvar[spriteid].mtype temp
							ifvare temp 1 iffloordistl 4
							{
								 cactor BOTALLY
								 action ALLYPJUMPING
								 move ALLYJUMPVEL geth getv
							}
						}
						else { setvarvar bouncesound tempb setvar tempb 100 }
					}
				}
				ifvare bouncesound 100 setvar bouncesound -1 
			}
			else
			{
				getactor[spriteid].x mx
				getactor[spriteid].y my
				subvarvar mx sprite[THISACTOR].x
				subvarvar my sprite[THISACTOR].y
				getangle angvar mx my
				setactor[THISACTOR].ang angvar
			}
		}
	}
	else
	ifactornotstayput
 	{
		setvar temp 99
		whilevarn temp -1
		{
			setvarvar spriteid ptrails[temp]
			ifvarn spriteid -1
			{
				canseespr THISACTOR spriteid tempc
				ifvare tempc 1
				{
					ldist tempd THISACTOR spriteid
					ifvarg tempd 1024
					{
						getactor[spriteid].x mx
						getactor[spriteid].y my
						subvarvar mx sprite[THISACTOR].x
						subvarvar my sprite[THISACTOR].y
						getangle angvar mx my
						setactor[THISACTOR].ang angvar
						setvarvar bouncesound temp
						move ALLYRUNVEL geth
						setvar temp 0
					}
				}
			}
			subvar temp 1
		}
 	}

	
// 	ifcansee ifaction ALLYPRUN
// 	{
// 		getplayer[THISACTOR].cursectnum temp
// 		getactor[THISACTOR].sectnum mysector
// 		ifvarvare temp mysector
// 		{
// 			setvar bouncesound -1
// 			ai AIBOTFACEPLAYER
// 			break
// 		}
// 		ifrnd 4 { ai AIBOTFACEPLAYER setvar bouncesound -1 }
// 	}
	
// 	ifcount 130
// 	{
// 		ifawayfromwall nullop else
// 		ai AIBOTFACEPLAYER
// 	}

ends

state botwanderstate


ifaction ALLYPJUMPING nullop else ifaction ALLYPFALLING nullop else
{
	ifvarn target -1 
	{
		ai AIBOTSTOPPED 
		ifrnd 184 
		{ 
			cactor BOTALLYCROUCH 
			action ALLYPDUCKING
		}
		break 
	}
	ifpdistl 1560 break
	ifvare CURRWEAP 10 { state checkbotdodge ifai AIBOTDODGE break }
	
	getplayer[THISACTOR].cursectnum temp
	getactor[THISACTOR].sectnum mysector
	ifvarvarn temp mysector
	{
		ifpdistg 2048 ifvarn command 1 // not patrolling
		{
			ai AIBOTSEEKPLAYER
			break
		}
	}
	else ifpdistg 6144 ai AIBOTSTOPPED
}
ifactornotstayput
state botjumpcode
ifaction ALLYPJUMPING nullop else ifaction ALLYPFALLING nullop else ifnotmoving ifcount 10 
{
	ifrnd 128 move ALLYWALKVEL randomangle
	else
	{
		getactor[THISACTOR].ang angvar
		addvar angvar 1024
		setactor[THISACTOR].ang angvar
		ai AIBOTSTOPPED
		cactor BOTALLYCROUCH
		action ALLYPDUCKING
	}
}
ends

state botfaceplayerstate


ifaction ALLYPJUMPING nullop else ifaction ALLYPFALLING nullop else
{
	ifvarn target -1 
	{ 
		ai AIBOTSTOPPED 
		ifrnd 184 
		{ 
			cactor BOTALLYCROUCH 
			action ALLYPDUCKING 
		}
		break 
	}
	ifvare CURRWEAP 10 { state checkbotdodge ifai AIBOTDODGE break }
	ifpdistl 2048 { ai AIBOTSTOPPED break }
}
ifactornotstayput
state botjumpcode

ifcansee nullop else ifaction ALLYPRUN ifrnd 8 ai AIBOTSEEKPLAYER

ends

state botswimstate

setvar temp 0	
ifvarg underwater 0 setvar temp 1
ifinwater setvar temp 1
ifvare temp 0
{
	ai AIBOTSEEKPLAYER
	action ALLYPJUMPING
	move ALLYJUMPVEL geth getv
	count 20
	break
}

ifaction ALLYPSWIMMINGWAIT
{
	ifcount 26 
	{ 
		resetcount
		action ALLYPSWIMMING 
		move ALLYSWIMUP seekplayer getv 
	}
	break
} else
ifnotmoving 
{ 
	action ALLYPSWIMMINGWAIT 
	move ALLYSTOP 
	resetcount
}

ifp phigher
{
	ifmove ALLYSWIMUP nullop else move ALLYSWIMUP seekplayer getv
}
else
	ifmove ALLYSWIMDOWN nullop else move ALLYSWIMDOWN seekplayer getv


ends

state botchargestate

// AIBOTCHARGE

ifaction ALLYPJUMPING nullop else ifaction ALLYPFALLING nullop else
{
	ifvare target -1 
	{ 
		ai AIBOTSTOPPED 
		ifrnd 184 
		{ 
			cactor BOTALLYCROUCH 
			action ALLYPDUCKING 
		}
		break 
	}
	state checkbotdodge 
	ifai AIBOTDODGE break
}
ifactornotstayput
state botjumpcode

ifvarn target -1
{
	ldist xydist THISACTOR target
	ifvarl xydist 2560 ai AIBOTSTOPPED
	else ifcount 150 ai AIBOTSTOPPED
}
else ifcount 150 ai AIBOTSTOPPED

ends

state botjetstate

ifp pjetpack nullop else
{
	iffloordistl 32 ai AIBOTSEEKPLAYER else
	ifmove ALLYJETDOWN nullop else move ALLYJETDOWN faceplayerslow getv
	break
}
cactor BOTALLY
ifp phigher
{
	ifmove ALLYJETUP nullop else 
	{
		ifcansee move ALLYJETUP faceplayerslow getv else
		move ALLYJETUP seekplayer getv
	}
} else
{
	getplayer[THISACTOR].posz mz
	getactor[THISACTOR].z z
	ifvarvarg mz z
	{
		ifmove ALLYJETDOWN nullop else
		{
			ifcansee move ALLYJETDOWN faceplayerslow getv else
			move ALLYJETDOWN seekplayer getv
		}
	}
	else
	{
		ifmove ALLYJET nullop else
		{
			ifcansee move ALLYJET faceplayerslow getv else
			move ALLYJET seekplayer getv
		}
	}
}

ifpdistl 3072 move ALLYJET geth getv // freezes them if they get close by repeating the move command

ends

state healally

ifvarn target2 -1
{
	getactor[target2].extra hp
	ifvarl hp 100
	{
		subvar ammo 30
		addvar hp 30
		setactor[target2].extra hp
		sound DUKE_USEMEDKIT
		globalsound GETATOMICHEALTH
		espawn FIRSTAID
		setactorvar[RETURN].myspawner target2
		userquote 1001
	}
	setvar target2 -1
}

ends

state botmedicstate

getactor[target2].picnum picnum
ifvare picnum APLAYER
{
	getplayer[THISACTOR].posx mx
	getplayer[THISACTOR].posy my
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	subvarvar mx x
	subvarvar my y
	getangle angvar mx my
	setactor[THISACTOR].ang angvar
	
	ifcansee
	{
		ifpdistl 1024
		{
			addphealth 30
			subvar ammo 30
			sound DUKE_USEMEDKIT
			globalsound GETATOMICHEALTH
			espawn FIRSTAID
			setactorvar[RETURN].myspawner target2
			setvar target2 -1
			ai AIBOTSTOPPED
			cactor BOTALLYCROUCH
			action ALLYPDUCKING
			userquote 1000
		}
	}
	else
	{
		setvar target2 -1
		ai AIBOTSTOPPED
	}
	ifcount 130 { setvar target2 -1 ai AIBOTSTOPPED }
	break
}
ifvare target2 -1 { ai AIBOTSTOPPED break }
setvarvar target target2
state facetarget
ifvare target -1 setvar target2 -1
ifvare target2 -1 { setvar target -1 ai AIBOTSTOPPED break }
state botchecksight
ifvare target -1 setvar target2 -1
ifvare target2 -1 { setvar target -1 ai AIBOTSTOPPED break }
setvar target -1
dist xydist THISACTOR target2
ifvarl xydist 1024
{
	state healally
	ai AIBOTSTOPPED
	cactor BOTALLYCROUCH
	action ALLYPDUCKING 
}
ifcount 130 { setvar target2 -1 ai AIBOTSTOPPED }


ends

state checkhealth

ifai AIBOTDODGE break
ifai AIBOTSWIM break
ifai AIBOTJET break
ifai AIBOTMEDIC break

ifvarl ammo 1 break
getactor[THISACTOR].extra hp
ifvarl hp 70
{
	addvar hp 30
	subvar ammo 30
	setactor[THISACTOR].extra hp
	sound DUKE_USEMEDKIT
	espawn FIRSTAID
	setactorvar[RETURN].myspawner THISACTOR
	ifvarl ammo 1 break
}
ifcansee ifphealthl 70
{
	cactor BOTALLY
	ai AIBOTMEDIC
	setvar target -1
	getplayer[THISACTOR].i target2
	break
}
	
ifvarl highally 1 break
ifvarn target2 -1 break
setvar spriteid 0
setvarvar temp highally
addvar temp 1
whilevarvarn spriteid temp
{
	setvarvar tempb botallies[spriteid]
	ifvarn tempb -1
	{
		getactorvar[tempb].monstatus tempc
		ifvare tempc 1
		{
			getactor[tempb].extra hp
			ifvarl hp 70 ifvarg hp 0
			{
				getactor[THISACTOR].z z
				subvar z 8192
				getactor[tempb].z mz
				subvar mz 8192
				setactor[THISACTOR].z z
				setactor[tempb].z mz
				canseespr THISACTOR tempb tempc
				addvar z 8192
				addvar mz 8192
				setactor[THISACTOR].z z
				setactor[tempb].z mz
				ifvare tempc 1 // tempb is now the healing target
				{
					setvarvar target2 tempb
				}
			}
		}
	}
	addvar spriteid 1
	ifvarn target2 -1 
	{
		setvarvar spriteid temp
		setvar countvarb 0
		setactorvar[target2].countvarb 0
		cactor BOTALLY
		ai AIBOTMEDIC
		setvar target -1
	}
}

ends

state botpatrolstate

setvar countvarb 0
ifai AIBOTSTOPPED break
// ifai AIBOTDODGE break
// ifai AIBOTSWIM break
//ifai AIBOTJET break

// setvarvar temp initx
// getactor[THISACTOR].x x

// subvarvar temp x
// mulvarvar temp temp
// 	
// setvarvar tempb inity
// getactor[THISACTOR].y y
// subvarvar tempb y
// mulvarvar tempb tempb
// 	
// addvarvar temp tempb
// sqrt temp temp

// temp now = xydistance to patrol point

setvar tempc 0
getactor[THISACTOR].sectnum tempd
ifvarvarn tempd mywall setvar tempc 1
ifawayfromwall nullop else // prevents bot from leaving the sector and falling off a cliff
setvar tempc 1
// setvar temp 5120 
// ifvarg temp 4096
ifvare tempc 1
{
	ifai AIBOTWANDER nullop else ai AIBOTWANDER
	setvarvar mx initx
	setvarvar my inity
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	subvarvar mx x
	subvarvar my y
	getangle angvar mx my
	setactor[THISACTOR].ang angvar	
}

ends

state lookforpath // bot is not on a path but is looking for one
// myspawner is the ID of the current destination waypoint
// hitag is the lotag being checked

ifvarg numwaypoints 0
{
	ifvarvarg hitag numwaypoints setvar hitag 1
	setvarvar myspawner waypoints[hitag]
	getactor[THISACTOR].z z
	subvar z 8192
	setactor[THISACTOR].z z
	canseespr THISACTOR myspawner temp
	addvar z 8192
	setactor[THISACTOR].z z
	ifvare temp 1 
	{
		setvar fallflag 0
		setvar command 2
		cactor BOTALLY
		ai AIBOTPATH
		break
	}
	// the following is a failsafe that makes bots teleport to the path nodes if visibility fails
	setvar myspawner -1
	addvar hitag 1
	addvar fallflag 1
	ifvarg fallflag 77
	{
		setvar fallflag 0
		subvar teleported 1
		ifvare teleported 0 setvar teleported 1
		setvarvar hitag teleported
		setvarvar myspawner waypoints[hitag]
		getactor[myspawner].x x
		getactor[myspawner].y y
		getactor[myspawner].z z
		setsprite THISACTOR x y z
		setvar command 2
		cactor BOTALLY
		ai AIBOTPATH
	}
	
}
ends

state botpathstate // bot is on a path

setvar temp 0
ifvarn target2 -1 setvar temp 1
ifvarn target -1 setvar temp 1
ifvare myspawner -1 setvar temp 1
ifvare temp 1 // break from path
{
	//subvar hitag 1 ifvarl hitag 1 setvar hitag 1
	setvar myspawner -1
	setvar command 0
	break
}

// check distance to waypoint
ldist xydist THISACTOR myspawner


// if close, set next waypoint as target, or disable waypoint following if it is the last one (monstflags 1)
ifvarl xydist 256 //384
{
	getactorvar[myspawner].target2 temp
	ifvare temp 0 // waypoint is not waiting on an activation
	{
		state wakeupmonsters
		getactorvar[myspawner].activator activator
		ifvarn activator 0 state activatorstate
		setactorvar[myspawner].activator 0
		getactorvar[myspawner].monstflags temp
		ifvarand temp 1
		{
			subvar monstflags 256
			ifvarand monstflags 1024 subvar monstflags 1024
			setvar command 0
			setvar myspawner -1
			setvar hitag 1
			break
		}
		
// 		ifvarand monstflags 1024
// 		{
// 			ifvarand temp 2 nullop else
// 			ifpdistg 4096
// 			{
// 				ai AIBOTSTOPPED
// 				cactor BOTALLY
// 				break
// 			}
// 		}
		addvar hitag 1
		ifvarvarg hitag numwaypoints setvar hitag 1
		setvarvar teleported hitag // tag of last known good waypoint
		setvarvar myspawner waypoints[hitag]
	} else // waiting IS waiting on an activation
	{
		ifai AIBOTSTOPPED nullop else 
		{
			ai AIBOTSTOPPED
			cactor BOTALLY
		}
	}
}
else ifnotmoving
{
	getactor[THISACTOR].htmovflag spriteid
	addvar spriteid 16384
	ifvarl spriteid 16384 
	ifvarg spriteid -1 
	ifvare sprite[spriteid].picnum BOTALLY 
	{
		cactor BOTALLY
		ai AIBOTSTOPPED
	}
}
ifai AIBOTSTOPPED
{
	ifcansee ifpdistl 6144 nullop else
	ifvarg xydist 1024
	{
		ifvarg hitag 1
		{
			subvar hitag 1
			setvarvar myspawner waypoints[hitag]
			getactor[THISACTOR].z z
			subvar z 8192
			setactor[THISACTOR].z z
			canseespr THISACTOR myspawner temp
			addvar z 8192
			setactor[THISACTOR].z z
			ifvare temp 0 setvar myspawner -1
			else
			{
				cactor BOTALLY
				ai AIBOTPATH
			}
		}
	}
} else
{
	// face waypoint	
	//setvarvar target myspawner
	//state gradualturn
	//setvar target -1
	getactor[myspawner].x mx
	getactor[myspawner].y my
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	subvarvar mx x
	subvarvar my y
	getangle angvar mx my
	setactor[THISACTOR].ang angvar
	
	ifvarl targetlock 4
	{
		getactor[THISACTOR].z z
		subvar z 8192
		setactor[THISACTOR].z z
		canseespr THISACTOR myspawner temp
		addvar z 8192
		setactor[THISACTOR].z z
		ifvare temp 1 setvar targetlock 6 else
		ifvarl targetlock 2
		{
			operate
		}
	}
	
}

getactorvar[myspawner].monstflags temp
ifvarand temp 2 nullop else
ifvarand monstflags 1024 // lead player mode
{
	ifmove ALLYSTOP setvar botwait 10 else
	{
		iffloordistl 4 ifcount 10
		{
			ifpdistg 5120
			ai AIBOTSTOPPED else
			ifcansee nullop else
			ai AIBOTSTOPPED
			
			ifai AIBOTSTOPPED
			{
				cactor BOTALLY
			}
		}
	}
}
	
ifai AIBOTPATH nullop else ifai AIBOTSWIM nullop else
ifmove ALLYSTOP nullop else { cactor BOTALLY ai AIBOTPATH }

ends

state botgoodbye

state botexitarray
sound TELEPORTER
espawn TRANSPORTERSTAR
getactor[THISACTOR].z z
subvar z 8192
setactor[RETURN].z z
setactor[RETURN].xrepeat 96
setactor[RETURN].yrepeat 96
sound JIBBED_ACTOR2
killit
ends



state botallycode

ifvarand monstflags 1 nullop else
ifvare monstatus 0
{
	ifcansee nullop else break
}
ifmove 0
{
	spriteflags 3
	// greeting sound
	randvar temp 3
	switch temp
	case 0 sound BONUS_SPEECH1 break
	case 1 sound BONUS_SPEECH2 break
	case 2 sound JIBBED_ACTOR2 break
	case 3 sound DUKE_GETWEAPON6 break
	default break
	endswitch
	setvar hitag 1
	setvar monstatus 1
	cstat 257
	ai AIBOTSTOPPED
	sizeat 42 36
	randvar countvar 25
	clipdist 24 //32
	setvar bouncesound -1
	setvar playerally -1
	setvar botclip 12
	
	ifspawnedby APLAYER
	{
		ifspritepal 12 orvar monstflags 128
		ifspritepal 21 orvar monstflags 64
		ifspritepal 10 orvar monstflags 64
		ifspritepal 23 orvar monstflags 32
		ifspritepal 22 orvar monstflags 32
		ifspritepal 16 orvar monstflags 16
		ifspritepal 14 orvar monstflags 8
	}
	ifvarand monstflags 8 spritepal 14 else
	ifvarand monstflags 128 spritepal 12 else
	ifvarand monstflags 64 spritepal 21 else
	ifvarand monstflags 32 spritepal 23 else
	ifvarand monstflags 16 spritepal 16
	
	ifvarand monstflags 512
	{
		setvar command 1
		getactor[THISACTOR].x initx
		getactor[THISACTOR].y inity
		getactor[THISACTOR].sectnum mywall
	}
	
	getactor[THISACTOR].extra hp
	ifvarand monstflags 2 mulvar hp 2
	ifvarand monstflags 4 mulvar hp 4
	setactor[THISACTOR].extra hp
	ifvarand usebots 4
	{
		espawn LIFEBAR
		setactorvar[RETURN].myspawner THISACTOR
	}
	// enter array
	ifvare clearbotarray 1
	{
		setvar clearbotarray 0
		setvar spriteid 0
		whilevarn spriteid 128
		{
			setarray botallies[spriteid] -1
			addvar spriteid 1
		}
	}
	addvar numallies 1
	setvar spriteid 0
	whilevarn spriteid 128
	{
		setvarvar temp botallies[spriteid]
		ifvare temp -1
		{
			setarray botallies[spriteid] THISACTOR
			setvarvar position spriteid // permanently saves position in array for deletion later
			ifvarvarg position highally setvarvar highally position
			setvar spriteid 127
		}
		addvar spriteid 1
	}
}
fall


ifvarand monstflags 1024 // lead player mode
{
	getactor[THISACTOR].extra temp
	ifvarl temp 200 setactor[THISACTOR].extra temp
	setactor[THISACTOR].htextra -1
}

ifvare command 666 { state botgoodbye break }
ifvarl ammo 200 ifrnd 16 addvar ammo 1
ifvarg targetlock 0 ifrnd 208 subvar targetlock 1
getsector[THISACTOR].floorpicnum FLOORTEX
state CHECKSTEPS
ifaction ALLYPRUN ifactioncount 2 state stepsounds


ifai AIBOTDYING { state botdyingstate break }
ifai AIBOTFROZEN { state botfrozenstate break }
ifai AIBOTSHRUNK { state botshrunkstate break }

// getactor[THISACTOR].sectnum mysector
// ifvarg mysector -1 ifvarl mysector 4096
// {
// 	getactor[THISACTOR].x x
// 	getactor[THISACTOR].y y
// 	getactor[THISACTOR].z z
// 	getzrange x y z mysector digz hitz temp tempb tempc CLIPMASK0
	// digz is ceilingz, hitz is what is above
	// temp is floorz, tempb is what is below
// }


ifai AIBOTPATH state botseekplayerstate else
ifai AIBOTSEEKPLAYER state botseekplayerstate else
ifai AIBOTSTOPPED state botstoppedstate else
ifai AIBOTCHARGE state botchargestate else
ifai AIBOTWANDER state botwanderstate else
ifai AIBOTFACEPLAYER state botfaceplayerstate else
ifai AIBOTDODGE state botdodgestate else
ifai AIBOTSWIM state botswimstate else
ifai AIBOTJET state botjetstate


ifai AIBOTMEDIC state botmedicstate
else setvar target2 -1


ifvare command 1 state botpatrolstate // patrolling around a certain point


ifai AIBOTSWIM nullop else 
{
	setvar temp 0
	ifvarg underwater 2 setvar temp 1
	ifinwater setvar temp 1
	ifvare temp 1
	{
		cactor BOTALLY 
		ai AIBOTSWIM 
	}
}

ifai AIBOTJET nullop 
else 
ifcansee 
  ifp pjetpack 
    ifvarn command 1 ifvarn command 2
    ifvare perplayeronbike -1
      ai AIBOTJET

ifinwater nullop else ifvarg underwater 0 nullop else ifgapzl 48
{
	setvar botdodge 0
	ifai AIBOTDODGE ai AIBOTFACEPLAYER 
	cactor BOTALLYCROUCH
	ifaction ALLYPCRAWLING nullop else action ALLYPCRAWLING
	ifmove ALLYWALKVEL nullop else move ALLYWALKVEL geth
	ifcount 26 ifnotmoving
	{
		ifrnd 128 move ALLYWALKVEL faceplayer else
		ifrnd 128 move ALLYWALKVEL randomangle 
		// else state botjumpcode
	}
		
}
else ifaction ALLYPCRAWLING
{
	cactor BOTALLY
	ai AIBOTSEEKPLAYER
}

ifvarand monstflags 1024 nullop else
ifhitspace
 ifpdistl 4096
  ifvarvare scannedsprite THISACTOR
  {
	  ifvare command 1
	  {
		  globalsound MONITOR_ACTIVE
		  setvar command 0
	  }
// 	  ifvare botselected -1 
// 	  {
// 		  setvarvar botselected THISACTOR
// 		  globalsound MONITOR_ACTIVE
// 		  userquote 1005
// 	  }
  }

ifvarn command 2
ifvarand monstflags 256 ifvare target -1 ifvare target2 -1 state lookforpath
ifvare command 2 state botpathstate // following a path

ifvarn target -1
{
	state facetarget
	ifvarn target -1
	{
		ldist xydist THISACTOR target
		ifvare xydist 0 setvar xydist 1
		state botfiringcode
	}
}

ifvarg botdodge 0 subvar botdodge 1
addvar countvar 1
ifvarand monstflags 8
{
	addvar mtype 1
	ifvarg mtype 25 { state checkhealth setvar mtype 0 }
}
ifvarg countvar 25 ifvare target2 -1
{
	setvar countvar 0
	ifvare target -1 
	{
	  state botfindtarget
	  ifvarn target -1
	  {
	  	state switchweapon
	  	state visibilitycheck
  	  }
    }
	else ifrnd 96
	{
		state botfindtarget
		ifvarn target -1
		{
			state switchweapon
			state visibilitycheck
		}
	}
}

getactor[THISACTOR].htextra temp
ifvarg temp 0
{
	getactor[THISACTOR].htowner spriteid
	ifvarn spriteid -1
	{
		getactor[spriteid].picnum picnum
		{
			
			ifvarn picnum BOTALLY ifvarn picnum BOTALLYCROUCH
			ifvarn picnum APLAYER
			{
				ifvare target -1 setvarvar target spriteid
			}
			else
			{
				divvar temp 2
				ifvarg temp 40 setvar temp 40
				setactor[THISACTOR].htextra temp
			}
		}
	}
}

ifhitweapon
{
	getactor[THISACTOR].extra hp
	  ifvarl hp YELLHURTSOUNDSTRENGTHMP
        {
          ifrnd 64
            sound DUKE_LONGTERM_PAIN2
          else
            ifrnd 64
              sound DUKE_LONGTERM_PAIN3
          else
            ifrnd 64
              sound DUKE_LONGTERM_PAIN4
        }
        else
        {
          ifrnd 64
            sound DUKE_LONGTERM_PAIN5
          else ifrnd 64
            sound DUKE_LONGTERM_PAIN6
          else ifrnd 64
            sound DUKE_LONGTERM_PAIN7
          else
            sound DUKE_LONGTERM_PAIN8
        }
	ifwasweapon SHRINKSPARK
	{
		sound ACTOR_SHRINKING
		cactor BOTALLY
		ai AIBOTSHRUNK
		cstat 0
		break
	}
	ifdead
	{
	  ifwasweapon FREEZEBLAST
      {
        spritepal 1
        strength 0
        cactor BOTALLY      
        ai AIBOTFROZEN
        sound SOMETHINGFROZE
        state icesmoke
        break
      }
      ifwasweapon FREEZENOAIM
      {
        spritepal 1
        strength 0
        cactor BOTALLY
        ai AIBOTFROZEN
        sound SOMETHINGFROZE
        state icesmoke
        break
      }
        state botdrop
		setvar monstatus 2
		sound DUKE_DEAD
		userquote 1002
		cactor BOTALLYCROUCH
		state botexitarray
		ai AIBOTDYING
		ifwasweapon RPG
		{
			sound SQUISHED
			state standard_pjibs
			killit
		}
		ifwasweapon RPGNOAIM
		{
			sound SQUISHED
			state standard_pjibs
			killit
		}
		ifwasweapon RADIUSEXPLOSION
		{
			sound SQUISHED
			state standard_pjibs
			killit
		}
		ifspritepal 1 nullop else guts JIBS6 10
		
	}
}

ifcansee setvar countvarb 0 else addvar countvarb 1
ifvarand monstflags 256 nullop else
ifvarg countvarb 260 ifrnd 8
ifactornotstayput
{
	updatesectorz prevsectstartx prevsectstarty prevsectstartz temp
	ifvarn temp -1
	{
		getplayer[THISACTOR].posx mx
		getplayer[THISACTOR].posy my
		getplayer[THISACTOR].posz mz
		updatesectorz mx my mz tempb
		ifvarn tempb -1
		{
			cansee mx my mz tempb prevsectstartx prevsectstarty prevsectstartz temp tempc
			setvar tempd 0
			ifvarn tempc 1 setvar tempd 1
			ifvarg countvarb 1560 setvar tempd 1
			ifvare tempd 1 
			{
				setvar bouncesound -1
				setvar countvarb 0
				setactor[THISACTOR].x prevsectstartx
				setactor[THISACTOR].y prevsectstarty
				setactor[THISACTOR].z prevsectstartz
				changespritesect THISACTOR temp
			}
		}
	}
}

ends

useractor notenemy BOTALLY 140

ifvarn lotag 1 break

state botallycode

    
enda

useractor notenemy BOTALLYCROUCH 140
ifvarn lotag 1 break
	
state botallycode

enda

useractor notenemy NOTHING 0 killit enda



////////////////////
///  4.4. Water  ///
////////////////////
// Imported from SD_Duke mod

action CIRCLE_ANIMATION 0 9 1 1 9

useractor notenemy WATERCIRCLE
  ifaction 0
  {
     state rf
     cstator 546 // 512+32+2
     action CIRCLE_ANIMATION
  }
  sizeto 30 30
  ifinwater state getceilz
       else state getfloorz
  setactor[THISACTOR].z z

  ifactioncount 9 killit
enda


action SPLASH_ANIMATION  0 12 1 1 2
action SPLASH_ANIMATION2 0 12 1 1 3

useractor notenemy NEWSPLASH
  ifaction 0
  {
    state rf
    cstator 640 // 512+128
    ifinwater cstator 32768
    ifspawnedby SHOTSPARK1 { action SPLASH_ANIMATION  sizeat 10 20 }
                      else { action SPLASH_ANIMATION2 sizeat 20 20 }
  }

  ifactioncount 6 nullop else { ifrnd 64 spawn WATERCIRCLE }
  ifactioncount 12 killit
enda

define SPACESHUTTLE 487
move SHUTTLEVELS 16
actor SPACESHUTTLE TOUGH
//  ifmove 0          //  Init once
//    move SHUTTLEVELS getv geth
enda

useractor notenemy LASERIMPACT 0

ifvare countvar 0
{
	flash
	cstat 642
	sizeat 32 32 
	state sparkstate
}

ifcount 3 
{
	state wakeupmonsters
	espawn NEWSMOKE
	setactor[RETURN].xrepeat 96
	setactor[RETURN].yrepeat 96
	killit 
}

enda

useractor notenemy ROCKETHALO 0

ifvare countvar 0
{
	ifspawnedby FIRELASER 
	{
		sizeat 24 24 
		state sparkstate
	} else
	ifvare myspawner -1 sizeat 10 10
	else
	{
		getactor[myspawner].xrepeat x
		subvar x 3
		setactor[THISACTOR].xrepeat x
		getactor[myspawner].yrepeat y
		subvar y 3
		setactor[THISACTOR].yrepeat y
	}
}
cstat 642

ifspawnedby FIRELASER 
{
	ifcount 3 
	{
		espawn NEWSMOKE
		setactor[RETURN].xrepeat 64
		setactor[RETURN].yrepeat 64
		killit 
	}
} 
else
ifcount 1 
	killit 
	
enda


actor SATELLITE TOUGH
  //  ifmove 0 move SHUTTLEVELS getv geth
  //  ifcount 120 move SHUTTLEVELS getv geth randomangle
enda


action BLIMPWAITTORESPAWN

state blimphitstate
  cstat 0
  spawn FIRSTGUNSPRITE
  spawn EXPLOSION2

  debris SCRAP1 40      // Weapons and ammo!
  debris SCRAP2 32
  debris SCRAP3 32
  debris SCRAP4 32
  debris SCRAP5 32

  sound PIPEBOMB_EXPLODE
  ifrespawn
  {
    action BLIMPWAITTORESPAWN
    count 0
    cstat 32768
  }
  else
    killit
ends

actor BLIMP 1

  ifaction BLIMPWAITTORESPAWN
  {
    ifcount BLIMPRESPAWNTIME
    {
      action 0
      cstat 0
    }
    break
  }

  ifhitweapon
  {
    ifwasweapon RADIUSEXPLOSION
      state blimphitstate
    ifwasweapon RPG
      state blimphitstate
    strength 1
  }
enda



state rats
  ifrnd 128
    spawn RAT
  ifrnd 128
    spawn RAT
  ifrnd 128
    spawn RAT
  ifrnd 128
    spawn RAT
  ifrnd 128
    spawn RAT
  ifrnd 128
    spawn RAT
  ifrnd 128
    spawn RAT
  ifrnd 128
    spawn RAT
ends

state barrelinwatercode
	ifvarg peractor4 2 subvar peractor4 1
	setactor[THISACTOR].zvel 0
	ifceilingdistl 48 nullop else
  	movesprite THISACTOR 0 0 -3072 CLIPMASK0 RETURN
  	getactor[watereffector].z mz
  	getactor[THISACTOR].z z
  	addvar mz 2048
  	ifvarvarl z mz setactor[THISACTOR].z mz
 	
  	getactor[THISACTOR].pitch temp
  	ifvarl temp 512 
  	{
	  	addvar temp 32
	  	setactor[THISACTOR].pitch temp
	  	shiftvarl temp 2 mulvar temp -1
	  	setactor[THISACTOR].mdzoff temp
  	}
  	
 ends

eventloadactor RUBBERCAN
getactor[THISACTOR].extra monstflags
ifvare monstflags -1 setvar monstflags 0
enda

move RESPAWN_ACTOR_FLAG
move MOUSEVELS 32

action RUBCANDENT 1 1 1 1 1

actor RUBBERCAN WEAK
setvar weight WEIGHT2
setvar bouncesound ENDSEQVOL2SND4

state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 state throwitem
	break
}
else ifmove PHOLDING move INIT geth 
state pickupcode

ifvarn underwater 0 state barrelinwatercode
//ifvare fallflag 1 
ifvarg underwater 0 ifceilingdistl 48 nullop else
fall

  ifaction RUBCANDENT
  {
    ifactioncount 16
    {
      strength 0
      action ANULLACTION
      break
    }
  }
  else
    ifhitweapon
  {
    ifwasweapon RADIUSEXPLOSION
    {
      state rats
      ifrnd 48
        spawn BURNING
      debris SCRAP3 12
      killit
    }
    else
      action RUBCANDENT
  }
enda

state toughgalspeech
  ifrnd 64
  {
    ifnosounds
      soundonce TOUGHGALSND1
  }
  else
    ifrnd 64
  {
    ifnosounds
      soundonce TOUGHGALSND2
  }
  else
    ifrnd 64
  {
    ifnosounds
      soundonce TOUGHGALSND3
  }
  else
    ifnosounds
      soundonce TOUGHGALSND4
ends

state jibfood
  sound SQUISHED
  guts JIBS6 3
  killit
ends


state breakobject


ifspawnedby APLAYER sizeat 40 40

state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifphealthl MAXPLAYERHEALTH
	{
		ifactor DONUTS { globalsound DUKE_TAKEPILLS addphealth 10 palfrom 40 0 40 setvar holding -1 killit }
		ifactor FOODOBJECT11 { globalsound DUKE_TAKEPILLS addphealth 10 palfrom 40 10 40 setvar holding -1  killit }
		ifactor FOODOBJECT12 { globalsound DUKE_TAKEPILLS addphealth 10 palfrom 40 10 40 setvar holding -1  killit }
		ifactor FOODOBJECT13 { globalsound DUKE_TAKEPILLS addphealth 15 palfrom 40 10 40 setvar holding -1  killit }
		ifactor FOODOBJECT18 { globalsound DUKE_TAKEPILLS addphealth 5 palfrom 40 10 40 setvar holding -1  cactor FOODOBJECT17 }
		ifactor FOODOBJECT19 { globalsound DUKE_TAKEPILLS addphealth 5 palfrom 40 10 40 setvar holding -1  killit }
	}
	ifvarand bits 4 state throwitem
	break
}
else ifmove PHOLDING move INIT geth 
getactor[THISACTOR].cstat temp
ifvarand temp 16 nullop else
ifvarand temp 32 nullop else
ifvarn sprite[THISACTOR].picnum METER
state pickupcode
ifvarn underwater 0 state barrelinwatercode

  ifaction 0
  {
    action ANULLACTION
    cstator 257
    ifactor ROBOTMOUSE
      clipdist 64
  }
  else
    ifactor ROBOTMOUSE
  {
      ifdead
      {
        ifcount 32
        {
          globalsound MOUSEANNOY
          killit
        }
        break
      }
      ifcount 64 ifrnd 6
      {
        ifrnd 128
          move MOUSEVELS randomangle geth
        else
        {
          ifrnd 64
            soundonce HAPPYMOUSESND1
          else
            ifrnd 64
              soundonce HAPPYMOUSESND2
          else
            ifrnd 64
              soundonce HAPPYMOUSESND3
          else
            soundonce HAPPYMOUSESND4
        }
        resetcount
      }
  }

  ifhitweapon
  {
    ifdead
    {
      ifactor FOODOBJECT6
        state jibfood
      else
        ifactor FOODOBJECT11
          state jibfood
      else
        ifactor FOODOBJECT12
          state jibfood
      else
        ifactor FOODOBJECT13
          state jibfood
      else
        ifactor FOODOBJECT14
          state jibfood
      else
        ifactor FOODOBJECT15
          state jibfood
      else
        ifactor FOODOBJECT16
          state jibfood
      else
        ifactor FOODOBJECT17
          state jibfood
      else
        ifactor SKINNEDCHICKEN
          state jibfood
      else
        ifactor 851
          state jibfood
      else
        ifactor SHOPPINGCART
      {
        debris SCRAP1 5
        debris SCRAP2 5
        debris SCRAP3 5
        sound GLASS_HEAVYBREAK
        killit
      }
      else
        ifactor ROBOTDOG2
      {
        soundonce DEAD_DOG
        guts JIBS2 1
        guts JIBS3 2
        guts JIBS6 3
        killit
      }
      else
        ifactor FEATHEREDCHICKEN
          state jibfood
      else
        ifactor DOLPHIN1
      {
        guts JIBS2 1
        guts JIBS3 2
        guts JIBS4 3
        guts JIBS5 2
        state jibfood
      }
      else
        ifactor DOLPHIN2
      {
        guts JIBS2 1
        guts JIBS3 2
        guts JIBS4 3
        guts JIBS5 2
        state jibfood
      }
      else
        ifactor SNAKEP
      {
        guts JIBS2 1
        guts JIBS3 2
        guts JIBS4 3
        guts JIBS5 2
        state jibfood
      }
      else
        ifactor FETUSJIB
      {
	    guts JIBS2 2
	    guts JIBS6 3
	    killit
      }
      else
        ifactor DONUTS
      {
        spritepal 7
        guts JIBS6 2
        killit
      }
      else
        ifactor DONUTS2
      {
        debris SCRAP1 1
        spritepal 7
        guts JIBS6 2
        killit
      }
      else
        ifactor MAILBAG
        {
          mail 30
          debris SCRAP3 5
          debris SCRAP4 3
          killit
        }
      else
        ifactor TEDDYBEAR
      {
        debris SCRAP3 5
        spritepal 1
        debris SCRAP3 6
      }
      else
        ifactor DUKECUTOUT
      {
	    spritepal 1
	    debris SCRAP6 5
	    spritepal 2
	    debris SCRAP4 5
	    spritepal 7
	    debris SCRAP5 5
	    killit
      }
      else
        ifactor AMERICANFLAG
      {
        debris SCRAP1 2
        debris SCRAP3 3
        debris SCRAP4 2
      }
      else
      {
        ifrnd 128
          sound GLASS_BREAKING
        else
          sound GLASS_HEAVYBREAK
      }

      ifactor CLOCK
      {
        cactor BROKENCLOCK
        break
      }
      else
        ifactor JOLLYMEAL
      {
        spawn ATOMICHEALTH
        debris SCRAP3 1
        debris SCRAP4 2
      }
      else
        ifactor GUMBALLMACHINE
      {
        cactor GUMBALLMACHINEBROKE
        strength 1
        debris SCRAP4 2
        lotsofglass 10
        break
      }
      else
        ifactor GUMBALLMACHINEBROKE
      {
        debris SCRAP3 3
        debris SCRAP4 2
        lotsofglass 10
      }
      else
        ifactor DUKEBURGER
      {
        debris SCRAP3 14
        debris SCRAP1 13
        debris SCRAP4 12
        debris SCRAP2 12
        debris SCRAP5 11
      }
      else
        ifactor POLICELIGHTPOLE
      {
        debris SCRAP3 4
        debris SCRAP1 3
        debris SCRAP4 2
        debris SCRAP2 2
        debris SCRAP5 1
      }
      else
        ifactor TOPSECRET
          paper 10
      else
        ifactor GUNPOWDERBARREL
       {
       ifvarn lotag 1
        {
        spawn EXPLOSION2
        sound PIPEBOMB_EXPLODE
        hitradius 2048 WEAKEST WEAK MEDIUMSTRENGTH TOUGH
        ifpdistl 2048
          wackplayer
        debris SCRAP1 10
        }
        debris SCRAP2 13
        debris SCRAP3 4
        debris SCRAP4 17
        debris SCRAP5 6
      }
      else
        ifactor FLOORBASKET
      {
        spawn PUKE
        debris SCRAP1 2
        debris SCRAP3 3
        debris SCRAP4 2
      }
      else
        ifactor ROBOTMOUSE
      {
        debris SCRAP2 10
        spritepal 1
        debris SCRAP3 4
        resetcount
        cstat 32768
        break
      }
      else
        ifactor ROBOTPIRATE
      {
        debris SCRAP2 10
        debris SCRAP1 5
        debris SCRAP3 3
        lotsofglass 10
      }
      else
        ifactor PIRATE1A
      {
        debris SCRAP2 10
        debris SCRAP1 5
        debris SCRAP3 3
        lotsofglass 10
      }
      else
        ifactor MAN
      {
        debris SCRAP2 10
        debris SCRAP1 5
        debris SCRAP3 3
        lotsofglass 10
      }
      else
        ifactor MAN2
      {
        debris SCRAP2 10
        debris SCRAP1 5
        debris SCRAP3 3
        lotsofglass 10
      }
      else
        ifactor PIRATE2A
      {
        debris SCRAP2 10
        debris SCRAP1 5
        debris SCRAP3 3
        lotsofglass 10
      }
      else
        ifactor PIRATE3A
      {
        debris SCRAP2 10
        debris SCRAP1 5
        debris SCRAP3 3
        lotsofglass 10
      }
      else
        ifactor PIRATE4A
      {
        debris SCRAP2 10
        debris SCRAP1 5
        debris SCRAP3 3
        lotsofglass 10
      }
      else
        ifactor PIRATE4A
      {
        debris SCRAP2 10
        debris SCRAP1 5
        debris SCRAP3 3
        lotsofglass 10
      }
      else
        ifactor PIRATE5A
      {
        debris SCRAP2 10
        debris SCRAP1 5
        debris SCRAP3 3
        lotsofglass 10
      }
      else
        ifactor PIRATE6A
      {
        debris SCRAP2 10
        debris SCRAP1 5
        debris SCRAP3 3
        lotsofglass 10
      }
	    
      else
      {
        lotsofglass 10
        debris SCRAP4 3
      }
      
      killit
    }
    else
      ifactor DOLPHIN1
    {
      guts JIBS6 1
      soundonce DOLPHINSND
      ifstrength TOUGH
      {
        cactor DOLPHIN2
        sound SQUISHED
      }
    }
    else
      ifactor DOLPHIN2
    {
      guts JIBS6 1
      soundonce DOLPHINSND
    }
    else
      ifactor ROBOTDOG2
    {
      guts JIBS6 1
      soundonce WHINING_DOG
    }
    
  }
  else
  {
    ifactor CLOCK
      nullop
    else
      ifactor TOPSECRET
        nullop
    else
      ifactor SKINNEDCHICKEN
        nullop
    else
      ifactor FEATHEREDCHICKEN
        nullop
    else
      ifactor FOODOBJECT2
        nullop
    else
      ifactor FOODOBJECT6
        nullop
    else
      ifactor DOLPHIN1
        nullop
    else
      ifactor DOLPHIN2
        nullop
    else ifvare fallflag 0

      fall
  }
ifvarg underwater 0 ifceilingdistl 48 nullop else
ifvare fallflag 1
fall

ends

state potcode

	setvar bouncesound BOUNCEMETALSND
	
	state moveitem
	
	ifvarvare holding THISACTOR
	{
		ifactor 691 orvar initcstat 16
		ifactor 692 orvar initcstat 16
		ifactor 693 orvar initcstat 16
		ifvarn pickup 0 break
		ifvarand bits 4 state throwitem
		break
	}
	else ifmove PHOLDING move INIT geth 
	state pickupcode

  fall
  strength 0
  ifhitweapon
  {
    state HITMETALSOUND
  	state sparkstate 
  }

ends

useractor notenemy 691 0 state potcode enda
useractor notenemy 692 0 state potcode enda
useractor notenemy 693 0 state potcode enda
useractor notenemy POT1 0 state potcode enda
useractor notenemy POT2 0 state potcode enda
useractor notenemy BALLANDCHAIN 0 setvar weight WEIGHT3 state potcode enda


action ABURGERROTS 0 1 5

useractor notenemy 851 WEAK setvar bouncesound PIPEBOMB_BOUNCE state breakobject enda

useractor notenemy DUKEBURGER PIRATEGALSTRENGTH ABURGERROTS setvar bouncesound FOODLAND state breakobject enda

useractor notenemy MOP WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy BROOM WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy WETFLOOR WEAK setvar bouncesound ENDSEQVOL2SND4 state breakobject enda

useractor notenemy DESKLAMP WEAK setvar bouncesound PIPEBOMB_BOUNCE state breakobject enda

useractor notenemy DUKECUTOUT WEAK state breakobject enda

useractor notenemy FETUSJIB WEAK state breakobject enda

useractor notenemy HATRACK WEAK setvar bouncesound PIPEBOMB_BOUNCE state breakobject enda

eventloadactor GUNPOWDERBARREL getactor[THISACTOR].lotag lotag setactor[THISACTOR].lotag 0 enda
useractor notenemy GUNPOWDERBARREL TOUGH setvar bouncesound ENDSEQVOL2SND4 state breakobject enda

useractor notenemy COFFEEMACHINE WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy TEDDYBEAR WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy TOPSECRET WEAK state breakobject enda

useractor notenemy ROBOTMOUSE ROBOTMOUSESTRENGTH setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy MAN PIRATEGALSTRENGTH state breakobject enda

useractor notenemy MAN2 PIRATEGALSTRENGTH state breakobject enda

useractor notenemy WOMAN PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE1A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE2A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE3A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE4A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE5A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE6A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy ROBOTPIRATE PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATEHALF TOUGH state breakobject enda

useractor notenemy CHESTOFGOLD WEAK state breakobject enda

useractor notenemy ROBOTDOG PIRATEGALSTRENGTH state breakobject enda

useractor notenemy ROBOTDOG2 TOUGH setvar bouncesound WHINING_DOG state breakobject enda

useractor notenemy PLEASEWAIT  setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy FOODOBJECT1 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT2 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT3 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT4 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT5 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT6 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT7 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT8 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT9 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT10 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT11 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT12 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT13 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT14 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT15 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT16 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT17 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT18 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT19 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT20 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy JOLLYMEAL WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy GUMBALLMACHINE WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy GUMBALLMACHINEBROKE WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy POLICELIGHTPOLE TOUGH setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy CLOCK WEAK setvar bouncesound PIPEBOMB_BOUNCE state breakobject enda

useractor notenemy MAILBAG WEAK state breakobject enda

useractor notenemy FEATHEREDCHICKEN WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy SKINNEDCHICKEN WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy HEADLAMP WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy DOLPHIN1 DOLPHINSTRENGTH state breakobject enda

useractor notenemy DOLPHIN2 DOLPHINSTRENGTH state breakobject enda

useractor notenemy SNAKEP MEDIUMSTRENGTH setvar bouncesound FOODLAND state breakobject enda

useractor notenemy DONUTS WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy GAVALS WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy GAVALS2 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy CUPS WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy DONUTS2 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FLOORBASKET WEAK setvar bouncesound ENDSEQVOL2SND4 state breakobject enda

useractor notenemy METER WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy DESKPHONE WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy MACE WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy SHOPPINGCART WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy COFFEEMUG WEAK setvar bouncesound PIPEBOMB_BOUNCE state breakobject enda

useractor notenemy POT3 WEAK state breakobject enda

useractor notenemy SUSHIPLATE1 WEAK state breakobject enda

useractor notenemy SUSHIPLATE2 WEAK state breakobject enda

useractor notenemy SUSHIPLATE3 WEAK state breakobject enda

useractor notenemy SUSHIPLATE4 WEAK state breakobject enda

useractor notenemy SUSHIPLATE5 WEAK state breakobject enda

useractor notenemy BOX WEAK state breakobject enda

useractor notenemy AMERICANFLAG TOUGH setvar bouncesound ENDSEQVOL2SND4 state breakobject enda


// define PLANKOFWOOD 4445

// useractor notenemy PLANKOFWOOD TOUGH

// sizeat 40 40
// setvar weight WEIGHT2

// 	setvar bouncesound FOODLAND
// 	
// 	orvar initcstat 33
// 	state moveitem
// 	
// 	ifvarvare holding THISACTOR
// 	{
// 		ifvarn pickup 0 break
// 		ifvarand bits 4 state throwitem
// 		break
// 	}
// 	else ifmove PHOLDING move INIT geth 
// 	state pickupcode

//   fall
//   ifhitweapon
//   {
//     ifrnd 128 sound HITWOOD4 else sound HITWOOD5
//     ifdead 
//     {
// 	    setvar monstflags NEWSCRAP4
// 	    state shootscrap
// 	    killit
//     }
//   	
//   }

// enda



action SEENINEFRAME     0   3   1   1   10
useractor notenemy SEENINE 5

  ifaction SEENINEFRAME
  {
    ifactioncount 3
    {
	  ifvarand monstflags 1
  	  hitradius 3072 30 60 120 240
  	  else
      hitradius 2748 MEDIUMSTRENGTH TOUGH REALLYTOUGH ROBOTMOUSESTRENGTH
      spawn EXPLOSION2
      debris SCRAP2 6
      sound PIPEBOMB_EXPLODE
      killit
    }
    break
  }
  ifsquished
  {
    debris SCRAP1 5
    killit
    break
  }
  ifhitweapon
  {
	ifvarvare holding THISACTOR state throwitem
    action SEENINEFRAME
  } 

state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 state throwitem
	break
}
else 
	ifmove PHOLDING move INIT geth
	
state pickupcode

fall

enda

state canwithsomethingcode

state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 state throwitem
	break
}
else ifmove PHOLDING move INIT geth 
state pickupcode
ifvarn underwater 0 state barrelinwatercode
ifvarg underwater 0 ifceilingdistl 48 nullop else
fall

  ifhitweapon
  {
    ifdead
    {
	  getactor[THISACTOR].picnum picnum
	  switch picnum
	  case CANWITHSOMETHING case CANWITHSOMETHING2 case CANWITHSOMETHING3 case CANWITHSOMETHING4
		sound VENT_BUST
	    debris SCRAP1 4
	    debris SCRAP6 3
	    ifvarn lotag 0 espawnvar lotag
      break
      case VASE case BOTTLE1 case BOTTLE2 case BOTTLE3 case BOTTLE4 case BOTTLE5 case BOTTLE6 case BOTTLE7
      case BOTTLE8 case BOTTLE10 case BOTTLE11 case BOTTLE12 case BOTTLE13 case BOTTLE14 case BOTTLE15 
      case BOTTLE16 case BOTTLE17 case BOTTLE18 case BOTTLE19 case FETUSBROKE
      	sound GLASS_BREAKING
      	lotsofglass 10
      break
      case CAMERALIGHT case TRIPODCAMERA case VACUUM case IVUNIT case MOVIECAMERA
        sound GLASS_BREAKING
        debris SCRAP6 10
        debris SCRAP2 10
      break  
      default break
      endswitch
      ifvarvare holding THISACTOR state throwitem
      ifvarvare gravitysprite THISACTOR setvar gravitysprite -1
      killit
    }
  }

ends

useractor notenemy CANWITHSOMETHING 0 state canwithsomethingcode enda
useractor notenemy CANWITHSOMETHING2 0 state canwithsomethingcode enda
useractor notenemy CANWITHSOMETHING3 0 state canwithsomethingcode enda
useractor notenemy CANWITHSOMETHING4 0 state canwithsomethingcode enda
useractor notenemy VASE 0 state canwithsomethingcode enda
useractor notenemy BOTTLE1 0 state canwithsomethingcode enda
useractor notenemy BOTTLE2 0 state canwithsomethingcode enda
useractor notenemy BOTTLE3 0 state canwithsomethingcode enda
useractor notenemy BOTTLE4 0 state canwithsomethingcode enda
useractor notenemy BOTTLE5 0 state canwithsomethingcode enda
useractor notenemy BOTTLE6 0 state canwithsomethingcode enda
useractor notenemy BOTTLE7 0 state canwithsomethingcode enda
useractor notenemy BOTTLE8 0 state canwithsomethingcode enda
useractor notenemy BOTTLE10 0 state canwithsomethingcode enda
useractor notenemy BOTTLE11 0 state canwithsomethingcode enda
useractor notenemy BOTTLE12 0 state canwithsomethingcode enda
useractor notenemy BOTTLE13 0 state canwithsomethingcode enda
useractor notenemy BOTTLE14 0 state canwithsomethingcode enda
useractor notenemy BOTTLE15 0 state canwithsomethingcode enda
useractor notenemy BOTTLE16 0 state canwithsomethingcode enda
useractor notenemy BOTTLE17 0 state canwithsomethingcode enda
useractor notenemy BOTTLE18 0 state canwithsomethingcode enda
useractor notenemy BOTTLE19 0 state canwithsomethingcode enda
useractor notenemy CAMERALIGHT 0 state canwithsomethingcode enda
useractor notenemy TRIPODCAMERA 0 state canwithsomethingcode enda
useractor notenemy VACUUM 0 state canwithsomethingcode enda
useractor notenemy IVUNIT 0 state canwithsomethingcode enda
useractor notenemy MOVIECAMERA 0 state canwithsomethingcode enda
useractor notenemy CHAIR3 0 setvar bouncesound ENDSEQVOL2SND4 state canwithsomethingcode enda
useractor notenemy FETUSBROKE 0 state canwithsomethingcode enda

action TOILETFRAME -5753 1 1 1 1
action TOILETBROKEFRAME -5707 1 1 1 1
useractor notenemy TOILET2 10 TOILETFRAME

state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 state throwitem
	break
}
else ifmove PHOLDING move INIT geth 
state pickupcode

fall

  ifhitweapon
  {
    ifdead
    {
	    
        sound VENT_BUST
        sound GLASS_BREAKING
        debris SCRAP6 10
        debris SCRAP1 5
        lotsofglass 10
        ifaction TOILETBROKEFRAME killit
        else
        {
	        strength 20
        	action TOILETBROKEFRAME
    	}
      
      ifvarvare holding THISACTOR state throwitem
      ifvarvare gravitysprite THISACTOR setvar gravitysprite -1
    }
  }
enda

action HYDRENTFRAME -5342 1 1 1 1
useractor notenemy HYDRENT2 10 HYDRENTFRAME

state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 state throwitem
	break
}
else ifmove PHOLDING move INIT geth 
state pickupcode

fall

  ifhitweapon
  {
    ifdead
    {
        sound VENT_BUST
        sound GLASS_BREAKING
        debris SCRAP6 5
        debris SCRAP1 10
        killit
      ifvarvare holding THISACTOR state throwitem
      ifvarvare gravitysprite THISACTOR setvar gravitysprite -1
    }
  }


enda

       
state conecode

	state moveitem
	
	ifvarvare holding THISACTOR
	{
		ifvarn pickup 0 break
		ifvarand bits 4 state throwitem
		break
	}
	else ifmove PHOLDING move INIT geth 
	state pickupcode
	
	fall
	strength 0	
	ifhitweapon
	{
		move INIT randomangle 
		setvar peractor4 13 
		sound FOODLAND
	} 
ends
	     
actor CONE 0 state conecode enda

action CHAIRBROKE1 3 1 1 1 1
action CHAIRBROKE2 2 1 1 1 1
action FETUSBROKEN 1 1 1 1 1

state chaircode

	setvar bouncesound BOUNCEMETALSND
	
	state moveitem
	
	ifvarvare holding THISACTOR
	{
		ifvarn pickup 0 break
		ifvarand bits 4 state throwitem
		break
	}
	else ifmove PHOLDING move INIT geth 
	state pickupcode

  fall
  ifhitweapon
  {
    ifdead 
    {
	    strength 0
	    ifaction 0
	    {
		    ifactor CHAIR1 action CHAIRBROKE1 else
		    ifactor CHAIR2 action CHAIRBROKE2 else
		    ifactor FETUS action FETUSBROKEN else
		    ifactor BROKENCHAIR ifwasweapon RADIUSEXPLOSION
		    {
			    debris SCRAP1 5
			    debris SCRAP6 5
			    ifvarvare holding THISACTOR state throwitem
      			ifvarvare gravitysprite THISACTOR setvar gravitysprite -1
			    killit
		    }
	    } else ifwasweapon RADIUSEXPLOSION
	    {
		    ifactor FETUS lotsofglass 10 else
		    {
			    debris SCRAP1 5
				debris SCRAP6 5
			}
			ifvarvare holding THISACTOR state throwitem
      		ifvarvare gravitysprite THISACTOR setvar gravitysprite -1
			killit
		}
	}
	  
  }

ends

action DPHYDROBROKE 1 1 1
useractor notenemy DPHYDROPLANT WEAK
cstator 256

// state moveitem
	
// ifvarvare holding THISACTOR
// {
// 	ifvarn pickup 0 break
// 	ifvarand bits 4 state throwitem
// 	break
// }
// else ifmove PHOLDING move INIT geth 
// state pickupcode

// fall
ifhitweapon
{
	ifdead 
	{
		sound GLASS_HEAVYBREAK
	    strength 0
		lotsofglass 10
		spawn WATERSPLASH2
		ifaction DPHYDROBROKE { killit break }
		spritepal 1
		spawn BLOODPOOL
		getlastpal
		spritepal 8
		guts JIBS6 5
		getlastpal
		action DPHYDROBROKE
	}
}

enda

useractor notenemy CHAIR1 10 state chaircode enda
useractor notenemy CHAIR2 10 state chaircode enda
useractor notenemy BROKENCHAIR 10 state chaircode enda
useractor notenemy FETUS 0 state chaircode enda

useractor notenemy FIREEXT 0


  ifsquished
  {
    ifvarvare holding THISACTOR state throwitem
    hitradius 2048 WEAK MEDIUMSTRENGTH TOUGH REALLYTOUGH
    spawn EXPLOSION2
    debris SCRAP2 2
    sound PIPEBOMB_EXPLODE
    killit
    break
  }
  ifhitweapon
  {
      ifvarvare holding THISACTOR state throwitem
      hitradius 2048 WEAK MEDIUMSTRENGTH TOUGH REALLYTOUGH
      spawn EXPLOSION2
      debris SCRAP2 2
      sound PIPEBOMB_EXPLODE
      killit
  }
    
  state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 
	{
		state throwitem
		break
	} 
	break
}
else ifmove PHOLDING move INIT geth 
state pickupcode

ifvarn fallflag 0 fall

enda

action OOZFILTERFRAMES   0    3   1   1   12
actor OOZFILTER 10 OOZFILTERFRAMES

ifhitweapon ifdead
{
  ifvarvare holding THISACTOR state throwitem
  ifvarand monstflags 1
  hitradius 3072 30 60 120 240
  else
  hitradius 2048 WEAK MEDIUMSTRENGTH TOUGH REALLYTOUGH
  spawn EXPLOSION2
  debris SCRAP1 4
  debris SCRAP2 4
  sound PIPEBOMB_EXPLODE
  killit
}

state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 state throwitem
	break
}
else 
{
	ifmove PHOLDING move INIT geth 
	getactor[THISACTOR].zvel temp
	ifvarg temp 0 setvar mtype 1 // falling
	ifvare mtype 1 ifvare temp 0 { soundvar bouncesound setvar mtype 0 }
}
state pickupcode

fall

enda


action EXPBARRELFRAME     0   2   1   1   10
actor EXPLODINGBARREL 26

setvar weight WEIGHT3
setvar bouncesound METALTHUD

  ifaction EXPBARRELFRAME
  {
    ifactioncount 2
    {
      hitradius 2048 WEAK MEDIUMSTRENGTH TOUGH REALLYTOUGH
      spawn EXPLOSION2
      debris SCRAP2 2
      sound PIPEBOMB_EXPLODE
      killit
    }
    break
  }
  ifsquished
  {
    debris SCRAP1 5
    killit
    break
  }
  ifhitweapon
  {
    ifvarvare holding THISACTOR state throwitem
    action EXPBARRELFRAME
  }
    
    state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 state throwitem
	break
}
else 
{
	ifmove PHOLDING move INIT geth 
	getactor[THISACTOR].zvel temp
	ifvarg temp 0 setvar mtype 1 // falling
	ifvare mtype 1 ifvare temp 0 { soundvar bouncesound setvar mtype 0 }
}
state pickupcode

  fall
  
enda

define BLOWENUPCAR 5259
useractor notenemy BLOWENUPCAR
sizeat 64 64
clipdist 32
cstator 257
ifhitweapon { strength 0 ifwasweapon SHOTSPARK1 state HITMETALSOUND }
enda

define BLOWENUPCAR180 5277
useractor notenemy BLOWENUPCAR180
sizeat 64 64
clipdist 32
cstator 257
ifhitweapon { strength 0 ifwasweapon SHOTSPARK1 state HITMETALSOUND }
enda

define CARXPLODE 1342
gamevar tempvar 0 2

define BLOWENUPCARSUV 5277
useractor notenemy BLOWENUPCARSUV
sizeat 71 82
clipdist 32
cstator 257
ifhitweapon { strength 0 ifwasweapon SHOTSPARK1 state HITMETALSOUND }
enda

define BLOWENUPORCHE 5344
useractor notenemy BLOWENUPORCHE
sizeat 64 58
clipdist 32
cstator 257
ifhitweapon { strength 0 ifwasweapon SHOTSPARK1 state HITMETALSOUND }
enda

define BLOWENUPCARSUV2 5338
useractor notenemy BLOWENUPCARSUV2
sizeat 74 82
clipdist 32
cstator 257
ifhitweapon { strength 0 ifwasweapon SHOTSPARK1 state HITMETALSOUND }
enda

define BLOWENUPCAR270 5278
useractor notenemy BLOWENUPCAR270
sizeat 73 63
clipdist 32
cstator 257
ifhitweapon { strength 0 ifwasweapon SHOTSPARK1 state HITMETALSOUND }
enda

define BLOWENUPCAR90 5279
useractor notenemy BLOWENUPCAR90
sizeat 60 62
clipdist 32
cstator 257
ifhitweapon { strength 0 ifwasweapon SHOTSPARK1 state HITMETALSOUND }
enda


define YOURCAR1 5281
define YOURCAR2 5275
define YOURCAR3 5245
define YOURCAR4 5243
define YOURCAR7 5246
define YOURCAR8 5306
define YOURCAR9 5292
define YOURCAR10 5363
define SEMI 5294
define TRAILER 5295
define GASPUMP 5290
define COPRED 5240
define LIGHTPOST 5248
define COPBLUE 5329
define AMBRED 5335
define AMBBLUE 5270
define SWAT 5241
define VAN 5244
define DOZER 5250
define APC 5251
define CREGISTER 2553
define FREZR 5261
define STOVE 5262
define LIMO 5266
define BOXTRUCK 5267
define BACKHOE 5268
define KEG 5269
define FIRETRUCK 5274
define GENERATOR1 5291 
define SCHOOLBUS 5293
define SHELF 5299
define WASHER1 5301
define WASHER2 5302
define WASHER3 5303
define WASHER4 5304
define GENERATOR2 5305
define BOXTRUCK2 5315
define GRAIL 5320
define DUMPSTER 5327
define TOOLBOX 5328
define TOOLBOX2 5336
define CARSTRENGTH 600


ai YOURCARAI 0 

state blowupcar

espawn EXPLOSION2
setactorvar[RETURN].peractor1 1
getactor[THISACTOR].picnum picnum
switch picnum
case YOURCAR1 case YOURCAR7 spawn BLOWENUPCAR270 break
case YOURCAR2 spawn BLOWENUPCAR90 break
case YOURCAR3 spawn BLOWENUPCARSUV break
case YOURCAR4 spawn BLOWENUPCAR break
case YOURCAR8 spawn BLOWENUPCARSUV2 break
case YOURCAR9 spawn BLOWENUPORCHE break
case YOURCAR10 spawn BLOWENUPCAR break
default spawn BLOWENUPCAR270 break
endswitch
 
ifrnd 128 spawn BURNING else spawn BURNING2  // Spawn an explosion and the model of your blowen up car
ezshoot -8192 CARXPLODE
randvar angvar 2047
setactor[RETURN].ang angvar 
randvar angvar  256
setactor[RETURN].xvel angvar 
sound RPG_EXPLODE
hitradius 2048 WEAKEST WEAK MEDIUMSTRENGTH TOUGH
killit

ends


state carcode

ifai 0

{
	clipdist 32 // Change this for the clipping distance but you would use blockers so we leaver it as normal clipdist
	cstator 257 // Make the car hitable and blocking 
	ai YOURCARAI
}

getactor[THISACTOR].htextra temp
ifvarg temp 0
ifvare sprite[THISACTOR].htpicnum RADIUSEXPLOSION
{
	shiftvarl temp 1
	setactor[THISACTOR].htextra temp // double damage from non-RPG explosives
}
	
ifhitweapon // Was the car hit by a weapon?
{
	debris SCRAP1 5 // Spawn some metal scraps
    ifdead state blowupcar // Is it dead yet?
	ifwasweapon RPG state blowupcar
    ifwasweapon SHOTSPARK1
    state HITMETALSOUND  
}

ends

state carcode2

ifai 0
{
    clipdist 32 // Change this for the clipping distance but you would use blockers so we leaver it as normal clipdist
    cstator 257 // Make the car hitable and blocking
    ai YOURCARAI
}
ifhitweapon // Was the car hit by a weapon?
{
    strength CARSTRENGTH
    ifwasweapon SHOTSPARK1
    state HITMETALSOUND  
}

ends
useractor notenemy SEMI CARSTRENGTH state carcode2 enda
useractor notenemy TRAILER CARSTRENGTH state carcode2 enda
useractor notenemy GASPUMP CARSTRENGTH state carcode2 enda
useractor notenemy COPRED CARSTRENGTH state carcode2 enda
useractor notenemy COPBLUE CARSTRENGTH state carcode2 enda
useractor notenemy AMBRED CARSTRENGTH state carcode2 enda
useractor notenemy AMBBLUE CARSTRENGTH state carcode2 enda
useractor notenemy SWAT CARSTRENGTH state carcode2 enda
useractor notenemy VAN CARSTRENGTH state carcode2 enda
useractor notenemy DOZER CARSTRENGTH state carcode2 enda
useractor notenemy APC CARSTRENGTH state carcode2 enda
useractor notenemy CREGISTER CARSTRENGTH state carcode2 enda
useractor notenemy FREZR CARSTRENGTH state carcode2 enda
useractor notenemy STOVE CARSTRENGTH state carcode2 enda
useractor notenemy LIMO CARSTRENGTH state carcode2 enda
useractor notenemy BOXTRUCK CARSTRENGTH state carcode2 enda
useractor notenemy BACKHOE CARSTRENGTH state carcode2 enda
useractor notenemy KEG CARSTRENGTH state carcode2 enda
useractor notenemy FIRETRUCK CARSTRENGTH state carcode2 enda
useractor notenemy GENERATOR1 CARSTRENGTH state carcode2 enda
useractor notenemy SHELF CARSTRENGTH state carcode2 enda
useractor notenemy WASHER1 CARSTRENGTH state carcode2 enda
useractor notenemy WASHER2 CARSTRENGTH state carcode2 enda
useractor notenemy WASHER3 CARSTRENGTH state carcode2 enda
useractor notenemy WASHER4 CARSTRENGTH state carcode2 enda
useractor notenemy GENERATOR2 CARSTRENGTH state carcode2 enda
useractor notenemy BOXTRUCK2 CARSTRENGTH state carcode2 enda
useractor notenemy GRAIL CARSTRENGTH state carcode2 enda
useractor notenemy DUMPSTER CARSTRENGTH state carcode2 enda
useractor notenemy TOOLBOX CARSTRENGTH state carcode2 enda
useractor notenemy TOOLBOX2 CARSTRENGTH state carcode2 enda
useractor notenemy LIGHTPOST CARSTRENGTH state carcode2 enda

useractor notenemy YOURCAR1 CARSTRENGTH sizeat 29 29 state carcode enda
useractor notenemy YOURCAR2 CARSTRENGTH sizeat 29 25 state carcode enda
useractor notenemy YOURCAR3 CARSTRENGTH sizeat 38 36 state carcode enda
useractor notenemy YOURCAR4 CARSTRENGTH sizeat 36 37 state carcode enda
useractor notenemy YOURCAR7 CARSTRENGTH sizeat 31 31 state carcode enda 
useractor notenemy YOURCAR8 CARSTRENGTH sizeat 42 37 state carcode enda
useractor notenemy YOURCAR9 CARSTRENGTH sizeat 73 63 state carcode enda
useractor notenemy YOURCAR10 CARSTRENGTH sizeat 18 18 state carcode enda




//defineprojectile CARXPLODE PROJ_WORKSLIKE 2054
defineprojectile CARXPLODE PROJ_WORKSLIKE 34822
defineprojectile CARXPLODE PROJ_HITRADIUS 0
defineprojectile CARXPLODE PROJ_EXTRA 0
defineprojectile CARXPLODE PROJ_XREPEAT 15
defineprojectile CARXPLODE PROJ_YREPEAT 14
defineprojectile CARXPLODE PROJ_BOUNCES 2
defineprojectile CARXPLODE PROJ_VEL 400
defineprojectile CARXPLODE PROJ_DROP -256
defineprojectile CARXPLODE PROJ_TRAIL EXPLOSION2
defineprojectile CARXPLODE PROJ_SPAWNS DUKEBIKEPART2
defineprojectile CARXPLODE PROJ_SXREPEAT 15
defineprojectile CARXPLODE PROJ_SYREPEAT 14
defineprojectile CARXPLODE PROJ_BSOUND DUKEBIKE_HIT
defineprojectile CARXPLODE PROJ_RANGE 32

action BURNING_FLAME  0   12   1   1   2
move BURNING_VELS 

state burningstate

  ifvarg underwater 0 killit
  sleeptime 300


  ifspawnedby BURNING
  {
    ifgapzl 16
      break
  }
  else
    ifspawnedby BURNING2
  {
    ifgapzl 16
      break
  }

   ifpdistg 10240
//   ifvare lighting NO
     break

  ifcount 128
  {
    ifspawnedby TIRE
    {
      ifactioncount 512
        killit
      ifrnd 16
        sizeto 64 48
    }
    else ifvare monstflags 0
    {
      sizeto 8 8
      sizeto 8 8
      ifcount 192
        killit
    }
  }
  else
  {
    ifmove 0
      move BURNING_VELS

    ifvare peractor1 1 sizeto 26 26 else
    sizeto 52 52

    ifp palive
      ifpdistl 844
        ifrnd 32
          ifcansee
            ifvare peractor1 0
    {
      soundonce DUKE_LONGTERM_PAIN
      //addphealth -1
      palfrom 24 16
      getplayer[THISACTOR].i spriteid
      getactorvar[spriteid].burning tempb
      addvar tempb 52
      setactorvar[spriteid].burning tempb
      count 128
    }
    findnearactorz SHOOTME 844 6752 spriteid
    ifvarn spriteid -1
    {
	    getactorvar[spriteid].myspawner temp
	    ifvarn temp -1
	    {
		    getactorvar[temp].burning tempb
		    addvar tempb 52
		    setactorvar[temp].burning tempb
		    count 128
	    }
    }
  }

ends

actor BURNING WEAK BURNING_FLAME
  state burningstate
enda

actor BURNING2 WEAK BURNING_FLAME
  state burningstate
enda

action TOILETWATERFRAMES 0 4 1 1 1
actor TOILETWATER 0 TOILETWATERFRAMES
  ifpdistl 8192
  {
    soundonce WATER_GURGLE
    ifspawnedby TOILET
      sizeto 34 34
    else
    {
      ifspawnedby WATERFOUNTAINBROKE
        sizeto 6 15
      else
        ifspawnedby TOILETWATER
          nullop
      else
        sizeto 24 32
    }

    ifp palive
      ifpdistl RETRIEVEDISTANCE
        ifp pfacing
          ifactioncount 32
            ifphealthl MAXWATERFOUNTAINHEALTH
              ifhitspace
                ifcansee
    {
	  ifvare mtype 0
	  {
		  setvar mtype 1
		  sound REFRESHING
		  addphealth 5
	  }
      addphealth 1
      globalsound DUKE_DRINKING
      resetactioncount
    }
  }
enda

action FOUNTAINIDLE -1
action FOUNTAINFLOW 0 3 1 1 6

useractor notenemy WATERFOUNTAIN2 15

ifaction 0 action FOUNTAINIDLE

ifhitweapon ifdead
{
	cactor WATERFOUNTAINBROKE
	spawn TOILETWATER
	sound VENT_BUST
	break
}

ifaction FOUNTAINIDLE
  ifactioncount 12
    ifp palive
     ifpdistl 1536
       ifp pfacing
         ifhitspace
           ifcansee
{
	action FOUNTAINFLOW
	ifphealthl MAXWATERFOUNTAINHEALTH
	{
		ifvare mtype 0
		  {
			  setvar mtype 1
			  sound REFRESHING
			  addphealth 5
		  }
		addphealth 1
		sound DUKE_DRINKING
	}
}

ifaction FOUNTAINFLOW ifactioncount 12 action FOUNTAINIDLE

enda 

action WOODENHORSEFRAME  0   1   4
action WOODENFALLFRAME  122  1   5

actor HORSEONSIDE WEAKEST
  cactor WOODENHORSE
  action WOODENFALLFRAME
enda
actor WOODENHORSE WEAK WOODENHORSEFRAME
setvar weight WEIGHT2
setvar bouncesound ENDSEQVOL2SND4

state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 state throwitem
	break
}
else 
{
	ifmove PHOLDING move INIT geth 
	getactor[THISACTOR].zvel temp
	ifvarg temp 0 setvar mtype 1 // falling
	ifvare mtype 1 ifvare temp 0 { soundvar bouncesound setvar mtype 0 }
} 
state pickupcode

  fall
  ifhitweapon
  {
    ifdead
    {
      debris SCRAP1 4
      debris SCRAP2 3
      killit
    }
    else
      action WOODENFALLFRAME
  }
enda

state steamcode
  ifpdistl 6144
    soundonce STEAM_HISSING

  ifcount 20
    {
      resetcount
      ifp palive
        ifpdistl 1024
      {
        addphealth -1
        palfrom 16 16
      }
    }
  else
  {
    ifspawnedby STEAM
      break
    else
      ifspawnedby CEILINGSTEAM
        break

    sizeto 24 24
  }
ends

action STEAMFRAMES    0     5     1     1     1
actor STEAM 0 STEAMFRAMES
  state steamcode
enda

actor CEILINGSTEAM 0 STEAMFRAMES
  state steamcode
enda

actor WATERBUBBLEMAKER 0 0 randomangle
  ifpdistl 3084
    ifrnd 24
      spawn WATERBUBBLE
enda

action BUBBLE
action CRACKEDBUBBLE  1
move BUBMOVE       -10 -36
move BUBMOVEFAST     -10 -52

actor WATERBUBBLE 0 BUBBLE BUBMOVE getv geth randomangle

  ifaction CRACKEDBUBBLE
  {
	ifvarg underwater 0
	  ifrnd 192
	    killit
    ifinwater
      ifrnd 192
        killit
    ifactioncount 7
      killit
  }
  else
  {
    ifcount 4
    {
      ifrnd 192
        move BUBMOVE getv geth randomangle
      else
        move BUBMOVEFAST getv geth randomangle
      resetcount

      ifrnd 84
        sizeat 8 10
      else
        ifrnd 84
          sizeat 10 8
      else
        sizeat 9 9
    }

    ifonwater
    {
      iffloordistl 8
        action CRACKEDBUBBLE
    }
    else
      ifactioncount 40
        action CRACKEDBUBBLE
  }
enda

move SMOKEVEL 8 -16
move ENGINE_SMOKE 64 -64
move SMOKESHOOTOUT -192
action SMOKEFRAMES 0 4 1 1 10
actor SMALLSMOKE 0 SMOKEFRAMES

  ifvarg underwater 0 { spawn WATERBUBBLE killit }
  
  ifmove 0
  {
	  ifvare monstatus 1 killit
	  ifspawnedby SHOTSPARK1
	  {
		  getactor[THISACTOR].owner spriteid
		  ifvarn spriteid -1
		  {
			  getactorvar[spriteid].mtype temp
			  ifvare temp 1 { ifrnd 32 guts JIBS6 1 killit break }
		  }
	  }
	  ifvare peractor1 1
	  {
		  
		getactor[THISACTOR].z z
		subvar z 3072
		setactor[THISACTOR].z z
		cstat 2
		sizeat 64 64
	    move ENGINE_SMOKE geth getv randomangle
	      
	  } 
      ifvarand morefx 8 
      {
	  	action 0 setvar mtype 1 
	  	changespritestat THISACTOR 1 
	  	cactor NEWSMOKE
	  	break 
      }
      

      
    else
    ifspawnedby RECON
      move SMOKESHOOTOUT geth
    else
      ifspawnedby SECTOREFFECTOR
        move ENGINE_SMOKE geth getv
    else
      ifspawnedby FIREBULLET
        { spritepal 2 cstat 2 move SMOKEVEL geth faceplayer }
    else
      ifspawnedby SHRAPNEL
        { spritepal 2 move SMOKEVEL geth faceplayer }
    else
      ifspawnedby NEWSCRAP6
        { cstator 2 ifrnd 128 cstator 512 move SMOKEVEL geth faceplayer }
    else
      ifspawnedby NEWSCRAP3
        { cstator 2 ifrnd 128 cstator 512 move SMOKEVEL geth faceplayer }    
    else
      move SMOKEVEL geth getv faceplayer
    ifspawnedby RPG
      cstat 2
  }
  ifpdistl 1596
    ifspawnedby RPG
      killit
  ifactioncount 4
    killit
enda

move SMOKEMOVE 0 -14
move SMOKEMOVE3 32 -14
move SMOKEMOVE4 16 -14
move SMOKEMOVE5 0 -32
move ENGINESMOKE -96 -64

move SMOKEMOVE2
action NEWSMOKEA 0 12 1 1 11
action NEWSMOKEB 0 12 1 1 4
action NEWSMOKEC 0 12 1 1 2
action NEWSMOKED 0 12 1 1 3
action NEWSMOKEE 0 12 1 1 20

useractor notenemy NEWSMOKE 0

ifmove 0
{
	ifrnd 128 cstator 8
	ifrnd 128 cstator 4
	ifspawnedby SKYCAR_CRASHED
	{
		action NEWSMOKEA 
		sizeat 64 64
		move SMOKEMOVE getv
		break
	}
	ifspawnedby DUKEBIKE
	{
		action NEWSMOKED
		sizeat 128 128
		getactor[THISACTOR].ang angvar
		randvar temp 512 subvar temp 128
		addvarvar angvar temp
		setactor[THISACTOR].ang angvar
		move ENGINESMOKE geth getv
		break
	}
	ifspawnedby BIGBOMB
	{
		action NEWSMOKEE
		sizeat 128 128
		move SMOKEMOVE getv
		break
	}
	ifspawnedby DPCANNONBALL
	{
		action NEWSMOKEE
		sizeat 128 128
		move SMOKEMOVE getv
		break
	}
	ifspawnedby POWEXPLOSION
	{
		action NEWSMOKEE
		sizeat 128 128
		move SMOKEMOVE getv
		break
	}
	ifspawnedby EXPLOSION2 
	{
		ifvarg sprite[THISACTOR].xrepeat 192
		action NEWSMOKEE
		else action NEWSMOKEA 
		// cstator 2
		getactor[THISACTOR].xrepeat initx
		ifvarl initx 41 move SMOKEMOVE4 geth getv randomangle else
		move SMOKEMOVE3 geth getv randomangle
		break
	}
	ifspawnedby LIZARDVOMIT
	{
		action NEWSMOKEB
		sizeat 24 24
		cstator 2
		spritepal 8
		move SMOKEMOVE2
		break
	}
	ifspawnedby ICESHARD
	{
		action NEWSMOKEA
		sizeat 12 12
		cstator 514
		move SMOKEMOVE2
		break
	}
	ifspawnedby FIREBALLPROJ
	{
		action NEWSMOKEB
		move SMOKEMOVE2
        sizeat 32 32
        spritepal 2
        cstator 128
        break
    }
	else
	ifspawnedby RPG 
	{
		action NEWSMOKEB
		ifvare rendmode 0 sizeat 32 32 else
		sizeat 48 48
		move SMOKEMOVE faceplayer
		break
	}
	else
	action NEWSMOKEB
	ifvare mtype 1 sizeat 32 32
	cstator 128
	
 	  ifspawnedby SHOTSPARK1
	  {
		  getactor[THISACTOR].owner spriteid
		  ifvarn spriteid -1
		  {
			  getactorvar[spriteid].mtype temp
			  ifvare temp 1 { ifrnd 32 guts JIBS6 1 killit }
		  }
	  }
	ifvare peractor1 1
	{
      move ENGINE_SMOKE geth getv randomangle
      sizeat 64 64
    }
    else
    ifspawnedby RECON
      move SMOKESHOOTOUT geth
    else
      ifspawnedby SECTOREFFECTOR
        move ENGINE_SMOKE geth getv
    else
      ifspawnedby FIREBULLET
        { spritepal 2 cstator 2 move SMOKEVEL geth faceplayer }
    else
      ifspawnedby SHRAPNEL
        { spritepal 2 move SMOKEVEL geth faceplayer }
    else
      ifspawnedby NEWSCRAP6
        { action NEWSMOKEC cstator 2 ifrnd 128 cstator 512 move SMOKEVEL geth faceplayer }
    else
      ifspawnedby NEWSCRAP3
        { action NEWSMOKEC cstator 2 ifrnd 128 cstator 512 move SMOKEVEL geth faceplayer } 
    else
      ifspawnedby ROCKETHALO
        move SMOKEVEL geth getv faceplayer
    else
      ifspawnedby LASERIMPACT
        move SMOKEVEL geth getv faceplayer   
    else
    {
      move SMOKEVEL geth getv faceplayer
      sizeat 32 32
    }
}

ifaction NEWSMOKEA ifactioncount 8 cstator 512
	         
ifactioncount 12 killit

ifpdistl 1596
    ifspawnedby RPG
      killit

  ifinwater
  { 
    spawn WATERBUBBLE
    killit
  }
  ifvarg underwater 0
  { 
    spawn WATERBUBBLE
    killit
  }
enda

action ICESMOKEFRAMES -3 12 1 1 14
useractor notenemy ICESMOKE 0

ifmove 0
{
	action ICESMOKEFRAMES
	sizeat 128 128
	spritepal 12
	cstat 2
	move SMOKEMOVE5 randomangle getv 
	getactor[THISACTOR].ang angvar
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	setvarvar mx x
	addvar mx 480
	rotatepoint x y mx y angvar mx my
	setactor[THISACTOR].x mx
	setactor[THISACTOR].y my
}

ifactioncount 12 killit
enda

action GASCLOUDFRAMES -2 12 1 1 20
action SLOWGASCLOUD -2 12 1 1 40
move CLOUDMOVE 48 -8
move CLOUDMOVE2 48 8
useractor notenemy POISONGAS 0 SLOWGASCLOUD
ifmove 0
{
	sizeat 192 192
	randvar temp 2
	ifvare temp 0 move CLOUDMOVE geth getv randomangle else
	ifvare temp 1 move CLOUDMOVE2 geth getv randomangle else
	ifvare temp 2 move CLOUDMOVE geth randomangle
	ifspritepal 8
	{
		action GASCLOUDFRAMES
		ifrnd 128 cstat 514 else cstat 518
	}
	else
		ifrnd 128 cstat 4
	
	
	// spritepal 8
	randvar countvar 52
}

ifactioncount 12 killit

addvar countvar 1
ifvarg countvar 52
{
	setvar countvar 0
	ifp palive
		ifcansee
			ifpdistl 1280
			{
				setvar smokecount 78
				ifrnd 96 soundonce DUKE_LONGTERM_PAIN
				ifspritepal 0 
				{ 
					palfrom 50 63 63 63 
					ifrnd 128 addphealth -1
				} 
				else
				{
					addphealth -1
					palfrom 30 10 63 10
				}
			}
}
	
enda

useractor notenemy POISONGASMAKER 0

ifmove 0
{
	move INIT
	cstat 32768
	sizeat 16 16
	ifspawnedby GASGRENADE { setvar pal 0 debris SCRAP3 3 debris SCRAP6 3 }
	else setvar pal 8
}

ifvare countvar 0 setvar countvar 2
getactor[THISACTOR].x initx
getactor[THISACTOR].y inity
getactor[THISACTOR].z initz
setvar peractor1 0
whilevarn peractor1 2 //3
{
	setvarvar tempc countvar
	shiftvarl tempc 5 //6
	randvarvar x tempc
	setvarvar temp x
	ifrnd 128 mulvar x -1
	setvarvar mx initx
	addvarvar mx x
	randvarvar y tempc
	setvarvar tempb y
	ifrnd 128 mulvar y -1
	setvarvar my inity
	addvarvar my y
	addvarvar temp tempb
	setvar tempb 10240 //16384
	subvarvar tempb temp
	randvarvar z tempb
	iffloordistl 48 nullop else
	ifrnd 128 mulvar z -1
	setvarvar mz initz
	subvarvar mz z
	espawn POISONGAS
	setactor[RETURN].x mx
	setactor[RETURN].y my
	setactor[RETURN].z mz
	setactor[RETURN].pal pal
	addvar peractor1 1
}
addvar countvar 1
ifspritepal 0 { ifvarg countvar 52 killit } else
ifvarg countvar 26 killit


enda

action BARREL_DENTING  2 2 1 1 6
action BARREL_DENTED   1
action BARREL_DENTED2  2

move SPAWNED_BLOOD

actor NUKEBARRELDENTED WEAK
  cactor NUKEBARREL
  action BARREL_DENTED
enda

actor NUKEBARRELLEAKED WEAK
  cactor NUKEBARREL
  action BARREL_DENTED2
enda


eventloadactor NUKEBARREL
getactor[THISACTOR].extra monstflags
ifvare monstflags -1 setvar monstflags 0
enda

actor NUKEBARREL MEDIUMSTRENGTH

setvar weight WEIGHT3
setvar bouncesound METALTHUD
state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 state throwitem
	break
}
else 
{
	ifmove PHOLDING move INIT geth 
	getactor[THISACTOR].zvel temp
	ifvarg temp 0 setvar mtype 1 // falling
	ifvare mtype 1 ifvare temp 0 { soundvar bouncesound setvar mtype 0 }
}
state pickupcode


  ifsquished
  {
    debris SCRAP1 32
    spawn BLOODPOOL
    state random_ooz
    killit
  }
  //ifvarand monstflags 1 
  ifvarn underwater 0 state barrelinwatercode
  ifvarg underwater 0 ifceilingdistl 48 nullop else
  fall
  ifaction BARREL_DENTING
  {
    ifactioncount 2
    {
      debris SCRAP1 10
      ifrnd 2 spawn BLOODPOOL
      killit
    }
  }
  else
    ifhitweapon
  {
    ifdead
    {
      sound VENT_BUST
      ifrnd 128
        spawn BLOODPOOL
      action BARREL_DENTING
    }
    else
    {
      ifaction 0
        action BARREL_DENTED
      else
        ifaction BARREL_DENTED
      {
        action BARREL_DENTED2
        spawn BLOODPOOL
      }
      else
        ifaction BARREL_DENTED2
          action BARREL_DENTING
    }
  }
enda

state burningbarrelcode
setvar bouncesound METALTHUD
setvar weight WEIGHT3
state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 state throwitem
	break
}
else 
{
	ifmove PHOLDING move INIT geth 
	getactor[THISACTOR].zvel temp
	ifvarg temp 0 setvar mtype 1 // falling
	ifvare mtype 1 ifvare temp 0 { soundvar bouncesound setvar mtype 0 }
}
state pickupcode

  fall
  ifcount 32
  {
    resetcount
    ifp palive
      ifpdistl 1480
        ifp phigher
    {
      addphealth -1
      palfrom 16 16
      ifrnd 96
        sound DUKE_LONGTERM_PAIN   
    }
  }
  ifhitweapon
  {
    sound VENT_BUST
    debris SCRAP1 10
    ifrnd 128
      spawn BURNING
    else
      spawn BURNING2
    killit
  }
ends

actor FIREBARREL
  state burningbarrelcode
enda
actor FIREVASE
  state burningbarrelcode
enda

action SHRINKERFRAMES 0 4 1 1 10
actor SHRINKEREXPLOSION 0 SHRINKERFRAMES
  ifactioncount 4
    killit
enda

move AWAYFROMWALL 24
action EXPLOSION_FRAMES 0 20 1 1  4
action EXPLOSION_FRAMES2 4535 20 1 1 4
action EXPLOSION_FRAMES3 4556 20 1 1 4
actor EXPLOSION2 1 EXPLOSION_FRAMES

ifpdistl 65535
{
	ifactorsound THISACTOR PIPEBOMB_EXPLODE
	{
		stopactorsound THISACTOR PIPEBOMB_EXPLODE
		displayrandvar temp 2
		ifvare temp 0 sound PIPEBOMB_EXPLODE2 else
		ifvare temp 1 sound NEW_EXPLODE else
		ifvare temp 2 sound NEW_EXPLODE2
	}
	ifactorsound THISACTOR RPG_EXPLODE
	{
		stopactorsound THISACTOR RPG_EXPLODE
		displayrandvar temp 2
		ifvare temp 0 sound RPG_EXPLODE2 else
		ifvare temp 1 sound NEW_EXPLODE else
		ifvare temp 2 sound NEW_EXPLODE2
	}
}

ifcount 1 nullop else
{
	ifvarand morefx 1
	{
		ifrnd 128 cstator 8
		ifrnd 128 action EXPLOSION_FRAMES2 else action EXPLOSION_FRAMES3
		move AWAYFROMWALL faceplayer
	}
	else
	ifceilingdistl 8 cstator 8
	ifvare smartmonsters YES state wakeupmonsters
	ifrnd 128 cstator 4
	ifspawnedby HEAVYHBOMB ifvare effects YES
	{
		setvar countvar 0
		getactor[THISACTOR].ang position
		whilevarn countvar 12
		{
			addvar countvar 1
			randvar zdist 8192 subvar zdist 6144 
			ifrnd 128 ezshoot zdist NEWSCRAP3 else 
			ezshoot zdist NEWSCRAP6
			ifrnd 128 setthisprojectile[RETURN].trail SMALLSMOKE
			randvar temp 128
			addvar temp 160
			setthisprojectile[RETURN].vel temp
			addvar position 170
			setactor[THISACTOR].ang position
		}
	}
// 	ifvare lighting YES ifvarl highlight 10
// 	{
// 			setvar intensity 80
// 			state enter_light_array
// 	}
	ifspawnedby FIREBALLPROJ 
	{
		sizeat 16 16
		cstator 128
		ifrnd 64 spawn BURNING else ifrnd 64 spawn BURNING2
	}
	ifspawnedby BIGBOMB
	{
		sizeat 64 64
		hitradius 3072 30 40 50 60
		espawn SCORCH
		state getfloorz
		setactor[RETURN].z z
		setactor[RETURN].cstat 32
		setactorvar[RETURN].lotag 1
	}
			
	ifvare peractor1 1 
		sizeat 80 80
	
	ifspawnedby SHOTSPARK1 ifvarn ONCAR 0 { sound PIPEBOMB_EXPLODE hitradius 1280 10 15 20 25 setvar weap 1 }
	ifvare weap 1 sizeat 16 16
}

// ifvarg intensity 2 subvar intensity 2

ifcount 18 nullop else ifcount 17 ifvarand morefx 8
{
	getactor[THISACTOR].xrepeat x
	shiftvarl x 2 
	ifvarg x 254 setvar x 255
	ifvarl x 40 setvar x 40
	espawn NEWSMOKE
	setactor[RETURN].xrepeat x
	setactor[RETURN].yrepeat x
	//ifvarl framerate 20 break
	espawn NEWSMOKE
	setactor[RETURN].xrepeat x
	setactor[RETURN].yrepeat x
	espawn NEWSMOKE
	setactor[RETURN].xrepeat x
	setactor[RETURN].yrepeat x
	espawn NEWSMOKE
	setactor[RETURN].xrepeat x
	setactor[RETURN].yrepeat x
}

  ifactioncount 20
    killit
    
  
enda

actor EXPLOSION2BOT 1 EXPLOSION_FRAMES
ifcount 1 nullop else
ifspawnedby FIREBULLET
  hitradius 1024 3 6 9 12
  ifactioncount 20
    killit
enda

action FFLAME_FR 0 16 1 1 1
action FFLAME 0 1 1 1 1

actor FLOORFLAME 0 FFLAME_FR

  ifaction FFLAME_FR
  {
    ifpdistl 1024
      hitradius 1024 WEAKEST WEAKEST WEAKEST WEAKEST
    ifactioncount 16
    {
      action FFLAME
      // ifvare lighting YES
      // state exitlightarray
    }
  }
  ifaction FFLAME
    ifrnd 4
  {
    action FFLAME_FR
    sound CAT_FIRE
//     ifvare lighting YES
//     {
// 	    setvar intensity 100
// 	    state enter_light_array
//     }
    resetactioncount
  }
enda



action RIP_F 0 8 1 1 1
actor FORCERIPPLE 0 RIP_F
  ifactioncount 8
    killit
enda

action TRANSFOWARD 0  6  1  1  2
action TRANSBACK   5  6  1 -1  2
action TRANSFOWARDFX 4848  20  1  1  1
actor TRANSPORTERSTAR 0 TRANSFOWARD

ifmove 0
{
	move INIT
	ifspawnedby FREEZENOAIM spritepal 1 else
	ifspawnedby FREEZEBLAST nullop else
	ifvarand morefx 8
		setvar mtype 1
}


ifvare mtype 1
{
	ifaction TRANSFOWARD action TRANSFOWARDFX
	ifaction TRANSFOWARDFX
	{
		ifactioncount 20
		  killit
	}
	break
}

  ifaction TRANSFOWARD
  {
    ifactioncount 6
      action TRANSBACK
  }
  else
    ifactioncount 6
      killit
enda


state lifebarcode

ifmove 0
{
	move INIT
	sizeat 50 10
	cstat 0
	getactor[myspawner].extra initx // stores the spawners initial hitpoints
}

getactor[myspawner].statnum temp
ifvare temp 1024 killit
getactorvar[myspawner].monstatus temp
ifvarn temp 1 killit


ifp pfacing 
{
	getactor[myspawner].cstat temp
	ifvarand temp 32768 cstat 32768 else
	cstat 0 
}	    
else cstat 32768

getactor[myspawner].x x
getactor[myspawner].y y
getactor[myspawner].z z

getactor[myspawner].yrepeat temp
mulvar temp 360 //384
getactor[myspawner].picnum picnum
switch picnum
case BOSS1
case BOSS2
case BOSS3
case BOSS4
mulvar temp 3 divvar temp 2
break
default break
endswitch
subvarvar z temp
updatesectorz x y z mysector

ifvarn mysector -1
{
	setactor[THISACTOR].x x
	setactor[THISACTOR].y y
	setactor[THISACTOR].z z
	changespritesect THISACTOR mysector
}

getactor[myspawner].extra temp
ifvarvarg temp initx setvarvar initx temp
ifvarvarn temp hp { spritepal 6 resetcount }
else ifcount 2 
{
	getactorvar[myspawner].playerally playerally
	ifvarn playerally 0 spritepal 1 else
	spritepal 10
}
setvarvar hp temp

setvarvar tempb initx
shiftvarr tempb 5
ifvarl tempb 1 setvar tempb 1
divvarvar temp tempb
ifvarl temp 1 setvar temp 1
setactor[THISACTOR].xrepeat temp
ends

useractor notenemy LIFEBAR 0
state lifebarcode
enda

action BEAMFOWARD  0  4  1  1  9
actor TRANSPORTERBEAM 0 BEAMFOWARD
  sizeto 32 64
  sizeto 32 64
  sizeto 32 64
  ifactioncount 4
    killit
enda

state getcode
  ifactor ATOMICHEALTH
    globalsound GETATOMICHEALTH
  else
ifvare dpsounds YES
{
  ifactor AMMO
    globalsound AMMOPICK
  else
  ifactor SHOTGUNAMMO
    globalsound SHOTPICK
  else
  ifactor BATTERYAMMO
    globalsound CHAINPICK
  else
  ifactor MP5CLIP
    globalsound CLIPPICK
  else
  ifactor RPGAMMO
    globalsound RPGPICK
  else
  ifactor DEVISTATORAMMO
    globalsound RPGPICK
  else
  ifactor CRYSTALAMMO
    globalsound SHRINKPICK
  else
  ifactor FREEZEAMMO
    globalsound FREEZEPICK
  else
  ifactor GROWAMMO
    globalsound GROWPICK
  ifactor SHIELD
    globalsound ARMORPICK
  else
    globalsound DUKE_GET
}
  else
    globalsound DUKE_GET
  palfrom 16 0 32
  ifrespawn
  {
    move RESPAWN_ACTOR_FLAG
    spawn RESPAWNMARKERRED
    cstat 32768
  }
  else
    killit
ends

state randgetweapsnds

ifactor LASERPISTOL
ifvarl LASERAMMO 31 { globalsound ALIENTECH break }
ifactor DBSPRITE { globalsound DBCLOSE break }
ifvare dpsounds YES globalsound GUNPICK
  ifrnd 64
    globalsound DUKE_GETWEAPON1
  else
    ifrnd 96
      globalsound DUKE_GETWEAPON2
  else
    ifrnd 128
      globalsound DUKE_GETWEAPON3
  else
    ifrnd 140
      globalsound DUKE_GETWEAPON4
  else
    globalsound DUKE_GETWEAPON6
ends

state getweaponcode

  state randgetweapsnds

  palfrom 32 0 32
  ifgotweaponce 1
    break
  ifrespawn
  {
    move RESPAWN_ACTOR_FLAG
    spawn RESPAWNMARKERRED
    cstat 32768
  }
  else
    killit
ends


state respawnit
  ifcount RESPAWNITEMTIME
  {
    spawn TRANSPORTERSTAR
    move 0
    cstat 0
    sound TELEPORTER
  }
ends

state quikget
ifvare dpsounds YES
{
  ifactor AMMO
    globalsound AMMOPICK
  else
  ifactor SHOTGUNAMMO
    globalsound SHOTPICK
  else
  ifactor BATTERYAMMO
    globalsound CHAINPICK
  else
  ifactor MP5CLIP
    globalsound CLIPPICK
  else
   ifactor RPGAMMO
    globalsound RPGPICK
  else
   ifactor CRYSTALAMMO
    globalsound SHRINKPICK
  else
  ifactor DEVISTATORAMMO
  {
	ifvare usebfg YES globalsound IMP_AMMO else
    globalsound RPGPICK
  }
  else
  ifactor FREEZEAMMO
    globalsound FREEZEPICK
  else
  ifactor GROWAMMO
    globalsound GROWPICK
  else
  ifactor ATOMICHEALTH
    globalsound GETATOMICHEALTH
  else
  ifactor SHIELD
    globalsound ARMORPICK
  else
    globalsound DUKE_GET
}
else
{ 
	ifactor ATOMICHEALTH
    globalsound GETATOMICHEALTH
    else
    globalsound DUKE_GET
}
  palfrom 16 0 32
  killit
ends

state quikweaponget
  state randgetweapsnds
  palfrom 32 0 32
  ifgotweaponce 1
    break
  killit
ends

state duplicate
ifactor RESPAWN
{
	orvar monstflags 2
	break
}
getactor[THISACTOR].picnum picnum
ifvarn picnum BOSS1 ifvarn picnum BOSS2 ifvarn picnum BOSS3 ifvarn picnum BOSS4 ifvarn picnum BOSS1STAYPUT
ifvarn picnum ROTATEGUN
{
	espawnvar picnum
	getactor[THISACTOR].xrepeat temp
	setactor[RETURN].xrepeat temp
	getactor[THISACTOR].yrepeat temp
	setactor[RETURN].yrepeat temp
	getactor[THISACTOR].cstat temp
	setactor[RETURN].cstat temp
	getactor[THISACTOR].pal temp
	setactor[RETURN].pal temp
	getactor[THISACTOR].shade temp
	setactor[RETURN].shade temp
	getactor[THISACTOR].lotag temp
	setactor[RETURN].lotag temp
	getactor[THISACTOR].hitag temp
	setactor[RETURN].hitag temp
	getactor[THISACTOR].extra temp
	setactor[RETURN].extra temp
	getactor[THISACTOR].xvel temp
	setactor[RETURN].xvel temp
	getactor[THISACTOR].yvel temp
	setactor[RETURN].yvel temp
	getactor[THISACTOR].zvel temp
	setactor[RETURN].zvel temp
	setactorvar[RETURN].initcstat initcstat
	setactorvar[RETURN].monstflags monstflags
	ifvarn droptile 60 ifvarn droptile 62 ifvarn droptile 63
	setactorvar[RETURN].droptile droptile
	setactorvar[RETURN].lotag lotag
} else { orvar monstflags 2 orvar monstflags 8 }

randvar angvar 2047
cos xvel angvar
sin yvel angvar

ifvare scaled NO
{
	shiftvarr xvel 3
	shiftvarr yvel 3
}
else
{
	shiftvarr xvel 2
	shiftvarr yvel 2
}

movesprite RETURN xvel yvel 0 CLIPMASK0 temp
ends

eventloadactor ACCESSSWITCH
{	
	getactor[THISACTOR].lotag lotag
	getactor[THISACTOR].pal pal
	ifvarg pal 65
	setactor[THISACTOR].pal 0
	getactor[THISACTOR].xvel peractor1
	getactor[THISACTOR].yvel activator
	getactor[THISACTOR].picnum command
	espawn ACCESSSWITCH
	getactor[THISACTOR].ang angvar
	addvar angvar 512
	setactor[RETURN].ang angvar
	setactor[RETURN].pal pal
	setactor[RETURN].cstat 32808
	setactor[RETURN].xrepeat 255
	setactor[RETURN].yrepeat 255
	setactorvar[RETURN].myspawner THISACTOR
	setactorvar[RETURN].pulse 2
}
enda

eventloadactor ACCESSSWITCH2
{
	getactor[THISACTOR].lotag lotag
	getactor[THISACTOR].pal pal
	ifvarg pal 65
	setactor[THISACTOR].pal 0
	getactor[THISACTOR].xvel peractor1
	getactor[THISACTOR].yvel activator
	getactor[THISACTOR].picnum command
	espawn ACCESSSWITCH
	getactor[THISACTOR].ang angvar
	addvar angvar 512
	setactor[RETURN].ang angvar
	setactor[RETURN].pal pal
	setactor[RETURN].cstat 32808
	setactor[RETURN].xrepeat 255
	setactor[RETURN].yrepeat 255
	setactorvar[RETURN].myspawner THISACTOR
	setactorvar[RETURN].pulse 2
}
enda

action BFGFRAME 6190 1 1 1 1
	
//eventloadactor ACCESSSWITCH { state mapitemload } enda
eventloadactor 131 { state mapitemload } enda
eventloadactor SLOTDOOR { state mapitemload } enda
eventloadactor 133 { state mapitemload } enda
eventloadactor LIGHTSWITCH { state mapitemload } enda
eventloadactor 135 { state mapitemload } enda
eventloadactor SPACEDOORSWITCH { state mapitemload } enda
eventloadactor 137 { state mapitemload } enda
eventloadactor SPACELIGHTSWITCH { state mapitemload } enda
eventloadactor 139 { state mapitemload } enda
eventloadactor FRANKENSTINESWITCH { state mapitemload } enda
eventloadactor 141 { state mapitemload } enda
eventloadactor NUKEBUTTON { state mapitemload } enda
eventloadactor MULTISWITCH { state mapitemload } enda
eventloadactor 147 { state mapitemload } enda
eventloadactor 148 { state mapitemload } enda
eventloadactor 149 { state mapitemload } enda
eventloadactor DIPSWITCH { state mapitemload } enda
eventloadactor 163 { state mapitemload } enda
eventloadactor DIPSWITCH2 { state mapitemload } enda
eventloadactor 165 { state mapitemload } enda
eventloadactor TECHSWITCH { state mapitemload } enda
eventloadactor 167 { state mapitemload } enda
eventloadactor DIPSWITCH3 { state mapitemload } enda
eventloadactor 169 { state mapitemload } enda
//eventloadactor ACCESSSWITCH2 { state mapitemload } enda
eventloadactor 171 { state mapitemload } enda
eventloadactor LIGHTSWITCH2 { state mapitemload } enda
eventloadactor 713 { state mapitemload } enda
eventloadactor POWERSWITCH1 { state mapitemload } enda
eventloadactor 861 { state mapitemload } enda
eventloadactor LOCKSWITCH1 { state mapitemload } enda
eventloadactor 863 { state mapitemload } enda
eventloadactor POWERSWITCH2 { state mapitemload } enda
eventloadactor 865 { state mapitemload } enda
eventloadactor HANDSWITCH { state mapitemload } enda
eventloadactor 1112 { state mapitemload } enda
eventloadactor PULLSWITCH { state mapitemload } enda
eventloadactor 1123 { state mapitemload } enda
eventloadactor ALIENSWITCH { state mapitemload } enda
eventloadactor 1143 { state mapitemload } enda
eventloadactor HANDPRINTSWITCH { state mapitemload } enda

eventloadactor AMMO { setvar weight WEIGHT1 state mapitemload } enda
eventloadactor FIRSTGUNSPRITE { setvar weight WEIGHT1 state mapitemload } enda
eventloadactor CHAINGUNSPRITE { setvar weight WEIGHT2 state mapitemload } enda
eventloadactor RPGSPRITE { setvar weight WEIGHT2 state mapitemload } enda
eventloadactor FREEZESPRITE { setvar weight WEIGHT2 state mapitemload } enda
eventloadactor SHRINKERSPRITE { setvar weight WEIGHT2 state mapitemload } enda
eventloadactor GROWSPRITEICON { setvar weight WEIGHT2 state mapitemload } enda
eventloadactor HEAVYHBOMB { setvar weight WEIGHT1 state mapitemload } enda
eventloadactor TRIPBOMBSPRITE { setvar weight WEIGHT1 state mapitemload } enda
eventloadactor SHOTGUNSPRITE { setvar weight WEIGHT2 state mapitemload } enda
eventloadactor DBSPRITE { setvar weight WEIGHT2 state mapitemload } enda
eventloadactor DEVISTATORSPRITE { setvar weight WEIGHT2 state mapitemload } enda
eventloadactor FREEZEAMMO { setvar weight WEIGHT1 state mapitemload ifvare doubled YES state duplicate } enda
eventloadactor BATTERYAMMO { setvar weight WEIGHT1 state mapitemload ifvare doubled YES state duplicate } enda
eventloadactor DEVISTATORAMMO { setvar weight WEIGHT1 state mapitemload ifvare doubled YES state duplicate } enda
eventloadactor RPGAMMO { setvar weight WEIGHT1 state mapitemload ifvare doubled YES state duplicate } enda
eventloadactor GROWAMMO { setvar weight WEIGHT1 state mapitemload ifvare doubled YES state duplicate } enda
eventloadactor CRYSTALAMMO { setvar weight WEIGHT1 state mapitemload ifvare doubled YES state duplicate } enda
eventloadactor HBOMBAMMO { setvar weight WEIGHT2 state mapitemload ifvare doubled YES state duplicate } enda
eventloadactor AMMOLOTS { setvar weight WEIGHT2 state mapitemload ifvare doubled YES state duplicate } enda
eventloadactor SHOTGUNAMMO { setvar weight WEIGHT1 state mapitemload } enda
eventloadactor COLA { setvar weight WEIGHT1 state mapitemload ifvare doubled YES state duplicate } enda
eventloadactor SIXPAK { setvar weight WEIGHT1 state mapitemload ifvare doubled YES state duplicate } enda
eventloadactor FIRSTAID { setvar weight WEIGHT2 state mapitemload } enda
eventloadactor SHIELD { setvar weight WEIGHT2 state mapitemload ifvare doubled YES state duplicate } enda
eventloadactor STEROIDS { setvar weight WEIGHT1 state mapitemload ifvare doubled YES ifvare scaled YES state duplicate } enda
eventloadactor AIRTANK { setvar weight WEIGHT2 state mapitemload } enda
eventloadactor JETPACK { setvar weight WEIGHT2 state mapitemload ifvare doubled YES  ifvare scaled YES state duplicate } enda
eventloadactor HEATSENSOR { setvar weight WEIGHT1 state mapitemload } enda
eventloadactor ACCESSCARD { setvar weight WEIGHT1 state mapitemload } enda
eventloadactor BOOTS { setvar weight WEIGHT1 state mapitemload ifvare doubled YES  ifvare scaled YES state duplicate } enda
eventloadactor ATOMICHEALTH { setvar weight WEIGHT1 state mapitemload } enda
eventloadactor HEALTHUPGRADE sizeat 40 40 getactor[THISACTOR].extra hp ifvare hp -1 setvar hp 10 enda
eventloadactor ARMORUPGRADE sizeat 40 40 getactor[THISACTOR].extra hp ifvare hp -1 setvar hp 10 enda
eventloadactor WOUNDUPGRADE sizeat 40 40 enda
eventloadactor BURNINGUPGRADE sizeat 40 40 enda
eventloadactor STUNUPGRADE sizeat 40 40 enda
eventloadactor PIERCINGUPGRADE sizeat 40 40 enda

state upgradeitemcode

ifmove 0
{
	move INIT
	sizeat 40 40
	ifvarl hp 1 setvar hp 10
	getactor[THISACTOR].z z
	subvar z 4096
	setactor[THISACTOR].z z
	cstat 16
	setvar intensity 2048
	setvar pal 0
	setvar tempd 2
	state spawnpointlight
}

getactor[THISACTOR].ang angvar
subvar angvar 40
setactor[THISACTOR].ang angvar

ifp pshrunk nullop else
ifp palive
ifpdistl RETRIEVEDISTANCE
ifcanseetarget
{
	globalsound ESHIELDPICK
	palfrom 42 63 63 63
	ifactor HEALTHUPGRADE 
	{ 
		getplayer[THISACTOR].max_player_health temp addvarvar temp hp setplayer[THISACTOR].max_player_health temp 
		quote 1183 addphealth 100 
	} else
	ifactor ARMORUPGRADE 
	{ 
		getplayer[THISACTOR].max_shield_amount temp addvarvar temp hp setplayer[THISACTOR].max_shield_amount temp 
		quote 1184 addphealth 100 
	} else
	ifactor WOUNDUPGRADE { orvar ppowers 1 quote 1185 } else
	ifactor BURNINGUPGRADE { orvar ppowers 2 quote 1186 } else
	ifactor STUNUPGRADE { orvar ppowers 4 quote 1187 } else
	ifactor PIERCINGUPGRADE { orvar ppowers 8 quote 1188 }
	killit
}

ends

useractor notenemy HEALTHUPGRADE 0 state upgradeitemcode enda
useractor notenemy ARMORUPGRADE 0 state upgradeitemcode enda
useractor notenemy WOUNDUPGRADE 0 state upgradeitemcode enda
useractor notenemy BURNINGUPGRADE 0 state upgradeitemcode enda
useractor notenemy STUNUPGRADE 0 state upgradeitemcode enda
useractor notenemy PIERCINGUPGRADE 0 state upgradeitemcode enda


actor STEROIDS
  ifvarvarn holding THISACTOR fall
  state moveitem
  
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk
      nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifpinventory GET_STEROIDS STEROID_AMOUNT
              ifcanseetarget
      {
        addinventory GET_STEROIDS STEROID_AMOUNT
        setvar RETURN 37 state itemquote
        ifspawnedby STEROIDS
          state getcode
        else
          state quikget
      }


enda

actor BOOTS
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk
      nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifpinventory GET_BOOTS BOOT_AMOUNT
              ifcanseetarget
      {
        addinventory GET_BOOTS BOOT_AMOUNT
        setvar RETURN 6 state itemquote
        ifspawnedby BOOTS
          state getcode
        else
          state quikget
      }

enda

actor HEATSENSOR
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk
      nullop
  else
    ifp palive
      ifcount 6
        ifpdistl RETRIEVEDISTANCE
          ifpinventory GET_HEATS HEAT_AMOUNT
            ifcanseetarget
      {
        addinventory GET_HEATS HEAT_AMOUNT
        setvar RETURN 101 state itemquote
        ifspawnedby HEATSENSOR
          state getcode
        else
          state quikget
      }

enda

actor SHIELD
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifpinventory GET_SHIELD SHIELD_AMOUNT
              ifcanseetarget
      {
        ifspawnedby PIGCOP
        {
          ifrnd 128
            addinventory GET_SHIELD PIG_SHIELD_AMOUNT1
          else
            addinventory GET_SHIELD PIG_SHIELD_AMOUNT2
          setvar RETURN 104 state itemquote
          sound KICK_HIT
          palfrom 24 0 32
          killit
        }
        else
          addinventory GET_SHIELD SHIELD_AMOUNT
        setvar RETURN 38 state itemquote
        ifspawnedby SHIELD
          state getcode
        else
          state quikget
      }

enda


actor AIRTANK
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifpinventory GET_SCUBA SCUBA_AMOUNT
              ifcanseetarget
      {
        addinventory GET_SCUBA SCUBA_AMOUNT
        setvar RETURN 39 state itemquote
        ifspawnedby AIRTANK
          state getcode
        else
          state quikget
      }

enda

action HOLODUKE_FRAMES 0 4 1 1 8
actor HOLODUKE 0 HOLODUKE_FRAMES
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifpinventory GET_HOLODUKE HOLODUKE_AMOUNT
              ifcanseetarget
      {
        addinventory GET_HOLODUKE HOLODUKE_AMOUNT
        setvar RETURN 51 state itemquote
        ifspawnedby HOLODUKE
          state getcode
        else
          state quikget
      }

enda

actor JETPACK
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifpinventory GET_JETPACK JETPACK_AMOUNT
              ifcanseetarget
      {
        addinventory GET_JETPACK JETPACK_AMOUNT
        setvar RETURN 41 state itemquote
        ifspawnedby JETPACK
          state getcode
        else
          state quikget
      }

enda

actor ACCESSCARD
  ifvarvarn holding THISACTOR fall
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvarn peractor4 0 setvar mtype 1 // was dropped
  ifvare mtype 1 ifpdistl 8192 quote 1124
  //state moveitem
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  //state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        ifpinventory GET_ACCESS 0
          break
        ifspritepal 66 spritepal 0
        addinventory GET_ACCESS 1
        setvar RETURN 43 state itemquote
        state getcode
      }

enda

actor AMMO
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
      {
	    ifvare CURRWEAP 0 ifvarg LASERAMMO 0
	    {
		    // this hack is necessary for preventing the addammo from switching the player to pistol
		    getplayer[THISACTOR].ammo_amount 1 temp
		    ifvare temp MAXPISTOLAMMO break
		    ifvare depistols YES addvar temp 8 else
		    addvar temp PISTOLAMMOAMOUNT
		    ifvarg temp MAXPISTOLAMMO setvar temp MAXPISTOLAMMO
		    setplayer[THISACTOR].ammo_amount 1 temp
	    }
	    else
	    {
		    ifvare depistols YES
		    addammo PISTOL_WEAPON 8
		    else
        	addammo PISTOL_WEAPON PISTOLAMMOAMOUNT
    	}
        setvar RETURN 65 state itemquote
        ifspawnedby AMMO
          state getcode
        else
          state quikget
      }

enda

actor FREEZEAMMO
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
      {
        addammo FREEZE_WEAPON FREEZEAMMOAMOUNT
        setvar RETURN 66 state itemquote
        ifspawnedby FREEZEAMMO
          state getcode
        else
          state quikget
      }

enda

actor SHOTGUNAMMO
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
      {
        addammo SHOTGUN_WEAPON SHOTGUNAMMOAMOUNT
        setvar RETURN 69 state itemquote
        ifspawnedby SHOTGUNAMMO
          state getcode
        else
          state quikget
      }

enda

actor AMMOLOTS
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
      {
        addammo PISTOL_WEAPON 48
        setvar RETURN 65 state itemquote
        ifspawnedby AMMOLOTS
          state getcode
        else
          state quikget
      }

enda

actor CRYSTALAMMO
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        addammo SHRINKER_WEAPON CRYSTALAMMOAMOUNT
        setvar RETURN 78 state itemquote
        ifspawnedby CRYSTALAMMO
          state getcode
        else
          state quikget
      }

enda

actor GROWAMMO
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        addammo GROW_WEAPON GROWCRYSTALAMMOAMOUNT
        setvar RETURN 123 state itemquote
        ifspawnedby GROWAMMO
          state getcode
        else
          state quikget
      }

enda

actor MP5CLIP

  sizeat 40 40

  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    
		addammo CHAINGUN_WEAPON 30
		setvar RETURN 1011 state itemquote
	    
        ifspawnedby MP5CLIP
          state getcode
        else
          state quikget
      }

enda

actor BATTERYAMMO


  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	   
        addammo CHAINGUN_WEAPON CHAINGUNAMMOAMOUNT
        setvar RETURN 63 state itemquote
      	
        ifspawnedby BATTERYAMMO
          state getcode
        else
          state quikget
      }

enda

action BFGAMMOFRAME 6175 1 1 1 1

actor DEVISTATORAMMO
  ifvare usebfg YES action BFGAMMOFRAME
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvare usebfg YES addammo DEVISTATOR_WEAPON 10 else
        addammo DEVISTATOR_WEAPON DEVISTATORAMMOAMOUNT
        setvar RETURN 14 state itemquote
        ifspawnedby DEVISTATORAMMO
          state getcode
        else
          state quikget
      }

enda
actor RPGAMMO
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else ifp palive
      ifpdistl RETRIEVEDISTANCE
        ifcount 6
          ifcanseetarget
      {
	    ifvare usebigrox YES addammo RPG_WEAPON 4 else
        addammo RPG_WEAPON RPGAMMOBOX
        setvar RETURN 64 state itemquote
        ifspawnedby RPGAMMO
          state getcode
        else
          state quikget
      }

enda

actor HBOMBAMMO
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        ifgotweaponce 0
          break

        addweapon HANDBOMB_WEAPON HANDBOMBBOX
        setvar RETURN 55 state itemquote
//        addammo HANDBOMB_WEAPON HANDBOMBBOX

        ifspawnedby HBOMBAMMO
          state getweaponcode
        else
          state quikweaponget
      }

enda

actor RPGSPRITE
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        ifgotweaponce 0
          break

        addweapon RPG_WEAPON RPGAMMOBOX
        setvar RETURN 56 state itemquote
        ifspawnedby RPGSPRITE
          state getweaponcode
        else
          state quikweaponget
      }

enda

actor CRUIZERSPRITE

  sizeat 32 32

  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    orvar ALTSHOTGUN 1
        ifspawnedby PIGCOP
        {
          addweapon SHOTGUN_WEAPON 0
          
          randvar temp 3
          addvar temp 1
          getplayer[THISACTOR].ammo_amount 2 tempb
          ifvare usemossberg YES ifvare SHOTGUNCLIP 0 ifvare FAKERELOAD 0
          	addvarvar SHOTGUNCLIP temp
    
	      addvarvar tempb temp
	      ifvarg tempb MAXSHOTGUNAMMO setvar tempb MAXSHOTGUNAMMO
	      setplayer[THISACTOR].ammo_amount 2 tempb
        }
        else
        {
          ifgotweaponce 0
            break
          ifvare usemossberg YES 
          {
	          ifvare SHOTGUNCLIP 0 ifvare FAKERELOAD 0
	          	setvar SHOTGUNCLIP 8
          	  addweapon SHOTGUN_WEAPON 8
          }
          else
          addweapon SHOTGUN_WEAPON SHOTGUNAMMOAMOUNT
          setvar RETURN 57 state itemquote
        }

        ifspawnedby SHOTGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }

enda

actor DBSPRITE

sizeat 40 40

  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
          ifgotweaponce 0
            break
          //setvar usemossberg YES
          //getplayer[THISACTOR].gotweapon 2 temp
          //ifvare temp YES orvar ALTSHOTGUN 1
          
          ifvarand ALTSHOTGUN 2 nullop else
          {
	          globalsound WEEDWACKER
	          orvar ALTSHOTGUN 2
	          getuserdef[THISACTOR].weaponswitch temp
	          ifvarand temp 1
	          {
		          orvar ALTSHOTGUN 4
		          setvar WEAPON2_FIREDELAY 4
				  setvar WEAPON2_SPAWN NOTHING
				  setvar WEAPON2_FIRESOUND DBFIRE
				  setvar WEAPON2_TOTALTIME 62 //82
				  setvar WEAPON2_SHOTSPERBURST 20
				  setvar WEAPON2_SOUND2SOUND -1
			  }
	          
          }
          ifspawnedby PIGCOP addweapon SHOTGUN_WEAPON 3 else
          addweapon SHOTGUN_WEAPON SHOTGUNAMMOAMOUNT
          setvar RETURN 1103 state itemquote
        

        ifspawnedby SHOTGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }

enda

actor SHOTGUNSPRITE

  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        ifspawnedby PIGCOP
        {
          addweapon SHOTGUN_WEAPON 0
          ifvare usemossberg YES 
	          	orvar ALTSHOTGUN 1
	      else orvar ALTSHOTGUN 16
          randvar temp 3
          addvar temp 1
          getplayer[THISACTOR].ammo_amount 2 tempb
          ifvare usemossberg YES ifvare SHOTGUNCLIP 0 ifvare FAKERELOAD 0
          	addvarvar SHOTGUNCLIP temp
    
	      addvarvar tempb temp
	      ifvarg tempb MAXSHOTGUNAMMO setvar tempb MAXSHOTGUNAMMO
	      setplayer[THISACTOR].ammo_amount 2 tempb

        }
        else
        {
		  ifvare usemossberg YES 
          {
	          orvar ALTSHOTGUN 1
	          ifvare SHOTGUNCLIP 0 ifvare FAKERELOAD 0
	          	setvar SHOTGUNCLIP 8
          	  addweapon SHOTGUN_WEAPON 8
          }
          else
          {
          	addweapon SHOTGUN_WEAPON SHOTGUNAMMOAMOUNT
          	orvar ALTSHOTGUN 16
      	  }
          setvar RETURN 57 state itemquote
        }

        ifspawnedby SHOTGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }

enda

actor MINIGUNSPRITE

sizeat 32 32
ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
		ifvarand ALTCHAINGUN 1 // ALREADY HAVE WEAPON
		{
			ifvarand ALTCHAINGUN 2
			addammo CHAINGUN_WEAPON 200
			else
			{
				ifvarg MINIGUNAMMO 799 break
				addvar MINIGUNAMMO 200
				ifvarg MINIGUNAMMO 800 setvar MINIGUNAMMO 800
			}
		}
		else
		{
			orvar ALTCHAINGUN 1
			addweapon CHAINGUN_WEAPON 0
			getuserdef[THISACTOR].weaponswitch temp
	        ifvarand temp 1
	        {
		          orvar ALTCHAINGUN 4
		          setplayer[THISACTOR].weapon_pos -1
			}
			addvar MINIGUNAMMO 200
			ifvarg MINIGUNAMMO 800 setvar MINIGUNAMMO 800
			
		}
		
		setvar RETURN 1165 state itemquote
		
		
        ifspawnedby MINIGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }

enda

actor SIXPAK
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode
	getplayer[THISACTOR].i spriteid
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
              ifcanseetarget
      {
	    // ifphealthl MAXPLAYERHEALTH 
	    ifvarvarl sprite[spriteid].extra player[THISACTOR].max_player_health
	    {
		    addphealth 30 
		    setvar RETURN 62 state itemquote
		    ifspawnedby SIXPAK
          		state getcode
        	else
          		state quikget
		} 
		
	    {
		    ifvarn storehealth YES break
		    getplayer[THISACTOR].firstaid_amount temp
		    setvarvar tempb maxmedkit
		    subvar tempb 1
		    ifvarvarg temp tempb break
		    addvar temp 30 ifvarvarg temp maxmedkit setvarvar temp maxmedkit
		    setplayer[THISACTOR].firstaid_amount temp
		    setplayer[THISACTOR].inven_icon 1
		    setplayer[THISACTOR].invdisptime 52
	        setvar RETURN 62 state itemquote
	        ifspawnedby SIXPAK
	          state getcode
	        else
	          state quikget
	        killit
        }
        
      }

enda

state iconstate

sizeat 24 24
cstat 2
getactor[myspawner].x x
getactor[myspawner].y y
getactor[myspawner].z z
subvar z 12288
setactor[THISACTOR].x x
setactor[THISACTOR].y y
setactor[THISACTOR].z z
ifcount 52 killit
ends

useractor notenemy HEALTHICON 0

sizeat 32 32
ifcount 1 killit

enda

actor COLA
  
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode
    getplayer[THISACTOR].i spriteid

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
              ifcanseetarget
      {
	    // ifphealthl MAXPLAYERHEALTH 
	    ifvarvarl sprite[spriteid].extra player[THISACTOR].max_player_health
	    {
		    addphealth 10 
		    setvar RETURN 61 state itemquote
		    ifspawnedby COLA
          		state getcode
        	else
          		state quikget
		} 
		else
	    {
		    ifvarn storehealth YES break
		    getplayer[THISACTOR].firstaid_amount temp
		    setvarvar tempb maxmedkit
		    subvar tempb 1
		    ifvarvarg temp tempb break
		    addvar temp 10 ifvarvarg temp maxmedkit setvarvar temp maxmedkit
		    setplayer[THISACTOR].firstaid_amount temp
		    setplayer[THISACTOR].inven_icon 1
		    setplayer[THISACTOR].invdisptime 52
	        setvar RETURN 61 state itemquote
	        ifspawnedby COLA
	          state getcode
	        else
	          state quikget
	        killit
        }
        
      }

enda

actor ATOMICHEALTH
  ifvarvarn holding THISACTOR fall
  state moveitem
  ifvarvare sprite[THISACTOR].sectnum player[THISACTOR].cursectnum setactor[THISACTOR].htflags 68
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
              ifcanseetarget
      {
	    ifphealthl MAXPLAYERATOMICHEALTH 
	    {
		    addphealth 50 
		    setvar RETURN 19 state itemquote
		    ifspawnedby ATOMICHEALTH
          		state getcode
        	else
          		state quikget
		} 
		else
	    {
		    ifvarn storehealth YES break
		    getplayer[THISACTOR].firstaid_amount temp
		    setvarvar tempb maxmedkit
		    subvar tempb 1
		    ifvarvarg temp tempb break
		    addvar temp 50 ifvarvarg temp maxmedkit setvarvar temp maxmedkit
		    setplayer[THISACTOR].firstaid_amount temp
		    setplayer[THISACTOR].inven_icon 1
		    setplayer[THISACTOR].invdisptime 52
	        setvar RETURN 19 state itemquote
	        ifspawnedby ATOMICHEALTH
	          state getcode
	        else
	          state quikget
	        killit
        }
      }

enda

actor FIRSTAID
  ifvarn myspawner -1 { state iconstate break }
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            //ifpinventory GET_FIRSTAID FIRSTAID_AMOUNT
              ifcanseetarget
      {      
	    getplayer[THISACTOR].firstaid_amount temp
	    setvarvar tempb maxmedkit
	    subvar tempb 1
	    ifvarvarg temp tempb break
	    addvar temp FIRSTAID_AMOUNT ifvarvarg temp maxmedkit setvarvar temp maxmedkit
	    setplayer[THISACTOR].firstaid_amount temp
	    setplayer[THISACTOR].inven_icon 1
		setplayer[THISACTOR].invdisptime 52  
        //addinventory GET_FIRSTAID FIRSTAID_AMOUNT
        setvar RETURN 3 state itemquote

        ifspawnedby FIRSTAID
          state getcode
        else
          state quikget
        killit
      }

enda

actor FIRSTGUNSPRITE
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	      ifvare player[THISACTOR].gotweapon 1 YES
		  ifvare useakimbo YES
	      ifvare akimbo -1
	      state changeakimbo
  
        ifgotweaponce 0
          break
        ifspawnedby LIZTROOP addweapon PISTOL_WEAPON 12 else
        addweapon PISTOL_WEAPON 48
        getplayer[THISACTOR].i spriteid
		getactorvar[spriteid].botclip botclip
		addvar botclip 12
		ifvarvarg botclip WEAPON1_CLIP setvarvar botclip WEAPON1_CLIP
		setactorvar[spriteid].botclip botclip
        setvar RETURN 1118 state itemquote
        ifspawnedby FIRSTGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
    
enda

useractor notenemy LASERPISTOL 0
  sizeat 32 32
  setvar weight WEIGHT1
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
  state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
              ifvarl LASERAMMO 100
      {
	      
        ifvare LASERAMMO 0
        {
	        setvar RETURN 1148 state itemquote
	        getuserdef[THISACTOR].weaponswitch temp
	        ifvarand temp 1
	        {
		        setplayer[THISACTOR].weapon_pos -9
		        setplayer[THISACTOR].curr_weapon 0
	        }
	    }
	    addvar LASERAMMO 20
		randvar temp 10
		addvarvar LASERAMMO temp
		ifvarg LASERAMMO 100 setvar LASERAMMO 100
        ifspawnedby LASERPISTOL
          state getweaponcode
        else
          state quikweaponget
      }
    
enda

action RIPPLE 0 9 1 -1 6

useractor notenemy REVERSERIPPLE 0

ifvare lotag 0 break

ifaction 0
{
	ifrnd 128 cstator 4
	action RIPPLE
	sizeat 255 255
	ifvare lotag 1
	{
		cstator 32
		espawn REVERSERIPPLE
		setactorvar[RETURN].lotag 2
		getactor[THISACTOR].ang angvar
		addvar angvar 512
		espawn REVERSERIPPLE
		setactorvar[RETURN].lotag 2
		setactor[RETURN].ang angvar
	}
	else
	cstator 144
	spritepal 7
}
ifactioncount 9 killit

enda

action PIPEFRAME -1 1 1 1 1

actor TRIPBOMBSPRITE

ifvare dukemon YES { sizeat 16 16 action PIPEFRAME }

setactor[THISACTOR].mdflags 16
  setvar position 32768
  
ifvarn playerally 0 // active dukeball
{
	ifaction 0 action PIPEFRAME
	ifvare mtype 0
	{
	  spritepal 8
	  addvar countvarb 1
	  ifvarg countvarb 26
	  {
		  setvar countvarb 0
		  espawn REVERSERIPPLE
		  setactorvar[RETURN].lotag 1
	  }
	  ifvare target -1
	  {
		  findnearactorz SHOOTME 3072 40960 spriteid
		  ifvare spriteid -1 findnearactorz SHOOTMEALLY 3072 40960 spriteid
		  ifvarn spriteid -1
		  {
			  getactorvar[spriteid].myspawner target
			  ifvarn target -1
			  {
				  getactor[target].picnum picnum
				  ifvare picnum ROTATEGUN
				  {
					  getactorvar[target].myspawner temp
					  ifvarn temp -1 setvarvar target temp
				  }
				  getactor[THISACTOR].z z
				  subvar z 8192
				  setactor[THISACTOR].z z
				  canseespr THISACTOR target temp
				  addvar z 8192
				  setactor[THISACTOR].z z
				  ifvare temp 1
				  {
					  getactor[target].extra temp
					  getactorvar[target].playerally tempb
					  ifvarvarg temp dukeballstrength ifvare tempb 0 setvar target -1
					  else
					  ifvare picnum EGG
					  {
						  getactorvar[target].playerally temp
						  ifvarn temp 0 setvar target -1
					  }  
				  }
				  else setvar target -1			  
		  	  }
	  	  }
	  }
	  ifvarn target -1
	  {
	  	  ifvare actorvar[target].monstatus 2 setvar target -1
		  else
		  ifvarg sprite[target].statnum 2 setvar target -1
		  else
		  ifvarl sprite[target].extra 1 setvar target -1
		  ifvarn target -1
		  {
			  getactor[target].picnum picnum
			  switch picnum 
			  case BOSS1 case BOSS2 case BOSS3 case BOSS4
			  ifvare sprite[target].pal 0 setvar target -1
			  break
			  default break
			  endswitch
		  }
	  }

	
	  ifvarn target -1 // suck them in
	  {
		  	soundonce ACTOR_SHRINKING
		  	// code that moves and shrinks target
		  	getactor[target].x x
			getactor[target].y y
			getactor[THISACTOR].x mx
			getactor[THISACTOR].y my
			subvarvar x mx
			subvarvar y my
			getangle angvar x y
			addvar angvar 1024
			cos xvel angvar
			sin yvel angvar
			shiftvarr xvel 6
			shiftvarr yvel 6
			movesprite target xvel yvel 0 CLIPMASK0 RETURN
			getactor[target].xrepeat digx
			ifvarg digx 5 
			{
				subvar digx 1 setactor[target].xrepeat digx 
				getactor[target].yrepeat digy
				ifvarg digy 5 { subvar digy 1 setactor[target].yrepeat digy }
			}
			else
			{
				userquote 1088
			  	stopsound ACTOR_SHRINKING
			  	getactor[target].picnum mtype
			  	ifvare mtype RECON setvar mtype RECONDP
			  	getactorvar[target].monstflags monstflags
			  	getactorvar[target].playerally temp
			  	ifvare temp 0 ifvarl dukeballstrength 1000
			  	{
				  	userquote 1094
				  	globalsound DUKE_GET
				  	getactor[target].extra hp
				  	shiftvarr hp 3
				  	ifvarg hp 50 setvar hp 50
				  	ifvarl hp 1 setvar hp 1
				  	addvarvar dukeballstrength hp
				  	ifvarg dukeballstrength 1000 setvar dukeballstrength 1000
			  	}
			  	orvar monstflags 2
			  	getactor[target].pal initshade
			  	setactor[target].xrepeat 0
			  	setactor[target].yrepeat 0
			  	setactorvar[target].monstatus 2
			  	getactorvar[target].activator activator
			  	getactorvar[target].droptile droptile
			  	state specialdeath
			  	setvar target -1
		  	}
		  	fall
		  	break
	  }
    }
	
	else spritepal 2
}

  ifvarvarn holding THISACTOR fall
  state moveitem
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	      ifvarn playerally 0 ifvarn mtype 0
	      {
		      addweapon TRIPBOMB_WEAPON 1
		      setvar RETURN 1090 state itemquote
		      state randgetweapsnds
  			  palfrom 32 0 32
  			  // store monster
  			  setvar position 0
  			  getplayer[THISACTOR].ammo_amount 8 temp
  			  whilevarvarn position temp // MAXTRIPBOMBAMMO
  			  {
	  			  setvarvar picnum dukeballpics[position]
	  			  ifvare picnum 0
	  			  {
		  			  setarray dukeballpics[position] mtype
		  			  setarray dukeballflags[position] monstflags
		  			  setarray dukeballpals[position] initshade
		  			  setvarvar dukeballselected position
		  			  setvarvar position temp //MAXTRIPBOMBAMMO
	  			  }
	  			  else addvar position 1
  			  }
	  			  
  			  killit
		      break
	      }
        ifgotweaponce 0
          break

        addweapon TRIPBOMB_WEAPON 1
        ifvarn playerally 0 setvar RETURN 1089 else
        setvar RETURN 58
        state itemquote
        ifspawnedby TRIPBOMBSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
   
enda

actor MP5SPRITE

  sizeat 32 32

  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        ifgotweaponce 0
          break
		ifvare usemp5 YES 
		{
			ifvare MP5INCLIP 0
			{
				addweapon CHAINGUN_WEAPON 30
				setvar MP5INCLIP 30
			} else
			addweapon CHAINGUN_WEAPON 30 
			setvar RETURN 1010 state itemquote
		}
		else
		{
        	addweapon CHAINGUN_WEAPON CHAINGUNAMMOAMOUNT
        	setvar RETURN 54 state itemquote
    	}
    	orvar ALTCHAINGUN 8
        ifspawnedby MP5SPRITE
          state getweaponcode
        else
          state quikweaponget
      }
    

enda

actor CHAINGUNSPRITE

  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarand monstflags 1
	    {
		    setvar usemp5 NO
			ifvarand ALTCHAINGUN 2 nullop else
			{
				setvar WEAPON3_SHOOTS CHAINGUN
				setvar WEAPON3_TOTALTIME 12
				ifvare dpsounds YES
				setvar WEAPON3_FIRESOUND DPCHAINGUNFIRE else
				setvar WEAPON3_FIRESOUND CHAINGUN_FIRE
				setvar WEAPON3_FLAGS 73812
				setvar WEAPON3_CLIP 0
				setvar WEAPON3_SPAWNTIME 0
				setvar WEAPON3_RELOADSOUND1 4
				setvar WEAPON3_RELOADSOUND2 5
			}
		}
        ifgotweaponce 0
          break
		ifvare usemp5 YES 
		{
			ifvare MP5INCLIP 0
			{
				addweapon CHAINGUN_WEAPON 30
				setvar MP5INCLIP 30
			} else
			addweapon CHAINGUN_WEAPON 60 
			setvar RETURN 1010 state itemquote
		}
		else
		{
        	addweapon CHAINGUN_WEAPON CHAINGUNAMMOAMOUNT
        	setvar RETURN 54 state itemquote
    	}
    	orvar ALTCHAINGUN 8
        ifspawnedby CHAINGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
    
enda

actor SHRINKERSPRITE
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        ifgotweaponce 0
          break
        getplayer[THISACTOR].ammo_amount 6 temp
        getplayer[THISACTOR].gotweapon 6 tempb
        ifvare temp MAXSHRINKERAMMO ifvare tempb 1 break
        addweapon SHRINKER_WEAPON 10
        
        ifvare gravgun YES 
        { 
	        setvar RETURN 1014 state itemquote
	        //addammo GROW_WEAPON 10 
	        // can't use addammo here because it will break on max ammo, then player gets infinite shrinker ammo
	        getplayer[THISACTOR].ammo_amount 11 temp
	        addvar temp 10
	        ifvarg temp MAXGROWAMMO setvar temp MAXGROWAMMO
	        setplayer[THISACTOR].ammo_amount 11 temp
	    }
	    else
	    {
        setvar RETURN 60 state itemquote
    	}
        ifspawnedby SHRINKERSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
  
enda

actor GROWSPRITEICON
  sizeat 36 36
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        //ifgotweaponce 0
        //  break
        getplayer[THISACTOR].ammo_amount 11 temp
        getplayer[THISACTOR].gotweapon 11 tempb
        ifvare temp MAXGROWAMMO ifvare tempb 1 break
        setplayer[THISACTOR].gotweapon 6 1
        addweapon GROW_WEAPON GROWCRYSTALAMMOAMOUNT
        
        ifvare gravgun YES setvar RETURN 1014 else
        setvar RETURN 60
        state itemquote
        ifspawnedby GROWSPRITEICON
          state getweaponcode
        else
          state quikweaponget
      }
      
enda

actor FREEZESPRITE
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        ifgotweaponce 0
          break

        addweapon FREEZE_WEAPON FREEZEAMMOAMOUNT
        setvar RETURN 59 state itemquote
        ifspawnedby FREEZESPRITE
          state getweaponcode
        else
          state quikweaponget
      }
     
enda

// actor DEVISTATORSPRITE
//   ifvarvarn holding THISACTOR fall
//   state moveitem
//   ifvare pal 66 spritepal 66
//   ifspritepal 66
//   {
// 	  getplayer[THISACTOR].heat_on temp
// 	  ifvare temp 0 break
//   }
//     state gravpickupcode

//   ifmove RESPAWN_ACTOR_FLAG state respawnit
//   else
//     ifp pshrunk nullop
//     else
//       ifp palive
//         ifpdistl RETRIEVEDISTANCE
//           ifcount 6
//             ifcanseetarget
//       {
//         ifgotweaponce 0
//           break
//         addweapon DEVISTATOR_WEAPON DEVISTATORAMMOAMOUNT
//         setvar RETURN 87 
//         state itemquote
//         ifspawnedby DEVISTATORSPRITE
//           state getweaponcode
//         else
//           state quikweaponget
//       }
//     
// enda

actor DEVISTATORSPRITE
  ifvare usebfg YES action BFGFRAME
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        ifvare usebfg YES
        {
	        ifvarand gunparts 15 ifvarg player[THISACTOR].ammo_amount 7 49 break
	        setplayer[THISACTOR].max_ammo_amount 7 50
	        globalsound IMP_UP
	        orvar gunparts 15
	        setplayer[THISACTOR].gotweapon 7 1
	        setplayer[THISACTOR].curr_weapon 7
	        setplayer[THISACTOR].crack_time 777
		    getplayer[THISACTOR].ammo_amount 7 temp
		    addvar temp 20
		    ifvarvarg temp player[THISACTOR].max_ammo_amount 7 setvarvar temp player[THISACTOR].max_ammo_amount 7
		    setplayer[THISACTOR].ammo_amount 7 temp
		    setvar RETURN 1172
		    state itemquote
	        globalsound WAR_AMBIENCE5
	        palfrom 30 50 60 60
	        globalsound IMP_UP
	        setvar wow 120
	        killit
	    }
        else 
        {
	       ifgotweaponce 0
              break
	        addweapon DEVISTATOR_WEAPON DEVISTATORAMMOAMOUNT
	        setvar RETURN 87 
	        state itemquote
	        ifspawnedby DEVISTATORSPRITE
	          state getweaponcode
	        else
	          state quikweaponget
		}
        
     }
    
enda

actor IMPGUNPART1
  sizeat 40 40
  // ifvare usebfg YES action BFGFRAME
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarand gunparts 1 ifvarg player[THISACTOR].ammo_amount 7 49 break
        
        setvar RETURN 1168 
        globalsound IMP_UP
        orvar gunparts 1
        setplayer[THISACTOR].gotweapon 7 1
	    getplayer[THISACTOR].ammo_amount 7 temp
	    addvar temp 20
	    ifvarvarg temp player[THISACTOR].max_ammo_amount 7 setvarvar temp player[THISACTOR].max_ammo_amount 7
	    setplayer[THISACTOR].ammo_amount 7 temp
	    
        state itemquote
        globalsound DUKE_GETWEAPON1
        palfrom 30 50 60 60
        killit
     }
    
enda

actor IMPGUNPART2
sizeat 40 40
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarand gunparts 2 //ifvarg player[THISACTOR].ammo_amount 7 49 break
	    
	    setplayer[THISACTOR].gotweapon 7 1
	    setplayer[THISACTOR].curr_weapon 7
	    setplayer[THISACTOR].crack_time 777
	    //getplayer[THISACTOR].ammo_amount 7 temp
	    //addvar temp 20
	    //ifvarvarg temp player[THISACTOR].max_ammo_amount 7 setvarvar temp player[THISACTOR].max_ammo_amount 7
	    //setplayer[THISACTOR].ammo_amount 7 temp
	    
        orvar gunparts 2
        setvar RETURN 1169 state itemquote
        globalsound WAR_AMBIENCE10
        globalsound IMP_UP
        palfrom 30 50 60 60
        setvar wow 120
        killit
      }
enda

actor IMPGUNPART3
sizeat 40 40
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarand gunparts 4 ifvarg player[THISACTOR].ammo_amount 7 49 break
	    
	    setplayer[THISACTOR].max_ammo_amount 7 50
	    setplayer[THISACTOR].gotweapon 7 1
	    setplayer[THISACTOR].curr_weapon 7
	    setplayer[THISACTOR].crack_time 777
	    //getplayer[THISACTOR].ammo_amount 7 temp
	    //addvar temp 50
	    //ifvarvarg temp player[THISACTOR].max_ammo_amount 7 setvarvar temp player[THISACTOR].max_ammo_amount 7
	    setplayer[THISACTOR].ammo_amount 7 50 //temp
        orvar gunparts 4
        setvar RETURN 1170 state itemquote
        globalsound BONUS_SPEECH1
        globalsound IMP_UP
        palfrom 30 50 60 60
        setvar wow 120
        killit
      }
enda

actor IMPGUNPART4
sizeat 40 40
  ifvarvarn holding THISACTOR fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare pal 66 spritepal 66
  ifspritepal 66
  {
	  getplayer[THISACTOR].heat_on temp
	  ifvare temp 0 break
  }
    state gravpickupcode

  ifmove RESPAWN_ACTOR_FLAG state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarand gunparts 8 //ifvarg player[THISACTOR].ammo_amount 7 49 break
	    
	    setplayer[THISACTOR].gotweapon 7 1
	    setplayer[THISACTOR].curr_weapon 7
	    setplayer[THISACTOR].crack_time 777
	    //getplayer[THISACTOR].ammo_amount 7 temp
	    //addvar temp 50
	    //ifvarvarg temp player[THISACTOR].max_ammo_amount 7 setvarvar temp player[THISACTOR].max_ammo_amount 7
	    //setplayer[THISACTOR].ammo_amount 7 temp
        orvar gunparts 8
        setvar RETURN 1171 state itemquote
        globalsound WAR_AMBIENCE5
        palfrom 30 50 60 60
        globalsound IMP_UP
        setvar wow 120
        killit
      }
enda

action FIRE_FRAMES   -1 14 1 1 1
move FIREVELS

state firestate

  ifaction 0
    ifrnd 16
    {
      action FIRE_FRAMES
      cstator 128
    }

  sleeptime 300         // Never let it fall to sleep

  ifspawnedby FIRE
  {
    ifgapzl 16
      break
  }
  else
    ifspawnedby FIRE2
  {
    ifgapzl 16
      break
  }

  ifinwater
    killit
  ifvarg underwater 0
    killit

  ifp palive
    ifpdistl 844
      ifrnd 32
        ifcansee
  {
    soundonce DUKE_LONGTERM_PAIN
    addphealth -1
    palfrom 32 32
  }

  ifactor FIRE
  {
    ifspawnedby FIRE
      break
  }
  else
    ifactor FIRE2
      ifspawnedby FIRE2
        break

  iffloordistl 128
  {
    ifrnd 128
    {
      ifcount 84
        killit
                // This line(and the else below)
                // is not necessary, since actors
                // with zero x-size are automatically
                // deleted anyway!
      else
        ifcount 42
          sizeto 0 0
      else
        sizeto 32 32
    }
  }
  else
    killit

ends

useractor notenemy FIRE WEAK 0 FIREVELS state firestate enda
useractor notenemy FIRE2 WEAK 0 FIREVELS state firestate enda

actor FECES
  ifcount 24
  {
    ifpdistl RETRIEVEDISTANCE
    {
      ifrnd SWEARFREQUENCY
        soundonce DUKE_STEPONFECES

      sound STEPNIT

      spawn BLOODPOOL   // Will be brown
      killit
    }
  }
  else
    sizeto 32 32
enda

action FEMSHRUNK
action FEMFROZEN1 1
action FEMGROW
action FEMFROZEN2
action FEMDANCE1 19 1 1 1 16
action FEMDANCE3 19 1 1 1 26
action FEMDANCE2 20 2 1 1 10

action FEMANIMATESLOW 0 2 1 1 100
action TOUGHGALANIM   0 5 1 1 25
// action FEMANIMATE

state femcode

  ifactor NAKED1 nullop
  else
    ifactor FEM6 nullop
    else
    {
      fall
      ifactor BLOODYPOLE
        ifhitweapon
          ifdead
      {
        state standard_jibs
        killit
      }
    }

  ifaction FEMSHRUNK
  {
    ifcount SHRUNKDONECOUNT
    {
      action FEMANIMATE
      cstat 257
    }
    else
      ifcount SHRUNKCOUNT
        sizeto 40 40
    else
      state genericshrunkcode
  }
  else ifaction FEMGROW
  {
    ifcount 32
    {
      respawnhitag
      guts JIBS4 20
      guts JIBS6 20
      spritepal 6
      soundonce LADY_SCREAM
      ifactor NAKED1
        debris SCRAP3 4
      else
        ifactor PODFEM1
          debris SCRAP3 4
      sound SQUISHED
      killit
    }
    else
      sizeto MAXXSTRETCH MAXYSTRETCH
  }

  else
    ifaction FEMDANCE1
  {
    ifactioncount 2
      action FEMDANCE2
  }
  else
    ifaction FEMDANCE2
  {
    ifactioncount 8
      action FEMDANCE3
  }
  else
    ifaction FEMDANCE3
  {
    ifactioncount 2
    action FEMANIMATE
  }
  else
    ifaction FEMFROZEN1
  {
    ifcount THAWTIME
    {
      action FEMANIMATE
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      lotsofglass 30
      state standard_jibs
      sound GLASS_BREAKING
      respawnhitag
      ifrnd 84
        spawn BLOODPOOL
      killit
    }
    else
      ifp pfacing
        ifpdistl FROZENQUICKKICKDIST
        ifvare superkicking 0
          pkick
    break
  }
  else ifaction FEMFROZEN2
  {
    ifcount THAWTIME
    {
      ifactor TOUGHGAL
        action TOUGHGALANIM
      else
        ifactor FEM10
          action FEMANIMATESLOW
      else
        action FEMANIMATE

      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
          break
      }

      lotsofglass 30
	  state standard_jibs
      sound GLASS_BREAKING
      ifrnd 84
        spawn BLOODPOOL
      respawnhitag

      ifrnd 128
        sound DUKE_HIT_STRIPPER1
      else
        sound DUKE_HIT_STRIPPER2

      killit
    }
    else
      ifp pfacing
        ifpdistl FROZENQUICKKICKDIST
        ifvare superkicking 0
          pkick
    break
  }

  ifhitweapon
  {
    ifdead
    {
	  ifwasweapon SHRINKSPARK
      {
        sound ACTOR_SHRINKING
        move 0
        action FEMSHRUNK
        cstat 0
        strength 0
        break
      }
      ifwasweapon GROWSPARK
      {
        cstat 0
        move 0
        sound ACTOR_GROWING
        action FEMGROW
        break
      }
      else ifwasweapon FREEZEBLAST
      {
        ifaction FEMSHRUNK
          break

        ifactor NAKED1
          action FEMFROZEN2
        else
          ifactor FEM5
            action FEMFROZEN2
        else
          ifactor FEM6
            action FEMFROZEN2
        else
          ifactor FEM8
            action FEMFROZEN2
        else
          ifactor FEM9
            action FEMFROZEN2
        else
          ifactor FEM10
            action FEMFROZEN2
        else
          ifactor TOUGHGAL
            action FEMFROZEN2
        else
          ifactor PODFEM1
            action FEMFROZEN2
        else
          action FEMFROZEN1

        move 0
        spritepal 1
        strength 0

        sound SOMETHINGFROZE
		state icesmoke
        break
      }

      ifrnd 128
        sound DUKE_HIT_STRIPPER1
      else
        sound DUKE_HIT_STRIPPER2

      respawnhitag
      state standard_jibs
      state random_wall_jibs
      spawn BLOODPOOL

      ifactor FEM1
        money 5
      else
        ifactor FEM2
      {
        money 7
        cactor BARBROKE
        cstat 0
      }
      else
        ifactor FEM3
          money 4
      else
        ifactor FEM7
          money 8

      ifactor FEM5
      {
        strength TOUGH
        cactor BLOODYPOLE
      }
      else ifactor FEM6
      {
        cstat 0
        cactor FEM6PAD
      }
      else
        ifactor FEM8
      {
        strength TOUGH
        cactor BLOODYPOLE
      }
      else
      {
        spritepal 6
        soundonce LADY_SCREAM
        ifactor NAKED1
          debris SCRAP3 18
        else
          ifactor PODFEM1
            debris SCRAP3 18
        killit
      }
    }
    else
    {
      ifwasweapon SHRINKSPARK
      {
        sound ACTOR_SHRINKING
        move 0
        action FEMSHRUNK
        cstat 0
        break
      }
      else
        ifwasweapon GROWSPARK
          sound EXPANDERHIT
      ifactor FEM8
        break

      ifactor TOUGHGAL
          state toughgalspeech
      else sound SQUISHED

      guts JIBS6 1
    }
  }
ends

state killme
  ifinwater nullop else
  ifvarg underwater 0 nullop
  else
    ifp pfacing
      ifpdistl 1280
        ifhitspace
          soundonce KILLME
ends

state tipme
  ifp pfacing
    ifpdistl 1280
      ifhitspace
  {
    tip
    ifrnd 128
      soundonce DUKE_TIP1
    else
      soundonce DUKE_TIP2
    ifactor FEM1
      action FEMDANCE1
  }
ends

state toughgaltalk
  ifp pfacing
    ifpdistl 1280
      ifhitspace
        state toughgalspeech
ends

actor FEM1 TOUGH FEMANIMATE
  state tipme
  state femcode
enda
actor FEM2 TOUGH FEMANIMATE
  state tipme
  state femcode
enda
actor FEM3 TOUGH FEMANIMATE
  state tipme
  state femcode
enda
actor FEM4 TOUGH FEMANIMATE
  state femcode
enda
actor FEM5 TOUGH FEMANIMATE
  state killme
  state femcode
enda
actor FEM6 TOUGH FEMANIMATE
  state killme
  state femcode
enda
actor FEM7 TOUGH FEMANIMATE
  state tipme
  state femcode
enda
actor FEM8 TOUGH FEMANIMATE
  state femcode
enda
actor FEM9 TOUGH FEMANIMATE
  state femcode
enda
actor FEM10 TOUGH FEMANIMATESLOW
  state tipme
  state femcode
enda

actor TOUGHGAL MANWOMANSTRENGTH TOUGHGALANIM
  state toughgaltalk
  state femcode
enda

actor NAKED1 TOUGH FEMANIMATE
  state killme
  state femcode
enda
actor PODFEM1 TOUGH FEMANIMATE
  state killme
  state femcode
enda
actor BLOODYPOLE TOUGH
  state femcode
enda
actor STATUEFLASH
  fall
  ifcount 32
    cactor STATUE
enda
actor STATUE
  fall
  ifp pfacing
    ifpdistl 1280
      ifhitspace
  {
    cactor STATUEFLASH
    move 0
  }
enda

actor MIKE
  ifp pfacing
    ifpdistl 1280
      ifhitspace
        mikesnd
enda

actor KNEE KNEE_WEAPON_STRENGTH enda
actor SPIT SPIT_WEAPON_STRENGTH enda
actor CHAINGUN CHAINGUN_WEAPON_STRENGTH enda
actor SHOTGUN SHOTGUN_WEAPON_STRENGTH enda
actor FIRELASER FIRELASER_WEAPON_STRENGTH enda
actor HEAVYHBOMB HANDBOMB_WEAPON_STRENGTH enda
actor BOUNCEMINE BOUNCEMINE_WEAPON_STRENGTH enda
actor MORTER MORTER_WEAPON_STRENGTH enda
actor SHRINKSPARK 5 enda // overrides user.con for SHRINKER_WEAPON_STRENGTH; necessary for immunity flag to work

actor GROWSPARK GROWSPARK_WEAPON_STRENGTH
  ifcount 18
    killit
  else
    ifcount 9
  {
    sizeto 0 0
    sizeto 0 0
    sizeto 0 0
    sizeto 0 0
  }
  else
  {
    sizeto 28 28
    sizeto 28 28
    sizeto 28 28
    sizeto 28 28
  }
enda

actor RPG RPG_WEAPON_STRENGTH enda
actor FREEZEBLAST FREEZETHROWER_WEAPON_STRENGTH enda
actor DEVISTATORBLAST FREEZETHROWER_WEAPON_STRENGTH enda
actor COOLEXPLOSION1 COOL_EXPLOSION_STRENGTH enda
actor TRIPBOMB TRIPBOMB_STRENGTH enda

state checkfloordist

setvar temp 3072
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z
updatesectorz x y z mysector
ifvarn mysector -1
{
	getflorzofslope mysector x y temp // temp is the return var
	subvarvar temp z
}

ends




state adjusttowall
  
  getwall[hitwall].x x
  getwall[hitwall].y y
  getwall[hitwall].point2 tempb

  getwall[tempb].x mx
  getwall[tempb].y my
  subvarvar x mx
  subvarvar y my
  getangle z x y

  getactor[THISACTOR].x x
  sin mz z
  shiftvarr mz 13
  addvarvar x mz
  setactor[THISACTOR].x x

  getactor[THISACTOR].y y
  cos mz z
  shiftvarr mz 13
  subvarvar y mz
  setactor[THISACTOR].y y

  addvar z 512
  setactor[THISACTOR].ang z
ends

action BLOODIMPACTFRAMES 0 11 1 1 2
action BLOODIMPSLOW 0 11 1 1 3
useractor notenemy BLOODIMPACT 0 BLOODIMPACTFRAMES
ifmove 0
{
	move INIT
	ifspawnedby SHOTSPARK1
	{
		sizeat 4 4
		action BLOODIMPSLOW
	}
	else { setvar mtype 1 sizeat 6 6 }
	cstator 128
	ifspritepal 33 spritepal 0
}
ifactioncount 11 killit

ifcount 11 nullop else ifcount 10
ifvare mtype 0
{
	espawn JIBS6
	ifspritepal 6 setactor[RETURN].pal 6
	setactor[RETURN].xrepeat 24
	setactor[RETURN].yrepeat 24
	setactor[RETURN].zvel 0
	setactor[RETURN].xvel 0
}

enda

useractor notenemy BLOODIMPACT2 0
ifmove 0
{
	move INIT
	ifspawnedby SHOTSPARK1
	sizeat 12 12
	else { setvar mtype 1 sizeat 20 20 }
	cstator 128
	ifrnd 128 cstator 4
	ifrnd 128 cstator 8
	ifspritepal 33 spritepal 0
}

ifcount 2 cstator 2
ifcount 4 cstator 512
ifcount 6 
{
	ifvare mtype 0
	{
		espawn JIBS6
		ifspritepal 6 setactor[RETURN].pal 6
		setactor[RETURN].xrepeat 20
		setactor[RETURN].yrepeat 20
		setactor[RETURN].zvel 0
		setactor[RETURN].xvel 0
	}
	killit
}

enda

state makewound

getactor[THISACTOR].ang angvar
addvar angvar 1024
setvarvar mx sprite[THISACTOR].x
addvar mx 256
rotatepoint sprite[THISACTOR].x sprite[THISACTOR].y mx sprite[THISACTOR].y angvar x y
setactor[THISACTOR].x x
setactor[THISACTOR].y y

espawn BULLETWOUND
ifvare sprite[temp].picnum NEWBEAST setactor[RETURN].pal 6 else
ifvare sprite[temp].picnum EGG setactor[RETURN].pal 6 else
ifvare sprite[temp].picnum BOSS4 setactor[RETURN].pal 6 else
setactor[RETURN].pal 0 // sprite[temp].pal
setvar tempb 144
ifrnd 128 orvar tempb 4
ifrnd 128 orvar tempb 8
setactor[RETURN].cstat tempb
setactorvar[RETURN].myspawner temp
setactorvar[RETURN].peractor5 sprite[temp].picnum
getactor[THISACTOR].ang angvar
			
getincangle A angvar sprite[temp].ang
setactorvar[RETURN].peractor1 A

ldist xydist THISACTOR temp
shiftvarr xydist 1
setactorvar[RETURN].mtype xydist

getactor[THISACTOR].x mx
getactor[THISACTOR].y my
getactor[temp].x x
getactor[temp].y y
subvarvar mx x
subvarvar my y
getangle tempc mx my // angle to make monster face wound
getincangle ammo tempc sprite[temp].ang
setactorvar[RETURN].ammo ammo

getactor[THISACTOR].z z
setactor[RETURN].z z
getactor[temp].z initz
subvarvar initz z
setactorvar[RETURN].initz initz

ifvare CURRWEAP 1 { ifvare depistols YES setvar tempb 8 else setvar tempb 4 } else
setvar tempb 5

setactorvar[RETURN].countvarb tempb

ends



action WEAP2FRAMES 0  4  1  1  6
actor SHOTSPARK1 PISTOL_WEAPON_STRENGTH WEAP2FRAMES
  ifdead
    killit
  ifactioncount 4
    killit
  else
  {
    ifactioncount 3
    {
      ifinwater
      spawn WATERBUBBLE
      ifvarg underwater 0
      spawn WATERBUBBLE
    }
    else
      ifcount 2 nullop
      else
        ifonwater
          spawn WATERSPLASH2
  }
  
  ifcount 1 nullop else
  {
	  ifspawnedby STARPROJ { sizeat 16 16 break }
	  ifvare smartmonsters YES state wakeupmonsters
	  ifvare sprite[THISACTOR].yvel ICEBEAM 
	  {
		  	getactor[THISACTOR].htg_t 8 temp // temp = hitsprite
	  		ifvarn temp -1
	  		setactor[temp].htpicnum FREEZEBLAST
	  		break
  	  }
  	  ifvare sprite[THISACTOR].yvel POWBEAM
  	  {
	  	  getactor[THISACTOR].htg_t 8 temp // temp = hitsprite
	  	  ifvarn temp -1
	  	  {
	  	  	setactor[temp].htpicnum POWBEAM
	  	  	getactor[temp].mdflags tempb
	  	 	orvar tempb 16
	  	  	setactor[temp].mdflags tempb
	  	  	setvar beamhit 10
  	  	  }
  	  }
	  state getfloordist
	  getactor[THISACTOR].htg_t 6 hitwall
		ifvarn hitwall -1
		{
			getwall[hitwall].picnum FLOORTEX
			state CHECKSTEPS
			state BULLETHITSOUNDS
			ifvare FLOORTEX 638 
			{
				sound GLASS_HEAVYBREAK 
				lotsofglass 15 
				setwall[hitwall].picnum 358 
			}
			
		}
		else
		ifvarl z 0
		{
			getsector[THISACTOR].floorpicnum FLOORTEX
			state CHECKSTEPS
			state BULLETHITSOUNDS
			ifvare FLOORTEX W_TECHWALL1 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].floorpicnum 363 } else
			ifvare FLOORTEX W_TECHWALL2 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].floorpicnum 362 } else
			ifvare FLOORTEX W_TECHWALL3 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].floorpicnum 360 } else
			ifvare FLOORTEX W_TECHWALL4 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].floorpicnum 361 } else
			ifvare FLOORTEX 5645 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].floorpicnum 5638 } else
			{
				getsector[THISACTOR].floorstat temp
				ifvarand temp 1 nullop else ifvarand temp 2 nullop else ifawayfromwall
				{
					setvarvar target2 FLOORTEX
					ifspawnedby APLAYER ifvarn ONCAR 0 espawn SCORCH else
					espawn BULLETHOLE
					setactor[RETURN].cstat 32
				}
			}
		}
		else
		ifceilingdistl 3
		{
			getsector[THISACTOR].ceilingpicnum FLOORTEX
			state CHECKSTEPS
			state BULLETHITSOUNDS
			ifvare FLOORTEX W_TECHWALL1 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].ceilingpicnum 363 } else
			ifvare FLOORTEX W_TECHWALL2 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].ceilingpicnum 362 } else
			ifvare FLOORTEX W_TECHWALL3 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].ceilingpicnum 360 } else
			ifvare FLOORTEX W_TECHWALL4 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].ceilingpicnum 361 } else
			{
				getsector[THISACTOR].ceilingstat temp
				ifvarand temp 1 nullop else ifvarand temp 2 nullop else ifawayfromwall
				{
					setvarvar target2 FLOORTEX
					ifspawnedby APLAYER ifvarn ONCAR 0 espawn SCORCH else
					espawn BULLETHOLE
					state getceilz
					setactor[RETURN].z z
					setactor[RETURN].cstat 32
				}
			}
		}
		
	  
	  getactor[THISACTOR].htg_t 8 temp // temp = hitsprite
	  ifvarn temp -1
	  {
		  ifvarand ppowers 8
		  ifspawnedby APLAYER
		  {
// 			  ifvare sprite[THISACTOR].yvel CHAINGUN
// 			  setvarvar chainsparksprite THISACTOR 
// 			  else
// 			  ifvare CURRWEAP 1
			  ifvarn CURRWEAP 2 ifvarn CURRWEAP 7
			  setvarvar chainsparksprite THISACTOR
			  
		  }
	       getactor[temp].picnum picnum
	       switch picnum
	       case FIREBALLPROJ
	       setactor[temp].yvel 0
	       break
	       case WATERTILE2
	       case DPWATERTILE
	       case WATERFLOW
	       spawn WATERSPLASH3
	       sound ITEM_SPLASH
	       break
	       case POWBALL
	       ifspawnedby APLAYER ifvare CURRWEAP 7    
	       	 setactor[temp].yvel 0
	       break
	        case NEWBEASTCORPSE
			case BOSS4CORPSE
			 spritepal 6
			 espawn JIBS6
		     setactor[RETURN].xrepeat 32
		     setactor[RETURN].yrepeat 32
	        case EGGCORPSE
			case LIZTROOPCORPSE
			case OCTABRAINCORPSE
			case COMMANDERCORPSE
			case PIGCOPCORPSE
			case LIZMANCORPSE
			case BOSS1CORPSE
			case BOSS1CORPSENOGUN
			case BOSS2CORPSE
			case BOSS3CORPSE
			 espawn JIBS6
		     setactor[RETURN].xrepeat 32
		     setactor[RETURN].yrepeat 32
		     setvar mtype 1
		     sound HITFLESH
		   break
	       case PIGCOP
	       case PIGCOPDIVE
	       case LIZTROOP
	       case LIZTROOPDUCKING
	       case LIZMAN
	       case COMMANDER
	       case OCTABRAIN
	       case NEWBEAST
	       case APLAYER
	       case BOSS1
	       case BOSS2
	       case BOSS3
	       case BOSS4
	       sound HITFLESH
	       ifvare actorvar[temp].monstatus 1
	       {
		       espawn BLOODIMPACT2
		       getactor[THISACTOR].htg_t 8 temp
		       getactor[temp].picnum picnum
			   ifvare picnum NEWBEAST setactor[RETURN].pal 6 else
			   ifvare picnum BOSS4 setactor[RETURN].pal 6
			   
			   ifvarand ppowers 1 ifspawnedby APLAYER state makewound
		   }	
	       
// 	       espawn JIBS6
// 	       getactor[THISACTOR].htg_t 8 temp
// 	       getactor[temp].picnum picnum
// 		    setactor[RETURN].xrepeat 24
// 		    setactor[RETURN].yrepeat 24
// 		    setactor[RETURN].zvel 0
// 		    ifvare picnum NEWBEAST setactor[RETURN].pal 6 else
// 		    ifvare picnum BOSS4 setactor[RETURN].pal 6		    
// 		    randvar angvar 2047
// 		    setactor[RETURN].ang angvar
// 		    randvar xvel 64
// 		    setactor[RETURN].xvel xvel
	       break
	       
	       case CIV3
	       sound HITFLESH
	       spawn BLOODIMPACT2
	       break
	       
	       case ROTATEGUN
	       case TANK
	       case DRONE
	       case RECON
	       		state sparkstate
	       		state HITMETALSOUND
	       break
	       default break
	       endswitch
	   }
   }
enda


actor ORGANTIC TURRETSTRENGTH
  ifcount 48
    resetcount
  else ifcount 32
  {
    sizeto 32 32
  }
  else
    ifcount 16
    {
      sizeto 48 18
      ifpdistl 2048
      {
        sound TURR_ATTACK
        addphealth -2
        palfrom 32 16
      }
    }
  ifhitweapon
  {
    ifdead
    {
      addkills 1 state specialdeath
      sound TURR_DYING
      guts JIBS5 10
      killit
    }
    sound TURR_PAIN
    break
  }
  ifrnd 1
    soundonce TURR_ROAM
enda

state shotflashcode

ifmove 0
{
	move INIT
	getactor[THISACTOR].ang angvar
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	setvarvar mx x
	ifspawnedby APLAYER
	addvar mx 256 else addvar mx 384
	rotatepoint x y mx y angvar x y
	setactor[THISACTOR].x x
	setactor[THISACTOR].y y
	sizeat 40 40
	ifspawnedby APLAYER
	{
		// position is player's horiz
		subvar position 100
		mulvar position -2
		addvar position 32
	}
	else
	{
		getactor[THISACTOR].ang angvar
		randvar temp 32
		ifrnd 128 mulvar temp -1
		addvarvar angvar temp
		setactor[THISACTOR].ang angvar
	}
	setactor[THISACTOR].pitch position

}
ifactioncount 2
  killit

ends

state shotflashcode3

ifmove 0
{
	move INIT
	getactor[THISACTOR].ang angvar
	ifspawnedby PIGCOP addvar angvar 160 else
	addvar angvar 224
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	setvarvar mx x
	ifspawnedby LIZMAN
	addvar mx 384 else addvar mx 512
	rotatepoint x y mx y angvar x y
	setactor[THISACTOR].x x
	setactor[THISACTOR].y y
	sizeat 40 40
	getactor[THISACTOR].ang angvar
	randvar temp 32
	ifrnd 128 mulvar temp -1
	addvarvar angvar temp
	setactor[THISACTOR].ang angvar
	// setactor[THISACTOR].pitch position

}
ifactioncount 2
  killit

ends

state shotflashcode5

ifmove 0
{
	move INIT
	getactor[THISACTOR].z z
	ifvarand position 2 subvar z 3072
	setactor[THISACTOR].z z
	getactor[THISACTOR].ang angvar
	ifvarand position 1 subvar angvar 272 else
	addvar angvar 272
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	setvarvar mx x
	addvar mx 480
	rotatepoint x y mx y angvar x y
	setactor[THISACTOR].x x
	setactor[THISACTOR].y y
	sizeat 40 40
	getactor[THISACTOR].ang angvar
	randvar temp 32
	ifrnd 128 mulvar temp -1
	addvarvar angvar temp
	setactor[THISACTOR].ang angvar
	// setactor[THISACTOR].pitch position

}
ifactioncount 2
  killit

ends

action SHOTSPARK2FRAMES 0  1  1  1  12 // 6
actor SHOTSPARK2 0 SHOTSPARK2FRAMES state shotflashcode enda  // for player
actor SHOTSPARK3 0 SHOTSPARK2FRAMES state shotflashcode3 enda // for pigcop, lizman
actor SHOTSPARK4 0 SHOTSPARK2FRAMES state shotflashcode enda // for turret, pigcopdive
actor SHOTSPARK5 0 SHOTSPARK2FRAMES state shotflashcode5 enda // for tank


// CANNONBALL for Pirates of the Carribean
define CANNONBALLSTRENGTH 400
move CANNONBALL1 512 0
move CANNONBALL2 512 10
move CANNONBALL3 512 20
move CANNONBALL4 512 40
move CANNONBALL5 512 80

useractor notenemy CANNONBALL CANNONBALLSTRENGTH

  ifaction 0
  {
    sizeat 32 32
    cstat 257         // Force actor to block
    action ANULLACTION
  }

    ifactioncount 46
    {
      ifactioncount 47 nullop
      else
        move CANNONBALL5 geth getv
    }
    else
      ifactioncount 44
    {
      ifactioncount 45 nullop
      else
        move CANNONBALL4 geth getv
    }
    else
      ifactioncount 40
    {
      ifactioncount 41 nullop
      else
        move CANNONBALL3 geth getv
    }
    else
      ifactioncount 32
    {
      ifactioncount 33 nullop
      else
        move CANNONBALL2 geth getv
    }
    else
      ifactioncount 16
    {
      ifactioncount 17 nullop
      else move CANNONBALL1 geth getv
    }

  ifnotmoving
  {
    spawn EXPLOSION2
    sound PIPEBOMB_EXPLODE
    hitradius 4096 WEAKEST WEAK MEDIUMSTRENGTH TOUGH
    killit
  }

  ifhitweapon
  {
    ifdead
    {
      spawn EXPLOSION2
      hitradius 4096 WEAKEST WEAK MEDIUMSTRENGTH TOUGH
      killit
    }
    else
      debris SCRAP1 3
  }

enda


define CANNONBALLS 1818
define CANNONBALLSSTRENGTH 10
move CANNONBALLSVEL

useractor notenemy CANNONBALLS CANNONBALLSSTRENGTH
  ifaction 0
  {
    cstator 257
    action ANULLACTION
  }
  ifhitweapon
  {
    ifdead
    {
      spawn EXPLOSION2
      hitradius 4096 WEAKEST WEAK MEDIUMSTRENGTH TOUGH
      killit
    }
    else
      debris SCRAP1 3
  }
enda


define CANNON 1810
define CANNONSTRENGTH 400
action ACANNONWAIT 0 1 7 1 1
action ACANNONSHOOTING 0 1 7 1 1
move CANNONSTOP

useractor enemy CANNON CANNONSTRENGTH // fall

  ifaction 0
  {
//    sizeat 64 64
    action ACANNONWAIT
  }
  else
    ifaction ACANNONSHOOTING
  {
    spawn CANNONBALL
    action ACANNONWAIT
  }
  else
    ifaction ACANNONWAIT
  {
    ifactioncount 64
    {
      ifrnd 128
        action ACANNONSHOOTING
      else
        resetactioncount
    }
  }

  ifhitweapon
  {
    ifdead
    {
      addkills 1 state specialdeath
      hitradius 4096 WEAKEST WEAK MEDIUMSTRENGTH TOUGH
      spawn EXPLOSION2
      killit
    }
    else debris SCRAP1 3
  }

  ifpdistl 1024
    ifhitspace
  {
    ifp pfacing
      ifcanshoottarget
        spawn CANNONBALL
      else break
  }
enda

useractor notenemy HOTMEAT TOUGH
  ifaction 0
  {
    action ANULLACTION
    cstator 257
  }
  ifhitweapon
  {
    ifdead
    {
      sound SQUISHED
      guts JIBS5 8
      guts JIBS6 9
      killit
    }
    else
      guts JIBS6 1
  }
  ifrnd 1
    spawn WATERDRIP

enda

action ASPEAKERBROKE 1
useractor notenemy SPEAKER
  ifaction 0
  {
    ifhitweapon
    {
      stopsound STORE_MUSIC
      soundonce STORE_MUSIC_BROKE
      action ASPEAKERBROKE
    }
    else
    {
      ifpdistl 10240
          soundonce STORE_MUSIC
      cstat 289
    }
  }
enda

action ALAVABUBBLE
action ALAVABUBBLEANIM 0 5 1 1 16

useractor notenemy LAVABUBBLE
  ifaction 0
  {
    cstat 32768
    action ALAVABUBBLE
  }
  else
    ifaction ALAVABUBBLE
  {
    ifcount 72
      ifrnd 2
    {
      cstat 0
      action ALAVABUBBLEANIM
    }
  }
  else
  {
    ifactioncount 5
    {
      cstat 32768
      action ALAVABUBBLE
    }
  }
enda

action CORPSEFROZEN 0 1 1

state corpsepickupcode

state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvare gravitysprite -1 ifhitspace state throwitem
	break
}

ifmove PHOLDING move INIT geth

fall

ifp ponsteroids
state pickupcode
else
state gravpickupcode

ends

state checkpview

ifvarg countvarb 0 subvar countvarb 1
ifvarn countvar 0 { addvarvar countvarb countvar }
ifvarg countvarb 30 setvar countvarb 30
getplayer[THISACTOR].i spriteid
getactor[spriteid].z mz
getactor[THISACTOR].z z


getactor[THISACTOR].x x
getactor[THISACTOR].y y
updatesectorz x y z mysector
ifvarn mysector -1
changespritesect THISACTOR mysector else
getactor[THISACTOR].sectnum mysector

getplayer[THISACTOR].cursectnum temp
ifvarvare temp mysector nullop else
ifcansee 
{
	ifcanshoottarget 
		nullop
	else
	ifpdistl 1536 nullop else
	addvar countvarb 2
} 
else
addvar countvarb 2

ends

state corpsemovecode

getactor[THISACTOR].htextra temp
getactor[THISACTOR].htpicnum picnum
ifvarg temp 0 ifvarn picnum FREEZEBLAST ifvare peractor4 0
{
	getactor[THISACTOR].htang peractor5 // the angle monster will move in
	setvarvar peractor6 temp // temp is damage
	mulvarvar peractor6 knockdist // peractor6 is the knockback force
	shiftvarr peractor6 1
	setvar tempc 0
	ifactor BOSS1CORPSENOGUN setvar tempc 1
	ifactor BOSS1CORPSE setvar tempc 1
	ifactor BOSS2CORPSE setvar tempc 1
	ifactor BOSS3CORPSE setvar tempc 1
	ifactor BOSS4CORPSE setvar tempc 1
	ifvare tempc 1
	{
		shiftvarr peractor6 1
	}
}
ifvarg peractor6 0
{
	cos xvel peractor5
	sin yvel peractor5
	mulvarvar xvel peractor6
	mulvarvar yvel peractor6
	shiftvarr xvel 13
	shiftvarr yvel 13
	setvar zvel 0
	movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN
	shiftvarr peractor6 1
	ifvarl peractor6 4 setvar peractor6 0
}

ends

state corpsecode

	ifmove 0
	{
		move INIT
		spriteflags 2
		getactor[THISACTOR].mdflags temp
		orvar temp 16 // process in animatesprites
		setactor[THISACTOR].mdflags temp
  		setvar position 32768
		getactor[THISACTOR].yrepeat inity
		setvarvar tempb inity
		subvar tempb 10
		setactor[THISACTOR].yrepeat tempb
		setvar bouncesound THUD
		cstator 256
		setvar weight WEIGHT3
		ifactor COMMANDERCORPSE setvar weight WEIGHT4
		ifactor BOSS1CORPSENOGUN setvar weight WEIGHT5
		ifactor BOSS1CORPSE setvar weight WEIGHT5
		ifactor BOSS2CORPSE setvar weight WEIGHT5
		ifactor BOSS3CORPSE setvar weight WEIGHT5
		ifactor BOSS4CORPSE setvar weight WEIGHT5
		getuserdef[THISACTOR].player_skill peractor1
		setvar weapcount 0
	}
	strength 0
	clipdist 64
	setactor[THISACTOR].owner THISACTOR
	
	state corpsemovecode
	getactor[THISACTOR].htpicnum picnum
	ifvare CURRWEAP 9 ifvare picnum SHOTSPARK1
	{
		getactor[THISACTOR].htowner spriteid
		ifvarn spriteid -1
		{
			getactor[spriteid].picnum temp
			ifvare temp APLAYER
			setactor[THISACTOR].htpicnum FREEZEBLAST
		}
	}
	ifaction CORPSEFROZEN
	{
		ifcount THAWTIME
	    {
	      action 0
	      getlastpal
	      resetcount
	    }
	    else
	      ifcount FROZENDRIPTIME
	    {
	      ifactioncount 26
	      {
	        spawn WATERDRIP
	        resetactioncount
	      }
	    }
		ifhitweapon
		{
			ifwasweapon FREEZEBLAST { resetcount resetactioncount break }
			lotsofglass 30
			state standard_jibs
	        sound GLASS_BREAKING
	        ifrnd 84
	        spawn BLOODPOOL
	        killit
		}
		break
	}
	ifvarg sprite[THISACTOR].htextra 0 setvarvar bleeding sprite[THISACTOR].htextra
	ifhitweapon
	{
		ifwasweapon FREEZEBLAST
		{
			sound SOMETHINGFROZE
			action CORPSEFROZEN
			resetcount
			spritepal 1
			state icesmoke
			break
		}
		ifwasweapon SHOTSPARK1 { addvar weapcount 1 ifvare CURRWEAP 2 addvar weapcount 3 }
		ifvarg weapcount 10 setactor[THISACTOR].htpicnum RADIUSEXPLOSION
		ifspritepal 1 nullop else ifwasweapon ICESHARD sound HITFLESH
		ifwasweapon RADIUSEXPLOSION
		{
			setvar position 0
			setvar bouncesound -1
			ifactor EGGCORPSE cactor EGG
			ifactor LIZTROOPCORPSE { cactor LIZTROOP state troop_body_jibs }
			ifactor OCTABRAINCORPSE cactor OCTABRAIN
			ifactor COMMANDERCORPSE cactor COMMANDER
			ifactor PIGCOPCORPSE cactor PIGCOP
			ifactor LIZMANCORPSE { cactor LIZMAN state liz_body_jibs }
			ifactor BOSS1CORPSENOGUN { cactor BOSS1 state standard_jibs }
			ifactor BOSS1CORPSE { cactor BOSS1 state standard_jibs }
			ifactor BOSS2CORPSE { cactor BOSS2 state standard_jibs }
			ifactor BOSS3CORPSE { cactor BOSS3 state standard_jibs }
			ifactor NEWBEASTCORPSE { spritepal 6 cactor NEWBEAST state liz_body_jibs }
			ifactor BOSS4CORPSE { spritepal 6 cactor BOSS4 state standard_jibs }
			sound SQUISHED
			state standard_jibs
			killit
		}
	}
	ifvare beamhit 0 ifwasweapon POWBEAM setactor[THISACTOR].htpicnum SHOTSPARK1
	state corpsepickupcode
	
	
  ifsquished
  {
    sound SQUISHED
    state standard_jibs
    state random_ooz
    killit
  }
  
    strength 0
    //ifrespawn
    ifvare peractor1 4
      ifcount RESPAWNACTORTIME
    {
	    setvar bouncesound -1
	    setvar position 0
	    setactor[THISACTOR].mdflags 0
	    ifactor LIZTROOPCORPSE { addkills -1 action 0 strength TROOPSTRENGTH cactor LIZTROOP action ATROOPDEAD }
	    ifactor OCTABRAINCORPSE { addkills -1 action 0 strength PIGCOPSTRENGTH cactor OCTABRAIN action AOCTADEAD }
		ifactor COMMANDERCORPSE { addkills -1 action 0 strength PIGCOPSTRENGTH cactor COMMANDER action ACOMMDEAD }
		ifactor PIGCOPCORPSE { addkills -1 action 0 strength PIGCOPSTRENGTH  cactor PIGCOP action APIGDEAD }
		ifactor LIZMANCORPSE { addkills -1 action 0 strength LIZSTRENGTH cactor LIZMAN action ALIZLYINGDEAD }
		ifactor BOSS1CORPSENOGUN { addkills -1 action 0 strength PIGCOPSTRENGTH cactor BOSS1 action ABOSS1DEAD }
		ifactor BOSS1CORPSE { addkills -1 action 0 strength PIGCOPSTRENGTH cactor BOSS1 action ABOSS1DEAD }
		ifactor BOSS2CORPSE { addkills -1 action 0 strength PIGCOPSTRENGTH cactor BOSS2 action ABOSS2DEAD }
		ifactor BOSS3CORPSE { addkills -1 action 0 strength PIGCOPSTRENGTH cactor BOSS3 action ABOSS3DEAD }
		ifactor NEWBEASTCORPSE { addkills -1 action 0 strength PIGCOPSTRENGTH cactor NEWBEAST action ANEWBEASTLYINGDEAD }
		ifactor EGGCORPSE nullop else setactor[THISACTOR].yrepeat inity
    }


ends

useractor notenemy EGGCORPSE 0 state corpsecode enda
useractor notenemy LIZTROOPCORPSE 0 state corpsecode enda
useractor notenemy OCTABRAINCORPSE 0 state corpsecode enda
useractor notenemy COMMANDERCORPSE 0 state corpsecode enda
useractor notenemy PIGCOPCORPSE 0 state corpsecode enda
useractor notenemy LIZMANCORPSE 0 state corpsecode enda
useractor notenemy BOSS1CORPSE 0 state corpsecode enda
useractor notenemy BOSS1CORPSENOGUN 0 state corpsecode enda
useractor notenemy BOSS2CORPSE 0 state corpsecode enda
useractor notenemy BOSS3CORPSE 0 state corpsecode enda
useractor notenemy NEWBEASTCORPSE 0 state corpsecode enda
useractor notenemy BOSS4CORPSE 0 state corpsecode enda

eventloadactor DPCANNON

getactor[THISACTOR].ang initz
getactor[THISACTOR].extra temp
ifvarn temp -1 setvarvar mtype temp

enda
useractor notenemy DPCANNON 300 ACANNONWAIT

sizeat 64 64

clipdist 84
ifpdistl 1024
	ifp pfacing
		ifangdiffl 512
			ifvare cannonid -1
				ifcount 13
{
	getplayer[THISACTOR].fta temp
	ifvarl temp 6 { setplayer[THISACTOR].fta 6 setplayer[THISACTOR].ftq 1161 }
	ifhitspace 
	{
		setvarvar cannonid THISACTOR 
		getactor[THISACTOR].ang angvar
		setplayer[THISACTOR].ang angvar
		getplayer[THISACTOR].i spriteid
		setactor[spriteid].ang angvar
		resetcount 
	}
}

ifvarvare cannonid THISACTOR
{
	cstat 32768
	ifhitspace
	ifcount 26
	{
		setvar cannonid -1
		resetcount
		break
	}
	ifp palive nullop else
	{
		setvar cannonid -1
		break
	}
	ifpdistg 1280
	{
		setvar cannonid -1
		break
	}
	getplayer[THISACTOR].ohoriz temp
	getplayer[THISACTOR].horiz tempb
	subvarvar tempb temp
	shiftvarr tempb 2
	addvarvar temp tempb
	setplayer[THISACTOR].horiz temp
	
	ifcount 10
	{
		getplayer[THISACTOR].oang temp
		getplayer[THISACTOR].ang tempb
		getincangle tempb temp tempb
		shiftvarr tempb 2
		addvarvar temp tempb
		
		ifvarn mtype 0 // angle limit
		{
			getincangle tempd initz temp
			ifvarvarg tempd mtype
			{
				setvarvar temp initz
				addvarvar temp mtype
				setvar tempb 0
			}
			else
			{
				setvarvar tempc mtype
				mulvar tempc -1
				ifvarvarl tempd tempc
				{
					setvarvar temp initz
					subvarvar temp mtype
					setvar tempb 0
				}
			}
			
		}
		
		ifvarn tempb 0 soundonce DUMPSTER_MOVE
		else stopsound DUMPSTER_MOVE
		
		setplayer[THISACTOR].ang temp
		setactor[THISACTOR].ang temp
	}
	
	ifvare countvar 0 ifvarand bits 4
	{
		sound CANNONSND
		setvar countvar 52
		getplayer[THISACTOR].horiz tempd
		subvar tempd 100
		mulvar tempd -128
		subvar tempd 1024
		ezshoot tempd DPCANNONBALL
		getactor[THISACTOR].x digx
		getactor[THISACTOR].y digy
		getactor[THISACTOR].ang angvar
		setvarvar mx digx
		addvar mx 512
		rotatepoint digx digy mx digy angvar x y
		// setactor[RETURN].x x
		// setactor[RETURN].y y
		updatesector x y temp
		ifvarn temp 1 changespritesect RETURN temp
		// this will make the cannonball's sector the one in front of the cannon
		// to prevent it from bouncing off of a sector floor it has already passed
	}
}
else cstat 257

ifvarg countvar 0 subvar countvar 1

ifhitweapon
{
	strength 300
	spritepal 4
	debris SCRAP1 1
	getlastpal
	state HITMETALSOUND
}

enda

state randexplosions

// this is meant to be called every tick over an extended period of time (e.g. during a robot death animation)
// it causes explosions to appear in random locations around the actor

ifrnd 128
{
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].z z
	randvar temp 2048
	ifrnd 128 mulvar temp -1
	addvarvar x temp
	randvar temp 2048
	ifrnd 128 mulvar temp -1
	addvarvar y temp
	randvar temp 8192
	subvarvar z temp
	updatesectorz x y z temp
	ifvarn temp -1
	{
	
		espawn EXPLOSION2
		sound PIPEBOMB_EXPLODE
		setactor[RETURN].x x
		setactor[RETURN].y y
		setactor[RETURN].z z
		ifactor SKYCAR_CRASHED
		{
			setactorvar[RETURN].weap 1
			setactor[RETURN].cstat 2
		}
	}
}

ends

eventloadactor SKYCAR_CRASHED 

getactor[THISACTOR].lotag lotag 
setactor[THISACTOR].lotag 0 
setvar ONCAR 1

enda

action SKYCARIDLE 0 1 1 1 1
action SKYCARTHRUST 1 1 1 1

move CARMOVE 384 0

useractor notenemy SKYCAR_CRASHED 0

ifmove 0
{
	action SKYCARTHRUST
	setvar ONCAR 1
	move CARMOVE geth
	sizeat 64 64
	cstat 0
	clipdist 64
	setactor[THISACTOR].pitch 64
}

ifmove CARMOVE
{
	//cstat 2
	quake 26
	getactorvar[lotag].locatorids myspawner
	
	ldist xydist THISACTOR myspawner
	ifvare lotag 0
	{
		ifvarl xydist 512
		{
			action SKYCARIDLE
			getplayer[THISACTOR].i spriteid
			setactor[spriteid].cstat 257
			getactor[myspawner].x x
			getactor[myspawner].y y
			setactor[THISACTOR].x x
			setactor[THISACTOR].y y
			getactor[myspawner].z z
			setactor[THISACTOR].z z
			getactor[myspawner].sectnum mysector
			changespritesect THISACTOR mysector
			setplayer[THISACTOR].posx x
			setplayer[THISACTOR].posy y
			subvar z 8192
			setplayer[THISACTOR].posz z
			setplayer[THISACTOR].cursectnum mysector
			setvar ONCAR 0
			globalsound GENERIC_AMBIENCE23
			wackplayer
			wackplayer
			wackplayer
			sound DUKE_LAND_HURT
			move INIT
			cstat 1
			spawn EXPLOSION2
			setvar countvar 0
			getactor[THISACTOR].ang botclip
			whilevarn countvar 32
			{
				addvar countvar 1
				randvar zdist 8192 subvar zdist 10240 
				ifrnd 128 ezshoot zdist NEWSCRAP1 else ezshoot zdist NEWSCRAP6
				setthisprojectile[RETURN].trail SMALLSMOKE
				randvar temp 128
				addvar temp 160
				setthisprojectile[RETURN].vel temp
				addvar botclip 64
				setactor[THISACTOR].ang botclip
			}
			ifrnd 128 espawn BURNING else espawn BURNING2
			setactorvar[RETURN].mtype 2
			espawn CAR_BLOCKER
			setactorvar[RETURN].myspawner THISACTOR
			getactor[THISACTOR].roll temp
			ifvarl temp -64 setactor[THISACTOR].roll -64 else
			ifvarg temp 64 setactor[THISACTOR].roll 64
			break
		}
		setvarvar target myspawner
		state gradualturn
		// state aimattarget
		setvar target -1
		getactor[myspawner].z mz
		getactor[THISACTOR].z z
		subvarvar mz z
		shiftvarr mz 3
		movesprite THISACTOR 0 0 mz CLIPMASK0 RETURN
		ifvarg mz 0
		{
			getactor[THISACTOR].z digz
			ifvarvare z digz // failure to move down
			fall
		}
	} else
	{
		setvarvar temp lotag
		subvar temp 1
		
		ifvarl xydist 512 setvarvar lotag temp
		else
		{
			getactorvar[temp].locatorids spriteid
			ldist xydist2 THISACTOR spriteid
			ifvarvarl xydist2 xydist setvarvar lotag temp
		}
		ifvarvarn lotag temp
		{
			setvarvar target myspawner
			state gradualturn
			// state aimattarget
			setvar target -1
			getactor[myspawner].z mz
			getactor[THISACTOR].z z
			subvarvar mz z
			shiftvarr mz 3
			movesprite THISACTOR 0 0 mz CLIPMASK0 RETURN
			ifvarg mz 0
			{
				getactor[THISACTOR].z digz
				ifvarvare z digz // failure to move down
				fall
			}
		}
	}
	setplayer[THISACTOR].over_shoulder_on 0
	setplayer[THISACTOR].poszv 0
	getactor[THISACTOR].ang angvar
	setplayer[THISACTOR].ang angvar
	getplayer[THISACTOR].i spriteid
	setactor[spriteid].htextra -1
	setactor[spriteid].htpicnum -1
	getactor[spriteid].extra temp
	ifvarl temp MAXPLAYERHEALTH setactor[spriteid].extra MAXPLAYERHEALTH
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	
	addvar angvar 1024
	setvarvar mx x
	addvar mx 1024
	rotatepoint x y mx y angvar x y

	setplayer[THISACTOR].posx x
	setplayer[THISACTOR].posy y
	getactor[THISACTOR].z z
	subvar z 12288
	setplayer[THISACTOR].posz z
	updatesectorz x y z mysector
	setplayer[THISACTOR].cursectnum mysector
	setactor[spriteid].sectnum mysector

	state randexplosions
	state recontilt
	
	break
}

fall

ifcount 52
{
	// spawn smoke etc.
	ifrnd 128 
	{
		getactor[THISACTOR].z initz
		subvar initz 6144
		getactor[THISACTOR].ang angvar
		addvar angvar 1024
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		setvarvar mx x
		addvar mx 844
		rotatepoint x y mx y angvar x y
		espawn NEWSMOKE
		setactor[RETURN].z initz
		setactor[RETURN].x x
		setactor[RETURN].y y
	}
		
	resetcount
}



enda

eventloadactor SKYCAR_FLY

	sizeat 64 64
	getactor[THISACTOR].lotag lotag 
	setactor[THISACTOR].lotag 0 

enda

eventloadactor SKYCAR_FLY2

	sizeat 64 64
	getactor[THISACTOR].lotag lotag 
	setactor[THISACTOR].lotag 0 
	cactor SKYCAR_FLY

enda

move CARSTOPPED
move CARFLY1 256 0

useractor notenemy CAR_BLOCKER 0

ifmove 0
{
	cstator 32768
	sizeat 64 32
	cstator 257
	clipdist 172
}
ifvarn ONCAR 0 cstat 32768
else
	cstator 257

getactor[myspawner].x x
getactor[myspawner].y y
getactor[myspawner].z z
getactor[myspawner].sectnum mysector
getactor[myspawner].ang angvar
setactor[THISACTOR].ang angvar

setactor[THISACTOR].x x
setactor[THISACTOR].y y
setactor[THISACTOR].z z

updatesectorz x y z mysector
ifvarn mysector -1
changespritesect THISACTOR mysector

getactorvar[myspawner].targetlock targetlock
ifvare targetlock 1 // owner is available for boarding
{
	getactorvar[myspawner].monstatus monstatus
	ifvare monstatus 1
		ifp palive
			ifp pfacing
	  			ifpdistl 1792
	  				ifhitspace
	  				{
		  				setplayer[THISACTOR].ang angvar
		  				setplayer[THISACTOR].horiz 100
	  					setactorvar[myspawner].fallflag 1
	  					globalsound BONUS_SPEECH4
  					}
}

enda

state movespriteoverride
	
getactor[THISACTOR].z digz

updatesectorz x y digz temp

ifvarn mysector -1 ifvare temp -1 { setactor[THISACTOR].z z changespritesect THISACTOR mysector }
else
{
	ifvarg mz 0
	{	
		ifvarvare z digz // failure to move down
		fall
	}
	ifvarl mz 0
	{
		ifvarvare z digz // failure to move up
		ifvarn mysector -1
		{
			getceilzofslope mysector x y temp
			ifonwater { setvarvar temp z subvar temp 8192 subvar z 6144 }
			subvar z 1024
			ifvarvarl temp z setactor[THISACTOR].z z else
			addvar z 1024
		}
	}
}
ends

state collision

setvar temp 0
addvar RETURN 16384
ifvarl RETURN 16384 ifvarg RETURN -1 
{
    // hit a sprite
    setvar temp 1
    getactor[THISACTOR].xvel tempb
    shiftvarr tempb 1
    setactor[RETURN].htextra tempb
    setactor[RETURN].htpicnum RPG
    setactor[RETURN].htowner THISACTOR
    getactor[THISACTOR].ang angvar
    setactor[RETURN].htang angvar
    break
}
getactor[THISACTOR].htmovflag hitwall
andvar hitwall 49152
ifvare hitwall 32768
{
	// hit a wall
	getactor[THISACTOR].htmovflag hitwall
	andvar hitwall 16383
	getwall[hitwall].cstat tempb
	setvar temp 1
	ifvarand tempb 128 setvar temp 0
	ifvarand tempb 32 setvar temp 0
	//getwall[hitwall].hitag tempb
	//ifvare tempb 5
	getwall[hitwall].overpicnum tempb
	ifvare tempb 230
	{
		setvar temp 0
		getactor[THISACTOR].x digx
		getactor[THISACTOR].y digy
		getactor[THISACTOR].ang angvar
		setvarvar mx digx
		addvarvar mx 512
		rotatepoint x y mx y angvar mx my
		setactor[THISACTOR].x mx
		setactor[THISACTOR].y my
		updatesector mx my tempc
		ifvarn tempc -1 { changespritesect THISACTOR tempc setvarvar mysector tempc }
	}
	ifvare temp 0 break
}
ifceilingdistl 4 ifoutside ifvare temp 0 break


ifrnd 128
sound SKYCAR_COLLIDE else
sound SKYCAR_COLLIDE2

setvar teleported 1

setvarvar temp skyspeed
divvar temp 48
ifvarl temp 1 setvar temp 1
getplayer[THISACTOR].i spriteid
setactor[spriteid].htextra temp
setactor[spriteid].htpicnum RPG
setactor[spriteid].htowner player[THISACTOR].i
shiftvarr skyspeed 1

ends

useractor notenemy SKYCAR_FLY 0

setactor[THISACTOR].mdflags 0

ifmove 0
{
	action SKYCARIDLE
	sizeat 64 64
	cstat 0
	clipdist 64
	setvar monstatus 1
	setvar playerally -1
	move INIT
	espawn CAR_BLOCKER
	setactorvar[RETURN].myspawner THISACTOR
}

ifvare fallflag 1 // player just got in, using the blocking actor
{
	setvar teleported 1
	setvar fallflag 0
	getplayer[THISACTOR].ammo_amount 9 peractor5
	getplayer[THISACTOR].gotweapon 9 mtype
	setvar WEAPON9_FIRESOUND DPPISTOLFIRE //SHOTGUN_FIRE
	setvar WEAPON9_SHOTSPERBURST 2
	setvar WEAPON9_FIREDELAY 2
	setvar WEAPON9_TOTALTIME 3
	setvar WEAPON9_SHOOTS EXPLOSIVEBULLET
	setvar WEAPON9_FLAGS 4232 // ADD 4160 = ammo perburst + shotgun shells
	setvar WEAPON9_SPAWNTIME 4
    setvar WEAPON9_SPAWN 2535
	
	setplayer[THISACTOR].over_shoulder_on 1
	setvar ONCAR 2
	
	move CARSTOPPED
	setvar skyspeed 0
	cstat 0
	resetcount
}

ifmove INIT
{
	stopactorsound THISACTOR SKYCAR_JET1
	setvar targetlock 1
	ifpdistl 6144
	  ifcansee
	    ifvare botclip 0
	      ifcount 26
	{
		globalsound GENERIC_AMBIENCE15
		setvar botclip 1
	}
	fall
		
	break
}
else setvar targetlock 0

ifvarn ONCAR 0
{
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].z z
	updatesectorz x y z mysector
	
	ifaction SKYCARTHRUST nullop else
	ifvarg skyspeed 128 action SKYCARTHRUST
	
	addvar traillock 1
	ifmove CARFLY1
	{
		addvar countvar 1
		
		ifvarg countvar 52
		{
			setvarvar mx x
			setvarvar temp skyspeed
			shiftvarl temp 1
			addvarvar mx temp
			addvar mx 4096
			rotatepoint x y mx y sprite[THISACTOR].ang digx digy
			updatesector digx digy tempd
			ifvarn tempd -1
			{
				getflorzofslope tempd digx digy digz
				subvar digz 2048
				espawn BOMBTARG
				setsprite RETURN digx digy digz
				setactor[RETURN].cstat 32768
			}
			
			
			ifvarand bits 262144
			{
				espawn BIGBOMB
				sound RPG_SHOOT
				ifvarn tempd -1
				{
					setactorvar[RETURN].initx digx
					setactorvar[RETURN].inity digy
				}
				setvar countvar 0
			}
		}
	}
	
	ifvarand extbits 1
	ifvarl skyspeed 4096
	{
		ifvarg traillock 6
		stopactorsound THISACTOR SKYCAR_JET1
		//soundonce SKYCAR_THRUST
		addvar skyspeed 24
		ifmove CARFLY1 nullop else
		move CARFLY1 geth
		ifvarl skyspeed 256 setvar skyspeed 256
	}
	else 
	ifvarand extbits 2
	{
		ifvarg skyspeed 384
		{
			ifvarg traillock 6
			stopactorsound THISACTOR SKYCAR_JET1
			subvar skyspeed 24
		}
		
		ifonwater nullop else
			ifvarl skyspeed 512 ifvarn mysector -1
			{
				getflorzofslope mysector x y temp
				subvarvar temp z
				ifvarl temp 8192
				{
					setvar skyspeed 0
					stopactorsound THISACTOR SKYCAR_JET1
					move CARSTOPPED 
					action 0 
				}
			}
	}
	
	
	//stopsound SKYCAR_THRUST
	ifmove CARSTOPPED nullop else
	ifvarg traillock 6
	{
		setvar traillock 0
		setvarvar temp skyspeed
		shiftvarr temp 2
		setplayer[THISACTOR].sound_pitch temp
		soundonce SKYCAR_JET1
		setplayer[THISACTOR].sound_pitch 0
	}
	
	
	getactor[THISACTOR].pitch temp
	ifvarl temp 0 mulvar temp -1
	setvar tempb 512
	subvarvar tempb temp
	ifvare tempb 0 setvar tempb 1
	divvar tempb 5
	mulvarvar tempb skyspeed
	divvar tempb 100
	
	setactor[THISACTOR].xvel tempb
	
	ifvarn booster 0
	{
		ifvare booster 51 
		{
			globalsound WHOOSH
			setvar skyspeed 4096
		}
		ifaction SKYCARTHRUST nullop else action SKYCARTHRUST
	}
		
	setplayer[THISACTOR].over_shoulder_on 1 // no skycar HUD yet
	stopsound CAT_FIRE
	ifvarand bits 4
	{
		setvar countvarb 6
		setvar peractor6 1
		cstator 514
	} else ifvare countvarb 0
	{
		ifvare peractor6 1
		{
			setvar peractor6 0
			cstat 0
		}
	}
	ifvarg countvarb 0 subvar countvarb 1
	
	getactor[THISACTOR].ang angvar
	getplayer[THISACTOR].ang temp
	
	getincangle tempd angvar temp
	
	ifvarg tempd -16 ifvarl tempd 16 nullop else
	{
		setvarvar tempb tempd
		shiftvarr tempb 2
		addvarvar angvar tempb
		setactor[THISACTOR].ang angvar
	}
	
	ifvarl tempd -128
	{
		setvarvar temp angvar
		subvar temp 128
		setplayer[THISACTOR].ang temp
	} else
	ifvarg tempd 128
	{
		setvarvar temp angvar
		addvar temp 128
		setplayer[THISACTOR].ang temp
	}
	ifmove CARSTOPPED nullop else
	ifvare botdodge 0
	ifvarg skyspeed 256
	{
		ifvarand extbits 4 
		{
			setvar botdodge 1
			 
		} else
		ifvarand extbits 8 
		{
			setvar botdodge -1 
		}
	}
	ifvarn botdodge 0
	{
		setvarvar temp botdodge
		shiftvarl temp 6
		setactor[THISACTOR].roll temp
		ifvarg botdodge 0 
		{
			addvar botdodge 1
			ifvare botdodge 32 
			{
				setvar botdodge 0
				setactor[THISACTOR].roll 0
			}
		}
		ifvarl botdodge 0
		{
			subvar botdodge 1
			ifvare botdodge -32
			{
				setvar botdodge 0
				setactor[THISACTOR].roll 0
			}
		}
	}
	
  
    getactor[THISACTOR].htmovflag RETURN
    ifmove CARSTOPPED setvar RETURN 0
    ifvare RETURN 0 setvar teleported -1
    else ifvare teleported -1 state collision
    
	setvar mz 0
	
	ifmove CARSTOPPED setvar tempb 100 else
	getplayer[THISACTOR].horiz tempb
	subvar tempb 100
	mulvar tempb -4
	addvarvar mz tempb
	ifvarl mz -480 setvar mz -480
	ifvarg mz 480 setvar mz 480
	setvarvar digz mz
	ifvarn botdodge 0 
	{
		getactor[THISACTOR].ang angvar
		ifvarl botdodge 0 addvar angvar 512 else subvar angvar 512
		cos xvel angvar
		sin yvel angvar
		shiftvarr xvel 7
		shiftvarr yvel 7
		setvarvar temp skyspeed
		ifvarg temp 2048 setvar temp 2048
		mulvarvar xvel temp
		mulvarvar yvel temp
		shiftvarr xvel 8
		shiftvarr yvel 8    
		movesprite THISACTOR xvel yvel 0 CLIPMASK0 RETURN
		
	}
	ifmove CARSTOPPED setactor[THISACTOR].pitch 0
	else
	setactor[THISACTOR].pitch digz
	ifvarl mz 16 ifvarg mz -16 nullop else
	{
		ifvarg mz 16 subvar mz 16 else
		ifvarl mz -16 addvar mz 16
		
		ifvarn countvarb 0 shiftvarl mz 3 else
		{
			mulvarvar mz skyspeed
			shiftvarr mz 5
	  	}
	  	
		movesprite THISACTOR 0 0 mz CLIPMASK0 RETURN
		state movespriteoverride
	}

// ground collision code is buggy
// 	getflorzofslope mysector x y temp
// 	subvar temp 256
// 	ifvarvarg z temp ifvarg digz 16 ifvare teleported -1 
// 	{ 
// 		state collision 
// 		setactor[THISACTOR].pitch -32 
// 		setplayer[THISACTOR].horiz 124 
// 	}
	
	ifvarand bits 1 setvar mz -6144 else
	ifvarand bits 2 setvar mz 6144 else
	setvar mz 0
	ifmove CARSTOPPED setvar mz 0
	ifvarn mz 0
	{
		movesprite THISACTOR 0 0 mz CLIPMASK0 RETURN
		state movespriteoverride
	}
	
	setplayer[THISACTOR].curr_weapon 9
	setplayer[THISACTOR].ammo_amount 9 99
	setplayer[THISACTOR].gotweapon 9 1
	setplayer[THISACTOR].poszv -256
	
// 	getactor[THISACTOR].ang angvar
// 	addvar angvar 1024
// 	setvarvar mx x
//	addvar mx 768
//	rotatepoint x y mx y angvar x y
	getplayer[THISACTOR].i spriteid
	getactor[THISACTOR].z z
	updatesectorz x y z mysector
	ifvarn mysector -1
	{
		setplayer[THISACTOR].posx x
		setplayer[THISACTOR].posy y
		setvarvar digz z
		subvar digz 8192
		setplayer[THISACTOR].posz digz
		setsprite spriteid x y z
		setplayer[THISACTOR].cursectnum mysector
		changespritesect spriteid mysector
		changespritesect THISACTOR mysector
	} else
	{
		getplayer[THISACTOR].posx x
		getplayer[THISACTOR].posy y
		getplayer[THISACTOR].posz z
		setsprite THISACTOR x y z
	}
	
// 	updatesectorz x y z mysector
// 	ifvarn mysector -1
// 	{
// 		getceilzofslope mysector x y temp
// 		ifonwater { setvarvar temp z subvar temp 1024 }
// 		ifvarvarg z temp
// 		{
// 			setvarvar digz z
// 			subvarvar digz temp
// 			ifvarg digz 8192 subvar z 8192 else subvarvar z digz
// 			setplayer[THISACTOR].posz z
// 			setplayer[THISACTOR].cursectnum mysector
// 			setactor[spriteid].sectnum mysector
// 		}
// 	}
	
	ifp palive nullop else
	{
		fall
		iffloordistl 4 
		{
			setvar ONCAR 0
			resetcount
			move INIT
		} else
		state randexplosions
		setvar monstatus 2
	}
	
	ifmove CARSTOPPED setactor[THISACTOR].roll 0 else
	ifvare botdodge 0
	state recontilt
	
	ifhitspace ifcount 6
	{
		action SKYCARIDLE
		setactor[spriteid].cstat 257
		setplayer[THISACTOR].ammo_amount 9 peractor5
		setplayer[THISACTOR].gotweapon 9 mtype
		state normalfreeze
		setplayer[THISACTOR].curr_weapon 0
		setplayer[THISACTOR].over_shoulder_on 0
		setvar ONCAR 0
		setvar countvar 0
		resetcount
		getactor[THISACTOR].ang botclip
		setactor[THISACTOR].pitch 0
		break
	}
}

ifvare ONCAR 0 { ifcount 78 move INIT else fall }

enda

move BOMBSPEED 768

useractor notenemy BIGBOMB 0

ifmove 0
{
	setactor[THISACTOR].pitch 512
	sizeat 64 16
	move CARFLY1 geth
}

ifvare initx 0 ifvare inity 0 nullop else
{
	updatesector initx inity tempd
	getflorzofslope tempd initx inity digz
	subvar digz 2048
	espawn BOMBTARG
	setsprite RETURN initx inity digz
	setactor[RETURN].cstat 32768
	setactor[RETURN].pal 2
			
	ifmove STOPPED nullop else
	{
		ifmove CARFLY1 move BOMBSPEED geth
		setvarvar mx initx
		setvarvar my inity
		subvarvar mx sprite[THISACTOR].x
		subvarvar my sprite[THISACTOR].y
		getangle angvar mx my
		setactor[THISACTOR].ang angvar
		
		ifvarl mx 0 mulvar mx -1
		ifvarl my 0 mulvar my -1
		addvarvar mx my
		ifvarl mx 1536 move STOPPED
	}
}

fall
spawn SMALLSMOKE
iffloordistl 8 ifpdistg 3072
{
	addvar countvar 1
	
	ifvare countvar 1
	{
		palfrom 40 63 63 63
		move INIT
		cstat 32768
		spawn EXPLOSION2
		sound PIPEBOMB_EXPLODE
		hitradius 4096 120 200 280 360
		setvar countvarb 0
		getactor[THISACTOR].ang botclip
		whilevarn countvarb 36
		{
			addvar countvarb 1
			randvar zdist 8192 subvar zdist 6144 
			ifrnd 128 ezshoot zdist NEWSCRAP1 else ezshoot zdist NEWSCRAP6
			setthisprojectile[RETURN].trail SMALLSMOKE
			randvar temp 128
			addvar temp 256
			setthisprojectile[RETURN].vel temp
			addvar botclip 170
			setactor[THISACTOR].ang botclip
		}
		ifrnd 128 spawn BURNING else spawn BURNING2
	}
	else
	{
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		getactor[THISACTOR].z z
		randvar temp 3072
		ifrnd 128 mulvar temp -1
		addvarvar x temp
		randvar temp 3072
		ifrnd 128 mulvar temp -1
		addvarvar y temp
		randvar temp 8192
		subvarvar z temp
		updatesectorz x y z temp
		ifvarn temp -1
		{
			espawn EXPLOSION2
			sound PIPEBOMB_EXPLODE	
			setactor[RETURN].x x
			setactor[RETURN].y y
			setactor[RETURN].z z
			espawn NEWSMOKE
			setactor[RETURN].x x
			setactor[RETURN].y y
			setactor[RETURN].z z
			
		}
		ifvarg countvar 26 
			killit
	}
}

enda


useractor notenemy ICEBLOCK 100

ifmove 0
{
	clipdist 64
	ifspawnedby APLAYER sizeat 64 64
	cstator 257
	move INIT
}

ifhitweapon
{
	ifdead
	{
		lotsofglass 30
		killit
	}
}
		

enda

eventloadactor BONUSRING
cstator 130
sizeat 160 160
//spritepal 0
getactor[THISACTOR].lotag lotag
setactor[THISACTOR].lotag 0
getactor[THISACTOR].hitag hitag
setactor[THISACTOR].hitag 0
getactor[THISACTOR].yvel activator
setactor[THISACTOR].yvel 0
getactor[THISACTOR].extra monstflags
ifvare monstflags -1 setvar monstflags 0
enda

spritenoshade BIGFLASH
useractor notenemy BIGFLASH 0
cstat 130
sizeat 160 160
ifcount 3 killit
enda

useractor notenemy BONUSRING 0

cstator 128

ifvare ONCAR 2
ifvarvare lastring lotag
{
	ifmove 0 { move INIT getactor[THISACTOR].pal pal }
	
	ifspritepal 6 setactor[THISACTOR].pal pal else spritepal 6
	
	setvar temp 0
	ifp pfacing
		ifpdistl 2560
	setvar temp 1
	
	ifpdistl 2048
	setvar temp 1
	ifvare temp 1
	{
		addvar lastring 1
		espawn BIGFLASH
		setactor[RETURN].pal pal
		globalsound RINGSOUND
		addphealth 5
		ifvare pal 33 setvar booster 52
		ifvarn activator 0 state activatorstate
// 		ifvarn hitag 0
// 		{
// 			// ADD POINTS, WHATEVER
// 		}
		ifvare monstflags 1
		{
			setvar spriteid 0
			whilevarn spriteid 16384
			{
				getactor[spriteid].statnum temp
				ifvarn temp 1024
				{
					getactor[spriteid].picnum picnum
					ifvare picnum SECTOREFFECTOR
					{
						getactor[spriteid].lotag tempb
						ifvare tempb -1
						{
							getactor[spriteid].sectnum mysector
							setsector[mysector].lotag -1
							quote 1143
						}
					}
				}
				addvar spriteid 1
			}
		}
		
		killit
	}
}

enda

spritenoshade ICEBEAMTRAIL
useractor notenemy ICEBEAMTRAIL 0

ifmove 0
{
	angoff 512
	setactor[THISACTOR].roll shotpitch
	move INIT
	sizeat 64 64

}
sizeto 0 0
sizeto 0 0
sizeto 0 0
ifcount 2 cstator 2
ifcount 4 cstator 512
enda

spritenoshade LAZBEAMTRAIL
useractor notenemy LAZBEAMTRAIL 0

ifmove 0
{
 	angoff 512
	getactor[THISACTOR].htowner spriteid
	ifvarn spriteid -1
	{
		getactor[spriteid].zvel zvel
		getactor[spriteid].xvel xvel
		shiftvarr zvel 4
		getangle temp xvel zvel
		ifvarg temp 1023 subvar temp 2048
		setactor[THISACTOR].roll temp
	}

	move INIT
	sizeat 64 64
	ifrnd 128 spritepal 3
}
ifspritepal 0 spritepal 3 else spritepal 0
ifcount 2 cstator 2
ifcount 4 cstator 512
ifcount 6 killit
enda

spritenoshade POWTRAIL
useractor notenemy POWTRAIL 0

ifmove 0
{
	setactor[THISACTOR].shade -127
	move INIT
	sizeat 96 96
	angoff 512
	setactor[THISACTOR].roll shotpitch
}
sizeto 0 0
sizeto 0 0
sizeto 0 0
sizeto 0 0

ifcount 4 cstator 2
ifcount 8 cstator 512

//ifcount 12 killit

enda

spritenoshade POWEXPLOSION

useractor notenemy SPARK4 0

ifmove 0
{
	move INIT
	getactor[THISACTOR].z z
	subvar z 12288
	setactor[THISACTOR].z z
	sizeat 96 96
	cstator 128
}
ifcount 61 killit
enda

useractor notenemy POWEXPLOSION 0

addvar countvar 1
ifmove 0
{
	// ifvare lighting NO 
	state wakeupmonsters
	flash
	ifvare mtype 0
	{
		setvar intensity 1000
		setvar tempd 0
		state spawnpointlight
		spawn SPARK4
	}
	quake 52
	move INIT randomangle
	cstator 642
	sizeat 16 16
	getactor[THISACTOR].x initx
	getactor[THISACTOR].y inity
	getactor[THISACTOR].z initz
}
else
{
	ifrnd 160 cstat 32768 else cstat 642
	addvar intensity 256
	ifvarg intensity 16384 setvar intensity 16384
	sizeto 255 255
	sizeto 255 255
	sizeto 255 255
	sizeto 255 255
	randvar angvar 2047
	setactor[THISACTOR].ang angvar
	randvar zdist 8192
	ifrnd 128 mulvar zdist -1
	zshoot zdist FLASHPROJ
}

ifvarg countvar 62 
{
	whilevarn countvar 0
	{
		subvar countvar 1
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		getactor[THISACTOR].z z
		randvar temp 8192
		ifrnd 128 mulvar temp -1
		addvarvar x temp
		randvar temp 8192
		ifrnd 128 mulvar temp -1
		addvarvar y temp
		randvar temp 32768
		ifrnd 128 mulvar temp -1
		addvarvar z temp
		updatesectorz x y z temp
		ifvarn temp -1
		{
			espawn NEWSMOKE
			setactor[RETURN].x x
			setactor[RETURN].y y
			setactor[RETURN].z z
		}
	}
	killit
}

ifcount 3 ifvare mtype 0
{
	resetcount
	ifvarl countvar 41
	{
		espawn POWEXPLOSION
		setactorvar[RETURN].mtype 1
	}
	setvarvar temp countvar
	shiftvarl temp 7
	hitradiusvar temp 100 100 100 100
	headspritestat spriteid 1
	whilevarn spriteid -1
	{
		ifvare sprite[spriteid].picnum SHOOTME
		{
			dist xydist THISACTOR spriteid
			ifvarvarl xydist temp
			{
				getactorvar[spriteid].myspawner tempb
				ifvarn tempb -1
				ifvarl sprite[tempb].htextra 100
				{
					setactor[tempb].htextra 100
					setactor[tempb].htpicnum RADIUSEXPLOSION
					setactor[tempb].htowner player[THISACTOR].i
				}
			}
		}
		nextspritestat spriteid spriteid
	}
}

enda

useractor notenemy POWBALLINNER 0
ifcount 1 killit
enda

useractor notenemy POWBALLOUTER 0
ifcount 1 killit
enda

state changetodecal
getactorvar[myspawner].target2 FLOORTEX
ifvare FLOORTEX -1
{
	getactor[myspawner].htg_t 6 hitwall
	ifvare hitwall -1 break
	getwall[hitwall].picnum FLOORTEX
}
state CHECKSTEPS

setvar x 0
switch STEPSOUNDFX
case 1 setvar picnum WOODHOLE
setvar x 10
break
case 2 setvar picnum METALHOLE
setvar x 7
break
case 5 case 7 

setvar picnum CONCRETEHOLE2 setvar x 7
break
case 10 setvar picnum ELECTRONICHOLE
setvar x 8
break
case 11 setvar picnum ORGANICHOLE 
setvar x 8
break
default break
endswitch
ifvarn picnum BULLETHOLE
{
	setactor[THISACTOR].picnum picnum
	setactor[THISACTOR].xrepeat x
	setactor[THISACTOR].yrepeat x
	cstator 16
	cstator 128
	ifrnd 128 cstator 4
	changespritestat THISACTOR 1
}
ends

action FIRELASERACTION 4701 1 1 1 1

onevent EVENT_EGS


ifspawnedby RESPAWN
{
	ifvarand morefx 32 
	{
		getactor[THISACTOR].picnum picnum
		switch picnum
		case EGG
		case LIZTROOP
		case LIZTROOPSTAYPUT
		case LIZTROOPSHOOT
		case LIZTROOPJETPACK
		case LIZTROOPRUNNING
		case LIZTROOPONTOILET
		case LIZTROOPJUSTSIT
		case LIZTROOPDUCKING
		case OCTABRAIN
		case OCTABRAINSTAYPUT
		case DRONE
		case COMMANDER
		case COMMANDERSTAYPUT
		case TANK
		case PIGCOP
		case PIGCOPSTAYPUT
		case PIGCOPDIVE
		case LIZMAN
		case LIZMANSTAYPUT
		case LIZMANJUMP
		case LIZMANSPITTING
		case ROTATEGUN
		case BOSS1
		case BOSS1STAYPUT
		case BOSS2
		case BOSS3
		case BOSS4
		case BOSS4STAYPUT
		case SHARK
		case MINIBEAST
		case FEM1
		case FEM2
		case FEM3
		case FEM4
		case FEM5
		case FEM6
		case FEM7
		case FEM8
		case FEM9
		case FEM10
		case TOUGHGAL
		case NAKED1
		case PODFEM1
		case BLOODYPOLE
		case FEM6PAD
		case GREENSLIME
		setactor[THISACTOR].mdflags 1
		break
		default break
		endswitch
	}
	getactor[THISACTOR].owner temp
	ifvarn temp -1
	{
		getactor[temp].pal pal
		setactor[THISACTOR].pal pal
		getactorvar[temp].droptile droptile
		getactorvar[temp].monstflags monstflags
		getactorvar[temp].initcstat tempb
		//ifvarand initcstat 1 cstator 1
		//ifvarand initcstat 4 cstator 4
		ifvarand tempb 8 cstator 8
		ifvarand tempb 256 cstator 256
		ifvarn monstflags 0
		{
			setvar tempb 0
			ifactor BURNING setvar tempb 1
			ifactor BURNING2 setvar tempb 1
			ifvare tempb 1
			{
				getactor[temp].xrepeat x
				getactor[temp].yrepeat y
				setactor[THISACTOR].xrepeat x
				setactor[THISACTOR].yrepeat y
			}
		}
		ifvarn randomize 0 ifvare monstflags 0 state randomizestate
	}
}

getactor[THISACTOR].picnum picnum

switch picnum

	case SHOTSPARK1
	ifspawnedby APLAYER ifvarg CURRWEAP 6 // ifvare CURRWEAP 9
	{
		getactor[THISACTOR].z z
		getplayer[THISACTOR].posz mz
		subvarvar z mz
		getplayer[THISACTOR].i spriteid
		ldist xydist THISACTOR spriteid
		shiftvarr z 4
		getangle shotpitch xydist z
		ifvarg shotpitch 1023 subvar shotpitch 2048
	}
	break
	// generic ground jibs
	case 2249
	case 2254
	case 2259
	case 2264
	case 2269
	// lizman ground jibs
	case 2203
	case 2207
	case 2211
	// troop ground jibs
	case 1770
	case 1774
	case 1778
	
	getactor[THISACTOR].z z
	addvar z 2048
	setactor[THISACTOR].z z
	clipdist 48
		
	getactor[THISACTOR].owner spriteid
	ifvarn spriteid -1
	{
		setactor[THISACTOR].xrepeat sprite[spriteid].xrepeat
		setactor[THISACTOR].yrepeat sprite[spriteid].yrepeat
		setactor[THISACTOR].pal sprite[spriteid].pal
		getactorvar[spriteid].mtype mtype
	}
	else
	sizeat 32 32
	setvar command 1
	break
	
	case GUNPOWDERBARREL
	setvar weight WEIGHT3
    setvar initcstat 257
    setvar bouncesound ENDSEQVOL2SND4
    sizeat 40 40
    break

	case ACCESSSWITCH
	case ACCESSSWITCH2
	spriteflags 4
	setactor[THISACTOR].shade -100
	break
	
  case RAINSPRITE 
  case PLAYERTRAIL
  spriteflags 128
  sleeptime -1
  break
	
  case HEAVYHBOMB
  
  ifvare dukemon YES
  {
  	ifspawnedby APLAYER ifvare CURRWEAP 8
  	{
	  	setvar playerally YES // you are a dukeball!
	  	setvar PIPEBOMB_CONTROL 2
	  	setvar countvar 30
	  	setactor[THISACTOR].extra 0
	  	sizeat 20 20
	  	setvarvar mtype dukeballpics[dukeballselected] // the picnum of monster to be spawned
	  	ifvare mtype 0 spritepal 8 else spritepal 2
	  	// if mtype == 0 then ball is empty
	  	setvarvar monstflags dukeballflags[dukeballselected]
	  	setvarvar peractor1 dukeballpals[dukeballselected]
	  	getplayer[THISACTOR].ammo_amount 8 temp
	  	ifvarvare temp dukeballselected
	  	{
		  	setarray dukeballpics[dukeballselected] 0
		  	setarray dukeballflags[dukeballselected] 0
		  	setarray dukeballpals[dukeballselected] 0
	  	}
		else
		{
			setvarvar tempb dukeballpics[temp]
			setarray dukeballpics[dukeballselected] tempb
			setarray dukeballpics[temp] 0
			setvarvar tempb dukeballflags[temp]
			setarray dukeballflags[dukeballselected] tempb
			setarray dukeballflags[temp] 0
			setvarvar tempb dukeballpals[temp]
			setarray dukeballpals[dukeballselected] tempb
			setarray dukeballpals[temp] 0
		}
		addvar dukeballselected 1
		subvar temp 1
		ifvarvarg dukeballselected temp setvar dukeballselected 0
		
  	}
  }
  ifspawnedby APLAYER ifvarn CURRWEAP 8
  {
	  getactor[THISACTOR].xvel xvel
	  getplayer[THISACTOR].i spriteid
	  getactorvar[spriteid].weapcount temp
	  mulvar temp 9 divvar temp 5
	  ifinwater shiftvarr temp 1
	  addvarvar xvel temp
	  setactor[THISACTOR].xvel xvel
	  setactorvar[spriteid].weapcount 0
  }

  break
  
  case SMALLSMOKE
  getactor[THISACTOR].owner spriteid
  ifvarn spriteid -1
  {
	  ifvare sprite[spriteid].picnum SHOTSPARK1
	  ifvarn sprite[spriteid].htg_t 8 -1
	  {
		  getactor[spriteid].htg_t 8 temp
		  getactorvar[temp].monstatus monstatus
		  ifvare monstatus 1 cstator 32768
	  }
	  
  }
  break
  
  case MORTER
  getactor[THISACTOR].owner spriteid
  ifvarn spriteid -1
  getactorvar[spriteid].target target
  ifvarn target -1
  {
	  ldist xydist THISACTOR target
	  setvarvar zvel xydist
	  shiftvarr zvel 1
	  mulvar zvel -1
	  ifvarl zvel -4096 setvar zvel -4096
	  setactor[THISACTOR].zvel zvel
	  shiftvarr xydist 4
	  setactor[THISACTOR].xvel xydist
  }
  break

  case BATTERYAMMO
  ifvare usemp5 YES cactor MP5CLIP
  setvar NOCODE 1
  break
  
  case SHOTGUNSPRITE
  ifvare usemossberg YES cactor CRUIZERSPRITE
  setvar NOCODE 1
  break
  
  case CHAINGUNSPRITE
  ifvarand monstflags 1 nullop else
  ifvare usemp5 YES cactor MP5SPRITE
  setvar NOCODE 1
  break

 case SHRINKSPARK
 case SHRINKEREXPLOSION
 
 ifspawnedby APLAYER ifvare altshrinker 1 
 {
	 setactor[THISACTOR].extra 2 
	 setvar mtype 1 
	 spritepal 6
 } 
// else
//  ifvare lighting YES ifvarl highlight 10
//  {
// 	 setvar intensity 60
// 	 state enter_light_array
//  }
 break

 case SPARKPROJ
 setactor[THISACTOR].xrepeat 3
 setactor[THISACTOR].yrepeat 3
 break
 
 case POWBALL
 setvar tempd 0
 setvar intensity 3072
 state spawnpointlight
 break

 case BOTALLY setvar lotag 1 break
 
 case MINIBEAST
 setvar mtype 1
 cactor NEWBEAST
 strength TROOPSTRENGTH
 sizeat 20 20 
 cstator 257
 break
 
 case EGG
 case RECON
 sizeat 40 40
 cstator 257
 break

case LIGHTSOURCEPROJ

 setvarvar flicker pflicker
 setactor[THISACTOR].pal pcolor
 setthisprojectile[THISACTOR].pal pcolor
 setvarvar pal pcolor
 //ifvare rendmode 4 
 //{ 
	 setvar tempd 0 
	 state spawnpointlight 
 //}
 //else
 //state enter_light_array
 espawn LIGHTGLOW 
 setactorvar[RETURN].myspawner THISACTOR
 setactor[RETURN].pal pcolor
 setvarvar myspawner RETURN
 setactorvar[RETURN].position position
 break
 
 case LIGHTSOURCE
 addvar flares 1
 ifspawnedby LIGHTSOURCEPROJ
 {
	 getactor[THISACTOR].owner spriteid
	 getactorvar[spriteid].intensity intensity
	 getactorvar[spriteid].peractor7 peractor7
 }
 break

case EXPLOSION2

ifvarl framerate 20 setactor[THISACTOR].htflags 256
ifspawnedby RPG
{
	getactor[THISACTOR].owner spriteid
	getactorvar[spriteid].peractor1 peractor1
	ifvarand ppowers 2
	{
		getactor[spriteid].owner tempb
		ifvarn tempb -1 ifvare sprite[tempb].picnum APLAYER
			ifvare CURRWEAP 4 
				state startfires
	}
}
ifspawnedby RPGNOAIM
{
	getactor[THISACTOR].owner spriteid
	getactor[spriteid].owner tempb
		ifvarn tempb -1 ifvare sprite[tempb].picnum BOTALLY
				state startfires
	getactorvar[spriteid].weap weap
}
ifspawnedby HEAVYHBOMB
{
	getactor[THISACTOR].owner spriteid
	getactorvar[spriteid].playerally playerally
	ifvarn playerally 0 
	{
		setactorvar[spriteid].playerally 0
		getactorvar[spriteid].mtype mtype
		getactorvar[spriteid].monstflags monstflags
		ifvare mtype 0 // empty dukeball
		{
			espawn TRIPBOMBSPRITE
			setactorvar[RETURN].playerally YES
			setactor[RETURN].xrepeat 20
			setactor[RETURN].yrepeat 20
			ifrnd 128 setactor[RETURN].cstat 4
		}
		else
		{
			espawnvar mtype
			setactorvar[RETURN].monstflags monstflags
			setactorvar[RETURN].playerally -1
			ifvare peractor1 0
			{
				ifvare mtype BOSS1 setvar peractor1 3
				ifvare mtype BOSS2 setvar peractor1 3
				ifvare mtype BOSS3 setvar peractor1 3
				ifvare mtype BOSS4 setvar peractor1 3
			}
			setactor[RETURN].pal peractor1
			
			setactor[RETURN].xrepeat 40
			setactor[RETURN].yrepeat 40
			addweapon TRIPBOMB_WEAPON 1
		}
		cstator 32768
	}
	else ifvarand ppowers 2 state startfires
}
ifspawnedby TRIPBOMB
ifvarand ppowers 2 state startfires
break

case SHOOTME cstat 32768 
break

case APLAYER
ifvare DONE YES
{
	ifvare scaled YES
    {
	    getactor[THISACTOR].x x
	    mulvar x 2
	    setactor[THISACTOR].x x
	    getactor[THISACTOR].y y
	    mulvar y 2
	    setactor[THISACTOR].y y
	    getactor[THISACTOR].z z
	    mulvar z 2
	    setactor[THISACTOR].z z
	    updatesectorz x y z temp
	    changespritesect THISACTOR temp
    }
	ifvare mirrored YES
	{
	    getactor[THISACTOR].x x
	    mulvar x -1
	    setactor[THISACTOR].x x
	    getactor[THISACTOR].y y
	    getactor[THISACTOR].z z
	    updatesectorz x y z temp
	    changespritesect THISACTOR temp
	    getactor[THISACTOR].ang angvar
	    ifvarg angvar 1024 setvar temp 1536
	    else setvar temp 512
	    subvarvar temp angvar
	    mulvar temp 2
	    addvarvar angvar temp
	    setactor[THISACTOR].ang angvar
	    setplayer[THISACTOR].ang angvar
    }
    
    setvar DONE 0
}
	// HOLODUKE HOLOGRAM
	ifvare holodukebot YES
		setvar monstatus 10
	else setvar monstatus 9
break


case BULLETHOLE
ifvare effects YES
{
	getactor[THISACTOR].owner myspawner
	ifvarn myspawner -1
	{
		getactor[myspawner].picnum temp
		ifvare temp SHOTSPARK1
			state changetodecal
		
	}
}
break

case SHOTGUNSHELL
ifvare usemossberg YES ifspawnedby APLAYER
{
	getactor[THISACTOR].cstat initcstat
	setactor[THISACTOR].cstat 32768
}
break


case FIREBALLPROJ
ifvare rendmode 4 ifvarg framerate 20
{
 setvar tempd 2
 setvar pal 2
 setvar intensity 3072
 state spawnpointlight
}
getactor[THISACTOR].ang angvar
addvar angvar 1024
setactor[THISACTOR].ang angvar
getactor[THISACTOR].zvel zvel
mulvar zvel -1
setactor[THISACTOR].zvel zvel
ifspawnedby APLAYER 
{
	sound RPG_SHOOT
	setthisprojectile[THISACTOR].extra RPG_WEAPON_STRENGTH
	setvarvar target scannedsprite
}
else 
{
	ifspawnedby BOSS2 
	randvar temp 192 
	else randvar temp 256 
	ifrnd 128 mulvar temp -1
	addvarvar angvar temp
	setactor[THISACTOR].ang angvar
	getactor[THISACTOR].owner spriteid
	ifvarn spriteid -1
	getactorvar[spriteid].target target
	ifvare target -1
	{
		getactorvar[spriteid].playerally temp
		ifvare temp 0
		getplayer[THISACTOR].i target
	}
}
break

case STARPROJ

randvar tempb 16
getactor[THISACTOR].ang angvar
ifrnd 128 addvarvar angvar tempb else subvarvar angvar tempb
setactor[THISACTOR].ang angvar

getactor[THISACTOR].ang angvar
addvar angvar 1024
setactor[THISACTOR].ang angvar
randvar tempb 1024
getactor[THISACTOR].zvel zvel
addvarvar zvel tempb
mulvar zvel -1
setactor[THISACTOR].zvel zvel
break

case FIREBULLET
ifvare rendmode 4 ifvarg framerate 24
{
 setvar tempd 2
 setvar pal 2
 setvar intensity 1280
 state spawnpointlight
}
state randtraj
break

case RAILSLUG_WEAK
ifvare rendmode 4 ifvarg framerate 24
{
 setvar tempd 2
 setvar pal 17
 setvar intensity 1280
 state spawnpointlight
}
state randtraj
break

case ICESHARD
ifvare rendmode 4 ifvarg framerate 24
{
 setvar tempd 2
 setvar pal 1
 setvar intensity 1280
 state spawnpointlight
}
ifspawnedby BOSS1
{
	getactor[THISACTOR].z z
	addvar z 4096
	setactor[THISACTOR].z z
}
state randtraj
break

case ELECTROPROJ
ifvare rendmode 4 ifvarg framerate 24
{
 setvar tempd 2
 setvar pal 0
 setvar intensity 2048
 state spawnpointlight
}
ifspawnedby APLAYER 
{
	state randtraj
	movesprite THISACTOR 0 0 8192 CLIPMASK0 RETURN
}
break

case HEADJIB1
case ARMJIB1
case LEGJIB1
case LIZMANHEAD1
case LIZMANARM1
case LIZMANLEG1
case JIBS1
case JIBS2
case JIBS3
case JIBS4
case JIBS5

randvar peractor1 96
ifrnd 128 mulvar peractor1 -1

getactor[THISACTOR].owner spriteid
ifvarn spriteid -1
{
	getactor[spriteid].pal pal
	setactor[THISACTOR].pal pal
	getactor[spriteid].htpicnum temp
	ifvare temp RPG ifrnd 96 setvar peractor1 1
	//ifvare temp RADIUSEXPLOSION ifrnd 96 setvar peractor1 1
}

getactor[THISACTOR].htpicnum temp
ifvare temp NEWBEASTHANG setactor[THISACTOR].htpicnum NEWBEAST
ifspawnedby NEWBEAST
{
	getactor[THISACTOR].owner temp
	ifvarn temp -1
	{
		getactorvar[temp].mtype mtype
		ifvare mtype 1
		{
			getactor[THISACTOR].xrepeat x
			divvar x 2
			setactor[THISACTOR].xrepeat x
			getactor[THISACTOR].yrepeat y
			divvar y 2
			setactor[THISACTOR].yrepeat y
		}
	}
}
break

case PIGHEAD
case PIGUPPER
case PIGUPPER2
case PIGLOWER
case PIGLOWER2

randvar peractor1 96
ifrnd 128 mulvar peractor1 -1

getactor[THISACTOR].owner spriteid
ifvarn spriteid -1
{
	getactor[spriteid].pal pal
	setactor[THISACTOR].pal pal
	getactor[spriteid].htpicnum temp
	ifvare temp RPG ifrnd 96 setvar peractor1 1
	//ifvare temp RADIUSEXPLOSION ifrnd 96 setvar peractor1 1
}
break

case JIBS6
ifspawnedby COLACANSTAND cstator 32768
ifspawnedby SMALLSMOKE { getactor[THISACTOR].z z addvar z 4096 setactor[THISACTOR].z z  }
getactor[THISACTOR].owner spriteid
ifvarn spriteid -1
{
	getactor[spriteid].pal pal
	ifvare pal 0 ifvare sprite[spriteid].picnum EGG setvar pal 6
	setactor[THISACTOR].pal pal	
	ifvarl sprite[THISACTOR].xrepeat 20 
	{
		setactor[THISACTOR].xrepeat sprite[spriteid].xrepeat
		setactor[THISACTOR].yrepeat sprite[spriteid].yrepeat
		randvar xvel 36
		setactor[THISACTOR].xvel xvel
		randvar angvar 2047
		setactor[THISACTOR].ang angvar
	}

// 	ifvarl sprite[spriteid].extra 10
// 	{
// 		getactorvar[spriteid].bleeding temp
// 		ifvarg temp 20
// 		{
// 			getactor[THISACTOR].zvel zvel
// 			{
// 				randvar tempb 56
// 				mulvarvar tempb temp
// 				shiftvarr tempb 2
// 				subvarvar zvel tempb
// 				setactor[THISACTOR].zvel zvel
// 			}
// 			shiftvarr temp 1
// 			ifvare sprite[spriteid].htpicnum SHOTSPARK1 shiftvarr temp 2
// 			getactor[THISACTOR].xvel xvel
// 			addvarvar xvel temp
// 			setactor[THISACTOR].xvel xvel
// 		}
// 	}

}
break

case FIRELASER

  action FIRELASERACTION
  ifvarl framerate 24 setactor[THISACTOR].htflags 256
ifspawnedby APLAYER
{
	getactor[THISACTOR].extra temp
	shiftvarl temp 1
	setactor[THISACTOR].extra temp
	setactor[THISACTOR].xoffset -32
}
ifspawnedby BOSS2 
{
	state randtraj
	getactor[THISACTOR].xrepeat x
	mulvar x 3 divvar x 2
	setactor[THISACTOR].xrepeat x
	getactor[THISACTOR].yrepeat y
	mulvar y 3 divvar y 2
	setactor[THISACTOR].yrepeat y
	getactor[THISACTOR].extra temp
	mulvar temp 2
	setactor[THISACTOR].extra temp
}
ifspawnedby ROTATEGUN
{
	getactor[THISACTOR].owner spriteid
	getactorvar[spriteid].mtype mtype
	ifvare mtype 1
	{
		getactor[THISACTOR].xrepeat x
		mulvar x 3 divvar x 2
		setactor[THISACTOR].xrepeat x
		getactor[THISACTOR].yrepeat y
		mulvar y 3 divvar y 2
		setactor[THISACTOR].yrepeat y
		getactor[THISACTOR].extra temp
		mulvar temp 2
		setactor[THISACTOR].extra temp
	}
}
break

case BIGFIRELASER

ifspawnedby APLAYER
{
	// add more damage
	randvar temp 20
	addvar temp 20
	setactor[THISACTOR].extra temp
}
ifvare rendmode 4 ifvarg framerate 19
{
 setvar tempd 2
 setvar intensity 4096
 setvar pal 23
 state spawnpointlight
}
break

case COOLEXPLOSION1
ifvarl framerate 25 setactor[THISACTOR].htflags 256
getactor[THISACTOR].owner spriteid
ifvarn spriteid -1
{
	getactorvar[spriteid].target target
	ifvarn target -1 state randtraj
	getactorvar[spriteid].playerally playerally
}
break

case MORTER2
getactor[THISACTOR].zvel zvel
subvar zvel 1536
setactor[THISACTOR].zvel zvel
ifvare rendmode 4 ifvarg framerate 24
{
 setvar tempd 2
 setvar intensity 2048
 setvar pal 2
 state spawnpointlight
}
break

case RPG
case RPGNOAIM

// CODE FOR SETTING CORRECT PITCH ON HRP ROCKET MODEL
// 	getactor[THISACTOR].zvel zvel
//     divvar zvel 50
//     setactor[THISACTOR].pitch zvel

    ifspawnedby APLAYER
    {
	    getplayer[THISACTOR].curr_weapon temp
	    ifvare temp 7 setvar peractor1 2 else
	    ifvare usebigrox YES
	    {
		    ifvare WEAPON4_FIRESOUND WHOOSH
		    {
			    setvar WEAPON4_FIRESOUND RPG_SHOOT
			    setactor[THISACTOR].xrepeat 12
			    setactor[THISACTOR].yrepeat 12
			    setvar weap 1
			    getactor[THISACTOR].xvel initx
			    getactor[THISACTOR].zvel initz
			    getplayer[THISACTOR].i myspawner
			    setactor[THISACTOR].extra 30
			    setvar peractor1 0
			    whilevarn peractor1 10
			    {
				    addvar peractor1 1
				    eshoot RPGNOAIM
				    setactorvar[RETURN].weap 1
					setactor[RETURN].extra 30
				    setactor[RETURN].xrepeat 12
				    setactor[RETURN].yrepeat 12
				    setactor[RETURN].xvel initx
				    setactor[RETURN].zvel initz
				    setactor[RETURN].htpicnum APLAYER
				    setactor[RETURN].htowner myspawner
			    }
			    setvar peractor1 -1
		    }
		    else
		    {
			    getactor[THISACTOR].extra temp
			    mulvar temp 3 shiftvarr temp 1
			    setactor[THISACTOR].extra temp
			    setvar temp RPGBLASTRADIUS
			    mulvar temp 3 shiftvarr temp 1
			    setthisprojectile[THISACTOR].hitradius temp
			    getactor[THISACTOR].xvel xvel
			    mulvar xvel 3 shiftvarr xvel 1
			    setactor[THISACTOR].xvel xvel
			    getactor[THISACTOR].zvel zvel
			    mulvar zvel 3 shiftvarr zvel 1
			    setactor[THISACTOR].zvel zvel
			    setvar peractor1 1
		    }
	    }
    }
    
	ifspawnedby BOSS2 
	{
		setvar peractor1 2
		ifactor RPGNOAIM
		{
			
			getactor[THISACTOR].owner spriteid
			getactor[spriteid].pal pal
			ifvare pal 0
			{
				getactor[THISACTOR].z z
				addvar z 5120
				setactor[THISACTOR].z z
			}
			getactor[THISACTOR].ang angvar
			randvar temp 128 ifrnd 128 mulvar temp -1
			addvarvar angvar temp
			setactor[THISACTOR].ang angvar
			getactor[THISACTOR].xrepeat x
			getactor[THISACTOR].yrepeat y
			mulvar x 4
			mulvar y 4
			setthisprojectile[THISACTOR].xrepeat x
			setthisprojectile[THISACTOR].yrepeat y
		}
	}
	
	ifspawnedby BOSS3
	{
		setvar peractor1 2
		getactor[THISACTOR].owner temp
		getactor[temp].pal pal
		ifvarn pal 0 
		{
			getactor[THISACTOR].z z
			ifactor RPG
			addvar z 3072 else
			ifactor RPGNOAIM subvar z 3072
			setactor[THISACTOR].z z
		}
	}
	
	ifspawnedby ROTATEGUN
	{
		setactor[THISACTOR].xrepeat 10
		setactor[THISACTOR].yrepeat 10
	}
	
	ifactor RPG { ifvarl framerate 20 setactor[THISACTOR].htflags 256 }
	else
	ifvare rendmode 4 ifvarg framerate 19
	{
	 setvar tempd 2
	 setvar pal 7
	 setvar intensity 1560
	 state spawnpointlight
	}
	
break

case ROCKETHALO
cstat 32768
break

case BLOODPOOL

// cstator 2
ifrnd 128 cstator 4
randvar angvar 2047
setactor[THISACTOR].ang angvar
ifoutside getsector[THISACTOR].ceilingshade temp else
getsector[THISACTOR].floorshade temp
addvar temp 6
ifvarg temp 28 setvar temp 28
ifvarl temp 0 setvar temp 0
setactor[THISACTOR].shade temp
// does nothing without spritenoshade!!
ifspawnedby LIZARDVOMIT spawn POISONGASMAKER
insertspriteq
getactor[THISACTOR].owner spriteid
ifvarn spriteid -1 
{
	getactorvar[spriteid].monstatus monstatus
	getactor[spriteid].pal peractor1
	ifvare peractor1 0 setvar peractor1 2
}

break

case NEWSPLASH
case WATERCIRCLE
spriteflags 16
break

case WATERSPLASH2
case WATERSPLASH3
ifvarand morefx 2 
ifspritepal 0 
{ 
	spawn NEWSPLASH 
	spritepal 40 
	cstator 32768 
} 
break
default break

endswitch


endevent

state scorchfloor

espawn SCORCH
setactor[RETURN].x hitx
setactor[RETURN].y hity
setactor[RETURN].z hitz
setvar temp 160
ifrnd 128 orvar temp 4
ifrnd 128 orvar temp 8
setactor[RETURN].cstat temp
getactor[THISACTOR].xrepeat x
ifvarl x 14 setactorvar[RETURN].initx x

ends

// state lodhack

// ifvarand peractor3 1 
// {
// 	findplayer xydist
// 	setvarvar tempb framerate
// 	ifvare tempb 0 setvar tempb 1
// 	divvarvar xydist tempb
// 	ifvarl xydist 512 
// 	{
// 		subvar peractor3 1
// 		setactor[THISACTOR].mdflags peractor3
// 	}
// }
// else
// ifvarl framerate 30
// {
// 	getactor[THISACTOR].statnum tempb
// 	setvar tempc 0
// 	ifvare tempb 0 setvar tempc 1
// 	ifvare tempb 6 setvar tempc 1
// 	ifvare tempc 1
// 	{
// 		setvar temp 0
// 		ifpdistg LODISTANCE
// 		{
// 			findplayer xydist
// 			setvarvar tempb framerate
// 			ifvare tempb 0 setvar tempb 1
// 			divvarvar xydist tempb
// 			ifvarg xydist 1024 setvar temp 1
// 		}
// 		ifvare temp 1
// 		{
// 			getactor[THISACTOR].mdflags peractor3
// 			orvar peractor3 1
// 			setactor[THISACTOR].mdflags peractor3
// 		}
// 	}
// }

// ends


state lightsprite

ifvarg intensity 0
ifvarn sprite[THISACTOR].picnum LIGHTSOURCE
// ifvarn sprite[THISACTOR].picnum SECTOR_CONTROLLER
{
	ifvarg flicker 0
	{
		ifvare peractor7 0 setvarvar peractor7 intensity else
		{
			setvarvar temp peractor7
			mulvarvar temp flicker
			divvar temp 100 // temp is now the random component of the intensity
			randvarvar intensity temp
			// now add the base component
			setvarvar tempb peractor7
			subvarvar tempb temp // base is what is left after subtracting max flickering amount
			addvarvar intensity tempb
			ifvarl intensity 1 setvar intensity 1
		}
	}
// 		ifvare lightidle 0
// 			addvar lightidle 26
	
	ifactor BURNING sleeptime -1
	ifactor BURNING2 sleeptime -1
}

// ifvare lighting YES
// ifvarn mywall -1
// {
// 	ifvare mywall 32768
// 	{
// 		getsector[THISACTOR].floorshade temp
// 		ifvarvarn temp ammo
// 		{
// 			setvarvar tempb initshade
// 			subvarvar temp ammo
// 			addvarvar tempb temp
// 			ifvarl tempb -127 setvar tempb -127
// 			setactor[THISACTOR].shade tempb
// 		}
// 		else setactor[THISACTOR].shade initshade
// 	}
// 	else
// 	{
// 		getwall[mywall].shade temp
// 		ifvarvarn temp ammo // wall has changed shade from its initial value
// 		{
// 			setvarvar tempb initshade
// 			subvarvar temp ammo
// 			addvarvar tempb temp
// 			ifvarl tempb -127 setvar tempb -127
// 			setactor[THISACTOR].shade tempb
// 		} else
// 		setactor[THISACTOR].shade initshade
// 	}
// }

ends

state flipit

switch picnum

case 255 case 341 case 387 case 391 case 479 case 487
case 489 case 515 case 516 case 544 case 546 case 547
case 548 case 549 case 594 case 631 case 798 case 860 case 861
case 913 case 918 case 993 case 1009 case 1011 case 1022 case 1049
case 1050 case 1148 case 1149 case 1150 case 1175 case 1225
case 1337 case 1338 case 1345 case 1346 case 1356 case 1357 case 2491
case 3426 case 3427 case 3428 case 4352 case 4364 case 4365
case 4416 case 4417 case 4423 case 4424 case 4430 case 4431
case 4432 case 4433 case 4434 case 4435 case 4456 case 4457
case 4480 case 4481 case 4482 case 4533 case 4558 case 4588
case 4589 case 4600 case 4601 case 4602 case 4603 case 4604
case 4605 case 4954
getactor[THISACTOR].cstat temp
ifvarand temp 4 subvar temp 4 else orvar temp 4
setactor[THISACTOR].cstat temp
ifvarand temp 32768 nullop else
setvarvar initcstat temp

break
default break
endswitch

ifvare NOCODE 2 setvar NOCODE 1

ends

onevent EVENT_SPAWN

ifactor 507
ifvare lotag 1
{
	getactor[THISACTOR].cstat initcstat
	ifvarand initcstat 256 { xorvar initcstat 256 setactor[THISACTOR].cstat initcstat }
	cstator 32768
	cstator 1
	setvar NOCODE 1
}

ifvare sector[THISACTOR].lotag 32767
ifvarn sprite[THISACTOR].statnum 4
{
	getactor[THISACTOR].htflags temp
	orvar temp 256
	setactor[THISACTOR].htflags temp
}

endevent


// EVENT CODE
onevent EVENT_GAME

// ifvare NOCODE 1
// {
// 	getactor[THISACTOR].htflags temp
// 	orvar temp 128
// 	setactor[THISACTOR].htflags temp
// 	break
// }

ifvarg underwater 0
{
	ifvarg underwater 3
	{
		soundonce ITEM_SPLASH
		espawn WATERSPLASH3
		ifvarn watereffector -1
		setactor[RETURN].z sprite[watereffector].z	
	}
	subvar underwater 1
	ifactor HEAVYHBOMB
	{
		getactor[THISACTOR].xvel xvel
		ifvarn xvel 0 ifvarl countvar 78
		{
			addvar countvar 1
			ifvarl xvel 104
			{
				setvar xvel 104
				setvarvar temp countvar
				shiftvarr temp 1
				subvarvar xvel temp
				setactor[THISACTOR].xvel xvel
			}
		}
		getactor[THISACTOR].zvel zvel
		ifvarn zvel 0 
		{
			subvar zvel 160 
			ifvarl zvel -256 addvar zvel 128
			ifvarl zvel -128 addvar zvel 64
			setactor[THISACTOR].zvel zvel 
		}
	} else
	ifvare peractor2 0
	ifvare sprite[THISACTOR].statnum 4
	{
		setvar peractor2 1
		getactor[THISACTOR].xvel xvel
		divvar xvel 2
		setactor[THISACTOR].xvel xvel
		getactor[THISACTOR].zvel zvel
		divvar zvel 2
		setactor[THISACTOR].zvel zvel
	}
	
	getactor[THISACTOR].statnum temp
	switch temp
	case 1 case 5
	{
		getactor[THISACTOR].zvel zvel
		ifvarg zvel 768 setactor[THISACTOR].zvel 768
		ifactor SHELL { ifvarg zvel 128 setactor[THISACTOR].zvel 128 }
		ifactor SHOTGUNSHELL { ifvarg zvel 128 setactor[THISACTOR].zvel 128 }
	}
	break
	default break
	endswitch
}



// ifvare lighting YES 
// {
// 	state lightsprite
// 	ifvare NOCODE 1 break
// } 


// ifvarg intensity 0
// {
// 	state lightsprite
// 	ifvare NOCODE 1 break
// }


ifspritepal 66 ifvarg sprite[THISACTOR].picnum 10
{
	ifvare initcstat -1
		getactor[THISACTOR].cstat initcstat
		
	ifvare player[THISACTOR].heat_on 1 
	{
		setactor[THISACTOR].cstat initcstat
		getactor[THISACTOR].picnum picnum
		ifvarg picnum 9000 
		{
			subvar picnum 9000 
			setactor[THISACTOR].picnum picnum 
		}
	}
	else 
	{
		setactor[THISACTOR].cstat 32768
		getactor[THISACTOR].picnum picnum
		switch picnum
		case ACCESSSWITCH case 131
		case SLOTDOOR case 133
		case LIGHTSWITCH case 135
		case SPACEDOORSWITCH case 137
		case SPACELIGHTSWITCH case 139
		case FRANKENSTINESWITCH case 141
		case NUKEBUTTON
		case MULTISWITCH case 147 case 148 case 149
		case DIPSWITCH case 163
		case DIPSWITCH2 case 165
		case TECHSWITCH case 167
		case DIPSWITCH3 case 169
		case ACCESSSWITCH2 case 171
		case LIGHTSWITCH2 case 713
		case POWERSWITCH1 case 861
		case LOCKSWITCH1 case 863
		case POWERSWITCH2 case 865
		case HANDSWITCH case 1112
		case PULLSWITCH case 1123
		case ALIENSWITCH case 1143
		case HANDPRINTSWITCH
		addvar picnum 9000
		setactor[THISACTOR].picnum picnum
		break
		default break
		endswitch
	}
}

ifvarn pulse 0
{
	spriteflags 4
	getplayer[THISACTOR].player_par temp
	divvarvar temp pulse
	shiftvarl temp 8
	sin shade temp
	shiftvarr shade 10
	addvarvar shade initshade
	setvarvar temp shade
	setvarvar shade peractor7
	subvarvar temp peractor7
	ifvarg temp 0 { addvar shade 1 ifvarl pulse 3 ifvarg temp 1 addvar shade 1 } else
	ifvarl temp 0 { subvar shade 1 ifvarl pulse 3 ifvarl temp -1 subvar shade 1 }
	setactor[THISACTOR].shade shade
	setvarvar peractor7 shade
}


getactor[THISACTOR].picnum picnum

switch picnum

case MORTER2

getactor[THISACTOR].xvel xvel
subvar xvel 5
setactor[THISACTOR].xvel xvel

break

case HEAVYHBOMB

ifvarn playerally 0
{
	ifvarg countvar 40 ifpdistl 1280 setvarvar countvar GRENADE_LIFETIME
	ifvarn sprite[THISACTOR].htmovflag 0 setvarvar countvar GRENADE_LIFETIME
	addvar countvar 1
	ifvarvarg countvar GRENADE_LIFETIME
	{
		spawn EXPLOSION2BOT
		sound VENT_BUST
		debris SCRAP1 5
		debris SCRAP6 5
		ifvare mtype 0 // empty dukeball
		{
			espawn TRIPBOMBSPRITE
			setactorvar[RETURN].playerally YES
			setactor[RETURN].xrepeat 20
			setactor[RETURN].yrepeat 20
			ifrnd 128 setactor[RETURN].cstat 4
		}
		else
		{
			espawnvar mtype
			setactorvar[RETURN].monstflags monstflags
			setactorvar[RETURN].playerally -1
			setactor[RETURN].pal peractor1
			setactor[RETURN].xrepeat 40
			setactor[RETURN].yrepeat 40
			addweapon TRIPBOMB_WEAPON 1
			setvar playerally 0
		}
		setvar playerally 0
		sizeat 0 0
		cactor SMALLSMOKE
		killit
		// TRYING EVERYTHING TO PREVENT THE MONSTER ARMY SPAWN BUG
	}
}

ifvarg sprite[THISACTOR].htg_t 7 40
setactor[THISACTOR].htg_t 7 40

ifspawnedby APLAYER ifvare CURRWEAP 10
iffloordistl 16
{
	findnearactorz SHOOTME 4096 10240 temp
	ifvare temp -1
	findnearactorz SHOOTMEALLY 4096 10240 temp
	ifvarn temp -1
	{
		getactorvar[temp].myspawner spriteid
		ifvarn spriteid -1
		{
			getactorvar[spriteid].monstflags tempb
			ifvarand tempb 2048
			ifvarn sprite[spriteid].picnum BOSS1 
			ifvarn sprite[spriteid].picnum BOSS2 ifvarn sprite[spriteid].picnum BOSS3
			{
				ifvarn actorvar[spriteid].mtype 1
				ifvarl sprite[spriteid].extra 300
				ifvare actorvar[spriteid].peractor6 0
				ifvare sprite[spriteid].htmovflag 0
				{
					ifvarl sprite[spriteid].xvel 128 setactor[spriteid].xvel 128
					getactor[spriteid].x mx
					getactor[spriteid].y my
					subvarvar mx sprite[THISACTOR].x
					subvarvar my sprite[THISACTOR].y
					getangle angvar mx my
					setactorvar[spriteid].botdodge 0
					setactor[spriteid].ang angvar
					setactorvar[spriteid].peractor3 -1
				}
			}
		}
	}
}

break

case BLOODPOOL
ifspawnedby COLACANSTAND ifvare mtype 0
 cstator 32768

ifvarn monstatus 0
ifvarn sprite[THISACTOR].pal 0
{
	ifrnd 128 cactor NEWBLOODP1 else cactor NEWBLOODP2
	changespritestat THISACTOR 1
	setactor[THISACTOR].pal peractor1
	randvar x 4
	addvarvar x 16
	randvar y 4
	addvarvar y 16
	setactor[THISACTOR].xrepeat x
	setactor[THISACTOR].yrepeat y
	
	getflorzofslope sprite[THISACTOR].sectnum sprite[THISACTOR].x sprite[THISACTOR].y z // z is the return var
	setactor[THISACTOR].z z
}
 
setvar NOCODE 1
break



// case SECTOR_CONTROLLER
// changespritestat THISACTOR 1
// break

case SECTOREFFECTOR

ifvare mirrored YES
{
	ifvarn mysector -1 setactor[THISACTOR].sectnum mysector
	ifvare lotag 24 // conveyer belt
	{
		getactor[THISACTOR].yvel yvel
		divvar yvel -64
		getsector[THISACTOR].floorxpanning mx
		addvarvar mx yvel
		setsector[THISACTOR].floorxpanning mx
	}
}


ifvare lotag 49 // point light
{
	ifvarn activator 0
	{
		ifvare intensity 0 setvarvar intensity hitag
		checkactivatormotion activator
		ifvare RETURN YES
		{
			ifvare hitag -1 
			{
				setactor[THISACTOR].hitag intensity 
				setvarvar hitag intensity 
				ifvarn target2 -1
				{
					getactor[target2].picnum picnum
					setactor[target2].picnum mtype
					setvarvar mtype picnum
				}
			} 
			else
			{
				setactor[THISACTOR].hitag 0 setvar hitag -1 
				ifvarn target2 -1
				{
					getactor[target2].picnum picnum
					setactor[target2].picnum mtype
					setvarvar mtype picnum
				}
			}
		}
	}
	ifvarn hitag -1
	{
		ifvarn myspawner -1
		{
			ifvare mtype APLAYER
			{
				ifoutside
				{
					setvarvar intensity outsideradius
					setvarvar xvel outsidered
					setvarvar yvel outsidegreen
					setvarvar zvel outsideblue
					setvarvar tempd outsidepriority
				}
				else
				{
					setvarvar intensity insideradius
					setvarvar xvel insidered
					setvarvar yvel insidegreen
					setvarvar zvel insideblue
					setvarvar tempd insidepriority
				}
				setactor[THISACTOR].hitag intensity
				setactor[THISACTOR].xvel xvel
				setactor[THISACTOR].yvel yvel
				setactor[THISACTOR].zvel zvel
			}
			else
			{
				getactorvar[myspawner].intensity intensity
				setactor[THISACTOR].hitag intensity
				getactor[myspawner].statnum temp
				ifvare temp 1024 killit
				getactor[myspawner].picnum temp
				ifvarvarn temp mtype killit
			}
				getactor[myspawner].x x
				getactor[myspawner].y y
				getactor[myspawner].z z
				ifvare mtype APLAYER subvar z 10240
			updatesectorz x y z mysector
			ifvarn mysector -1
			{
				changespritesect THISACTOR mysector
				getflorzofslope mysector x y mz
				getceilzofslope mysector x y digz
				setvarvar temp mz
				subvarvar mz z
				ifvarl mz 4096 
				{
					setvarvar z temp 
					subvar z 4096 
					ifvarvarl z digz setvarvar z digz
				}
			}
			
			setsprite THISACTOR x y z				
		}
		ifspritepal 1
		{
			ifvarl initshade 0 { mulvar temp -1 addvar temp 127 }
			
			addvar countvar 1
			ifvarg countvar 1
			{
				setvar countvar 0
				randvar temp 255
				addvar temp 1
				ifvarvarl temp initshade 
				{
					ifvare sprite[THISACTOR].hitag 0
					{
						setactor[THISACTOR].hitag hitag 
						ifvarn target2 -1
						{
							getactor[target2].picnum picnum
							setactor[target2].picnum mtype
							setvarvar mtype picnum
						}
					}
				}
				else
				{
					ifvarn sprite[THISACTOR].hitag 0
					{
						setactor[THISACTOR].hitag 0
						ifvarn target2 -1
						{
							getactor[target2].picnum picnum
							setactor[target2].picnum mtype
							setvarvar mtype picnum
						}
					}
				}
			}
			
		}
		else
		ifspritepal 2
		{
			setvarvar temp intensity // hitag
			subvarvar temp monstflags
			randvarvar tempb temp
			setvarvar tempc monstflags
			addvarvar tempc tempb
			setactor[THISACTOR].hitag tempc
		}
		else
		ifvarn monstflags 0 // pulsing light
		{
			// hitag the var is the max brightness
			// monstflags is the length of the cycle
			// shade is the time offset on the cycle
				
			// tempe at a time = peak deviation from mid-intensity value * sin ( (frequency * time) + offset value )
			
			setvarvar temp initshade
			setvarvar tempd timer
			addvarvar tempd temp 
			mulvarvar tempd monstflags // frequency * time
			sin tempe tempd
			mulvarvar tempe hitag
			shiftvarr tempe 14
			setactor[THISACTOR].hitag tempe
			
		}
	}
}
else
ifvare lotag 50 // spot light
{
	ifvarn activator 0
	{
		ifvare intensity 0 setvarvar intensity hitag
		checkactivatormotion activator	
		ifvare RETURN YES
		{
			ifvare hitag -1 
			{ 
				setactor[THISACTOR].hitag intensity setvarvar hitag intensity 
				ifvarn target2 -1
				{
					getactor[target2].picnum picnum
					setactor[target2].picnum mtype
					setvarvar mtype picnum
				}
			} 
			else
			{ 
				setactor[THISACTOR].hitag 0 setvar hitag -1 
				ifvarn target2 -1
				{
					getactor[target2].picnum picnum
					setactor[target2].picnum mtype
					setvarvar mtype picnum
				}
			}
		}
	}
	ifvarn hitag -1
	{
		ifvarn myspawner -1
		{
			getactorvar[myspawner].intensity intensity
			setactor[THISACTOR].hitag intensity
			
	// 		getactor[myspawner].statnum temp
	// 		ifvare temp 1024 killit
	// 		getactor[myspawner].picnum temp
	// 		ifvarvarn temp mtype killit
			ifvarg countvar 0
			{
				subvar countvar 1
				ifvare countvar 0 killit
			}
			else		
				setactor[THISACTOR].ang sprite[myspawner].ang
			
			getactor[myspawner].x x
			getactor[myspawner].y y
			getactor[myspawner].z z
			ifvare mtype APLAYER subvar z 8192
			ifvare mtype DUKEBIKE subvar z 6144
			updatesectorz x y z mysector
			ifvarn mysector -1
			{
				changespritesect THISACTOR mysector
				getflorzofslope mysector x y mz
				getceilzofslope mysector x y digz
				setvarvar temp mz
				subvarvar mz z
				ifvarl mz 4096 
				{
					setvarvar z temp 
					subvar z 4096 
					ifvarvarl z digz setvarvar z digz
				}
			}
			ifvare mtype DUKEBIKE
			{
				//getactorvar[myspawner].dukebikeANGOFF temp
				getactor[myspawner].angoff temp
				getactor[myspawner].ang angvar
				addvarvar angvar temp
				setactor[THISACTOR].ang angvar
				setvarvar mx x
				addvarvar mx 512
				rotatepoint x y mx y angvar x y
			}
			
			setsprite THISACTOR x y z	
		}
	}
}
else
ifvare lotag 88 // portal SE
{
	ifvare peractor1 0
	{
		checkactivatormotion activator
		ifvare RETURN YES setvar peractor1 1
	}
	else
	{
		ifpdistl 16384
		{
			ifcansee
			{
				ifvarn portalcam -1 ifvarvarn portalcam THISACTOR
				{
					findplayer xydist
					dist xydist2 portalcam player[THISACTOR].i
					ifvarvarl xydist xydist2
					{
						setvarvar portalcam myspawner
						setvar portalview 52
					}
				} 
				else
				{
					setvarvar portalcam myspawner
					setvar portalview 52
				}
			}
			else ifpdistl 4096
			{
				setvarvar portalcam myspawner
				setvar portalview 52
			}
		}
	}
	
}
else
ifvare lotag 89
{
	ifvare peractor1 0
	{
		checkactivatormotion activator
		ifvare RETURN YES setvar peractor1 1
	}
	else
	{
		ifvare monstatus 1 // player just teleported into your sector
		{
			ifvarvarn sprite[THISACTOR].sectnum player[THISACTOR].cursectnum
			setvar monstatus 0
		}
		else
		ifvarvare sprite[THISACTOR].sectnum player[THISACTOR].cursectnum
		{
			getactor[myspawner].x x
			getactor[myspawner].y y
			getactor[myspawner].z z
			getactor[myspawner].ang angvar
			getactor[myspawner].sectnum tempc
			setplayer[THISACTOR].posx x
			setplayer[THISACTOR].posy y
			setplayer[THISACTOR].posz z
			setplayer[THISACTOR].cursectnum tempc
			setplayer[THISACTOR].ang angvar
			addvar z 8192
			getplayer[THISACTOR].i spriteid
			setsprite spriteid x y z
			ifvarn target 0 globalsoundvar target
			setactorvar[myspawner].monstatus 1
			ifvarg sprite[THISACTOR].pal 0
			{
				ifspritepal 1 palfrom 63 10 10 55 else
				ifspritepal 2 palfrom 63 55 10 10 else
				ifspritepal 3 palfrom 63 63 63 63 else
				ifspritepal 4 palfrom 63 0 0 0 else
				ifspritepal 7 palfrom 63 50 50 0 else
				ifspritepal 8 palfrom 63 10 55 10
			}
		}
		
	}
	
}
else
ifvare lotag 90 // cutscene SE
{
	ifvare hitag 0
		setvarvar camerasprite THISACTOR
	else
	{
		checkactivatormotion hitag
		ifvare RETURN 1
			setvarvar camerasprite THISACTOR	
	}
	ifvarvare camerasprite THISACTOR
	{
		ifvarand monstflags 4 // move player to camera
		{
			getplayer[THISACTOR].i spriteid
			setsprite spriteid sprite[THISACTOR].x sprite[THISACTOR].y sprite[THISACTOR].z
			setplayer[THISACTOR].cursectnum sprite[THISACTOR].sectnum
			setplayer[THISACTOR].posx sprite[THISACTOR].x
			setplayer[THISACTOR].posy sprite[THISACTOR].y
			setplayer[THISACTOR].posz sprite[THISACTOR].z
		}
		setplayer[THISACTOR].knuckle_incs 0
		ifvarand monstflags 8 nullop else
		{
			setplayer[THISACTOR].on_crane 0
			setplayer[THISACTOR].posxv 0
			setplayer[THISACTOR].posyv 0
			getplayer[THISACTOR].i spriteid
			setactor[spriteid].htextra -1
			//ifvarand monstflags 2 nullop else setplayer[THISACTOR].over_shoulder_on YES
		}

		ifvare initx 0 setvar initx 130
		ifvare playerally 0 // stationary cam
		{
			ifvarand monstflags 16 addvar countvarb 1
			ifvare initx 0 setvar initx 130
			addvar countvar 1
			ifvarand monstflags 1
			{
				setvarvar temp initx
				subvarvar temp countvar
				ifvarl temp 22
				{
					mulvar temp 3
					setvar tempb 63
					subvarvar tempb temp
					setplayer[THISACTOR].pals 0 0
					setplayer[THISACTOR].pals 1 0
					setplayer[THISACTOR].pals 2 0
					setplayer[THISACTOR].pals_time tempb
				}
			}
			ifvarvarg countvar initx
			{
				setvar camerasprite -1
				ifvarn activator 0 state activatorstate
				ifvare camerasprite -1 
				{
					setplayer[THISACTOR].on_crane -1
					//setplayer[THISACTOR].over_shoulder_on NO
				}
				killit
			}
			
		}
		else
		{
			ifvare activator 0 { setvar camerasprite -1 setplayer[THISACTOR].on_crane -1 killit }
			ifvare myspawner -1
			{
				headspritestat spriteid 3
				whilevarn spriteid -1 // loop through the SEs
				{
					ifvare actorvar[spriteid].lotag 90
					ifvarvare activator actorvar[spriteid].hitag
					{ setvarvar myspawner spriteid setvar spriteid -1 }
					else
					nextspritestat spriteid spriteid
				}
				ifvare myspawner -1
				{
					setvar camerasprite -1
					setplayer[THISACTOR].on_crane -1
					//setplayer[THISACTOR].over_shoulder_on NO
					killit // no destination SE found
				}
			}
			ldist xydist THISACTOR myspawner
			ifvarvarn sprite[THISACTOR].shade sprite[myspawner].shade
			{
				setvarvar tempb xydist
				divvarvar tempb initx
				ifvarl tempb 26 // adjust z-axis view to next SE in last second
				{
					getactor[THISACTOR].shade shade
					getactor[myspawner].shade tempc
					subvarvar tempc shade
					divvar tempc 25
					ifvare tempc 0 
					{
						ifvarvarl shade sprite[myspawner].shade addvar shade 1
						else subvar shade 1
					}
					else addvarvar shade tempc
					setactor[THISACTOR].shade shade
				}
			}
			subvar xydist 1
			ifvarvarl xydist initx
			{
				state activatorstate
				setvarvar camerasprite myspawner
				killit
			}
			else
			{
				getactor[myspawner].z mz
				getactor[THISACTOR].z z
				setvarvar temp initx
				shiftvarl temp 3
				ifvarvarl z mz
				{
					addvarvar z temp
					ifvarvarg z mz setvarvar z mz
				}
				else
				ifvarvarg z mz
				{
					subvarvar z temp
					ifvarvarl z mz setvarvar z mz
				}
				getactor[myspawner].x mx
				getactor[myspawner].y my
				getactor[THISACTOR].x x
				getactor[THISACTOR].y y
				subvarvar mx x
				subvarvar my y
				getangle angvar mx my
				
				setvarvar tempb xydist
				divvarvar tempb initx
				getincangle tempd sprite[THISACTOR].ang sprite[myspawner].ang
				divvarvar tempd tempb
				addvarvar tempd sprite[THISACTOR].ang
				setactor[THISACTOR].ang tempd
				
				setvarvar mx x
				addvarvar mx initx // initx is the speed
				rotatepoint x y mx y angvar mx my
				setsprite THISACTOR mx my z
				
			}
		}
	}
	
}
else
ifvare lotag 102
{
	
	ifvare headunder 1
	{
		setsector[mysector].floorpal playerally
		setsector[mysector].ceilingpal playerally
	}
	else
	{
		setsector[mysector].floorpal pal
		setsector[mysector].ceilingpal peractor7
	}
	
	ifvare topladder 0 ifvarn monstflags 1
	{
		headspritesect spriteid mysector
		whilevarn spriteid -1
		{
			getactor[spriteid].picnum picnum
			ifvare picnum HEIGHTSPRITE
			{
				getactorvar[spriteid].lotag temp
				ifvare temp 1
				{
					getactor[spriteid].z z
					setvarvar topladder z
					ifvare topladder 0 setvar topladder 1
					getactorvar[spriteid].fallflag fallflag
					ifvarn fallflag 0
					{
						setvarvar peractor6 topladder
						addvarvar peractor6 fallflag
					}
					getactorvar[spriteid].peractor1 peractor1
				}
			}
			nextspritesect spriteid spriteid
		}
	}
	
	getactor[THISACTOR].z z
	ifvarn activator 0
	{
		ifvare mtype 0
		{
			setvarvar temp activator
			checkactivatormotion temp
			ifvare RETURN 1
			{
				ifvarvare z topladder setvar mtype -1 else setvar mtype 1
				ifvare hitag 1 setvar activator -1
			}
 			else ifvare peractor1 1
 			{
	 			setvar peractor1 0
 				ifvarvare z topladder setvar mtype -1 else setvar mtype 1
 				ifvare hitag 1 setvar activator -1
			}
		}
		ifvarn mtype 0 // activated
		{
			setvar peractor1 0
			setvarvar mz z
			ifvare mtype 1 
			{
				ifvarvare z topladder setvar mtype 0
				subvarvar mz topladder
			}
			else ifvare mtype -1
			{
				ifvarvare z initz setvar mtype 0
				subvarvar mz initz
			}
			// if mz > 0, move up, if mz < 0 move down
			ifvarn mtype 0
			{
				ifvarg mz 0
				{
					ifvarl mz 256 { subvarvar z mz setvar mtype 0 } else
					subvar z 256
					setactor[THISACTOR].z z
				} else
				ifvarl mz 0
				{
					ifvarg mz -256 { subvarvar z mz setvar mtype 0 } else
					addvar z 256
					setactor[THISACTOR].z z
				}
				headspritesect spriteid mysector
				whilevarn spriteid -1
				{
					getactor[spriteid].picnum picnum
					setvar temp 0
					ifvare picnum WATERTILE2 setvar temp 1
					ifvare picnum WATERFLOW setvar temp 1
					ifvare picnum DPWATERTILE setvar temp 1
					ifvare temp 1
					{
						setactor[spriteid].z z
						setactor[spriteid].statnum 1
					}
					nextspritesect spriteid spriteid
				}
			}	
		}
	} else
	ifvarn fallflag 0
	{
		ifvare mtype 0 setvar mtype -1
		setvarvar mz z
		ifvare mtype 1 // moving up
		{
			ifvarvarl z topladder setvar mtype -1
			else
			{
				subvarvar z peractor1
				setactor[THISACTOR].z z
			}
		}
		else ifvare mtype -1 // moving down
		{
			ifvarvarg z peractor6 setvar mtype 1
			else
			{
				addvarvar z peractor1
				setactor[THISACTOR].z z
			}
		}

		headspritesect spriteid mysector
		whilevarn spriteid -1
		{
			getactor[spriteid].picnum picnum
			setvar temp 0
			ifvare picnum WATERTILE2 setvar temp 1
			ifvare picnum WATERFLOW setvar temp 1
			ifvare picnum DPWATERTILE setvar temp 1
			ifvare temp 1
			{
 				setactor[spriteid].z z
				setactor[spriteid].statnum 1
			}
			nextspritesect spriteid spriteid
		}
				
	}
	headspritesect spriteid mysector
	whilevarn spriteid -1
	{
		ifvarvarn spriteid THISACTOR
		{
			setvar temp 0
			getactor[spriteid].z mz
			getactor[spriteid].picnum picnum
			ifvare picnum SHARK 
			{
				getactorvar[spriteid].monstatus tempb
				ifvare tempb 2 subvar mz 2048 else
				subvar mz 8192
			}
			ifvare picnum BOTALLY subvar mz 2048
			ifvare picnum BOTALLYCROUCH subvar mz 2048
			ifvare picnum APLAYER 
			{
				ifp pducking subvar mz 6144
			}
			ifvarvarg mz z setvar temp 1
			ifvare monstflags 1 setvar temp 1
			ifvare temp 1
			{
				getactor[spriteid].htflags tempb
				ifvarand tempb 128
				{
					xorvar tempb 128
					setactor[spriteid].htflags tempb
					setactorvar[spriteid].NOCODE 0
				}
				getactorvar[spriteid].underwater underwater
				ifvare underwater 0 
				{
					//getactor[spriteid].statnum temp
					//setvar tempb 0
					//setvar temp 1
					//ifvare temp 1 setvar tempb 1
					//ifvare temp 4 setvar tempb 1
					//ifvare temp 6 setvar tempb 1
					//ifvare temp 10 setvar tempb 1
					//ifvarg tempb 0
					ifvarn picnum WATERSPLASH3 ifvarn picnum NEWSPLASH
					ifvarn picnum WATERCIRCLE ifvarn picnum WATERTILE2
					ifvarn picnum DPWATERTILE
					ifvarn picnum WATERFLOW ifvarn picnum HEIGHTSPRITE
					ifvarg picnum 10
					{
						subvarvar mz z
						ifvarl mz 0 mulvar mz -1
						ifvarl mz 2048
						setactorvar[spriteid].underwater 5
						// 5 splash in
						else setactorvar[spriteid].underwater 3
						setactorvar[spriteid].watereffector THISACTOR
					}
				}
				else 
				{
					setactorvar[spriteid].underwater 3
					setactorvar[spriteid].watereffector THISACTOR
				}
			}
		}
		nextspritesect spriteid spriteid
	}
	setvar underwater 0

}
else
ifvare lotag 104 // texture panning
{
	// topladder 0 = floor only, 1 = ceiling only, 2 = floor and ceiling
	// initx xpanning
	// activator ypanning
	ifvarn topladder 1
	{
		// floor panning
		getsector[mysector].floorxpanning x
		addvarvar x initx
		setsector[mysector].floorxpanning x
		getsector[mysector].floorypanning y
		addvarvar y activator
		setsector[mysector].floorypanning y
	}
	ifvarn topladder 0
	{
		// ceiling panning
		getsector[mysector].ceilingxpanning x
		addvarvar x initx
		setsector[mysector].ceilingxpanning x
		getsector[mysector].ceilingypanning y
		addvarvar y activator
		setsector[mysector].ceilingypanning y
	}
} else
ifvare lotag 105
{
	// makes player sleep
	
	getplayer[THISACTOR].cursectnum temp
	ifvarvare temp mysector ifvare topladder 0
	{
		setvar temp 1
		ifvarand monstflags 8
		{
			ifangdiffl 768 setvar temp 0 else
			ifhitspace nullop else setvar temp 0
		}
		ifvare temp 1
		{
			ifvarn activator 0 soundvar activator
			addvar lotag 1
			setvar sleeping -130
			subvarvar sleeping initx
			getplayer[THISACTOR].i spriteid
			setactorvar[spriteid].hitag hitag
			setactorvar[spriteid].teleported lotag
			setactorvar[spriteid].peractor7 playerally
			setactorvar[spriteid].peractor5 monstflags
			getactor[THISACTOR].ang angvar
			addvar angvar 1024
			setactorvar[spriteid].peractor4 angvar
		}
	}
	
} else
ifvare lotag 107
{
	// transition effector
	getplayer[THISACTOR].cursectnum temp
	ifvarvare temp mysector
	{
		ifvare sleeping 0
		ifvarn mtype -1
		{
			setvar temp 1
			ifvarand monstflags 8
			{
				ifangdiffl 768 setvar temp 0 else
				ifhitspace nullop else setvar temp 0
			}			
			ifvare temp 1
			{
				ifvarn activator 0 soundvar activator
				setvar sleeping -130
				getplayer[THISACTOR].i spriteid
				ifvarl initx -1 setvar initx -1
				setactorvar[spriteid].fallflag initx
				setactorvar[spriteid].targetlock mysector
				setactorvar[spriteid].hitag hitag
				setactorvar[spriteid].teleported lotag
				setactorvar[spriteid].peractor7 playerally
				setactorvar[spriteid].peractor5 monstflags
				getactor[THISACTOR].ang angvar
				addvar angvar 1024
				setactorvar[spriteid].peractor4 angvar
			}
		}
	}
	else setvar mtype 0
} else
ifvarg lotag 115 ifvarl lotag 120
{
	
	// initshade = number of elevator positions
	// hitag = activation sound
	// initx = the distance (in z units) between floors
	// topladder = elevator speed (number of z units moved per tick)
	// make topladder negative and it will start by going down otherwise up
	
	// mtype is 0 when lift is stationary; -1 when moving up, 1 when moving down
	// position is the last position of elevator; starting position is 0
	// when the elevator goes up, position decreases, while going down increases it
	// initshade has already been set to the last position before reversing (negative or positive)
	ifvare mtype 0 // elevator is stationary
	{
		setvar tempb 0
		ifvarn peractor1 0 setvar tempb 1
		ifvare activator 0
		{
			ifhitspace
			ifp palive
			{
				getplayer[THISACTOR].cursectnum temp
				ifvarvare temp mysector
				setvar tempb 1
				else
				{
					ifvarvare nextsector mysector setvar tempb 1
				}
			}
		}
		ifvare tempb 1
		{
			soundvar hitag
			ifvarn peractor1 0
			{
				ifvare peractor1 2
				{
					ifvarg topladder 0 mulvar topladder -1
				}
				else ifvarl topladder 0 mulvar topladder -1
				setvar peractor1 0
				ifvarg topladder 0 setvar mtype 1 else setvar mtype -1
				ifvarg peractor2 0
				{
					ifvare position 0 ifvare mtype 1 setvar mtype 0
					ifvarvare position initshade ifvare mtype -1 setvar mtype 0
				}
				else
				{
					ifvare position 0 ifvare mtype -1 setvar mtype 0
					ifvarvare position initshade ifvare mtype 1 setvar mtype 0
				}
				ifvarn mtype 0
				{
					getsector[mysector].floorz target
					setvarvar temp initx
					mulvarvar temp mtype
					addvarvar target temp // target is now the destination z of next floor
					getsector[mysector].ceilingz target2
					addvarvar target2 temp // target2 is now the destination z of ceiling
				}
			}
			else
			{
				ifvarvare position initshade mulvar topladder -1 else
				ifvare position 0 mulvar topladder -1
				ifvarg topladder 0 setvar mtype 1 else setvar mtype -1
				getsector[mysector].floorz target
				setvarvar temp initx
				mulvarvar temp mtype
				addvarvar target temp // target is now the destination z of next floor
				getsector[mysector].ceilingz target2
				addvarvar target2 temp // target2 is now the destination z of ceiling
			}
			
		}
	}
	else
	{
		setvar peractor1 0
		getsector[mysector].floorz z
		setvarvar bouncesound z
		addvarvar z topladder
		setsector[mysector].floorz z
		setvarvar digz z
		subvar digz 2048
		setactor[THISACTOR].z digz
		
		 ifvarg lotag 117
		 {
			 getsector[mysector].ceilingz mz
			 addvarvar mz topladder
			 setsector[mysector].ceilingz mz
		 }
		
		subvarvar z target
		ifvarl z 0 mulvar z -1
		setvarvar tempb topladder
		ifvarl tempb 0 mulvar tempb -1
		ifvarvarl z tempb
		{
			setsector[mysector].floorz target
			ifvarg lotag 117 setsector[mysector].ceilingz target2
			subvarvar position mtype
			setvar mtype 0
			sound ELEVATOR_OFF
		}
		getsector[mysector].floorz z
		subvarvar z bouncesound
		
		getplayer[THISACTOR].cursectnum temp
		ifvarvare temp mysector ifp ponground
		{
			getplayer[THISACTOR].posz mz
			addvarvar mz z
			setplayer[THISACTOR].posz mz
		}
			
		headspritesect spriteid mysector
		whilevarn spriteid -1
		{
			getactor[spriteid].picnum picnum
			ifvarg picnum 10 ifvarn picnum WATERTILE2 ifvarn picnum WATERFLOW
			ifvarn picnum DPWATERTILE
			ifvarn picnum DNSWITCH ifvarn picnum UPSWITCH
			{
				getactor[spriteid].z mz
				addvarvar mz z
				setactor[spriteid].z mz
				setactor[spriteid].sectnum mysector
			}
			nextspritesect spriteid spriteid
		}
		
	}
	
}
else
ifvare lotag 666
{
	headspritesect spriteid mysector
	whilevarn spriteid -1
	{
		getactor[spriteid].picnum picnum
		setvar temp 0
		ifvare picnum APLAYER
		{
			getuserdef[THISACTOR].god tempb
			ifvare tempb NO
			{
				getactor[spriteid].yvel tempb
				getplayer[tempb].dead_flag tempc
				ifvare tempc 0 setvar temp 1
			}
		}
		else setvar temp 1
		ifvare temp 1
		{
			getactor[spriteid].z mz
			ifvarvarg mz initz
			{
				ifvarg topladder 0
				{
					subvarvar mz initz
					setvarvar tempb topladder
					shiftvarl tempb 3
					ifvarvarg mz tempb setvar temp 0
				}
				ifvare temp 1
				{
					setactor[spriteid].htextra 140
					setactor[spriteid].htpicnum RADIUSEXPLOSION
					setactor[spriteid].htowner spriteid
					getactor[spriteid].picnum picnum
					ifvare picnum SAWBLADEGROUND { setactor[spriteid].xrepeat 0 setactor[spriteid].yrepeat 0 }
				}
			}
		}
		nextspritesect spriteid spriteid
	}
}
else ifvare mirrored NO setvar NOCODE 1
	
break

case BATTERYAMMO
ifvare usemp5 YES cactor MP5CLIP
ifvare NOCODE 2 setvar NOCODE 1
break

case SHOTGUNSPRITE
ifvare usemossberg YES cactor CRUIZERSPRITE
ifvare NOCODE 2 setvar NOCODE 1
break

case CHAINGUNSPRITE
ifvarand monstflags 1 nullop else
ifvare usemp5 YES cactor MP5SPRITE
ifvare NOCODE 2 setvar NOCODE 1
break

case 908 case 910 // tree

ifvarn lotag 0 setactor[THISACTOR].cstat initcstat
ifvare NOCODE 2 setvar NOCODE 1
break

case SEENINE
case FIREEXT
case OOZFILTER
ifvare hitag 0 changespritestat THISACTOR 1
ifvare NOCODE 2 setvar NOCODE 1
// getactor[THISACTOR].statnum tempb
// ifvarn tempb 1
// {
// 	getactor[THISACTOR].cstat temp
// 	ifvarand temp 1 ifvare hitag 0
// 	{
// 		state pickupcode2
// 		ifvarvare holding THISACTOR
// 		{
// 			changespritestat THISACTOR 1
// 			ifvare NOCODE 2 setvar NOCODE 1
// 		}

// 	}
// }
break

case TOILET
case HYDRENT
getactor[THISACTOR].statnum tempb
ifvarn tempb 1
{
	state gravpickupcode
	ifvarvare gravitysprite THISACTOR
	{
		spawn TOILETWATER
		sound VENT_BUST
		changespritestat THISACTOR 1
		ifactor TOILET 
		{
			cactor TOILET2
			action TOILETFRAME
		}
		ifactor HYDRENT
		{
			cactor HYDRENT2
			action HYDRENTFRAME
		}
		strength 10
		
		setvar NOCODE 1
	}
}
break

case QUOTER

ifvarg lotag 3
{
	checkactivatormotion lotag
	ifvare RETURN 1
	{
		setvar mtype 1
		setvar lotag 1
		changespritestat THISACTOR 1
		setvarvar quoterid THISACTOR
	}
}
					
break

case HELICOPTER
case BLACKHAWK
ifvarn lotag 0
	changespritestat THISACTOR 1
break

case CANWITHSOMETHING
case CANWITHSOMETHING2
case CANWITHSOMETHING3
case CANWITHSOMETHING4
case VASE
case BOTTLE1
case BOTTLE2
case BOTTLE3
case BOTTLE4
case BOTTLE5
case BOTTLE6
case BOTTLE7
case BOTTLE8
case BOTTLE10
case BOTTLE11
case BOTTLE12
case BOTTLE13
case BOTTLE14
case BOTTLE15
case BOTTLE16
case BOTTLE17
case BOTTLE18
case BOTTLE19
case CHAIR1
case CHAIR2
case CHAIR3
case BROKENCHAIR
case CAMERALIGHT
case TRIPODCAMERA
case VACUUM
case IVUNIT
case MOVIECAMERA
case FETUS
case FETUSBROKE
case 691
case 692
case 693
case POT1
case POT2
case POT3
case SUSHIPLATE1
case SUSHIPLATE2
case SUSHIPLATE3
case SUSHIPLATE4
case SUSHIPLATE5
case CONE
case BOX

ifvarn sprite[THISACTOR].statnum 1
{
	getactor[THISACTOR].cstat temp
	ifvarand temp 16 setvar NOCODE 1 else
	ifvarand temp 32 setvar NOCODE 1 else
	{
		//changespritestat THISACTOR 1
		//setvar NOCODE 1
		state pickupcode2
		ifvarvare holding THISACTOR
		{
			changespritestat THISACTOR 1
			ifvare NOCODE 2 setvar NOCODE 1
		}
		ifvarn underwater 0
		{
			changespritestat THISACTOR 1
			ifvare NOCODE 2 setvar NOCODE 1
		}
		
	}
}
break

case FOOTPRINTS
case FOOTPRINTS2
case FOOTPRINTS3
case FOOTPRINTS4
ifspritepal 13 
{
	addvar countvar 1
	ifvarg countvar 780
	cstator 2
	ifvarg countvar 2340
	cstator 512
} else setvar NOCODE 1
break

case DPTOUCHPLATE

ifvarn droptile 0
{
	checkactivatormotion droptile
	ifvare RETURN 1 setvar droptile 0
}

ifvarn lotag 0 ifvarn activator 0
ifvare droptile 0
ifvarvare player[THISACTOR].cursectnum mysector
{
	setvar tempb 1
	ifvarand monstflags 1
	ifp phigher setvar tempb 0
	ifvare tempb 1 { state activatorstate setvar activator 0 }
}

break

case LIGHTSOURCEPROJ
setthisprojectile[THISACTOR].pal pcolor
ifvarg flicker 0
{
//	setvar lightidle 40
	setvarvar temp peractor7
	mulvarvar temp flicker
	divvar temp 100 // temp is now the random component of the intensity
	randvarvar intensity temp
	// now add the base component
	setvarvar tempb peractor7
	subvarvar tempb temp // base is what is left after subtracting max flickering amount
	addvarvar intensity tempb
}
break

case WAYPOINT
// setactor[THISACTOR].x initx
// setactor[THISACTOR].y inity
// setactor[THISACTOR].z initz
setsprite THISACTOR initx inity initz
break

case OOZ
case OOZ2
ifoutside killit else
ifspawnedby JIBS2 killit else
setvar NOCODE 1
break

case NEWSCRAP1
case NEWSCRAP2
case NEWSCRAP3
case NEWSCRAP4
case NEWSCRAP5
case NEWSCRAP6
getactor[THISACTOR].pitch temp
addvar temp 16
setactor[THISACTOR].pitch temp
addvar countvar 1
break

case SPARKPROJ  
addvar countvar 1
ifvarg countvar 5 sizeat 2 2
ifvarg countvar 12 sizeat 1 1
break


case CAMERA1

getplayer[THISACTOR].newowner temp
ifvarn temp -1
ifvarn viewmode 0
{
	setvar tolerance CAMTOLERANCE1
	setvar viewcam -1
	setvar nextcam -1
	setvar distlock -1
}
ifvarvare temp THISACTOR
{
	
	ifvarg underwater 0 ifvarn watereffector -1
	{
		getactor[watereffector].pal waterpal
		ifvare waterpal 32
		palfrom 52 0 3 6 // very dark water
		else
	    ifvare waterpal 31
	    palfrom 36 0 5 10 // dark water
	    else
	    ifvare waterpal 27 // red liquid
	    palfrom 36 30
	    else
	    ifvare waterpal 28 // green liquid
	    palfrom 36 0 30
	    else
	    ifvare waterpal 29 // blue liquid
	    palfrom 36 0 0 30
	    else
	    palfrom 18 0 25 35 // normal water
	}

	ifvarand monstflags 1
	{
		getinput[THISACTOR].extbits tempb
		ifvarand tempb 16 // If the player presses 'turn left'
		{
			getactor[THISACTOR].ang tempc
			subvar tempc 16
			setactor[THISACTOR].ang tempc
		}
		ifvarand tempb 32 // If the player presses 'turn right'
		{
			getactor[THISACTOR].ang tempc
			addvar tempc 16
			setactor[THISACTOR].ang tempc
		}
		getinput[THISACTOR].bits tempb
		ifvarand tempb 8192 // Look up
		{
			getactor[THISACTOR].shade tempc
			ifvarl tempc 124
			{
				addvar tempc 4
				setactor[THISACTOR].shade tempc
			}
		}
		ifvarand tempb 16384 // Look down
		{
			getactor[THISACTOR].shade tempc
			ifvarg tempc -128
			{
				subvar tempc 4
				setactor[THISACTOR].shade tempc
			}
		}
	}
}
break

case FOLLOWCAM


ifvarvarn THISACTOR viewcam
{
	getactor[THISACTOR].z mz
	state getceilz
	subvarvar mz z
	ifvarl mz 3072
	movesprite THISACTOR 0 0 2048 CLIPMASK0 RETURN
	else
	{
		getactor[THISACTOR].z mz
		getplayer[THISACTOR].posz digz
		subvarvar digz mz
		ifvarl digz 6144
		{
			subvarvar mz z
			ifvarg mz 5120
			movesprite THISACTOR 0 0 -2048 CLIPMASK0 RETURN
		}
		else
		ifvarg digz 16384
			movesprite  THISACTOR 0 0 2048 CLIPMASK0 RETURN
	}
}

state checkpview
ifvarl countvarb KILLCAM 
ifpdistl 6144 // 10240
ifvare player[THISACTOR].over_shoulder_on YES
{
	ifvare viewcam -1 
	{
		setvarvar temp THISACTOR
		state pview2
		ifvare tempd 1
		{
			setvarvar viewcam THISACTOR
			setvar distlock -1 
			ifvarvare nextcam THISACTOR setvar nextcam -1 
		}
	}
	else ifvarvarn viewcam THISACTOR
		ifvare nextcam -1 setvarvar nextcam THISACTOR				
}
else
{
	ifvarvare viewcam THISACTOR
	{
		setvar tolerance CAMTOLERANCE1
		setvar viewcam -1
		setvar distlock -1 
		ifvarn nextcam -1
		{
			setvarvar temp nextcam
			state pview2
			ifvare tempd 1
			{
				setvarvar viewcam nextcam 
				setvar nextcam -1
				killit
			}
		}
	}
	ifvarvare nextcam THISACTOR
		setvar nextcam -1	
}
ifvarvarn viewcam THISACTOR ifvarvarn nextcam THISACTOR killit

setvar temp 0
ifvare viewmode NO setvar temp 1
ifvare player[THISACTOR].over_shoulder_on NO setvar temp 1
ifvarn ONCAR 0 setvar temp 1
ifvarn player[THISACTOR].newowner -1 setvar temp 1
ifvarn camerasprite -1 setvar temp 1
ifvare temp 1
{
	setvar viewcam -1
	setvar nextcam -1
	setvar distlock -1
	killit
}

break

case WATERTILE2
case WATERFLOW
case DPWATERTILE

getactor[THISACTOR].cstat temp
ifvarand temp 32
{
	// setvar monstatus 1
// 	getplayer[THISACTOR].i spriteid
// 	getactorvar[spriteid].underwater tempb
// 	ifvarg tempb 0
// 	{
// 		ifvarand temp 256 { subvar temp 256 setactor[THISACTOR].cstat temp }
// 	}
// 	else
// 	{
// 		getplayer[THISACTOR].curr_weapon tempb
// 		ifvarg tempb 3
// 		{
// 			ifvarand temp 256 { subvar temp 256 setactor[THISACTOR].cstat temp }
// 		}
// 		else
// 		{
// 			orvar temp 256
// 			setactor[THISACTOR].cstat temp
// 		}
// 	}
	ifactor WATERTILE2 ifvare rendmode 4 cactor DPWATERTILE
	ifvarvarg sprite[THISACTOR].z player[THISACTOR].posz
	{
		orvar temp 256
 		setactor[THISACTOR].cstat temp
 	}
	else
	{
		ifvarand temp 256 { subvar temp 256 setactor[THISACTOR].cstat temp }
 	}
	
}

break

case DIPSWITCH
case DIPSWITCH2
case DIPSWITCH3
case TECHSWITCH
case ALIENSWITCH
case FRANKENSTINESWITCH
ifvare pal 66 { setactor[THISACTOR].pal 66 setvar pal 0 }
ifvare goggleswitches YES
{
	getplayer[THISACTOR].heat_on temp
	ifvare temp 1
	{
		getactor[THISACTOR].hitag hitag
		ifvare hitag 1 setactor[THISACTOR].pal 6
		else setactor[THISACTOR].pal pal
	}
	else setactor[THISACTOR].pal pal
}
ifvarn activator 0
{
	ifvarvarn command picnum state activatorstate
	getactor[THISACTOR].picnum command
	getactor[THISACTOR].htpicnum temp
	ifvare temp SHOTSPARK1 { state activatorstate setactor[THISACTOR].htpicnum -1 }
}
setactor[THISACTOR].htflags 256

		
break

case 163 case 165 case 167 case 169
case 1143 case 141
ifvare pal 66 { setactor[THISACTOR].pal 66 setvar pal 0 }
ifvare goggleswitches YES
{
	getplayer[THISACTOR].heat_on temp
	ifvare temp 1
	{
		getactor[THISACTOR].hitag hitag
		ifvare hitag 0 setactor[THISACTOR].pal 6
		else setactor[THISACTOR].pal pal
	}
	else setactor[THISACTOR].pal pal
}
ifvarn activator 0
{
	ifvarvarn command picnum state activatorstate
	getactor[THISACTOR].picnum command
	getactor[THISACTOR].htpicnum temp
	ifvare temp SHOTSPARK1 { state activatorstate setactor[THISACTOR].htpicnum -1 }
}
setactor[THISACTOR].htflags 256
break

case SLOTDOOR case 133
case LIGHTSWITCH case 135
case SPACEDOORSWITCH case 137
case SPACELIGHTSWITCH case 139
case NUKEBUTTON
case MULTISWITCH case 147 case 148 case 149
case LIGHTSWITCH2 case 713
case POWERSWITCH1 case 861
case LOCKSWITCH1 case 863
case POWERSWITCH2 case 865
case HANDSWITCH case 1112
case PULLSWITCH case 1123
case HANDPRINTSWITCH
ifvare pal 66 { setactor[THISACTOR].pal 66 setvar pal 0 }
ifvarn activator 0
{
	ifvarvarn command picnum state activatorstate
	getactor[THISACTOR].picnum command
}
setactor[THISACTOR].htflags 256
break

case ACCESSSWITCH case 131
case ACCESSSWITCH2 case 171
ifvare pal 66 { setactor[THISACTOR].pal 66 setvar pal 0 }
ifvarn activator 0
{
	ifvarvarn command picnum state activatorstate
	getactor[THISACTOR].picnum command
}
ifvarn myspawner -1
{
	getplayer[THISACTOR].zoom temp
	ifvarg temp 1024 setvar temp 1024
	setvar tempb 1024
	subvarvar tempb temp
	shiftvarr tempb 2
	addvar tempb 40
	ifvarg tempb 255 setvar tempb 255
	setactor[THISACTOR].xrepeat tempb
	setactor[THISACTOR].yrepeat tempb
	getactor[myspawner].picnum picnum
	setactor[THISACTOR].picnum picnum
}
break

case APLAYER
ifvarg monstatus 8 // HOLODUKE HOLOGRAM
{
  ifvare monstatus 9
  {
		findplayer xydist
		ifvarg xydist 1280
		{
			addvar countvar 1
			ifvarg countvar 25
			{
				setvar countvar 0
				findnearactorz SHOOTME 1024 10240 spriteid
				ifvarn spriteid -1
				{
					spawn ELECTROSPAWN
					getplayer[THISACTOR].holoduke_amount temp
					subvar temp 120
					ifvarl temp 24 setvar temp 24
					setplayer[THISACTOR].holoduke_amount temp
				}
				
			}
		}
	}
	ifvare monstatus 10
	{
		espawn BOTALLY
		randvar pal 3
		ifvare pal 0 setactor[RETURN].pal 16 else
		ifvare pal 1 setactor[RETURN].pal 22 else
		ifvare pal 2 setactor[RETURN].pal 23 else
		//ifvare pal 3 setactor[RETURN].pal 10 else
		//ifvare pal 4 setactor[RETURN].pal 21 else
		ifvare pal 3 setactor[RETURN].pal 12
		setactor[RETURN].htpicnum APLAYER
		setplayer[THISACTOR].holoduke_on -1
		getplayer[THISACTOR].holoduke_amount temp
		subvar temp 1200
		ifvarl temp 0 setvar temp 0
		setplayer[THISACTOR].holoduke_amount temp
		killit
	}
}
else
state dukebikecode
break

case BOTALLY
case BOTALLYCROUCH
ifvare monstatus 1 sleeptime -1
ifvarand morefx 32 setactor[THISACTOR].mdflags 1
break


case BONUSRING
case CORONA1
case CORONA2
case CORONA3
// case BOTMARKER
case SPAWNER
// case LIGHTSOURCE
case GUSTSPAWNER
case DNSWITCH
case UPSWITCH
sleeptime -1
setvar NOCODE 1
break

case NOISESPRITE
ifvarn activator 0
{
	checkactivatormotion activator
	ifvare RETURN YES
	{
		changespritestat THISACTOR 1
		setvar activator 0
		setvar mtype 1
	}
}
break

	

case SHOOTER
ifvare mtype 0 sleeptime -1
break


case LADDER
ifvare monstflags 1
{
	ifvare monstatus 0
	{
		setvar monstatus 1
		setvar temp 0
		whilevarn temp 16384
		{
			getactor[temp].picnum picnum
			ifvare picnum LADDER ifvarvarn temp THISACTOR
			{
				getactorvar[temp].monstflags tempb
				ifvare tempb 1 // it is another ladder, not just a letter
				{
					getactorvar[temp].hitag tempc
					ifvarvare hitag tempc // it is the other of the pair
					{
						setvarvar myspawner temp
						setvar monstatus 1
						setvar temp 16383 // we can stop the loop now
						getactor[THISACTOR].z z
						getactor[myspawner].z mz
						ifvarvarg z mz 
						{
							setvar mtype 1 // the bottom of the ladder
							setvarvar topladder mz
						}
					}
				}
			}
			addvar temp 1
		}
	}
	ifvare mtype 1 ifvare dodge 0
	{
		getplayer[THISACTOR].posz mz
		ifp pducking subvar mz 4096
		getactor[THISACTOR].z z
		ifvarvarg mz topladder ifvarvarl mz z
		{
			getplayer[THISACTOR].i target
			ldist xydist THISACTOR target

			ifangdiffl 384 ifvarl xydist 384 // 192 512
			{
				ifvare onladder 0
				{
					getplayer[THISACTOR].posx lastladderx
					getplayer[THISACTOR].posy lastladdery
				}
				setvar onladder 3
				ifvarn lotag 0 setvarvar laddersound lotag else setvar laddersound -1
			}
		}
	}	
}
break

case TEMPSPRITE

ifvarn lotag 0
{
	ifvare peractor1 0 
	{
		ifvare hitag 0 setvar peractor1 1
		else
		{
			setvarvar temp hitag
			checkactivatormotion temp
			ifvare RETURN 1 setvar peractor1 1
		}
	}
	else
	ifvare peractor1 1 // activated
	{
		getactor[THISACTOR].mdflags temp
		orvar temp 16
		setactor[THISACTOR].mdflags temp
		setactor[THISACTOR].cstat initcstat
	}
	else killit
}

break

case GREENSLIME
ifvarand morefx 32 setactor[RETURN].mdflags 1
break

case ROTATEGUN
ifvare mtype 1
{
	setactor[THISACTOR].xrepeat hitx
	setactor[THISACTOR].yrepeat hity
	setvar NOCODE 1
}
break

case RECON

ifvare monstatus 0
{
	ifvare smartmonsters YES cactor RECONDP else
	{
		setvar monstatus 1
		espawn SHOOTME
		setactorvar[RETURN].myspawner THISACTOR
	}
}
addvar target2 1
ifvarg target2 25
{
	setvar target2 0
	espawn SHOOTME
	setactorvar[RETURN].myspawner THISACTOR
}
state recontilt
 
break

case SAWBLADEPROJ

	cstat 514
	spawn FRAMEEFFECT1
	cstat 0
	getactor[THISACTOR].zvel zvel
    divvar zvel 50
    setactor[THISACTOR].pitch zvel
    getactor[THISACTOR].yvel temp
    ifvarvarl temp countvar
    {
	    state sparkstate
		getactor[THISACTOR].xvel tempb
		mulvar tempb 3
		shiftvarr tempb 2
		setactor[THISACTOR].xvel tempb
		getactor[THISACTOR].zvel tempb
		mulvar tempb 3
		shiftvarr tempb 2
		setactor[THISACTOR].zvel tempb
		getthisprojectile[THISACTOR].drop temp
		subvar temp 24
		setthisprojectile[THISACTOR].drop temp
    }
    setvarvar countvar temp
    
break

case ICESHARD
getactor[THISACTOR].xvel xvel
subvar xvel 8
ifvarl xvel 256 setvar xvel 256
setactor[THISACTOR].xvel xvel
getactor[THISACTOR].zvel zvel
shiftvarl zvel 4
divvarvar zvel xvel
setactor[THISACTOR].pitch zvel
break

case DPCANNONBALL
addvar countvar 1
ifvare countvar 2 spawn NEWSMOKE
ifvare countvar 3 cstat 257
ifoutside
{
	getactor[THISACTOR].sectnum mysector
	getactor[THISACTOR].zvel zvel
	ifvarn mysector -1 ifvarl zvel 0
	{
		divvar zvel -4
		ifvarn zvel 0
		{
			getactor[THISACTOR].x x
			getactor[THISACTOR].y y
			getactor[THISACTOR].z z
			getceilzofslope mysector x y mz // z is the return var
			subvarvar z mz
			divvarvar z zvel
			ifvarl z 4 ifawayfromwall // 2
			{
				setvar peractor1 2
				killit
			}
		}
	}
}
getactor[THISACTOR].htmovflag hitwall
andvar hitwall 49152
ifvare hitwall 32768
killit
break

case RAILSLUG_WEAK
getactor[THISACTOR].cstat temp
ifvarand temp 8 xorvar temp 8 else orvar temp 8
setactor[THISACTOR].cstat temp
break

case POWBALL
espawn POWBALLINNER
setactor[RETURN].cstat 128
setactor[RETURN].xrepeat 40
setactor[RETURN].yrepeat 40
espawn POWBALLOUTER
setactor[RETURN].cstat 642
setactor[RETURN].xrepeat 40
setactor[RETURN].yrepeat 40
ifvarg sprite[THISACTOR].yvel 1
setactor[THISACTOR].yvel 1
break

case RPG
case RPGNOAIM

ifvare peractor1 -1 killit
ifvarl framerate 20 setactor[THISACTOR].htflags 256

ifvare weap 1 
{
	state randtraj
	getactor[THISACTOR].zvel zvel
    divvar zvel 50
    setactor[THISACTOR].pitch zvel
    setthisprojectile[THISACTOR].extra 16
}

ifvarg highglass -1
{
	setvarvar spriteid THISACTOR
	state projectilehitscan
	ifvarn hitsprite -1
	{
		getactor[hitsprite].picnum temp
		ifvare temp GLASS
		{
			state pythagoras
			ifvarl xydist 1024
			{
				setactor[hitsprite].htextra 60
				setactor[hitsprite].htpicnum RPG
				setactor[hitsprite].htowner THISACTOR
			}
		}
	}
}

espawn ROCKETHALO
setactorvar[RETURN].myspawner THISACTOR


ifoutside
{
	getactor[THISACTOR].sectnum mysector
	getactor[THISACTOR].zvel zvel
	ifvarn mysector -1 ifvarl zvel 0
	{
		divvar zvel -4
		ifvarn zvel 0
		{
			getactor[THISACTOR].x x
			getactor[THISACTOR].y y
			getactor[THISACTOR].z z
			getceilzofslope mysector x y mz // z is the return var
			subvarvar z mz
			divvarvar z zvel
			ifvarl z 2 ifawayfromwall 
			{
				setvar peractor1 2
				killit
			}
		}
	}
}

ifspawnedby BOSS3 ifvarl countvar 2
{
	addvar countvar 1
	ifvare countvar 2
	{
		getactor[THISACTOR].owner temp
		getactor[temp].pal pal
		ifvarn pal 0 
		{
			setactor[THISACTOR].xrepeat 14
			setactor[THISACTOR].yrepeat 14
			getactor[THISACTOR].extra temp
			divvar temp 4
			setactor[THISACTOR].extra temp
		}
	}
}

setvarvar spriteid THISACTOR
state projectilehitscan
ifvarn hitsprite -1
{
	getactor[hitsprite].picnum picnum
	ifvare picnum COMMANDER
	{
		getactorvar[hitsprite].monstflags temp
		ifvarand temp 2048
		{
			getactorvar[hitsprite].peractor6 peractor6
			getactorvar[hitsprite].botdodge botdodge
			getactorvar[hitsprite].weapcount weapcount
			ifvare peractor6 0 ifvare botdodge 0 ifvarn weapcount -1
			{
				getactor[hitsprite].x mx
				getactor[hitsprite].y my
				getactor[THISACTOR].x x
				getactor[THISACTOR].y y
				subvarvar mx x
				subvarvar my y
				getangle angvar mx my
				ifrnd 128 addvar angvar 512 else subvar angvar 512
				setactorvar[hitsprite].peractor5 angvar
				setactorvar[hitsprite].botdodge 16
				ifspawnedby APLAYER
				setactorvar[hitsprite].weapcount 1
			}
		}
	}
}
break

case COOLEXPLOSION1

getactor[THISACTOR].statnum temp
ifvare temp 4
{
	getactor[THISACTOR].htmovflag spriteid
	ifvarn spriteid 0
	{
		// hit something
		addvar spriteid 16384
	    ifvarl spriteid 16384 ifvarg spriteid -1 
	    {
	        // hit a sprite
	        getactorvar[spriteid].playerally playerally
	        ifvarn playerally 0
	        {
		        setactor[spriteid].htextra COOL_EXPLOSION_STRENGTH
				setactor[spriteid].htpicnum COOLEXPLOSION1
				setactor[THISACTOR].xrepeat 0
				setactor[THISACTOR].yrepeat 0
				killit
			}
	    }
    }
	
}
break

// case NATURALLIGHTNING
// addvar countvar 1
// getactor[THISACTOR].cstat temp
// ifvarand temp 32768 
// { ifvare lighting YES ifvarn intensity 0  ifvarg countvar 4 state exitlightarray } 
// else 
// {
// 	ifvare lighting YES 
// 	{
// 		ifvare intensity 0
// 		{
// 			setvar countvar 0
// 			setvar intensity 300
// 			state enter_light_array
// 		}
// 	}
// 	else
// 	{
// 		getactor[THISACTOR].z initz
// 		getplayer[THISACTOR].posz z
// 		setactor[THISACTOR].z z
// 		ifcansee flash
// 		setactor[THISACTOR].z initz
// 	}
// }
// break

case FIREBALLPROJ
ifvarand timer 1
{
	getactor[THISACTOR].cstat temp
	ifvare temp 384 setvar temp 388 else
	ifvare temp 388 setvar temp 392 else
	ifvare temp 392 setvar temp 396 else
	setvar temp 384
	setactor[THISACTOR].cstat temp
}
ifvarn target -1
state guideit
break

case FIREBULLET
ifaction FBF1 action FBF2 else
ifaction FBF2 action FBF3 else
ifaction FBF3 action FBF4 else
action FBF1
ifvare countvar 0
{
	getactor[THISACTOR].yvel temp
	ifvarl temp 3 // bounced once
	{
		// setvar NOCODE 1
		setvar countvar 1
		setthisprojectile[THISACTOR].workslike 34822
		setthisprojectile[THISACTOR].drop -100
	}
}
break

case ELECTROPROJ
setvar temp 0
ifrnd 128 orvar temp 4
ifrnd 128 orvar temp 8
setactor[THISACTOR].cstat temp
break

case SHELL
case SHOTGUNSHELL
ifactor SHOTGUNSHELL ifvare usemossberg YES
{
	getactor[THISACTOR].cstat temp
	ifvarand temp 32768
	{
		addvar countvar 1
		ifvarg countvar 6
		{
			setactor[THISACTOR].cstat initcstat 
			setvar countvar 0
		}
	}
}
state getfloorz
getactor[THISACTOR].z mz
subvarvar z mz
ifvarl z 512
{
	getactor[THISACTOR].statnum tempb
	ifvarn tempb 1
	{
		ifactor SHELL cactor 2534
		ifactor SHOTGUNSHELL cactor SSHELLGROUND
		changespritestat THISACTOR 1
		setvar NOCODE 1
	}
}

ifspritepal 30 // reverses shell direction when fired from left pistol (DeeperThought akimbo)
{
	spritepal 0
	getactor[THISACTOR].ang temp
	addvar temp 1024
	setactor[THISACTOR].ang temp
}
break

case HEADJIB1
case ARMJIB1
case LEGJIB1
case LIZMANHEAD1
case LIZMANARM1
case LIZMANLEG1

ifvare mtype 0
{
	getactor[THISACTOR].pitch temp
	addvarvar temp peractor1
	setactor[THISACTOR].pitch temp
	getactor[THISACTOR].roll temp
	addvarvar temp peractor1
	setactor[THISACTOR].roll temp
	ifrnd 32 state random_wall_jibs

	state checkfloordist
	ifvarl temp 2048
	{
		setvar mtype 1
		setvar NOCODE 1
		getactor[THISACTOR].picnum picnum
		addvar picnum 1
		espawnvar picnum
		setactor[RETURN].xrepeat sprite[THISACTOR].xrepeat
		setactor[RETURN].yrepeat sprite[THISACTOR].yrepeat
		setactor[RETURN].pal sprite[THISACTOR].pal
		ifrnd 64 { ifrnd 128 sound JIBLAND else sound JIBLAND2 }
		ifvare peractor1 1 { ifrnd 128 espawn BURNING else espawn BURNING2 setactorvar[RETURN].peractor1 1 }
		setvar NOCODE 1
	}

}
break

case PIGHEAD
case PIGUPPER
case PIGUPPER2
case PIGLOWER
case PIGLOWER2

	getactor[THISACTOR].pitch temp
	addvarvar temp peractor1
	setactor[THISACTOR].pitch temp
	getactor[THISACTOR].roll temp
	addvarvar temp peractor1
	setactor[THISACTOR].roll temp
	
state random_wall_jibs

ifvare countvar 0
{
	ifrnd 128 cstator 4
	ifspritepal 1 
	{ 
		setthisprojectile[THISACTOR].trail -1 
		setvar mtype -1 
	}
}

addvar countvar 1
addvar countvarb 1
ifvare countvarb 26 setthisprojectile[THISACTOR].trail -1

	getactor[THISACTOR].yvel tempb
	ifvare tempb 1
	{
		getactor[THISACTOR].picnum picnum
		addvar picnum 1
		setactor[THISACTOR].picnum picnum
		setactor[THISACTOR].statnum 1
		setactor[THISACTOR].zvel 0
		setactor[THISACTOR].pitch 0
		setactor[THISACTOR].roll 0
		ifspritepal 1 soundonce GLASSCRACKSND else
		ifrnd 128 soundonce JIBLAND else soundonce JIBLAND2
	}
break

case JIBSPROJ1
case JIBSPROJ2
case JIBSPROJ3
case JIBSPROJ4
case JIBSPROJ5

case LIZMANHEADPROJ
case LIZMANARMPROJ
case LIZMANLEGPROJ

case TROOPHEADPROJ
case TROOPARMPROJ
case TROOPLEGPROJ

ifvare sprite[THISACTOR].statnum 4
{
	getactor[THISACTOR].pitch temp
	addvarvar temp peractor1
	setactor[THISACTOR].pitch temp
	getactor[THISACTOR].roll temp
	addvarvar temp peractor1
	setactor[THISACTOR].roll temp

	ifvare countvar 0
	{
		ifrnd 128 cstator 4
		ifspritepal 1 
		{
			setthisprojectile[THISACTOR].trail -1 
			setvar mtype -1 
		}
// 		ifvarl framerate 20
// 		{
// 			setthisprojectile[THISACTOR].trail -1 
// 			setvar mtype -1 
// 		}
	}

	addvar countvar 1
	addvar countvarb 1
	ifvare countvarb 26 setthisprojectile[THISACTOR].trail -1
	ifvarg countvar 3
	{
		ifaction JIBSPROJFRAME1 action JIBSPROJFRAME2 else
		ifaction JIBSPROJFRAME2 action JIBSPROJFRAME3 else
		ifaction JIBSPROJFRAME3 action JIBSPROJFRAME4 else
		action JIBSPROJFRAME1
		setvar countvar 0
		
		ifactor JIBSPROJ1
		{
			ifaction JIBSPROJFRAME1 cstat 128 else
			ifaction JIBSPROJFRAME2 cstat 132 else
			ifaction JIBSPROJFRAME3 cstat 140 else
			ifaction JIBSPROJFRAME4 cstat 136
			else action JIBSPROJFRAME1
		}
	}
	ifspritepal 1 ifvarg sprite[THISACTOR].yvel 2 spawn NEWSMOKE // lotsofglass 1
	state random_wall_jibs
}
break

case JIBS1
case JIBS2
case JIBS3
case JIBS4
case JIBS5
ifvare mtype 0
{
	ifspritepal 0 ifspawnedby EGG spritepal 6
	getactor[THISACTOR].pitch temp
	addvarvar temp peractor1
	setactor[THISACTOR].pitch temp
	getactor[THISACTOR].roll temp
	addvarvar temp peractor1
	setactor[THISACTOR].roll temp
// 	ifspritepal 1 spawn NEWSMOKE else
// 	{
// 		ifrnd 32 state random_wall_jibs
// 	}
// 	state checkfloordist
// 	ifvarl temp 2048
// 	{
// 		getactor[THISACTOR].picnum picnum
// 		setvar mtype 1
// 		setvar NOCODE 1
// 		addvar picnum 4
// 		espawnvar picnum
// 		getactor[THISACTOR].xrepeat x
// 		setactor[RETURN].xrepeat x
// 		getactor[THISACTOR].yrepeat y
// 		setactor[RETURN].yrepeat y
// 		getactor[THISACTOR].pal pal
// 		setactor[RETURN].pal pal
// 		ifrnd 64 
// 		{ 
// 			ifspritepal 1 sound GLASSCRACKSND else
// 			ifrnd 128 sound JIBLAND else sound JIBLAND2 
// 		}
// 		ifvarg underwater 0 nullop else ifinwater nullop else
// 		ifvare peractor1 1 { ifrnd 128 espawn BURNING else espawn BURNING2 setactorvar[RETURN].peractor1 1 }
// 		setvar NOCODE 1
// 	}

}
break



default

ifvare timer 1 ifvare mirrored YES
	state flipit
	
ifspritepal 66 nullop else ifvare pulse 0 setvar NOCODE 1 
break

endswitch

endevent

state cannondeath

ifvare peractor1 2 { setvar RETURN 0 break }
getactor[THISACTOR].htmovflag temp
	ifvare temp 0 
	{
		setvar RETURN 0 
		sound PIPEBOMB_EXPLODE 
		spawn EXPLOSION2  
	    hitradius 1792 80 120 160 200
	    spritepal 4
	    debris SCRAP1 5
	    debris SCRAP3 5
	    debris SCRAP6 5
	    break
	}
	// hit something
	addvar temp 16384
    ifvarl temp 16384 ifvarg temp -1 // hit a sprite
    {
	    setactor[temp].htpicnum RPG
	    getactorvar[temp].monstatus tempc
	    ifvarn tempc 0
	    {
		    setvar tempb 130
		    getactor[temp].extra hp
		    ifvarvarg tempb hp setvar RETURN 1 else
		    setvar RETURN 0
    	}
    	else setvar RETURN 0
	    
    } else
    setvar RETURN 0
    ifvare RETURN 0 
    {
	    sound PIPEBOMB_EXPLODE 
	    spawn EXPLOSION2 
	    hitradius 1792 80 120 160 200
	    spritepal 4
	    debris SCRAP1 5
	    debris SCRAP3 5
	    debris SCRAP6 5
	}
ends


onevent EVENT_KILLIT

ifvarg intensity 0 
{
	ifactor LIGHTSOURCEPROJ
	{
		setactorvar[myspawner].monstatus 2
		spawn LIGHTSOURCE
	}
	// state exitlightarray 
	setvar RETURN 0 
}
ifactor LIGHTSOURCE subvar flares 1

getactor[THISACTOR].picnum picnum
switch picnum
case CRACK1
case CRACK2
case CRACK3
case CRACK4
ifvarn activator 0 state activatorstate
break

case FIRELASER
ifvare effects YES
{
	getactor[THISACTOR].htmovflag temp
	ifvarn temp 0
	{
		randvar temp 2
		ifvare temp 0 sound FIRELASER_IMPACT1 else
		ifvare temp 1 sound FIRELASER_IMPACT2
		ifvare temp 2 sound FIRELASER_IMPACT3  
		getactor[THISACTOR].htowner spriteid
		addvar temp 16384
		ifvarvarn temp spriteid
			spawn ROCKETHALO
	}
}
break

case FIREBULLET

ifvarand ppowers 2
{
	headspritestat spriteid 1
	whilevarn spriteid -1
	{
		ifvare playerally 0
		ifvare actorvar[spriteid].playerally 0
		ifvarn actorvar[spriteid].monstatus 0
		nullop // no friendly fire
		else
		{
			getactor[THISACTOR].z z
			getactor[spriteid].z mz
			subvarvar mz z
			ifvarl mz 16384 ifvarg mz -16384
			{
				ldist xydist THISACTOR spriteid
				ifvarl xydist 1560
				{
					
					getactorvar[spriteid].burning tempb
					setvar tempc 1560
					subvarvar tempc xydist
					shiftvarr tempc 5
					addvar tempc 6
					addvarvar tempb tempc
					setactorvar[spriteid].burning tempb
				}
			}
		}
		nextspritestat spriteid spriteid
	}
	ifrnd 64 { ifrnd 128 spawn BURNING else spawn BURNING2 }
	ifcansee ifpdistl 1560
	ifvare playerally 0
	{
		getplayer[THISACTOR].i spriteid
		getactorvar[spriteid].burning tempb
		addvar tempb 52
		setactorvar[spriteid].burning tempb
	}
}
break


case COLACANSTAND 
ifaction CANSQUISHED
{
	getactor[THISACTOR].yrepeat y
	ifvarg y 8
	{
		setactor[THISACTOR].yrepeat 6
		stopsound SQUISHED
		sound CRUSHCAN
		setvar RETURN 1
	}
}
break

case SAWBLADEPROJ

	addvar mtype 1
	ifvarl mtype 6 setvar RETURN 1
	else 
	{
		ifceilingdistl 32 setvar RETURN 0 else
		
		{ 
			cactor SAWBLADEGROUND 
			changespritestat THISACTOR 1
			move 0
			setvar RETURN 1 
		} 
		
	}

break


case DPCANNONBALL
state cannondeath
break
default break
endswitch

ifactor ICESHARD
{
	spritepal 12
	lotsofglass 4
	getactor[THISACTOR].htmovflag temp
	ifvarn temp 0
	{
		// hit something
		addvar temp 16384
		ifvarl temp 16384 ifvarg temp -1 
		{
		    // hit a sprite
		    setvar RETURN 0 
		    break 
		}
	}
	
	sound GLASSCRACKSND
	setvar RETURN 0 
	break
}

ifactor RPGNOAIM { ifvare weap 1 cactor RPG setvar peractor1 2 }
ifactor RPG
{
	ifvare effects YES
	ifvarn peractor1 -1
	{
		ifvarn peractor1 2
		{
			setvar countvar 0
			getactor[THISACTOR].ang position
			whilevarn countvar 16
			{
				addvar countvar 1
				randvar zdist 8192 subvar zdist 6144 
				ifrnd 128 ezshoot zdist NEWSCRAP3 else 
				ezshoot zdist NEWSCRAP6
				ifrnd 160 setthisprojectile[RETURN].trail SMALLSMOKE
				randvar temp 128
				addvar temp 160
				setthisprojectile[RETURN].vel temp
				randvar temp 128
				addvar position 64
				addvarvar position temp
				setactor[THISACTOR].ang position
			}
			ifrnd 64 spawn BURNING else ifrnd 64 spawn BURNING2
		}

		getactor[THISACTOR].htmovflag temp
		ifvare temp 0 { setvar RETURN 0 break }
		// hit something
		addvar temp 16384
        ifvarl temp 16384 ifvarg temp -1 
        {
	        // hit a sprite
	        setvar RETURN 0 
	        break 
	    }
        getactor[THISACTOR].htmovflag hitwall
		andvar hitwall 49152
		ifvare hitwall 32768
		{
            
			getactor[THISACTOR].htmovflag hitwall
			andvar hitwall 16383 // temp is now the wall ID that it hit
			// stop if there is a lotag 13 SE in the nextsector of hitwall
			getwall[hitwall].nextsector temp
			ifvarg temp -1
			{
				setvar tempc 0
				headspritesect spriteid temp
				whilevarn spriteid -1
				{
					getactor[spriteid].statnum picnum
					ifvare picnum 3 // SE
					{
						getactor[spriteid].lotag tempb
						ifvare tempb 13 // NO SCORCH
							setvar tempc 1
					}
					nextspritesect spriteid spriteid
				}
				ifvare tempc 1 { setvar RETURN 0 break }
			}
			getwall[hitwall].overpicnum temp
			ifvare temp BIGFORCE { setvar RETURN 0 break }
			ifvare temp W_FORCEFIELD { setvar RETURN 0 break }
			getwall[hitwall].cstat temp
			ifvarand temp 128 { setvar RETURN 0 break } // break on transparent
			ifvarand temp 16 { setvar RETURN 0 break } // break on masking
			setvarvar peractor1 hitwall
			getactor[THISACTOR].z z
			subvar z 3072
			setactor[THISACTOR].z z
			setvarvar spriteid THISACTOR
			state projectilehitscan
			setvar temp 0
			ifvarn hitsprite -1 
			{
				getactor[hitsprite].picnum picnum
				ifvare picnum SCORCH { setvar RETURN 0 break }
				setvar temp 1
			}
			ifvarvare hitwall peractor1 setvar temp 1
			ifvare temp 1
			{
				addvar z 6144
				setactor[THISACTOR].z z
				state projectilehitscan
				setvar temp 0
				ifvarn hitsprite -1 ifvarn sprite[hitsprite].picnum SCORCH setvar temp 1
				ifvarvare hitwall peractor1 setvar temp 1
				ifvare temp 1
				{
					subvar z 3072
					setactor[THISACTOR].z z
					state projectilehitscan
					setvarvar hitwall peractor1
					getwall[hitwall].x x
					getwall[hitwall].y y
					getwall[hitwall].point2 tempb
					
					getwall[tempb].x mx
					getwall[tempb].y my
					subvarvar x mx
					subvarvar y my
				    getangle z x y
				    addvar z 512
				    setactor[THISACTOR].ang z
				    getactor[THISACTOR].x x
				    getactor[THISACTOR].y y
				    state pythagoras
				    ifvarl xydist 512
			    	{
					    espawn SCORCH
					    getactor[THISACTOR].xrepeat x
					    ifvarl x 14 setactorvar[RETURN].initx x
					    setactor[RETURN].x hitx
					    setactor[RETURN].y hity
					    setactor[RETURN].z hitz
					    
// 					    cos xvel z
// 						sin yvel z
// 					    subvar z 1024
// 						shiftvarr xvel 10
// 						shiftvarr yvel 10
// 						movesprite RETURN xvel yvel zvel CLIPMASK0 temp
						
					    setvar temp 144
						ifrnd 128 orvar temp 4
						ifrnd 128 orvar temp 8
						setactor[RETURN].cstat temp
						setactorvar[RETURN].target hitwall
					}
				}
			}
			setvar RETURN 0
			break
		    
		}
		setvarvar spriteid THISACTOR
		state projectilehitscan
		ifvarl hitsector 0 { setvar RETURN 0 break }
		ifvarg hitsector 4095 { setvar RETURN 0 break }

		getceilzofslope hitsector hitx hity temp
	    setvarvar z hitz
	    subvarvar z temp
	    shiftvarr z 8
	    subvar z 1
	    setvarvar mz z
	    getflorzofslope hitsector hitx hity z
	    setvarvar temp hitz
	    subvarvar z temp
	    shiftvarr z 8
	    subvar z 1
	    
	    ifvarl z 1
	    {
		    getsector[THISACTOR].floorstat tempb
		    ifvarand tempb 1 nullop else ifvarand tempb 2 nullop else
		    {
			    state scorchfloor
			    setactorvar[RETURN].lotag 1
		    }
		    // floor decal 
		    
		} else
	    ifvarl mz 0 
	    {
		   getsector[THISACTOR].ceilingstat tempb
		   ifvarand tempb 1 nullop else ifvarand tempb 2 nullop else
		   {
			   state scorchfloor
			   setactorvar[RETURN].hitag 1
		   } 
		   // ceiling decal 
		}
 	}
 	setvar RETURN 0

}


endevent

gamevar chwep 0 1

onevent EVENT_PREVIOUSWEAPON
 setvar chwep 1
endevent

onevent EVENT_NEXTWEAPON
 setvar chwep 2
endevent

onevent EVENT_SELECTWEAPON

ifvare chwep 1
{
  
  ifvarvarg RETURN CURRWEAP
  {
    ifvarn CURRWEAP 0
	setvar RETURN 0
  }
}
ifvare chwep 2 
{
  ifvarvarl RETURN CURRWEAP
    setvar RETURN 0

}
ifvarvare RETURN CURRWEAP ifvarn chwep 0 ifvarg LASERAMMO 0
  setvar RETURN 0
setvar chwep 0

endevent

onevent EVENT_CHEATGETJETPACK

ifvare useakimbo YES
ifvare akimbo -1 state changeakimbo
ifvare usemossberg YES
orvar ALTSHOTGUN 1
else orvar ALTSHOTGUN 16
orvar ALTCHAINGUN 1
orvar ALTCHAINGUN 8
setvar MINIGUNAMMO 800
orvar ALTSHOTGUN 2
setvar MP5INCLIP 30
setvar SHOTGUNCLIP 8
ifvare depistols YES setvar botclip 8 else
setvar botclip 12
ifvare usebfg YES
{
	setvar gunparts 15
	setplayer[THISACTOR].max_ammo_amount 7 50
	setplayer[THISACTOR].ammo_amount 7 50
}

endevent

onevent EVENT_MOVEFORWARD

setvar fpress 2

ifp prunning setvar runflag 2
setvar forbackdir 2

ifvarg onladder 0 ifp palive
{
	setvar RETURN -1
	ifp ponground 
	{ 
		getplayer[THISACTOR].posz z 
		subvar z 1024 
		setplayer[THISACTOR].posz z
		addvar z 8192
		getplayer[THISACTOR].i temp
		setactor[temp].z z
	}
	setvar temp RUNNINGSPEED
	divvar temp -50
	setvarvar laddervel temp
}

addvar fpresstime 1

ifvarvare timer fpresstime addvar fhold 1 else
{
	addvar ftap 1
	setvar fhold 0
}

setvarvar fpresstime timer

endevent

onevent EVENT_MOVEBACKWARD

setvar bpress 2

ifp prunning setvar runflag 2
setvar forbackdir -2

ifvarg onladder 0 ifp palive
{
	setvar RETURN -1
	setvar temp RUNNINGSPEED
	divvar temp 50
	subvar temp 512
	setvarvar laddervel temp
}

addvar bpresstime 1

ifvarvare timer bpresstime addvar bhold 1 else
{
	addvar btap 1
	setvar bhold 0
	ifvarg ftap 1 setvarvar fpresstime timer
}

setvarvar bpresstime timer
endevent

onevent EVENT_STRAFELEFT

ifp prunning setvar runflag 2
setvar strafedir -13

addvar lpresstime 1

ifvarvare timer lpresstime addvar lhold 1 else
{
	addvar ltap 1
	setvar lhold 0
}
		
setvarvar lpresstime timer

endevent

onevent EVENT_STRAFERIGHT

ifp prunning setvar runflag 2
setvar strafedir 13

addvar rpresstime 1

ifvarvare timer rpresstime addvar rhold 1 else
{
	addvar rtap 1
	setvar rhold 0
}
		
setvarvar rpresstime timer

endevent

definegamefuncname 11 DUKEPLUS_MENU
// Look Up

onevent EVENT_LOOKUP
setvar RETURN -1
addvar lastinput 1
ifvarvarg lastinput timer setvarvar lastinput timer
ifvarvare lastinput timer nullop else
{
	setvarvar lastinput timer
	
	ifvare menutoggle 0 
	{
		ifvare ONCAR 0
		{
			
			sound INTO_MENU 
			ifvare nomenu YES quote 1179
			else
			{
				setvar menutoggle 1 
				setvar menunag NO
				savegamevar menunag
			}
		}
	} else
	{
		sound EXITMENUSOUND
		setvar menutoggle 0
		setvar menuitem 0
		setvar lastchange 0
		setplayer[THISACTOR].movement_lock 0
	}
}

endevent

definegamefuncname 12 USE_FLARE
// look down
onevent EVENT_LOOKDOWN

setvar temp USE_FLARES
ifvare temp YES 
{
	setvar RETURN -1
	ifcount 26
	{
		resetcount
		ifvarn holding -1 
			setvar holding -1 
		else ifvarl flares MAX_FLARES
		{
			espawn LIGHTSOURCE
			setvarvar holding RETURN
			setvar holdingpic LIGHTSOURCE
		} else
		quote 1012
	}
}


endevent

definegamefuncname 18 QUICK_PIPEBOMB

onevent EVENT_AIMDOWN

ifp palive
ifvare quikpipe 0
ifvarg player[THISACTOR].ammo_amount 5 0
ifvare KICKBACKPIC 0
ifvarn CURRWEAP 5
ifvare player[THISACTOR].weapon_pos 0
{
	setvar quikpipe 1
	setplayer[THISACTOR].weapon_pos -1
}

setvar RETURN -1
endevent

onevent EVENT_TURNAROUND
ifvare backview 0
{
	ifvare mantling 1 
	{
		setvar RETURN -1
		setvar backview 52
	} else
	ifvarg onladder 0
	{
		setvar RETURN -1
		setvar backview 52
	}
}
endevent

state checksuperkick

ifvarn perplayeronbike -1 break
ifvarn cannonid -1 break
ifvarn sleeping 0 break
ifp pshrunk nullop else
ifvare superkicking 0 ifvarg kickenergy 130
{
	 setvar temp 0
	 setvar temp 0
	 ifvarand extbits 1 setvar temp 1
	 ifvarand extbits 2 { setvar temp 1 setvar spinkick 1 getplayer[THISACTOR].ang dodgeang }
	 ifvare temp 1
	 {
		setvar RETURN -1
		setvar superkicking 1
		subvar kickenergy 156
		ifinwater nullop else
		ifvare dodge 0 ifvare underwater 0
		{
			getplayer[THISACTOR].ang dodgeang
			setvar dodge 10
		}
  	}
	 
}

ends

onevent EVENT_QUICKKICK

ifvarn camerasprite -1
{
	ifvarand actorvar[camerasprite].monstflags 2 nullop else
	{ setvar RETURN -1 break }
}
ifvarn superkicking 0 setvar RETURN -1

ifvare karate YES state checksuperkick

endevent


onevent EVENT_CROUCH
ifvarn sleeping 0 { setvar RETURN -1 break }
endevent

onevent EVENT_JUMP

setvar cannonid -1
ifvarn sleeping 0 { setvar RETURN -1 break }
ifvarn menutoggle 0 { setvar RETURN -1 break }
ifvarg underwater 0 { setvar RETURN -1 break }

setvar jumped 1
ifvarg numallies 0
{
	setvarvar tempd RETURN
	espawn PLAYERTRAIL
	getplayer[THISACTOR].posz z
	addvar z 4096
	setactor[RETURN].z z
	setvar ptrailtimer 0 
	setactorvar[RETURN].mtype 1
	setvarvar RETURN tempd
}

ifvarg dodge 0
	addvar dodge 10
	
ifvare dpsounds YES
{
	randvar temp 2
	ifvare temp 0 sound JUMP5 else
	ifvare temp 1 sound JUMP2 else
	sound JUMP4
}

	

endevent

onevent EVENT_USEMEDKIT
ifvarg underwater 0
setplayer[THISACTOR].sound_pitch 0
endevent


onevent EVENT_PROCESSINPUT


// ifsound PIPEBOMB_EXPLODE
// {
// 	stopsound PIPEBOMB_EXPLODE
// 	displayrandvar temp 3
// 	ifvarl temp 2 sound PIPEBOMB_EXPLODE2 else
// 	ifvare temp 2 sound NEW_EXPLODE else
// 	ifvare temp 3 sound NEW_EXPLODE2
// }
// ifsound RPG_EXPLODE
// {
// 	stopsound RPG_EXPLODE
// 	displayrandvar temp 3
// 	ifvarl temp 2 sound RPG_EXPLODE2 else
// 	ifvare temp 2 sound NEW_EXPLODE else
// 	ifvare temp 3 sound NEW_EXPLODE2
// }


getinput[THISACTOR].bits bits
getinput[THISACTOR].extbits extbits

ifvarn ONCAR 0 break

ifvarand bits 1 // jumping
{
	ifvarg underwater 0 ifvare mantling 0 ifvare onladder 0
	{
		getplayer[THISACTOR].posz z
		addvar z 3072
		ifvarvarg z peractor2
		{
			ifvarand bits 2 nullop else
			getplayer[THISACTOR].poszv zvel
			subvar zvel 384
			ifvarl zvel -1024 setvar zvel -1024
			setplayer[THISACTOR].poszv zvel
		}
		ifp ponground 
		{ 
			getplayer[THISACTOR].posz z subvar z 128 setplayer[THISACTOR].posz z
			setplayer[THISACTOR].jumping_counter 181
			setplayer[THISACTOR].jumping_toggle 1
			setvar jumped 1
		}
	}
	ifvare mantling 1 ifvarvarg mantwait mantwaittime setvar mantling 2
	ifvarg onladder 0
	{
		setvar onladder -6
		setplayer[THISACTOR].jumping_toggle 1
	}
}


ifvarand bits 2 // crouching
{
  ifvare mantling 1 setvar mantling -10
  ifvarg underwater 0 
  {
	  getplayer[THISACTOR].poszv zvel
	  addvar zvel 640
	  ifvarg zvel 768 setvar zvel 768
	  setplayer[THISACTOR].poszv zvel
  }
}


ifvarand bits 262144 // altfire/reload
ifvare ONCAR 0
ifvare cannonid -1
{
	ifvare CURRWEAP 0 ifvarg LASERAMMO 4 
	{
		ifvare LASERCHARGE 0 sound CHARGESND
		ifvarg LASERCHARGE 26 soundonce CHARGEHOLD
		ifvarl LASERCHARGE 52 
		addvar LASERCHARGE 1
	}
	ifvarn camerasprite -1
	{
		ifvarand actorvar[camerasprite].monstflags 2 nullop else break
	}
	setvarvar temp WEAPON1_CLIP
	ifvare depistols YES subvar temp 1
 	ifvare CURRWEAP 1 ifvare KICKBACKPIC 0 ifvarvarl botclip temp
	{
		getplayer[THISACTOR].ammo_amount 1 tempb
		ifvarg akimbo -2 ifvarl akimbo 2 ifvarvarg tempb botclip
		ifvare player[THISACTOR].weapon_pos 0
		{
			ifvarl akimbo 1 setvar WEAPON1_RELOAD 27 else
			setvar WEAPON1_RELOAD 48
			ifvare depistols YES addvar WEAPON1_RELOAD 2
			setplayer[THISACTOR].reloading 1
			ifvare depistols YES setplayer[THISACTOR].kickback_pic 11
			else
			setplayer[THISACTOR].kickback_pic 9
			sound EJECT_CLIP
			setvar PISTOLRELOAD 1
		}
	}

	ifvare usemossberg YES
	ifvare CURRWEAP 2 ifvare KICKBACKPIC 0
	ifvare FAKERELOAD 0 ifvarl SHOTGUNCLIP 8
	{
		getplayer[THISACTOR].ammo_amount 2 tempb
		ifvarvarg tempb SHOTGUNCLIP
		{
			setvar FAKERELOAD 1
			setvar reloadonce 1
		}	
	}
	ifvarand ALTSHOTGUN 4 ifvare KICKBACKPIC 0
	ifvare CURRWEAP 2
	ifvare ALTMELEE 0 ifp palive
	{
		setvar ALTMELEE 1
		sound ALTMELEESND
	}
	
	ifvare CURRWEAP 3
	ifvarand ALTCHAINGUN 2
	{
		ifvarg player[THISACTOR].ammo_amount 3 9
		ifvare player[THISACTOR].weapon_pos 0
		ifvare grenadecounter 0
		{
			getplayer[THISACTOR].ammo_amount 3 temp
			subvar temp 10
			setplayer[THISACTOR].ammo_amount 3 temp
			setvar grenadecounter 1
		}
	}
	else
	{
		ifvare usemp5 YES
		ifvare CURRWEAP 3 ifvare KICKBACKPIC 0
		ifvare FAKERELOAD 0 ifvarl MP5INCLIP 30 ifvarvarg MP5AMMO MP5INCLIP { setvar FAKERELOAD 1 setvar reloadonce 1 }
	}
	
	ifvare CURRWEAP 4 ifvare usebigrox YES ifvare KICKBACKPIC 0
	ifvare player[THISACTOR].weapon_pos 0
	ifvarg player[THISACTOR].ammo_amount 4 0
	{
		setplayer[THISACTOR].kickback_pic 1
		setvar WEAPON4_FIRESOUND WHOOSH	
	}
	ifvare usebfg YES
	ifvare CURRWEAP 7 ifvare gunparts 15 ifvare KICKBACKPIC 0
	ifvare wow 0
	{
		getplayer[THISACTOR].ammo_amount 7 temp
		ifvarg temp 19
		{
			subvar temp 19
			setplayer[THISACTOR].ammo_amount 7 temp
			setvar WEAPON7_SHOOTS POWBALL
			setvar WEAPON7_TOTALTIME 30
			setvar WEAPON7_FIRESOUND IMP_ALTFIRE
			setplayer[THISACTOR].kickback_pic 1
		}
	}
	
	ifvare CURRWEAP 9 ifvare altfreeze YES ifvare KICKBACKPIC 0
	ifvare player[THISACTOR].weapon_pos 0
	ifvarg player[THISACTOR].ammo_amount 9 0
	{
		setplayer[THISACTOR].kickback_pic 1
		setvar WEAPON9_SHOOTS ICESHARD
		setvar WEAPON9_FIRESOUND SHARDSHOOTSND
		setvar WEAPON9_SHOTSPERBURST 3
		setvar WEAPON9_TOTALTIME 9		
	}
}
else 
{
	ifvarg LASERCHARGE 25 ifvare CURRWEAP 0
	{
		setvar weap BIGFIRELASER
		setvar LASERFIRE 1
		shoot BIGFIRELASER
		sound BLASTERSND
		subvar LASERAMMO 5
		ifvarl LASERAMMO 0 setvar LASERAMMO 0
	}
	ifvarg LASERCHARGE 0
	{
		setvar LASERCHARGE 0
		stopsound CHARGESND
		stopsound CHARGEHOLD
	}
	ifvarand bits 4
	{
		ifvare ONCAR 0 ifvare CURRWEAP 9 ifvare altfreeze YES
		{
			setvar WEAPON9_SHOOTS ICEBEAM
			setvar WEAPON9_FIRESOUND ICEBEAMSND
			setvar WEAPON9_INITIALSOUND -1
			setvar WEAPON9_TOTALTIME 10
			setvar WEAPON9_SHOTSPERBURST 1
		}
	}
}
ifvarn botselected -1
{
	getinput[THISACTOR].extbits temp
	ifvarand temp 4 ifvarand temp 8 
	{
		userquote 1004
		setactorvar[botselected].command 0
		setvar botselected -1
	}
}
	  
endevent

state throwit

	ifvare holdingpic LIGHTSOURCE
	{
		getactorvar[holding].intensity X
		getactorvar[holding].countvar tempb
		setactorvar[holding].countvar FLARE_LIFETIME
		setactor[holding].cstat 32768
		setactorvar[holding].intensity 0
		setactorvar[holding].flicker 0
		eshoot LIGHTSOURCEPROJ
		ifvarg tempb FLARE_FADETIME
		{
			setactorvar[RETURN].intensity X
			setactorvar[RETURN].peractor7 X
		}
		else
		{
			setactorvar[RETURN].intensity pintensity
			setactorvar[RETURN].peractor7 pintensity
		}
	}
	else
	{
		getactorvar[holding].weight temp
		ifvarl temp WEIGHT2 setvar tempb 36 else
		ifvarl temp WEIGHT3 setvar tempb 26 else
		setvar tempb 16 
		setactorvar[holding].peractor4 tempb
		getactorvar[holding].initcstat temp
		setactor[holding].cstat temp
	}
	setvar holding -1
	setvar RETURN -1
	setvar pickup -12
ends

onevent EVENT_FIRE

ifvarn camerasprite -1
{
	ifvarand actorvar[camerasprite].monstflags 2 nullop else
	{ setvar RETURN -1 break }
}
ifvarn cannonid -1 { setvar RETURN -1 break }
ifvarn sleeping 0 { setvar RETURN -1 break }
ifvarn mantling 0 { setvar RETURN -1 break }
ifvarn menutoggle 0 { setvar RETURN -1 break }
ifvare ONCAR 1 { setvar RETURN -1 break }
ifvarn ALTMELEE 0 { setvar RETURN -1 break }
ifvarn wow 0 { setvar RETURN -1 break }

ifvare gravgun YES ifvare CURRWEAP 11 
{
	ifvarand bits 262144 setvar RETURN -1
	ifvarn gravitysprite -1
	{
		ifvarvare holding gravitysprite { setvar RETURN -1 orvar gravonce 2 } else
		ifvarand bits 262144 setvar RETURN -1
		else setvar WEAPON11_SHOOTS GRAVPROJ
	}
	else 
	{
		ifvare holding -1
		setvar WEAPON11_SHOOTS GRAVPROJ2
		else { state throwit break }
		
	}
}
else
ifvarn holding -1
{
	state throwit
	break 
}

ifvarl pickup 0 { setvar RETURN -1 break }

ifvarn FAKERELOAD 0 { setvar RETURN -1 break }

ifvare CURRWEAP 3
{
	ifvarand ALTCHAINGUN 2 break // no need to check the rest
	ifvare usemp5 YES
	ifvarl MP5INCLIP 1 setvar RETURN -1 
}


ifvare CURRWEAP 1
{
	ifvarl botclip 1 setvar RETURN -1
	ifvare useakimbo YES
	{
		ifvarg akimbo 1 setvar RETURN -1
		ifvarl akimbo -1 setvar RETURN -1
	}
}


ifvare CURRWEAP 0 
{
	ifvarg LASERFIRE 0 { setvar RETURN -1 break }
	ifvarg LASERAMMO 0 
	{
		ifvarg LASERCHARGE 25
		{
			shoot BIGFIRELASER
			setvar LASERCHARGE 0
			sound BLASTERSND
			subvar LASERAMMO 5
			ifvarl LASERAMMO 0 setvar LASERAMMO 0
		} else
		{
			shoot FIRELASER
			sound PRED_ATTACK2
			subvar LASERAMMO 1
		}
		setvar LASERFIRE 1 
		setvar RETURN -1 
		break
	}
	ifvare karate YES state checksuperkick
}



ifvare CURRWEAP 2
	ifvare usemossberg YES
	{
		ifvarand ALTSHOTGUN 4 break
		ifvarl SHOTGUNCLIP 1 setvar RETURN -1 else
			ifvarg SHOTGUNCLIP 0 subvar SHOTGUNCLIP 1
	}

ifvare CURRWEAP 7
ifvare usebfg YES
{
	ifvarand gunparts 1 ifvarand gunparts 2 nullop else setvar RETURN -1
}


endevent



definegamefuncname 41 RELOAD_ALTFIRE
// Center View

onevent EVENT_RESETWEAPONS

state resetweaponstate

endevent

onevent EVENT_SELECTWEAPON
ifvare useakimbo YES setvar weapswitch 26
ifvare CURRWEAP 8 setvarvar PIPEBOMB_CONTROL pipecontrol
setvar FAKERELOAD 0
endevent

onevent EVENT_WEAPKEY2

ifvare CURRWEAP 1
ifvare useakimbo YES
{
	ifvarn akimbo 0 ifvarn akimbo 1 break
	getplayer[THISACTOR].kickback_pic temp
	ifvare temp 0
	state changeakimbo
}
endevent

onevent EVENT_WEAPKEY3

ifvarn FAKERELOAD 0 { setvar RETURN -1 break }

ifvare CURRWEAP 2
ifvare KICKBACKPIC 0 ifvarand ALTSHOTGUN 2
{
	setvar temp 0
	ifvarand ALTSHOTGUN 1 setvar temp 1
	ifvarand ALTSHOTGUN 16 setvar temp 1 // you must have one of the other shotguns
	ifvare temp 1
	{
		setvar ALTMELEE 0
		setplayer[THISACTOR].weapon_pos -1
		orvar ALTSHOTGUN 8
		// shotgun should not be switched until weapon_pos reaches -9
		ifvarand ALTSHOTGUN 4 
		{
			ifvarand ALTSHOTGUN 1
			sound MOSSPUMP
			else sound SHOTGUN_COCK
		}
	}
}
endevent

onevent EVENT_WEAPKEY4

ifvarn FAKERELOAD 0 { setvar RETURN -1 break }

ifvare CURRWEAP 3
ifvare KICKBACKPIC 0 ifvarand ALTCHAINGUN 1
ifvarand ALTCHAINGUN 8 // you must have the minigun and either chaingun or mp5
{
	
	setplayer[THISACTOR].weapon_pos -1
	orvar ALTCHAINGUN 4
	// should not be switched until weapon_pos reaches -9
	// ADD A SOUND
	
}
endevent

onevent EVENT_RETURNTOCENTER

ifvarn ONCAR 0 { setvar RETURN -1 break }
getplayer[THISACTOR].hard_landing temp
ifvarn player[THISACTOR].hard_landing 0 break

setvar RETURN -1
	
ifvare CURRWEAP 7 ifvare usebfg NO
ifvare player[THISACTOR].weapon_pos 0
ifvare player[THISACTOR].kickback_pic 0
{
	ifvare devshotty 1 
	{
		quote 1083
		setvar devshotty 2 
	
		setvar WEAPON7_SHOTSPERBURST 6
		setvar WEAPON7_SHOOTS SHOTSPARK1
		setvar WEAPON7_FIRESOUND SHOTGUN_FIRE
		setvar WEAPON7_FLAGS 4224
		setvar WEAPON7_SPAWNTIME 4
	    setvar WEAPON7_SPAWN 2535
	    setvar WEAPON7_INITIALSOUND -1
	}
	else 
	{
		quote 1084
		state normaldev
		setvar devshotty 1
	}
	setplayer[THISACTOR].weapon_pos -9
	sound SELECT_WEAPON
}
	
ifvare CURRWEAP 5 ifvare KICKBACKPIC 0
{
	getplayer[THISACTOR].weapon_pos temp
	ifvare temp 0
	{
		ifvare PIPEBOMB_CONTROL 1 
		{
			quote 1076
			setvar PIPEBOMB_CONTROL 2 
			setvar pipecontrol 2
		}
		else 
		{
			quote 1077
			setvar PIPEBOMB_CONTROL 1
			setvar pipecontrol 1
		}
		setplayer[THISACTOR].weapon_pos -9
		sound SELECT_WEAPON
	}
}

ifvare CURRWEAP 6 ifvare KICKBACKPIC 0 ifvare usemindblast YES
{
	getplayer[THISACTOR].weapon_pos temp
	ifvare temp 0
	{
		ifvare altshrinker 1 
		{
			quote 1078
			setvar altshrinker 0 
		}
		else 
		{
			quote 1079
			setvar altshrinker 1
		}
		setplayer[THISACTOR].weapon_pos -9
		sound SELECT_WEAPON
	}
}

ifvare CURRWEAP 8 ifvare dukemon YES
{
	getplayer[THISACTOR].weapon_pos temp
	ifvare temp 0
	{
		getplayer[THISACTOR].ammo_amount 8 tempb
		addvar dukeballselected 1
		ifvarvare dukeballselected tempb setvar dukeballselected 0
		else // paranoia
		ifvarvarg dukeballselected tempb setvar dukeballselected 0
		setplayer[THISACTOR].weapon_pos -9
		sound SELECT_WEAPON
	}
}


endevent

onevent EVENT_GETSHOTRANGE

ifvarn mydukebike -1 
{
	getactorvar[mydukebike].target2 temp
	ifvarn temp -1
	setactor[temp].cstat 32768
}

ifvare CURRWEAP 1
{
 	ifvarg botclip 0 subvar botclip 1
	
	setvar ANGRANGE PISTOLSPREAD
	ifvarl ANGRANGE 4 setvar ANGRANGE 4
	setvarvar temp ANGRANGE
	mulvar temp 8
	setvarvar ZRANGE temp
	
	ifvare useakimbo YES ifvarg akimbo 0
	{
		shiftvarl ANGRANGE 1
		shiftvarl ZRANGE 1
	}
}
else
ifvare CURRWEAP 2
{
	setvar ANGRANGE SHOTGUNSPREAD
	ifvarl ANGRANGE 4 setvar ANGRANGE 4
	setvarvar temp ANGRANGE
	shiftvarl temp 3
	setvarvar ZRANGE temp
	ifvarand ALTSHOTGUN 4 { mulvar ANGRANGE 2 mulvar ZRANGE 2 }
}
else
ifvare CURRWEAP 3
{
	ifvarand ALTCHAINGUN 2 // using battlelord minigun
	{
		
		// change spread depending on current speed
	}
	else
	{
		ifvare usemp5 YES 
		{
			randvar mp5ang 2047
			ifvarg MP5INCLIP 0 subvar MP5INCLIP 1
			ifvare MP5INCLIP 0
			{
				setplayer[THISACTOR].kickback_pic 0
				getplayer[THISACTOR].ammo_amount 3 MP5AMMO
				ifvarg MP5AMMO 0 setvar FAKERELOAD 1
			}
		} else
		{
			ifvarg chaingunheat 984 addvar chaingunheat 78
			addvar chaingunheat 16
		}
		setvar ANGRANGE CHAINGUNSPREAD
		ifvarl ANGRANGE 4 setvar ANGRANGE 4
		setvarvar temp ANGRANGE
		shiftvarl temp 3
		setvarvar ZRANGE temp
	}
	
} else
ifvare CURRWEAP 7
{
	ifvare usebfg YES
	ifvare ONCAR 0
	{
		setvar ANGRANGE 1
		setvar ZRANGE 1
	}
// 	else
// 	{
// 		setvar ANGRANGE 64
// 		setvar ZRANGE 512
// 	}
}

ifvare CURRWEAP 9 ifvare WEAPON9_SHOOTS ICEBEAM
{
	setvar ANGRANGE 1
	setvar ZRANGE 1
	//setvar pal 1
	//setvar shade 96
	//setvar tempd 0
	//setvar intensity 32767
	//getplayer[THISACTOR].horiz M
	//state spawnspotlight
	//setactorvar[RETURN].countvar 14
}
ifvare CURRWEAP 11 ifvare gravgun YES
{
	setvar ANGRANGE 1
	setvar ZRANGE 1
}
else ifvare player[THISACTOR].over_shoulder_on YES
ifvare ONCAR 0
ifvare perplayeronbike -1
{
	espawn SHOTSPARK2
	getplayer[THISACTOR].horiz temp
	setactorvar[RETURN].position temp
}


	
endevent



state initsprites

setvar spriteid 0
whilevarn spriteid 16384
{

	getactor[spriteid].picnum picnum
	ifvarg picnum 1519 ifvarl picnum 1544 // DUKE JIBS
	setactor[spriteid].mdflags 2
	ifvarg picnum 1744 ifvarl picnum 1780 // HEADJIB1, ARMJIB1, LEGJIB1
	setactor[spriteid].mdflags 2 // ANIMATION OFF
	ifvarg picnum 2200 ifvarl picnum 2213 // LIZMANHEAD1, LIZMANARM1, LIZMANLEG1
	setactor[spriteid].mdflags 2 // ANIMATION OFF
	ifvarg picnum 2244 ifvarl picnum 2270 // JIBS1, JIBS2, JIBS3, JIBS4, JIBS5
	setactor[spriteid].mdflags 2 // ANIMATION OFF
	ifvarg picnum 2285 ifvarl picnum 2294 // JIBS6
	setactor[spriteid].mdflags 2 // ANIMATION OFF
	ifvarg picnum 2389 ifvarl picnum 2419 // SCRAPS
	setactor[spriteid].mdflags 2 // ANIMATION OFF

	switch picnum
	
	case 21 case 22 case 23 case 24 case 25 case 26 case 27 case 28 case 29
	case 32 case 37 case 40 case 41 case 42 case 44 case 45 case 46 case 47
	case 49 case 51 case 52 case 53 case 54 case 55 case 56 case 57 case 59
	case 60 case 61 case 100
	getactorvar[spriteid].pal temp
	ifvare temp 66
		setactor[spriteid].pal 66
	break
	
	case WATERFOUNTAIN
	addvar picnum 1
	setactor[spriteid].picnum picnum 
	changespritestat spriteid 1
	break
	
	case LIGHTBUG
	getactor[spriteid].lotag temp
	ifvarn temp 0
	{
		setactor[spriteid].picnum LIGHTBUG2
		setactorvar[spriteid].lotag temp
		setactor[spriteid].xrepeat 3
		setactor[spriteid].yrepeat 3
		changespritestat spriteid 1
	}
	break
	default break
	endswitch
	addvar spriteid 1
}
ends

onevent EVENT_ENTERLEVEL

setvar raining 0
setvar numallies 0
setvar clearbotarray 1
setvar ONCE 0

state initsprites

endevent

onevent EVENT_RESETPLAYER

// setvar wallpoint 0
// whilevarvarn wallpoint NUMWALLS
// {
// 	getwall[wallpoint].shade temp
// 	addvar temp 10
// 	setwall[wallpoint].shade temp
// 	getactor[wallpoint].shade temp
// 	addvar temp 10
// 	setactor[wallpoint].shade temp
// 	addvar wallpoint 1
// }
// setvar spriteid 0
// whilevarvarn spriteid NUMSECTORS
// {
// 	getsector[spriteid].floorshade temp
// 	addvar temp 10
// 	setsector[spriteid].floorshade temp
// 	getsector[spriteid].ceilingshade temp
// 	addvar temp 10
// 	setsector[spriteid].ceilingshade temp
// 	addvar spriteid 1
// }

// ifvare rendmode 4
// {
	setvar pintensity LIGHT_BRIGHTNESS
	shiftvarl pintensity 7
// }
setvar quikpipe 0
setvar cannonid -1
setvar ONCAR 0
setvar activemonsters 0
setvar kickasscount 0
setvar tauntcount 0
setvar lastspeechtime -1500
setvar lastring 0
setvar booster 1
setvar camerasprite -1
setvar viewcam -1
setvar nextcam -1
setvar camzoomcontrol 65536
setvarvar cameraonwall player[THISACTOR].cursectnum
setvar mydukebike -1
setvar distlock -1
setvar tolerance CAMTOLERANCE1
setvar weapcount 0
setvar lastchange 0
setvar ftap 0
setvar btap 0
setvar ltap 0
setvar rtap 0
setvar fpresstime 0
setvar bpresstime 0
setvar lpresstime 0
setvar rpresstime 0
setvar superkicking 0
setvar superkickdone 0
setvar kickenergy KENERGY
setplayer[THISACTOR].runspeed 53200
ifmultiplayer 
{
	setvar usebigrox YES
	setvar canmantle NO
	setvar usemossberg YES
	setvar usemp5 YES
	setvar gravgun YES
	setvar altfreeze YES
	setvar lifebars YES
	setvar menunag NO
	setvar numbots 0
	setvar viewmode 0
} else
{
	readgamevar played
	ifvarn played 2 // DP 2.0
	{
		setvar played 2
		savegamevar played
		savegamevar menunag
		savegamevar effects
		savegamevar morefx
		
		// HRP edition default options
// 		setvar viewmode NO
// 		setvar dpsounds YES
// 		setvar karate NO
//		setvar uselaser NO
// 		setvar useakimbo YES
// 		setvar usemossberg NO
// 		setvar usemp5 NO
// 		setvar usebigrox NO
// 		setvar pipethrow YES
// 		setvar usemindblast NO
// 		setvar dukemon NO
// 		setvar altfreeze NO
// 		setvar gravgun NO
// 		setvar usebots NO
// 		setvar numbots NO
// 		setvar knockdist NO
// 		setvar goodarmor NO
// 		setvar cangrab NO
// 		setvar candodge NO
// 		setvar canmantle NO
// 		setvar slowrunaccel NO
// 		setvar lifebars NO
// 		setvar infighting NO
// 		setvar killerpigs NO
// 		setvar storehealth NO
// 		setvar steroidkicks NO
// 		setvar holodukebot NO
// 		setvar goggleswitches NO
// 		setvar randomize NO
// 		setvar rainradius NO
// 		setvar pdamage 100
// 		setvar mdamage 100
// 		setvar mirrored NO
// 		setvar scaled NO
// 		setvar doubled NO
// 		setvar quotestyle 0
// 		setvar smartmonsters NO
		// end HRP default options
		
		savegamevar viewmode
		savegamevar dpsounds
		savegamevar moretalk
		savegamevar karate
		savegamevar uselaser
		savegamevar useakimbo
		savegamevar depistols
		savegamevar usemossberg
		savegamevar usemp5
		savegamevar usebigrox
		savegamevar pipethrow
		savegamevar usemindblast
		savegamevar dukemon
		savegamevar altfreeze
		savegamevar gravgun
		savegamevar usebots
		savegamevar numbots
		savegamevar knockdist
		savegamevar goodarmor
		savegamevar cangrab
		savegamevar candodge
		savegamevar canmantle
		savegamevar slowrunaccel
		savegamevar lifebars
		savegamevar infighting
		savegamevar killerpigs
		savegamevar storehealth
		savegamevar maxmedkit
		savegamevar steroidkicks
		savegamevar holodukebot
		savegamevar goggleswitches
		savegamevar randomize
		savegamevar rainradius
		savegamevar pdamage
		savegamevar mdamage
		savegamevar mirrored
		savegamevar scaled
		savegamevar doubled
		savegamevar quotestyle
		savegamevar smartmonsters
	}	
	else
	{
		readgamevar menunag
		readgamevar effects
		readgamevar morefx
		ifvarand morefx 32 setactor[THISACTOR].mdflags 1
		readgamevar viewmode
		readgamevar dpsounds
		readgamevar moretalk
		readgamevar karate
		readgamevar uselaser
		readgamevar depistols
		readgamevar useakimbo
		readgamevar usemossberg
		readgamevar usemp5
		readgamevar usebigrox
		readgamevar pipethrow
		readgamevar usemindblast
		readgamevar usebfg
		readgamevar dukemon
		readgamevar altfreeze
		readgamevar gravgun
		readgamevar usebots
		readgamevar numbots
		readgamevar knockdist
		readgamevar goodarmor
		readgamevar cangrab
		readgamevar lifebars
		readgamevar infighting
		ifvare infighting 1 { setvar infighting 20 savegamevar infighting }
		readgamevar killerpigs
		readgamevar slowrunaccel
		readgamevar candodge
		readgamevar canmantle
		readgamevar storehealth
		readgamevar maxmedkit
		readgamevar steroidkicks
		readgamevar holodukebot
		readgamevar goggleswitches
		readgamevar randomize
		readgamevar pdamage
		readgamevar mdamage
		readgamevar mirrored
		readgamevar scaled
		readgamevar doubled
		readgamevar quotestyle
		readgamevar smartmonsters
		ifvare rainstart 0
		{
			readgamevar rainpal
			readgamevar raincstat
			readgamevar rainradius
			//readgamevar raining
			//setvarvar rainstart raining
		}
	}
}


ifvarn playermoves -1
{
	ifvarand playermoves 1 setvar slowrunaccel 1 else setvar slowrunaccel 0
	ifvarand playermoves 2 setvar canmantle 1 else setvar canmantle 0
	ifvarand playermoves 4 setvar candodge 1 else setvar candodge 0
	ifvarand playermoves 8 setvar cangrab 1 else setvar cangrab 0
	ifvarand playermoves 16 setvar moretalk NO else readgamevar moretalk
}
setvar ONCE 1
setvar flares 0
setvar startlights YES
setvar quoterid -1
setvar quoteridpic -1
setvar target 0
ifvare colamachines 0
{
	setvar colamachines 1
	whilevarvarn target NUMWALLS
	{
		getwall[target].picnum picnum
		ifvare picnum COLAMACHINE
		{
			getwall[target].x x
			getwall[target].y y
			getwall[target].point2 tempb
			getwall[tempb].x mx
			getwall[tempb].y my
			
			subvarvar mx x
			subvarvar my y
			getangle angvar mx my

			getwall[tempb].x mx
			getwall[tempb].y my
			
			setvarvar temp x
			setvarvar spriteid mx
			subvarvar temp spriteid
			mulvarvar temp temp
				
			setvarvar spriteid y
			setvarvar tempc my
			subvarvar spriteid tempc
			mulvarvar spriteid spriteid
				
			addvarvar temp spriteid
			sqrt temp temp
			setvarvar xydist temp
			
			addvarvar x mx
			divvar x 2
			addvarvar y my
			divvar y 2
			
			updatesector x y mysector // the sector of the midpoint between the walls
			getflorzofslope mysector x y digz // digz is top of cola machine
			setvarvar zdist digz
			
			subvar angvar 512
			setvarvar mx x
			addvar mx 64
			rotatepoint x y mx y angvar temp my
			updatesectorz temp my digz hitwall // the sector 64 units out from midpoint in one direction
			ifvarvarn hitwall mysector ifvarn hitwall -1
			{
				getflorzofslope hitwall temp my tempd
				ifvarvarg tempd digz 
				{
					setvarvar zdist tempd setvarvar mysector hitwall 
					setvarvar x temp setvarvar y my
				}
			}
			else
			{
				addvar angvar 1024
				rotatepoint x y mx y angvar temp my
				updatesectorz temp my digz hitwall
				ifvarvarn hitwall mysector ifvarn hitwall -1
				{
					getflorzofslope hitwall temp my tempd
					ifvarvarg tempd digz
					{
						setvarvar zdist tempd setvarvar mysector hitwall 
						setvarvar x temp setvarvar y my
					}
				}
			}
			ifvarvare zdist digz // failsafe
			{
				setvarvar tempd digz
				setvar zdist 10240
				rotatepoint x y mx y angvar temp my
				updatesectorz temp my tempd mysector
				ifvare mysector -1
				{
					addvar angvar 1024
					rotatepoint x y mx y angvar temp my
					updatesectorz temp my tempd mysector
				}	
			} else
			{
				subvarvar zdist digz
				ifvarl zdist 0 mulvar zdist -1
			}
			ifvarg zdist 8192 ifvarn mysector -1
			{
				espawn COLAMACHINE
				setactorvar[RETURN].lotag 1
				setactorvar[RETURN].initz zdist
				setactor[RETURN].ang angvar
				setactor[RETURN].x temp
				setactor[RETURN].y my
				setactor[RETURN].z tempd
				
				shiftvarr xydist 4 ifvarg xydist 255 setvar xydist 255
				setactor[RETURN].xrepeat xydist
				
				shiftvarr zdist 9 ifvarg zdist 255 setvar zdist 255
				setactor[RETURN].yrepeat zdist
				setactor[RETURN].sectnum mysector
				setactor[RETURN].cstat 32768
				setactorvar[RETURN].myspawner target
			}
			
		}
		addvar target 1
	}
}

setvar temp OVERHEAT
ifvare temp YES ifvarn usemp5 YES
{
	setvar chaingunheat 0
	setvar tempb MAXCHAINGUNAMMO
	mulvar tempb 2
	smaxammo 3 tempb
	setvar WEAPON3_SHOOTS SHOTGUN
}
setvar clearlocators 1
setvar clearglassarray 1
setvar clearwaypoints 1
ifvarn startweapons -1
{
	ifvarand startweapons 2048 // was set from last map; there is no weapon sprite
		setvar startweapons -1
	else
	{
		ifvarand startweapons 1
			setvar useakimbo YES
	    else setvar useakimbo NO
		ifvarand startweapons 2
		    setvar usemossberg YES
		else setvar usemossberg NO
		ifvarand startweapons 4
		    setvar usemp5 YES
		else setvar usemp5 NO
		ifvarand startweapons 8
		    setvar usebigrox YES
		else setvar usebigrox NO
		ifvarand startweapons 16
		    setvar usemindblast YES
		else setvar usemindblast NO
		ifvarand startweapons 32
			setvar karate YES
		else setvar karate NO
		ifvarand startweapons 64
		    setvar gravgun YES
		else setvar gravgun NO
		ifvarand startweapons 128
		    setvar dukemon YES
		else setvar dukemon NO
		ifvarand startweapons 256
			setvar altfreeze YES
		else setvar altfreeze NO
		ifvarand startweapons 512
		    setvar usebfg YES
		else setvar usebfg NO
		ifvarand startweapons 1024
			setvar depistols YES
		else setvar depistols NO
		orvar startweapons 2048
	}
}
ifvarn startinventory -1
{
	ifvarand startinventory 1024 // was set from last map; there is no inventory sprite
	  setvar startinventory -1
	else
	{
		ifvarand startinventory 1 setvar storehealth YES else setvar storehealth NO
		ifvarand startinventory 2 setvar holodukebot YES else setvar holodukebot NO
		ifvarand startinventory 4 setvar steroidkicks YES else setvar steroidkicks NO
		ifvarand startinventory 8 setvar goggleswitches YES else setvar goggleswitches NO
		ifvarand startinventory 16 setvar goodarmor YES else setvar goodarmor NO
		ifvarand startinventory 32 setvar newjetpack YES else setvar newjetpack NO
		orvar startinventory 1024
	}
}
ifvare dpsounds YES
{
	setvar WEAPON1_FIRESOUND DPPISTOLFIRE
	ifvare usemp5 NO
	setvar WEAPON3_FIRESOUND DPCHAINGUNFIRE
}
ifvare depistols YES
{
	setvar depistols NO
	state changepistols
}
else
{
	setvar depistols YES
	state changepistols
}
ifvare usemossberg YES
{
	ifvarand ALTSHOTGUN 4 nullop // shotgun vars have alrady been set in an earlier level
	else
	{
		setvar WEAPON2_FIREDELAY 2
		setvar WEAPON2_TOTALTIME 26
		setvar WEAPON2_SHOTSPERBURST 8
		setvar WEAPON2_FIRESOUND MOSSFIRE
		setvar WEAPON2_SOUND2TIME 13
		setvar WEAPON2_SOUND2SOUND -1
	}
}
else
{
		// normal shotgun
		ifvarand ALTSHOTGUN 4 nullop else
		{
			setvar WEAPON2_FIREDELAY 4
			setvar WEAPON2_TOTALTIME 30
			setvar WEAPON2_SPAWN SHOTGUNSHELL
			setvar WEAPON2_SHOTSPERBURST 7
			setvar WEAPON2_FIRESOUND SHOTGUN_FIRE
			setvar WEAPON2_SOUND2TIME 15
			setvar WEAPON2_SOUND2SOUND SHOTGUN_COCK	
		}
}
ifvarand ALTCHAINGUN 2
{
	setvar WEAPON3_SHOTSPERBURST 2
	setvar WEAPON3_SHOOTS SHOTSPARK1
	setvar WEAPON3_FIRESOUND BOS1_ATTACK1 // MINIGUN_FIRE
	setvar WEAPON3_FLAGS 84
	setvar WEAPON3_FIREDELAY 2
	setvar WEAPON3_TOTALTIME 12
	// setvar WEAPON3_FIRESOUND DPCHAINGUNFIRE
	setvar WEAPON3_FLAGS 73812
	setvar WEAPON3_CLIP 0
	setvar WEAPON3_SPAWNTIME 0
	setvar WEAPON3_RELOADSOUND1 4
	setvar WEAPON3_RELOADSOUND2 5
}
else
ifvare usemp5 YES
{
	setvar WEAPON3_SHOOTS MP5BULLET
	setvar WEAPON3_TOTALTIME 4
	setvar WEAPON3_FIRESOUND MP5FIRE
	setvar WEAPON3_FLAGS 8196
	setvar WEAPON3_SPAWN 2533
	setvar WEAPON3_CLIP 30
	setvar WEAPON3_SPAWNTIME 2
	setvar WEAPON3_RELOADSOUND1 -1
	setvar WEAPON3_RELOADSOUND2 -1
}
else
{
	// normal chaingun
	setvar WEAPON3_SHOOTS CHAINGUN
	setvar WEAPON3_TOTALTIME 12
	ifvare dpsounds YES
	setvar WEAPON3_FIRESOUND DPCHAINGUNFIRE else
	setvar WEAPON3_FIRESOUND CHAINGUN_FIRE
	setvar WEAPON3_FLAGS 73812
	setvar WEAPON3_CLIP 0
	setvar WEAPON3_SPAWNTIME 0
	setvar WEAPON3_RELOADSOUND1 4
	setvar WEAPON3_RELOADSOUND2 5
}
ifvare usebigrox YES
{
	setvar WEAPON4_CLIP 2
	setvar WEAPON4_FLAGS 1024
	setvar WEAPON4_RELOAD 65 // 78
	setvar WEAPON4_RELOADSOUND1 RPGOPEN
	setvar WEAPON4_RELOADSOUND2 RPGCLOSE
}
else
{
	// normal rpg
	setvar WEAPON4_CLIP 0
	setvar WEAPON4_FLAGS 0
	setvar WEAPON4_RELOAD 0
}
ifvare gravgun YES
{
	setvar WEAPON11_SHOOTS GRAVPROJ2
	setvar WEAPON11_FIRESOUND GRAVSHOOTSND
	setvar WEAPON11_TOTALTIME 20
}
else
{
	// normal expander
	setvar WEAPON11_SHOOTS GROWSPARK
	setvar WEAPON11_FIRESOUND EXPANDERSHOOT
	setvar WEAPON11_TOTALTIME 5
}
ifvare dukemon YES
{
	setplayer[THISACTOR].gotweapon 8 YES
	getplayer[THISACTOR].ammo_amount 8 temp
	ifvarl temp 3 setplayer[THISACTOR].ammo_amount 8 3
	setvar WEAPON8_WORKSLIKE 5
	setvar WEAPON8_FLAGS 512
	setvar WEAPON8_RELOAD 30
	setvar WEAPON8_FIREDELAY 6
	setvar WEAPON8_TOTALTIME 19
	setvar WEAPON8_HOLDDELAY 12
	setvar WEAPON8_SHOOTS HEAVYHBOMB
}
else
{
	// normal tripbombs
	setvar WEAPON8_WORKSLIKE 8
	setvar WEAPON8_FLAGS 3072
	setvar WEAPON8_RELOAD 16
	setvar WEAPON8_FIREDELAY 3
	setvar WEAPON8_TOTALTIME 16
	setvar WEAPON8_HOLDDELAY 7
	setvar WEAPON8_SHOOTS HANDHOLDINGLASER
}
ifvare usebfg YES
state bfgdev else
state normaldev

state normalfreeze
// setvarvar raining rainstart
// setvar rainstart 0
setvar underwater 0
setvar botselected -1
setplayer[THISACTOR].sound_pitch 0

// reset fuse array
setvar temp 0
whilevarn temp 10
{
	setarray fusegroups[temp] 0
	addvar temp 1
}

// reset ptrail array
setvar temp 0
whilevarn temp 100
{
	setarray ptrails[temp] -1
	addvar temp 1
}
	
endevent


state nocodecheck2

getactor[THISACTOR].extra temp
ifvare temp -1
{
	getactor[THISACTOR].hitag temp
	ifvare temp 0
	{
		getactor[THISACTOR].lotag temp
		ifvare temp 0
		{
			getactor[THISACTOR].xvel temp
			ifvare temp 0
			{
				getactor[THISACTOR].yvel temp
				ifvare temp 0
				{
					getactor[THISACTOR].zvel temp
					ifvare temp 0
					{
						getactor[THISACTOR].pal temp
						ifvarl temp 66
						ifvarl pal 66 ifvare lotag 0 ifvare hitag 0
						ifvare monstflags 0 ifvare activator 0
						ifvare droptile 0
						setvar NOCODE 2
					}
				}
			}
		}
	}
}

ends

state nocodecheck1

ifvare mirrored YES
{
	state nocodecheck2
	break
}

getactor[THISACTOR].extra temp
ifvare temp -1
{
	getactor[THISACTOR].hitag temp
	ifvare temp 0
	{
		getactor[THISACTOR].lotag temp
		ifvare temp 0
		{
			getactor[THISACTOR].xvel temp
			ifvare temp 0
			{
				getactor[THISACTOR].yvel temp
				ifvare temp 0
				{
					getactor[THISACTOR].zvel temp
					ifvare temp 0
					{
						getactor[THISACTOR].pal temp
						ifvarl temp 66
						ifvarl pal 66 ifvare lotag 0 ifvare hitag 0
						ifvare monstflags 0 ifvare activator 0
						ifvare droptile 0
						setvar NOCODE 1
					}
				}
			}
		}
	}
}

ends

state scalemap

setvar I 0
whilevarvarn I NUMWALLS
{
    getwall[I].x A
    mulvar A 2
    setwall[I].x A
    getwall[I].y A
    mulvar A 2
    setwall[I].y A
//     getwall[I].xrepeat A
//     divvar A 2
//     setwall[I].xrepeat A
     getwall[I].yrepeat A
     divvar A 2
     setwall[I].yrepeat A

    addvar I 1
}
setvar I 0
whilevarvarn I NUMSECTORS
{
    getsector[I].ceilingz A
    mulvar A 2
    setsector[I].ceilingz A
    getsector[I].floorz A
    mulvar A 2
    setsector[I].floorz A

    addvar I 1
}
setvar I 0
whilevarn I 16384
{
    getactor[I].x A
    mulvar A 2
    setactor[I].x A
    getactor[I].y A
    mulvar A 2
    setactor[I].y A
	getactor[I].z A
	mulvar A 2
	setactor[I].z A
    
    getactor[I].xrepeat mx
    mulvar mx 2
    ifvarg mx 255 setvar mx 255
    setactor[I].xrepeat mx
    getactor[I].yrepeat my
    mulvar my 2
    ifvarg my 255 setvar my 255
    setactor[I].yrepeat my
    
    getactor[I].picnum picnum
    ifvare picnum GPSPEED
    {
	    getactor[I].sectnum temp
	    setvar tempb 0
	    headspritesect spriteid temp
	    whilevarn spriteid -1
	    {
		    getactor[spriteid].picnum picnum
		    ifvare picnum SECTOREFFECTOR
		    {
			    getactor[spriteid].lotag tempc
			    ifvare tempc 36 setvar tempb 1
		    }
		    ifvare picnum CYCLER
		    {
			    setvar tempb 1
		    }
		    nextspritesect spriteid spriteid
	    }
	    ifvare tempb 0 // do not double lotag if a shooter SE is in the sector
	    {
		    getactor[I].lotag temp
			mulvar temp 2
			setactor[I].lotag temp
		}
    }
    
    addvar I 1
}
ends


onevent EVENT_LOADACTOR

ifvare DONE NO
{
	state redefinequotes
	readgamevar morefx
	
	ifmultiplayer nullop else
	{
		readgamevar mirrored
		ifvare mirrored YES state mirror
	}
	readgamevar scaled
	ifvare scaled YES state scalemap
	readgamevar doubled
	setvar DONE YES
	
	ifmultiplayer nullop else
	{
		// thanks to Hunter_Rus for randomizer
		readgamevar randomstart
		addvar randomstart 1
		andvar randomstart 65535
		setvarvar temp randomstart
		xorvar temp 43690
		whilevarn temp 0
	    {
	    ifrnd 1 { }
	    subvar temp 1
	    }
	    savegamevar randomstart
    }
    
}

getactor[THISACTOR].picnum picnum
ifvare initcstat -1 getactor[THISACTOR].cstat initcstat

switch picnum

case ACCESSSWITCH
case ACCESSSWITCH2
break

case WATERTILE2
case WATERFLOW
case DPWATERTILE
getactor[THISACTOR].xrepeat initx
getactor[THISACTOR].yrepeat inity // only for water tiles
case CAMERA1
case SHOTGUNSPRITE
case CHAINGUNSPRITE
case BATTERYAMMO

state nocodecheck2
break

case 507
getactor[THISACTOR].lotag lotag
ifvare lotag 1
{
	cstator 32768
	cstator 1
}
break

case 908 case 910 // tree
getactor[THISACTOR].lotag lotag
ifvarn lotag 0
setactor[THISACTOR].lotag 0
state nocodecheck2
break

case CRACK1
case CRACK2
case CRACK3
case CRACK4
getactor[THISACTOR].yvel activator
state nocodecheck1
break

// dead body sprites
case 677 // EGG
case 1734 // LIZTROOP
case 1855 // OCTABRAIN
case 1957 // COMMANDER
case 2060 // PIGCOP
case 2185 // LIZMAN
case 2685 // BOSS1
case 2758 // BOSS2
case 2809 // BOSS3
case 4689 // NEWBEAST
case 4789 // BOSS4
break

case SEENINE
case FIREEXT
case OOZFILTER
getactor[THISACTOR].lotag lotag
getactor[THISACTOR].hitag hitag
getactor[THISACTOR].extra monstflags
setvar weight WEIGHT2
setvar bouncesound BOUNCEMETALSND
getactor[THISACTOR].xrepeat temp
ifvarl temp 5 setvar NOCODE 1 else state nocodecheck2
orvar initcstat 256
break

case CANWITHSOMETHING
case CANWITHSOMETHING2
case CANWITHSOMETHING3
case CANWITHSOMETHING4
getactor[THISACTOR].lotag lotag
getactor[THISACTOR].hitag hitag
setvar weight WEIGHT2
setvar bouncesound METALTHUD
orvar initcstat 257
break

case CAMERALIGHT
case TRIPODCAMERA
case VACUUM
case IVUNIT
case MOVIECAMERA
case VASE
case 691
case 692
case 693
case POT1
case POT2
case AMERICANFLAG
setvar weight WEIGHT2
setvar bouncesound BOUNCEMETALSND
ifactor VASE setvar bouncesound PIPEBOMB_BOUNCE
state nocodecheck2
orvar initcstat 256
break

case CHAIR1
case CHAIR2
case CHAIR3
case BROKENCHAIR
case WAITTOBESEATED
setvar weight WEIGHT2
state nocodecheck2
orvar initcstat 256
break

case GUNPOWDERBARREL
setvar weight WEIGHT3
state nocodecheck2
orvar initcstat 257
setvar bouncesound ENDSEQVOL2SND4
break


case DUKECUTOUT
setvar weight WEIGHT2
setvar bouncesound ENDSEQVOL2SND4
state nocodecheck2
orvar initcstat 256
break

case TOILET
case HYDRENT
setvar weight WEIGHT3
setvar bouncesound METALTHUD
orvar initcstat 256
break

case BOTTLE1
case BOTTLE2
case BOTTLE3
case BOTTLE4
case BOTTLE5
case BOTTLE6
case BOTTLE7
case BOTTLE8
case BOTTLE10
case BOTTLE11
case BOTTLE12
case BOTTLE13
case BOTTLE14
case BOTTLE15
case BOTTLE16
case BOTTLE17
case BOTTLE18
case BOTTLE19
case FETUS
case FETUSBROKE
case POT3
case SUSHIPLATE1
case SUSHIPLATE2
case SUSHIPLATE3
case SUSHIPLATE4
case SUSHIPLATE5
case CONE
case BOX
case DESKLAMP
setvar weight WEIGHT1
setvar bouncesound PIPEBOMB_BOUNCE
ifactor BOTTLE11 setvar bouncesound BOUNCEMETALSND
ifactor CONE setvar bouncesound FOODLAND
ifactor BOX setvar bouncesound FOODLAND
ifactor FETUSBROKE setvar bouncesound JIBLAND
state nocodecheck2
orvar initcstat 256
break

case HYDROPLANT
cactor DPHYDROPLANT
orvar initcstat 256
state nocodecheck2
setvar weight WEIGHT3
setvar bouncesound GENERICBOUNCE
break

case RECON
case RECONDP
state eventloadactorstate
break

case EGG
case LIZTROOP
case LIZTROOPSTAYPUT
case LIZTROOPSHOOT
case LIZTROOPJETPACK
case LIZTROOPRUNNING
case LIZTROOPONTOILET
case LIZTROOPJUSTSIT
case LIZTROOPDUCKING
case OCTABRAIN
case OCTABRAINSTAYPUT
case DRONE
case COMMANDER
case COMMANDERSTAYPUT
case TANK
case PIGCOP
case PIGCOPSTAYPUT
case PIGCOPDIVE
case LIZMAN
case LIZMANSTAYPUT
case LIZMANJUMP
case LIZMANSPITTING
case ROTATEGUN
case BOSS1
case BOSS1STAYPUT
case BOSS2
case BOSS3
case BOSS4
case BOSS4STAYPUT
case SHARK
case MINIBEAST
case FEM1
case FEM2
case FEM3
case FEM4
case FEM5
case FEM6
case FEM7
case FEM8
case FEM9
case FEM10
case TOUGHGAL
case NAKED1
case PODFEM1
case BLOODYPOLE
case FEM6PAD

orvar initcstat 256
state nocodecheck1
state eventloadactorstate 
ifvare doubled YES state duplicate
break

case RESPAWN
setvar NOCODE 1
state eventloadactorstate 
ifvare doubled YES state duplicate
break


case NEWBEAST
case NEWBEASTSTAYPUT
case NEWBEASTHANG
case NEWBEASTJUMP
sizeat 40 40
orvar initcstat 256
state nocodecheck1
state eventloadactorstate 
ifvare doubled YES state duplicate
break

case BOUNDINGBOX
cstator 33025
setactor[THISACTOR].clipdist sprite[THISACTOR].xrepeat
break

default

	ifvare droptile 0 getactor[THISACTOR].xvel droptile
	state nocodecheck1
break
endswitch

getactor[THISACTOR].pal temp
ifvarg pal 69 setvarvar temp pal
ifactor SPAWNER nullop else ifactor SECTOREFFECTOR nullop else
ifvarg temp 69
{
	spriteflags 4
	subvar temp 70
	setactor[THISACTOR].pal temp
	setvarvar pal temp
	getactor[THISACTOR].shade initshade
	setvarvar peractor7 initshade
	setvar pulse 1 
	setvarvar temp droptile
	ifvare temp 0
	getactor[THISACTOR].hitag temp
	addvarvar pulse temp
}

ifvarn group 0
{
	setvarvar temp mongroup[group]
	addvar temp 1
	setarray mongroup[group] temp
}

endevent