
//scriptsize 332976
setdefname dukeplus.def
setcfgname dp.cfg
setgamename Duke Plus 1.8

//include DukePlus/dpcons/DPDEFS.CON
//include DukePlus/dpcons/DPDEFS.CON
include DEFS.CON
include USER.CON
include DukePlus/dpcons/USERPLUS.CON
include DukePlus/dpcons/LIGHTS.CON

//include DukePlus/USERPLUS.CON
//include DukePlus/LIGHTS.CON

define RAINSPRITE 2287
define LIFEBAR 1389
define WATERFLOW 889
define RECONDP 1966
define XIT 2963
define CONCRETEHOLE1 8025
define CONCRETEHOLE2 3460
define ELECTRONICHOLE 3466
define METALHOLE 3462
define ORGANICHOLE 3467
define WOODHOLE 3464
define TOILET2 3506
define HYDRENT2 3507
define EGGCORPSE 677
define LIZTROOPCORPSE 1734
define OCTABRAINCORPSE 1855
define COMMANDERCORPSE 1957
define PIGCOPCORPSE 2060
define LIZMANCORPSE 2185
define BOSS1CORPSE 2685
define BOSS2CORPSE 2758
define BOSS3CORPSE 2809
define NEWBEASTCORPSE 4689
define BOSS4CORPSE 4789

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
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
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].extra monstflags

ifmultiplayer nullop else
{
	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
	break
	case LIZTROOP
	setvar monstflags LIZTROOP_FLAGS
	break
	case LIZTROOPSTAYPUT
	setvar monstflags LIZTROOP_FLAGS
	break
	case LIZTROOPSHOOT
	setvar monstflags LIZTROOP_FLAGS
	break
	case LIZTROOPJETPACK
	setvar monstflags LIZTROOP_FLAGS
	break
	case LIZTROOPONTOILET
	setvar monstflags LIZTROOP_FLAGS
	break
	case LIZTROOPJUSTSIT
	setvar monstflags LIZTROOP_FLAGS
	break
	case LIZTROOPDUCKING
	setvar monstflags LIZTROOP_FLAGS
	break
	case OCTABRAIN
	setvar monstflags OCTABRAIN_FLAGS
	break
	case OCTABRAINSTAYPUT 
	setvar monstflags OCTABRAIN_FLAGS
	break
	case DRONE
	setvar monstflags DRONE_FLAGS
	break
	case COMMANDER
	setvar monstflags COMMANDER_FLAGS
	break
	case COMMANDERSTAYPUT
	setvar monstflags COMMANDER_FLAGS
	break
	case TANK
	setvar monstflags TANK_FLAGS
	break
	case PIGCOP
	setvar monstflags PIGCOP_FLAGS
	break
	case PIGCOPSTAYPUT
	setvar monstflags PIGCOP_FLAGS
	break
	case PIGCOPDIVE
	setvar monstflags PIGCOP_FLAGS
	break
	case LIZMAN
	setvar monstflags LIZMAN_FLAGS
	break
	case LIZMANSTAYPUT
	setvar monstflags LIZMAN_FLAGS
	break
	case LIZMANJUMP
	setvar monstflags LIZMAN_FLAGS
	break
	case ROTATEGUN
	setvar monstflags ROTATEGUN_FLAGS
	break
	case BOSS1
	setvar monstflags BOSS1_FLAGS
	break
	case BOSS1STAYPUT
	setvar monstflags BOSS1_FLAGS
	break
	case BOSS2
	setvar monstflags BOSS2_FLAGS
	break
	case BOSS3
	setvar monstflags BOSS3_FLAGS
	break
	case NEWBEAST
	setvar monstflags NEWBEAST_FLAGS
	break
	case NEWBEASTSTAYPUT
	setvar monstflags NEWBEAST_FLAGS
	break
	case NEWBEASTHANG
	setvar monstflags NEWBEAST_FLAGS
	break
	case NEWBEASTJUMP
	setvar monstflags NEWBEAST_FLAGS
	break
	case BOSS4
	setvar monstflags BOSS4_FLAGS
	break
	case BOSS4STAYPUT
	setvar monstflags BOSS4_FLAGS
	break
	case SHARK
	setvar monstflags SHARK_FLAGS
	break
	case RECONDP
	setvar monstflags RECONDP_FLAGS
	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
	setvar droptile LIZTROOP_DROPS
	break
	case LIZTROOPSTAYPUT
	setvar droptile LIZTROOP_DROPS
	break
	case LIZTROOPSHOOT
	setvar droptile LIZTROOP_DROPS
	break
	case LIZTROOPJETPACK
	setvar droptile LIZTROOP_DROPS
	break
	case LIZTROOPONTOILET
	setvar droptile LIZTROOP_DROPS
	break
	case LIZTROOPJUSTSIT
	setvar droptile LIZTROOP_DROPS
	break
	case LIZTROOPDUCKING
	setvar droptile LIZTROOP_DROPS
	break
	case OCTABRAIN
	setvar droptile OCTABRAIN_DROPS
	break
	case OCTABRAINSTAYPUT 
	setvar droptile OCTABRAIN_DROPS
	break
	case DRONE
	setvar droptile DRONE_DROPS
	break
	case COMMANDER
	setvar droptile COMMANDER_DROPS
	break
	case COMMANDERSTAYPUT
	setvar droptile COMMANDER_DROPS
	break
	case TANK
	setvar droptile TANK_DROPS
	break
	case PIGCOP
	setvar droptile PIGCOP_DROPS
	break
	case PIGCOPSTAYPUT
	setvar droptile PIGCOP_DROPS
	break
	case PIGCOPDIVE
	setvar droptile PIGCOP_DROPS
	break
	case LIZMAN
	setvar droptile LIZMAN_DROPS
	break
	case LIZMANSTAYPUT
	setvar droptile LIZMAN_DROPS
	break
	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
	setvar droptile NEWBEAST_DROPS
	break
	case NEWBEASTSTAYPUT
	setvar droptile NEWBEAST_DROPS
	break
	case NEWBEASTHANG
	setvar droptile NEWBEAST_DROPS
	break
	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
	endswitch
}
setactor[THISACTOR].extra -1
ends

define GUSTSPAWNER 2946
define SMOKEGUST 8055
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
}
getactor[THISACTOR].roll temp
addvar temp 4
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

getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z
updatesectorz x y z mysector
ifvare mysector -1 killit
ifnotmoving killit
ifvarg countvarb 0 ifvarvarg countvar countvarb killit
addvar countvar 1
enda


define HEIGHTSPRITE 2947
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

define LIGHTBUG 4884
define LIGHTBUG2 4863
spritenopal LIGHTBUG2
eventloadactor LIGHTBUG
{
	getactor[THISACTOR].lotag lotag
	//ifvare lotag 1
	//setactor[spriteid].picnum LIGHTBUG2
}

enda

define LIGHTLOADER 2943
eventloadactor LIGHTLOADER
{
	getactor[THISACTOR].lotag lotag
	ifvare lotag 1
	{
		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
	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].pal playerally // for storing fog pal in water sectors
	getactor[THISACTOR].sectnum mysector
	getsector[mysector].floorpal pal
	getsector[mysector].ceilingpal peractor7
	getactor[THISACTOR].shade initshade
	ifvare lotag 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 lighting YES
		{
			setactor[THISACTOR].lotag 108
			setvar lotag 108
		}
	}
	ifvarg lotag 115 ifvarl lotag 120
	  ifvarl topladder 0 mulvar initshade -1 // correctly sets destination position of elevator
}
enda

eventloadactor CYCLER
{
	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 lighting YES
	{
		setactor[THISACTOR].lotag 107
		setvar lotag 107
		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 
	setactor[THISACTOR].extra 0
} 
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

define SPAWNER 2958
define SHOOTER 2959
define WAYPOINT 1490

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

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

getactor[THISACTOR].picnum command
ends

// state enterquotearray

// setvarvar tempb ftscalearray[3]
// ifvarg tempb 0
// {
// 	setarray ftscalearray[4] tempb
// 	setvarvar tempc ftqarray[3]
// 	setarray ftqarray[4] tempc
// }
// setvarvar tempb ftscalearray[2]
// ifvarg tempb 0
// {
// 	setarray ftscalearray[3] tempb
// 	setvarvar tempc ftqarray[2]
// 	setarray ftqarray[3] tempc
// }
// setvarvar tempb ftscalearray[1]
// ifvarg tempb 0
// {
// 	setarray ftscalearray[2] tempb
// 	setvarvar tempc ftqarray[1]
// 	setarray ftqarray[2] tempc
// }
// setvarvar tempb ftscalearray[0]
// ifvarg tempb 0
// {
// 	setarray ftscalearray[1] tempb
// 	setvarvar tempc ftqarray[0]
// 	setarray ftqarray[1] tempc
// }

// setarray ftqarray[0] temp
// setarray ftscalearray[0] QUOTEDISPLAYSIZE

// setvarvar temp ftscalearray[1]
// ifvarg temp SMALLERQUOTEDSIZE setarray ftscalearray[1] SMALLERQUOTEDSIZE

// setvar tempb SMALLERQUOTEDSIZE
// subvar tempb 20480
// setvarvar temp ftscalearray[2]
// ifvarvarg temp tempb setarray ftscalearray[2] tempb
// subvar tempb 20480
// setvarvar temp ftscalearray[3]
// ifvarvarg temp tempb setarray ftscalearray[3] tempb
// subvar tempb 20480
// setvarvar temp ftscalearray[4]
// ifvarvarg temp tempb setarray ftscalearray[4] tempb

// ends



state itemquote

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

ifvare quotestyle 2 { userquote RETURN break }

setvar fta 130
setvarvar ftq RETURN

ends

action HELIFRAMES -1 2 1 1 1

define HELICOPTER 1338
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

move HELIMOVE

useractor notenemy HELICOPTER 0

ifvare lotag 0 break

ifmove 0
{
	ifaction 0 action HELIFRAMES
	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
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
{
	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
	endswitch
} 
enda

state activatorstate

setvar countvarb 0
whilevarn countvarb 16384
{
	getactor[countvarb].picnum picnum
	switch picnum
	//case ACTIVATOR case ACTIVATORLOCKED 
	case SPAWNER
	case SHOOTER
	case SECTOREFFECTOR
	getactor[countvarb].lotag tempb
	ifvare picnum SPAWNER
	{
		getactorvar[countvarb].lotag tempc
		ifvarvare tempc activator setactorvar[countvarb].mtype 1
	} else
	ifvare picnum SHOOTER
	{
		getactorvar[countvarb].lotag tempc
		ifvarvare tempc activator 
			setactorvar[countvarb].mtype 1
		else
		{
			addvar tempc 1
			ifvarvare tempc activator
			  setactorvar[countvarb].mtype 0
		}
		
	} else
	ifvare picnum SECTOREFFECTOR
	{
		getactorvar[countvarb].activator tempc
		ifvarvare tempc activator 
		{
			ifvarn peractor1 0 setactorvar[countvarb].peractor1 2 else
			setactorvar[countvarb].peractor1 1
		}
	}

	break
	
	case HELICOPTER
	getactorvar[countvarb].activator tempc
	ifvarvare tempc activator setactorvar[countvarb].peractor1 1
	break
	
	case FUSE
	getactorvar[countvarb].topladder tempc
	ifvarvare tempc activator setactorvar[countvarb].topladder 0
	break
	
	case WAYPOINT
	getactorvar[countvarb].target2 tempc
	ifvarvare tempc activator setactorvar[countvarb].target2 0
	break
	
	endswitch
	addvar countvarb 1
}
operatemasterswitches activator
operaterespawns activator
operateactivators activator 0
	
ends

define DPTOUCHPLATE 2940
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

define DNSWITCH 8032
define UPSWITCH 8037
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


define BOTALLY 1431
define BOTALLYCROUCH 1471
eventloadactor APLAYER
ifmultiplayer nullop else
{
	readgamevar played
	ifvarn played 0
	readgamevar usebots
	ifvare usebots YES
	{
		getactor[THISACTOR].lotag lotag
		ifvare lotag 1
		{
			setactor[THISACTOR].picnum BOTALLY
			ifrnd 64 orvar monstflags 8 // medic
			ifrnd 128 orvar monstflags 16 // shotgun
			ifrnd 96 orvar monstflags 32 // chaingun
			ifrnd 64 orvar monstflags 64 // rpg
			ifrnd 48 orvar monstflags 128 // freezer
		}
	}
}
enda

eventloadactor 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
enda

define LADDER 2951
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

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

state turnoffmodels

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

state turnoffanim

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


define NOMODEL 2953
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

define NOISESPRITE 2954
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
	cstat 32768
	setvar NOCODE 1
}
enda

useractor notenemy NOISESPRITE 0

ifvarn lotag 1 break

ifvare mtype 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

define QUOTER 2956
eventloadactor QUOTER
getactor[THISACTOR].lotag lotag
// lotag 1 = quoter, lotag 2 = picture
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

ifvarn lotag 1 ifvarn lotag 2 ifvarn lotag 3 break

ifvare mtype 0
{
	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
	}
}

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

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

eventloadactor SHOOTER

getactor[THISACTOR].lotag lotag
ifvarn lotag 0 // lotag -1 or 1 = activate on sight, 2 or > = activated remotely
{
	setactor[THISACTOR].lotag 0
	getactor[THISACTOR].hitag hitag // the tilenum of the projectile it shoots
	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
	getactor[THISACTOR].extra monstflags // bitfield:  -1, 0 = no aiming, 2 = aims at player and friends, 4 = aims at bad guys, 8 = randomized
	ifvare monstflags -1 setvar monstflags 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
	setactor[THISACTOR].cstat 32768
	getactor[THISACTOR].ang position
}

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
	startlevel VOLUME hitag
}

enda

state attachfloor

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

ends

move BLOODMOVE 12

state newbloodstate

ifp ponground ifpdistl 512
{
	getactor[THISACTOR].pal temp
	ifvare temp 0
	setplayer[THISACTOR].footprintpal 2
	else 
	setplayer[THISACTOR].footprintpal temp
	setplayer[THISACTOR].footprintcount 3
}


fall

getsector[THISACTOR].floorshade temp
addvar temp 10
setactor[THISACTOR].shade temp

iffloordistl 1 ifvare mtype 0
{
	setvar peractor1 0
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].z z
	getactor[THISACTOR].sectnum mysector
	setvarvar mx x
	addvar mx 320
	setvar angvar 0
	whilevarn angvar 2048
	{
		rotatepoint x y mx y angvar hitx hity
		updatesectorz hitx hity z temp
		ifvarvarn temp mysector ifvarn temp -1
		{
			getflorzofslope temp hitx hity mz
			subvarvar mz z
			ifvarg mz 256
				setvar peractor1 1 // killit
			
		}
		addvar angvar 512
		ifvare peractor1 1 setvar angvar 2048
	}
	ifvare peractor1 1 { killit break }
	move INIT
	setvar mtype 1
	getsector[THISACTOR].floorstat temp
	ifvarand temp 1 killit else
	ifvarand temp 2 killit else
	insertspriteq
	cstat 160
	ifrnd 128 cstator 4
	ifrnd 128 cstator 8
	state attachfloor
}

ends



useractor notenemy NEWBLOOD1 0
ifmove 0
{
	//ifspritepal 0 spritepal 2
	ifspritepal 6 nullop else spritepal 2
	randvar angvar 2047
	setactor[THISACTOR].ang angvar
	clipdist 0
	setvar temp 128
	ifrnd 128 addvar temp 4
	ifrnd 128 addvar temp 8
	setactor[THISACTOR].cstat temp
	randvar temp 4
	addvar temp 4
	setactor[THISACTOR].xrepeat temp
	randvar temp 4
	addvar temp 4
	setactor[THISACTOR].yrepeat temp
	
	randvar tempb 3
	switch tempb
	case 0 cactor NEWBLOOD2 break
	case 1 cactor NEWBLOOD3 break
	case 2 cactor NEWBLOOD4 break
	endswitch
	move BLOODMOVE geth
}
state newbloodstate
enda

useractor notenemy NEWBLOOD2 0
state newbloodstate
enda
useractor notenemy NEWBLOOD3 0
state newbloodstate
enda
useractor notenemy NEWBLOOD4 0
state newbloodstate
enda
useractor notenemy NEWBLOOD5 0
state newbloodstate
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

define SCORCH 3457
spritenoshade SCORCH

useractor notenemy SCORCH 0

ifspritepal 3 break

ifmove 0
{
	ifvare lotag 0 ifvare hitag 0 ifawayfromwall killit
	move INIT
	ifvarn initx 0 sizeat 4 4 else
	sizeat 16 16 //64 64
	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 }
	getwall[target].nextsector target2
	
	ifvarn target2 -1
	{
    	getsector[target2].lotag temp
    	switch temp
    	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
	    killit
	    break
	    endswitch
	}
	
	
	// calculate distance to wallpoint
	// calculate distance to wallpoint2
	// if either ditance is short, shrink accordingly
	setvar xydist2 8192
	getwall[target].x hitx
	// setvarvar hp hitx
	getwall[target].y hity
	state pythagoras	
	setvarvar xydist2 xydist
	getwall[target].point2 currwall
	getwall[currwall].x hitx
	// setvarvar weap hitx
	getwall[currwall].y hity
	state pythagoras
	
	// we need to check angle to the next wallpoint before we decide that this is a distance to worry about
	getwall[currwall].point2 wallpoint
	getwall[wallpoint].x digx
	getwall[wallpoint].y digy
	subvarvar hitx digx
	subvarvar hity digy
	getangle tempb digx digy
    getactor[THISACTOR].ang angvar
    getincangle tempd angvar tempb
    ifvarl tempd 0 mulvar tempd -1
    ifvarg tempd 128
	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
		}
				
	}
	
}

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

ifvarn target -1
{
	getwall[target].shade shade
	ifvarl shade 0 setvar shade 0
	addvar shade 5
	setactor[THISACTOR].shade shade
}
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

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

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

useractor notenemy WOODHOLE 0
ifmove 0
{
	sizeat 4 4
	cstator 2
	move INIT
	insertspriteq
	eqspawn 3465
	{
		getactor[THISACTOR].cstat temp
		subvar temp 2
		setactor[RETURN].cstat temp
		setactor[RETURN].xrepeat 4
		setactor[RETURN].yrepeat 4
		getactor[THISACTOR].ang angvar
		setactor[RETURN].ang angvar
	}
}
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


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 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
		setvarvar countvar countvarb
		subvar monstatus 1
	}
	subvar countvar 1
}
enda


define WEAPONS 2962
eventloadactor WEAPONS
{
	getactor[THISACTOR].lotag lotag
	ifvare lotag 1
	{
		getactor[THISACTOR].extra startweapons
		setactor[THISACTOR].lotag 0
		killit
	}
}
enda

state rollfordrop

// about 5% chance of drop
ifrnd 12
{
	randvar temp 100
	ifvarl temp 18 setvar picnum COLA else
	ifvarl temp 25 setvar picnum SIXPAK else
	ifvarl temp 30 setvar picnum FIRSTAID else
	ifvarl temp 35 setvar picnum ATOMICHEALTH else
	ifvarl temp 42 setvar picnum AMMO else
	ifvarl temp 46 setvar picnum FIRSTGUNSPRITE else
	ifvarl temp 50 setvar picnum SHOTGUNAMMO else
	ifvarl temp 52 { ifvare usemossberg YES ifrnd 96 setvar picnum DBSPRITE else setvar picnum SHOTGUNSPRITE } else
	ifvarl temp 56 setvar picnum BATTERYAMMO else
	ifvarl temp 58 setvar picnum CHAINGUNSPRITE else
	ifvarl temp 62 setvar picnum RPGAMMO else
	ifvarl temp 64 setvar picnum RPGSPRITE else
	ifvarl temp 68 setvar picnum HEAVYHBOMB else
	ifvarl temp 70 setvar picnum HBOMBAMMO else
	ifvarl temp 73 setvar picnum CRYSTALAMMO else
	ifvarl temp 76 setvar picnum GROWAMMO else
	ifvarl temp 78 setvar picnum SHRINKERSPRITE else
	ifvarl temp 82 setvar picnum DEVISTATORAMMO else
	ifvarl temp 82 setvar picnum DEVISTATORSPRITE else
	ifvarl temp 83 setvar picnum TRIPBOMBSPRITE else
	ifvarl temp 86 setvar picnum FREEZEAMMO else
	ifvarl temp 88 setvar picnum FREEZESPRITE else
	ifvarl temp 90 setvar picnum HOLODUKE else
	ifvarl temp 92 setvar picnum HEATSENSOR else
	ifvarl temp 94 setvar picnum BOOTS else
	ifvarl temp 95 setvar picnum JETPACK else
	ifvarl temp 96 setvar picnum AIRTANK else
	setvar picnum SHIELD
	espawnvar picnum
	setactorvar[RETURN].peractor4 13
	randvar angvar 2047
	setactor[RETURN].ang angvar
}

ends

state randomdrop

ifactor TRIPBOMBSPRITE break

setvar peractor1 20 // peractor1 will be the value of the monster
ifactor PIGCOP addvar peractor1 25
ifactor PIGCOPDIVE addvar peractor1 25
ifactor LIZMAN addvar peractor1 35
ifactor OCTABRAIN addvar peractor1 20
ifactor COMMANDER addvar peractor1 40
ifactor DRONE addvar peractor1 10
ifactor NEWBEAST ifvarn mtype 1 addvar peractor1 30
ifactor EGG subvar peractor1 10
ifactor BOSS1 addvar peractor1 80
ifactor BOSS2 addvar peractor1 80
ifactor BOSS3 addvar peractor1 80
ifactor BOSS4 addvar peractor1 80
ifactor RECON addvar peractor1 20
ifactor RECONDP addvar peractor1 25
ifvarand monstflags 128 addvar peractor1 15
ifvarand monstflags 512 addvar peractor1 10
ifvarand monstflags 1024 addvar peractor1 10
ifvarand monstflags 2048 addvar peractor1 5

ifvarand monstflags 2 { mulvar peractor1 3 divvar peractor1 2 }
ifvarand monstflags 4 mulvar peractor1 2
ifvarand monstflags 8 { mulvar peractor1 3 divvar peractor1 2 }
ifvarand monstflags 64 mulvar peractor1 2 else
ifvarand monstflags 32 { mulvar peractor1 3 divvar peractor1 2 } else
ifvarand monstflags 16 { mulvar peractor1 3 divvar peractor1 2 }

shiftvarr peractor1 3
ifvarl peractor1 2 setvar peractor1 2
setvar botclip 0
whilevarvarn botclip peractor1
{
	state rollfordrop
	addvar botclip 1
}

ends

state specialdeath // for special events that happen when monsters die

ifvarg intensity 0 
{
	state exitlightarray
	setvar intensity 0
}

setvar monstatus 2 // dead
ifvarn activator 0 state activatorstate
setvar activator 0
ifvarn randomize 0 
{
	ifvare droptile -1 break 
	state randomdrop 
	ifvarn randomize 0 setvar droptile -1 
}
ifvarl droptile 1 break
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
ifactor ROTATEGUN nullop else
setactorvar[RETURN].peractor4 13
setvar droptile 0

ends

state gradualturn
// assumes target is set

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
ifactor FIREBALLPROJ addvar angvar 1024
getactor[THISACTOR].ang tempb
getincangle tempd angvar tempb

ifvarl tempd 17 ifvarg tempd -17
{
	setactor[THISACTOR].ang angvar
	break
}
ifactor RECONDP
{
	ifvarl tempd 33 ifvarg tempd -33
	{
		setactor[THISACTOR].ang angvar
		break
	}
}

ifvarl tempd 0 
{
	addvar tempb 16
	ifactor RECONDP addvar tempb 16 
}
else
ifvarg tempd 0 
{
	subvar tempb 16
	ifactor RECONDP subvar tempb 16
}

setactor[THISACTOR].ang tempb

ends

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
}

getactor[THISACTOR].htextra temp
ifvarg temp 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 temp
					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 subvar temp 1
		ifvarand temp 256 subvar temp 256
		setactor[THISACTOR].cstat temp
	}
}
	

enda

gamearray fusegroups 10 // this array stores the number of fuses that have been placed in each group

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
{
  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 
  {
	  action SHELLROLLING
	  ifrnd 128 sound SHELLFALL1 else sound SHELLFALL2
  }
  else
  {
	  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
	    resetcount
    }
}

  
ifmove SHELLROLL1 ifcount 22 { move SHELLROLL2 geth resetcount }
ifmove SHELLROLL2 ifcount 16 { move SHELLROLL3 geth resetcount }
ifmove SHELLROLL3 
  ifcount 12
    ifrnd 32 
{
     move SHELLSTOP
     ifactor 2534 action SHELLSTOPPED
     ifrnd 128 cstat 388
      
     getactor[THISACTOR].x x
     getactor[THISACTOR].y y
     getactor[THISACTOR].sectnum mysector
     getflorzofslope mysector x 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
	}
	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
	} 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 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 nullop 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 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
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 4
          ifvare holding -1
{
	resetcount
	addvar countvar 1
	sound COINSLOT
}

ifvarg countvar 2
{
	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

state shelleject
espawn SHELL
setactor[RETURN].xrepeat 8
setactor[RETURN].yrepeat 8
getactor[THISACTOR].ang angvar
addvar angvar 512
setactor[RETURN].ang angvar
randvar temp 64
addvar temp 64
setactor[RETURN].xvel temp
ends

state shelleject2
ifactor PIGCOPDIVE
{
	getactor[THISACTOR].z z
	addvar z 4096
	setactor[THISACTOR].z z
}
espawn SHOTGUNSHELL
setactor[RETURN].xrepeat 8
setactor[RETURN].yrepeat 8
getactor[THISACTOR].ang angvar
addvar angvar 512
setactor[RETURN].ang angvar
randvar temp 32
addvar temp 32
setactor[RETURN].xvel temp
ifactor PIGCOPDIVE
{
	getactor[THISACTOR].z z
	subvar z 4096
	setactor[THISACTOR].z z
}
ends


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

useractor notenemy SHOTGUNSHELL 0 state shellcode enda

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
	ifvare effects YES nullop else
	spawn BLOODPOOL
	ifactor 1769 strength 50
	ifactor 2202 strength 50
}

setvar temp 0
ifactor 1769 setvar temp 1 
ifactor 2202 setvar temp 1
ifvare temp 1
{
	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
		spawn BLOODPOOL
		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 1769 nullop else
ifactor 2202 nullop else
strength 0
ifhitweapon 
	ifdead { guts JIBS6 2 killit }
	


ends

action JIBMODELFRAME1 1210 1 1 1 1

state jibcode2
fall
ifvare countvar 0
{
	cstat 256
	ifrnd 128 cstator 4
	action JIBSTILL2
	setvar countvar 1
	ifvare effects YES nullop else
	spawn BLOODPOOL
	ifactor 2264 ifvare effects YES action JIBMODELFRAME1
	state attachfloor
}
strength 0
ifhitweapon { guts JIBS6 2 killit }

ends

useractor notenemy 1769 state jibcode enda // HEADJIB1
useractor notenemy 1773 state jibcode enda // ARMJIB1
useractor notenemy 1777 state jibcode enda // LEGJIB1
useractor notenemy 2249 state jibcode2 enda // JIBS1 = ?
useractor notenemy 2254 state jibcode2 enda // JIBS2 = eyeball
useractor notenemy 2259 state jibcode2 enda // JIBS3 = heart
useractor notenemy 2264 state jibcode2 enda // JIBS4 = guts
useractor notenemy 2269 state jibcode2 enda // JIBS5 = ribcage
useractor notenemy 2202 state jibcode enda // LIZMANHEAD1
useractor notenemy 2206 state jibcode enda // LIZMANARM1
useractor notenemy 2210 state jibcode enda // LIZMANLEG1

define CORONA1 1632
eventloadactor CORONA1

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

enda

define CORONA2 1633
eventloadactor CORONA2

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

enda

define MAPSTAR 1635
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

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

define JUMPAD 2949

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

// define MOVEBLOCKA 8060
// define MOVEBLOCKB 8061
// eventloadactor MOVEBLOCKA
// {
//   getactor[THISACTOR].hitag hitag
//   getactor[THISACTOR].lotag lotag
//   getactor[THISACTOR].extra monstflags
//   setactor[THISACTOR].hitag 0
//   setactor[THISACTOR].lotag 0
//   setactor[THISACTOR].extra 0
// }
// enda

// eventloadactor MOVEBLOCKB
// {
//   getactor[THISACTOR].hitag hitag
//   getactor[THISACTOR].lotag lotag
//   getactor[THISACTOR].extra monstflags
//   setactor[THISACTOR].hitag 0
//   setactor[THISACTOR].lotag 0
//   setactor[THISACTOR].extra 0
// }
// enda

// move BLOCKSTOPPED
// move SPEED0
// move SPEED1B 8
// move SPEED2B 16
// move SPEED3B 32
// move SPEED4 64
// move SPEED5 96
// move SPEED6 128
// move SPEED7 160
// move SPEED8 192
// move SPEED9 224
// move SPEED10 256
// move SPEED11 288
// move SPEED12 320
// move SPEED13 384
// move SPEED14 448
// move SPEED15 512

// state setblockxyspeed

// 	switch hitag
// 	case 0 move SPEED0 geth break
// 	case 8 move SPEED1B geth break
// 	case 16 move SPEED2B geth break
// 	case 32 move SPEED3B geth break
// 	case 64 move SPEED4 geth break
// 	case 96 move SPEED5 geth break
// 	case 128 move SPEED6 geth break
// 	case 160 move SPEED7 geth break
// 	case 192 move SPEED8 geth break
// 	case 224 move SPEED9 geth break
// 	case 256 move SPEED10 geth break
// 	case 288 move SPEED11 geth break
// 	case 320 move SPEED12 geth break
// 	case 384 move SPEED13 geth break
// 	case 448 move SPEED14 geth break
// 	case 512 move SPEED15 geth break
// 	default move SPEED6 geth break
// 	endswitch

// ends

// useractor notenemy MOVEBLOCKA 0 // moves back and forth and/or up and down

// ifmove 0
// {
// 	cstat 257
// 	//sizeat 64 64
// 	sizeat 128 32
// 	clipdist 96
// 	getactor[THISACTOR].x initx
// 	getactor[THISACTOR].y inity
// 	getactor[THISACTOR].z initz
// 	getactor[THISACTOR].x x
// 	getactor[THISACTOR].y y
// 	getactor[THISACTOR].z z
// 	getactor[THISACTOR].ang teleported
// 	ifvare lotag 0 setvar lotag 78
// 	setvar temp 0
// 	ifvarg monstflags 1024 { subvar monstflags 1024 mulvar monstflags -1 }
// 	mulvar monstflags -8
// 	state setblockxyspeed
// }

// ifmove BLOCKSTOPPED ifcount 6
// {
// 	state setblockxyspeed
// }

// ifmove BLOCKSTOPPED nullop else
// {
// 	ifvarvare countvar lotag 
// 	{
// 		getactor[THISACTOR].ang angvar
// 		addvar angvar 1024
// 		setactor[THISACTOR].ang angvar
// 		setvar peractor1 1
// 		move BLOCKSTOPPED
// 		resetcount
// 	}
// 	
// 	ifvare peractor1 0 addvar countvar 1
// 	ifvare peractor1 1 subvar countvar 1


// 	ifvare countvar 0
// 	{
// 		setactor[THISACTOR].x initx
// 		setactor[THISACTOR].y inity
// 		setactor[THISACTOR].z initz
// 		setactor[THISACTOR].ang teleported
// 		setvar peractor1 0
// 		move BLOCKSTOPPED
// 		resetcount
// 	}
// 	
// 	ifvarn monstflags 0
// 	{
// 		setvarvar temp monstflags
// 		ifvare peractor1 1 mulvar temp -1
// 		getactor[THISACTOR].z digz
// 		addvarvar digz temp
// 		setactor[THISACTOR].z digz
// 	}
// 	
// }
// getplayer[THISACTOR].posz mz
// getactor[THISACTOR].z digz
// ifp pducking addvar mz 8192 else addvar mz 12288 //10240

// ifvarvarl digz mz
// {
// 	ifcansee
// 		ifpdistl 1280 //640
// 	{
// 		getplayer[THISACTOR].poszv temp
// 		ifvarl temp 0
// 		{
// 			setplayer[THISACTOR].poszv 512
// 			setplayer[THISACTOR].jumping_counter 0
// 			// soundonce BUMPSOUND
// 		}
// 	}

// }

// getplayer[THISACTOR].i target
// ldist xydist THISACTOR target
// ifvarl xydist 1024 //640
// {
// 	subvarvar mz z // mz is positive if player is below, negative if above
// 	ifvarg mz -8192 ifvarl mz 0

// 	{
// 		getactor[THISACTOR].x digx
// 		getactor[THISACTOR].y digy
// 		getactor[THISACTOR].z digz
// 		subvarvar digx x
// 		subvarvar digy y
// 		subvarvar digz z
// 		getplayer[THISACTOR].posx mx
// 		getplayer[THISACTOR].posy my
// 		getplayer[THISACTOR].posz mz
// 		addvarvar mx digx
// 		addvarvar my digy
// 		addvarvar mz digz
// 		setplayer[THISACTOR].posx mx
// 		setplayer[THISACTOR].posy my
// 		setplayer[THISACTOR].posz mz
// 		getactor[THISACTOR].sectnum mysector
// 		ifvarn mysector -1 setplayer[THISACTOR].cursectnum mysector
// 		setvar onblock 2
// 		//setplayer[THISACTOR].sbs THISACTOR
// 		//setplayer[THISACTOR].spritebridge 1
// 	}
// }

// getactor[THISACTOR].x x
// getactor[THISACTOR].y y
// getactor[THISACTOR].z z

// enda

// useractor notenemy MOVEBLOCKB 0 // moves in a circle; starting location is the center of the circle

// ifmove 0
// {
// 	cstat 257
// 	//sizeat 64 64
// 	sizeat 128 32
// 	clipdist 128
// 	getactor[THISACTOR].x initx
// 	getactor[THISACTOR].y inity
// 	getactor[THISACTOR].z initz
// 	getactor[THISACTOR].z z
// 	getactor[THISACTOR].ang teleported
// 	ifvare lotag 0 setvar lotag 3072
// 	setvar temp 0
// 	ifvarg monstflags 1024 { subvar monstflags 1024 mulvar monstflags -1 }
// 	mulvar monstflags -8
// 	
// 	setvarvar temp initx
// 	addvarvar temp lotag
// 	addvar teleported 8
// 	ifvarg teleported 2047 subvar teleported 2048
// 	rotatepoint initx inity temp inity teleported hitx hity
// 	setvarvar hitz initz // temporary
// 	ifvarg hitag 1024 { subvar hitag 1024 setvar peractor1 1 }
// 	state setblockxyspeed
// }


// getactor[THISACTOR].x digx
// getactor[THISACTOR].y digy
// setvarvar mx hitx
// setvarvar my hity
// subvarvar mx digx
// subvarvar my digy
// getangle angvar mx my
// setactor[THISACTOR].ang angvar

// espawn NOTHING
// setactor[RETURN].x hitx
// setactor[RETURN].y hity
// setactor[RETURN].z hitz
// ldist xydist THISACTOR RETURN
// ifvarl xydist 1024
// {
// 	setvarvar temp initx
// 	addvarvar temp lotag
// 	setvarvar tempb hitag
// 	mulvar tempb 256
// 	divvarvar tempb lotag
// 	ifvarl tempb 2 setvar tempb 2
// 	ifvarg tempb 256 setvar tempb 256
// 	ifvare peractor1 0 addvarvar teleported tempb else subvarvar teleported tempb
// 	ifvarg teleported 2047 subvar teleported 2048 else ifvarl teleported 0 addvar teleported 2048
// 	rotatepoint initx inity temp inity teleported hitx hity
// 	setvarvar hitz initz // temporary
// }

// getplayer[THISACTOR].posz mz
// getactor[THISACTOR].z digz
// ifp pducking addvar mz 8192 else addvar mz 12288 //10240

// getplayer[THISACTOR].i target
// ldist xydist THISACTOR target
// ifvarl xydist 1280
// {
// 	subvarvar mz digz // mz is positive if player is below, negative if above
// 	ifvarg mz -8192 ifvarl mz 0
// 	{
// 		getactor[THISACTOR].x digx
// 		getactor[THISACTOR].y digy
// 		getactor[THISACTOR].z digz
// 		subvarvar digx x
// 		subvarvar digy y
// 		subvarvar digz z
// 		getplayer[THISACTOR].posx mx
// 		getplayer[THISACTOR].posy my
// 		getplayer[THISACTOR].posz mz
// 		addvarvar mx digx
// 		addvarvar my digy
// 		addvarvar mz digz
// 		setplayer[THISACTOR].posx mx
// 		setplayer[THISACTOR].posy my
// 		setplayer[THISACTOR].posz mz
// 		getactor[THISACTOR].sectnum mysector
// 		ifvarn mysector -1 setplayer[THISACTOR].cursectnum mysector
// 		setvar onblock 2
// 	}
// }

// getactor[THISACTOR].x x
// getactor[THISACTOR].y y
// getactor[THISACTOR].z z

// 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



define LIGHTHALO 1629

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
{
	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
}


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].x x
getactor[myspawner].y y
getactor[myspawner].z z
getactor[myspawner].zvel zvel
ifvarl zvel 0 subvar z 256
updatesectorz x y z mysector
setactor[THISACTOR].x x
setactor[THISACTOR].y y
setactor[THISACTOR].z z
ifvarn mysector -1 changespritesect THISACTOR mysector

enda

action RAINFRAME -1627 1 1 1 1
action SNOWFRAME  1169 1 1 1 1
action RAINSPLASH 93 9 1 1 3
move SNOWFALL 0 96

useractor notenemy RAINSPRITE 0
ifvarg raining 0 fall

ifvarg underwater 0 killit
ifinwater killit
ifaction 0
{
	setactor[THISACTOR].mdflags 1
	ifoutside nullop else killit
	//ifinspace killit
	ifvarg raining 0
	{
		action RAINFRAME
		sizeat 10 15
	}
	else
	{
		getactor[THISACTOR].z z
		action SNOWFRAME
		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
		addvarvar x y // between 6 and 12
		setvar mtype 1040
		mulvar x 32
		subvarvar mtype x
	}

	setactor[THISACTOR].pal rainpal
	ifvarand raincstat 512 cstator 514 else
	ifvarand raincstat 2 cstator 2
}


ifaction RAINFRAME
{
	iffloordistl 2 action RAINSPLASH else
	ifnotmoving action RAINSPLASH
} else

ifaction RAINSPLASH 
{
	ifactioncount 9 killit
}
else
{
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].z z
	addvarvar z mtype
	updatesectorz x y z mysector
	ifvare mysector -1 killit else
	{
		setactor[THISACTOR].z z
		changespritesect THISACTOR mysector
	}

}

enda

define WATERSPLASH3 1545

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

state jib_sounds

setplayer[THISACTOR].sound_pitch 0

  ifrnd SWEARFREQUENCY
  {
    ifrnd 128
    {
      ifrnd 128
      {
        ifrnd 128
        {
          ifrnd 128
          {
            ifrnd 128
              globalsound JIBBED_ACTOR12
            else
              globalsound JIBBED_ACTOR1
          }
          else
          {
            ifrnd 128
              globalsound JIBBED_ACTOR9
            else
              globalsound JIBBED_ACTOR14
          }
        }
        else
        {
          ifrnd 128
            globalsound SMACKED
          else
            globalsound JIBBED_ACTOR2
        }
      }
      else
      {
        ifrnd 128
          globalsound MDEVSPEECH
        else
          globalsound JIBBED_ACTOR5
      }
    }
    else
    {
      ifrnd 128
      {
        ifrnd 128
        {
          ifrnd 128
            globalsound JIBBED_ACTOR11
          else
            globalsound JIBBED_ACTOR13
        }
        else
        {
          ifrnd 128
            globalsound JIBBED_ACTOR3
          else
            globalsound JIBBED_ACTOR8
        }
      }
      else
      {
        ifrnd 128
        {
          ifrnd 128
            globalsound JIBBED_ACTOR6
          else
            globalsound JIBBED_ACTOR4
        }
        else
        {
          ifrnd 128
          {
            ifrnd 128
              globalsound JIBBED_ACTOR10
            else
              globalsound JIBBED_ACTOR15

          }
          else
            globalsound JIBBED_ACTOR7
        }
      }
    }
  }
ends


state standard_jibs
  guts JIBS2 1
  guts JIBS3 2
  guts JIBS4 3
  guts JIBS5 2
  guts JIBS6 3
  guts JIBS1 1
  ifrnd 12
  {
    //guts JIBS1 1
    spawn BLOODPOOL
  }         // a badly drawn spine

  state jib_sounds
ends

state standard_pjibs
  guts JIBS1 1
  guts JIBS3 2
  guts JIBS4 1
  guts JIBS5 1
  guts JIBS6 2
  guts DUKETORSO 1
  guts DUKELEG 2
  guts DUKEGUN 1
  ifrnd 16 money 1
ends

state genericshrunkcode
  ifcount 32
  {
	  
    ifpdistl SQUISHABLEDISTANCE
    {
    	
    	ifactor BOTALLY break
    	state specialdeath
    	pstomp
    	break
	}
	setactor[THISACTOR].htextra -1
  }
  else
  {
    sizeto MINXSTRETCH MINYSTRETCH
    spawn FRAMEEFFECT1
  }
ends

state genericgrowcode
  ifcount 32
  {
    guts JIBS4 24
    guts JIBS6 28
    addkills 1 state specialdeath
    sound SQUISHED
    sound PIPEBOMB_EXPLODE
    hitradius 2048 60 70 80 90
    spawn BLOODPOOL
    spawn EXPLOSION2
    killit
  }
  else
  {
    ifactor COMMANDER
      sizeto 100 100
    else
      ifactor SHARK
        sizeto 84 84
    else
      sizeto MAXXSTRETCH MAXYSTRETCH
    break
  }
ends

action BOTMARKERFRAME -5 1 1 1 1
define BOTMARKER 1414
useractor notenemy BOTMARKER 0 BOTMARKERFRAME

spritepal 4
cstat 2
sizeat 42 36
ifcount 1 killit

enda

useractor notenemy SHOOTME 0
ifmove 0
{
	move INIT
	sizeat 32 32
	cstat 32768
}
getactor[myspawner].x x
getactor[myspawner].y y
getactor[myspawner].z z
setactor[THISACTOR].z z
setactor[THISACTOR].y y
setactor[THISACTOR].x x
getactorvar[myspawner].playerally playerally
ifvarn playerally 0 { sizeat 16 16 cactor SHOOTMEALLY }
ifcount 26 killit
enda

useractor notenemy SHOOTMEALLY 0

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

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
endswitch
subvarvar z temp
subvar z 1560
setactor[THISACTOR].z z
setactor[THISACTOR].y y
setactor[THISACTOR].x x
ifcount 27 killit
ifcount 1 cstat 0
enda

eventloadactor BOTALLY
{
	getactor[THISACTOR].lotag lotag
	setactor[THISACTOR].lotag lotag
	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

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 AIBOTFROZEN ALLYPFROZEN ALLYSTOP geth
ai AIBOTSHRUNK ALLYPRUN BOTSHRUNKVELS randomangle



state checksight

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 facetarget

ifmove 0 ifspritepal 1 { setvar target -1 break } // frozen

ifvarvare target THISACTOR { setvar target -1 break }

setvar digz 0
ifactor BOTALLY setvar digz 1
ifactor BOTALLYCROUCH setvar digz 1

getactor[target].statnum temp
ifvare temp 1024
{
	ifvare digz 1 state jib_sounds
	setvar target -1 
	setvar targetlock 0
	break 
}

getactorvar[target].monstatus temp
ifvarn temp 1 
{ 
	//ifvare digz 1 
	//{
		setvar target -1 
		setvar targetlock 0
		break 
	//}
	
}

ifactor RECONDP { state gradualturn break }
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

ends

state calczdist

getactor[THISACTOR].z z

getactor[target].z mz
setvarvar zdist mz
subvarvar zdist z // zdist now holds how far up or down you would have to go from THISACTOR's position to get to target's position
getactor[target].picnum temp
ifvare temp ROTATEGUN addvar zdist 4096
ifvare temp GREENSLIME addvar zdist 4096
ifvare temp PIGCOPDIVE addvar zdist 4096

ifvarl zdist -8192 subvar zdist 4096 // aim for the head when shooting up into windows

ends

state visibilitycheck // ALSO CHECKS FOR TRANSPARENT WALLS

ifcansee
{
	getplayer[THISACTOR].i spriteid
	dist temp spriteid target
	ifvarl temp 1560 { setvar target -1 setvar targetlock 0 break }
}

getactor[target].cstat temp

ifvarand temp 256 nullop else { setvar target -1 setvar targetlock 0 break }

ldist xydist THISACTOR target

state calczdist

getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z
subvar z 8192
getactor[THISACTOR].sectnum mysector
getactor[THISACTOR].ang angvar
cos mycos angvar
sin mysin angvar
shiftvarl zdist 14

ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist
hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask

//  	espawn EXPLOSION2
//  	setactor[RETURN].x hitx
//  	setactor[RETURN].y hity
//  	setactor[RETURN].z hitz
//  	setactor[RETURN].xrepeat 32
//  	setactor[RETURN].yrepeat 32

ifvarvare hitsprite target 
{
	setvar targetlock 26 
}


addvar z 4096
hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask
ifvarvarn hitsprite target
{
	ifvarn targetlock 0 break
	setvar target -1
}
else setvar targetlock 26

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
{
	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 checksight
				}
			}
		}
		ifvare target -1
		ifvarand monstflags 4
		{
			// aim at bad guys
			findnearactorz SHOOTME 16384 65536 target
			ifvarn target -1 
			{
				getactorvar[target].myspawner target
				state checksight
			}
		}
		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
			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
			setvar xvel 256
			break
			
			case FIREBULLET
			case RAILSLUG_WEAK
			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
		}
		else 
		{
			setactor[THISACTOR].ang position
			ezshootvar peractor1 hitag
			setactor[RETURN].ang position
		}
		
		ifvarand monstflags 8
		{
			// 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
}
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 validatetarget

getactor[target].picnum picnum
ifvare picnum ROTATEGUN
{
	getactorvar[target].myspawner temp
	ifvarn temp -1 getactorvar[target].myspawner target
}

getactor[THISACTOR].ang tempd
state facetarget
ifvarn target -1
state visibilitycheck
ifvare target -1 setactor[THISACTOR].ang tempd

ends

state botfindtarget

setvar target -1

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

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

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

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

findnearspritez 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
        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
			{
				cactor BOTALLY
				action ALLYPJUMPING
				move ALLYJUMPVEL geth getv
			}
		}
		else
		{
			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
sound PISTOL_FIRE
state calczdist
ifvarg zdist -2048 ifvarl zdist 2048
{
	shoot SHOTSPARK1
	break
}
shiftvarl zdist 8
divvarvar zdist xydist
zshoot zdist SHOTSPARK1

ends

state shotgunfire
sound SHOTGUN_FIRE
subvar ammo 3
state calczdist
ifvarg zdist -2048 ifvarl zdist 2048
{
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	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 4
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 { 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 }
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
	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
		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 botstoppedstate

	ifvarn target -1
	{
		state checkbotdodge
	}
	else
	{
		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
				}	
				cactor BOTALLY
				ai AIBOTPATH
			} else
			ifrnd 2
			{
				ifrnd 128 soundonce DUKE_CRACK else soundonce DUKE_CRACK2
			}
			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
	{
		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 
		}
	}
	
	
	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
			{
				//canseespr THISACTOR spriteid tempc
				//ifvare tempc 0 setvar bouncesound -1
				//else
				//{
					getactor[spriteid].x mx
					getactor[spriteid].y my
					getactor[THISACTOR].x x
					getactor[THISACTOR].y y
					subvarvar mx x
					subvarvar my y
					getangle angvar mx my
					setactor[THISACTOR].ang angvar
				//}
			}
		}
	}
	else
 	{
		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
						getactor[THISACTOR].x x
						getactor[THISACTOR].y y
						subvarvar mx x
						subvarvar my 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
	
	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
}
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 
	}
	ifpdistl 2048 { ai AIBOTSTOPPED break }
}

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 botjetstate

ifp pjetpack nullop else
{
	iffloordistl 32 ai AIBOTSEEKPLAYER else
	ifmove ALLYJETDOWN nullop else move ALLYJETDOWN faceplayerslow getv
	break
}

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 checksight
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
ifawayfromwall nullop else // prevents bot from leaving the sector and falling off a cliff
// setvar temp 5120 
// ifvarg temp 4096
{
	ifai AIBOTWANDER nullop else ai AIBOTWANDER
	setvarvar mx initx
	setvarvar my inity
	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
	}
	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
	{
		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
		}
	}
}
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 nullop 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

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
	endswitch
	setvar hitag 1
	setvar monstatus 1
	cstat 257
	ai AIBOTSTOPPED
	sizeat 42 36
	randvar countvar 25
	clipdist 24 //32
	setvar bouncesound -1
	setvar botclip 12
	
	ifspawnedby APLAYER
	{
		ifspritepal 12 orvar monstflags 128
		ifspritepal 21 orvar monstflags 64
		ifspritepal 23 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].extra hp
	ifvarand monstflags 2 mulvar hp 2
	ifvarand monstflags 4 mulvar hp 4
	setactor[THISACTOR].extra hp
	ifvare lifebars YES
	{
		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 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 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
      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 4 
	{
		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
        break
      }
      ifwasweapon FREEZENOAIM
      {
        spritepal 1
        strength 0
        cactor BOTALLY
        ai AIBOTFROZEN
        sound SOMETHINGFROZE
        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
{
	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
		// cansee x1 y1 z1 sect1 x2 y2 z1 sect2 returnvar
		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

state generate_location

ifvarn target -1
{
	getactor[target].x mx
	getactor[target].y my
	getactor[target].z mz
} else
{
	getplayer[THISACTOR].posx mx
	getplayer[THISACTOR].posy my
	getactor[THISACTOR].z mz
}
setvarvar xydist mx
randvar temp 5120 // the random component of the distance from player
addvar temp 2048
addvarvar xydist temp
ifvarn target -1 getactor[target].ang angvar else
getplayer[THISACTOR].ang angvar
addvar angvar 512
randvar temp 1024 // the random component of the angle from player
addvarvar angvar temp

rotatepoint mx my xydist my angvar tempb my
// tempb and my are the new x and y coords

setvar tempd 0
updatesectorz tempb my mz mysector
ifvarn mysector -1
{
	// it's in a sector, so now we check for visibility
	espawn NOTHING
	setactor[RETURN].x tempb
	setactor[RETURN].y my
	setvarvar tempc mz
	subvar tempc 4096
	setactor[RETURN].z tempc
	getplayer[THISACTOR].i spriteid
	canseespr spriteid RETURN tempd // tempd is 1 if location is valid
}

ends

state teleport_behind

// first, we look for a valid location to teleport to
// this will be (a) behind the player, (b) in a sector, and (c) a place where the player can be seen from
state generate_location
ifvare tempd 0 state generate_location
ifvare tempd 0 state generate_location
ifvare tempd 0 state generate_location
ifvare tempd 0 state generate_location
ifvare tempd 0 state generate_location // a total of 6 tries

ifvare tempd 1
{
	sound TELEPORTER
	espawn TRANSPORTERSTAR
	ifactor NEWBEAST setactor[RETURN].pal 6 else
	{
		getactor[THISACTOR].pal pal
		setactor[RETURN].pal pal
	}
	getactor[THISACTOR].z z
	subvar z 8192
	setactor[RETURN].z z
	setactor[RETURN].xrepeat 96
	setactor[RETURN].yrepeat 96
	
	setactor[THISACTOR].x tempb
	setactor[THISACTOR].y my
	setactor[THISACTOR].z mz
	changespritesect THISACTOR mysector
	
	sound TELEPORTER
	espawn TRANSPORTERSTAR
	ifactor NEWBEAST setactor[RETURN].pal 6 else
	{
		getactor[THISACTOR].pal pal
		setactor[RETURN].pal pal
	}
	getactor[THISACTOR].z z
	subvar z 8192
	setactor[RETURN].z z
	setactor[RETURN].xrepeat 96
	setactor[RETURN].yrepeat 96
	setvar teleported 130
}
	 
ends

action ACOMMSPIN   -5  1  5  1  12
move COMMSTOPPED
ai AICOMMSPIN ACOMMSPIN COMMSTOPPED spin

state monsterai

ifvarg peractor6 0
{
	cos xvel peractor5
	sin yvel peractor5
	setvarvar temp peractor6
	ifvarg temp 1024 setvar temp 1024
	mulvarvar xvel temp
	mulvarvar yvel temp
	shiftvarr xvel 13
	shiftvarr yvel 13
	setvar zvel 0
	movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN
	ifvarn RETURN 0
	{
		addvar RETURN 16384
        ifvarl RETURN 16384
        ifvarg RETURN -1 // hit a sprite
        {
	        getactor[RETURN].picnum picnum
	        ifvare picnum GLASS
	        {
		        setactor[RETURN].htextra peractor6
		        setactor[RETURN].htpicnum SHOTSPARK1 //RPG
	        }
        }
    }
	shiftvarr peractor6 1
	ifvarl peractor6 4 setvar peractor6 0
}

ifvare monstatus 2 break

ifvarg superkicking 0 ifvare kickimpact 0
{
	ifp pfacing
		ifpdistl 1792
			ifcansee
				ifcanshoottarget
	{
		setvar dodge 0
		ifvarg superkicking 7
		{
			ifvare spinkick 0 setvar kickimpact 1
			//addphealth 5
			sound WHACK
			setactor[THISACTOR].htpicnum KNEE
			getactor[THISACTOR].htextra temp
			addvar temp 40
			setactor[THISACTOR].htextra temp
			
			getplayer[THISACTOR].i spriteid
			setactor[THISACTOR].htowner spriteid	
		}
	}
}

ifvarn playerally 0 
{
	setvar monallies 10
	ifvarg playerally 0 { subvar playerally 1 ifvare playerally 0 setvar target -1 setvar countvarb 0 }
}
addvar countvarb 1
addvar target2 1
ifvarg target2 25
{
	setvar target2 0
	getplayer[THISACTOR].heat_on temp
	ifvare temp 0 ifspritepal 66 nullop else ifvare playerally 0
	{
		espawn SHOOTME
		setactorvar[RETURN].myspawner THISACTOR
	}
	ifvarn playerally 0
	{
		espawn SHOOTMEALLY
		setactorvar[RETURN].myspawner THISACTOR
		setactorvar[RETURN].lotag 1
	}
}

getactor[THISACTOR].extra hp

ifvare monstatus 0
{
	ifvarl hp 0 setvar hp 0
	ifvare lifebars YES
	{
		espawn LIFEBAR
		setactorvar[RETURN].myspawner THISACTOR
	}
	randvar countvarb 25
	setvar monstatus 1
	ifvarn playerally 0 { espawn SHOOTMEALLY setactorvar[RETURN].lotag 1 } else
	espawn SHOOTME
	setactorvar[RETURN].myspawner THISACTOR
	getactor[THISACTOR].x initx
	getactor[THISACTOR].y inity
	getactor[THISACTOR].z initz
	ifvarand monstflags 4
	{
		mulvar hp 3 setactor[THISACTOR].extra hp
	} 
	ifvarand monstflags 2
	{
		mulvar hp 2 setactor[THISACTOR].extra hp
	}
	
	randvar temp 100
	ifvarvarl temp killerpigs
	{
		ifactor PIGCOP orvar monstflags 256
		ifactor PIGCOPDIVE orvar monstflags 256
	}
	
	ifvarg hp 32767 setactor[THISACTOR].extra 32767
	ifvarand monstflags 16384 setvar playerally -1
}

getactor[THISACTOR].htextra temp
ifvarg temp 0
{
	getactor[THISACTOR].htpicnum picnum
	getactor[THISACTOR].htowner spriteid
	ifvarn spriteid -1
	{
		getactor[spriteid].picnum tempb
		ifvare tempb APLAYER
		{
			ifvarg temp 80 ifvare CURRWEAP 2 ifvarand ALTSHOTGUN 4
			{
				setvar tempb 0
				ifactor DRONE setvar tempb 1
				ifactor TANK setvar tempb 1
				ifactor RECONDP setvar tempb 1
				ifactor ROTATEGUN setvar tempb 1
				ifvare tempb 1
				{
					debris SCRAP1 4
					debris SCRAP2 2
					debris SCRAP3 3
				} else
				guts JIBS6 10
			}
				
			ifvare altshrinker 1 ifvare picnum SHRINKSPARK
			{
				ifvarn playerally -1 ifvarl hp 600
				{
					setvarvar tempc hp
					shiftvarl tempc 3
					ifvarg tempc 1300 setvar tempc 1300
					addvar playerally 1560
					subvarvar playerally tempc
				}
				setvar picnum SHOTSPARK1
				setactor[THISACTOR].htpicnum SHOTSPARK1
				setvar temp 0
				setactor[THISACTOR].htextra 0
				setvar target -1
				setvar countvarb 26
			}
			ifvarn pdamage 100
			{
				mulvarvar temp pdamage
				divvarvar temp 100
				setactor[THISACTOR].htextra temp
			}
		} else
		{
			ifvare target -1 ifvarvarn spriteid THISACTOR 
			{
				ifvarg playerally 0
				setvarvar target spriteid else
				ifvarg infighting 0 
				{
					randvar temp 100
					ifvarvarl temp infighting
					setvarvar target spriteid 
				}	
			}
			
			ifvarn mdamage 100
			{
				mulvarvar temp mdamage
				divvarvar temp 100
				setactor[THISACTOR].htextra temp
			}
		}
	}
	
	switch picnum
	
	case RPGNOAIM
	case RPG
	case RADIUSEXPLOSION
	// knock back direction code
	getactor[THISACTOR].xvel xvel
	mulvar xvel -1
	setactor[THISACTOR].xvel xvel
	ifvare picnum RPGNOAIM { setvar picnum RPG setactor[THISACTOR].htpicnum RPG }
	break
	case KNEE
	ifvare steroidkicks YES
	{
		ifp ponsteroids
		{
			mulvar temp 4
			setactor[THISACTOR].htextra temp
		}
	}
	break
	case FREEZENOAIM
	setvar picnum FREEZEBLAST
	setactor[THISACTOR].htpicnum FREEZEBLAST
	break
	
	case SAWBLADEPROJ
	setvar picnum RADIUSEXPLOSION
	setactor[THISACTOR].htpicnum RADIUSEXPLOSION
	break
	
	endswitch
	
	setvarvar tempb knockdist
	ifvarvarg temp hp ifvarn droptile 0 { mulvar temp 3 ifvarl temp 30 setvar temp 40 }
	ifvare CURRWEAP 11 ifvare gravgun YES ifwasweapon SHOTSPARK1 setvar temp 200
	ifactor SHARK setvar tempb 0
	ifvarn tempb 0
	//ifvarg temp 30 
	ifvarn picnum FREEZEBLAST
	{
		
		ifactor ROTATEGUN nullop else
		{
			getactor[THISACTOR].htang peractor5 // the angle monster will move in
			setvarvar peractor6 temp // temp is damage
			mulvarvar peractor6 tempb // peractor6 is the knockback force
			setvarvar temp hp
			shiftvarl temp 1
			subvarvar peractor6 temp
			setvar tempc 0
			ifactor BOSS1 setvar tempc 1
			ifactor BOSS2 setvar tempc 1
			ifactor BOSS3 setvar tempc 1
			ifactor BOSS4 setvar tempc 1
			ifactor TANK setvar tempc 1
			ifvare tempc 1
			{
				ifvare picnum SHOTSPARK1 shiftvarr peractor6 1
				shiftvarr peractor6 1
			}
			ifvarl peractor6 0 setvar peractor6 0
		}
	}
	
	// weapon resistance code

	ifactor NEWBEAST ifvare picnum SPIT setactor[THISACTOR].htextra -1
	
	ifvarand monstflags 512 // explosives resistance
	{
		switch picnum
		case RPG case RADIUSEXPLOSION case FIREBALLPROJ
			ifactor OCTABRAIN ifvare picnum RPG setactor[THISACTOR].htpicnum RADIUSEXPLOSION
			divvar temp 4
			ifvarl temp 1 setvar temp 1
			setactor[THISACTOR].htextra temp
		break
		endswitch
	}
	ifvarand monstflags 1024 // energy weapon immunity
	{
		switch picnum
		case SHRINKSPARK case GROWSPARK case FIRELASER case FIREBULLET
			setactor[THISACTOR].htpicnum -1
			setactor[THISACTOR].htextra -1
		break
		endswitch
	}
	ifvarand monstflags 2048 // freezer
	{
		ifvare picnum FREEZEBLAST
		{
			setactor[THISACTOR].htpicnum -1
			setactor[THISACTOR].htextra -1
		}
		
	}
}

ifmove 0 break

ifvare target -1 ifvarg countvarb 25 
{
	setvar countvarb 0
	ifvarn playerally 0
	{
		findnearactorz SHOOTME 4096 16384 target
		ifvarn target -1
		{
			getactorvar[target].myspawner target
			state checksight
		} 
		ifvare target -1
		{
			findnearactorz SHOOTME 16384 65536 target
			ifvarn target -1 
			{
				getactorvar[target].myspawner target
				state checksight
			}
		}
	} else
	{
		ifvarg numallies 0
		{
			findnearactorz BOTALLY 4096 16384 target
			ifvarn target -1 state checksight
			ifvare target -1
			findnearactorz BOTALLY 16384 65536 target
			ifvarn target -1 state checksight
			ifvare target -1 
			findnearactorz BOTALLY 32768 131072 target
			ifvarn target -1 state checksight
		}
		ifvare target -1
		ifvarg monallies 0
		{
			
			findnearactorz SHOOTMEALLY 4096 16384 target
			ifvarn target -1
			{
				getactorvar[target].myspawner target
				state checksight
			} 
			ifvare target -1
			{
				findnearactorz SHOOTMEALLY 16384 65536 target
				ifvarn target -1 
				{
					getactorvar[target].myspawner target
					state checksight
				}
			}
		}
	}
}
ifvarn target -1 
{
	ifai AICOMMSPIN nullop else
	state facetarget
	ifvarn target -1
	ifrnd 8 ifvarg countvarb 52 state checksight
	ifvarn target -1
	{
		dist xydist THISACTOR target
		ifvare xydist 0 setvar xydist 1
	}
	ifvarvare target THISACTOR setvar target -1
}



ifspritepal 1 nullop else ifvarand monstflags 128 ifvare monstatus 1 // teleporting
{
	ifvarg teleported 0 subvar teleported 1
	ifvare teleported 0
	{
		ifpdistl 10240
		//ifvarvare scannedsprite THISACTOR
		ifp pfacing
		ifcansee
		{
			ifrnd 4
				state teleport_behind
			else 
			{
				getactor[THISACTOR].ang angvar
				ifbulletnear
				{
					setactor[THISACTOR].ang angvar
					state teleport_behind
				}
			}
			
		}
	}
}


ends


move RECONDYINGVELS 192 160
move RECONPATROLVELS 256 0
move RECONRUNVELS 320 0
move RECONRUNUPVELS 320 0
move RECONBULLVELS 320 0
move RECONBACKWARDS -160 0
move RECONRISE 32 -128
move RECONSTOPPED

action RECONFLY -6 1 7 1 1
action RECONTURN 1 1 7 1 1

ai AIRECONGETE RECONFLY RECONRUNVELS geth getv
ai AIRECONWAIT RECONFLY RECONSTOPPED geth
ai AIRECONGETUP RECONFLY RECONRUNUPVELS geth getv
ai AIRECONPULLBACK RECONFLY RECONBACKWARDS geth
ai AIRECONHIT RECONFLY RECONBACKWARDS geth
ai AIRECONSHRUNK RECONFLY BOTSHRUNKVELS geth
ai AIRECONDODGE RECONFLY RECONBULLVELS dodgebullet geth
ai AIRECONDODGEUP RECONFLY RECONRISE getv geth
ai AIRECONDYING RECONTURN RECONDYINGVELS geth getv

state recontilt

 // tilt code thanks to Hunter_Rus for initial version
  getactor[THISACTOR].ang angvar
  getincangle temp angvar peractor1
//    ifactor RECONDP 
//    {
//  	  ifaction RECONTURN
//  	  {
//  		ifai AIRECONDYING nullop else ifvarg temp -16 ifvarl temp 16
//  	    action RECONFLY
//  	  }
//  	  else
//  	    ifvarn temp 0 
//  	    {
// 	 	    ifvarg temp 0 cstat 257 else cstat 261
// 	 	    action RECONTURN
//  	    }
//   }
	  
  setvarvar peractor1 angvar
  shiftvarl temp 20
  divvar temp 18768
  ifvarg temp  256 setvar temp  256 else
  ifvarl temp -256 setvar temp -256 
  // added this code to make it smoother 
  getactor[THISACTOR].roll mtype
  ifvarvarg temp mtype 
  {
	  addvar mtype 24
	  ifvarvarg mtype temp setvarvar mtype temp
  }
  else ifvarvarl temp mtype
  {
	  subvar mtype 24
	  ifvarvarl mtype temp setvarvar mtype temp
  }
  setactor[THISACTOR].roll mtype
  
ends

state recondead
  addkills 1
  state specialdeath
  debris SCRAP1 16
  debris SCRAP2 8
  debris SCRAP3 14
  spawn EXPLOSION2
  spawn BURNING
  sound RPG_EXPLODE
  espawn PIGCOP
  hitradius 1560 5 10 15 20
  killit
  break
ends

state recondying

getactor[THISACTOR].htextra temp
ifvarl temp 50 
{
   setactor[THISACTOR].htextra -1
   setactor[THISACTOR].htpicnum -1
}
else state recondead

iffloordistl 16 state recondead
addvar countvar 1
ifvarg countvar 2
{
    ifrnd 64 { spawn EXPLOSION2 sound RPG_EXPLODE }
    else ifrnd 64 espawn EXPLOSION2
    spawn SMALLSMOKE
    setvar countvar 0
}

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

ends

state checkreconhitstate
  getactor[THISACTOR].extra hp
  ifvarl hp 1 { ai AIRECONDYING break }
  else ifsquished { ai AIRECONDYING break }
  else
  {
    ifwasweapon SHOTSPARK1 sound PISTOL_RICOCHET
    debris SCRAP1 1
    // ai AIRECONHIT
  }
ends

state reconshrunkstate
  ifcount 24
    killit
  else
    sizeto 1 1
ends

state checkreconnearplayer

  ifvarn target -1 ifvarl xydist 1024 ifvarl zdist 16384
  {
    ifcount 8 nullop
     else
      ifai AIRECONPULLBACK nullop
         else
             ai AIRECONPULLBACK
  }

ends

state recongetstate

// ramming code
ifvarn target -1 ifvarl xydist 1280 ifvarl zdist 16384 ifvare botclip 1
  {
    getactor[target].picnum temp
    ifvare temp APLAYER
	palfrom 32 16
	setactor[target].htowner THISACTOR
	setactor[target].htpicnum RADIUSEXPLOSION
	setactor[target].htextra 45
    soundonce SQUISHED
    setvar botclip 0
    setvar ammo 0
  }

  ifrnd 192
  {
    ifvarn target -1
    {
      ifmove RECONBULLVELS
      {
        ifcount 64
          ai AIRECONPULLBACK
        else
          ifnotmoving
            ifcount 16
              ai AIRECONPULLBACK
      }
      else
        ifcount 32
      {
        ifvarvarg z mz
          move RECONBULLVELS geth getv
        else
          move RECONBULLVELS geth
      }
    }

  }

ends

state recondodgestate
  ifai AIRECONDODGEUP
  {
     ifcount 8
       { ai AIRECONGETE  ifvarg ammo 51 setvar botclip 1 }
     else
       ifnotmoving 
         { ai AIRECONGETE ifvarg ammo 51 setvar botclip 1 }
  }
  else
  {
    ifcount 8
      { ai AIRECONGETE ifvarg ammo 51 setvar botclip 1 }
    else
      ifnotmoving
        { ai AIRECONGETE ifvarg ammo 51 setvar botclip 1 }
        
  }
ends

useractor enemy RECONDP 130

ifai AIRECONDYING { setvar target -1 state recondying break }
ifai AIRECONDODGE setvar botdodge 2 else setvar botdodge 0 // AIRECONDODGE not currently used

ifvare target -1 ifrnd 4 ifpdistl 16384 ifvare playerally 0
{
	ifcansee 
	{
	    getplayer[THISACTOR].i target
    }
}
ifvarn target -1
{
	setvar myspawner -1 // no locator set
	getactor[THISACTOR].z z
	getactor[target].z mz
	setvarvar zdist mz
	subvarvar zdist z
	ifvarl zdist 0 mulvar zdist -1
}
else
{
	ifvarg locators 0
	{
		ifmove RECONRUNVELS move RECONPATROLVELS geth
		getactorvar[lotag].locatorids myspawner
		canseespr THISACTOR myspawner temp
		ifvare temp 1
		{
			ldist xydist THISACTOR myspawner
			setvarvar temp lotag
			addvar temp 1
			ifvarvarg temp locators setvar temp 0
			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
				setvar target -1
				getactor[myspawner].z mz
				getactor[THISACTOR].z z
				subvarvar mz z
				shiftvarr mz 3
				movesprite THISACTOR 0 0 mz CLIPMASK0 RETURN
			}
		}
		else
		{
			addvar lotag 1
			ifvarvarg lotag locators setvar lotag 0
			
		}
	}
	
}


state monsterai

state checkreconnearplayer
addvar ammo 1 // used as a counter

ifai AIRECONGETE nullop else
  ifvarn target -1
     {
      ifvarvarg z mz 
       {
        getactor[THISACTOR].z z
        subvar z 512
        updatesectorz x y z temp
        ifvarn temp -1
        setactor[THISACTOR].z z
        }
      else ifvarvarg mz z
        {
        getactor[THISACTOR].z z
        addvar z 512
        updatesectorz x y z temp
        ifvarn temp -1
        setactor[THISACTOR].z z
        }
     }

    soundonce RECO_ROAM

 
  ifaction 0
  {
     ai AIRECONGETE
     setvar ammo 0 
     setvar botclip 1
     sizeat 48 48
     cstat 257
     clipdist 100
     sound PIG_ROAM
  }

  else
    ifai AIRECONWAIT
  {
    ifcount 14
      ifvarn target -1
    {
      addvar weap 1
      ifvarg weap 52
       {
	    ifrnd 128 setvar target -1
        setvar weap 0
        setvar weapcount 0
        ifvarvarg z mz
          { ai AIRECONGETUP ifvarg ammo 51 setvar botclip 1 }
        else { ai AIRECONGETE ifvarg ammo 51 setvar botclip 1 }
        }
      else
       {
        ifvare weap 2
        {

	        ifvarand monstflags 32
	        {
		        sound BLASTERSND
			    eshoot FIREBALLPROJ 
				ifvarand monstflags 8 
				{
					setthisprojectile[RETURN].pal 13
					setthisprojectile[RETURN].extra 64
				}
			}
			else
			{
	            sound RPG_SHOOT
				shoot MORTER
			}
        }
        else ifvarg weap 19
        {
	         ldist xydist THISACTOR target
	         ifvare xydist 0 setvar xydist 1
	         state calczdist
	         subvar zdist 8192
             addvar weapcount 1
             ifvarg weapcount 2
             {
	             flash
	             setvar weapcount 0
	             ifvarand monstflags 16
				{
					setprojectile[STARPROJ].workslike 38914
					mulvar zdist 768
					divvarvar zdist xydist
					sound PISTOL_LOW
					zshoot zdist STARPROJ
					ifvarand monstflags 8 zshoot zdist STARPROJ
					setprojectile[STARPROJ].workslike 34818
				}
				else
				{
	                 // shoot bullets
					 sound PISTOL_LOW
	                 state calczdist
	                 shiftvarl zdist 8
	                 ifvare xydist 0 setvar xydist 1 
	                 divvarvar zdist xydist
	                 zshoot zdist SHOTSPARK1
	                 zshoot zdist SHOTSPARK1
	                 ifvarand monstflags 8
	                 {
		                zshoot zdist SHOTSPARK1
	                 	zshoot zdist SHOTSPARK1
	             	 }
                }
             }
         }
        }
    }
    else ifcount 52 ai AIRECONGETE
  }
  else
    ifai AIRECONGETE
      state recongetstate
  else
    ifai AIRECONGETUP
      state recongetstate
  else
    ifai AIRECONPULLBACK
  {
    ifcount 32
    ai AIRECONWAIT
  }
  else
    ifai AIRECONHIT
  {
    ifcount 8
      ai AIRECONWAIT
  }
  else
    ifai AIRECONSHRUNK
      state reconshrunkstate
  else
    ifai AIRECONDODGE
      state recondodgestate
  else
    ifai AIRECONDODGEUP
      state recondodgestate

  ifhitweapon
    state checkreconhitstate

  state recontilt
  
  ifceilingdistl 96 { getactor[THISACTOR].z temp addvar temp 512 setactor[THISACTOR].z temp }
  else
  {
	  getactor[THISACTOR].x x
	  getactor[THISACTOR].y y
	  getactor[THISACTOR].z z
	  getactor[THISACTOR].sectnum mysector
	  getflorzofslope mysector x y temp
	  subvar temp 8192
	  ifvarvarg z temp setactor[THISACTOR].z temp
  }

enda

state getfloordist
  getactor[THISACTOR].x x
  getactor[THISACTOR].y y
  updatesector x y mysector
  ifvare mysector -1 getsector[THISACTOR].floorz z else
  getflorzofslope mysector x y z
  getactor[THISACTOR].z temp
  subvarvar z temp
  shiftvarr z 8
  subvar z 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



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

define ROCKETHALO 3458
define NEWSMOKE 3511
useractor notenemy ROCKETHALO 0

ifvare countvar 0
{
	ifspawnedby FIRELASER 
	{
		sizeat 32 32 
		getactor[THISACTOR].z z
		addvar z 8192
		setactor[THISACTOR].z z
		state sparkstate
		subvar z 8192
		setactor[THISACTOR].z z
	}
	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 ASHARKCRUZING 0 8 5 1 24
action ASHARKFLEE  0 8 5 1 10
action ASHARKATACK   0 8 5 1 6
action ASHARKSHRUNK  0 8 5 1 24
action ASHARKGROW  0 8 5 1 24
action ASHARKFROZEN  0 1 5 1 24
action ASHARKDEAD    0 1 5 1 24

move SHARKBACK -84
move SHARKVELS 24
move SHARKFASTVELS 72
move SHARKFLEEVELS 40
move KILLERSHARKVELS 128
move KILLERSHARKVELSUP 128 -64
move KILLERSHARKVELSDOWN 128 32

state killershark

 ifpdistl 1560 
   ifp palive ifcansee
{
      setplayer[THISACTOR].sound_pitch 0
      randvar temp 6
      switch temp
      case 0 soundonce DUKE_LONGTERM_PAIN2 break
      case 1 soundonce DUKE_LONGTERM_PAIN3 break
      case 2 soundonce DUKE_LONGTERM_PAIN4 break
      case 3 soundonce DUKE_LONGTERM_PAIN5 break
      case 4 soundonce DUKE_LONGTERM_PAIN6 break
      case 5 soundonce DUKE_LONGTERM_PAIN7 break
      case 6 soundonce DUKE_LONGTERM_PAIN8 break
      endswitch
      palfrom 48 32
      addphealth SHARKBITESTRENGTH
      wackplayer
  	  resetcount
  	  ifrnd 32
  	  {
  	  		action ASHARKFLEE
	        move SHARKFLEEVELS fleeenemy
      }
}
      	  
ends

actor SHARK SHARKSTRENGTH ASHARKCRUZING SHARKVELS randomangle geth

ifvare countvar 0
{
	setvar countvar 1
	getactor[THISACTOR].extra hp
	ifvarand monstflags 4
	{
		mulvar hp 3 setactor[THISACTOR].extra hp
	} 
	ifvarand monstflags 2
	{
		mulvar hp 2 setactor[THISACTOR].extra hp
	}
}

//state monsterai

state getfloordist
ifvarl z 0 movesprite THISACTOR 0 0 -512 CLIPMASK0 RETURN

ifaction ASHARKDEAD
{
	strength 0
	setvar monstatus 2
	ifhitweapon
    {
	  sound SQUISHED
      //guts JIBS6 5
      state standard_jibs
      killit
    } 
    ifvarg underwater 0
    {
		setactor[THISACTOR].zvel 0
		getactor[watereffector].z mz
	  	getactor[THISACTOR].z z
	  	addvar mz 6144 //3072
	  	ifvarvarl z mz setactor[THISACTOR].z mz else
	  	ifvarvarg z mz
	  	{
		  	fall // necessary or the movesprite won't work; don't know why but it's true 	
	  		movesprite THISACTOR 0 0 -1024 CLIPMASK0 RETURN
	  		getactor[THISACTOR].z z
	  		ifvarvarl z mz setactor[THISACTOR].z mz
  	    }
	  	
  	} else
  	ifinwater nullop else iffloordistl 16 nullop else
  	{
	  	getactor[THISACTOR].z z
	  	addvar z 128
	  	setactor[THISACTOR].z z
	  	//fall
  	}
    break
}

ifvarn watereffector -1
{
	ifvarl underwater 2
	{
		getactor[watereffector].x mx
		getactor[watereffector].y my
		getactor[watereffector].z mz
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		subvarvar mx x
		subvarvar my y
		getangle angvar mx my
		cos xvel angvar
		sin yvel angvar
		shiftvarr xvel 6
		shiftvarr yvel 6
		setvar zvel 2048
		movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN	
	}
}

ifvarand monstflags 8
{
	setactor[THISACTOR].zvel 0
	//fall
	ifmove SHARKFASTVELS move KILLERSHARKVELS geth
	ifp phigher ifrnd 8
	{
		ifinwater
		{
			ifmove KILLERSHARKVELSUP nullop else move KILLERSHARKVELSUP faceplayerslow getv
		} else
		ifvarg underwater 1 ifvare headunder YES
		{
			ifmove KILLERSHARKVELSUP nullop else move KILLERSHARKVELSUP faceplayerslow getv
		}
	}
	else ifrnd 8
	{
		getactor[THISACTOR].z z
		getplayer[THISACTOR].posz mz
		ifvarvarg mz z
		{
			ifmove KILLERSHARKVELSDOWN nullop else move KILLERSHARKVELSDOWN faceplayerslow getv
		}
	}
	
}

ifinwater nullop else ifvarg underwater 1 nullop else
fall


  ifaction ASHARKSHRUNK
  {
    ifcount SHRUNKDONECOUNT
      action ASHARKCRUZING
    else ifcount SHRUNKCOUNT
      sizeto 60 60
    else
      state genericshrunkcode
    break
  }
  else
    ifaction ASHARKGROW
  {
    ifcount SHRUNKDONECOUNT
      action ASHARKCRUZING
    else
      ifcount SHRUNKCOUNT
        sizeto 24 24
    else
      state genericgrowcode
  }
  else
    ifaction ASHARKFROZEN
  {
    fall

    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick

    ifcount THAWTIME
    {
      action ASHARKFLEE
      getlastpal
      break
    }
    else
      ifcount FROZENDRIPTIME
        ifactioncount 26
          resetactioncount

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
        break

      lotsofglass 30
      sound GLASS_BREAKING
      addkills 1 state specialdeath
      killit
    }
    break
  }
  else
    ifaction ASHARKFLEE
  {
    ifcount 16
      ifrnd 48
    {
      action ASHARKCRUZING
      move SHARKVELS randomangle geth
    }
  }
  else
    ifaction ASHARKCRUZING
  {
    ifcansee
      ifcount 48
        ifrnd 2
          ifcanshoottarget
    {
      action ASHARKATACK
      ifvarand monstflags 8 move KILLERSHARKVELS faceplayerslow getv
      else
      move SHARKFASTVELS faceplayerslow getv 
      break
    }
    ifcount 32
      ifnotmoving
    {
      ifrnd 128
        move SHARKVELS randomangle geth
      else
        move SHARKFASTVELS randomangle geth
    }
  }
  else
    ifaction ASHARKATACK
  {
    ifcount 4
    {
	  ifvarand monstflags 8 state killershark else
	  {
		  ifpdistl 1280 
	      {
	        ifp palive ifcanshoottarget
	        {
		      setplayer[THISACTOR].sound_pitch 0
	          sound DUKE_GRUNT
	          palfrom 32 32
	          addphealth SHARKBITESTRENGTH
	        }
	        action ASHARKFLEE
	        move SHARKFLEEVELS fleeenemy
	      }
      }
    }
    else
      ifnotmoving
    {
      ifcount 32
      {
        action ASHARKCRUZING
        move SHARKVELS randomangle geth
      }
    }
    else
      ifcount 48
        ifrnd 2
    {
      action ASHARKCRUZING
      move SHARKFASTVELS randomangle geth
    }
  }

  ifhitweapon
  {
    ifdead
    {
      ifwasweapon GROWSPARK
      {
        move 0
        cstat 0
        action ASHARKGROW
        sound ACTOR_GROWING
        break
      }
      else
        ifwasweapon FREEZEBLAST
      {
        spritepal 1
        strength 0
        action ASHARKFROZEN
        sound SOMETHINGFROZE
      }
      else
        ifwasweapon RPG
      {
	    sound SQUISHED
        //guts JIBS6 5
        state standard_jibs
        addkills 1 state specialdeath
        killit
      } 
      else
        ifwasweapon RADIUSEXPLOSION
      {
	    sound SQUISHED
        //guts JIBS6 5
        state standard_jibs
        addkills 1 state specialdeath
        killit
      } 
      else
      {
	    
        //sound SQUISHED
        guts JIBS6 5
        //state standard_jibs
        addkills 1 state specialdeath
        //killit
        setactor[THISACTOR].mdflags 2

        
        action ASHARKDEAD
        cstat 8
        move INIT
      }
    }
    else
    {
      ifwasweapon SHRINKSPARK
      {
        action ASHARKSHRUNK
        sound ACTOR_SHRINKING
        move 0
        break
      }
      else
        ifwasweapon GROWSPARK
          sound EXPANDERHIT
	  
      ifvarand monstflags 8
      {   
	      action ASHARKATACK
	      move SHARKFASTVELS faceplayerslow getv break
	  } else
      move SHARKVELS randomangle geth
    }
  }
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

define AMERICANFLAG 4443

state breakobject


state moveitem

ifvarvare holding THISACTOR
{
	ifvarn pickup 0 break
	ifvarand bits 4 state throwitem
	break
}
else ifmove PHOLDING move INIT geth 
ifactor CLOCK state gravpickupcode else
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 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
      {
        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
      {
        spawn EXPLOSION2
        sound PIPEBOMB_EXPLODE
        hitradius 2048 WEAKEST WEAK MEDIUMSTRENGTH TOUGH
        ifpdistl 2048
          wackplayer
        debris SCRAP1 10      // Weapons and ammo!
        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 AMERICANFLAG
    {  
        debris SCRAP1 2
        debris SCRAP3 3
        debris SCRAP4 2
    }
  }
  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
define BALLANDCHAIN 4446
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 HATRACK WEAK setvar bouncesound PIPEBOMB_BOUNCE state breakobject enda

useractor notenemy GUNPOWDERBARREL TOUGH 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 BOUNCEMETALSND 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

state headhitstate

// Unrem the following line to invoke screen tilting during
// low player hitpoint damage.

// wackplayer

ends


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
	    ifvare lotag 0 spawn NOTHING else
	    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  
      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 -2937 1 1 1 1
action TOILETBROKEFRAME -2891 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 -2526 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

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

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 lighting YES
      {
	      setvar flicker 50
	      setvar intensity 52
	      setvar peractor7 52
	      state enter_light_array
      }
      
    }
    ifvare lighting YES
    {
	    getactor[THISACTOR].xrepeat x
	    ifvarg x 9
	    setvarvar peractor7 x
    }

    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
    }
  }

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
    {
      addphealth 1
      globalsound DUKE_DRINKING
      resetactioncount
    }
  }
enda

action FOUNTAINIDLE -1
action FOUNTAINFLOW 0 3 1 1 6

define WATERFOUNTAIN2 564
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
	{
		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
  {
	  ifspawnedby SHOTSPARK1
	  {
		  getactor[THISACTOR].owner spriteid
		  ifvarn spriteid -1
		  {
			  getactorvar[spriteid].mtype temp
			  ifvare temp 1 { ifrnd 32 guts JIBS6 1 killit break }
		  }
	  }
      ifvare effects YES 
      {
	  	action 0 setvar mtype 1 
	  	changespritestat THISACTOR 1 
	  	cactor NEWSMOKE 
	  	break 
      }
  
    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 16 -14
move SMOKEMOVE4 8 -14

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

useractor notenemy NEWSMOKE 0

ifmove 0
{
	ifrnd 128 cstator 8
	ifrnd 128 cstator 4
	ifspawnedby EXPLOSION2 
	{
		action NEWSMOKEA 
		cstator 2 //130
		getactor[THISACTOR].xrepeat initx
		ifvarl initx 41 move SMOKEMOVE4 geth getv randomangle else
		move SMOKEMOVE3 geth getv randomangle
		break
	}
	else
	ifspawnedby RPG action NEWSMOKED
	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 }
		  }
	  }
    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
      move SMOKEVEL geth getv faceplayer
}

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 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

state random_ooz
  ifrnd 128
    spawn OOZ2
  else
    spawn OOZ
ends


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

action EXPLOSION_FRAMES 0 20 1 1  4
actor EXPLOSION2 1 EXPLOSION_FRAMES

ifcount 1 nullop else
{
	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
		ifrnd 64 spawn BURNING else ifrnd 64 spawn BURNING2
	}
	ifvare peractor1 1 
	{
		// additional explosion sound
		sizeat 96 96
	}
	ifvare weap 1 sizeat 16 16
}

ifvarg intensity 2 subvar intensity 2

ifcount 18 nullop else ifcount 17 ifvare effects YES
{
	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
	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

state turretshootbot

state calczdist
subvar zdist 4096
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1

ifvarand monstflags 64
{
	setprojectile[RAILSLUG_WEAK].workslike 36866 //4097
	//shiftvarl zdist 8
	mulvar zdist 844
	divvarvar zdist xydist
	sound SHOTTY2
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 30
	zshoot zdist RAILSLUG_WEAK
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 15
	setprojectile[RAILSLUG_WEAK].workslike 32770 //1
} else
ifvarand monstflags 32 ifvarg xydist TRIPBOMBBLASTRADIUS
{
	mulvar zdist 644
	divvarvar zdist xydist
	sound RPG_SHOOT
	ezshoot zdist RPGNOAIM
	ifvarand monstflags 8 nullop else
	setthisprojectile[RETURN].extra 40
} else
ifvarand monstflags 16
{
	shiftvarl zdist 8
	divvarvar zdist xydist
	sound PISTOL_FIRE
	zshoot zdist SHOTSPARK1
	zshoot zdist SHOTSPARK1
	ifvarand monstflags 8 
	{
		zshoot zdist SHOTSPARK1
		zshoot zdist SHOTSPARK1
	}
} else
{
	mulvar zdist 768
	divvarvar zdist xydist
	ifvare mtype 1 sound BLASTERSND else
	ifvare effects YES sound PRED_ATTACK2 else
	sound PRED_ATTACK
	zshoot zdist FIRELASER
	ifvarand monstflags 8 zshoot zdist FIRELASER
}

ends

state turretshoot

ifvarn target -1 { state turretshootbot break }
ifvare target -1 ifvarn playerally 0 break

ifvarand monstflags 64
{
	sound SHOTTY2
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 30
	shoot RAILSLUG_WEAK
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 15
} else
ifvarand monstflags 32
{
	sound RPG_SHOOT
	shoot RPG
} else
ifvarand monstflags 16
{
	sound PISTOL_FIRE
	shoot SHOTSPARK1
	shoot SHOTSPARK1
	ifvarand monstflags 8 
	{
		shoot SHOTSPARK1
		shoot SHOTSPARK1
	}
} else
{
	ifvare mtype 1 sound BLASTERSND else
	ifvare effects YES sound PRED_ATTACK2 else
	sound PRED_ATTACK
	shoot FIRELASER
	ifvarand monstflags 8 shoot FIRELASER
}
ends


action ASATNSPIN     0 5 1 1 4
action ASATSHOOTING   -10 3 5 1 40
action ASATWAIT      0 1 5 1 1
move TURRVEL

state fastshooting

ifactioncount 12
      ifrnd 32
    {
      action ASATWAIT
      move 0
    }
    ifcount 16
      resetcount
    else
      ifcount 9
    {
      ifcount 10 nullop
      else
        state turretshoot
      
    }
    else
      ifcount 2
    {
      ifcount 3 nullop
      else
      {
	    setvar temp 0
        ifcansee
          //ifcanshoottarget
        setvar temp 1
        else ifvarn target -1 setvar temp 1
        ifvare temp 1
          state turretshoot
        
      }
    } 

ends

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

actor ROTATEGUN ROTTURRETSTRENGTH
// ASATSHOOTING TURRVEL faceplayer
state monsterai

  ifvarn myspawner -1
  {
	  cstator 8
	  getactorvar[myspawner].playerally playerally
	  setvar tempb 0
	  getactor[myspawner].statnum temp
	  ifvare temp 1024 setvar tempb 1
	  getactor[myspawner].picnum temp
	  ifvarn temp DRONE setvar tempb 1
	  ifvare tempb 1
	  {
		  strength 0
		  setactor[THISACTOR].htextra 10
		  setactor[THISACTOR].htpicnum RADIUSEXPLOSION
	  }
	  getactor[myspawner].x x
	  getactor[myspawner].y y
	  getactor[myspawner].z z
	  subvar z 512 //1024
	  setactor[THISACTOR].x x
	  setactor[THISACTOR].y y
	  setactor[THISACTOR].z z
	  ifvare target -1 getactorvar[myspawner].target target

  }
  ifvare mtype 1
  {
	  ifstrength 100 ifrnd 6
	  {
		  espawn NEWSMOKE
		  setactor[RETURN].xrepeat 128
		  setactor[RETURN].yrepeat 128
		  getactor[THISACTOR].cstat temp
		  ifvarand temp 8 nullop else
		  {
			  getactor[THISACTOR].z digz
			  subvar digz 10240
			  setactor[RETURN].z digz
		  }
	  }
  }
  
  ifaction 0
  {
    action ASATSHOOTING
    move TURRVEL faceplayer
    ifvare mtype 1 addstrength 200
  }
  else
    ifaction ASATNSPIN
  {
	getactor[THISACTOR].ang angvar
	ifrnd 128 addvar angvar 64 else subvar angvar 64
	setactor[THISACTOR].ang angvar
	
    ifactioncount 32
    {
      action ASATWAIT
      move TURRVEL faceplayer
      ifvare mtype 1 move TURRVEL faceplayerslow
    }
  }
  else
    ifaction ASATSHOOTING
  {
	ifvarand monstflags 256 state fastshooting
	else
	{
	    ifactioncount 12
	      ifrnd 32
	    {
	      action ASATWAIT
	      move 0
	    }
	    ifcount 32
	      resetcount
	    else
	      ifcount 16
	    {
	      ifcount 17 nullop
	      else
	      {
	        state turretshoot
	      }
	    }
	    else
	      ifcount 4
	    {
	      ifcount 5 nullop
	      else
	      {
		    ifvarn target -1 state turretshoot
		    else
	        ifcansee
	          state turretshoot
	      }
	    }
    }
  }
  else
    ifaction ASATWAIT
  {
    ifactioncount 64
      ifrnd 32
        ifp palive
    {
	   ifvarn target -1 { action ASATSHOOTING move TURRVEL geth }
	   else
          ifcansee
            ifvare playerally 0
	    {
	      action ASATSHOOTING
	      move TURRVEL faceplayer
	      ifvare mtype 1 move TURRVEL faceplayerslow
	    }
    }
  }
  ifhitweapon
  {
    ifdead
    {
      addkills 1 state specialdeath
      sound LASERTRIP_EXPLODE
      debris SCRAP1 15
      spawn EXPLOSION2
      ifvare mtype 1 { ifrnd 128 spawn BURNING else spawn BURNING2 }
      ifvarn myspawner -1
      {
	      getactorvar[myspawner].monstflags temp
	      ifvarand temp 16 subvar temp 16
	      ifvarand temp 32 subvar temp 32
	      ifvarand temp 64 subvar temp 64
	      setactorvar[myspawner].monstflags temp
      }
      killit
    }
    else
    {
      action ASATNSPIN
      debris SCRAP1 4
    }
    move 0
  }
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
actor TRANSPORTERSTAR 0 TRANSFOWARD

ifspawnedby FREEZENOAIM spritepal 1
  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
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
ifvarvarl 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

state changeshotgun

// THIS STATE SHOULD NOT BE CALLED UNLESS YOU HAVE TWO SHOTGUNS

ifvarand ALTSHOTGUN 4
{
	subvar ALTSHOTGUN 4
	ifvarand ALTSHOTGUN 1
	{
		setvar WEAPON2_FIREDELAY 2
		setvar WEAPON2_TOTALTIME 26
		setvar WEAPON2_SHOTSPERBURST 8
		setvar WEAPON2_SPAWN SHOTGUNSHELL
		setvar WEAPON2_FIRESOUND MOSSFIRE
		setvar WEAPON2_SOUND2TIME 13
		setvar WEAPON2_SOUND2SOUND -1
	} else
	{
		setvar WEAPON2_FIREDELAY 4
		setvar WEAPON2_TOTALTIME 30
		setvar WEAPON2_SHOTSPERBURST 7
		setvar WEAPON2_SPAWN SHOTGUNSHELL
		setvar WEAPON2_FIRESOUND SHOTGUN_FIRE
		setvar WEAPON2_SOUND2TIME 15
		setvar WEAPON2_SOUND2SOUND SHOTGUN_COCK
	}
} else
{
	sound DBCLOSE
	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
}


ends

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
    globalsound DUKE_GET
  palfrom 16 0 32
  ifrespawn
  {
    move RESPAWN_ACTOR_FLAG
    spawn RESPAWNMARKERRED
    cstat 32768
  }
  else
    killit
ends

state randgetweapsnds

ifactor DBSPRITE { globalsound DBCLOSE break }

  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
  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
{
	getactor[THISACTOR].hitag temp
	ifvarn temp BOSS1 ifvarn temp BOSS2 ifvarn temp BOSS3 ifvarn temp BOSS4 ifvarn temp BOSS1STAYPUT nullop else
	{
		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

	
//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


actor STEROIDS
  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
        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
  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
  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
  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
  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
  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
  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
  
  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
  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 PISTOLAMMOAMOUNT
        setvar RETURN 65 state itemquote
        ifspawnedby AMMO
          state getcode
        else
          state quikget
      }

enda

actor FREEZEAMMO
  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
        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
  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
  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
  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
  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
  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
  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

actor DEVISTATORAMMO
  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
      {
        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
  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
  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
  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
  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
  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
	          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
	          
          }
          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
  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 SIXPAK
  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
      {
	    ifphealthl MAXPLAYERHEALTH 
	    {
		    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

actor COLA
  
  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
      {
	    ifphealthl MAXPLAYERHEALTH 
	    {
		    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
  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
  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


state changeakimbo

ifvarl akimbo 1
{
	setvar akimbo 9 // countdown timer for moving guns into correct position
	setvar WEAPON1_CLIP 24
	setvar WEAPON1_RELOAD 48
	setvar WEAPON1_FIREDELAY 2
	setvar WEAPON1_TOTALTIME 8
	setvar WEAPON1_FLAGS 68
	setvar WEAPON1_SPAWNTIME 2
	setvar WEAPON1_SPAWN 2533
	setvar WEAPON1_INITIALSOUND 0
	setvar WEAPON1_SOUND2TIME 0
	setvar WEAPON1_SOUND2SOUND 0
	setvar WEAPON1_RELOADSOUND1 4
	setvar WEAPON1_RELOADSOUND2 5
	ifvarn botclip 0 ifvare menutoggle 0
	{
		getplayer[THISACTOR].ammo_amount 1 tempb
		mulvar botclip 2
		ifvarvarg botclip tempb setvarvar botclip tempb
	}
}
else
{
	setvar akimbo -9
	setvar WEAPON1_CLIP 12
	setvar WEAPON1_RELOAD 27
	setvar WEAPON1_FIREDELAY 2
	setvar WEAPON1_TOTALTIME 6
	setvar WEAPON1_FLAGS 4
	setvar WEAPON1_SPAWNTIME 2
	setvar WEAPON1_SPAWN 2533
	setvar WEAPON1_INITIALSOUND 0
	setvar WEAPON1_SOUND2TIME 0
	setvar WEAPON1_SOUND2SOUND 0
	setvar WEAPON1_RELOADSOUND1 4
	setvar WEAPON1_RELOADSOUND2 5
	ifvarn botclip 0 ifvarg timer 1 ifvare menutoggle 0
	{
		setvarvar temp botclip
		divvar botclip 2
	}
		
		
}

ends

actor FIRSTGUNSPRITE
  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
      {
	      ifvare useakimbo YES
	      {
		      getplayer[THISACTOR].gotweapon 1 temp
		      ifvare temp 1 ifvare akimbo -1 state changeakimbo
	      }
        ifgotweaponce 0
          break
        ifspawnedby LIZTROOP addweapon PISTOL_WEAPON 12 else
        addweapon PISTOL_WEAPON 48
        setvar RETURN 1118 state itemquote
        ifspawnedby FIRSTGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
    
enda

define REVERSERIPPLE 1679
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 20 20 action PIPEFRAME }
  
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
	  {
		  findnearspritez SHOOTME 3072 24576 spriteid
		  ifvare spriteid -1 findnearspritez SHOOTMEALLY 4096 32768 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 setvar target -1	  
		  	  }
	  	  }
	  }
	  ifvarn target -1
	  {
	  	getactorvar[target].monstatus monstatus
	  	ifvare monstatus 2 setvar target -1
  	  }
	  ifvarn target -1
	  {
	  	getactor[target].statnum temp
	  	ifvarg temp 2 setvar target -1
	  }
	  ifvarn target -1
	  {
	  	getactor[target].extra temp
	  	ifvarl temp 1 setvar target -1
	  }
	  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
  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
    	}
        ifspawnedby CHAINGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
    

enda

actor CHAINGUNSPRITE

  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
		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
    	}
        ifspawnedby CHAINGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
    
enda



actor SHRINKERSPRITE
  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
        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 40 40
  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
        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 SHRINKERSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
      
enda

actor FREEZESPRITE
  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 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

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

state drop_ammo
ifvarn droptile 0 break
  ifrnd SPAWNAMMOODDS
  {
	ifvare useakimbo YES ifvare akimbo -1
	ifrnd 16 espawn FIRSTGUNSPRITE else
    espawn AMMO
    setactorvar[RETURN].peractor4 13
  }
ends

state drop_battery
ifvarn droptile 0 break
  ifrnd SPAWNAMMOODDS
  {
    espawn BATTERYAMMO
    setactorvar[RETURN].peractor4 13
  }
ends
state drop_sgshells
ifvarn droptile 0 break
  ifrnd SPAWNAMMOODDS
  {
    espawn SHOTGUNAMMO
    setactorvar[RETURN].peractor4 13
  }
ends
state drop_shotgun
ifvarn droptile 0 break
  ifrnd SPAWNAMMOODDS
  {
	ifvarand monstflags 256 espawn DBSPRITE else
    espawn SHOTGUNSPRITE
    setactorvar[RETURN].peractor4 13
  }
  else ifvarand monstflags 256 ifrnd SPAWNAMMOODDS
  {
	  espawn SHOTGUNSPRITE
      setactorvar[RETURN].peractor4 13
      // DOUBLE CHANCE AT DBSHOTGUN
  }
ends
state drop_chaingun
ifvarn droptile 0 break
  ifrnd SPAWNAMMOODDS
  {
    ifrnd 32
      espawn CHAINGUNSPRITE
    else
      espawn BATTERYAMMO
    setactorvar[RETURN].peractor4 13
  }
ends


state random_wall_jibs
  ifrnd 96
    shoot BLOODSPLAT1
  ifrnd 96
    shoot BLOODSPLAT2
  ifrnd 96
    shoot BLOODSPLAT3
  ifrnd 96
    shoot BLOODSPLAT4
  ifrnd 96
    shoot BLOODSPLAT1
ends




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
      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

      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 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

        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



state troop_body_jibs
  //ifrnd 64
    guts HEADJIB1 1
  //ifrnd 64
    guts LEGJIB1 2
  //ifrnd 64
    guts ARMJIB1 1
  ifrnd 48
    spawn BLOODPOOL
ends

state liz_body_jibs
  //ifrnd 64
    guts LIZMANHEAD1 1
  //ifrnd 64
    guts LIZMANLEG1 2
  //ifrnd 64
    guts LIZMANARM1 1
  ifrnd 48
    spawn BLOODPOOL
ends

action BLOODFRAMES 0 4 1 1 15
actor BLOOD 0 BLOODFRAMES
  sizeto 72 72 sizeto 72 72 sizeto 72 72
  ifpdistg 3144 killit
  ifactioncount 4 killit
enda

action EGGOPEN1 1 1 1 1 4
action EGGOPEN2 2 1 1 1 4
action EGGOPEN3 2 1 1 1 4
action EGGWAIT  0
action EGGFROZEN 1
action EGGGROW 1
action EGGSHRUNK 1

actor EGG TOUGH
  state monsterai
  setvar countvarb 0 // to prevent it from targetting enemies and facing them
  fall
  ifaction 0
  {
    ifcount 64
    {
      ifrnd 128
      {
        action EGGWAIT
        move 0
      }
      else
      {
        sound SLIM_HATCH
        action EGGOPEN1
      }
    }
  }
  else
    ifaction EGGOPEN1
      ifactioncount 4
        action EGGOPEN2
  else
    ifaction EGGOPEN2
      ifactioncount 4
    {
	  ifvarand monstflags 16
	  {
		espawn NEWBEASTHANG
	  	setactorvar[RETURN].mtype 1
      	setactorvar[RETURN].playerally playerally
      	//setactorvar[RETURN].monstflags 256
      	getactor[THISACTOR].pal pal
      	setactor[RETURN].pal pal
  	  } else
      spawn GREENSLIME
      action EGGOPEN3
    }
  else
    ifaction EGGGROW
      state genericgrowcode
  else
    ifaction EGGSHRUNK
      state genericshrunkcode
  else
    ifaction EGGFROZEN
  {
    ifcount THAWTIME
    {
      action 0
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      lotsofglass 30

      sound GLASS_BREAKING
      ifrnd 84
        spawn BLOODPOOL

      addkills 1 state specialdeath
      killit
    }

    // ifp pducking
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick

    break
  }

  ifhitweapon
  {
    ifdead
    {
      ifwasweapon FREEZEBLAST
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action EGGFROZEN
        strength 0
        break
      }
      else
        ifwasweapon GROWSPARK
      {
        cstat 0
        move 0
        sound ACTOR_GROWING
        action EGGGROW
        break
      }

      addkills 1 state specialdeath

      sound SQUISHED

      state standard_jibs
      killit
    }
    else
      ifwasweapon SHRINKSPARK
      {
        move 0
        sound ACTOR_SHRINKING
        action EGGSHRUNK
        break
      }

      ifwasweapon GROWSPARK
        sound EXPANDERHIT
  }
  else
    ifaction EGGWAIT
  {
    ifcount 512
      ifrnd 2
    {
      ifaction EGGSHRUNK
        break
      sound SLIM_HATCH
      action EGGOPEN1
    }
  }

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 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 }

	  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
					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
					espawn BULLETHOLE
					state getceilz
					setactor[RETURN].z z
					setactor[RETURN].cstat 32
				}
			}
		}
		
	  
	  getactor[THISACTOR].htg_t 8 temp // temp = hitsprite
	  ifvarn temp -1
	  {
	       getactor[temp].picnum picnum
	       switch picnum
	       case FIREBALLPROJ
	       setactor[temp].yvel 0
	       break
	       case WATERTILE2
	       case WATERFLOW
	       spawn WATERSPLASH3
	       sound ITEM_SPLASH
	       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 BOSS2CORPSE
			case BOSS3CORPSE
			 espawn JIBS6
		     setactor[RETURN].xrepeat 32
		     setactor[RETURN].yrepeat 32
		     setvar mtype 1
	       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
	       break
	       case ROTATEGUN
	       case TANK
	       case DRONE
	       case RECON
	       		state HITMETALSOUND
	       break
	       endswitch
	   }
   }
enda

move DUKENOTMOVING
state handle_dead_dukes
  fall
  ifmove 0   // 1st time initializiation...
  {
    ifrnd 128
      cstat 4
    else
      cstat 0
    move DUKENOTMOVING
  }

  ifsquished
  {
    sound SQUISHED
    state random_ooz
    killit
  }
  else
    ifcount 1024
      ifpdistg 4096
        killit
  else
  {
    strength 0
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      state standard_jibs
      killit
    }
  }
ends

action PLYINGFRAMES 0 1 0 1 1
actor DUKELYINGDEAD 0 PLYINGFRAMES
  state handle_dead_dukes
enda

action PGROWING   0
action PSTAND     0   1   5   1  1
action PEXPLODE   106   5   1   1   10
action PEXPLODEAD   113   1   1
action PJPHOUVER  15   1   5   1
action PWALK    20   4   5   1   16
action PRUN     20   4   5   1   10
action PWALKBACK  45   4   5  -1   16
action PRUNBACK   45   4   5  -1   10
action PJUMPING   50   4   5   1   30
action PFALLING   60   1   5
action PDUCKING   86   1   5
action PCRAWLING  86   3   5   1   20
action PAKICKING  40   2   5   1   25
action PFLINTCHING  106  1   1   1   10
action PTHROWNBACK  106  5   1   1   18
action PFROZEN     20  1   5
action PLYINGDEAD   113  1   1

action PSWIMMINGGO   375   1   5   1   10
action PSWIMMING   375   4   5   1   13
action PSWIMMINGWAIT 395   1   5   1   13
action PTREDWATER  395   2   5   1   17

action PSKICKING 40 2 5 1 20

move PSTOPED
move PSHRINKING // used as a var only

state check_pstandard
  ifp pwalking
    action PWALK
  else
    ifp pkicking
      action PAKICKING
  else
    ifp pwalkingback
      action PWALKBACK
  else
    ifp prunning
      action PRUN
  else
    ifp prunningback
      action PRUNBACK
  else
    ifp pjumping
      action PJUMPING
  else
    ifp pducking
      action PDUCKING
ends

state wallhitscan

getactor[spriteid].picnum picnum
ifvare picnum TRIPBOMB break

getactor[spriteid].pal pal
ifvarg pal 69 break
getactorvar[spriteid].pulse pal
ifvarn pal 0 break

// the sprite ID of the scanning projectile has been put in spriteid before this state is called
getactor[spriteid].x x
getactor[spriteid].y y
getactor[spriteid].z z
getactor[spriteid].sectnum mysector
ifvare mysector -1 updatesector x y mysector
ifvarl mysector 0 break
ifvarg mysector 4095 break
getactor[spriteid].ang angvar
addvar angvar 1024
cos mycos angvar
sin mysin angvar
hitscan x y z mysector mycos mysin 0 hitsector hitwall hitsprite hitx hity hitz clipmask

state pythagoras
ifvarg xydist 1024 setvar hitwall -1
ifvarn hitwall -1
{
	setactorvar[spriteid].mywall hitwall
	getactor[spriteid].shade shade
	setactorvar[spriteid].initshade shade
	getwall[hitwall].shade shade
	setactorvar[spriteid].ammo shade
}
else 
{
	setactorvar[spriteid].mywall 32768 // dummy value
	getactor[spriteid].sectnum hitsector
	getsector[hitsector].floorshade shade
	setactorvar[spriteid].ammo shade
	getactor[spriteid].shade shade
	setactorvar[spriteid].initshade shade
} 
	
ends

state checkhitscan

getplayer[THISACTOR].posx x
getplayer[THISACTOR].posy y
getplayer[THISACTOR].posz z
getplayer[THISACTOR].cursectnum temp
ifvarl temp 0 
	break // i don't know what this will fuck up but it has to be better than those log errors
ifvarg temp 4095 break

ifvarvarn temp mysector
{
	// just moved to new sector
	setvarvar prevsectstartx lastsectstartx
	setvarvar prevsectstarty lastsectstarty
	setvarvar prevsectstartz lastsectstartz
	setvarvar lastsectstartx cursectstartx
	setvarvar lastsectstarty cursectstarty
	setvarvar lastsectstartz cursectstartz
	getplayer[THISACTOR].posx cursectstartx
	getplayer[THISACTOR].posy cursectstarty
	getplayer[THISACTOR].posz cursectstartz
	addvar cursectstartz 6144
}

setvarvar mysector temp
getplayer[THISACTOR].ang angvar
getplayer[THISACTOR].horiz zdist
subvar zdist 100
mulvar zdist -2048
cos mycos angvar
sin mysin angvar

// horiz at 0 z angle is 100; pos for up, neg for down

hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask

setvar nextsector -1
ifhitspace
{
	ifvarn hitwall -1
	{
	  state pythagoras
	  ifvarl xydist 480
	  getwall[hitwall].nextsector nextsector
  	}
}

setvarvar scannedsprite hitsprite


ends

state projectilehitscan

// the sprite ID of the scanning projectile has been put in spriteid before this state is called
getactor[spriteid].x x
getactor[spriteid].y y
getactor[spriteid].z z
getactor[spriteid].sectnum mysector
getactor[spriteid].ang angvar
getactor[spriteid].zvel zvel
getactor[spriteid].xvel xvel
shiftvarl zvel 14
ifvare xvel 0 setvar xvel 1
divvarvar zvel xvel
cos mycos angvar
sin mysin angvar
hitscan x y z mysector mycos mysin zvel hitsector hitwall hitsprite hitx hity hitz clipmask
ends

state runningcode

ifp pjetpack break
subvar runflag 1

setvarvar temp strafedir
mulvarvar temp laststrafedir
ifvarl temp 0 setvar runcount 1 // lose speed if switching strafe directions

ifvarn forbackdir 0
{
	ifvare strafedir 13
		ifvarg runcount 20 setvar runcount 20
	ifvare strafedir -13
		ifvarg runcount 20 setvar runcount 20
}

ifvarg strafedir 0 subvar strafedir 1
ifvarl strafedir 0 addvar strafedir 1
ifvarg forbackdir 0 subvar forbackdir 1
ifvarl forbackdir 0 addvar forbackdir 1


ifp prunning ifvarg runflag 0
{
	ifvare runcount SPEED2TIME setplayer[THISACTOR].runspeed RUNNINGSPEED
	else
	{
		ifp pducking nullop else ifp ponground addvar runcount 1
		ifvarg runcount SPEED2TIME setvar runcount SPEED2TIME
		else
		{
			setvar temp SPEED1
			setvarvar tempb runcount
			mulvar tempb ACCEL
			addvarvar temp tempb
			ifp pducking { mulvar temp 4 divvar temp 5 }
			ifvarg temp RUNNINGSPEED setvar temp RUNNINGSPEED
			setplayer[THISACTOR].runspeed temp
		}
	}
}
else
{
	setvar temp RUNNINGSPEED
	ifp pducking { mulvar temp 4 divvar temp 5 }
	
	ifvare runcount 0 setplayer[THISACTOR].runspeed temp
	else ifp pfalling nullop else
	
	ifp ponground
	{
		subvar runcount 2
		ifvarl runcount 0 setvar runcount 0
		setplayer[THISACTOR].runspeed temp
	}
	
}

setvarvar lastforbackdir forbackdir
setvarvar laststrafedir strafedir

ends

state raincode

setvar tempe 0
setvar countvar 0
setvarvar countvarb raining
ifvarl countvarb 0 mulvar countvarb -1
ifmultiplayer nullop else
{
	ifvarvarg countvarb framerate ifvarg framerate 0 setvarvar countvarb framerate
}
ifvarg countvarb 64 setvar countvarb 64
whilevarvarn countvar countvarb
{
	addvar countvar 1
	getplayer[THISACTOR].posx x
	getplayer[THISACTOR].posy y
	setvarvar xydist x
	randvarvar temp rainradius // the random component of the distance from player
	addvar temp 512
	addvarvar xydist temp
	randvar angvar 2047
	
	rotatepoint x y xydist y angvar tempb y
	// tempb and y are the new x and y coords
	updatesector tempb y mysector
	ifvarn mysector -1
	{
		getsector[mysector].ceilingstat temp
		getsector[mysector].ceilingpicnum picnum
		ifvarn picnum MOONSKY1 ifvarn picnum BIGORBIT1
		ifvarand temp 1
		{
			getceilzofslope mysector tempb y z // z is the return var
			ifvarl raining 0 // don't put snow too high up
			{
				getplayer[THISACTOR].posz temp
				setvarvar tempc temp // save posz in tempc
				subvarvar temp z // positive value is distance above player to ceiling
				ifvarvarg temp snowceiling 
				{
					subvarvar tempc snowceiling 
					setvarvar z tempc 
				}
			}
			updatesectorz tempb y z mysector
			ifvarn mysector -1
			{
				espawn RAINSPRITE
				setactor[RETURN].x tempb
				setactor[RETURN].y y
				setactor[RETURN].z z
				setactor[RETURN].sectnum mysector
				addvar tempe 1
			}
		}
	}
}
ifvarg raining 16 
{
	ifoutside ifvare headunder 0
		soundonce RAIN
	 else
	{
		stopsound RAIN
	    ifvarg tempe 4 
	    soundonce RAINWINDOW //else stopsound RAINWINDOW
    }
}

ends

state slipperycode

ifp pjetpack break 
iffloordistl 48 nullop else break

getsector[THISACTOR].lotag lotag
ifvarn lotag 50
{
	getplayer[THISACTOR].spritebridge temp
	ifvare temp 1
	{
		getplayer[THISACTOR].sbs spriteid
		getactor[spriteid].lotag lotag
	}
	ifvarn lotag 50 break
}

getplayer[THISACTOR].posxv xvel
setvar x 0
ifvarg xvel 0 ifvarvarl xvel oposxv setvar x -1 // slowing down x vel
ifvarl xvel 0 ifvarvarg xvel oposxv setvar x -1

getplayer[THISACTOR].posyv yvel
setvar y 0
ifvarg yvel 0 ifvarvarl yvel oposyv setvar y -1 // slowing down y vel
ifvarl yvel 0 ifvarvarg yvel oposyv setvar y -1

ifvarg dodge 0 ifvare jumpadxvel 0 { setvar x -1 setvar y -1 }
	
subvarvar oposxv xvel
ifvare x -1
{ 
	mulvar oposxv 15 divvar oposxv 16
} else
{
	mulvar oposxv 3 divvar oposxv 4
}
addvarvar xvel oposxv
setplayer[THISACTOR].posxv xvel

subvarvar oposyv yvel
ifvare y -1
{
	mulvar oposyv 15 divvar oposyv 16
} else
{
	mulvar oposyv 3 divvar oposyv 4
}
addvarvar yvel oposyv
setplayer[THISACTOR].posyv yvel

ifvare x -1 state STOPSTEPSOUNDS else
ifvare y -1 state STOPSTEPSOUNDS
ends

state laddercode

ifaction PSTAND nullop else action PSTAND
ifp ponground setvar bpress 0
setplayer[THISACTOR].falling_counter 0
ifvare fpress 0 ifvare bpress 0
{
	 setvar laddervel -256
	 getplayer[THISACTOR].posx lastladderx
	 getplayer[THISACTOR].posy lastladdery
}
 else
 {
	 soundoncevar laddersound
	 getplayer[THISACTOR].posz z
	 updatesectorz lastladderx lastladdery z mysector
	 ifvarn mysector -1
	 {
		 setplayer[THISACTOR].posx lastladderx
		 setplayer[THISACTOR].posy lastladdery
		 getplayer[THISACTOR].i spriteid
		 setactor[spriteid].x lastladderx
		 setactor[spriteid].y lastladdery
	 }
 }
ifp ponground setvar laddervel 0 else
{
	setplayer[THISACTOR].posxv 0
	setplayer[THISACTOR].posyv 0
}
subvar onladder 1
setplayer[THISACTOR].poszv laddervel

ends

define MANTDIST 480

// state checkmantlesprite

// ifvarn hitsprite -1
// {
// 	getactor[hitsprite].picnum picnum
// 	ifvare picnum 3699 // special mantling sprite
// 	ifvarl xydist MANTDIST
// 		setvar mantling 1
// }
// ends

gamevar watch 0 0

state checkwall // checks to see if there is a close wall to grab onto

// mantling will be set to 1 if the answer is yes, 0 otherwise
setvar mantling 0

getactor[THISACTOR].z z
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].sectnum mysector
getactor[THISACTOR].ang angvar
setvar zdist 0
cos mycos angvar
sin mysin angvar

hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask
state pythagoras
setvarvar xydist2 xydist // saves the distance
subvar z 1536
hitscan x y z mysector mycos mysin zdist hitsector hitwall2 hitsprite hitx hity hitz clipmask
state pythagoras
ifvarn hitsprite -1
{
	getactor[hitsprite].picnum picnum
	
	ifvare picnum CRATE2 ifvarl xydist 844
	{
		setvar mantling 1 break 
	}
	
}

subvar z 4096

setvar hp 0
whilevarn hp 10 //20
{
	setvar initcstat 1
	hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask
	state pythagoras
	ifvarn hitsprite -1 ifvarl xydist MANTDIST getactor[hitsprite].cstat initcstat
	setvarvar xydist2 xydist
	subvar z 512 //256
	hitscan x y z mysector mycos mysin zdist hitsector hitwall2 hitsprite hitx hity hitz clipmask
	state pythagoras
	ifvarn hitsprite -1 ifvarl xydist MANTDIST
	{
		getactor[hitsprite].picnum picnum
		ifvarn picnum BGRATE1 ifvarn picnum FANSPRITEBROKE
		getactor[hitsprite].cstat initcstat
	}
	
	
	ifvare watch 1
	{
		addlogvar xydist
		addlogvar xydist2
		addlogvar hitsprite
		addlogvar hitwall
		addlogvar hitwall2
		addlogvar initcstat
	}
	ifvarg xydist2 MANTDIST nullop else
	ifvare hitsprite -1 ifvare hitwall -1 nullop else
	ifvarn hitwall -1 ifvarvare hitwall hitwall2 nullop else
	ifvarand initcstat 1
	{
		ifvarvarg xydist xydist2 
		{
			setvar mantling 1
			ifvare hitsprite -1
			setvar mantling 1 else
			{
				getactor[hitsprite].cstat tempb
				ifvarand tempb 32768 nullop else
				ifvarand tempb 1 setvar mantling 1
			}
		}
		else ifvarn hitsprite -1
		{
		    ifvare picnum BGRATE1
		    setvar mantling 1
		    ifvare picnum FANSPRITEBROKE
		    setvar mantling 1
	    }
	}
	
	
	addvar hp 1
	ifvare mantling 1 setvar hp 10 //20
	subvar z 512 // 256
}

ends

state mantlingcode

ifonwater nullop else
ifvare scaled NO
{
	getplayer[THISACTOR].jumping_counter temp
	ifp ponsteroids setvar tempb 901 else setvar tempb 721
	ifvarvare temp tempb setplayer[THISACTOR].jumping_counter 0
}

ifp ponground ifvare jumped 1 setvar jumped 0
ifvarl mantling 0 addvar mantling 1
ifvare mantling 1 addvar mantwait 1 else setvar mantwait 0

ifvarn onladder 0 break
ifvarg dodge 0 break
ifvarn holding -1 break

ifvare mantling 0 ifvare jumpadxvel 0
{
	getplayer[THISACTOR].posx x
	getplayer[THISACTOR].posy y
	getactor[THISACTOR].z z
	getplayer[THISACTOR].cursectnum mysector
	ifvare mysector -1 getsector[THISACTOR].floorz mz else
	getflorzofslope mysector x y mz // mz is the return var
	subvarvar mz z // mz is now the distance to the ground
	setvar temp 0
	ifvarg mz 6144 setvar temp 1
	ifvarg underwater 0 
	{
		ifvarg mz 3072 setvar temp 1
		ifvarand bits 1 nullop else setvar temp 0
	}
	ifvare temp 1 
	{
		getplayer[THISACTOR].poszv zvel
		ifvare jumped 1 setvar tempb 0 else setvar tempb 1536
		ifvarg underwater 0 setvar zvel 2048
		//ifonwater setvar zvel 2048
		//ifinwater setvar zvel 2048
		ifvarvarg zvel tempb
		{
			state checkwall
			ifvare mantling 1 
			{
				getplayer[THISACTOR].posz mantz
				ifvarg underwater 0
				setplayer[THISACTOR].sound_pitch 0
				sound DUKE_GRUNT
				wackplayer
				getplayer[THISACTOR].posz z
				subvar z 512
				setplayer[THISACTOR].posz z
				shiftvarr zvel 7
				addvar zvel 3
				setvarvar mantwaittime zvel
				ifvarg mantwaittime 40 setvar mantwaittime 40
			}
			
		}
	}

}

ifvarg mantling 0
{
	
	ifvare mantling 1 // hanging there, possibly strafing
	{
		setplayer[THISACTOR].falling_counter 0
		getplayer[THISACTOR].posxv xvel
		divvar xvel 2
		setplayer[THISACTOR].posxv xvel
		getplayer[THISACTOR].posyv yvel
		divvar yvel 2
		setplayer[THISACTOR].posyv yvel
		setplayer[THISACTOR].posz mantz
		setplayer[THISACTOR].poszv -256 // 0
		state checkwall
		ifvare mantling 0
		{
			ifvarg underwater 0 ifvarand bits 1 setvar mantling 2 else
			ifvarg mantcheck 0 setvar mantling 1
		} else setvar mantcheck 6 // 6 ticks grace period
	}
	else
	{
		setplayer[THISACTOR].poszv -1536
		getplayer[THISACTOR].ang angvar
		cos xvel angvar
     	sin yvel angvar
        mulvar xvel 64 
        mulvar yvel 64
		setplayer[THISACTOR].posxv xvel
		setplayer[THISACTOR].posyv yvel
		getactor[THISACTOR].z z
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		getactor[THISACTOR].sectnum mysector
		getactor[THISACTOR].ang angvar
		setvar zdist 0
		cos mycos angvar
		sin mysin angvar
		hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask
		state pythagoras
		ifvarg xydist 384 ifvarg mantling 5 setvar mantling -10
		//addvar mantling 1
		else
		ifvarand bits 1 addvar mantling 1 else setvar mantling -10
		ifvarg mantling 23 setvar mantling -10
		setplayer[THISACTOR].jumping_toggle 1
	}
	
}

ends

state dodgewallcheck // checks to see if there is a close wall in the actor's path at angvar

getactor[THISACTOR].z z
subvar z 6144
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].sectnum mysector
setvar zdist 0
cos mycos angvar
sin mysin angvar

hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask

// temp will be set to 1 if the answer is yes, 0 otherwise
setvar temp 0
ifvarn hitsprite -1
{
	 getactor[hitsprite].cstat tempb
	 ifvarand tempb 16 nullop else
	 ifvarand tempb 1 nullop else 
		   break
	   
}
espawn NOTHING
setactor[RETURN].x hitx
setactor[RETURN].y hity
setactor[RETURN].z hitz
ldist xydist THISACTOR RETURN

// next code gets distance between (x,y) and (hitx,hity), puts result in xydist

ifvarg xydist 512 break

setvar temp 1

ends

state walljumpcode

setvarvar angvar dodgeang
addvar angvar 1024
state dodgewallcheck
ifvare temp 1 
{
	addvar walljump 1
	addvar runcount 3
	getplayer[THISACTOR].falling_counter digz
	ifvarg digz 8 
	{
		subvar digz 8
		setplayer[THISACTOR].falling_counter digz
		setvar dodgeagain 5
	}
}

ends

state dodgecode

ifvarg dodgeagain 0 subvar dodgeagain 1

setvarvar tempb dodge
setvar temp FREERUNNER
ifvare temp YES ifvarn walljump 0 setvar tempb 0

ifp palive
   //ifvare dodge 0 
   ifvare tempb 0
     ifvare dodgeagain 0
   {
	   setvar temp 0
	   ifp ponground ifvare walljump 0 setvar temp 1
	   
	   ifvare ltap 2
	   {
		  getplayer[THISACTOR].ang dodgeang
		  subvar dodgeang 512
		  ifvare temp 0 state walljumpcode

		  ifvare temp 1
		  {  
		     setvar dodge 10
		     sound DUKE_GRUNT
	      }
	   }
	   ifvare rtap 2
	   {
		  getplayer[THISACTOR].ang dodgeang
		  addvar dodgeang 512
		  ifvare temp 0 state walljumpcode
		  
		  ifvare temp 1
		  {
		     setvar dodge 10
		     sound DUKE_GRUNT
	      }
	   }
	   ifvare ftap 2
	   {
		  getplayer[THISACTOR].ang dodgeang
		  ifvare temp 0 state walljumpcode
		  ifvare temp 1
		  {
		     setvar dodge 10
		     sound DUKE_GRUNT 
	      }
	   }
	   ifvare btap 2
	   {
		  getplayer[THISACTOR].ang dodgeang
		  addvar dodgeang 1024
		  ifvare temp 0 state walljumpcode

		  ifvare temp 1
		  {
		     setvar dodge 10
		     sound DUKE_GRUNT
	      }
	   }
   }
 
 
ifvarg dodge 0
{
	 cos xvel dodgeang
     sin yvel dodgeang
     ifvarn jumpadxvel 0
     {
	     mulvarvar xvel jumpadxvel
	     mulvarvar yvel jumpadxvel
     }
     else
     {
	     ifvarg superkicking 0
	     {
		     ifvare spinkick 1
		     {
			     shiftvarl xvel 7
			     shiftvarl yvel 7
		     } else
		     {
			     shiftvarl xvel 8
			     shiftvarl yvel 8
		     }
	     }
	     else
	     {
		     mulvar xvel 352
		     mulvar yvel 352
	     }
	     setvar temp FREERUNNER
	     ifvare temp YES
	     ifvarg walljump 0
	     {
		     shiftvarr xvel 1
		     shiftvarr yvel 1
	     }
     }
	 ifvarg walljump 0
	 {
		 setvar zvel -1536
		 ifvarg walljump 1 
		 {
			 setvarvar tempb walljump
		     divvar tempb 2
		     ifvare tempb 0 setvar tempb 1
			 divvarvar zvel tempb
		 }
		 setplayer[THISACTOR].poszv zvel
	 }
	 
	 setplayer[THISACTOR].posxv xvel
	 setplayer[THISACTOR].posyv yvel
	 ifvarn jumpadxvel 0 
	 {
		 setplayer[THISACTOR].falling_counter 0
		 ifaction PJUMPING nullop else action PJUMPING
	 }
}

ends

state underwatercode

getplayer[THISACTOR].posxv xvel
mulvar xvel 5 divvar xvel 4
ifvarg xvel 1000000 setvar xvel 1000000
ifvarl xvel -1000000 setvar xvel -1000000
setplayer[THISACTOR].posxv xvel
getplayer[THISACTOR].posyv yvel
mulvar yvel 5 divvar yvel 4
ifvarg yvel 1000000 setvar yvel 1000000
ifvarl yvel -1000000 setvar yvel -1000000
setplayer[THISACTOR].posyv yvel

getactorvar[watereffector].initx temp // waterspeed
ifvarn temp 0 ifvare mantling 0 // moving water
{
	getactor[watereffector].ang angvar // water direction
	cos xvel angvar
    sin yvel angvar
	mulvarvar xvel temp
	mulvarvar yvel temp
	
    getplayer[THISACTOR].posxv mx
    setvarvar tempc xvel
    divvar tempc 2
    addvarvar mx tempc // xvel
	getplayer[THISACTOR].posyv my
	setvarvar tempc yvel
	divvar tempc 2
	addvarvar my tempc // yvel
	ifvarg xvel 0 
	{
		ifvarl xvel 1000000 setvar xvel 1000000
		ifvarvarg mx xvel setvarvar mx xvel
	}
	else 
	{
		ifvarg xvel -1000000 setvar xvel -1000000
		ifvarvarl mx xvel setvarvar mx xvel
	}
	ifvarg yvel 0
	{
		ifvarl yvel 1000000 setvar yvel 1000000
		ifvarvarg my yvel setvarvar my yvel
	}
	else 
	{
		ifvarg yvel -1000000 setvar yvel -1000000
		ifvarvarl my yvel setvarvar my yvel
	}
	
	setplayer[THISACTOR].posxv mx
	setplayer[THISACTOR].posyv my
}

ifvarg underwater 3 soundonce ITEM_SPLASH
else
ifvare underwater 1 
{
	setgamepalette 0
	setuserdef[THISACTOR].const_visibility DEFAULTVISIBILITY
	setplayer[THISACTOR].footprintcount 6
	setplayer[THISACTOR].footprintpal 0
	setplayer[THISACTOR].footprintshade 0
	stopsound DUKE_UNDERWATER
	setplayer[THISACTOR].sound_pitch 0
	setplayer[THISACTOR].runspeed RUNNINGSPEED
	stopsound DUKE_UNDERWATER
	getactor[watereffector].sectnum tempb
	//getactorvar[watereffector].pal temp
	//setsector[tempb].floorpal temp
	break
}


getactor[watereffector].z peractor2
setplayer[THISACTOR].falling_counter 0
setvar temp RUNNINGSPEED
mulvar temp 2 divvar temp 3
setplayer[THISACTOR].runspeed temp
setplayer[THISACTOR].footprintcount 0

getplayer[THISACTOR].posz z
addvar z 512
getactorvar[watereffector].monstflags temp
ifvarvarg z peractor2 setvar temp 1
ifvare temp 1
{
	setgamepalette 1
	setvar headunder YES
	stopsound RAIN
	getactorvar[watereffector].initshade temp
	addvar temp 1
	shiftvarl temp 5
	addvar temp DEFAULTVISIBILITY
	setuserdef[THISACTOR].const_visibility temp
	
	getactor[watereffector].pal waterpal
	getactor[watereffector].sectnum tempb
	//setsector[tempb].floorpal 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
	setplayer[THISACTOR].sound_pitch 0
	setplayer[THISACTOR].crack_time 777
	soundonce DUKE_UNDERWATER
	setplayer[THISACTOR].sound_pitch -1024
	getplayer[THISACTOR].scuba_amount temp
	ifvarg temp 0
	{
		subvar temp 1
		setplayer[THISACTOR].scuba_amount temp
		setplayer[THISACTOR].scuba_on 1
		setvar oxygen 390
	}
	else
	{
		ifvarg oxygen 0 subvar oxygen 1
		setplayer[THISACTOR].airleft oxygen
		ifvare oxygen 0
		{
			getplayer[THISACTOR].extra_extra8 temp
			addvar temp 32
			setplayer[THISACTOR].extra_extra8 temp
		}
	}
}
else 
{
	setgamepalette 0
	setvar headunder 0
	stopsound DUKE_UNDERWATER
	setplayer[THISACTOR].sound_pitch 0
	setuserdef[THISACTOR].const_visibility DEFAULTVISIBILITY
	getactor[watereffector].sectnum tempb
	//getactorvar[watereffector].pal temp
	//setsector[tempb].floorpal temp
	ifvarl oxygen 312 sound DUKE_GASP
	setvar oxygen 390
}


getplayer[THISACTOR].poszv zvel
ifvarg zvel 0
{
 	subvar zvel 480
 	ifvarl zvel -176 setvar zvel -176
 	setplayer[THISACTOR].poszv zvel 
}

ends

state botcommandcode

ifhitspace
  ifvarvarn hitsprite botselected
{
	setactorvar[botselected].initx hitx
	setactorvar[botselected].inity hity
	setactorvar[botselected].initz hitz
	setactorvar[botselected].command 1
	globalsound EXITMENUSOUND
	setvar botselected -1
	userquote 1003
}
else
{
	espawn BOTMARKER
	setactor[RETURN].x hitx
	setactor[RETURN].y hity
	ifvarn hitsector -1
	{
		getflorzofslope hitsector hitx hity temp
		setactor[RETURN].z temp
	}
}

ends

state positionholding

ifvare drinksoda 0
{
	getactor[holding].pitch temp
	ifvarg temp 0 
	{ 
		subvar temp 32 
		ifvarl temp 0 setvar temp 0 
		setactor[holding].pitch temp 
		setactor[holding].mdzoff 0
	}
}
getplayer[THISACTOR].horiz zdist
subvar zdist 100
mulvar zdist -32
addvarvar mz zdist
rotatepoint x y digx y angvar mx my
updatesectorz mx my mz temp
ifvarn temp -1
{
	changespritesect holding temp
	setactor[holding].x mx
	setactor[holding].y my
	ifvarn pickup 0
	{
		getactor[holding].z tempb
		ifvarvarg mz tempb setvarvar mz tempb
	}
	setactor[holding].z mz
}

ends

state holdingcode

ifvarn holding -1
{
	ifvarvare holding gravitysprite soundonce GRAVPULL
	getactor[holding].statnum temp
	ifvare temp 1024 { setvar holding -1 setvar pickup -12 }
	ifvarn holding -1
	{
		getactor[holding].picnum picnum
		ifvarvarn picnum holdingpic { setvar holding -1 setvar pickup -12 }
	}
	ifvarn holding -1
	{
		ifp ponsteroids nullop else
		ifvare gravitysprite -1
		{
			// limit player speed
			getactorvar[holding].weight temp
			ifvarg temp 40
			{
				getplayer[THISACTOR].posxv xvel
				ifvarg xvel 350000 setplayer[THISACTOR].posxv 350000
				ifvarl xvel -350000 setplayer[THISACTOR].posxv -350000
				getplayer[THISACTOR].posyv xvel
				ifvarg xvel 350000 setplayer[THISACTOR].posyv 350000
				ifvarl xvel -350000 setplayer[THISACTOR].posyv -350000
			}
		}
		getplayer[THISACTOR].posz mz
		ifvare holdingpic SAWBLADEGROUND addvar mz 1536 else
		addvar mz 3072
		setvarvar temp pickup
		mulvar temp 640
		addvarvar mz temp
		getplayer[THISACTOR].posx x
		getplayer[THISACTOR].posy y
		setvarvar digx x
		ifvarn drinksoda 0 addvar digx 480 else
		addvar digx 320 //480
		ifvare holdingpic SAWBLADEGROUND addvar digx 80
		ifvare holdingpic CRATE1 addvar digx 80
		ifvarg drinksoda 20
		{
			setvarvar temp drinksoda
			subvar temp 20
			shiftvarl temp 4
			ifvarg temp 240 
			{
				setvar temp 240
				ifvarl drinksoda 70 soundonce DUKE_TAKEPILLS
			}
			subvarvar digx temp
			setvarvar temp drinksoda
			subvar temp 20
			shiftvarl temp 7
			ifvarg temp 4096 setvar temp 4096
			subvarvar mz temp
		}
		getplayer[THISACTOR].ang angvar
		state positionholding
		ifvare temp -1 ifvare pickup 0 // object not in sector
		{
			getactorvar[holding].bouncesound temp
			ifvarn temp -1 soundoncevar temp
			subvar digx 96
			state positionholding
			ifvare temp -1 ifvarn holdingpic FUSE ifvarvarn holding gravitysprite
			{
				getactorvar[holding].initcstat temp
				setactor[holding].cstat temp
				setactor[holding].x x
				setactor[holding].y y
				//subvar mz 6144
				setactor[holding].z mz
				setvar holding -1
				setvar pickup -12
				setvar drinksoda 0
			}
		}
	
		ifvarg pickup 0 subvar pickup 1
	}
} 
else setvar droptile 0 // in the player, droptile is 1 only when pressing alt-fire should drop the gg's sprite
ifvarl pickup 0 addvar pickup 1

ends

state resetweaponstate

ifvare useakimbo YES
{
	setvar akimbo 1
	state changeakimbo
	setvar akimbo -1
}

ifvare dukemon YES
{
	setvar dukeballstrength 50
	setvar dukeballselected 0
	setvar temp 0
	whilevarn temp MAXTRIPBOMBAMMO
	{
		setarray dukeballpics[temp] 0
		setarray dukeballflags[temp] 0
		setarray dukeballpals[temp] 0
		addvar temp 1
	}

}

setvar SHOTGUNCLIP 0
setvar MP5INCLIP 0
setvar botclip 0
setvar ALTSHOTGUN 0

ends

state sleepingcode

setplayer[THISACTOR].movement_lock 31
setvar ftap 0
setvar btap 0
setvar ltap 0
setvar rtap 0
setactor[THISACTOR].htextra -1
getactor[THISACTOR].extra temp
ifvarl temp MAXPLAYERHEALTH setactor[THISACTOR].extra MAXPLAYERHEALTH
addvar sleeping 1
ifvare sleeping 0 
{
	addvar sleeping 1 // do not let it be zero until finished
	// teleport to next SE if one exists
	setvar spriteid 0
	whilevarn spriteid 16384
	{
		getactor[spriteid].picnum picnum
		getactor[spriteid].statnum temp
		ifvare picnum SECTOREFFECTOR ifvarn temp 1024
		{
			getactorvar[spriteid].lotag temp
			ifvare temp 105
			{
				getactor[spriteid].hitag tempb
				ifvarvare hitag tempb
				{
					getactor[spriteid].x x
					getactor[spriteid].y y
					getactor[spriteid].z z
					setplayer[THISACTOR].posx x
					setplayer[THISACTOR].posy y
					setactor[THISACTOR].z z
					subvar z 8192
					setplayer[THISACTOR].posz z
					getactor[spriteid].sectnum mysector
					changespritesect THISACTOR mysector
					setplayer[THISACTOR].cursectnum mysector
					setactorvar[spriteid].lotag 106
					getactor[spriteid].ang peractor4
					getactor[spriteid].pal temp
					ifvare temp 2
					{
						state resetweaponstate
						setplayer[THISACTOR].gotweapon 1 0
						setplayer[THISACTOR].gotweapon 2 0
						setplayer[THISACTOR].gotweapon 3 0
						setplayer[THISACTOR].gotweapon 4 0
						setplayer[THISACTOR].gotweapon 5 0
						setplayer[THISACTOR].gotweapon 6 0
						setplayer[THISACTOR].gotweapon 7 0
						setplayer[THISACTOR].gotweapon 8 0
						setplayer[THISACTOR].gotweapon 9 0
						setplayer[THISACTOR].gotweapon 11 0
						setplayer[THISACTOR].ammo_amount 1 0
						setplayer[THISACTOR].ammo_amount 2 0
						setplayer[THISACTOR].ammo_amount 3 0
						setplayer[THISACTOR].ammo_amount 4 0
						setplayer[THISACTOR].ammo_amount 5 0
						setplayer[THISACTOR].ammo_amount 6 0
						setplayer[THISACTOR].ammo_amount 7 0
						setplayer[THISACTOR].ammo_amount 8 0
						setplayer[THISACTOR].ammo_amount 9 0
						setplayer[THISACTOR].ammo_amount 11 0
						setplayer[THISACTOR].curr_weapon 0
						setactor[THISACTOR].extra MAXPLAYERHEALTH
						setplayer[THISACTOR].heat_amount 0
						setplayer[THISACTOR].firstaid_amount 0
						setplayer[THISACTOR].steroids_amount 0
						setplayer[THISACTOR].holoduke_amount 0
						setplayer[THISACTOR].jetpack_amount 0
						setplayer[THISACTOR].boot_amount 0
						setplayer[THISACTOR].scuba_amount 0
						setvar fpresstime 0
						setvar bpresstime 0
						setvar lpresstime 0
						setvar rpresstime 0
					}
					
					setvar spriteid 16383
				}
			}
		}
		addvar spriteid 1
	}
}
ifvarg sleeping 0 setplayer[THISACTOR].ang peractor4
setplayer[THISACTOR].pals 0 0
setplayer[THISACTOR].pals 1 0
setplayer[THISACTOR].pals 2 0
setvarvar temp sleeping
ifvarl temp 0
mulvar temp -1
setvar tempb 130
subvarvar tempb temp
mulvar tempb 2 divvar tempb 3
ifvarg tempb 63 setvar tempb 63
setplayer[THISACTOR].pals_time tempb

ifvarg sleeping 130
{
	setvar sleeping 0
	setplayer[THISACTOR].movement_lock 0
}


ends



state normaldev
setvar WEAPON7_SHOTSPERBURST 2
setvar WEAPON7_SHOOTS 2605
setvar WEAPON7_FIRESOUND RPG_SHOOT
setvar WEAPON7_FIREDELAY 3
setvar WEAPON7_TOTALTIME 5
setvar WEAPON7_FLAGS 72
setvar WEAPON7_SPAWNTIME 0
setvar WEAPON7_SPAWN 0
setvar WEAPON7_INITIALSOUND CAT_FIRE
ends

state toggledukemon
quote 1059
sound SWITCH_ON
ifvare dukemon YES
{
	setvar dukemon NO
	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
}
else
{
	setvar dukemon YES
	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
	setplayer[THISACTOR].gotweapon 8 YES
	getplayer[THISACTOR].ammo_amount 8 temp
	ifvarl temp 3 setplayer[THISACTOR].ammo_amount 8 3
}
savegamevar dukemon
ends

state togglegravgun
sound SWITCH_ON
ifvare gravgun YES
{
	setvar gravgun NO
	setvar WEAPON11_SHOOTS GROWSPARK
	setvar WEAPON11_FIRESOUND EXPANDERSHOOT
	setvar WEAPON11_TOTALTIME 5
}
else
{
	setvar gravgun YES
	setvar WEAPON11_SHOOTS GRAVPROJ2
	setvar WEAPON11_FIRESOUND GRAVSHOOTSND
	setvar WEAPON11_TOTALTIME 20
}
savegamevar gravgun
ends

state togglerpg
sound SWITCH_ON
ifvare usebigrox YES
{
	setvar usebigrox NO
	setvar WEAPON4_CLIP 0
	setvar WEAPON4_FLAGS 0
	setvar WEAPON4_RELOAD 0
}
else
{
	setvar usebigrox YES
	setvar WEAPON4_CLIP 2
	setvar WEAPON4_FLAGS 1024
	setvar WEAPON4_RELOAD 78 //104
	setvar WEAPON4_RELOADSOUND1 RPGOPEN
	setvar WEAPON4_RELOADSOUND2 RPGCLOSE
}
savegamevar usebigrox
ends

state togglechaingun
sound SWITCH_ON
ifvare usemp5 YES
{
	setvar usemp5 NO
	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
}
else
{
	setvar usemp5 YES
	setvar WEAPON3_SHOOTS MP5BULLET
	setvar WEAPON3_TOTALTIME 4
	setvar WEAPON3_FIRESOUND MP5FIRE
	setvar WEAPON3_FLAGS 8196
	setvar WEAPON3_CLIP 30
	setvar WEAPON3_SPAWNTIME 2
	setvar WEAPON3_RELOADSOUND1 -1
	setvar WEAPON3_RELOADSOUND2 -1
}
savegamevar usemp5
ends

state toggleshotgun
sound SWITCH_ON
ifvare usemossberg YES
{
	setvar usemossberg NO
	ifvarand ALTSHOTGUN 16 setvar ALTSHOTGUN 16
	else setvar ALTSHOTGUN 0
	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
}
else
{
	setvar usemossberg YES
	ifvarand ALTSHOTGUN 16 { subvar ALTSHOTGUN 16 orvar ALTSHOTGUN 1 }
	setvar WEAPON2_FIREDELAY 2
	setvar WEAPON2_TOTALTIME 26
	setvar WEAPON2_SHOTSPERBURST 8
	setvar WEAPON2_FIRESOUND MOSSFIRE
	setvar WEAPON2_SOUND2TIME 13
	setvar WEAPON2_SOUND2SOUND -1
}
savegamevar usemossberg
ends

state toggleakimbo
sound SWITCH_ON
ifvare useakimbo YES 
{
	setvar akimbo 1
	state changeakimbo
	setvar useakimbo NO 
	setvar akimbo -1
}
else setvar useakimbo YES
savegamevar useakimbo
ends

state swapwall
ifvarvarn J K {
getwall[J].x temp
getwall[K].x tempb
setwall[J].x tempb
setwall[K].x temp
getwall[J].y temp
getwall[K].y tempb
setwall[J].y tempb
setwall[K].y temp
getwall[J].cstat temp
getwall[K].cstat tempb
setwall[J].cstat tempb
setwall[K].cstat temp
getwall[J].picnum temp
getwall[K].picnum tempb
setwall[J].picnum tempb
setwall[K].picnum temp
getwall[J].overpicnum temp
getwall[K].overpicnum tempb
setwall[J].overpicnum tempb
setwall[K].overpicnum temp
getwall[J].shade temp
getwall[K].shade tempb
setwall[J].shade tempb
setwall[K].shade temp
getwall[J].pal temp
getwall[K].pal tempb
setwall[J].pal tempb
setwall[K].pal temp
getwall[J].xrepeat temp
getwall[K].xrepeat tempb
setwall[J].xrepeat tempb
setwall[K].xrepeat temp
getwall[J].yrepeat temp
getwall[K].yrepeat tempb
setwall[J].yrepeat tempb
setwall[K].yrepeat temp
getwall[J].xpanning temp
getwall[K].xpanning tempb
setwall[J].xpanning tempb
setwall[K].xpanning temp
getwall[J].ypanning temp
getwall[K].ypanning tempb
setwall[J].ypanning tempb
setwall[K].ypanning temp
getwall[J].lotag temp
getwall[K].lotag tempb
setwall[J].lotag tempb
setwall[K].lotag temp
getwall[J].hitag temp
getwall[K].hitag tempb
setwall[J].hitag tempb
setwall[K].hitag temp
getwall[J].extra temp
getwall[K].extra tempb
setwall[J].extra tempb
setwall[K].extra temp
getwall[J].nextwall temp
getwall[K].nextwall tempb
setwall[J].nextwall tempb
setwall[K].nextwall temp
getwall[J].nextsector temp
getwall[K].nextsector tempb
setwall[J].nextsector tempb
setwall[K].nextsector temp
}
ends

state mirror

setvar I 0
whilevarn I 16384
{
    getactor[I].x A
    mulvar A -1
    setactor[I].x A
    getactor[I].picnum picnum
    getactor[I].lotag temp
    	
    getactor[I].ang A
    ifvarg A 1024
    {
        setvar B 1536
    } else {
        setvar B 512
    }
    subvarvar B A
    mulvar B 2
    addvarvar A B
    
    setactor[I].ang A
    
    getactor[I].lotag temp
    ifvare picnum SECTOREFFECTOR ifvare temp 0
	{
	    getactor[I].pal temp
	    ifvare temp 2 setactor[I].pal 0 else
	    ifvare temp 0 setactor[I].pal 2
    }
    ifvare picnum SECTOREFFECTOR ifvare temp 11
    {
        ifvarg A 0 ifvarl A 1025 subvar A 1 else
        ifvarg A 1024 ifvarl A 2047 addvar A 1
        addvar A 1025
        ifvarg A 2047 subvar A 2048
        setactor[I].ang A
    }
    addvar I 1
}

setvar I 0
whilevarvarn I NUMWALLS
{
    getwall[I].x A
    mulvar A -1
    setwall[I].x A
    setarray SWAPWALLS[I] -1
    getwall[I].picnum temp
    switch temp
    case 277 case 394 case 415 case 498 case 499
    case 500 case 502 case 518 case 519 case 520 case 521 case 522 case 523 case 524 case 525
    case 526 case 527 case 528 case 529 case 530 case 531 case 532 case 533 case 534 case 535
    case 568 case 593 case 594 case 598 case 599 case 600 case 612 case 613 case 614 case 639
    case 657 case 666 case 667 case 687 case 699 case 721 case 728 case 736 case 766 case 776 
    case 777 case 778 case 784 case 817 case 818 case 822 case 826 case 835 case 838 case 837
    case 841 case 839 case 848 case 849 case 856 case 858 case 871 case 872 case 937 case 938 
    case 945 case 946 case 949 case 961 case 963 case 964 case 965 case 966 case 967 case 968
    case 970 case 980 case 992 case 1043 case 1044 case 1046 case 1047 case 1064 case 1065 case 1066
    case 1072 case 1210 case 1211 case 1212 case 1214 case 1215 case 1217 case 1244 case 1245
    case 2486 case 2492 case 2493 case 2500 case 2504 case 2505 case 2506 case 3370 case 3371 case 3372
    case 3373 case 3374 case 3382 case 3383 case 3391 case 3402 case 3403 case 3421 case 3422 case 3423
    case 4096 case 4108 case 4125 case 4126 case 4238 case 4306 case 4307 case 4318 case 4323
    case 4329 case 4447 case 4450 case 4451 case 4477 case 4472 case 4475 case 4476
    case 4478 case 4479 case 4484 case 4485 case 4486 case 4487 case 4488 case 4492 case 4499
    case 4494 case 4504 case 4505 case 4506 case 4507 case 4508 case 4553 case 4564 case 4565
    case 4578 case 4579 case 4597 case 4598 case 4599 case 4889 case 4891 case 4892 case 4896 
    case 4897 case 4898 case 4899 case 4903 case 4904 case 4905 case 4906 case 4907 case 4908
    case 4924 case 4925 case 4926 case 4927 case 4928 case 4929 case 4930 case 4931 case 4932
    case 4933 case 4934 case 4937 case 4938 case 4939 case 4942 case 4945 case 4947 case 4948
    case 4950 case 4951 case 4952 case 4956
    break
    default
        getwall[I].cstat temp
        ifvarand temp 8 subvar temp 8 else orvar temp 8
        setwall[I].cstat temp
    break
    endswitch
    addvar I 1
}

setvar I 0
whilevarvarn I NUMWALLS
{
    setvarvar A I
    getwall[I].point2 B
    setvarvar K I
    whilevarvarn A B
    {
        addvar K 1
        getwall[K].point2 B
    }
    setvarvar A K
    setvarvar J I
    setvarvar L K
    subvarvar L J
    divvar L 2
    addvar J 1
    whilevarn L 0
    {
        state swapwall
        setarray SWAPWALLS[J] K
        setarray SWAPWALLS[K] J
        addvar J 1
        addvar K -1
        addvar L -1
    }

    setvarvar J I
    whilevarvarn I A
    {
        setvarvar K I
        addvar K 1
        getwall[J].x B
        getwall[J].y C
        getwall[K].x D
        getwall[K].y E
        setwall[J].x D
        setwall[J].y E
        setwall[K].x B
        setwall[K].y C

        addvar I 1
    }

    addvar I 1
}

setvar I 0
whilevarvarn I NUMWALLS
{
    getwall[I].nextwall A
    ifvarn A -1
        ifvarn SWAPWALLS[A] -1
            setwall[I].nextwall SWAPWALLS[A]

    addvar I 1
}

ends

state optiontogglestate
setvarvar lastinput timer
switch menuitem
case 0
setvar menutoggle 2 // weapons sub-menu
setvar menuitem 10
sound INTO_MENU
break
case 1
setvar menutoggle 3 // abilities sub-menu
setvar menuitem 20
sound INTO_MENU
break
case 2
setvar menutoggle 4 // monsters sub-menu
setvar menuitem 30
sound INTO_MENU
break
case 3
setvar menutoggle 5 // effects sub-menu
setvar menuitem 40
sound INTO_MENU
break
case 4
// menu nag toggle
sound SWITCH_ON
ifvare menunag NO setvar menunag YES else setvar menunag NO
savegamevar menunag
break
case 5 // restore DUKE PLUS defaults
sound SWITCH_ON

setvar effects DAMAGE_EFFECTS
setvar useakimbo AKIMBO_PISTOLS
setvar usemossberg ALT_SHOTTY
setvar usemp5 ALT_CHAINGUN
setvar usebigrox ALT_RPG
setvar gravgun GRAVITY_GUN
setvar devshotty YES
setvar dukemon YES
setvar usebots BOTALLIES
setvar doubled NO
setvar scaled NO
setvar mirrored NO
setvar knockdist KNOCKBACK
ifvare playermoves -1
{
	setvar cangrab GRABSTUFF
	setvar candodge DODGING
	setvar canmantle MANTLING
	setvar slowrunaccel REALRUNNING
}
setvar lifebars MONLIFEBARS
setvar infighting 40
setvar killerpigs 30
setvar storehealth STOREHEALTH
setvar maxmedkit FIRSTAID_MAX
setvar steroidkicks STEROIDKICKS
setvar holodukelightning HOLODUKELIGHTNING
setvar goggleswitches GOGGLESWITCHES
setvar randomize RANDOM
setvar rainradius 32768
setvar pdamage 100
setvar mdamage 100
setvar raining 0
setvar quotestyle 0

savegamevar effects
savegamevar useakimbo
savegamevar usemossberg
savegamevar usemp5
savegamevar usebigrox
savegamevar gravgun
savegamevar devshotty
savegamevar dukemon
savegamevar usebots
savegamevar doubled
savegamevar scaled
savegamevar mirrored
savegamevar knockdist
ifvare playermoves -1
{
	savegamevar cangrab
	savegamevar candodge
	savegamevar canmantle
	savegamevar slowrunaccel
}
savegamevar lifebars
savegamevar infighting
savegamevar killerpigs
savegamevar storehealth
savegamevar maxmedkit
savegamevar steroidkicks
savegamevar holodukelightning
savegamevar goggleswitches
savegamevar randomize
savegamevar rainradius
savegamevar raining
savegamevar pdamage
savegamevar mdamage
savegamevar quotestyle
quote 1071

break
case 6

sound SWITCH_ON

setvar effects NO
setvar dpsounds NO
ifvare useakimbo YES state toggleakimbo
ifvare usemossberg YES state toggleshotgun
ifvare usemp5 YES state togglechaingun
ifvare usebigrox YES state togglerpg
ifvare gravgun YES state togglegravgun
ifvarn devshotty 0 { state normaldev setvar devshotty 0 }
ifvare dukemon YES state toggledukemon
setvar usebots NO
setvar doubled NO
setvar scaled NO
setvar mirrored NO
setvar knockdist 0
ifvare playermoves -1
{
	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 maxmedkit 100
setvar steroidkicks NO
setvar holodukelightning NO
setvar goggleswitches NO
setvar randomize NO
setvar rainradius 32768
setvar pdamage 100
setvar mdamage 100
setvar raining 0
setvar quotestyle 1

savegamevar effects
savegamevar dpsounds
savegamevar useakimbo
savegamevar usemossberg
savegamevar usemp5
savegamevar usebigrox
savegamevar gravgun
savegamevar dukemon
savegamevar usebots
savegamevar doubled
savegamevar scaled
savegamevar mirrored
savegamevar knockdist
ifvare playermoves -1
{
	savegamevar cangrab
	savegamevar candodge
	savegamevar canmantle
	savegamevar slowrunaccel
}
savegamevar lifebars
savegamevar infighting
savegamevar killerpigs
savegamevar storehealth
savegamevar maxmedkit
savegamevar steroidkicks
savegamevar holodukelightning
savegamevar goggleswitches
savegamevar randomize
savegamevar rainradius
savegamevar raining
savegamevar pdamage
savegamevar mdamage
savegamevar quotestyle
quote 1072

break

case 7
setvar menutoggle 0 // exit menu
setvar menuitem 0
setplayer[THISACTOR].movement_lock 0
sound EXITMENUSOUND
break
case 19
case 29
case 38
case 50
setvar menutoggle 1 // main menu
setvar menuitem 7
sound EXITMENUSOUND
break

// various game options
case 10 // toggle akimbo
ifvare startweapons -1
state toggleakimbo
else { quote 1060 soundonce LASERTRIP_ARMING }
break

case 11 // toggle shotgun type
//ifvare startweapons -1
state toggleshotgun
//else { quote 1060 soundonce LASERTRIP_ARMING }
break

case 12 // toggle chaingun type
//ifvare startweapons -1
state togglechaingun
//else { quote 1060 soundonce LASERTRIP_ARMING }
break

case 13 // toggle rpg type
//ifvare startweapons -1
state togglerpg
//else { quote 1060 soundonce LASERTRIP_ARMING }
break

case 14 // toggle mind blast
ifvare startweapons -1
{
	ifvare usemindblast YES { setvar usemindblast NO setvar altshrinker NO } else setvar usemindblast YES
	savegamevar usemindblast
	sound SWITCH_ON
}
else { quote 1060 soundonce LASERTRIP_ARMING }
break

case 15 // toggle gravity gun
ifvare startweapons -1
state togglegravgun
else { quote 1060 soundonce LASERTRIP_ARMING }
break

case 16 // toggle shotty devastator
ifvare startweapons -1
{
	sound SWITCH_ON
	ifvarn devshotty 0 
	{ 
		state normaldev
		setvar devshotty 0
	} else setvar devshotty YES
	savegamevar devshotty
}
else { quote 1060 soundonce LASERTRIP_ARMING }
break


case 17 // toggle dukemon
ifvare startweapons -1
state toggledukemon
else { quote 1060 soundonce LASERTRIP_ARMING }
break

case 20 // toggle realistic running
ifvare playermoves -1
{
	sound SWITCH_ON
	ifvare slowrunaccel YES setvar slowrunaccel NO else setvar slowrunaccel YES
	savegamevar slowrunaccel
} else { quote 1060 soundonce LASERTRIP_ARMING }
break

case 21 // toggle mantling
ifvare playermoves -1
{
	sound SWITCH_ON
	ifvare canmantle YES setvar canmantle NO else setvar canmantle YES
	savegamevar canmantle
} else { quote 1060 soundonce LASERTRIP_ARMING }
break

case 22 // toggle dodging
ifvare playermoves -1
{
	sound SWITCH_ON
	ifvare candodge YES setvar candodge NO else setvar candodge YES
	savegamevar candodge
} else { quote 1060 soundonce LASERTRIP_ARMING }
break

case 23 // toggle grabbing
ifvare playermoves -1
{
	sound SWITCH_ON
	ifvare cangrab YES setvar cangrab NO else setvar cangrab YES
	savegamevar cangrab
} else { quote 1060 soundonce LASERTRIP_ARMING }
break

case 24 // toggle health storage
sound SWITCH_ON
ifvare storehealth YES setvar storehealth NO else setvar storehealth YES
savegamevar storehealth
break

// case 25 medkit max is controlled by strafing

case 26 // steroid enhanced kicks
sound SWITCH_ON
ifvare steroidkicks YES setvar steroidkicks NO else setvar steroidkicks YES
savegamevar steroidkicks
break

case 27 // holoduke lightning
sound SWITCH_ON
ifvare holodukelightning YES setvar holodukelightning NO else setvar holodukelightning YES
savegamevar holodukelightning
break

case 28 // goggles reveal dipswitch patterns
sound SWITCH_ON
ifvare goggleswitches YES setvar goggleswitches NO else setvar goggleswitches YES
savegamevar goggleswitches
break

case 30 // monster life bars
sound SWITCH_ON
quote 1059
ifvare lifebars YES setvar lifebars NO else setvar lifebars YES
savegamevar lifebars
break

case 35 // toggle bot assistance
sound SWITCH_ON
ifvare usebots YES setvar usebots NO else setvar usebots YES
quote 1059
savegamevar usebots
break

case 36 // double monsters
sound SWITCH_ON
ifvare doubled YES setvar doubled NO else setvar doubled YES
quote 1059
savegamevar doubled
break

// case 31 monster random attributes controlled by strafing

case 40 // toggle damage effects
sound SWITCH_ON
ifvare effects YES setvar effects NO else setvar effects YES
savegamevar effects
break

case 41 // toggle weather type
ifvare raining 0
{
	soundonce LASERTRIP_ARMING
	quote 1064
} else
{
	sound SWITCH_ON
	mulvar raining -1
	savegamevar raining
}
break

case 46 // toggle map mirroring
sound SWITCH_ON
ifvare mirrored NO
setvar mirrored YES else setvar mirrored NO
quote 1059
savegamevar mirrored
break

case 47 // toggle double sized maps
sound SWITCH_ON
ifvare scaled NO
setvar scaled YES else setvar scaled NO
quote 1059
savegamevar scaled
break

case 48 // toggle Duke Plus sounds
sound SWITCH_ON
ifvare dpsounds NO
{
	setvar dpsounds YES 
	setvar WEAPON1_FIRESOUND DPPISTOLFIRE
	ifvare usemp5 NO
	setvar WEAPON3_FIRESOUND DPCHAINGUNFIRE
}
else 
{
	setvar dpsounds NO
	setvar WEAPON1_FIRESOUND PISTOL_FIRE
	ifvare usemp5 NO
	setvar WEAPON3_FIRESOUND CHAINGUN_FIRE
}
savegamevar dpsounds
break

endswitch
ends

state superkickcode


	ifvare superkicking 1 { getplayer[THISACTOR].posz initz addvar initz 1536 }
	getplayer[THISACTOR].posz z
	ifvarvarl z initz
	setplayer[THISACTOR].posz initz
	
	ifvare spinkick 1 ifvare superkickdone 0
	{
		getplayer[THISACTOR].oang angvar
		addvar angvar 194
		setplayer[THISACTOR].ang angvar
	}
	
	ifvare superkickdone 1 ifvarl superkicking 4 nullop else
	{
		getplayer[THISACTOR].rotscrnang temp
		subvar temp 36
		setplayer[THISACTOR].rotscrnang temp
	}
	ifvare superkickdone 0 
	{
		addvar superkicking 1
		ifvarg superkicking 6 ifvare spinkick 1
		{
			// hit objects
			shoot KNEE
	    } else ifvare superkicking 8 shoot KNEE
		ifvare superkicking 7 ifvare kickimpact 0 sound KICKOUT
	}
	else 
	{ 
		subvar superkicking 1
		ifvare superkicking 0 setvar kickimpact 0
	}
	ifvare superkicking 0 { setvar superkickdone 0 setvar spinkick 0 }
	ifvare spinkick 1 { ifvarg superkicking 11 setvar superkickdone 1 } else
	ifvarg superkicking 9 setvar superkickdone 1

ends

state kludges

ifvare HUBEXITS YES
{
	getplayer[THISACTOR].gm temp
	ifvarand temp 8
	{
		setvar temp 1
		setvar tempb 1
		whilevarvarn tempb LEVEL
		{
			mulvar temp 2
			addvar tempb 1
		}
		orvarvar completed temp
		savegamevar completed
		
		
		startlevel VOLUME 0
		setuserdef[THISACTOR].display_bonus_screen YES
		state resetweaponstate
		setplayer[THISACTOR].gotweapon 1 1
		setplayer[THISACTOR].gotweapon 2 0
		setplayer[THISACTOR].gotweapon 3 0
		setplayer[THISACTOR].gotweapon 4 0
		setplayer[THISACTOR].gotweapon 5 0
		setplayer[THISACTOR].gotweapon 6 0
		setplayer[THISACTOR].gotweapon 7 0
		setplayer[THISACTOR].gotweapon 8 0
		setplayer[THISACTOR].gotweapon 9 0
		setplayer[THISACTOR].gotweapon 11 0
		setplayer[THISACTOR].ammo_amount 1 48
		setplayer[THISACTOR].ammo_amount 2 0
		setplayer[THISACTOR].ammo_amount 3 0
		setplayer[THISACTOR].ammo_amount 4 0
		setplayer[THISACTOR].ammo_amount 5 0
		setplayer[THISACTOR].ammo_amount 6 0
		setplayer[THISACTOR].ammo_amount 7 0
		setplayer[THISACTOR].ammo_amount 8 0
		setplayer[THISACTOR].ammo_amount 9 0
		setplayer[THISACTOR].ammo_amount 11 0
		setplayer[THISACTOR].curr_weapon 0
		setactor[THISACTOR].extra MAXPLAYERHEALTH
		setplayer[THISACTOR].heat_amount 0
		setplayer[THISACTOR].firstaid_amount 0
		setplayer[THISACTOR].steroids_amount 0
		setplayer[THISACTOR].holoduke_amount 0
		setplayer[THISACTOR].jetpack_amount 0
		setplayer[THISACTOR].boot_amount 0
		setplayer[THISACTOR].scuba_amount 0
		
	}
}

iffloordistl 16 ifvare slowrunaccel YES
{
	getplayer[THISACTOR].poszv zvel
	ifvarg zvel 0 { addvar zvel 256 setplayer[THISACTOR].poszv zvel }
}

ifvare scaled YES
{
	getplayer[THISACTOR].falling_counter temp
	ifvarg temp 0 ifrnd 128
	{
		subvar temp 1 
		setplayer[THISACTOR].falling_counter temp
	}
	ifvarand bits 1
	{
		getplayer[THISACTOR].jumping_counter temp
		ifvare canmantle YES { ifvare temp 901 setplayer[THISACTOR].jumping_counter 0 } else
		ifvare temp 1081 setplayer[THISACTOR].jumping_counter 0
	}
	getplayer[THISACTOR].airleft temp
	ifvarl temp 390 ifrnd 128 addvar temp 1
	setplayer[THISACTOR].airleft temp
	getplayer[THISACTOR].scuba_on temp
	ifvare temp 1
	{
		getplayer[THISACTOR].scuba_amount temp
		ifvarl temp 6400 ifrnd 128 addvar temp 1
		setplayer[THISACTOR].scuba_amount temp
	}
	
}

ifvarl totalclock 60 setuserdef[THISACTOR].const_visibility DEFAULTVISIBILITY

ifvarg fta 0 subvar fta 1
ifvarg mantcheck 0 subvar mantcheck 1

ends


define PLAYERTRAIL 3505

state enter_ptrail

setvar temp 0
whilevarn temp 100
{
	setvarvar tempb ptrails[temp]
	ifvare tempb -1 // empty spot
	{
		setarray ptrails[temp] THISACTOR
		setvar temp 99
	}
	addvar temp 1
}

ends

state exit_ptrail

setarray ptrails[0] -1
setvar temp 1
setvar tempb 0
whilevarn temp 100
{
	setvarvar tempc ptrails[temp]
	setarray ptrails[tempb] tempc
	addvar temp 1
	addvar tempb 1
}

ifvarg numallies 0
{
	setvar tempb 0
	setvarvar tempc highally
	addvar tempc 1
	whilevarvarn tempb tempc
	{
		setvarvar spriteid botallies[tempb]
		ifvarn spriteid -1
		{
			getactorvar[spriteid].bouncesound temp
			ifvarn temp -1 subvar temp 1
			setactorvar[spriteid].bouncesound temp
		}
		addvar tempb 1
	}
}

ends


useractor notenemy PLAYERTRAIL 0
ifmove 0
{
	cstat 32768
	move INIT
	sizeat 40 40
	state enter_ptrail
	getactor[THISACTOR].x initx
	getactor[THISACTOR].y inity
	getactor[THISACTOR].z initz
}
else
{
	setactor[THISACTOR].x initx
	setactor[THISACTOR].y inity
	setactor[THISACTOR].z initz
}

ifcount 520 { state exit_ptrail killit }

enda

state playertrailcode


addvar ptrailtimer 1
ifvarg ptrailtimer 6 
{
	espawn PLAYERTRAIL
	getplayer[THISACTOR].posz z
	addvar z 4096
	setactor[RETURN].z z
	setvar ptrailtimer 0 
}


ends

move PGROWINGPOP        // Used only as a variable


actor APLAYER MAXPLAYERHEALTH PSTAND 0 0

ifmultiplayer nullop else ifvare steroidkicks YES
{
	ifp ponsteroids 
		inittimer 80 
	else 
		inittimer 120
}


state checkhitscan
ifvarn botselected -1 state botcommandcode
state kludges

ifvarg numallies 0 state playertrailcode

getplayer[THISACTOR].curr_weapon CURRWEAP
getplayer[THISACTOR].kickback_pic KICKBACKPIC
getplayer[THISACTOR].ammo_amount 3 MP5AMMO

ifvarn menutoggle 0
{
	setplayer[THISACTOR].crack_time 777
	setplayer[THISACTOR].weapon_pos -9
	setplayer[THISACTOR].movement_lock 31
	getplayer[THISACTOR].oang angvar
	setplayer[THISACTOR].ang angvar
	getplayer[THISACTOR].ohoriz temp
	getplayer[THISACTOR].horiz tempb
	setplayer[THISACTOR].horiz temp
	subvarvar tempb temp
	getuserdef[THISACTOR].mouseflip tempc
	ifvare tempc 0 mulvar tempb -1
	ifvarg tempb 1 
	{
		setvarvar temp timer
		subvarvar temp lastchange
		ifvarg temp 2
		{
			orvar extbits 1
			subvar lastinput 1
		}
	} else
	ifvarl tempb -1 
	{ 
		setvarvar temp timer
		subvarvar temp lastchange
		ifvarg temp 2
		{
			orvar extbits 2
			subvar lastinput 1
		}
	}
	
	ifvarand extbits 1 addvar lastinput 1
	ifvarand extbits 2 addvar lastinput 1
	ifvarand extbits 4 addvar lastinput 1
	ifvarand extbits 8 addvar lastinput 1
	ifvarand bits 4 addvar lastinput 1
	ifvarvarg lastinput timer setvarvar lastinput timer
	
	ifvarvarn timer lastinput
	{
		ifvarand extbits 1 // move up
		{
			sound KICK_HIT
			setvarvar lastinput timer
			subvar menuitem 1
			setvarvar lastchange timer
			ifvare menutoggle 1
				ifvarl menuitem 0 setvar menuitem 7 // main menu
			
			ifvare menutoggle 2
				ifvarl menuitem 10 setvar menuitem 19 // weapons
			
			ifvare menutoggle 3
				ifvarl menuitem 20 setvar menuitem 29 // abilities
			
			ifvare menutoggle 4
				ifvarl menuitem 30 setvar menuitem 38 // monsters
			
			ifvare menutoggle 5
				ifvarl menuitem 40 setvar menuitem 50 // effects
			
		} else
		ifvarand extbits 2 // move down
		{
			sound KICK_HIT
			setvarvar lastinput timer
			addvar menuitem 1
			setvarvar lastchange timer
			ifvare menutoggle 1
				ifvarg menuitem 7 setvar menuitem 0
			
			ifvare menutoggle 2
				ifvarg menuitem 19 setvar menuitem 10
			
			ifvare menutoggle 3
				ifvarg menuitem 29 setvar menuitem 20
			
			ifvare menutoggle 4
				ifvarg menuitem 38 setvar menuitem 30
			
			ifvare menutoggle 5
				ifvarg menuitem 50 setvar menuitem 40
			
		}
		
		ifvarand extbits 4 // strafe left, subtract
		{
			sound FOODLAND
			setvarvar lastinput timer
			
			switch menuitem
			case 18 // knockback distance
			ifvarg knockdist 0 subvar knockdist 1
			savegamevar knockdist
			break
			
			case 25 // maxmedkit
			subvar maxmedkit 5
			ifvarl maxmedkit 0 setvar maxmedkit 0
			savegamevar maxmedkit
			break
			
			case 31 // monster random attributes
			ifvarg randomize 0 { quote 1059 subvar randomize 1 }
			savegamevar randomize
			break
			
			case 32 // reduce monster damage
			ifvarg mdamage 10 subvar mdamage 10
			savegamevar mdamage
			break
			
			case 33 // reduce player damage
			ifvarg pdamage 10 subvar pdamage 10
			savegamevar pdamage
			break
			
			case 34 // monster in-fighting
			ifvarg infighting 0 subvar infighting 20
			ifvarl infighting 0 setvar infighting 0
			savegamevar infighting
			break
			
			case 37 // reduce pig db shotgun %
			ifvarg killerpigs 0 subvar killerpigs 10
			savegamevar killerpigs
			break
			
			case 42 // weather color
			subvar rainpal 1
			ifvarl rainpal 0 setvar rainpal 25
			savegamevar rainpal
			break
			
			case 43 // weather transparency
			ifvarand raincstat 512 subvar raincstat 512 else
			ifvarand raincstat 2 subvar raincstat 2 else
			{ orvar raincstat 2 orvar raincstat 512 }
			savegamevar raincstat
			break
			
			case 44 // weather severity
			ifvarl raining 0 addvar raining 1 else
			ifvare raining 0 nullop else
			subvar raining 1
			savegamevar raining
			break
			
			case 45 // rainradius
			subvar rainradius 1024
			ifvarl rainradius 1024 setvar rainradius 1024
			savegamevar rainradius
			break
			
			case 49
			ifvare quotestyle 0 setvar quotestyle 2 else
			ifvare quotestyle 2 setvar quotestyle 1 else
			setvar quotestyle 0
			savegamevar quotestyle
			break
			
			endswitch
			state optiontogglestate
		}
		
		ifvarand extbits 8 // strafe right, add
		{
			sound FOODLAND
			setvarvar lastinput timer
			
			switch menuitem
			case 18 // knockback distance
			ifvarl knockdist 100 addvar knockdist 1
			savegamevar knockdist
			break
			
			case 25 // maxmedkit
			addvar maxmedkit 5
			ifvarg maxmedkit 255 setvar maxmedkit 255
			savegamevar maxmedkit
			break
			
			case 31 // monster random attributes
			ifvarl randomize 20 { quote 1059 addvar randomize 1 }
			savegamevar randomize
			break
			
			case 32 // increase monster damage
			ifvarl mdamage 1000 addvar mdamage 10
			savegamevar mdamage
			break
			
			case 33 // increase player damage
			ifvarl pdamage 1000 addvar pdamage 10
			savegamevar pdamage
			break
			
			case 34 // monster in-fighting
			ifvarl infighting 100 addvar infighting 20
			ifvarg infighting 100 setvar infighting 100
			savegamevar infighting
			break
			
			case 37 // increase pig db shotgun %
			ifvarl killerpigs 100 addvar killerpigs 10
			savegamevar killerpigs
			break
					
			case 42 // weather color
			addvar rainpal 1
			ifvarg rainpal 25 setvar rainpal 0
			savegamevar rainpal
			break
			
			case 43 // weather transparency
			ifvarand raincstat 512 setvar raincstat 0 else
			ifvarand raincstat 2 orvar raincstat 512 else
			orvar raincstat 2
			savegamevar raincstat
			break
			
			case 44 // weather severity
			ifvarl raining 0 subvar raining 1 else
			addvar raining 1
			ifvarg raining 64 setvar raining 64
			savegamevar raining
			break
			
			case 45 // rainradius
			addvar rainradius 1024
			ifvarg rainradius 131072 setvar rainradius 131072
			savegamevar rainradius
			break
			
			case 49
			ifvare quotestyle 0 setvar quotestyle 1 else
			ifvare quotestyle 1 setvar quotestyle 2 else
			setvar quotestyle 0
			savegamevar quotestyle
			break
			
			endswitch
			state optiontogglestate
		}
				
		ifvarand bits 4 
		{
			state optiontogglestate
			
		}
	}
	setactor[THISACTOR].htextra -1
	getplayer[THISACTOR].player_par timer
	setvar mantling 0
	break
}

ifvarn sleeping 0 state sleepingcode


// ifvarg onblock 0
// {
// 	ifaction PRUN ifvare runflag 0 action PSTAND
// 	ifaction PCRAWLING ifvare runflag 0 action PDUCKING
// 	subvar onblock 1
// }

ifvarg superkicking 0 state superkickcode
ifvarl kickenergy KENERGY addvar kickenergy 1
ifvarn FAKERELOAD 0 addvar FAKERELOAD 1

findnearsprite RPG 1536 spriteid
  ifvarn spriteid -1
  {
		getactor[spriteid].owner temp
		ifvarvarn temp THISACTOR
		{
		  state projectilehitscan
		  ifvarvarn hitsprite THISACTOR
			soundonce WHOOSH
		}
  }

ifp palive
{
	ifvare gravgun YES
	{
		ifvare CURRWEAP 11
		{
			ifvarand gravonce 1 nullop else
			{
				getplayer[THISACTOR].fta temp
				ifvarl temp 6
				{
					setplayer[THISACTOR].ftq 1075
					setplayer[THISACTOR].fta 6
				}
			}
			ifvarn gravitysprite -1 
			{
				ifvarand gravonce 2 nullop else ifvarvare holding gravitysprite
				{
					getplayer[THISACTOR].fta temp
					ifvarl temp 6
					{
						setplayer[THISACTOR].ftq 1082
						setplayer[THISACTOR].fta 6
					}
				}
				orvar gravonce 1
				setplayer[THISACTOR].kickback_pic 18
				ifvare holdingpic SAWBLADEGROUND ifvarand bits 4
				{
					setplayer[THISACTOR].kickback_pic 1
					setvar WEAPON11_SHOOTS SAWBLADEPROJ
					setactorvar[holding].mtype 1
					setactor[holding].cstat 32768
					setvar holding -1
				}
			}
			ifvarand bits 262144 { soundonce GRAVPULL setplayer[THISACTOR].kickback_pic 18 }
			else ifvare holding -1 { setvar gravitysprite -1 stopsound GRAVPULL }
		}
		else { setvar gravitysprite -1 stopsound GRAVPULL }
	}
	ifvare CURRWEAP 7 ifvare devshotty 2 ifvare KICKBACKPIC 3
	{
		getplayer[THISACTOR].ammo_amount 7 temp
		ifvarg temp 1 subvar temp 1
		setplayer[THISACTOR].ammo_amount 7 temp
	}
	ifvare CURRWEAP 5 setvarvar PIPEBOMB_CONTROL pipecontrol
	ifvare CURRWEAP 4 ifvare usebigrox YES
	{
		ifvare KICKBACKPIC 20 setplayer[THISACTOR].weapon_pos -1
		ifvarg KICKBACKPIC 29 ifvarl KICKBACKPIC 65 setplayer[THISACTOR].weapon_pos -9
		ifvare KICKBACKPIC 52 sound RPGLOAD
		ifvare KICKBACKPIC 38 sound RPGLOAD
		
	}
	ifvare CURRWEAP 3 
	{
		getplayer[THISACTOR].ammo_amount 3 tempb
		ifvare tempb 0 ifvarand bits 4 
		{
			ifvarvarl lastinput timer soundonce WEAPEMPTY
			setvarvar lastinput timer addvar lastinput 1
		}
		ifvare usemp5 YES
		{
			ifvarg FAKERELOAD 65 setvar FAKERELOAD 0
			// ifvare KICKBACKPIC 20 setvar wacked -1
			
			ifvarn FAKERELOAD 0
			{
				ifvare FAKERELOAD 16 sound MP5CLIPOUT
				ifvare FAKERELOAD 48
				{
					setvar tempc 30
					subvarvar tempc MP5INCLIP // tempc is now how much room is in the clip
					setvarvar tempb MP5AMMO
					subvarvar tempb MP5INCLIP // tempb is the amount you have in excess of the amount in clip
					ifvarvarl tempb tempc // if you have less ammo than what the clip can hold
						addvarvar MP5INCLIP tempb
					else
						setvar MP5INCLIP 30
					sound MP5CLIPIN
				}
			}
			else
			{
				ifvare MP5INCLIP 0
				{
					ifvare KICKBACKPIC 0
					ifvarg MP5AMMO 0
					{
						setvar FAKERELOAD 1
					}
				}
				else
				ifvarl MP5INCLIP 15 ifvare reloadonce 0 ifvare KICKBACKPIC 0
				{
					ifvarg MP5AMMO 0
					{
						getplayer[THISACTOR].fta temp
						ifvarl temp 6
						{
							setplayer[THISACTOR].ftq 1074
							setplayer[THISACTOR].fta 6
						}
					}
				}
			}
			
		} 
	}
	else
	ifvare CURRWEAP 2
	{
		ifvare usemossberg YES
		{
			getplayer[THISACTOR].weaponswitch temp
			andvar temp 0xFFFD // clear bit2
			setplayer[THISACTOR].weaponswitch temp // to prevent auto switching away
		}

		ifvarand ALTSHOTGUN 8 // switching shotguns
		{
			getplayer[THISACTOR].weapon_pos temp
			ifvare temp -9 { state changeshotgun subvar ALTSHOTGUN 8 }
		}
		ifvarand ALTSHOTGUN 4 // double barreled shotgun
		{
			//ifvarn WEAPON2_SHOOTS NOTHING
			//{
				ifvare KICKBACKPIC 5 // firing time
				{
					getplayer[THISACTOR].ammo_amount 2 temp
					ifvarg temp 0 subvar temp 1
					setplayer[THISACTOR].ammo_amount 2 temp
				}
				ifvare KICKBACKPIC 18 sound DBOPEN else
				ifvare KICKBACKPIC 34
				{
					//spawn NEWSMOKE
					espawn SHOTGUNSHELL
					getactor[RETURN].z z
					addvar z 2048
					setactor[RETURN].z z
					getplayer[THISACTOR].ang angvar
					addvar angvar 1024
					setactor[RETURN].ang angvar
					espawn SHOTGUNSHELL
					setactor[RETURN].z z
					setactor[RETURN].ang angvar
				} else
				ifvare KICKBACKPIC 42 sound DBLOAD else
				ifvare KICKBACKPIC 54 
					sound DBCLOSE
				
				ifvarg KICKBACKPIC 15
				{
					ifvare KICKBACKPIC 16
					{
						getplayer[THISACTOR].ammo_amount 2 temp
						ifvarg temp 0
						setvar dbpicnum 8826 else
						{
							setplayer[THISACTOR].kickback_pic 0
							setvar KICKBACKPIC 0
						}
					}
					
					else ifvarl KICKBACKPIC 61
						setvar dbpicnum 8828	
					else
					setvar dbpicnum 8826
				}

			//}
			//ifvare KICKBACKPIC 20 setvar wacked -1
		} else ifvare usemossberg YES 
		{
			ifvare FAKERELOAD 0
			{
				ifvare KICKBACKPIC 13 sound MOSSPUMP
				ifvare KICKBACKPIC 0 ifvare SHOTGUNCLIP 0
				{
					getplayer[THISACTOR].ammo_amount 2 tempb
					ifvarg tempb 0
						setvar FAKERELOAD 1
				} else
				ifvarl SHOTGUNCLIP 4 ifvare reloadonce 0 ifvare KICKBACKPIC 0
				{
					getplayer[THISACTOR].ammo_amount 2 tempb
					ifvarg tempb 0
					{
						getplayer[THISACTOR].fta temp
						ifvarl temp 6
						{
							setplayer[THISACTOR].ftq 1074
							setplayer[THISACTOR].fta 6
						}
					}
				}
			}
			else
			{
				ifvare reloadpicnum 8844 ifvare FAKERELOAD 25 sound MOSSINSERTSHELL // 27
				ifvare reloadpicnum 8847 ifvare FAKERELOAD 30 // 34
					sound MOSSPUMP
			}
		}
		
	}
	else ifvare usemossberg NO setvar FAKERELOAD 0
	
	ifvare FAKERELOAD 0
		setvar reloadpicnum -1

	
	ifvare CURRWEAP 2 ifvarn FAKERELOAD 0
	{
		ifvarand bits 4 ifvarn SHOTGUNCLIP 0 setvar STOPRELOAD 1
		ifvarl FAKERELOAD 20
		  setvar reloadpicnum 8843
		else
		{
			ifvare reloadpicnum 8843 { setvarvar shellstarted timer setvar reloadpicnum 8844 }
			else
			{
				ifvarl reloadpicnum 8846 // in the shell loading loop
				{
					ifvare reloadpicnum 8844 // the shell loading animation
					{
						setvarvar temp timer
						subvarvar temp shellstarted
						ifvarg temp 12 // 16 another shell has been loaded
						{
							// stop when full, or when all the shells you have are loaded, whichever comes first...
							addvar SHOTGUNCLIP 1
							getplayer[THISACTOR].ammo_amount 2 temp
							setvar tempb 0
							ifvarl temp 1 setvar tempb 1
							ifvarvare SHOTGUNCLIP temp setvar tempb 1
							ifvarg SHOTGUNCLIP 7 setvar tempb 1
							ifvare STOPRELOAD 1 setvar tempb 1 // also stop if the player wants to fire
							ifvare tempb 1
							{
								setvar reloadpicnum 8846
								setvar FAKERELOAD 21
							}
							else
							{
								setvar reloadpicnum 8845 // this will reset the loading loop
								setvar FAKERELOAD 21
							}
					    }
				    } else
				    // time to start another shell
				    {
					    setvarvar shellstarted timer setvar reloadpicnum 8844
				    }
			    }
			    else 
			    {
				    ifvarl FAKERELOAD 28 setvar reloadpicnum 8846
				    else setvar reloadpicnum 8847
				}
		    }
		}
		ifvarg FAKERELOAD 37 setvar FAKERELOAD 0
	}
	else setvar STOPRELOAD 0
	
	ifvare CURRWEAP 1
	{
		
		ifvarn PISTOLRELOAD 0
		{
			getplayer[THISACTOR].ammo_amount 1 tempb
			subvarvar tempb botclip // tempb is the amount of ammo you have in excess of what is in clip
			setvarvar PISTOLRELOAD KICKBACKPIC
			ifvare akimbo -1 setvar temp 26 
			else ifvare akimbo 0 setvar temp 26 
			else setvar temp 47
			ifvarvare PISTOLRELOAD temp
			{
				ifvare akimbo -1 setvar tempc 12 else
				ifvare akimbo 0 setvar tempc 12 
				else setvar tempc 24 // CLIP SIZE
				subvarvar tempc botclip // tempc is now how much room is in the clip
				ifvarvarl tempb tempc // if you have less ammo than what the clip can hold
					addvarvar botclip tempb
				else
				{
					ifvare akimbo -1 setvar botclip 12 
					else ifvare akimbo 0 setvar botclip 12 
					else setvar botclip 24
				}
				
			}
		}
		else
		{
			getplayer[THISACTOR].ammo_amount 1 tempb
			ifvare tempb 0 ifvarand bits 4 
			{
				ifvarvarl lastinput timer soundonce WEAPEMPTY
				setvarvar lastinput timer addvar lastinput 1
			}
			getplayer[THISACTOR].last_weapon temp
			ifvarn temp 0
			ifvare botclip 0 ifvarg akimbo -2 ifvarl akimbo 2 ifvarg tempb 0
			{
				ifvare akimbo -1 setvar WEAPON1_RELOAD 27 else
				ifvare akimbo 0 setvar WEAPON1_RELOAD 27 
				else setvar WEAPON1_RELOAD 48
				setplayer[THISACTOR].reloading 1
				setplayer[THISACTOR].kickback_pic 9
				sound EJECT_CLIP
				setvar PISTOLRELOAD 1
			}
			else
			setvar WEAPON1_RELOAD 0
			setvar temp 0
			ifvarl akimbo 1 { ifvarl botclip 6 setvar temp 1 }
			else ifvarl botclip 12 setvar temp 1
			ifvare temp 1 ifvarg tempb 1 ifvare reloadonce 0 ifvare KICKBACKPIC 0
			{
				getplayer[THISACTOR].fta temp
				ifvarl temp 6
				{
					setplayer[THISACTOR].ftq 1074
					setplayer[THISACTOR].fta 6
				}
				
			}
			
		}
			
	}
				
}

ifvarg monallies 0 subvar monallies 1
ifvarg numallies 0
{
	getsector[THISACTOR].hitag temp
	ifvare temp 666 // kill the bots
	{
		setvar tempb 0
		setvarvar tempc highally
		addvar tempc 1
		whilevarvarn tempb tempc
		{
			setvarvar spriteid botallies[tempb]
			setactorvar[spriteid].command 666
			addvar tempb 1
		}
	}
}
ifvarg lightidle 0 subvar lightidle 1
ifvarg backview 0 subvar backview 1
ifhitspace setvar lightidle 40
ifvarg underwater 0 state underwatercode else { setvar oxygen 390 setvar headunder 0 }

state holdingcode
ifvarg drinksoda 0
{
	addvar drinksoda 1
	ifvarg drinksoda 78 
	{
		addphealth 5
		setvar drinksoda 0
		setactor[holding].pitch 0
		setactor[holding].roll 0
		setactor[holding].picnum COLACANSTAND
		setvar holding -1
	}
}

// friendly fire damage reduction
getactor[THISACTOR].htextra temp
ifvarg temp 0
{
	ifvarn mdamage 100
	{
		getactor[THISACTOR].htpicnum picnum
		ifvarn picnum RADIUSEXPLOSION
		{
			mulvarvar temp mdamage
			divvarvar temp 100
			setactor[THISACTOR].htextra temp
		}
	}
	
	getactor[THISACTOR].htowner spriteid
	ifvarn spriteid -1
	{
		getactor[spriteid].picnum picnum
		{
			ifvarn picnum BOTALLY ifvarn picnum BOTALLYCROUCH
			{
				nullop
			}
			else
			{
				divvar temp 2
				ifvarg temp 40 setvar temp 40
				setactor[THISACTOR].htextra temp
			}
		}
	}
}

setvar monstatus 1

ifvare useakimbo YES
{
	ifvarg weapswitch 0 subvar weapswitch 1
	ifvarg akimbo 1 subvar akimbo 1
	ifvarl akimbo -1
	{
		addvar akimbo 1
		ifvare akimbo -1 setvar akimbo 0
	}
	
	ifvare CURRWEAP 1 ifvarg akimbo 0 
	{
		getplayer[THISACTOR].kickback_pic temp
		ifvare temp 6 //5
		{
			ifvare dpsounds YES sound DPPISTOLFIRE else
			sound PISTOL_FIRE
			shoot SHOTSPARK1
			getplayer[THISACTOR].ammo_amount 1 temp
			ifvarg temp 0 subvar temp 1
			setplayer[THISACTOR].ammo_amount 1 temp
			espawn SHELL
			setactor[RETURN].pal 30
		}
	}
}

ifvarg chaingunheat 0 subvar chaingunheat 1
setvar temp OVERHEAT
ifvare temp YES ifvarg chaingunheat 1000
{
	ifvare CURRWEAP 3
	{
		setplayer[THISACTOR].kickback_pic 0
		soundonce STEAM_HISSING
	}
}
ifvarg fpress 0 subvar fpress 1
ifvarg bpress 0 subvar bpress 1
ifvarl onladder 0 addvar onladder 1

ifvarg onladder 0 state laddercode

ifp ponground setvar nofalldamage 0
ifvarn nofalldamage 0 setplayer[THISACTOR].falling_counter 0

ifvarg bhold 7 { setvar btap 0 setvar bhold 0 }
ifvarg fhold 7 { setvar ftap 0 setvar fhold 0 }
ifvarg lhold 7 { setvar ltap 0 setvar lhold 0 }
ifvarg rhold 7 { setvar rtap 0 setvar rhold 0 }

ifvarvarn timer fpresstime setvar fhold 0
ifvarvarn timer bpresstime setvar bhold 0


getplayer[THISACTOR].player_par timer
ifvare timer 1
{
	setvar lastchange 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 canmantle NO
		setvar usemossberg YES
		setvar usemp5 YES
		setvar menunag NO
	} else
	{
		readgamevar played
		ifvare played NO
		{
			setvar played YES
			savegamevar played
			savegamevar menunag
			savegamevar effects
			savegamevar dpsounds
			savegamevar useakimbo
			savegamevar usemossberg
			savegamevar usemp5
			savegamevar usebigrox
			savegamevar usemindblast
			savegamevar devshotty
			savegamevar dukemon
			savegamevar gravgun
			savegamevar usebots
			savegamevar knockdist
			savegamevar cangrab
			savegamevar candodge
			savegamevar canmantle
			savegamevar slowrunaccel
			savegamevar lifebars
			savegamevar infighting
			savegamevar killerpigs
			savegamevar storehealth
			savegamevar maxmedkit
			savegamevar steroidkicks
			savegamevar holodukelightning
			savegamevar goggleswitches
			savegamevar randomize
			savegamevar rainradius
			savegamevar pdamage
			savegamevar mdamage
			savegamevar mirrored
			savegamevar scaled
			savegamevar doubled
			savegamevar quotestyle
		}	
		else
		{
			readgamevar menunag
			readgamevar effects
			readgamevar dpsounds
			readgamevar useakimbo
			readgamevar usemossberg
			readgamevar usemp5
			readgamevar usebigrox
			readgamevar usemindblast
			readgamevar devshotty
			readgamevar dukemon
			readgamevar gravgun
			readgamevar usebots
			readgamevar knockdist
			readgamevar cangrab
			readgamevar lifebars
			readgamevar infighting
			ifvare infighting 1 { setvar infighting 40 savegamevar infighting }
			readgamevar killerpigs
			readgamevar slowrunaccel
			readgamevar candodge
			readgamevar canmantle
			readgamevar storehealth
			readgamevar maxmedkit
			readgamevar steroidkicks
			readgamevar holodukelightning
			readgamevar goggleswitches
			readgamevar randomize
			readgamevar pdamage
			readgamevar mdamage
			readgamevar mirrored
			readgamevar scaled
			readgamevar doubled
			readgamevar quotestyle
			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
	}
	// dynamic lighting initialization
	//ifvare ONCE 0 // ifvare lighting YES
	//{
		setvar ONCE 1
		setvar flares 0
// 		ifvare darkworld 1
// 		{
// 			setvar lighting 1
// 			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
// 			}
// 		}
		state clear_light_array
		state fill_light_array
		ifvare lighting YES
		{
			state fill_wall_arrays
			ifvare lightinmap 0
			{
				setvarvar temp NUMSECTORS
				subvar temp 1
				whilevarn temp -1
				{
					state spawn_controller
					subvar temp 1
				}
			}
			setvar lightinmap 0
	
			// make wall aligned sprites get the ID of their wall, so they can check their wall later on
			setvar spriteid 0
			whilevarn spriteid 16384
			{
				getactor[spriteid].statnum temp
				ifvarn temp 1024
				{
					getactor[spriteid].cstat tempb
					ifvarand tempb 16
					{
						getactor[spriteid].pal pal
						ifvarl pal 70
						state wallhitscan
					} else
					ifvarand tempb 32
					{
						getactor[spriteid].pal pal
						ifvarl pal 70
						{
							setactorvar[spriteid].mywall 32768 // dummy value
							getactor[spriteid].sectnum hitsector
							ifvarn hitsector -1 ifvarl hitsector 4096
							{
								getsector[hitsector].floorshade shade
								setactorvar[spriteid].ammo shade
								getactor[spriteid].shade shade
								setactorvar[spriteid].initshade shade
							}
							// else addlogvar hitsector
						}
					}
				}
				addvar spriteid 1
			}
			setvar pal 0
		}	
			
	//}
	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 1024 // 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 devshotty YES
			else setvar devshotty NO
			ifvarand startweapons 64
			    setvar gravgun YES
			else setvar gravgun NO
			ifvarand startweapons 128
			    setvar dukemon YES
			else setvar dukemon NO
			orvar startweapons 1024
		}
	}
	ifvare dpsounds YES
	{
		setvar WEAPON1_FIRESOUND DPPISTOLFIRE
		ifvare usemp5 NO
		setvar WEAPON3_FIRESOUND DPCHAINGUNFIRE
	}
	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	
			}
	}
	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 78 //104
		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
	}
	state normaldev

	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
	}
	
// 	ifvarn randomize 0 ifvare raining 0
// 	{
// 		randvar raining 24
// 		ifrnd 128 mulvar raining -1
// 		ifrnd 128 setvar rainpal 0 else setvar rainpal 13
// 		setvar rainradius 12288
// 		setvar snowceiling 65536
// 		setvar raincstat 0
// 		ifrnd 128 orvar raincstat 2
// 		ifrnd 128 orvar raincstat 512
// 	}

} else setvar colamachines 0

setvarvar tempb timer
subvarvar tempb fpresstime
ifvarg tempb 4 setvar ftap 0

setvarvar tempb timer
subvarvar tempb bpresstime
ifvarg tempb 4 setvar btap 0

setvarvar tempb timer
subvarvar tempb lpresstime
ifvarg tempb 4 setvar ltap 0

setvarvar tempb timer
subvarvar tempb rpresstime
ifvarg tempb 4 setvar rtap 0

ifvare candodge YES 
{
	ifinwater nullop else
	ifvare underwater 0 state dodgecode
}
else
ifvarn dodge 0 state dodgecode
ifvarg dodge 0 
{
	subvar dodge 1 // safest to put it here
	ifvare dodge 0 
    {
// 	       ifvarn jumpadxvel 0 setvar dodgeagain 6 else
// 	       setvar dodgeagain 26
// 	       setvar walljump 0
// 	       setvar jumpadxvel 0
	       
	       setvar temp FREERUNNER
	       ifvarn jumpadxvel 0 setvar dodgeagain 6 else
	       setvar dodgeagain 26
	       ifp ponground setvar walljump 0 else
	       ifvare temp YES ifvarn walljump 0 setvar dodgeagain 0
	       setvar jumpadxvel 0
	}
}
ifp ponground setvar walljump 0

ifp pdead nullop 
 else 
  state stepsoundstuff
  

ifvare slowrunaccel YES ifvare underwater 0 state runningcode
ifvare canmantle YES state mantlingcode
else ifvarg underwater 0 state mantlingcode else
ifvarn mantling 0 state mantlingcode


state slipperycode
getplayer[THISACTOR].posxv oposxv
getplayer[THISACTOR].posyv oposyv

ifvarn raining 0 state raincode


  ifaction 0
    action PSTAND
  

  ifaction PFROZEN
  {
    cstat 257

    fall

    palfrom 16 0 0 24

    ifmove 0
    {
      ifhitweapon
      {
        ifwasweapon FREEZEBLAST
          break
        lotsofglass 60
        ifrnd 84
          spawn BLOODPOOL

        sound GLASS_BREAKING
        spawn ATOMICHEALTH

        getlastpal

        move 1
        break
      }
    }
    else
    {
      cstat 32768
      quote 13
      ifhitspace
      {
        action PSTAND
        resetplayer
      }
      break
    }

    ifactioncount THAWTIME
    {
      getlastpal
      strength 1
      move 0
      action PSTAND
    }
    else
      ifactioncount FROZENDRIPTIME
    {
      ifrnd 32
      spawn WATERDRIP
    }

    ifp pfacing   // assumes another other player  (multiplayer)
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick

    break
  }

  ifdead
  {
    ifaction PGROWING
    {
      ifmove PGROWINGPOP
      {
        quote 13
        ifhitspace
        {
          action 0
          resetplayer
        }
        break
      }
      else
      {
        ifcount 32
        {
          sound SQUISHED
          palfrom 48 64

          state standard_pjibs

          guts JIBS4 20
          guts JIBS6 20
          move PGROWINGPOP
          cstat 32768
          tossweapon

          hitradius 2048 60 70 80 90

        }
        else
          sizeto MAXXSTRETCH MAXYSTRETCH
      }
      break
    }

    ifsquished
      palfrom 32 63 63 63
    else
      fall

    ifactioncount 7
      move 0
    else
      ifactioncount 6
    {
      ifmultiplayer nullop
      else
      {
        ifrnd 32
          sound DUKE_KILLED5
        else
          ifrnd 32
            sound DUKE_KILLED3
        else
          ifrnd 32
            sound DUKE_KILLED1
        else
          ifrnd 32
            sound DUKE_KILLED2
      }
    }

    ifaction PLYINGDEAD
    {
      ifactioncount 3
        move PSTOPED
      quote 13
      ifhitspace
      {
        action PSTAND
        spawn DUKELYINGDEAD
        resetplayer
      }
      break
    }

    ifaction PTHROWNBACK
    {
      ifactioncount 5
      {
        spawn BLOODPOOL
        action PLYINGDEAD
      }
      else
        ifactioncount 1
          move 0
      break
    }

    ifaction PEXPLODEAD
    {
      quote 13
      ifhitspace
      {
        resetplayer
        action PSTAND
      }
      break
    }
    ifaction PEXPLODE
    {
      ifactioncount 5
      {
        action PEXPLODEAD
        spawn BLOODPOOL
      }
      break
    }

    ifp pshrunk
    {
      state standard_pjibs
      spawn BLOODPOOL

      sound SQUISHED
      sound DUKE_DEAD

      cstat 32768         // Hide the sprite

      action PLYINGDEAD
    }
    else
    {
	  setvar temp 0
	  ifinwater setvar temp 1
	  ifvarg underwater 0 setvar temp 1
	  ifvare temp 1
      {
        action PLYINGDEAD
        spawn WATERBUBBLE
        spawn WATERBUBBLE
      }
      else
      {
        action PEXPLODE
        state standard_pjibs
        cstat 32768
        sound SQUISHED
        sound DUKE_DEAD
      }
    }

    tossweapon

    break
  }

  ifsquished
  {
    strength -1
    sound SQUISHED
    state random_ooz
    break
  }

  ifp ponsteroids
  {
    ifp pstanding nullop
    else
      spawn FRAMEEFFECT1
  }

  ifmove PSHRINKING
  {
    ifcount 32
    {
      ifcount SHRUNKDONECOUNT
      {
        move 0
        cstat 257
      }
      else
        ifcount SHRUNKCOUNT
      {
        sizeto 42 36
        ifgapzl 24
        {
          strength 0
          sound SQUISHED
          palfrom 48 64
          break
        }
      }
      else
        ifp ponsteroids
          count SHRUNKCOUNT
    }
    else
    {
      ifp ponsteroids
        count SHRUNKCOUNT
      else
      {
        sizeto 8 9
        spawn FRAMEEFFECT1
      }
    }
  }
  else ifhitweapon
  {
    ifdead
    {
      ifmultiplayer
        sound DUKE_KILLED4

      ifwasweapon GROWSPARK
      {
        palfrom 48 48
        action PGROWING
        count 0
        move 0
        sound ACTOR_GROWING
        cstat 0
        break
      }
    }
    else
    {
	  setplayer[THISACTOR].sound_pitch 0
      ifmultiplayer
      {
        ifphealthl YELLHURTSOUNDSTRENGTHMP
        {
          ifrnd 64
            sound DUKE_LONGTERM_PAIN2
          else
            ifrnd 64
              sound DUKE_LONGTERM_PAIN3
          else
            ifrnd 64
              sound DUKE_LONGTERM_PAIN4
          else
            sound DUKE_DEAD
        }
        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
        }
      }
      else
      {
        ifphealthl YELLHURTSOUNDSTRENGTH
        {
          ifrnd 74
            sound DUKE_LONGTERM_PAIN2
          else
            ifrnd 8
              sound DUKE_LONGTERM_PAIN3
          else
            sound DUKE_LONGTERM_PAIN4
        }
        ifrnd 128
          sound DUKE_LONGTERM_PAIN
      }
    }
    ifstrength TOUGH
    {
      state headhitstate
      sound DUKE_GRUNT
      ifp pstanding
        action PFLINTCHING
    }

    ifwasweapon RPG
    {
      ifrnd 32
        spawn BLOOD
      ifdead
        state standard_pjibs
      palfrom 48 52
      break
    }
    ifwasweapon RADIUSEXPLOSION
    {
      ifrnd 32
        spawn BLOOD
      ifdead
        state standard_pjibs
      palfrom 48 52
      break
    }
    ifwasweapon FIREEXT
    {
      ifrnd 32
        spawn BLOOD
      ifdead
        state standard_pjibs
      palfrom 48 52
      break
    }
    ifwasweapon GROWSPARK
    {
      palfrom 48 52
      sound EXPANDERHIT
      break
    }
    ifwasweapon SHRINKSPARK
    {
      palfrom 48 0 48
      move PSHRINKING // used as a var only.
      sound ACTOR_SHRINKING
      cstat 0
      break
    }
    ifwasweapon SHOTSPARK1
      palfrom 24 48
    ifwasweapon STARPROJ
      palfrom 28 48
    ifwasweapon SHRAPNEL
      palfrom 20 48
    ifwasweapon FIREBALLPROJ
      palfrom 32 48
    ifwasweapon FIREBULLET
      palfrom 28 48
    ifwasweapon ELECTROPROJ
      palfrom 40 63 63 63
    ifwasweapon RAILSLUG_WEAK
      palfrom 32 48
    ifwasweapon FREEZEBLAST
    {
      palfrom 48 0 0 48
      ifdead
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action PFROZEN
        break
      }
    }
    ifwasweapon COOLEXPLOSION1
      palfrom 48 48 0 48
    ifwasweapon KNEE
      palfrom 16 32
    ifwasweapon FIRELASER
      palfrom 32 32

    ifdead
    {
      action PTHROWNBACK
      tossweapon
    }

    state random_wall_jibs

    break
  }
  
  ifaction PSKICKING // superkicking action
  {
	ifactioncount 2 
		action PSTAND 
	break 
  }
  else
  ifvarn superkicking 0 ifvare superkickdone 0 ifp palive
  {
	ifaction PDUCKING nullop else ifaction PCRAWLING nullop else ifaction PFROZEN nullop else
    action PSKICKING
    break
  }

  ifaction PFLINTCHING
  {
    ifactioncount 2
      action PSTAND
    break
  }

  setvar temp 0
  getplayer[THISACTOR].posz z
  ifinwater setvar temp 1
  ifvarg underwater 0 ifvarvarg z peractor2 setvar temp 1
  ifvare temp 1
  {
    ifaction PTREDWATER
    {
      ifp pwalking prunning
        action PSWIMMINGGO
    }
    else
      ifp pstanding pwalkingback prunningback
        action PTREDWATER
    else
    {
      ifaction PSWIMMING
      {
        ifrnd 4
          spawn WATERBUBBLE
        ifactioncount 4
          action PSWIMMINGWAIT
      }
      else
        ifaction PSWIMMINGWAIT
      {
        ifactioncount 2
          action PSWIMMINGGO
      }
      else
        ifaction PSWIMMINGGO
      {
        ifactioncount 2
          action PSWIMMING
      }
      else
        action PTREDWATER
    }

    ifrnd 4
      spawn WATERBUBBLE // For effect

    break
  }
  else ifp pjetpack
  {
    ifaction PJPHOUVER
    {
      ifactioncount 4
        resetactioncount
    }
    else
      action PJPHOUVER
    break
  }
  else
  {
    ifaction PTREDWATER
      action PSTAND
    ifaction PSWIMMING
      action PSTAND
    ifaction PSWIMMINGWAIT
      action PSTAND
    ifaction PSWIMMINGGO
      action PSTAND
    ifaction PJPHOUVER
      action PFALLING
  }

    ifaction PFALLING
  {
    state STOPSTEPSOUNDS
    ifp ponground
      { 
	      action PSTAND 
	      state landsounds
	  }
    else
    {
      ifp pfalling
        break
      else
        state check_pstandard
    }
  }

  ifaction PDUCKING
  {
    state STOPSTEPSOUNDS
    ifgapzl 48
    {
      ifp pwalking pwalkingback prunning prunningback
        action PCRAWLING
    }
    else ifp pducking
    {
      ifp pwalking pwalkingback prunning prunningback
        action PCRAWLING
    }
    else
    {
      ifp pstanding
        action PSTAND
      else
        state check_pstandard
    }
  }

  else ifaction PCRAWLING
  {
    state STOPSTEPSOUNDS
    ifgapzl 48
    {
      ifp pstanding
        action PCRAWLING
    }
    else
      ifp pducking
    {
      ifp pstanding
        action PDUCKING
    }
    else
    {
      ifp pstanding
        action PSTAND
      else
        state check_pstandard
    }
  }
  else
    ifgapzl 48
      action PDUCKING

  else
    ifaction PJUMPING
  {
    state STOPSTEPSOUNDS
    ifp ponground
      action PSTAND
    else
      ifactioncount 4
        ifp pfalling
          action PFALLING
  }


  ifp pfalling
    action PFALLING
  else
    ifaction PSTAND
      state check_pstandard
  else
    ifaction PAKICKING
  {
    ifactioncount 2
      action PSTAND
    break
  }
  else
    ifaction PWALK
  {
    ifp pfalling
      action PFALLING
    else
      ifp pstanding
        action PSTAND
    else
      ifp prunning
        action PRUN
    else
      ifp pwalkingback
        action PWALKBACK
    else
      ifp prunningback
        action PRUNBACK
    else
      ifp pjumping
        action PJUMPING
    else
      ifp pducking
        action PDUCKING
  }

  else
    ifaction PRUN
  {
    ifp pstanding
      action PSTAND
    else
      ifp pwalking
        action PWALK
    else
      ifp pwalkingback
        action PWALKBACK
    else
      ifp prunningback
        action PRUNBACK
    else
      ifp pjumping
        action PJUMPING
    else
      ifp pducking
        action PDUCKING
  }

  else
    ifaction PWALKBACK
  {
    ifp pstanding
      action PSTAND
    else
      ifp pwalking
        action PWALK
    else
      ifp prunning
        action PRUN
    else
      ifp prunningback
        action PRUNBACK
    else
      ifp pjumping
        action PJUMPING
    else
      ifp pducking
        action PDUCKING
  }

  else
    ifaction PRUNBACK
  {
    ifp pstanding
      action PSTAND
    else
      ifp pwalking
        action PWALK
    else
      ifp prunning
        action PRUN
    else
      ifp pwalkingback
        action PWALKBACK
    else
      ifp pjumping
        action PJUMPING
    else
      ifp pducking
        action PDUCKING
  }
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 rf
  ifrnd 128
    cstat 4
  else
    cstat 0
ends


//
//
//    TROOP/LIZTROOP CODE
//
//

action ATROOPSTAND     0  1  5  1  1
action ATROOPGROW    0  1  5  1  1
action ATROOPSTAYSTAND  -2  1  5  1  1
action ATROOPWALKING   0  4  5  1   12
action ATROOPWALKINGBACK 15   4  5   -1   12
action ATROOPRUNNING   0  4  5  1  8
action ATROOPSHOOT    35  1  5  1   30
action ATROOPJETPACK  40  1  5  1  1
action ATROOPJETPACKILL 40  2  5  1   50
action ATROOPFLINTCH  50  1  1  1  6
action ATROOPDYING    50  5  1  1   16
action ATROOPDEAD     54
action ATROOPPLAYDEAD   54
action ATROOPSUFFERDEAD 58  2  1   -4   24
action ATROOPSUFFERING  59  2  1  1   21
//action ATROOPDUCK     64  1  5  1  3
//action ATROOPDUCKSHOOT  64  2  5  1   25
action ATROOPDUCK     0  1  5  1  3
action ATROOPDUCKSHOOT  0  2  5  1   25
action ATROOPABOUTHIDE  74  1  1  1   25
action ATROOPABOUTBLOW  74  1  1  1   25
action ATROOPHIDE     79  1  1  1   25
action ATROOPREAPPEAR   74  1  1  1   25
action ATROOPFROZEN    0  1  5

move TROOPWALKVELS 72
move TROOPWALKVELSBACK -72
move TROOPJETPACKVELS 64 -84
move TROOPJETPACKILLVELS 192 -38
move TROOPRUNVELS 108
move TROOPSTOPPED
move DONTGETUP
move SHRUNKVELS 32

ai AITROOPSEEKENEMY  ATROOPWALKING   TROOPWALKVELS seekplayer
ai AITROOPSEEKPLAYER ATROOPWALKING   TROOPWALKVELS seekplayer
ai AITROOPFLEEING  ATROOPWALKING   TROOPWALKVELS fleeenemy
ai AITROOPFLEEINGBACK ATROOPWALKINGBACK   TROOPWALKVELSBACK faceplayer
ai AITROOPDODGE    ATROOPWALKING   TROOPRUNVELS  dodgebullet
ai AITROOPSHOOTING   ATROOPSHOOT   TROOPSTOPPED  faceplayer
ai AITROOPDUCKING  ATROOPDUCK    TROOPSTOPPED  faceplayer
ai AITROOPJETPACK  ATROOPJETPACK   TROOPJETPACKVELS seekplayer
ai AITROOPSHRUNK   ATROOPWALKING   SHRUNKVELS fleeenemy
ai AITROOPHIDE     ATROOPABOUTHIDE TROOPSTOPPED faceplayer
ai AITROOPGROW     ATROOPGROW    DONTGETUP faceplayerslow

state troophidestate
  ifaction ATROOPREAPPEAR
  {
    ifactioncount 2
    {
      sound TELEPORTER
      ai AITROOPSHOOTING
      cstat 257
    }
    else
    {
      sizeto 41 40
      sizeto 41 40
      sizeto 41 40
      sizeto 41 40
      spawn FRAMEEFFECT1
    }
  }
  else
    ifaction ATROOPWALKING
  {
    ifpdistl 2448
      ifpdistg 1024
    {
      ifceilingdistl 48
        break
      ifp pfacing
        break

      ifgapzl 64 nullop
      else
        ifawayfromwall
      {
        spawn TRANSPORTERSTAR
        action ATROOPREAPPEAR
        move 0
        break
      }
    }
  }
  else
    ifaction ATROOPHIDE
  {
    ifactioncount 2
    {
      spawn TRANSPORTERSTAR
      sound TELEPORTER
      action ATROOPWALKING
      move TROOPWALKVELS faceplayer
      cstat 32768
    }
    else
    {
      sizeto 4 40
      sizeto 4 40
      sizeto 4 40
      sizeto 4 40
      spawn FRAMEEFFECT1
    }
  }
  else
    ifaction ATROOPABOUTHIDE
      ifactioncount 2
    {
      action ATROOPHIDE
      cstat 0
    }
ends

state troopgunnashootbot
  
    ifvarl xydist 1024
    {
	    ifrnd 128 ifactornotstayput
	    ai AITROOPFLEEINGBACK else
        ai AITROOPSHOOTING
    }
    else
      ifactornotstayput
    {
      ifactioncount 12
        ifrnd 16
      {
        ifspritepal 21
          ifrnd 4
            ifvarg xydist 4096
              ai AITROOPHIDE
        else
        {
          ifvarl xydist 1280 // 1100
            ai AITROOPFLEEINGBACK
          else
          {
            ifvarl xydist 4096
            {
	            ifvarand monstflags 256 { move TROOPRUNVELS seekplayer action ATROOPRUNNING break }
                  ai AITROOPSHOOTING
            }
            else
            {
	          ifvarg peractor1 0 { ai AITROOPSHOOTING break }
              move TROOPRUNVELS seekplayer
              action ATROOPRUNNING
            }
          }
        }
      }
    }
    else
      ifcount 26
        ifrnd 32
        {
	      ifvarand monstflags 256 nullop else
          ai AITROOPSHOOTING
        }
  
ends

state troopgunnashoot
  ifp palive
  {
    ifpdistl 1024
      ai AITROOPSHOOTING
    else
      ifactornotstayput
    {
      ifactioncount 12
        ifrnd 16
          ifcanshoottarget
      {
        ifspritepal 21
          ifrnd 4
            ifpdistg 4096
              ai AITROOPHIDE
        else
        {
          ifpdistl 1100
            ai AITROOPFLEEING
          else
          {
            ifpdistl 4096
              ifcansee
                ifcanshoottarget
                {
	              ifvarand monstflags 256 { move TROOPRUNVELS seekplayer action ATROOPRUNNING break }
                  ai AITROOPSHOOTING
                }
            else
            {
	          ifvarg peractor1 0 { ai AITROOPSHOOTING break }
              move TROOPRUNVELS seekplayer
              action ATROOPRUNNING
            }
          }
        }
      }
    }
    else
      ifcount 26
        ifrnd 32
        {
	      ifvarand monstflags 256 nullop else
          ai AITROOPSHOOTING
        }
  }
ends

state troopseekstate
  ifpdistl 1596 ifp pfacing ifvarn playerally 0 { ai AITROOPFLEEINGBACK break }
  ifvarn target -1 state troopgunnashootbot else
  state troopgunnashoot
  ifinwater
  {
    ai AITROOPJETPACK
    break
  }
  ifvarg underwater 0
  {
	ai AITROOPJETPACK
	break
  }
  ifcansee
  {
    ifmove TROOPRUNVELS
      ifpdistl 1596
      {
	    ifp pfacing ifvarn playerally 0 ai AITROOPFLEEINGBACK else
	    {
		    ifvarand monstflags 256 nullop else
		    {
		    	cactor LIZTROOPDUCKING
	        	ai AITROOPDUCKING
        	}
        }
      }
    ifp phigher
    {
      ifceilingdistl 128 nullop
      else
        ifactornotstayput
          ai AITROOPJETPACK
      break
    }
    else
      ifrnd 2
    {
      ifspritepal 21
        ifpdistg 1596
      {
        ai AITROOPHIDE
        break
      }
      ifbulletnear
      {
        ifrnd 128
          ai AITROOPDODGE
        else
        {
	      cactor LIZTROOPDUCKING
          ai AITROOPDUCKING
        }
        break
      }
    }
  }
  ifnotmoving
  {
    ifrnd 32
      operate
    else
      ifcount 32
        ifp palive
        {
	      setvar temp 0
          ifcansee
            ifcanshoottarget
          setvar temp 1
          ifvarn target -1 setvar temp 1
          ifvare temp 1
              ai AITROOPSHOOTING
        }
  }
  ifrnd 1
  {
    ifrnd 128
      soundonce PRED_ROAM
    else
      soundonce PRED_ROAM2
  }
ends

state troopshootbot

ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1
state calczdist

ifvarand monstflags 64
{
	setprojectile[RAILSLUG_WEAK].workslike 36866 // 4097
	//shiftvarl zdist 8
	mulvar zdist 844
	divvarvar zdist xydist
	sound SHOTTY2
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 30
	zshoot zdist RAILSLUG_WEAK
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 15
	setprojectile[RAILSLUG_WEAK].workslike 32770 //1
}
else
ifvarand monstflags 32
{
    sound BLASTERSND
    eshoot FIREBALLPROJ 
	ifvarand monstflags 8 
	{
		setthisprojectile[RETURN].pal 13
		setthisprojectile[RETURN].extra 64
	}
} else
ifvarand monstflags 16
{
	setprojectile[STARPROJ].workslike 38914
	mulvar zdist 768
	divvarvar zdist xydist
	sound PISTOL_LOW
	zshoot zdist STARPROJ
	ifvarand monstflags 8 zshoot zdist STARPROJ
	setprojectile[STARPROJ].workslike 34818
}
else
{
	mulvar zdist 768
	divvarvar zdist xydist
	ifvare effects YES sound PRED_ATTACK2 else
    sound PRED_ATTACK
    zshoot zdist FIRELASER
    ifvarand monstflags 8 zshoot zdist FIRELASER
}

ends

state troopshooting

ifvarn target -1 { state troopshootbot break }

ifvarand monstflags 64
{
	sound SHOTTY2
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 30
	shoot RAILSLUG_WEAK
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 15
}
else
ifvarand monstflags 32
{
	ifcansee
	{
		sound BLASTERSND
		eshoot FIREBALLPROJ 
		ifvarand monstflags 8 
		{
			setthisprojectile[RETURN].pal 13
			setthisprojectile[RETURN].extra 64
		}
	}
} else
ifvarand monstflags 16
{
	ifvare xydist 0 setvar xydist 1
	divvarvar zdist xydist
	sound PISTOL_LOW
	shoot STARPROJ
	ifvarand monstflags 8 shoot STARPROJ
}
else
{
	ifvare effects YES sound PRED_ATTACK2 else
    sound PRED_ATTACK
    shoot FIRELASER
    ifvarand monstflags 8 shoot FIRELASER
}
ends

state troopduckstate
  ifaction ATROOPDUCK
  {
    ifactioncount 8
    {
      ifp palive
      {
        ifrnd 128
          action ATROOPDUCKSHOOT
      }
      else
        ifmove DONTGETUP
          break
        else
        {
	      cactor LIZTROOP
          ai AITROOPSEEKPLAYER
        }
    }
  }
  else
    ifaction ATROOPDUCKSHOOT
  {
    ifcount 64
    {
      ifmove DONTGETUP
        resetcount
      else
      {
	    cactor LIZTROOP
        ifpdistl 1100
          ai AITROOPFLEEING
        else
        ifvarn target -1 ifvarl xydist 1100
          ai AITROOPFLEEING
        else
          ai AITROOPSEEKPLAYER
      }
    }
    else
      ifactioncount 2
      {
	    ifvarn target -1 { state troopshootbot resetactioncount } else
        ifcanshoottarget ifvare playerally 0
        {
	      state troopshooting
          resetactioncount
        }
        else 
        {
	        cactor LIZTROOP
	        ifvarn playerally 0 ai AITROOPFLEEINGBACK else
	        ai AITROOPSEEKPLAYER
        }
      }
  }
ends

state suicidebomber

setvar temp 0
ifvarn target -1
{
  dist xydist2 THISACTOR target
  ifvarl xydist2 1280 setvar temp 1
}
ifvare playerally 0
ifcanshoottarget ifpdistl 1280 setvar temp 1

ifvare temp 0 break
action ATROOPABOUTBLOW
sound LASERTRIP_ONWALL
sound LASERTRIP_ARMING

ends

state suicideblow
	debris SCRAP1 8
	debris SCRAP2 4
	debris SCRAP3 7
	state standard_jibs
	spawn EXPLOSION2
	sound RPG_EXPLODE
	ifvarand monstflags 8
	hitradius 3072 72 96 120 144 else
	hitradius 3072 36 48 60 72
	addkills 1
	state specialdeath
	killit 
ends

state troopshootstate

ifvarn playerally 0 ifvare target -1 { ai AITROOPSEEKPLAYER break }

ifaction ATROOPABOUTBLOW
{
	ifactioncount 2
	{
		state suicideblow
	}
	break
}
else ifvarand monstflags 256 state suicidebomber

  ifactioncount 2
  {
	setvar temp 0
	ifcanshoottarget setvar temp 1
	ifvarn target -1 setvar temp 1
	ifvare temp 1
    {
      state troopshooting
      resetactioncount
      ifrnd 128
        ai AITROOPSEEKPLAYER
      ifcount 24
      {
        ifrnd 96
          ifpdistg 2048
            ai AITROOPSEEKPLAYER
          else
          {
            ifpdistg 1596
              ai AITROOPFLEEING
            else
              ai AITROOPFLEEINGBACK
          }
      }
    }
    else
      ai AITROOPSEEKPLAYER
  }
ends

state troopfleestate
  ifactioncount 7
  {
    ifpdistg 3084
    {
      ai AITROOPSEEKPLAYER
      break
    }
    else
      ifrnd 32
        ifp palive
          ifcansee
            ifcanshoottarget
      {
        ifrnd 128
        {
	      cactor LIZTROOPDUCKING
          ai AITROOPDUCKING
        }
        else
          ai AITROOPSHOOTING
          break
      }
  }
  ifnotmoving
  {
    ifrnd 32
      operate
    else
      ifcount 32
        ifp palive   
      {
	    setvar temp 0
	    ifcansee
          ifcanshoottarget
            setvar temp 1
        ifvarn target -1 setvar temp 1
        ifvare temp 1
          {
	        ifrnd 128
	          ai AITROOPSHOOTING
	        else
	        {
		      cactor LIZTROOPDUCKING
	          ai AITROOPDUCKING
	        }
          }
      }
  }
ends

state troopdying
  iffloordistl 32
  {
    ifactioncount 5
    {
      cstat 0
      iffloordistl 8
      sound THUD
      ifrnd 64
        spawn BLOODPOOL
      state rf
      strength 0
      //move TROOPSTOPPED geth
      //action ATROOPDEAD
      action 0
      move 0
      cactor LIZTROOPCORPSE
    }
    break
  }
  else
  {
    state rf
    move 0
    action ATROOPDYING
  }
ends

state checktroophit
  ifaction ATROOPSUFFERING
  {
    stopsound LIZARD_BEG
    sound PRED_DYING
    cstat 0
    strength 0
    action ATROOPSUFFERDEAD
    ifvarand monstflags 256 state suicideblow
    break
  }
  ifdead
  {
	cactor LIZTROOP
    ifwasweapon FREEZEBLAST
    {
      sound SOMETHINGFROZE
      spritepal 1
      move 0
      action ATROOPFROZEN
      strength 0
      break
    }

    state drop_ammo
    state random_wall_jibs

    ifwasweapon GROWSPARK
    {
      cstat 0
      sound ACTOR_GROWING
      ai AITROOPGROW
      break
    }

    addkills 1 state specialdeath

    ifwasweapon RPG
    {
      sound SQUISHED
      state troop_body_jibs
      state standard_jibs
      killit
    }
    else
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state troop_body_jibs
      state standard_jibs
      killit
    }
    else
    {
      sound PRED_DYING
      ifrnd 32
        iffloordistl 32
      {
        sound LIZARD_BEG
        spawn BLOODPOOL
        strength 0
        move 0
        action ATROOPSUFFERING
        break
      }
      action ATROOPDYING
      break
    }
  }
  else
  {
    state random_wall_jibs
    sound PRED_PAIN

    ifwasweapon SHRINKSPARK
    {
	  cactor LIZTROOP
      sound ACTOR_SHRINKING
      ai AITROOPSHRUNK
    }
    else
      ifwasweapon GROWSPARK
        sound EXPANDERHIT
    else
      iffloordistl 32
        ifrnd 96
        {
	      cactor LIZTROOP
          action ATROOPFLINTCH
        }
  }
ends

state troopjetpackstate
cactor LIZTROOP // because stop things can happen :(
  ifaction ATROOPJETPACKILL
  {
    //ifcansee
      ifactioncount 2
    {
	  setvar temp 0
	  ifvare playerally 0
	  ifcansee setvar temp 1
	  ifvarn target -1 setvar temp 1
	  ifvare temp 1
	  {
		  state troopshooting
	      resetactioncount
      }
    }

    ifp phigher
      ai AITROOPJETPACK
    else
      ifinwater
        ai AITROOPJETPACK
    else
      ifvarg underwater 0
        ai AITROOPJETPACK
    else
      ifcount 26
        iffloordistl 32
          ai AITROOPSEEKPLAYER
  }
  else
    ifcount 48
      //ifcansee
  {
	  setvar temp 0
	  ifcansee setvar temp 1
	  ifvarn target -1 setvar temp 1
	  ifvare temp 1
	  {
	    action ATROOPJETPACKILL
	    move TROOPJETPACKILLVELS seekplayer
      }
  }
ends

state checksquished
  ifsquished
  {
    addkills 1 state specialdeath
    sound SQUISHED
    state standard_jibs
    state random_ooz
    killit
  }
ends

state troopsufferingstate
  ifactioncount 2
  {
    ifrnd 16
      spawn WATERDRIP
    ifactioncount 14
    {
      stopsound LIZARD_BEG
      cstat 0
      strength 0
      action ATROOPSUFFERDEAD
      break
    }
  }
ends

state troopshrunkstate
  ifcount SHRUNKDONECOUNT
    ai AITROOPSEEKENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 48 40
  else
    state genericshrunkcode
ends


state troopcode fall
state monsterai
  ifinwater
    ifrnd 1
      spawn WATERBUBBLE
  ifvarg underwater 0
    ifrnd 1
      spawn WATERBUBBLE
  ifaction ATROOPSTAND
  {
    ifrnd 192
      ai AITROOPSHOOTING
    else
      ai AITROOPSEEKPLAYER
  }
  else
    ifaction ATROOPFROZEN
  {
    ifcount THAWTIME
    {
      ai AITROOPSEEKENEMY
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }
    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1 
      state specialdeath

      ifrnd 84
        spawn BLOODPOOL
      lotsofglass 30
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick
    break
  }
  else ifaction ATROOPPLAYDEAD
  {
    ifhitweapon
    {
      ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state troop_body_jibs
        state standard_jibs
        killit
      }
      break
    }
    else
      state checksquished

    ifcount PLAYDEADTIME
    {
      addkills -1
      setvar monstatus 0
      soundonce PRED_ROAM
      cstat 257
      strength 1
      //ai AITROOPSHOOTING
      cactor LIZTROOPDUCKING
      ai AITROOPDUCKING
      action ATROOPDUCKSHOOT
    }
    else
      ifp pfacing
        resetcount

    break
  }
  else
    ifaction ATROOPDEAD
  {
    strength 0
    ifrespawn
      ifcount RESPAWNACTORTIME
    {
      spawn TRANSPORTERSTAR
      cstat 257
      strength TROOPSTRENGTH
      setvar monstatus 1
      ai AITROOPSEEKENEMY
    }
    ifhitweapon
    {
      ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state troop_body_jibs
        state standard_jibs
        killit
      }
      break
    }
    else
      state checksquished
    break
  }
  else
    ifaction ATROOPSUFFERDEAD
  {
    ifactioncount 2
    {
      ifrnd 64
      {
        resetcount
        action ATROOPPLAYDEAD
      }
      else
      {
        soundonce PRED_DYING
        action 0
        move 0
        cactor LIZTROOPCORPSE
        //action ATROOPDEAD
      }
    }
  }
  else
    ifaction ATROOPDYING
  {
    state troopdying
    break
  }
  else
    ifaction ATROOPSUFFERING
  {
    state troopsufferingstate
    ifhitweapon
      state checktroophit
    break
  }
  else
    ifaction ATROOPFLINTCH
  {
    ifactioncount 4
      ai AITROOPSEEKENEMY
  }
  else
  {
    ifai AITROOPSEEKPLAYER
      state troopseekstate
    else
      ifai AITROOPJETPACK
    {
      state troopjetpackstate
      ifinwater nullop
      else
      ifvarg underwater 0 nullop
      else
        soundonce DUKE_JETPACK_IDLE
    }
    else
      ifai AITROOPSEEKENEMY
        state troopseekstate
    else
      ifai AITROOPSHOOTING
        state troopshootstate
    else
      ifai AITROOPFLEEING
        state troopfleestate
    else
      ifai AITROOPFLEEINGBACK
        state troopfleestate
    else
      ifai AITROOPDODGE
        state troopseekstate
    else
      ifai AITROOPDUCKING
        state troopduckstate
    else
      ifai AITROOPSHRUNK
        state troopshrunkstate
    else
      ifai AITROOPGROW
        state genericgrowcode
    else
      ifai AITROOPHIDE
    {
      state troophidestate
      break
    }
  }

  ifhitweapon
    state checktroophit
  else
    state checksquished
ends

state checktrooppalette
  ifai 0
  {
    ifspritepal 0
        nullop
    else
        ifspritepal 21
          addstrength TROOPSTRENGTH // Double the hitpoint vals
  }
ends


actor LIZTROOPJETPACK TROOPSTRENGTH
  state checktrooppalette
  ai AITROOPJETPACK
  cactor LIZTROOP
enda

actor LIZTROOPDUCKING TROOPSTRENGTH
  ifai 0 
  {  state checktrooppalette
     ai AITROOPDUCKING
     ifgapzl 48
       move DONTGETUP
  }
  //cactor LIZTROOP
  state troopcode
  
enda

actor LIZTROOPSHOOT TROOPSTRENGTH ATROOPSTAND
  state checktrooppalette
  ai AITROOPSHOOTING
  cactor LIZTROOP
enda
actor LIZTROOPSTAYPUT TROOPSTRENGTH ATROOPSTAYSTAND
  state checktrooppalette
  ai AITROOPSEEKPLAYER
  cactor LIZTROOP
enda
actor LIZTROOPRUNNING TROOPSTRENGTH ATROOPSTAND
  state checktrooppalette
  ai AITROOPSEEKPLAYER
  cactor LIZTROOP
enda
actor LIZTROOPONTOILET TROOPSTRENGTH
  ifcount 24
  {
    sound FLUSH_TOILET
    operate
    ai AITROOPSEEKPLAYER
    cactor LIZTROOP
  }
  else
    ifcount 2
      nullop
  else
    state checktrooppalette
    
   getactor[THISACTOR].htextra temp
   ifvarg temp TROOPSTRENGTH { cactor LIZTROOP spawn FECES }
enda

actor LIZTROOPJUSTSIT TROOPSTRENGTH
  ifcount 30
  {
    operate
    ai AITROOPSEEKPLAYER
    cactor LIZTROOP
  }
  else
    ifcount 2
      nullop
  else
    state checktrooppalette
     
    getactor[THISACTOR].htextra temp
    ifvarg temp TROOPSTRENGTH 
    {
	    ifvarg temp 100 setactor[THISACTOR].htextra 100
	    cactor LIZTROOP
    }
enda


actor LIZTROOP TROOPSTRENGTH ATROOPSTAND
  state checktrooppalette
  state troopcode
enda

action ALIZSTAND     0
action ALIZWALKING     0   4  5  1  15
action ALIZRUNNING     0   4  5  1  11
action ALIZTHINK     20  2  5  1  40
action ALIZSCREAM    30  1  5  1  2
action ALIZJUMP      45  3  5  1  20
action ALIZFALL      55  1  5
action ALIZSHOOTING    70  2  5  1  7
action ALIZDYING     60  6  1  1  15
action ALIZLYINGDEAD   65  1
action ALIZFROZEN     0  1  5
action ALIZFLINTCH 60 1 1 1 6

move LIZWALKVEL 32
move LIZRUNVEL 092
move LIZJUMPVEL 184
move LIZSTOP
move LIZWALKVELBACK -72
move LIZRUNVELBACK  -192
move LIZJUMPVELBACK -184

ai AILIZGETENEMY ALIZWALKING LIZWALKVEL seekplayer
ai AILIZDODGE ALIZRUNNING LIZRUNVEL dodgebullet
ai AILIZCHARGEENEMY ALIZRUNNING LIZRUNVEL seekplayer
ai AILIZFLEENEMY ALIZWALKING LIZWALKVEL fleeenemy
ai AILIZSHOOTENEMY ALIZSHOOTING LIZSTOP faceplayer
ai AILIZJUMPENEMY ALIZJUMP LIZJUMPVEL jumptoplayer
ai AILIZTHINK ALIZTHINK LIZSTOP faceplayerslow
ai AILIZSHRUNK ALIZWALKING SHRUNKVELS fleeenemy
ai AILIZGROW ALIZSTAND  LIZSTOP faceplayerslow
ai AILIZSPIT ALIZSCREAM LIZSTOP faceplayerslow
ai AILIZDYING ALIZDYING LIZSTOP geth //faceplayer
ai AILIZHIT ALIZFLINTCH LIZSTOP geth

state lizseekbotstate

getactor[THISACTOR].z z
getactor[target].z mz

 ifactornotstayput
  {
        ifvarl xydist 2048
          ifcount 16
    {
      ai AILIZSHOOTENEMY
      break
    }
    ifai AILIZCHARGEENEMY
    {
	  ifcount 13
	    ifvarg peractor1 0 
	  { 
		  ai AILIZSHOOTENEMY 
		  break 
	  }
      ifcount 72
      {
        ai AILIZSHOOTENEMY
        break
      }
       ifvarvarg z mz
        ifvarg xydist 2048
          ifrnd 6
      {
        ai AILIZJUMPENEMY
        break
      }
    }
    else
      ifvarg xydist 4096
    {
      ifrnd 92
      {
        ifcount 48
            ai AILIZSHOOTENEMY
      }
      else
        ifcount 24
      {
        ai AILIZCHARGEENEMY
        break
      }
    }

    iffloordistl 16
    {
      ifcount 48
        ifnotmoving
      {
	      ifmove LIZWALKVELBACK { ai AILIZSHOOTENEMY break } else
		  ifmove LIZRUNVELBACK { ai AILIZSHOOTENEMY break } else
        ai AILIZJUMPENEMY
        break
      }
    }
    else
    {
      ifvarg xydist 1280
        ai AILIZJUMPENEMY
      break
    }

    ifrnd 4
      ifnotmoving
        operate
    else
      ifrnd 1
        ifbulletnear
    {
      ifgapzl 128
        ai AILIZDODGE
      else
        ifactornotstayput
      {
        ifrnd 32 ifvare peractor1 0
          ai AILIZJUMPENEMY
        else
          ai AILIZDODGE
      }
    }
  }
  else
  {
    ifactioncount 16
    {
        ifrnd 32
              ai AILIZSHOOTENEMY
    }
    ifcount 16
      ifrnd 32
        move LIZWALKVEL randomangle geth
  }

ends

state lizseekstate

ifvarn target -1 { state lizseekbotstate break }

  ifactornotstayput
  {
    ifcansee
      ifp palive
        ifpdistl 2048
          ifcount 16
            ifcanshoottarget
    {
	  ifvarn playerally 0 ai AILIZFLEENEMY else
      ai AILIZSHOOTENEMY
      break
    }
    ifai AILIZCHARGEENEMY
    {
	  ifcount 13
	    ifvarg peractor1 0 
	     ifcansee ifcanshoottarget ifvare playerally 0
	  {
		  ai AILIZSHOOTENEMY 
		  break 
	  }
      ifcount 72
        ifcanshoottarget
      {
	    ifvarn playerally 0 ai AILIZGETENEMY else
        ai AILIZSHOOTENEMY
        break
      }
      ifp phigher
        ifpdistg 2048
          ifrnd 6
      {
        ai AILIZJUMPENEMY
        break
      }
    }
    else
      ifpdistg 4096
    {
      ifrnd 92
      {
        ifcount 48
          ifcanshoottarget
            ifvare playerally 0
              ai AILIZSHOOTENEMY
      }
      else
        ifcount 24
      {
        ai AILIZCHARGEENEMY
        break
      }
    }

    iffloordistl 16
    {
      ifcount 48
        ifnotmoving
          ifcansee
      {
	      ifmove LIZWALKVELBACK { ifvarn playerally 0 ai AILIZTHINK else ai AILIZSHOOTENEMY break } else
		  ifmove LIZRUNVELBACK { ifvarn playerally 0 ai AILIZTHINK else ai AILIZSHOOTENEMY break } else
        ai AILIZJUMPENEMY
        break
      }
    }
    else
    {
      ifpdistg 1280
        ai AILIZJUMPENEMY
      break
    }

    ifrnd 4
      ifnotmoving
        operate
    else
      ifrnd 1
        ifbulletnear
    {
      ifgapzl 128
        ai AILIZDODGE
      else
        ifactornotstayput
      {
        ifrnd 32 ifvare peractor1 0
          ai AILIZJUMPENEMY
        else
          ai AILIZDODGE
      }
    }
  }
  else
  {
    ifactioncount 16
    {
      ifp palive
        ifrnd 32
          ifcansee
            ifcanshoottarget
              ifvare playerally 0
                ai AILIZSHOOTENEMY
    }
    ifcount 16
      ifrnd 32
        move LIZWALKVEL randomangle geth
  }

ends

state lizshrunkstate
  ifcount SHRUNKDONECOUNT
    ai AILIZGETENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 48 40
  else
    state genericshrunkcode
ends

state lizfleestate
  ifcount 16
  {
    ifrnd 48
      ifp palive
      {
        ifcansee
          ai AILIZSPIT
        ifvarn target -1
          ai AILIZSPIT
      }
  }
  else
  {
    iffloordistl 16 nullop
    else
      ai AILIZGETENEMY
    break
  }
ends

state lizthinkstate
  ifrnd 8
    soundonce CAPT_ROAM
  ifactioncount 3
  {
	ifvarn target -1
	{
		ifrnd 32
		  ai AILIZSPIT
		else
		  ifrnd 96
		    ai AILIZGETENEMY
	}
	else
	{
    ifrnd 32
      ifp palive
        ifcansee
         ifvare playerally 0
          ai AILIZSPIT
        else
          ifrnd 96
            ai AILIZGETENEMY
    }
  }
  else
    ifactioncount 2
      ifrnd 1
        spawn FECES
  ifrnd 1
    ifbulletnear
  {
    ifgapzl 96
      ai AILIZDODGE
    else
    {
      ifrnd 128
        ai AILIZJUMPENEMY
      else
        ai AILIZDODGE
    }
  }
ends

state lizshootbot

state calczdist
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1

ifvarand monstflags 64
{
	setprojectile[RAILSLUG_WEAK].workslike 36866 // 4097
	//shiftvarl zdist 8
	mulvar zdist 844
	divvarvar zdist xydist
	sound SHOTTY2
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 30
	zshoot zdist RAILSLUG_WEAK
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 15
	setprojectile[RAILSLUG_WEAK].workslike 32770 // 1
} else
ifvarand monstflags 32
{
	mulvar zdist 844
	divvarvar zdist xydist
	setprojectile[FIREBULLET].workslike 36870
	sound RPG_SHOOT
	zshoot zdist FIREBULLET
	ifvarand monstflags 8 zshoot zdist FIREBULLET
	setprojectile[FIREBULLET].workslike 32774
} else
ifvarand monstflags 16
{
	mulvar zdist 768
	divvarvar zdist xydist
	setprojectile[STARPROJ].workslike 38914
	sound PISTOL_LOW
	zshoot zdist STARPROJ
	ifvarand monstflags 8 zshoot zdist STARPROJ
	setprojectile[STARPROJ].workslike 34818
} else
{
	shiftvarl zdist 8
	divvarvar zdist xydist
	sound CAPT_ATTACK
	zshoot zdist SHOTSPARK1
	ifvarand monstflags 8 zshoot zdist SHOTSPARK1
}
state shelleject
resetactioncount


ends

state lizshooting

ifvarn target -1 { state lizshootbot break }

ifvarand monstflags 64
{
	sound SHOTTY2
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 30
	shoot RAILSLUG_WEAK
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 15
	ifvarand monstflags 8 shoot RAILSLUG_WEAK
} else
ifvarand monstflags 32
{
	sound RPG_SHOOT
	shoot FIREBULLET
	ifvarand monstflags 8 shoot FIREBULLET
} else
ifvarand monstflags 16
{
	sound PISTOL_LOW
	shoot STARPROJ
	ifvarand monstflags 8 shoot STARPROJ
} else
{
	sound CAPT_ATTACK
	shoot SHOTSPARK1
	ifvarand monstflags 8 shoot SHOTSPARK1
}
state shelleject
resetactioncount

ends

state lizshootbotstate

  ifcount 20
    ifrnd 8
  {
      ifvarl xydist 2048
    {
      ifrnd 128
        ai AILIZFLEENEMY
      break
    }
    ifrnd 80
      ai AILIZTHINK
    else
      ai AILIZGETENEMY
  }
  ifactioncount 2
  {
	canseespr THISACTOR target temp
    ifvare temp 1
    {
      //ifrnd 224
      //{
	    state lizshooting
      //}
      //else
      //  ai AILIZTHINK
    }
    else
      ai AILIZGETENEMY
  }

ends

state lizshootstate

ifvarn target -1 { state lizshootbotstate break } else
ifvarn playerally 0 { ai AILIZGETENEMY break }

  ifcount 20
    ifrnd 8
  {
    ifcansee
      ifpdistl 2048
    {
      ifrnd 128
        ai AILIZFLEENEMY
      break
    }
    ifrnd 80
      ai AILIZTHINK
    else
      ai AILIZGETENEMY
  }
  ifactioncount 2
  {
    ifcansee
    {
      ifcanshoottarget
      {
	    state lizshooting
      }
      else
        ai AILIZTHINK
    }
    else
      ai AILIZGETENEMY
  }
ends

state checklizhit
  spawn BLOOD
  ifai AILIZSHRUNK
  {
    addkills 1 state specialdeath
    sound SQUISHED
    state standard_jibs
    killit
  }
  ifdead
  {
    ifwasweapon FREEZEBLAST
    {
      sound SOMETHINGFROZE
      spritepal 1
      move 0
      action ALIZFROZEN
      strength 0
      break
    }

    state drop_chaingun

    ifwasweapon GROWSPARK
    {
      cstat 0
      sound ACTOR_GROWING
      ai AILIZGROW
      break
    }

    addkills 1 state specialdeath

    ifwasweapon RPG
    {
      sound SQUISHED
      state liz_body_jibs
      state standard_jibs
      killit
    }
    else
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state liz_body_jibs
      state standard_jibs
      killit
    }
    else
    {
      state rf
      ai AILIZDYING
      ifrnd 64
        spawn BLOODPOOL
    }
    sound CAPT_DYING
  }
  else
  {
    sound CAPT_PAIN
    ifwasweapon SHRINKSPARK
    {
      sound ACTOR_SHRINKING
      ai AILIZSHRUNK
      break
    }
    ifwasweapon GROWSPARK
      sound EXPANDERHIT
    
    ifwasweapon KNEE ifvarn superkicking 0
    ai AILIZHIT

    state random_wall_jibs
    ifai AILIZHIT break
    
    ifvarn target -1 ai AILIZSHOOTENEMY else
    ifp palive
      ifcansee
        ifcanshoottarget
          ifvare playerally 0
      ai AILIZSHOOTENEMY
      

    
  }
ends

state lizjumpstate
  ifaction ALIZFALL
  {
    iffloordistl 16
      ai AILIZGETENEMY
  }
  else
    ifactioncount 3
      action ALIZFALL
ends

state lizdyingstate
  ifaction ALIZLYINGDEAD
  {
    strength 0
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    ifcount RESPAWNACTORTIME
      ifrespawn
    {
      spawn TRANSPORTERSTAR
      cstat 257
      setvar monstatus 1
      strength LIZSTRENGTH
      ai AILIZGETENEMY
    }
  }
  else
    ifai AILIZDYING
      ifactioncount 6
  {
    iffloordistl 8
      sound THUD
    //move LIZSTOP
    //action ALIZLYINGDEAD
    action 0
    move 0
    cactor LIZMANCORPSE
  }
ends

state lizdodgestate
  ifcount 13
    ai AILIZGETENEMY
ends

actor LIZMANSTAYPUT LIZSTRENGTH ai AILIZGETENEMY cactor LIZMAN enda
actor LIZMANSPITTING LIZSTRENGTH ai AILIZSPIT cactor LIZMAN enda
actor LIZMANJUMP LIZSTRENGTH ai AILIZJUMPENEMY cactor LIZMAN enda

state lizcode

state monsterai
  state checksquished
  ifai 0
    ai AILIZGETENEMY
  else
    ifaction ALIZLYINGDEAD
  {
    fall
    state lizdyingstate
    break
  }
  else
    ifaction ALIZFROZEN
  {
    ifcount THAWTIME
    {
      ai AILIZGETENEMY
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1 state specialdeath
      state drop_chaingun

      ifrnd 84
        spawn BLOODPOOL
      lotsofglass 30
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick
    break
  }
  else
    ifai AILIZJUMPENEMY
      state lizjumpstate
  else
  {
    fall
    ifai AILIZGETENEMY
      state lizseekstate
    else
      ifai AILIZCHARGEENEMY
        state lizseekstate
    else
      ifai AILIZDODGE
        state lizdodgestate
    else
      ifai AILIZSHOOTENEMY
        state lizshootstate
    else
      ifai AILIZFLEENEMY
        state lizfleestate
    else
      ifai AILIZTHINK
        state lizthinkstate
    else
      ifai AILIZSHRUNK
        state lizshrunkstate
    else
      ifai AILIZGROW
        state genericgrowcode
    else
      ifai AILIZDYING
        state lizdyingstate
    else
      ifai AILIZHIT
    {
	  ifcount 6 ai AILIZTHINK
    }
    else
      ifai AILIZSPIT
    {
      ifcount 26
        ai AILIZGETENEMY
      else
        ifcount 18
          ifrnd 96
      {
	    ifvarn playerally 0 ifvare target -1 nullop else
	    {
	        shoot SPIT
	        ifvarand monstflags 8 shoot SPIT
	        sound LIZARD_SPIT
        }
      }
    }
  }

  ifai AILIZSHRUNK
    break
  ifhitweapon
    state checklizhit
ends

actor LIZMAN LIZSTRENGTH
  fall
  state lizcode
enda


action DRONEFRAMES   0   1   7   1   1
action DRONESCREAM   0   1   7   1   1
move DRONERUNVELS 128 64
move DRONERUNUPVELS 128 -64
move DRONEBULLVELS 252 -64
move DRONEBACKWARDS -64 -64
move DRONERISE 32 -32
move DRONESTOPPED -16

ai AIDRONEGETE DRONESCREAM DRONERUNVELS faceplayerslow getv
ai AIDRONEWAIT DRONEFRAMES DRONESTOPPED faceplayerslow
ai AIDRONEGETUP DRONESCREAM DRONERUNUPVELS faceplayer getv
ai AIDRONEPULLBACK DRONEFRAMES DRONEBACKWARDS faceplayerslow
ai AIDRONEHIT DRONESCREAM DRONEBACKWARDS faceplayer
ai AIDRONESHRUNK DRONEFRAMES SHRUNKVELS fleeenemy
ai AIDRONEDODGE DRONEFRAMES DRONEBULLVELS dodgebullet geth
ai AIDRONEDODGEUP DRONEFRAMES DRONERISE getv geth

state dronedead
  addkills 1 state specialdeath
  debris SCRAP1 8
  debris SCRAP2 4
  debris SCRAP3 7
  spawn EXPLOSION2
  sound RPG_EXPLODE
  ifvarand monstflags 8 hitradius 2048 30 40 50 60 else
  hitradius 2048 15 20 25 30
  killit
ends

state checkdronehitstate

  ifdead state dronedead
  else ifsquished state dronedead
  else
  {
    sound DRON_PAIN
    ifbulletnear
    {
      ifceilingdistl 64
        ifrnd 48
          ai AIDRONEDODGE
      ai AIDRONEDODGEUP
    }
    else
      ai AIDRONEGETE
  }
ends

state droneshrunkstate
  ifcount 24
    killit
  else
    sizeto 1 1
ends

state checkdronenearplayer

setvar temp 0

ifvarn target -1 ifvarl xydist 1596 setvar temp 1 else
ifvare playerally 0
ifp palive ifpdistl 1596 setvar temp 1

  ifvare temp 1
  {
    ifcount 8
    {
	  ifvarand monstflags 16 { ai AIDRONEPULLBACK break }
	  ifvarand monstflags 32 { ai AIDRONEPULLBACK break }
	  ifvarand monstflags 64 { ai AIDRONEPULLBACK break }
      addkills 1 state specialdeath
      sound DRON_ATTACK2
      debris SCRAP1 8
      debris SCRAP2 4
      debris SCRAP3 7
      spawn EXPLOSION2
      sound RPG_EXPLODE
      ifvarand monstflags 8 hitradius 2048 30 40 50 60 else
      hitradius 2048 15 20 25 30
      killit
    }
    else
      ifcount 3 nullop
      else
        sound LASERTRIP_ARMING
  }

ends

state dronegetbotstate

getactor[THISACTOR].z z
getactor[target].z mz


      ifbulletnear
      {
        ai AIDRONEDODGE
        break
      }
      ifmove DRONEBULLVELS
      {
        ifcount 64
          ai AIDRONEPULLBACK
        else
          ifnotmoving
            ifcount 16
              ai AIDRONEPULLBACK
      }
      else
        ifcount 32
      {
        ifvarvarg z mz
          move DRONEBULLVELS geth getv
        else
          move DRONEBULLVELS geth
      }
   
ends

state dronegetstate

ifvarn target -1 { state dronegetbotstate break }

  ifrnd 192
  {
    ifcansee
    {
      ifbulletnear
      {
        ai AIDRONEDODGE
        break
      }
      ifmove DRONEBULLVELS
      {
        ifcount 64
          ai AIDRONEPULLBACK
        else
          ifnotmoving
            ifcount 16
              ai AIDRONEPULLBACK
      }
      else
        ifcount 32
      {
        ifp phigher
          move DRONEBULLVELS geth getv
        else
          move DRONEBULLVELS geth
      }
    }
    else
      ifrnd 1
        operate
  }
ends

state dronedodgestate
  ifai AIDRONEDODGEUP
  {
     ifcount 8
       ai AIDRONEGETE
     else
       ifnotmoving
         ai AIDRONEGETE
  }
  else
  {
    ifcount 8
      ai AIDRONEGETE
    else
      ifnotmoving
        ai AIDRONEGETE
  }
ends

actor DRONE DRONESTRENGTH
state monsterai
  state checkdronenearplayer

  ifrnd 2
    fall
  else
    soundonce DRON_JETSND

  ifaction 0
  {
    ai AIDRONEGETE
    getactor[THISACTOR].pal pal
    ifvarand monstflags 64
    {
	    espawn ROTATEGUN
		setactorvar[RETURN].myspawner THISACTOR
		setactorvar[RETURN].monstflags 32
		setactor[RETURN].pal pal
	}
    ifvarand monstflags 32
    {
	    espawn ROTATEGUN
		setactorvar[RETURN].myspawner THISACTOR
		setactorvar[RETURN].monstflags 16
		setactor[RETURN].pal pal
	} else
    ifvarand monstflags 16
    {
	    espawn ROTATEGUN
		setactorvar[RETURN].myspawner THISACTOR
		setactor[RETURN].pal pal
	}
  }

  else
    ifai AIDRONEWAIT
  {
	ifvarn target -1
	{
		getactor[THISACTOR].z z
		getactor[target].z mz
		ifactioncount 4
	      ifrnd 16
	    {
	      sound DRON_ATTACK1
	      ifvarvarg z mz
	        ai AIDRONEGETUP
	      else ai AIDRONEGETE
	    }
	}
	else
	{
	    ifactioncount 4
	      ifrnd 16
	        ifcansee
	    {
	      sound DRON_ATTACK1
	      ifp phigher
	        ai AIDRONEGETUP
	      else ai AIDRONEGETE
	    }
    }
  }
  else
    ifai AIDRONEGETE
      state dronegetstate
  else
    ifai AIDRONEGETUP
      state dronegetstate
  else
    ifai AIDRONEPULLBACK
  {
    ifcount 32
    ai AIDRONEWAIT
  }
  else
    ifai AIDRONEHIT
  {
    ifcount 8
      ai AIDRONEWAIT
  }
  else
    ifai AIDRONESHRUNK
      state droneshrunkstate
  else
    ifai AIDRONEDODGE
      state dronedodgestate
  else
    ifai AIDRONEDODGEUP
      state dronedodgestate

  ifhitweapon
    state checkdronehitstate

  ifrnd 1
    soundonce DRON_ROAM

enda

action AOCTAWALK    0   3   5   1   15
action AOCTASTAND     0   1   5   1   15
action AOCTASCRATCH   0   4   5   1   15
action AOCTAHIT    30   1   1   1   10
action AOCTASHOOT    20   1   5   1   10
action AOCTADYING    30   8   1   1   17
action AOCTADEAD     38   1   1   1  1
action AOCTAFROZEN    0   1   5

move OCTAWALKVELS 96 -30
move OCTAUPVELS 96 -70
move OCTASTOPPED 0 -30
move OCTAINWATER 96 24

ai AIOCTAGETENEMY AOCTAWALK OCTAWALKVELS seekplayer
ai AIOCTASHOOTENEMY AOCTASHOOT OCTASTOPPED faceplayer
ai AIOCTASCRATCHENEMY AOCTASCRATCH OCTASTOPPED faceplayerslow
ai AIOCTAHIT AOCTAHIT OCTASTOPPED faceplayer
ai AIOCTASHRUNK AOCTAWALK SHRUNKVELS faceplayer
ai AIOCTAGROW AOCTASTAND OCTASTOPPED faceplayerslow
ai AIOCTADYING AOCTADYING OCTASTOPPED geth //faceplayer


state octagetbotstate

    ifactioncount 32
    {
      ifrnd 48
      {
        sound OCTA_ATTACK1
        ai AIOCTASHOOTENEMY
        break
      }
    }
    else
      ifvarl xydist 1280
        ai AIOCTASCRATCHENEMY
  
ends

state octagetenemystate

ifvarn target -1 { state octagetbotstate break }
  ifcansee
  {
    ifactioncount 32
    {
      ifrnd 48
        ifcanshoottarget
      {
        sound OCTA_ATTACK1
        ai AIOCTASHOOTENEMY
        break
      }
    }
    else
      ifpdistl 1280
        ai AIOCTASCRATCHENEMY
  }

ends

state octascratchbotstate

  ifvarg xydist 1280
    ai AIOCTAGETENEMY
  else
    ifcount 32
  {
    resetcount
    sound OCTA_ATTACK2
    setvar temp OCTASCRATCHINGPLAYER
    mulvar temp -1
    ifvarand monstflags 8 mulvar temp 2
    setactor[target].htextra temp
    setactor[target].htpicnum KNEE
    setactor[target].htowner THISACTOR
  }
ends

state octascratchenemystate

ifvarn target -1 { state octascratchbotstate break }
ifvare target -1 ifvarn playerally 0 ai AIOCTAGETENEMY

  ifpdistg 1280
    ai AIOCTAGETENEMY
  else
    ifcount 32
  {
    resetcount
    sound OCTA_ATTACK2
    palfrom 8 32
    addphealth OCTASCRATCHINGPLAYER
    ifvarand monstflags 8 addphealth OCTASCRATCHINGPLAYER
  }
ends

state octashootbot

state calczdist
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1

	ifvarand monstflags 64
	{
		eshoot FIREBALLPROJ
		ifvarand monstflags 8 
		{
			setthisprojectile[RETURN].pal 13
			setthisprojectile[RETURN].extra 64
		}
	} else
	ifvarand monstflags 32
	{
		mulvar zdist 768
		divvarvar zdist xydist
		sound SHRINKER_FIRE
		zshoot zdist SHRINKER
	} else
	  ifvarand monstflags 16 
	  {
		  mulvar zdist 768
		  divvarvar zdist xydist
		  setprojectile[ELECTROPROJ].workslike 36866
		  zshoot zdist ELECTROPROJ
		  ifvarand monstflags 8 zshoot zdist ELECTROPROJ
		  setprojectile[ELECTROPROJ].workslike 32770
	  } else
	  {
		  // will always shoot at player ?
	      shoot COOLEXPLOSION1
	      ifvarand monstflags 8 shoot COOLEXPLOSION1
      }
ends

state octashooting

ifvarn target -1 { state octashootbot break }

	ifvarand monstflags 64
	{
		eshoot FIREBALLPROJ
		ifvarand monstflags 8 
		{
			setthisprojectile[RETURN].pal 13
			setthisprojectile[RETURN].extra 64
		}
	} else
	ifvarand monstflags 32
	{
		sound SHRINKER_FIRE
		shoot SHRINKER
	} else
	  ifvarand monstflags 16 
	  {
		  shoot ELECTROPROJ
		  ifvarand monstflags 8 shoot ELECTROPROJ
	  } else
	  {
	      shoot COOLEXPLOSION1
	      ifvarand monstflags 8 shoot COOLEXPLOSION1
      }
ends

state octashootenemystate
ifvare target -1 ifvarn playerally 0 ai AIOCTAGETENEMY

  ifcount 25
  {
    ifcount 27
      ai AIOCTAGETENEMY
  }
  else
    ifcount 24
    {
	  state octashooting
    }
  else
    ifactioncount 6
      resetactioncount
ends

state checkoctahitstate
  ifwasweapon SHRINKSPARK
  {
    sound ACTOR_SHRINKING
    ai AIOCTASHRUNK
  }
  else
  {
    ifdead
    {
      ifwasweapon FREEZEBLAST
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action AOCTAFROZEN
        strength 0
        break
      }

      addkills 1 state specialdeath
      ifwasweapon RPG
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      else
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      else
        ifwasweapon GROWSPARK
      {
        cstat 0
        sound ACTOR_GROWING
        ai AIOCTAGROW
        break
      }
      else
      {
        state rf
        ai AIOCTADYING
      }
      sound OCTA_DYING
    }
    else
    {
      ifwasweapon RPG
      {
        sound OCTA_DYING
        addkills 1 state specialdeath
        state standard_jibs
        killit
      }
      else
        ifwasweapon GROWSPARK
          sound EXPANDERHIT

      sound OCTA_PAIN
      spawn BLOOD
      ifrnd 64
        ai AIOCTAHIT
    }
  }
  state random_wall_jibs
ends

state octashrunkstate
  ifcount SHRUNKDONECOUNT
    ai AILIZGETENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 40 40
  else
    state genericshrunkcode
ends


state octadyingstate
  ifactioncount 8
  {
    ifrnd 64
      spawn BLOODPOOL
    //move OCTASTOPPED
    action 0
    //action AOCTADEAD
    move 0
    cactor OCTABRAINCORPSE
    break
  }
  else
    ifactioncount 5 nullop
  else
    ifactioncount 4
      iffloordistl 8
        sound THUD
ends

actor OCTABRAINSTAYPUT OCTASTRENGTH
  ai AIOCTAGETENEMY
  cactor OCTABRAIN
enda

actor OCTABRAIN OCTASTRENGTH
  fall
  state monsterai
  state checksquished
  ifai 0
    ai AIOCTAGETENEMY
  else
    ifaction AOCTADEAD
  {
    strength 0
    ifcount RESPAWNACTORTIME
      ifrespawn
    {
      addkills -1
      setvar monstatus 0
      spawn TRANSPORTERSTAR
      cstat 257
      setvar monstatus 1
      strength OCTASTRENGTH
      ai AIOCTAGETENEMY
    }
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      state standard_jibs
      killit
    }
    break
  }
  else ifaction AOCTAFROZEN
  {
    ifcount THAWTIME
    {
      ai AIOCTAGETENEMY
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
      {
        ifactioncount 26
        {
          spawn WATERDRIP
          resetactioncount
        }
      }

    ifhitweapon
    {
      addkills 1 state specialdeath
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }

      lotsofglass 30
      ifrnd 84
        spawn BLOODPOOL
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick
    break
  }
  else
  {
    ifrnd 1
      soundonce OCTA_ROAM

    ifai AIOCTAGETENEMY
      state octagetenemystate
    else
      ifai AIOCTAHIT
      {
        ifcount 8
          ai AIOCTASHOOTENEMY
      }
    else
      ifai AIOCTADYING
      {
        state octadyingstate
        break
      }
    else
      ifai AIOCTASCRATCHENEMY
        state octascratchenemystate
    else
      ifai AIOCTASHOOTENEMY
        state octashootenemystate
    else
      ifai AIOCTASHRUNK
      {
        state octashrunkstate
        break
      }
    else
      ifai AIOCTAGROW
        state genericgrowcode

    ifmove OCTAUPVELS nullop
    else
    {  
	  setvar temp 0
	  ifvarn target -1
	  {
		  getactor[THISACTOR].z z
		  getactor[target].z mz
		  ifvarvarg z mz setvar temp 1
	  }
	  else
      ifp phigher setvar temp 1
      
      ifvare temp 1
        move OCTAUPVELS seekplayer
    }
    else
      ifmove OCTAINWATER nullop
      else
      {
        ifinwater
          move OCTAINWATER seekplayer else
        ifvarg underwater 0
          move OCTAINWATER seekplayer 
      }

    ifhitweapon
      state checkoctahitstate
  }
enda

action APIGWALK     0  4 5 1 20
action APIGRUN      0  4 5 1 11
action APIGSHOOT    30 2 5 1 58
action APIGCOCK     25 1 5 1 16
action APIGSTAND    30 1 5 1 1
//action APIGDIVE     40 2 5 1 40
action APIGDIVE     -5 2 5 1 40
action APIGDIVEWAIT -5 1 5 1 40
//action APIGDIVESHOOT  45 2 5 1 58
action APIGDIVESHOOT  0 2 5 1 58
action APIGDYING    55 5 1 1 15
action APIGHIT      55 1 1 1 10
action APIGDEAD     60 1 1 1 1
action APIGFROZEN    0 1 5
action APIGGROW      0


move PIGWALKVELS 32
move PIGRUNVELS 68
move PIGSTOPPED

ai AIPIGSEEKENEMY APIGWALK PIGWALKVELS seekplayer
ai AIPIGSHOOTENEMY APIGSHOOT PIGSTOPPED faceplayer
ai AIPIGFLEEENEMY APIGWALK PIGWALKVELS fleeenemy
ai AIPIGSHOOT APIGSHOOT PIGSTOPPED faceplayer
ai AIPIGDODGE APIGRUN PIGRUNVELS dodgebullet
ai AIPIGCHARGE APIGRUN PIGRUNVELS seekplayer
ai AIPIGDIVING APIGDIVE PIGSTOPPED faceplayer
ai AIPIGDYING APIGDYING PIGSTOPPED geth //faceplayer
ai AIPIGSHRINK APIGWALK SHRUNKVELS fleeenemy
ai AIPIGGROW APIGGROW PIGSTOPPED faceplayerslow
ai AIPIGHIT APIGHIT PIGSTOPPED faceplayer

state pigseekenemybot

  ifai AIPIGCHARGE
  {
	ifvarg peractor1 0 ifrnd 16
	{
		//ifcansee ifcanshoottarget
		//{
			ai AIPIGSHOOTENEMY
			break
		//}
	}
    ifvarl xydist 3084
    {
      ifnotmoving
        ai AIPIGSEEKENEMY
      else
      {
	    cactor PIGCOPDIVE
        ai AIPIGDIVING
      }
    }
    getactor[THISACTOR].ang angvar
    ifbulletnear
    {
	    setactor[THISACTOR].ang angvar
	    cactor PIGCOPDIVE
        ai AIPIGDIVING
    }
    break
  }
  else iffloordistl 32
  {
    ifvarg xydist 4096
    {
	  ifvarg peractor1 0 
	     ifrnd 64
	     {
	       ai AIPIGSHOOTENEMY 
         }
	       else
      ifactornotstayput
      ai AIPIGCHARGE
    }
    ifrnd 8
    {
      ifbulletnear
        ai AIPIGDODGE
    }
  }

  ifrnd 128
  {
    ifai AIPIGDODGE
    {
      ifcount 32
        ai AIPIGCHARGE
          break
    }
    iffloordistl 32
    {
      ifvarl xydist 1024
      {
        ai AIPIGSHOOTENEMY
        break
      }
      ifcount 48
      {
        ifrnd 8
        {
          ifrnd 192
            ai AIPIGSHOOTENEMY
          else
          {
	        cactor PIGCOPDIVE
            ai AIPIGDIVING
          }
          break
        }
      }
    }
  }
ends

state pigseekenemystate

  ifvarn target -1 { state pigseekenemybot break }

  ifai AIPIGCHARGE
  {
	ifvarn playerally 0 nullop else
	ifvarg peractor1 0 ifrnd 16
	{
		ifcansee //ifcanshoottarget
		{
			ai AIPIGSHOOTENEMY
			break
		}
	}
    ifcansee
      ifpdistl 3084
    {
      ifnotmoving
        ai AIPIGSEEKENEMY
      else
      {
	    cactor PIGCOPDIVE
        ai AIPIGDIVING
      }
    }
    getactor[THISACTOR].ang angvar
    ifbulletnear
    {
	    setactor[THISACTOR].ang angvar
	    cactor PIGCOPDIVE
        ai AIPIGDIVING
    }
    break
  }
  else iffloordistl 32
  {
    ifpdistg 4096
    {
	  ifvarg peractor1 0 
	   ifcansee 
	    //ifcanshoottarget 
	     ifrnd 64
	     {
		   ifvarn playerally 0 ai AIPIGCHARGE else
	       ai AIPIGSHOOTENEMY 
         }
	       else
      ifactornotstayput
      ai AIPIGCHARGE
    }
    ifrnd 8
    {
      ifbulletnear
        ai AIPIGDODGE
    }
  }

  ifrnd 128
    ifcansee
  {
    ifai AIPIGDODGE
    {
      ifcount 32
        ai AIPIGCHARGE
          break
    }
    iffloordistl 32
    {
      ifpdistl 1024
        ifp palive
          //ifcanshoottarget
      {
	    ifvarn playerally 0 ai AIPIGFLEEENEMY else
        ai AIPIGSHOOTENEMY
        break
      }
      ifcount 48
      {
        ifrnd 8
          ifp palive
            //ifcanshoottarget
        {
	      ifvarn playerally 0 break
          ifrnd 192
            ai AIPIGSHOOTENEMY
          else
          {
	        cactor PIGCOPDIVE
            ai AIPIGDIVING
          }
          break
        }
      }
    }
  }
ends

state pigshootbot

ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1
state calczdist

ifvarand monstflags 64
{
	setprojectile[RAILSLUG_WEAK].workslike 36866 //4097
	//shiftvarl zdist 8
	mulvar zdist 844
	divvarvar zdist xydist
	ifvarand monstflags 256 sound DBFIRE else
	sound SHOTTY2
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 30
	zshoot zdist RAILSLUG_WEAK
	zshoot zdist RAILSLUG_WEAK
	zshoot zdist RAILSLUG_WEAK
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 15
	ifpdistg 4096 ifrnd 128 shoot MORTER
	setprojectile[RAILSLUG_WEAK].workslike 32770 //1
}
else
ifvarand monstflags 32
{
	setprojectile[FIREBULLET].workslike 36870
	mulvar zdist 844
	divvarvar zdist xydist
	ifvarand monstflags 256 sound DBFIRE else
	sound PIG_ATTACK
	sound RPG_SHOOT
	zshoot zdist FIREBULLET
	zshoot zdist FIREBULLET
	zshoot zdist FIREBULLET
	zshoot zdist FIREBULLET
	ifvarand monstflags 8
	{
		zshoot zdist FIREBULLET
		zshoot zdist FIREBULLET
		zshoot zdist FIREBULLET
		zshoot zdist FIREBULLET
	}
	setprojectile[FIREBULLET].workslike 32774
}
else			
ifvarand monstflags 16
{
	setprojectile[STARPROJ].workslike 38914
	mulvar zdist 768
	divvarvar zdist xydist
	ifvarand monstflags 256 sound DBFIRE else
	sound PIG_ATTACK
	zshoot zdist STARPROJ
	zshoot zdist STARPROJ
	zshoot zdist STARPROJ
	zshoot zdist STARPROJ
	ifvarand monstflags 8
	{
		zshoot zdist STARPROJ
		zshoot zdist STARPROJ
		zshoot zdist STARPROJ
		zshoot zdist STARPROJ
	}
	setprojectile[STARPROJ].workslike 34818
}
else
{
	shiftvarl zdist 8
	divvarvar zdist xydist
	ifvarand monstflags 256 sound DBFIRE else
	sound PIG_ATTACK
	zshoot zdist SHOTGUN
	zshoot zdist SHOTGUN
	zshoot zdist SHOTGUN
	zshoot zdist SHOTGUN
	zshoot zdist SHOTGUN
	
	ifvarand monstflags 8 
	{
		zshoot zdist SHOTGUN
		zshoot zdist SHOTGUN
		zshoot zdist SHOTGUN
		zshoot zdist SHOTGUN
		zshoot zdist SHOTGUN
	}
}

ends

state pigshooting

ifvarn target -1 { state pigshootbot break }

getactor[THISACTOR].picnum picnum

ifvarand monstflags 64
{
	ifvarand monstflags 256 sound DBFIRE else
	sound SHOTTY2
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 30
	shoot RAILSLUG_WEAK
	shoot RAILSLUG_WEAK
	shoot RAILSLUG_WEAK
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 15
	ifpdistg 4096 ifrnd 128 shoot MORTER
	
}
else
ifvarand monstflags 32
{
	ifvarand monstflags 256 sound DBFIRE else
	sound PIG_ATTACK
	sound RPG_SHOOT
	shoot FIREBULLET
	shoot FIREBULLET
	shoot FIREBULLET
	shoot FIREBULLET
	ifvarand monstflags 8
	{
		shoot FIREBULLET
		shoot FIREBULLET
		shoot FIREBULLET
		shoot FIREBULLET
	}
}
else		
	
ifvarand monstflags 16
{
	ifvarand monstflags 256 sound DBFIRE else
	sound PIG_ATTACK
	shoot STARPROJ
	shoot STARPROJ
	shoot STARPROJ
	shoot STARPROJ
	ifvarand monstflags 8
	{
		shoot STARPROJ
		shoot STARPROJ
		shoot STARPROJ
		shoot STARPROJ
	}
}
else
{
	ifvarand monstflags 256 sound DBFIRE else
	sound PIG_ATTACK
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	shoot SHOTGUN
	
	ifvarand monstflags 8 
	{
		shoot SHOTGUN
		shoot SHOTGUN
		shoot SHOTGUN
		shoot SHOTGUN
		shoot SHOTGUN
	}
}

ends

state pigdbshooting

ifvare target -1 ifvarn playerally 0 { ai AIPIGSEEKENEMY break }
	
    ifcount 12 nullop
    else
      ifcount 11
    {
	  ifvarn target -1 {  state pigshooting state pigshooting state pigshooting } else
      //ifcanshoottarget
      ifcanseetarget
      {
	    state pigshooting
	    state pigshooting
	    state pigshooting
      }
      else
        ai AIPIGSEEKENEMY
    }
    ifcount 19 nullop
    else
      ifcount 18
      {
        action APIGCOCK
        sound DBOPEN
      }
    ifcount 35 nullop
    else
      ifcount 34
      {
        state shelleject2
        state shelleject2
        getactor[THISACTOR].ang angvar
	    ifbulletnear
	    {
		    setactor[THISACTOR].ang angvar
		    cactor PIGCOPDIVE
	        ai AIPIGDIVING
	    }
      }
    ifcount 43 nullop else ifcount 42 sound DBLOAD
    ifcount 55 nullop else ifcount 54 sound DBCLOSE
    
 
    ifcount 62
    {
      ifrnd 64
      {
        resetcount
        action APIGSHOOT
      }
      else
      {
        ifpdistl 768
          ai AIPIGFLEEENEMY
        else
          ai AIPIGSEEKENEMY
      }
    }

ends

state pigshootenemystate

ifvarand monstflags 256 { state pigdbshooting break }

ifcount 47 nullop else
ifvare target -1 ifvarn playerally 0 { ai AIPIGSEEKENEMY break }

//  ifcansee
//  {
	
    ifcount 12 nullop
    else
      ifcount 11
    {
	  ifvarn target -1 state pigshooting else
      //ifcanshoottarget
      ifcanseetarget
	    state pigshooting
	    
      else
        ai AIPIGSEEKENEMY
    }
    ifcount 25 nullop
    else
      ifcount 24
      {
        action APIGCOCK
        sound SHOTGUN_COCK
        state shelleject2
        getactor[THISACTOR].ang angvar
	    ifbulletnear
	    {
		    setactor[THISACTOR].ang angvar
		    cactor PIGCOPDIVE
	        ai AIPIGDIVING
	    }
      }
    ifcount 48 nullop
    else
      ifcount 47
    {
	  ifvarn target -1 state pigshooting else
      //ifcanshoottarget
      ifcanseetarget
        state pigshooting
      else
        ai AIPIGSEEKENEMY
    }
    ifcount 60 nullop
    else
      ifcount 59
      {
        action APIGCOCK
        sound SHOTGUN_COCK
        state shelleject2
        getactor[THISACTOR].ang angvar
	    ifbulletnear
	    {
		    setactor[THISACTOR].ang angvar
		    cactor PIGCOPDIVE
	        ai AIPIGDIVING
	    }
      }
    ifcount 72
    {
      ifrnd 64
        resetcount
      
      else
      {
        ifpdistl 768
          ai AIPIGFLEEENEMY
        else
          ai AIPIGSEEKENEMY
      }
    }
    ifaction APIGCOCK
      ifactioncount 2
        action APIGSHOOT
//  }
//  else
//    ai AIPIGSEEKENEMY
ends

state pigfleeenemystate
  ifactioncount 8
    ai AIPIGSEEKENEMY
  else
    ifnotmoving
      ai AIPIGSEEKENEMY
ends

state pigdivedb

ifaction APIGDIVESHOOT
  {
	ifvare target -1 ifvarn playerally 0 { cactor PIGCOP ai AIPIGSEEKENEMY break }
    //ifcansee
    //{
      ifcount 12 nullop
      else
        ifcount 11
      {
	    ifvarn target -1 { state pigshooting state pigshooting state pigshooting } else
        //ifcanshoottarget
        ifcanseetarget
        {
          state pigshooting
          state pigshooting
          state pigshooting
        }
        else
        {
	      cactor PIGCOP
          ai AIPIGSEEKENEMY
        }
      }
      ifcount 19 nullop
      else
        ifcount 18 sound DBOPEN
      ifcount 35 action APIGDIVESHOOT
      else
        ifcount 34
        {
          state shelleject2
          state shelleject2
        }
      ifcount 43 nullop else ifcount 42 sound DBLOAD
      ifcount 55 nullop else ifcount 54 sound DBCLOSE
      
      
      ifcount 62
      {
	      ifgapzl 32
	         ai AIPIGDIVING
	       else
	       {
		      cactor PIGCOP
	          ifpdistl 4096
	            ai AIPIGFLEEENEMY
	          else
	            ai AIPIGSEEKENEMY
	       }
       }
    //}
    ifcansee nullop else ifcount 10 nullop else ifgapzl 32 nullop else
    {
	    cactor PIGCOP
	    ai AIPIGSEEKENEMY
    }
    
  }
  else
    ifactioncount 2
    ifp palive
    {
      resetcount
      ifvare target -1 ifvarn playerally 0 { cactor PIGCOP ai AIPIGSEEKENEMY } else
      action APIGDIVESHOOT
    }

ends

state pigdivestate

ifvarand monstflags 256 { state pigdivedb break }

  ifaction APIGDIVESHOOT
  {
	ifvare target -1 ifvarn playerally 0 { cactor PIGCOP ai AIPIGSEEKENEMY break }
    ifcansee
    {
      ifcount 12 nullop
      else
        ifcount 11
      {
	    ifvarn target -1 state pigshooting else
        //ifcanshoottarget
        ifcanseetarget
          state pigshooting
 
        else
        {
	      cactor PIGCOP
          ai AIPIGSEEKENEMY
        }
      }
      ifcount 25 nullop
      else
        ifcount 24
        {
          sound SHOTGUN_COCK
          state shelleject2
        }
      ifcount 48 nullop
      else
        ifcount 47
      {
	    ifvarn target -1 state pigshooting else
        //ifcanshoottarget
        ifcanseetarget
          state pigshooting
        else
        {
	      cactor PIGCOP
          ai AIPIGSEEKENEMY
        }
      }
      ifcount 60 nullop
      else
        ifcount 59
      {
        sound SHOTGUN_COCK
        state shelleject2
        ifgapzl 32
          ai AIPIGDIVING
        else
        {
	      cactor PIGCOP
          ifpdistl 4096
            ai AIPIGFLEEENEMY
          else
            ai AIPIGSEEKENEMY
        }
      }
    }
    else
      ifgapzl 32
        ai AIPIGDIVING
      else
      {
	    cactor PIGCOP
        ai AIPIGSEEKENEMY
      }
  }
  else
    ifactioncount 2
    ifp palive
    {
      resetcount
      ifvare target -1 ifvarn playerally 0 { cactor PIGCOP ai AIPIGSEEKENEMY } else
      action APIGDIVESHOOT
    }
ends

state checkpighitstate
  spawn BLOOD
  ifdead
  {
	cactor PIGCOP
    state random_wall_jibs
    
    ifwasweapon GROWSPARK
    {
      sound ACTOR_GROWING
      ai AIPIGGROW
      break
    }

    ifwasweapon FREEZEBLAST
    {
      sound SOMETHINGFROZE
      spritepal 1
      move 0
      action APIGFROZEN
      strength 0
      break
    }
    ifrnd 16
      spawn SHIELD
    else
      state drop_shotgun
    addkills 1 state specialdeath
    ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    else
      ifwasweapon RPG
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    else
      ai AIPIGDYING
        sound PIG_DYING
  }
  else
  {
    sound PIG_PAIN
    state random_wall_jibs

    ifwasweapon SHRINKSPARK
    {
	  cactor PIGCOP
      sound ACTOR_SHRINKING
      ai AIPIGSHRINK
    }
    else
      ifwasweapon GROWSPARK
        sound EXPANDERHIT
    else
      ifrnd 32
      {
	    cactor PIGCOP
        ai AIPIGHIT
      }
      else ifwasweapon KNEE ifvarn superkicking 0
       {
	     cactor PIGCOP
	     ai AIPIGHIT
       }
    else
      ifrnd 64
      {
	    cactor PIGCOP
        ai AIPIGSHOOTENEMY
      }
    else
      ifrnd 64
      {
	    cactor PIGCOPDIVE
        ai AIPIGDIVING
        action APIGDIVESHOOT
      }
  }
ends

state pigshrinkstate
  ifcount SHRUNKDONECOUNT
    ai AIPIGSEEKENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 48 40
  else
    state genericshrunkcode
ends

state pigdyingstate
  ifactioncount 5
  {
    ifrnd 64
      spawn BLOODPOOL
    state rf
    iffloordistl 8
      sound THUD
    //action APIGDEAD
    action 0
    //move PIGSTOPPED
    move 0
    cactor PIGCOPCORPSE
    break
  }
ends


state pigcopcode
state monsterai
  fall
  state checksquished
  ifaction APIGSTAND
    ai AIPIGSEEKENEMY
  else
    ifaction APIGDEAD
  {
    ifrespawn
      ifcount RESPAWNACTORTIME
    {
      spawn TRANSPORTERSTAR
      cstat 257
      setvar monstatus 1
      strength PIGCOPSTRENGTH
      ai AIPIGSEEKENEMY
    }
    else
    {
      strength 0
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      break
    }
  }
  else
    ifaction APIGFROZEN
  {
    ifcount THAWTIME
    {
      ai AIPIGSEEKENEMY
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
        ifrnd 8
          spawn WATERDRIP
    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1 state specialdeath
      ifrnd 16
      spawn SHIELD
      else
      state drop_shotgun
      lotsofglass 30
      ifrnd 84 spawn BLOODPOOL
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick
    break
  }
  else
    ifai AIPIGDYING
      state pigdyingstate
  else
    ifai AIPIGHIT
    {
      ifactioncount 3
      ai AIPIGSEEKENEMY
    }
  else
    ifai AIPIGSHRINK
      state pigshrinkstate
  else
  {
    ifai AIPIGSEEKENEMY
      state pigseekenemystate
    else
      ifai AIPIGDODGE
        state pigseekenemystate
    else
      ifai AIPIGSHOOTENEMY
        state pigshootenemystate
    else
      ifai AIPIGGROW
        state genericgrowcode
    else
      ifai AIPIGFLEEENEMY
        state pigfleeenemystate
    else
      ifai AIPIGDIVING
        state pigdivestate
    else
      ifai AIPIGCHARGE
        state pigseekenemystate
    ifhitweapon
      state checkpighitstate
    ifrnd 1
    {
      ifrnd 32
        soundonce PIG_ROAM
      else
        ifrnd 64
          soundonce PIG_ROAM2
      else
        soundonce PIG_ROAM3
    }
  }
ends

actor PIGCOPDIVE PIGCOPSTRENGTH
ifai 0 ai AIPIGDIVING
state pigcopcode
enda
actor PIGCOPSTAYPUT PIGCOPSTRENGTH
  ai AIPIGSEEKENEMY
  cactor PIGCOP
enda
actor PIGCOP PIGCOPSTRENGTH APIGSTAND
state pigcopcode
enda



action ABOSS1STAND       0  1  5  1  10
action ABOSS1WALK        0  4  5  1  12
action ABOSS1FROZEN        30 1  5
action ABOSS1RUN         0  6  5  1  5
action ABOSS1SHOOT         30 2  5  1  4
action ABOSS1LOB         40 2  5  1  35
action ABOSS1DYING        50 5  1  1  35
action BOSS1FLINTCH       50 1  1  1  1
action ABOSS1DEAD         55

move PALBOSS1SHRUNKRUNVELS 32
move PALBOSS1RUNVELS 128
move BOSS1WALKVELS 208
move BOSS1RUNVELS 296
move BOSS1STOPPED

ai AIBOSS1WAIT ABOSS1STAND BOSS1STOPPED geth
ai AIBOSS1SEEKENEMY ABOSS1WALK BOSS1WALKVELS seekplayer
ai AIBOSS1RUNENEMY ABOSS1RUN BOSS1RUNVELS faceplayer
ai AIBOSS1SHOOTENEMY ABOSS1SHOOT BOSS1STOPPED faceplayer
ai AIBOSS1LOBBED ABOSS1LOB BOSS1STOPPED faceplayer
ai AIBOSS1DYING ABOSS1DYING BOSS1STOPPED geth // faceplayer
ai AIBOSS1PALSHRINK ABOSS1WALK PALBOSS1SHRUNKRUNVELS furthestdir

state boss1wait // only used by allied BOSS1

setactor[THISACTOR].mdflags 2
ifvarn target -1 { setactor[THISACTOR].mdflags 0 ai AIBOSS1SHOOTENEMY break }

ifpdistg 1560
ifactioncount 2 
{
	setactor[THISACTOR].mdflags 0
	ai AIBOSS1SEEKENEMY
}

ends

state boss1palshrunkstate
  ifcount SHRUNKDONECOUNT
  {
    ai AIBOSS1SEEKENEMY
    cstat 257
  }
  else
    ifcount SHRUNKCOUNT
      sizeto 40 40
  else
    state genericshrunkcode
ends

state checkboss1seekstate
  ai AIBOSS1SEEKENEMY
  ifspritepal 0 nullop
    else   // a fake way of doing a ifspritepal NOT.
      move PALBOSS1RUNVELS seekplayer
ends

state boss1runbotstate


  ifvarl xydist 2048
  {
      ai AIBOSS1SHOOTENEMY
    break
  }
  else
    ifactioncount 6
    {
        resetactioncount
        sound BOS1_WALK
    }
  
  ifcount 130 ifvarg xydist 6144
    ai AIBOSS1SEEKENEMY
ends

state boss1runenemystate

ifvarn target -1 { state boss1runbotstate break }

  ifpdistl 2048
  {
	ifvarn playerally 0 ai AIBOSS1WAIT else
    ifp palive
      ai AIBOSS1SHOOTENEMY
    break
  }
  else
    ifcansee
  {
    ifactioncount 6
    {
      ifcanshoottarget
      {
        resetactioncount
        sound BOS1_WALK
      }
      else
        ai AIBOSS1SEEKENEMY
    }
  }
  else
    ai AIBOSS1SEEKENEMY
ends

state boss1seekbotstate

  ifrnd 2
    soundonce BOS1_ROAM
  else
    ifactioncount 6
  {
    resetactioncount
    sound BOS1_WALK
  }

  ifvarl xydist 2548
  {
    ai AIBOSS1SHOOTENEMY
    break
  }

    ifcount 32
  {
    ifrnd 32
    {
          ai AIBOSS1SHOOTENEMY
    }
    else
      ifvarg xydist 2548
        ifrnd 192
    {
      ifrnd 64
      {
        ai AIBOSS1RUNENEMY
        ifspritepal 0 nullop
        else
          move PALBOSS1RUNVELS seekplayer
      }
      else
        ai AIBOSS1LOBBED
    }
  }

ends

state boss1seekenemystate

ifvarn target -1 { state boss1seekbotstate break }

  ifrnd 2
    soundonce BOS1_ROAM
  else
    ifactioncount 6
  {
    resetactioncount
    sound BOS1_WALK
  }

  ifpdistl 2548
    ifp palive
  {
	ifvarn playerally 0 ai AIBOSS1WAIT else
    ai AIBOSS1SHOOTENEMY
    break
  }

  ifcansee
    ifcount 32
  {
    ifrnd 32
    {
	  ifvarn playerally 0 nullop else
      ifp palive
        ifcanshoottarget
          ai AIBOSS1SHOOTENEMY
    }
    else
      ifpdistg 2548
        ifrnd 192
          ifcanshoottarget
    {
      ifrnd 64
      {
        ai AIBOSS1RUNENEMY
        ifspritepal 0 nullop
        else
          move PALBOSS1RUNVELS seekplayer
      }
      else ifvare playerally 0
        ai AIBOSS1LOBBED
    }
  }

ends

state boss1dyingstate
  ifaction ABOSS1DEAD
  {
    ifspritepal 0
      break
    ifrespawn
      ifcount RESPAWNACTORTIME
    {
      spawn TRANSPORTERSTAR
      cstat 257
      setvar monstatus 1
      strength PIGCOPSTRENGTH
      state checkboss1seekstate
    }
    else
    {
      strength 0
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      break
    }
  }
  ifactioncount 5
  {
    iffloordistl 8
      sound THUD
    //action ABOSS1DEAD
    cstat 0
    ifspritepal 0
    endofgame 52
    action 0
    move 0
    cactor BOSS1CORPSE
  }
ends

state boss1lobbedstate
ifvare target -1 ifvarn playerally 0 { state checkboss1seekstate break }
  ifcansee
  {
    ifactioncount 2
    {
      resetactioncount
      sound BOS1_ATTACK2
      shoot MORTER
      ifvarand monstflags 8 
	  shoot MORTER

    }
    else
      ifcount 64
        ifrnd 16
          state checkboss1seekstate
  }
  else
    state checkboss1seekstate
ends

state boss1shootbot

state calczdist

ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1

ifvarand monstflags 64
{
	//shiftvarl zdist 8
	mulvar zdist 844
	divvarvar zdist xydist
	sound SHOTTY2
	setprojectile[RAILSLUG_WEAK].workslike 36866 //4097
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 30
	zshoot zdist RAILSLUG_WEAK
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 15
	setprojectile[RAILSLUG_WEAK].workslike 32770 //1
} else
ifvarand monstflags 32
{
	mulvar zdist 844
	divvarvar zdist xydist
	sound RPG_SHOOT
	setprojectile[FIREBULLET].workslike 36870
	zshoot zdist FIREBULLET
	zshoot zdist FIREBULLET
	ifvarand monstflags 8
	{
		zshoot zdist FIREBULLET
		zshoot zdist FIREBULLET
	}
	setprojectile[FIREBULLET].workslike 32774
}
ifvarand monstflags 16
{
	mulvar zdist 768
	divvarvar zdist xydist
	sound PISTOL_LOW
	setprojectile[STARPROJ].workslike 38914
	zshoot zdist STARPROJ
	zshoot zdist STARPROJ
	ifvarand monstflags 8
	{
		zshoot zdist STARPROJ
		zshoot zdist STARPROJ
	}
	setprojectile[STARPROJ].workslike 34818
}
else
{
	shiftvarl zdist 8
	divvarvar zdist xydist
	sound BOS1_ATTACK1
	cactor PIGCOP // to prevent hardcoded auto-aiming at player
	zshoot zdist SHOTSPARK1
	zshoot zdist SHOTSPARK1
	zshoot zdist SHOTSPARK1
	zshoot zdist SHOTSPARK1
	ifspritepal 0
	{
	zshoot zdist SHOTSPARK1
	zshoot zdist SHOTSPARK1
	}
	
	ifvarand monstflags 8 
	{
	    zshoot zdist SHOTSPARK1
	    zshoot zdist SHOTSPARK1
	    zshoot zdist SHOTSPARK1
	    zshoot zdist SHOTSPARK1
	    ifspritepal 0
	    {
	    zshoot zdist SHOTSPARK1
	    zshoot zdist SHOTSPARK1
    	}
	}
	cactor BOSS1
}
state shelleject
state shelleject
resetactioncount

ends

state boss1shooting

ifvarn target -1 { state boss1shootbot break }
ifvarn playerally 0 { state checkboss1seekstate break }


ifvarand monstflags 64
{
	sound SHOTTY2
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 30
	shoot RAILSLUG_WEAK
	ifvarand monstflags 8 setprojectile[RAILSLUG_WEAK].extra 15
} else
ifvarand monstflags 32
{
	sound RPG_SHOOT
	shoot FIREBULLET
	shoot FIREBULLET
	ifvarand monstflags 8
	{
		shoot FIREBULLET
		shoot FIREBULLET
	}
}
ifvarand monstflags 16
{
	sound PISTOL_LOW
	shoot STARPROJ
	shoot STARPROJ
	ifvarand monstflags 8
	{
		shoot STARPROJ
		shoot STARPROJ
	}
}
else
{
	sound BOS1_ATTACK1
	shoot SHOTSPARK1
	shoot SHOTSPARK1
	shoot SHOTSPARK1
	shoot SHOTSPARK1
	ifspritepal 0
	{
	shoot SHOTSPARK1
	shoot SHOTSPARK1
	}
	
	ifvarand monstflags 8 
	{
	    shoot SHOTSPARK1
	    shoot SHOTSPARK1
	    shoot SHOTSPARK1
	    shoot SHOTSPARK1
	    ifspritepal 0
	    {
	    shoot SHOTSPARK1
	    shoot SHOTSPARK1
    	}
	}
}
state shelleject
state shelleject
resetactioncount

ends

state boss1shootenemy
  ifcount 72
    state checkboss1seekstate
  else
    ifaction ABOSS1SHOOT
      ifactioncount 2
  {
	state boss1shooting
  }
ends

state checkboss1hitstate
  ifrnd 2
    spawn BLOODPOOL
  ifdead
  {
    ifspritepal 0
      globalsound DUKE_TALKTOBOSSFALL
    else
    {
      ifrnd 64
        globalsound DUKE_TALKTOBOSSFALL
      ifwasweapon FREEZEBLAST
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action ABOSS1FROZEN
        strength 0
        break
      }
    }

    sound BOS1_DYING

    addkills 1 state specialdeath
    ai AIBOSS1DYING
  }
  else
  {
    ifrnd 32
    {
      action BOSS1FLINTCH
      move 0
    }

    ifspritepal 0 nullop
    else
      ifwasweapon SHRINKSPARK
    {
      sound ACTOR_SHRINKING
      ai AIBOSS1PALSHRINK
      cstat 0
      break
    }

    soundonce BOS1_PAIN

    debris SCRAP1 1
    guts JIBS6 1
  }
ends

state boss1code
state monsterai
  ifaction ABOSS1FROZEN
  {
    ifcount THAWTIME
    {
      ai AIBOSS1SEEKENEMY
      spritepal 21
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1 state specialdeath
      lotsofglass 30

      ifrnd 84
        spawn BLOODPOOL
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick
    break
  }
  ifai 0
  {
    ifspritepal 0
      ai AIBOSS1RUNENEMY
    else
    {
	  cstator 257
      strength BOSS1PALSTRENGTH
      ai AIBOSS1SHOOTENEMY
      getactor[THISACTOR].extra hp
	  // this was already done in monsterai, but has to be done again for pal bosses	
	  ifvarand monstflags 2 mulvar hp 2
	  ifvarand monstflags 4 mulvar hp 4
	  ifvarg hp 32767 setvar hp 32767
	  setactor[THISACTOR].extra hp	
		
    }
  }
  else
    ifaction BOSS1FLINTCH
  {
    ifactioncount 3
    ai AIBOSS1SHOOTENEMY
  }
  else
    ifai AIBOSS1SEEKENEMY
      state boss1seekenemystate
  else
    ifai AIBOSS1RUNENEMY
      state boss1runenemystate
  else
    ifai AIBOSS1SHOOTENEMY
    state boss1shootenemy
  else
    ifai AIBOSS1LOBBED
      state boss1lobbedstate
  else
    ifai AIBOSS1PALSHRINK
      state boss1palshrunkstate
  else
    ifai AIBOSS1WAIT
      state boss1wait

  ifai AIBOSS1DYING
    state boss1dyingstate
  else
  {
    ifhitweapon
      state checkboss1hitstate
    else
      ifp palive
      {
		  ifspritepal 0        
		  {
			  ifpdistl 1280 ifvare playerally 0
			  {
			      addphealth -1000
			      palfrom 63 63
		      }
		      ifvarn target -1 ifvarl xydist 1280
		      {
			      setactor[target].htextra 100
			      setactor[target].htpicnum KNEE
			      setactor[target].htowner THISACTOR
		      }
		  }
		  else
		  {
			  ifvarn target -1 ifvarl xydist 768
			  {
				  setactor[target].htextra 2
			      setactor[target].htpicnum KNEE
			      setactor[target].htowner THISACTOR
			  }
		  }
	  }
  }
ends

actor BOSS1STAYPUT BOSS1STRENGTH cactor BOSS1 enda
actor BOSS1 BOSS1STRENGTH fall state boss1code enda


action ABOSS2WALK        0  4  5  1  30
action ABOSS2FROZEN        0  1  5
action ABOSS2RUN         0  4  5  1  15
action ABOSS2SHOOT         20 2  5  1  15
action ABOSS2LOB         30 2  5  1  105
action ABOSS2DYING        40 8  1  1  35
action BOSS2FLINTCH       40 1  1  1  1
action ABOSS2DEAD         48

move PALBOSS2SHRUNKRUNVELS 32
move PALBOSS2RUNVELS 256
move BOSS2WALKVELS 192
move BOSS2RUNVELS 256
move BOSS2STOPPED

ai AIBOSS2SEEKENEMY ABOSS2WALK BOSS2WALKVELS seekplayer
ai AIBOSS2RUNENEMY ABOSS2RUN BOSS2RUNVELS faceplayerslow
ai AIBOSS2SHOOTENEMY ABOSS2SHOOT BOSS2STOPPED faceplayersmart
ai AIBOSS2LOBBED ABOSS2LOB BOSS2STOPPED faceplayer
ai AIBOSS2DYING ABOSS2DYING BOSS2STOPPED geth // faceplayer
ai AIBOSS2PALSHRINK ABOSS2WALK PALBOSS2SHRUNKRUNVELS furthestdir

state boss2palshrunkstate
  ifcount SHRUNKDONECOUNT
  {
    cstat 257
    ai AIBOSS2SEEKENEMY
  }
  else
    ifcount SHRUNKCOUNT
      sizeto 40 40
  else
    state genericshrunkcode
ends

state checkboss2seekstate
  ai AIBOSS2SEEKENEMY
  // ifspritepal 0 nullop
  //else   // a fake way of doing a ifspritepal NOT.
  //  move PALBOSS2RUNVELS seekplayer
ends

state boss2runbotstate

    ifactioncount 3
    {
        resetactioncount
        sound BOS1_WALK
    }
    ifcount 48
      ifrnd 2
    {
        sound BOS2_ATTACK
        ai AIBOSS2SHOOTENEMY
      break
    }
  
ends

state boss2runenemystate

ifvarn target -1 { state boss2runbotstate break }

  ifcansee
  {
    ifactioncount 3
    {
      ifcanshoottarget
      {
        resetactioncount
        sound BOS1_WALK
      }
      else
        ai AIBOSS2SEEKENEMY
    }
    ifvarn playerally 0 nullop else
    ifcount 48
      ifrnd 2
    {
      ifp palive
      {
        sound BOS2_ATTACK
        ai AIBOSS2SHOOTENEMY
      }
      break
    }
  }
  else
    ai AIBOSS2SEEKENEMY
ends

state boss2seekbotstate

  ifrnd 2
    soundonce BOS2_ROAM
  else
    ifactioncount 3
  {
    resetactioncount
    sound BOS1_WALK
  }

 
    ifcount 32
        ifrnd 48
  {
    ifrnd 64
      ifvarg xydist 4096
    {
      ai AIBOSS2RUNENEMY
      // ifspritepal 0 nullop
      // else
      //  move PALBOSS2RUNVELS seekplayer
      break
    }

    ifvarl xydist 10240
    {
      ifrnd 128
      {
        sound BOS2_ATTACK
        ai AIBOSS2LOBBED
      }
    }
    else
    {
      sound BOS2_ATTACK
      ai AIBOSS2SHOOTENEMY
    }
  }
ends

state boss2seekenemystate

ifvarn target -1 { state boss2seekbotstate break }

  ifrnd 2
    soundonce BOS2_ROAM
  else
    ifactioncount 3
  {
    resetactioncount
    sound BOS1_WALK
  }

  ifcansee
    ifcount 32
      ifp palive
        ifrnd 48
          ifcanshoottarget
  {
    ifrnd 64
      ifpdistg 4096
    {
      ai AIBOSS2RUNENEMY
      // ifspritepal 0 nullop
      // else
      //  move PALBOSS2RUNVELS seekplayer
      break
    }
	ifvarn playerally 0 break
    ifpdistl 10240
    {
      ifrnd 128
      {
        sound BOS2_ATTACK
        ai AIBOSS2LOBBED
      }
    }
    else
    {
      sound BOS2_ATTACK
      ai AIBOSS2SHOOTENEMY
    }
  }
ends

state boss2dyingstate
  ifaction ABOSS2DEAD
  {
    ifspritepal 0
      break
    ifrespawn
      ifcount RESPAWNACTORTIME
    {
      spawn TRANSPORTERSTAR
      cstat 257
      setvar monstatus 1
      strength PIGCOPSTRENGTH
      state checkboss2seekstate
    }
    else
    {
      strength 0
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        state standard_jibs
        killit
      }
      break
    }
  }
  ifactioncount 8
  {
    iffloordistl 8
      sound THUD
    //action ABOSS2DEAD
    action 0
    cstat 0
    ifspritepal 0
      endofgame 52
    move 0
    cactor BOSS2CORPSE
  }
ends

state boss2lobbingbot
state calczdist
ifspritepal 0 addvar zdist 10240 // else addvar zdist 6144
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1
cactor LIZTROOP // avoids hardcoded auto-aim at player

	ifvarand monstflags 16
	{
      sound BLASTERSND
	  mulvar zdist 768
	  divvarvar zdist xydist
	  zshoot zdist FIRELASER
	  ifvarand monstflags 8 zshoot zdist FIRELASER
    } else
	ifrnd 128
    {
	  mulvar zdist 768
	  divvarvar zdist xydist
      zshoot zdist COOLEXPLOSION1
      ifvarand monstflags 8 zshoot zdist COOLEXPLOSION1
    }
cactor BOSS2
ends

state boss2lobbing

ifvarn target -1 { state boss2lobbingbot break }

	ifvarand monstflags 16
	{
	  sound BLASTERSND
	  shoot FIRELASER
	  ifvarand monstflags 8 shoot FIRELASER
    } else
	ifrnd 128
    {
      shoot COOLEXPLOSION1
      ifvarand monstflags 8 shoot COOLEXPLOSION1
    }

ends

state boss2shootbot
state calczdist
ifspritepal 0 addvar zdist 12288 else addvar zdist 8192
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1
cactor LIZTROOP // avoids hardcoded auto-aim at player

ifvarand monstflags 16
{
	sound BLASTERSND
	mulvar zdist 768
	divvarvar zdist xydist
	zshoot zdist FIRELASER
	zshoot zdist FIRELASER
	zshoot zdist FIRELASER
	ifvarand monstflags 8
	{
		zshoot zdist FIRELASER
		zshoot zdist FIRELASER
		zshoot zdist FIRELASER
	}
// 	sound BLASTERSND
// 	eshoot FIREBALLPROJ 
// 	ifvarand monstflags 8 
// 	{
// 		setthisprojectile[RETURN].pal 13
// 		setthisprojectile[RETURN].extra 64
// 	}
} 
else
{
	mulvar zdist 644
	divvarvar zdist xydist
	ezshoot zdist RPGNOAIM
	ifspritepal 0 nullop else
	{
		getactor[RETURN].extra temp
		divvar temp 2
		setactor[RETURN].extra temp
	}
	ifvarand monstflags 8 shoot MORTER
}
	cactor BOSS2
    resetactioncount

ends

state boss2shooting
ifvarn target -1 { state boss2shootbot break }

ifvarand monstflags 16
{
	sound BLASTERSND
	shoot FIRELASER
	shoot FIRELASER
	shoot FIRELASER
	ifvarand monstflags 8
	{
		shoot FIRELASER
		shoot FIRELASER
		shoot FIRELASER
	}
// 	eshoot FIREBALLPROJ 
// 	ifvarand monstflags 8 
// 	{
// 		setthisprojectile[RETURN].pal 13
// 		setthisprojectile[RETURN].extra 64
// 	}
} 
else
{
	shoot RPG
	ifvarand monstflags 8 shoot MORTER
}
	
    resetactioncount

ends

state boss2lobbedstate

ifvare target -1 ifvarn playerally 0 { state checkboss2seekstate break }

  ifcansee
  {
    ifactioncount 2
      resetactioncount
    else
      ifactioncount 1
    {
      state boss2lobbing
    }
    else
      ifcount 64
        ifrnd 16
          state checkboss2seekstate
  }
  else
    state checkboss2seekstate
ends

state boss2shootenemy

ifvare target -1 ifvarn playerally 0 { state checkboss2seekstate break }

  ifcount 72
    state checkboss2seekstate
  else
    ifaction ABOSS2SHOOT
      ifactioncount 2
  {
	state boss2shooting
  }
ends

state checkboss2hitstate
  ifrnd 2
    spawn BLOODPOOL
  ifdead
  {
    ifspritepal 0
      globalsound DUKE_TALKTOBOSSFALL
    else
    {
      ifrnd 64
        globalsound DUKE_TALKTOBOSSFALL
      ifwasweapon FREEZEBLAST
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action ABOSS2FROZEN
        strength 0
        break
      }
    }

    sound BOS2_DYING

    addkills 1 state specialdeath

    ai AIBOSS2DYING
  }
  else
  {
    ifrnd 144
    {
      ifrnd 32
      {
        action BOSS2FLINTCH
        move 0
      }
      else
      {
        sound BOS2_ATTACK
        ai AIBOSS2SHOOTENEMY
      }
    }

    ifspritepal 0 nullop
    else
      ifwasweapon SHRINKSPARK
    {
      sound ACTOR_SHRINKING
      ai AIBOSS2PALSHRINK
      break
    }

    soundonce BOS2_PAIN

    debris SCRAP1 1
    guts JIBS6 1
  }
ends

state boss2code
state monsterai
  ifaction ABOSS2FROZEN
  {
    ifcount THAWTIME
    {
      ai AIBOSS2SEEKENEMY
        spritepal 21
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1 state specialdeath

      lotsofglass 60
      sound GLASS_BREAKING
      ifrnd 84 spawn BLOODPOOL
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick
    break
  }
  ifai 0
  {
    ifspritepal 0
      ai AIBOSS2RUNENEMY
    else
    {
	  cstator 257
	  clipdist 32
	  sizeat 40 40
      strength BOSS1PALSTRENGTH
      sound BOS2_ATTACK ai AIBOSS2SHOOTENEMY
      getactor[THISACTOR].extra hp
	  // this was already done in monsterai, but has to be done again for pal bosses
	  ifvarand monstflags 2 mulvar hp 2
	  ifvarand monstflags 4 mulvar hp 4
	  ifvarg hp 32767 setvar hp 32767
	  setactor[THISACTOR].extra hp	
    }
  }
  else
    ifaction BOSS2FLINTCH
  {
    ifactioncount 3
      ai AIBOSS2SEEKENEMY
  }
  else
    ifai AIBOSS2SEEKENEMY
      state boss2seekenemystate
  else
    ifai AIBOSS2RUNENEMY
      state boss2runenemystate
  else
    ifai AIBOSS2SHOOTENEMY
      state boss2shootenemy
  else
    ifai AIBOSS2LOBBED
      state boss2lobbedstate
  else
    ifai AIBOSS2PALSHRINK
      state boss2palshrunkstate

  ifai AIBOSS2DYING
    state boss2dyingstate
  else
  {
    ifhitweapon state checkboss2hitstate
    else
    {
	  ifvarn target -1
	  {
		 ifspritepal 0
		 {
			 ifvarl xydist 1280
			 {
				 setactor[target].htextra 100
				 setactor[target].htpicnum KNEE
				 setactor[target].htowner THISACTOR
			 }
		 }
		 else ifvarl xydist 844
		 {
			 ifai AIBOSS2PALSHRINK nullop else
			 {
				 setactor[target].htextra 2
				 setactor[target].htpicnum KNEE
				 setactor[target].htowner THISACTOR
			 }
		 }
	  }
      ifp palive ifcansee
      {
	     ifspritepal 0 
	     {
		    ifpdistl 1280 ifvare playerally 0
		    {
		      addphealth -1000
		      palfrom 63 63
		    }
	    }
	    else ifpdistl 844
	    {
		    ifai AIBOSS2PALSHRINK nullop else
		    ifvare playerally 0
		    {
			    addphealth -1
			    ifvarand monstflags 8 addphealth -1
			    palfrom 30 63
		    }
	    }
      }
    }
  }


ends

actor BOSS2 BOSS2STRENGTH fall state boss2code enda

action ABOSS3WALK        0  4  5  1  30
action ABOSS3FROZEN        0  1  5
action ABOSS3RUN         0  4  5  1  15
action ABOSS3LOB        20 4  5  1  50
action ABOSS3LOBBING      30 2  5  1  15
action ABOSS3DYING        40 8  1  1  20
action BOSS3FLINTCH       40 1  1  1  1
action ABOSS3DEAD         48

move PALBOSS3SHRUNKRUNVELS 32
move PALBOSS3RUNVELS 208 //84
move BOSS3WALKVELS 208
move BOSS3RUNVELS 270
move BOSS3STOPPED

ai AIBOSS3SEEKENEMY ABOSS3WALK BOSS3WALKVELS seekplayer
ai AIBOSS3RUNENEMY ABOSS3RUN BOSS3RUNVELS faceplayerslow
ai AIBOSS3LOBENEMY ABOSS3LOB BOSS3STOPPED faceplayer
ai AIBOSS3DYING ABOSS3DYING BOSS3STOPPED geth // faceplayer
ai AIBOSS3PALSHRINK ABOSS3WALK PALBOSS3SHRUNKRUNVELS furthestdir

state boss3palshrunkstate
  ifcount SHRUNKDONECOUNT
    ai AIBOSS3SEEKENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 40 40
  else
    state genericshrunkcode
ends

state checkboss3seekstate
  ai AIBOSS3SEEKENEMY
  ifspritepal 0 nullop
  else   // a fake way of doing a ifspritepal NOT.
    move PALBOSS3RUNVELS seekplayer
ends

state boss3runenemystate


  ifcansee
  {
    ifactioncount 3
    {
      ifcanshoottarget
      {
        resetactioncount
        sound BOS1_WALK
      }
      else
        ai AIBOSS3SEEKENEMY
    }
  }
  else
    ai AIBOSS3SEEKENEMY
ends

state boss3seekbotstate

  ifrnd 2
    soundonce BOS3_ROAM
  else
    ifactioncount 3
    {
      resetactioncount
      sound BOS1_WALK
    }

 
    ifcount 32
      ifrnd 48
  {
    ifrnd 64
      ifvarg xydist 4096
      {
        ai AIBOSS3RUNENEMY
        ifspritepal 0
          break
        move PALBOSS3RUNVELS seekplayer
        break
      }

      ai AIBOSS3LOBENEMY
  }
ends

state boss3seekenemystate

ifvarn target -1 { state boss3seekbotstate break }

  ifrnd 2
    soundonce BOS3_ROAM
  else
    ifactioncount 3
    {
      resetactioncount
      sound BOS1_WALK
    }

  ifcansee
    ifcount 32
      ifrnd 48
        ifcanshoottarget
  {
    ifrnd 64
      ifpdistg 4096
      {
        ai AIBOSS3RUNENEMY
        ifspritepal 0
          break
        move PALBOSS3RUNVELS seekplayer
        break
      }

    ifp palive
    {
	  ifvare playerally 0
	  {
        ai AIBOSS3LOBENEMY
        break
        
      }
      ai AIBOSS3RUNENEMY
        ifspritepal 0
          break
        move PALBOSS3RUNVELS seekplayer
      
    }
  }
ends

state boss3dyingstate
  ifaction ABOSS3DEAD
  {
    ifspritepal 0
      break
    ifrespawn
      ifcount RESPAWNACTORTIME
    {
      spawn TRANSPORTERSTAR
      cstat 257
      setvar monstatus 1
      strength PIGCOPSTRENGTH
      state checkboss3seekstate
    }
    else
    {
      strength 0
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        state standard_jibs
        killit
      }
      break
    }
  }
  ifactioncount 8
  {
    iffloordistl 8
      sound THUD
    //action ABOSS3DEAD
    action 0
    cstat 0
    ifspritepal 0
    endofgame 52
    move 0
    cactor BOSS3CORPSE
  }
ends

state boss3lobbingbot

state calczdist
ifspritepal 0 addvar zdist 12288 else addvar zdist 8192
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1

ifvarand monstflags 32
{
	mulvar zdist 768
	divvarvar zdist xydist
	setprojectile[ELECTROPROJ].workslike 36866
	zshoot zdist ELECTROPROJ
	ifvarand monstflags 8 zshoot zdist ELECTROPROJ
	setprojectile[ELECTROPROJ].workslike 32770
} else
ifvarand monstflags 16
{
	eshoot FIREBALLPROJ 
	ifvarand monstflags 8 
	{
		setthisprojectile[RETURN].pal 13
		setthisprojectile[RETURN].extra 64
	}
} 
else
{
	mulvar zdist 644
	divvarvar zdist xydist
	ezshoot zdist RPGNOAIM
	ifspritepal 0 nullop else ifvarand monstflags 8 nullop else
	{
		getactor[RETURN].extra temp
		divvar temp 2
		setactor[RETURN].extra temp
	}
	
}

ends

state boss3lobbing

ifvarn target -1 { state boss3lobbingbot break }

ifvarand monstflags 32
{
	shoot ELECTROPROJ
	ifvarand monstflags 8 shoot ELECTROPROJ
} else
ifvarand monstflags 16
{
	eshoot FIREBALLPROJ 
	ifvarand monstflags 8 
	{
		setthisprojectile[RETURN].pal 13
		setthisprojectile[RETURN].extra 64
	}
} 
else
{
	shoot RPG
	ifvarand monstflags 8 shoot RPG
}

ends


state boss3lobbedstate
  setvar temp 0
  ifcansee ifvare playerally 0 setvar temp 1
  ifvarn target -1 setvar temp 1
  ifvare temp 1
  {
    ifaction ABOSS3LOBBING
      ifactioncount 2
    {
      state boss3lobbing
      resetactioncount
      ifrnd 8
        ai AIBOSS3SEEKENEMY
    }

    ifactioncount 3
    {
      action ABOSS3LOBBING
      resetcount
    }
  }
  else
    state checkboss3seekstate
ends

state checkboss3hitstate
  ifrnd 2
    spawn BLOODPOOL
  ifdead
  {
    ifspritepal 0
      globalsound DUKE_TALKTOBOSSFALL
    else
    {
      ifrnd 64
        globalsound DUKE_TALKTOBOSSFALL
      ifwasweapon FREEZEBLAST
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action ABOSS3FROZEN
        strength 0
        break
      }
    }

    addkills 1 state specialdeath
    ai AIBOSS3DYING

    sound BOS3_DYING
    sound JIBBED_ACTOR9

  }
  else
  {
    ifrnd 32
    {
      action BOSS3FLINTCH
      move 0
    }

    ifspritepal 0 nullop
    else
      ifwasweapon SHRINKSPARK
    {
      sound ACTOR_SHRINKING
      ai AIBOSS3PALSHRINK
      break
    }

    soundonce BOS3_PAIN

    debris SCRAP1 1
    guts JIBS6 1
  }
ends

state boss3code
state monsterai
  ifaction ABOSS3FROZEN
  {
	ifcount THAWTIME
    {
      ai AIBOSS3SEEKENEMY
        getlastpal
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }
    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }

      addkills 1 state specialdeath
      lotsofglass 30

      ifrnd 84
        spawn BLOODPOOL
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick
    break
  }
  ifai 0
  {
    ifspritepal 0
      ai AIBOSS3RUNENEMY
    else
    {
	  cstator 257
	  sizeat 40 40
	  clipdist 32 //16
      strength BOSS1PALSTRENGTH
      ai AIBOSS3LOBENEMY
      getactor[THISACTOR].extra hp
	  // this was already done in monsterai, but has to be done again for pal bosses	
	  ifvarand monstflags 2 mulvar hp 2
	  ifvarand monstflags 4 mulvar hp 4
	  ifvarg hp 32767 setvar hp 32767
	  setactor[THISACTOR].extra hp	
    }
  }
  else
    ifaction BOSS3FLINTCH
    {
      ifactioncount 3
      ai AIBOSS3SEEKENEMY
    }
  else
    ifai AIBOSS3SEEKENEMY
      state boss3seekenemystate
  else
    ifai AIBOSS3RUNENEMY
      state boss3runenemystate
  else
    ifai AIBOSS3LOBENEMY
      state boss3lobbedstate
  else
    ifai AIBOSS3PALSHRINK
      state boss3palshrunkstate

  ifai AIBOSS3DYING
    state boss3dyingstate
  else
  {
    ifhitweapon
      state checkboss3hitstate
    else
    {
	  ifvarn target -1
	  {
		 ifspritepal 0
		 {
			 ifvarl xydist 1280
			 {
				 setactor[target].htextra 100
				 setactor[target].htpicnum KNEE
				 setactor[target].htowner THISACTOR
			 }
		 }
		 else ifvarl xydist 844
		 {
			 ifai AIBOSS2PALSHRINK nullop else
			 {
				 setactor[target].htextra 2
				 setactor[target].htpicnum KNEE
				 setactor[target].htowner THISACTOR
			 }
		 }
	  }
      ifp palive ifcansee ifvare playerally 0
      {
	     ifspritepal 0 
	     {
		    ifpdistl 1280
		    {
		      addphealth -1000
		      palfrom 63 63
		    }
	    }
	    else ifpdistl 844
	    {
		    ifai AIBOSS2PALSHRINK nullop else
		    {
			    addphealth -1
			    ifvarand monstflags 8 addphealth -1
			    palfrom 30 63
		    }
	    }
      }
    }
  }
ends

actor BOSS3 BOSS3STRENGTH fall state boss3code enda


action ACOMMBREETH  0  3  5  1  40
action ACOMMFROZEN  0  1  5
//action ACOMMSPIN   -5  1  5  1  12
action ACOMMGET   0  3  5  1  30
action ACOMMSHOOT  20  1  5   1 35
action ACOMMABOUTTOSHOOT 20 1 5 1 30
action ACOMMDYING  30  8  1  1  12
action ACOMMDEAD   38  1  1  1  1


move COMMGETUPVELS 128 -64
move COMMGETVELS 128 64
move COMMSLOW 64 24
//move COMMSTOPPED

ai AICOMMWAIT ACOMMBREETH COMMSTOPPED faceplayerslow
ai AICOMMGET ACOMMGET COMMGETVELS seekplayer
ai AICOMMSHOOT ACOMMSHOOT COMMSTOPPED faceplayerslow
ai AICOMMABOUTTOSHOOT ACOMMABOUTTOSHOOT COMMSTOPPED faceplayerslow
// ai AICOMMSPIN ACOMMSPIN COMMSTOPPED spin
ai AICOMMDYING ACOMMDYING COMMSTOPPED geth // faceplayer
ai AICOMMSHRUNK ACOMMGET COMMSLOW furthestdir
ai AICOMMGROW ACOMMGET COMMSTOPPED furthestdir

state checkcommhitstate

  ifhitweapon
  {
    guts JIBS6 2

    ifdead
    {
      ifwasweapon FREEZEBLAST
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action ACOMMFROZEN
        strength 0
        break
      }
      else
        ifwasweapon GROWSPARK
      {
        sound ACTOR_GROWING
        ai AICOMMGROW
        break
      }

      addkills 1 state specialdeath

      ifwasweapon RADIUSEXPLOSION
      {
        spawn BLOODPOOL
        sound SQUISHED
        state standard_jibs
        killit
      }
      else
        ifwasweapon RPG
      {
        sound SQUISHED
        spawn BLOODPOOL
        state standard_jibs
        killit
      }

      sound COMM_DYING
      ai AICOMMDYING
    }
    else
    {
      soundonce COMM_PAIN
      ifwasweapon SHRINKSPARK
      {
        sound ACTOR_SHRINKING
        ai AICOMMSHRUNK
      }
      else
        ifwasweapon GROWSPARK
          sound EXPANDERHIT
      else
        ifrnd 24
          ai AICOMMABOUTTOSHOOT
    }
  }
ends

state commshootbot

state calczdist
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1

ifvarand monstflags 32
{
	mulvar zdist 768
	divvarvar zdist xydist
	setprojectile[ELECTROPROJ].workslike 36866
	ezshoot zdist ELECTROPROJ
	setthisprojectile[RETURN].extra 50
	ifvarand monstflags 8
	{
		ezshoot zdist ELECTROPROJ
		setthisprojectile[RETURN].extra 50
	}
	setprojectile[ELECTROPROJ].workslike 32770
}
ifvarand monstflags 16
{
	eshoot FIREBALLPROJ 
	ifvarand monstflags 8 
	{
		setthisprojectile[RETURN].pal 13
		setthisprojectile[RETURN].extra 64
	}
} 
else
{
	mulvar zdist 644
	divvarvar zdist xydist
	ifvarand monstflags 8
	setprojectile[RPGNOAIM].extra 80 else
	setprojectile[RPGNOAIM].extra 40
	ezshoot zdist RPGNOAIM
	setprojectile[RPGNOAIM].extra RPG_WEAPON_STRENGTH

}


resetactioncount

ends

state commshooting

ifvarn target -1 { state commshootbot break }

ifvarand monstflags 32
{
	eshoot ELECTROPROJ
	setthisprojectile[RETURN].extra 50
	ifvarand monstflags 8
	{
		eshoot ELECTROPROJ
		setthisprojectile[RETURN].extra 50
	}
} else
ifvarand monstflags 16
{
	eshoot FIREBALLPROJ 
	ifvarand monstflags 8 
	{
		setthisprojectile[RETURN].pal 13
		setthisprojectile[RETURN].extra 64
	}
} 
else
{
	shoot RPG
	ifvarand monstflags 8 shoot RPG
}


resetactioncount

ends

actor COMMANDERSTAYPUT COMMANDERSTRENGTH
  cactor COMMANDER
  ai AICOMMABOUTTOSHOOT
enda

state commspinbotstate

getactor[target].x mx
getactor[target].y my
getactor[target].z mz
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z
subvarvar mx x
subvarvar my y
getangle angvar mx my

cos xvel angvar
sin yvel angvar
shiftvarr xvel 7
shiftvarr yvel 7
subvarvar z mz 
ifvarg z 2048
setvar zvel -512 else
ifvarl z -2048 setvar zvel 512
movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN

    soundonce COMM_SPIN
    ifcount 16
    {
      ifvarl xydist 1280
      {
	    setvar temp CAPTSPINNINGPLAYER
        ifvarand monstflags 8 mulvar temp -2 else mulvar temp -1
        setactor[target].htextra temp
        setactor[target].htpicnum RPG
        setactor[target].htowner THISACTOR
        //sound DUKE_GRUNT
        resetcount
      }
      else
        ifvarg xydist 2300
          ai AICOMMWAIT
    }
    ifactioncount 52
      ai AICOMMWAIT
    ifnotmoving
      ifrnd 32
        operate

ends

state commspinstate

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

cos xvel angvar
sin yvel angvar
shiftvarr xvel 7
shiftvarr yvel 7
setvar zvel 0
movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN 

    soundonce COMM_SPIN
    ifcount 16
    {
      ifpdistl 1280
      {
        addphealth CAPTSPINNINGPLAYER
        ifvarand monstflags 8 addphealth CAPTSPINNINGPLAYER
        sound DUKE_GRUNT
        palfrom 32 16 
        resetcount
      }
      else
        ifpdistg 2300
          ai AICOMMWAIT
    }
    ifactioncount 52
      ai AICOMMWAIT
    ifnotmoving
      ifrnd 32
        operate
        
ends

actor COMMANDER COMMANDERSTRENGTH

ifvarn target -1
{
	getactor[THISACTOR].z z
	getactor[target].z mz
}

  state checksquished
  state monsterai
  ifaction ACOMMFROZEN
  {
    fall

    ifcount THAWTIME
    {
      getlastpal
      ai AICOMMWAIT
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1 state specialdeath

      ifrnd 84
        spawn BLOODPOOL
      lotsofglass 30
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick
    break
  }
  ifai 0
    ai AICOMMSHOOT
  else
    ifai AICOMMWAIT
  {
    ifcount 20
    {
	  ifvarn target -1
	  {
		  ifrnd 96
	            ai AICOMMGET
	          else
	            ai AICOMMABOUTTOSHOOT
	  }
	  else
	  {
	      ifcansee
	      {
	        ifcanshoottarget
	        {
	          ifrnd 96
	            ai AICOMMGET
	          else ifvare playerally 0
	            ai AICOMMABOUTTOSHOOT
	        }
	      }
	      else
	        ai AICOMMGET
      }
    }
  }
  else
    ifai AICOMMABOUTTOSHOOT
  {
	ifvare target -1 ifvarn playerally 0 { ai AICOMMGET break }
    ifactioncount 2
    {
	  ifvarn target -1 ai AICOMMSHOOT else
      ifcansee ifvare playerally 0
        ai AICOMMSHOOT
      else
      {
        ai AICOMMGET
        break
      }
    }
    ifrnd 32 soundonce COMM_ATTACK
  }
  else
    ifai AICOMMSHOOT
  {
	ifvare target -1 ifvarn playerally 0 { ai AICOMMGET break }
	setvar temp 0
	ifvarn target -1 setvar temp 1
	ifcanshoottarget setvar temp 1
    ifvare temp 1
    {
      ifcount 24
        ifrnd 16
          ai AICOMMWAIT
      ifactioncount 2
      {
	    state commshooting
      }
    }
    else
      ai AICOMMGET
  }
  else
    ifai AICOMMSHRUNK
  {
    ifcount SHRUNKDONECOUNT
      ai AICOMMGET
    else
      ifcount SHRUNKCOUNT
        sizeto 48 40
    else
      state genericshrunkcode
  }
  else
    ifai AICOMMGROW
      state genericgrowcode
  else
    ifai AICOMMGET
  {
	ifvarn playerally 0 ifvare target -1 ifpdistl 1280 { ai AICOMMWAIT break }
    ifnotmoving
      ifrnd 4
        operate
    ifvare playerally 0
    ifpdistl 1280
      ifp palive
    {
      sound COMM_SPIN
      ai AICOMMSPIN
      break
    }
    ifvarn target -1
      ifvarl xydist 1280
    {
	  sound COMM_SPIN
	  ai AICOMMSPIN
	  break
    }

    ifcansee
    {
	  setvar temp 0
	  ifp phigher setvar temp 1
	  ifvarn target -1
	  ifvarvarg z mz setvar temp 1
	  
      ifvare temp 1
        move COMMGETUPVELS getv geth faceplayer
      else
        move COMMGETVELS getv geth faceplayer
    }
    ifactioncount 8
      ifrnd 2
        ai AICOMMABOUTTOSHOOT
  }
  else
    ifai AICOMMSPIN
  {
	ifvarn target -1 state commspinbotstate else
	state commspinstate
  }

  ifai AICOMMDYING
  {
    fall
    strength 0

    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      spawn BLOODPOOL
      state standard_jibs
      killit
    }

    ifaction ACOMMDYING
      ifactioncount 8
    {
      iffloordistl 8
        sound THUD
      cstat 0
      action 0
      //action ACOMMDEAD
      move 0
      cactor COMMANDERCORPSE
    }
  }
  else
  {
    ifrnd 2
      soundonce COMM_ROAM
    state checkcommhitstate
  }
enda


// 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
    cstat 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

// RIOT TANK with Pigcop inside

define TANKSTRENGTH       500      // 2 3 4 5 7 8
//           off-set, numofframes, numofrot, skipframes, delay
action ATANKSPIN   0 1 7 1 4
action ATANKSHOOTING 7 2 7 1 10
action ATANKWAIT 0 1 7 1 1
action ATANKDESTRUCT 0 1 7 1 1
action ATANKDEAD 0 1 7 1 1
// move TANKVEL horiz vert
move TANKFORWARD 2
move TANKSTOP


state tankshootbot

state calczdist
dist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1
ldist xydist2 THISACTOR target
ifvare xydist2 0 setvar xydist2 1

ifactioncount 22
{
  ifvarg xydist 8192
  {
    mulvar zdist 644
    divvarvar zdist xydist2
    sound BOS1_ATTACK2
    ezshoot zdist RPGNOAIM
    ifvarand monstflags 8 setthisprojectile[RETURN].extra 80
    else setthisprojectile[RETURN].extra 40
  }
  resetcount
  move 0 action ATANKWAIT
}
else
  ifactioncount 2
{
    ifvarl xydist 16384
    {
      ifrnd 128
      {
        ifvarand monstflags 16
        {
	        mulvar zdist 768
	        divvarvar zdist xydist2
	        sound PISTOL_LOW
	        setprojectile[STARPROJ].workslike 38914
	        zshoot zdist STARPROJ
	        ifvarand monstflags 8 zshoot zdist STARPROJ
	        setprojectile[STARPROJ].workslike 34818
        } else
        {
	        shiftvarl zdist 8
	        divvarvar zdist xydist2
            sound PISTOL_FIRE
            zshoot zdist RPG
            ifvarand monstflags 8 zshoot zdist RPG
        }
      }
    }
    else
      ifrnd 128
    {
        ifvarand monstflags 16
        {
	        mulvar zdist 844
	        divvarvar zdist xydist2
	        setprojectile[FIREBULLET].workslike 36870
	        sound RPG_SHOOT
	        zshoot zdist FIREBULLET
	        ifvarand monstflags 8 zshoot zdist FIREBULLET
	        setprojectile[FIREBULLET].workslike 32774
        }
        else
        {
	      mulvar zdist 768
	      divvarvar zdist xydist2
	      ifvare effects YES sound PRED_ATTACK2 else
          sound PRED_ATTACK
          zshoot zdist RPG
          ifvarand monstflags 8 zshoot zdist RPG
        }
    }
  
  else
  {
    move TANKFORWARD seekplayer
    action ATANKSPIN
  }
}

ifrnd 16
{
  stopsound TANK_ROAM
  move TANKSTOP faceplayerslow
}
	    
ends


useractor enemy TANK TANKSTRENGTH fall
  state monsterai
  ifaction 0
  {
    sizeat 60 60
    action ATANKWAIT
    cstat 257
    clipdist 100
  }
  else
    ifaction ATANKSPIN
  {
    soundonce TANK_ROAM

    ifactioncount 20
    {
	  ifvare target -1 ifvarn playerally 0 nullop else
      ifrnd 16
        ifcansee
          ifcanshoottarget
      {
        move TANKSTOP geth
        action ATANKSHOOTING
        stopsound TANK_ROAM
      }
    }

    ifrnd 16
      move TANKFORWARD seekplayer
  }
  else
    ifaction ATANKSHOOTING
  {
	ifvarn target -1 state tankshootbot else
	{
		ifvarn playerally 0 { move 0 action ATANKWAIT break }
	    ifactioncount 22
	    {
	      ifpdistg 8192
	      {
	        sound BOS1_ATTACK2
	        shoot MORTER
	        ifvarand monstflags 8 shoot MORTER
	      }
	      resetcount
	      move 0 action ATANKWAIT
	    }
	    else
	      ifactioncount 2
	    {
	      ifcansee
	      {
	        ifpdistl 16384
	        {
	          ifrnd 128
	          {
		        ifvarand monstflags 16
		        {
			        sound PISTOL_LOW
			        shoot STARPROJ
			        ifvarand monstflags 8 shoot STARPROJ
		        } else
		        {
		            sound PISTOL_FIRE
		            shoot RPG
		            ifvarand monstflags 8 shoot RPG
	            }
	          }
	        }
	        else
	          ifrnd 128
	        {
		        ifvarand monstflags 16
		        {
			        sound RPG_SHOOT
			        shoot FIREBULLET
			        ifvarand monstflags 8 shoot FIREBULLET
		        }
		        else
		        {
			      ifvare effects YES sound PRED_ATTACK2 else
		          sound PRED_ATTACK
		          shoot RPG
		          ifvarand monstflags 8 shoot RPG
	            }
	        }
	      }
	      else
	      {
	        move TANKFORWARD seekplayer
	        action ATANKSPIN
	      }
	    }
	
	    ifrnd 16
	    {
	      stopsound TANK_ROAM
	      move TANKSTOP faceplayerslow
	    }
    }
  }
  else
    ifaction ATANKWAIT
  {
    ifactioncount 32
    {
      move TANKFORWARD seekplayer
      action ATANKSPIN
    }
  }
  else
    ifaction ATANKDESTRUCT
  {
    ifactioncount 64
      action ATANKDEAD
    else
      ifactioncount 56
       sound LASERTRIP_ARMING
     else
       ifactioncount 48
         sound LASERTRIP_ARMING
     else
       ifactioncount 32
         sound LASERTRIP_ARMING
     else
       ifactioncount 16
         sound LASERTRIP_ARMING
     break
  }
  else
    ifaction ATANKDEAD
  {
    addkills 1 state specialdeath
    hitradius 6144 TOUGH TOUGH TOUGH TOUGH
    sound LASERTRIP_EXPLODE
    debris SCRAP1 15
    spawn EXPLOSION2
    ifrnd 128 spawn PIGCOP
    killit
  }

  ifhitweapon
  {
    ifdead
      action ATANKDEAD
    else
    {
      debris SCRAP1 1
      ifaction ATANKSHOOTING break
	  ifvare target -1 ifvarn playerally 0 nullop else
      ifrnd 192
      {
        move TANKSTOP geth
        action ATANKSHOOTING
        stopsound TANK_ROAM
      }
    }
  }

  ifpdistl 1280
    ifhitspace
      ifp pfacing
        ifangdiffl 512
          action ATANKDESTRUCT
enda





action ABOSS4WALK          0 4  5  1  30
action ABOSS4DYING        40 9  1  1  20
action ABOSS4ABOUTTOSHOOT 20 1  5  1  40
action ABOSS4SHOOT        25 2  5  1  10
action ABOSS4LAYIT        50 3  5  1  120
action BOSS4FLINTCH       40 1  1  1  1
action ABOSS4DEAD         49

move BOSS4WALKVELS 128
move BOSS4STOPPED

ai AIBOSS4LAYEGGS ABOSS4WALK BOSS4WALKVELS randomangle geth
ai AIBOSS4SHOOT ABOSS4ABOUTTOSHOOT BOSS4STOPPED faceplayer
ai AIBOSS4DYING ABOSS4DYING BOSS4STOPPED geth // faceplayer

state boss4shoottarget
ifvarand monstflags 16 
{ 
    shiftvarl zdist 8
	divvarvar zdist xydist
	zshoot zdist GROWSPARK
    zshoot zdist GROWSPARK 
} 
else 
{
    mulvar zdist 768
    divvarvar zdist xydist
    setprojectile[ELECTROPROJ].workslike 36866
    zshoot zdist ELECTROPROJ
    setprojectile[ELECTROPROJ].workslike 32770
}
ends

state boss4shootbot

state calczdist
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1

  ifaction ABOSS4ABOUTTOSHOOT
    ifactioncount 3
      action ABOSS4SHOOT

  ifaction ABOSS4SHOOT
  {
    ifcount 48
    {
      ifrnd 4
        ai AIBOSS4LAYEGGS
    }
    ifcount 26
    {
	    ifvare pal 0
	    {
		    ifrnd 32
		    {
			  setactor[target].htpicnum SHOTSPARK1
		      setactor[target].htowner THISACTOR
		      sound SHORT_CIRCUIT
		      ifrnd 128
		      {
		        ifvarand monstflags 8 setactor[target].htextra 4 else
		        setactor[target].htextra 2
		      }
		      else
		      {
		        ifvarand monstflags 8 setactor[target].htextra 2 else
		        setactor[target].htextra 1
		      }
		    }
	    } else
	    {
		    ifcount 27 nullop else
			    state boss4shoottarget
			
		    ifcount 34 nullop else
		    ifcount 33 
			    state boss4shoottarget
			
		    ifcount 41 nullop else
		    ifcount 40 
			    state boss4shoottarget
			
		    ifvarand monstflags 8
		    {
			    ifcount 31 nullop else ifcount 30 state boss4shoottarget
			    ifcount 38 nullop else ifcount 37 state boss4shoottarget
			    ifcount 45 nullop else ifcount 44 state boss4shoottarget
		    }
	    }
    }
  }

ends

state boss4shootstate

ifvarn target -1  { state boss4shootbot break }
  ifaction ABOSS4ABOUTTOSHOOT
    ifactioncount 3
      action ABOSS4SHOOT

  ifaction ABOSS4SHOOT
  {
    ifcount 48
    {
      ifrnd 4
        ai AIBOSS4LAYEGGS
    }
    ifcount 26
    {
	    ifvare pal 0
	    {
		    ifrnd 32
		    {
		      ifrnd 128
		      {
		        sound SHORT_CIRCUIT
		        addphealth -2
		        ifvarand monstflags 8 addphealth -2
		      }
		      else
		      {
		        sound DUKE_GRUNT
		        addphealth -1
		        ifvarand monstflags 8 addphealth -1
		      }
		      palfrom 32 32 0 0
		    }
	    } else
	    {
		    ifcount 27 nullop else
		    { ifvarand monstflags 16 { shoot GROWSPARK shoot GROWSPARK } else shoot ELECTROPROJ }
		    ifcount 34 nullop else
		    ifcount 33 { ifvarand monstflags 16 { shoot GROWSPARK shoot GROWSPARK } else shoot ELECTROPROJ }
		    ifcount 41 nullop else
		    ifcount 40 { ifvarand monstflags 16 { shoot GROWSPARK shoot GROWSPARK } else shoot ELECTROPROJ }
		    ifvarand monstflags 8
		    {
			    ifcount 31 nullop else ifcount 30 { ifvarand monstflags 16 { shoot GROWSPARK shoot GROWSPARK } else shoot ELECTROPROJ }
			    ifcount 38 nullop else ifcount 37 { ifvarand monstflags 16 { shoot GROWSPARK shoot GROWSPARK } else shoot ELECTROPROJ }
			    ifcount 45 nullop else ifcount 44 { ifvarand monstflags 16 { shoot GROWSPARK shoot GROWSPARK } else shoot ELECTROPROJ }
		    }
	    }
    }
  }

ends

state boss4layeggs
  ifrnd 2
    sound BOS4_ROAM

  ifaction ABOSS4LAYIT
  {
    ifactioncount 3
      ifcount 32
    {
      ai AIBOSS4LAYEGGS
      ifrnd 32
        move BOSS4WALKVELS furthestdir geth
      espawn NEWBEASTHANG
      ifvarn pal 0 setactorvar[RETURN].mtype 1
      setactorvar[RETURN].playerally playerally
    }
  }
  else
    ifcount 64
      ifrnd 4
  {
    move 0

    ifrnd 88
    {
      action ABOSS4LAYIT
      sound BOS4_LAY
    }
    else
      ifp palive
        ifcansee
    {
	  ifvare target -1 ifvarn playerally 0 nullop else
	  {
      	ai AIBOSS4SHOOT
      	sound BOS4_ATTACK
      }
    }
  }

ends

state boss4dyingstate
  ifaction ABOSS4DEAD
    break
  else
    ifactioncount 9
  {
    iffloordistl 8
      sound THUD
	ifvare pal 0
    endofgame 52
    //action ABOSS4DEAD
    action 0
    cstat 0
    move 0
    cactor BOSS4CORPSE
  }
ends

state checkboss4hitstate
  ifrnd 2
    spawn BLOODPOOL

  ifdead
  {
    globalsound DUKE_TALKTOBOSSFALL

    addkills 1 state specialdeath
    ai AIBOSS4DYING

    sound BOS4_DYING
    sound BOSS4_DEADSPEECH
  }
  else
  {
    soundonce BOS4_PAIN
    debris SCRAP1 1
    guts JIBS6 1

    ifaction ABOSS4LAYIT
      break

    ifrnd 16
    {
      action BOSS4FLINTCH
      move 0
    }
  }
ends

state boss4code
state monsterai
  ifai 0
  {
    ai AIBOSS4LAYEGGS
    ifvarn pal 0
    {
	    cstator 257
	    sizeat 40 40
	    clipdist 32
	    strength BOSS1PALSTRENGTH
	    addstrength NEWBEASTSTRENGTH
	    getactor[THISACTOR].extra hp
	    // this was already done in monsterai, but has to be done again for pal bosses	
		ifvarand monstflags 2 mulvar hp 2
	    ifvarand monstflags 4 mulvar hp 4
	    ifvarg hp 32767 setvar hp 32767
	    setactor[THISACTOR].extra hp
    }
  }
  else
    ifaction BOSS4FLINTCH
    {
      ifactioncount 3
        ai AIBOSS4LAYEGGS
    }
  else
    ifai AIBOSS4LAYEGGS
      state boss4layeggs
  else
    ifai AIBOSS4SHOOT
      state boss4shootstate

  ifai AIBOSS4DYING
    state boss4dyingstate
  else
  {
    ifhitweapon
      state checkboss4hitstate
    else
      ifp palive ifcansee ifvare playerally 0
      {
	      ifvare pal 0
	      {
		    ifpdistl 1280
		    {
		        addphealth -1000
		        palfrom 63 63
	        }
	      }
	      else ifpdistl 844
	      {
		    addphealth -1
		    ifvarand monstflags 8 addphealth -1
		    palfrom 30 63
	      }
      }
  }
ends

actor BOSS4STAYPUT BOSS4STRENGTH

  fall
  ifaction 0 getactor[THISACTOR].pal pal
  cactor BOSS4
  spritepal 6
  state boss4code
  getlastpal

enda

actor BOSS4 BOSS4STRENGTH

  fall
  ifaction 0 getactor[THISACTOR].pal pal
  cactor BOSS4
  spritepal 6
  state boss4code
  getlastpal

enda

action ANEWBEASTSTAND     0
action ANEWBEASTWALKING   10  4  5  1  12
action ANEWBEASTRUNNING   10  4  5  1  8
action ANEWBEASTTHINK     0   2  5  1  40
action ANEWBEASTSCRATCHING  30  3  5  1  20
action ANEWBEASTDYING     72  8  1  1  15
action ANEWBEASTFLINTCH   71  1  1  1  1
action ANEWBEASTLYINGDEAD 79  1  1
action ANEWBEASTSCREAM    50  2  5  1  40
action ANEWBEASTJUMP      80  2  5  1  50
action ANEWBEASTFALL      90  1  5
action ANEWBEASTFROZEN    10  1  5

action ANEWBEASTHANG      0  1  5

action ANEWBEASTHANGDEAD      -1  1  5
useractor enemy NEWBEASTHANGDEAD TOUGH

  ifaction 0
  {
    action ANEWBEASTHANGDEAD
    sizeat 40 40
    cstator 257
  }
  else
    ifhitweapon
  {
    ifdead
    {
      state standard_jibs
      spawn BLOODPOOL
      sound SQUISHED
      killit
    }
    else
    {
      guts JIBS6 1
      sound SQUISHED
    }
  }
enda

define MINIBEAST 4614
eventloadactor MINIBEAST
getactor[THISACTOR].lotag lotag
setactor[THISACTOR].lotag 0
ifvare lotag 1
{
    setvar mtype 1
	//cactor NEWBEAST
	sizeat 20 20 
	strength TROOPSTRENGTH
	cstator 257
}
enda

useractor enemy MINIBEAST TROOPSTRENGTH

cactor NEWBEAST

enda


move BABYBEASTVEL 128
move NEWBEASTWALKVEL 182
move NEWBEASTRUNVEL 256
move NEWBEASTJUMPVEL 264
move NEWBEASTSTOP

ai AINEWBEASTGETENEMY ANEWBEASTWALKING NEWBEASTWALKVEL seekplayer
ai AINEWBEASTDODGE ANEWBEASTRUNNING NEWBEASTRUNVEL dodgebullet
ai AINEWBEASTCHARGEENEMY ANEWBEASTRUNNING NEWBEASTRUNVEL seekplayer
ai AINEWBEASTFLEENEMY ANEWBEASTWALKING NEWBEASTWALKVEL fleeenemy
ai AINEWBEASTSCRATCHENEMY ANEWBEASTSCRATCHING NEWBEASTSTOP faceplayerslow
ai AINEWBEASTJUMPENEMY ANEWBEASTJUMP NEWBEASTJUMPVEL jumptoplayer
ai AINEWBEASTTHINK ANEWBEASTTHINK NEWBEASTSTOP
// ai AINEWBEASTSHRUNK ANEWBEASTWALKING SHRUNKVELS fleeenemy
ai AINEWBEASTGROW ANEWBEASTSTAND  NEWBEASTSTOP faceplayerslow
ai AINEWBEASTDYING ANEWBEASTDYING NEWBEASTSTOP geth // faceplayer
ai AINEWBEASTSHOOT ANEWBEASTSCREAM NEWBEASTSTOP faceplayer
ai AINEWBEASTFLINTCH ANEWBEASTFLINTCH NEWBEASTSTOP faceplayerslow

state babynewbeastmoves

ifmove BABYBEASTVEL break
ifmove NEWBEASTSTOP break
ifai AINEWBEASTGETENEMY move BABYBEASTVEL seekplayer else
ifai AINEWBEASTDODGE move BABYBEASTVEL dodgebullet else
ifai AINEWBEASTCHARGEENEMY move BABYBEASTVEL seekplayer else
ifai AINEWBEASTFLEENEMY move BABYBEASTVEL fleeenemy else
ifai AINEWBEASTJUMPENEMY move BABYBEASTVEL jumptoplayer else

ifcount 2 nullop else count 78

ends


state newbeastseekbot

  ifactornotstayput
  {
    ifvarl xydist 1596
    {
      ai AINEWBEASTSCRATCHENEMY
      break
    }

    ifai AINEWBEASTCHARGEENEMY
    {
      ifvarl xydist 1596
      {
        ai AINEWBEASTSCRATCHENEMY
        break
      }
	  ifvarand monstflags 256 nullop else
      ifrnd 1
        ifvarg xydist 4096
      {
        ai AINEWBEASTSHOOT
        break
      }
    }
    else
      ifvarg xydist 4096
    {
      ai AINEWBEASTCHARGEENEMY
      break
    }

    iffloordistl 16
    {
      ifcount 32
        ifrnd 16
      {
        ifceilingdistl 96 break
        ai AINEWBEASTJUMPENEMY
      }
      break
    }

    ifrnd 4
    {
      ifnotmoving
        operate
    }
    else
      ifrnd 16
        ifbulletnear
    {
      ifgapzl 128
        ai AINEWBEASTDODGE
      else
        ifactornotstayput
      {
        ifrnd 128
        {
          ifceilingdistl 96 break
          ai AINEWBEASTJUMPENEMY
        }
        else
          ai AINEWBEASTDODGE
      }
    }
  }
  else
  {
    ifactioncount 16
    {
      ifvarl xydist 1596
      {
        ai AINEWBEASTSCRATCHENEMY
        break
      }
    }
    ifcount 16
      ifrnd 32
        move NEWBEASTWALKVEL randomangle geth
  }

ends



state newbeastseekstate

  ifvarn target -1 { state newbeastseekbot break }

  ifactornotstayput
  {
    ifp palive
      ifcansee
        ifpdistl 1596
          ifvare playerally 0
    {
      ai AINEWBEASTSCRATCHENEMY
      break
    }

    ifai AINEWBEASTCHARGEENEMY
    {
      ifp palive
        ifpdistl 1596
          ifcansee
            ifvare playerally 0
      {
        ai AINEWBEASTSCRATCHENEMY
        break
      }
	  ifvarand monstflags 256 nullop else
      ifrnd 1
        ifpdistg 4096
          ifp palive
            ifcansee
              ifvare playerally 0
      {
        ai AINEWBEASTSHOOT
        break
      }
    }
    else
      ifpdistg 4096
    {
      ai AINEWBEASTCHARGEENEMY
      break
    }

    iffloordistl 16
    {
      ifcount 32
        ifrnd 16
      {
        ifceilingdistl 96 break
        ai AINEWBEASTJUMPENEMY
      }
      break
    }

    ifrnd 4
    {
      ifnotmoving
        operate
    }
    else
      ifrnd 16
        ifbulletnear
    {
      ifgapzl 128
        ai AINEWBEASTDODGE
      else
        ifactornotstayput
      {
        ifrnd 128
        {
          ifceilingdistl 96 break
          ai AINEWBEASTJUMPENEMY
        }
        else
          ai AINEWBEASTDODGE
      }
    }
  }
  else
  {
    ifactioncount 16
    {
      ifp palive
        ifpdistl 1596
          ifcansee
            ifvare playerally 0
      {
        ai AINEWBEASTSCRATCHENEMY
        break
      }
    }
    ifcount 16
      ifrnd 32
        move NEWBEASTWALKVEL randomangle geth
  }

ends

/*
state newbeastshrunkstate
  ifcount SHRUNKDONECOUNT
    ai AINEWBEASTGETENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 48 40
  else
    state genericshrunkcode
ends
*/

state newbeastfleestate
  ifvarand monstflags 256 nullop else
  ifcount 8
  {
    ifrnd 64
    {
	  ifvarn target -1
	  {
		  ifvarg xydist 3500 ai AINEWBEASTSHOOT
	  }
	  else
	  {
	      ifpdistg 3500
	        ifp palive
	          ifcansee
	            ifvare playerally 0
	              ai AINEWBEASTSHOOT
      }
    }
  }
  else
  {
    iffloordistl 16
    {
      ifnotmoving
        ai AINEWBEASTGETENEMY
    }
    else
      ai AINEWBEASTGETENEMY
    break
  }
ends

state newbeastthinkstate

  ifrnd 8
    soundonce NEWBEAST_ROAM

  ifactioncount 3
  {
    ifrnd 128
    {
	  ifvarand monstflags 256 nullop else
	  ifvarn target -1
	  {
		  ifvarg xydist 3500 ai AINEWBEASTSHOOT
	  }
	  else
	  {
	      ifpdistg 3500
	        ifp palive
	          ifcansee
	            ifvare playerally 0
	              ai AINEWBEASTSHOOT
      }
    }
    else
      ai AINEWBEASTGETENEMY
  }

  ifrnd 16
    ifbulletnear
  {
    ifgapzl 96
      ai AINEWBEASTDODGE
    else
    {
      ifrnd 128
      {
        ifceilingdistl 144 break
        ai AINEWBEASTJUMPENEMY
      }
      else
        ai AINEWBEASTDODGE
    }
  }
ends

state newbeastscratchbot

  ifcount 20
    ifrnd 8
  {
      ifvarl xydist 2048
    {
      ifrnd 128
        ai AINEWBEASTFLEENEMY
      break
    }
    ifrnd 80
      ai AINEWBEASTTHINK
    else
      ai AINEWBEASTGETENEMY
  }

  ifactioncount 3
  {
    ifvarg xydist 1596
      ai AINEWBEASTTHINK
    else
    {
	  ifvare mtype 0 setvar temp NEWBEASTSCRATCHAMOUNT
	  else setvar temp OCTASCRATCHINGPLAYER
	  ifvarand monstflags 8 mulvar temp -2 else mulvar temp -1
	  setactor[target].htextra temp
	  setactor[target].htpicnum KNEE
	  setactor[target].htowner THISACTOR
      resetactioncount
      resetcount
    }
  }
  else
    ifcount 15
      nullop
  else
    ifcount 14
  {
    ifvarl xydist 1596
      soundonce NEWBEAST_ATTACK
    else
      soundonce NEWBEAST_ATTACKMISS
  }
ends

state newbeastscratchstate

ifvarg target -1 { state newbeastscratchbot break }

  ifcount 20
    ifrnd 8
  {
    ifcansee
      ifpdistl 2048
    {
      ifrnd 128
        ai AINEWBEASTFLEENEMY
      break
    }
    ifrnd 80
      ai AINEWBEASTTHINK
    else
      ai AINEWBEASTGETENEMY
  }

  ifactioncount 3
  {
    ifpdistg 1596
      ai AINEWBEASTTHINK
    else ifp palive ifcansee
    {
      palfrom 16 16
      ifvare mtype 0
      addphealth NEWBEASTSCRATCHAMOUNT
      else addphealth OCTASCRATCHINGPLAYER
      ifvarand monstflags 8 addphealth NEWBEASTSCRATCHAMOUNT
      sound DUKE_GRUNT
      resetactioncount
      resetcount
    }
  }
  else
    ifcount 15
      nullop
  else
    ifcount 14
  {
    ifpdistl 1596
      soundonce NEWBEAST_ATTACK
    else
      soundonce NEWBEAST_ATTACKMISS
  }
ends

state checknewbeasthit
  spawn BLOOD
/*
  ifai AINEWBEASTSHRUNK
  {
    addkills 1 state specialdeath
    sound SQUISHED
    state standard_jibs
    killit
  }
*/
  ifdead
  {
    ifwasweapon FREEZEBLAST
    {
      sound SOMETHINGFROZE
      spritepal 1
      move 0
      action ANEWBEASTFROZEN
      strength 0
      break
    }

    ifwasweapon GROWSPARK
    {
      cstat 0
      sound ACTOR_GROWING
      ai AINEWBEASTGROW
      break
    }

    addkills 1 state specialdeath

    ifwasweapon RPG
    {
      sound SQUISHED
      state liz_body_jibs
      state standard_jibs
      killit
    }
    else
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state liz_body_jibs
      state standard_jibs
      killit
    }
    else
    {
      state rf
      ai AINEWBEASTDYING
      ifrnd 64
        spawn BLOODPOOL
    }
    sound NEWBEAST_DYING
  }
  else
  {
    sound NEWBEAST_PAIN
    ifwasweapon GROWSPARK
      sound EXPANDERHIT
/*
//  The alien is immune to the shrinker
    ifwasweapon SHRINKSPARK
    {
      sound ACTOR_SHRINKING
      ai AINEWBEASTSHRUNK
      break
    }
*/
    state random_wall_jibs
    ifrnd 32
      ai AINEWBEASTFLINTCH
    else
    ifwasweapon KNEE ifvarn superkicking 0
      ai AINEWBEASTFLINTCH
    else
    ifvarand monstflags 256 { ifrnd 32 ai AINEWBEASTGETENEMY }
    else
      ifrnd 32
        ifpdistg 3500
          ifp palive
            ifcansee
              ai AINEWBEASTSHOOT
  }
ends

state newbeastjumpstate
  ifaction ANEWBEASTFALL
  {
    iffloordistl 16
      ai AINEWBEASTGETENEMY
  }
  else
    ifcount 32
      action ANEWBEASTFALL
ends

state newbeastdyingstate
  ifaction ANEWBEASTLYINGDEAD
  {
    strength 0
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    ifcount RESPAWNACTORTIME
      ifrespawn
    {
      spawn TRANSPORTERSTAR
      cstat 257
      setvar monstatus 1
      strength NEWBEASTSTRENGTH
      ai AINEWBEASTGETENEMY
    }
  }
  else
    ifai AINEWBEASTDYING
      ifactioncount 7
  {
    iffloordistl 8
      sound THUD
    move NEWBEASTSTOP
    //action ANEWBEASTLYINGDEAD
    action 0
    move 0
    cactor NEWBEASTCORPSE
  }
ends

state newbeastdodgestate
  ifcount 13
    ai AINEWBEASTGETENEMY
ends

state newbeastshootbot

state calczdist
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1

ifvarand monstflags 64
{
	shiftvarl zdist 8
	divvarvar zdist xydist
	sound EXPANDERSHOOT
	zshoot zdist GROWSPARK zshoot zdist GROWSPARK zshoot zdist GROWSPARK
	ifvarand monstflags 8
	{
		zshoot zdist GROWSPARK zshoot zdist GROWSPARK zshoot zdist GROWSPARK
	}
} else
ifvarand monstflags 32 
{ 
	mulvar zdist 768
	divvarvar zdist xydist
	setprojectile[ELECTROPROJ].workslike 36866
	shoot ELECTROPROJ 
	ifvarand monstflags 8 shoot ELECTROPROJ 
	setprojectile[ELECTROPROJ].workslike 32770
} 
else
ifvarand monstflags 16 
{ 
	eshoot FIREBALLPROJ 
	ifvarand monstflags 8 
	{
		setthisprojectile[RETURN].pal 13
		setthisprojectile[RETURN].extra 64
	}
} else
{
	mulvar zdist 768
	divvarvar zdist xydist
	zshoot zdist SHRINKER
}

ends

state newbeastshooting

ifvarn target -1 { state newbeastshootbot break }

ifvarand monstflags 64
{
	sound EXPANDERSHOOT
	shoot GROWSPARK shoot GROWSPARK shoot GROWSPARK
	ifvarand monstflags 8
	{
		shoot GROWSPARK shoot GROWSPARK shoot GROWSPARK
	}
} else
ifvarand monstflags 32 { shoot ELECTROPROJ ifvarand monstflags 8 shoot ELECTROPROJ } else
ifvarand monstflags 16 
{ 
	eshoot FIREBALLPROJ 
	ifvarand monstflags 8 
	{
		setthisprojectile[RETURN].pal 13
		setthisprojectile[RETURN].extra 64
	}
} else
shoot SHRINKER

ends

useractor enemystayput NEWBEASTSTAYPUT NEWBEASTSTRENGTH ai AINEWBEASTGETENEMY cstator 257 cactor NEWBEAST enda
useractor enemy NEWBEASTJUMP NEWBEASTSTRENGTH ai AINEWBEASTJUMPENEMY cstator 257 cactor NEWBEAST enda

state newbeastcode

  state monsterai
  state checksquished
  ifai 0
  {
    cstator 257
    ai AINEWBEASTGETENEMY
  }
  else
    ifaction ANEWBEASTLYINGDEAD
  {
    fall
    state newbeastdyingstate
    break
  }
  else
    ifaction ANEWBEASTFROZEN
  {
    ifcount THAWTIME
    {
      ai AINEWBEASTGETENEMY
      spritepal 0
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1 state specialdeath

      ifrnd 84
        spawn BLOODPOOL
      lotsofglass 30
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
        pkick
    break
  }
  else
    ifai AINEWBEASTJUMPENEMY
      state newbeastjumpstate
  else
  {
    fall
    ifai AINEWBEASTGETENEMY
      state newbeastseekstate
    
    else
      ifai AINEWBEASTCHARGEENEMY
       state newbeastseekstate
    else
      ifai AINEWBEASTFLINTCH
    {
      ifcount 8
        ai AINEWBEASTGETENEMY
    }

    else
      ifai AINEWBEASTDODGE
        state newbeastdodgestate
    else
      ifai AINEWBEASTSCRATCHENEMY
        state newbeastscratchstate
    else
      ifai AINEWBEASTFLEENEMY
        state newbeastfleestate
    else
      ifai AINEWBEASTTHINK
        state newbeastthinkstate
/*
    else
      ifai AINEWBEASTSHRUNK
        state newbeastshrunkstate
*/
    else
      ifai AINEWBEASTGROW
        state genericgrowcode
    else
      ifai AINEWBEASTDYING
        state newbeastdyingstate
    else
      ifai AINEWBEASTSHOOT
    {
      ifp pshrunk
        ai AINEWBEASTGETENEMY
      else
        ifcount 26
          ai AINEWBEASTGETENEMY
      else
        ifcount 25
        {
	      ifvare mtype 1 shoot SPIT else
	      state newbeastshooting
        }
      else
      {
        ifcount 5
          nullop
        else
          ifcount 4
            sound NEWBEAST_SPIT
      }
    }
  }

  ifhitweapon
    state checknewbeasthit
    
ends


useractor enemy NEWBEAST NEWBEASTSTRENGTH
  fall
  ifaction 0
  {
    cstator 257
    ifvare mtype 1 sizeat 20 20 else
    sizeat 40 40
    ai AINEWBEASTDODGE
  }
  ifaction ANEWBEASTFROZEN
    state newbeastcode
  else
  {
    spritepal 6
    state newbeastcode
    ifaction ANEWBEASTFROZEN
      break
    getlastpal
  }
  ifvare mtype 1 state babynewbeastmoves 
enda

useractor enemy NEWBEASTHANG NEWBEASTSTRENGTH

  ifaction 0
  {
    action ANEWBEASTHANG
    cstator 257
	ifvare mtype 1 { sizeat 20 20 strength TROOPSTRENGTH } else
    sizeat 40 40
  }
  else
    ifhitweapon
  {
    cactor NEWBEAST
    action ANEWBEASTSTAND
    sound NEWBEAST_PAIN
    spritepal 6
    state checknewbeasthit
    getlastpal
  }
  else
    ifspawnedby BOSS4
      ifcount 200
        ifrnd 1
  {
    cactor NEWBEAST
    action ANEWBEASTSTAND
    sound NEWBEAST_PAIN
  }
  else ifspawnedby EGG
    ifcount 78
      ifrnd 2
  {
    cactor NEWBEAST
    action ANEWBEASTSTAND
    sound NEWBEAST_PAIN
  }
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 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 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
		setvar bouncesound THUD
		cstator 256
		setvar weight WEIGHT3
		ifactor COMMANDERCORPSE setvar weight WEIGHT4
		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
	}
	strength 0
	clipdist 64
	
	
	state corpsemovecode
	
	ifaction CORPSEFROZEN
	{
		ifcount THAWTIME
	    {
	      action 0
	      getlastpal
	      resetcount
	    }
	    else
	      ifcount FROZENDRIPTIME
	    {
	      ifactioncount 26
	      {
	        spawn WATERDRIP
	        resetactioncount
	      }
	    }
		ifhitweapon
		{
			ifwasweapon FREEZEBLAST { resetcount resetactioncount break }
			lotsofglass 30
	        sound GLASS_BREAKING
	        ifrnd 84
	        spawn BLOODPOOL
	        killit
		}
		break
	}
	ifhitweapon
	{
		ifwasweapon FREEZEBLAST
		{
			sound SOMETHINGFROZE
			action CORPSEFROZEN
			resetcount
			spritepal 1
			break
		}
		ifwasweapon RADIUSEXPLOSION
		{
			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 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
		}
	}
	
	state corpsepickupcode
	
	
  ifsquished
  {
    sound SQUISHED
    state standard_jibs
    state random_ooz
    killit
  }
  
    strength 0
    //ifrespawn
    ifvare peractor1 4
      ifcount RESPAWNACTORTIME
    {
	    ifactor LIZTROOPCORPSE { strength TROOPSTRENGTH cactor LIZTROOP action ATROOPDEAD }
	    ifactor OCTABRAINCORPSE { strength PIGCOPSTRENGTH cactor OCTABRAIN action AOCTADEAD }
		ifactor COMMANDERCORPSE { strength PIGCOPSTRENGTH cactor COMMANDER action ACOMMDEAD }
		ifactor PIGCOPCORPSE { strength PIGCOPSTRENGTH  cactor PIGCOP action APIGDEAD }
		ifactor LIZMANCORPSE { strength LIZSTRENGTH cactor LIZMAN action ALIZLYINGDEAD }
		ifactor BOSS1CORPSE { strength PIGCOPSTRENGTH cactor BOSS1 action ABOSS1DEAD }
		ifactor BOSS2CORPSE { strength PIGCOPSTRENGTH cactor BOSS2 action ABOSS2DEAD }
		ifactor BOSS3CORPSE { strength PIGCOPSTRENGTH cactor BOSS3 action ABOSS3DEAD }
		ifactor NEWBEASTCORPSE { strength PIGCOPSTRENGTH cactor NEWBEAST action ANEWBEASTLYINGDEAD }
    }


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 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

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
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 1885 1 1 1 1

onevent EVENT_EGS

ifmultiplayer nullop else

ifactor APLAYER ifvare DONE YES
{
	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
    }
    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
    }
    setvar DONE 0
}

ifspawnedby RESPAWN
{
	getactor[THISACTOR].owner temp
	ifvarn temp -1
	{
		getactorvar[temp].droptile droptile
		getactorvar[temp].monstflags monstflags
		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 ACCESSSWITCH
	case ACCESSSWITCH2
	spriteflags 4
	setactor[THISACTOR].shade -100
	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
		
  	}
  }
  break
  
  case SMALLSMOKE
  getactor[THISACTOR].owner spriteid
  ifvarn spriteid -1
  {
// 	  getactorvar[spriteid].countvar temp
// 	  ifvarn temp 0 
// 	  ifvarl temp 27 
	  getactor[spriteid].picnum picnum
	  ifvare picnum SHOTSPARK1
	  {
		getactor[spriteid].htg_t 8 temp
		ifvarn temp -1
		{
			getactorvar[temp].monstatus monstatus
			ifvare monstatus 1 killit
		}
	  }
  }
  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
  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 BOTALLY setvar lotag 1 break
 
 case MINIBEAST
 setvar mtype 1
 cactor NEWBEAST
 strength TROOPSTRENGTH
 sizeat 20 20 
 cstator 257
 break

case LIGHTSOURCEPROJ

 setvarvar flicker pflicker
 setactor[THISACTOR].pal pcolor
 setthisprojectile[THISACTOR].pal pcolor
 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

ifspawnedby RPG
{
	getactor[THISACTOR].owner spriteid
	getactorvar[spriteid].peractor1 peractor1
}
ifspawnedby RPGNOAIM
{
	getactor[THISACTOR].owner spriteid
	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
			setactor[RETURN].pal peractor1
			setactor[RETURN].xrepeat 40
			setactor[RETURN].yrepeat 40
			addweapon TRIPBOMB_WEAPON 1
		}
		killit
	}
}
break

case SHOOTME cstat 32768 
break

case APLAYER
	ifvare holodukelightning YES
		setvar monstatus 10 // HOLODUKE HOLOGRAM
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
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
case RAILSLUG_WEAK
state randtraj
break

case ELECTROPROJ
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

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 JIBS6
ifspawnedby COLACANSTAND killit
ifspawnedby SMALLSMOKE { getactor[THISACTOR].z z addvar z 4096 setactor[THISACTOR].z z  }
getactor[THISACTOR].owner temp
ifvarn temp -1
{
	getactor[temp].pal pal
	ifvare pal 6 setactor[THISACTOR].pal 6
}
break

case FIRELASER

  action FIRELASERACTION

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 COOLEXPLOSION1
getactor[THISACTOR].owner spriteid
ifvarn spriteid -1
{
	getactorvar[spriteid].target target
	ifvarn target -1 state randtraj
	getactorvar[spriteid].playerally playerally
}
break

case RPG
case RPGNOAIM

	ifvare lighting YES
	{
		ifspawnedby APLAYER ifvare CURRWEAP 7 nullop else
		ifvarl highlight 10
		{
			setvar intensity 80
			state enter_light_array
		}
	}
	// 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 2
			    killit
		    } 
		    else
		    {
			    getactor[THISACTOR].extra temp
			    mulvar temp 2
			    setactor[THISACTOR].extra temp
			    setvar temp RPGBLASTRADIUS
			    mulvar temp 2
			    setthisprojectile[THISACTOR].hitradius temp
			    getactor[THISACTOR].xvel xvel
			    mulvar xvel 3 divvar xvel 2
			    setactor[THISACTOR].xvel xvel
			    getactor[THISACTOR].zvel zvel
			    mulvar zvel 3 divvar zvel 2
			    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
	}
	
break

case BLOODPOOL
ifspawnedby COLACANSTAND killit

cstator 2
ifrnd 128 cstator 4
randvar angvar 2047
setactor[THISACTOR].ang angvar
getsector[THISACTOR].floorshade temp
addvar temp 10
ifvarg temp 28 setvar temp 28
ifvarl temp 0 setvar temp 0
setactor[THISACTOR].shade temp

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 operateSC

// ifvare lighting YES
// {
// 	ifvarg hightaggedSC 0
// 	{
// 		setvar temp 0
// 		whilevarvarn temp hightaggedSC
// 		{
// 			getactorvar[temp].taggedSC spriteid
// 			getactorvar[spriteid].lotag tempb
// 			ifvarvare tempb lotag
// 			{
// 				getactorvar[spriteid].weapcount weapcount
// 				ifvarvarn weapcount timer
// 				{
// 					getactorvar[spriteid].command tempc
// 					ifvare tempc 1 setvar tempc 0 else setvar tempc 1
// 					setactorvar[spriteid].command tempc
// 					setactorvar[spriteid].weapcount timer
// 				}
// 			}
// 			 getactorvar[spriteid].hp tempb
// 			 ifvarvare tempb lotag
// 			 {
// 				 getactorvar[spriteid].weapcount weapcount
// 				 ifvarvarn weapcount timer
// 				 {
// 			 		getactorvar[spriteid].command tempc
// 					ifvare tempc 2 setvar tempc 0 else setvar tempc 2
// 					setactorvar[spriteid].command tempc
// 					setactorvar[spriteid].weapcount timer
// 				}
// 			 }
// 			addvar temp 1
// 		}
// 	}
// }
// ends



move TROOPRUNVELSBACK -108
move OCTAWALKVELSBACK -96 -30
move OCTAUPVELSBACK -96 -70
move PIGWALKVELSBACK -72
move PIGRUNVELSBACK -108
move PALBOSS1RUNVELSBACK -128
move BOSS1WALKVELSBACK -208
move BOSS1RUNVELSBACK -296
move PALBOSS2RUNVELSBACK -84
move BOSS2WALKVELSBACK -192
move BOSS2RUNVELSBACK -256
move PALBOSS3RUNVELSBACK -84
move BOSS3WALKVELSBACK -208
move BOSS3RUNVELSBACK -270
move COMMGETUPVELSBACK -128 -64
move COMMGETVELSBACK -128 64
move COMMSLOWBACK -64 24
move TANKFORWARDBACK -100
move BOSS4WALKVELSBACK -128
move NEWBEASTWALKVELBACK -182
move NEWBEASTRUNVELBACK -256
move NEWBEASTJUMPVELBACK -264


// 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
{
	getactor[THISACTOR].picnum picnum
	ifvarn picnum SECTOR_CONTROLLER ifvarn picnum LIGHTSOURCE
	{
		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 0
		ifactor BURNING2 sleeptime 0
	}
}
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 277 case 394 case 415 case 498 case 499
// case 500 case 502 case 518 case 519 case 520 case 521 case 522 case 523 case 524 case 525
// case 526 case 527 case 528 case 529 case 530 case 531 case 532 case 533 case 534 case 535
// case 568 case 593 case 594 case 598 case 599 case 600 case 612 case 613 case 614 case 639
// case 657 case 666 case 667 case 687 case 699 case 721 case 728 case 736 case 766 case 776 
// case 777 case 778 case 784 case 817 case 818 case 822 case 826 case 835 case 838 case 837
// case 841 case 839 case 848 case 849 case 856 case 858 case 871 case 872 case 937 case 938 
// case 945 case 946 case 949 case 961 case 963 case 964 case 965 case 966 case 967 case 968
// case 970 case 980 case 992 case 1043 case 1044 case 1046 case 1047 case 1064 case 1065 case 1066
// case 1072 case 1210 case 1211 case 1212 case 1214 case 1215 case 1217 case 1244 case 1245
// case 2486 case 2492 case 2493 case 2500 case 2504 case 2505 case 2506 case 3370 case 3371 case 3372
// case 3373 case 3374 case 3382 case 3383 case 3391 case 3402 case 3403 case 3421 case 3422 case 3423
// case 4096 case 4108 case 4125 case 4126 case 4238 case 4306 case 4307 case 4318 case 4323
// case 4329 case 4447 case 4450 case 4451 case 4477 case 4472 case 4475 case 4476
// case 4478 case 4479 case 4484 case 4485 case 4486 case 4487 case 4488 case 4492 case 4499
// case 4494 case 4504 case 4505 case 4506 case 4507 case 4508 case 4553 case 4564 case 4565
// case 4578 case 4579 case 4597 case 4598 case 4599 case 4889 case 4891 case 4892 case 4896 
// case 4897 case 4898 case 4899 case 4903 case 4904 case 4905 case 4906 case 4907 case 4908
// case 4924 case 4925 case 4926 case 4927 case 4928 case 4929 case 4930 case 4931 case 4932
// case 4933 case 4934 case 4937 case 4938 case 4939 case 4942 case 4945 case 4947 case 4948
// case 4950 case 4951 case 4952 case 4956
// break
// default
// 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

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

endswitch

ends

// EVENT CODE
onevent EVENT_GAME

ifactor SECTOR_CONTROLLER { changespritestat THISACTOR 1 break }

// ifmultiplayer nullop else
// {
// 	setvar temp LODHACK
// 	ifvare temp YES state lodhack
// }

ifvarg underwater 0
{
	ifvarg underwater 3
	{
		soundonce ITEM_SPLASH
		espawn WATERSPLASH3
		ifvarn watereffector -1
		{
			getactor[watereffector].z digz
			setactor[RETURN].z digz
		}
	}
	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
				divvar temp 2
				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
	{
		getactor[THISACTOR].statnum temp
		ifvare temp 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
	endswitch
}

//  getactor[THISACTOR].statnum temp
//  getactor[THISACTOR].mdflags tempb
//    ifvare temp 2 ifvarn tempb 2 ifvarn ANIMATION 1 setactor[THISACTOR].mdflags 2 else // inactive 
// 	  ifvarvarn tempb ANIMATION 
// 	     setactor[THISACTOR].mdflags ANIMATION
   


ifvare lighting YES state lightsprite

ifvare NOCODE 1 break

ifspritepal 66
{
	ifvare initcstat -1
		getactor[THISACTOR].cstat initcstat
		
	getplayer[THISACTOR].heat_on temp
	ifvare temp 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
		endswitch
	}
}

ifvarn pulse 0
{
	spriteflags 4
	getplayer[THISACTOR].player_par temp
	divvarvar temp pulse
	shiftvarl temp 8 //7
	sin shade temp
	shiftvarr shade 10 //11
	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 HEAVYHBOMB
ifvarn playerally 0
{
	ifvarg countvar 40 ifpdistl 1280 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
		killit
	}
}

break

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

case SECTOREFFECTOR

ifvare mirrored YES ifvarn mysector -1 setactor[THISACTOR].sectnum mysector

ifvare lotag 102
{
	ifmultiplayer nullop else
	{
		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 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 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
			{
				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 WATERTILE2
					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
	{
		addvar lotag 1
		setvar sleeping -130
		subvarvar sleeping initx
		getplayer[THISACTOR].i spriteid
		setactorvar[spriteid].hitag hitag
	}
	
} 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 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
	}
}
	
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
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 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

getactor[THISACTOR].statnum tempb
ifvarn tempb 1
{
	getactor[THISACTOR].cstat temp
	ifvarand temp 1
	{
		state pickupcode2
		ifvarvare holding THISACTOR
		{
			changespritestat THISACTOR 1
			ifvare NOCODE 2 setvar NOCODE 1
		}
		
	}
}
break

case DPTOUCHPLATE
ifvarn lotag 0 ifvarn activator 0
{
	getplayer[THISACTOR].cursectnum temp
	ifvarvare temp 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
break

case OOZ
case OOZ2
ifoutside killit
ifspawnedby JIBS2 killit
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
// getactor[THISACTOR].xrepeat x
// getactor[THISACTOR].yrepeat y
// ifvarg x 8 setvar x 8
// ifvarg y 8 setvar y 8
// ifvarg x 1 subvar x 1
// ifvarg y 1 subvar y 1
// setactor[THISACTOR].xrepeat x
// setactor[THISACTOR].yrepeat y
break

// case TOUCHPLATE
// ifvare mtype 0 // not activated yet
// {
// 	getplayer[THISACTOR].cursectnum temp
// 	ifvarvare temp mysector 
// 	{
// 		setvar mtype 1
// 		state operateSC
// 	}
// 	
// }
// break

case CAMERA1

getplayer[THISACTOR].newowner temp
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 WATERTILE2
case WATERFLOW

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
		}
	}
	
}

break
	
case DIPSWITCH
case DIPSWITCH2
case DIPSWITCH3
case TECHSWITCH
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 }
}

		
break

case 163 case 165 case 167 case 169
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 }
}

break

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 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
ifvare pal 66 { setactor[THISACTOR].pal 66 setvar pal 0 }
ifvarn activator 0
{
	ifvarvarn command picnum state activatorstate
	getactor[THISACTOR].picnum command
}

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
ifvare monstatus 10 // HOLODUKE HOLOGRAM
{
	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
			}
			
		}
	}
}
break

case BOTALLY
case BOTALLYCROUCH
ifvare monstatus 1 sleeptime 0
break

case RAINSPRITE
case PLAYERTRAIL
sleeptime 0
//changespritestat THISACTOR 1
break

case CORONA1
case CORONA2
case BOTMARKER
case MOVEMENT
case SPAWNER
case LIGHTSOURCE
case GUSTSPAWNER
case DNSWITCH
case UPSWITCH
//case MOVEBLOCKA
//case MOVEBLOCKB
sleeptime 0
break

case SHOOTER
ifvare mtype 0 sleeptime 0
break

case SHOOTME
sleeptime 0
//changespritestat THISACTOR 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 LIZTROOP  
case LIZTROOPDUCKING   
case OCTABRAIN  
case DRONE  
case COMMANDER  
case TANK  
case PIGCOP  
case PIGCOPDIVE  
case LIZMAN  
case ROTATEGUN   
case BOSS1  
case BOSS2  
case BOSS3  
case NEWBEAST
case NEWBEASTHANG   
case BOSS4
case EGG

ifactor ROTATEGUN
ifvare mtype 1
{
	setactor[THISACTOR].xrepeat hitx
	setactor[THISACTOR].yrepeat hity
}
ifvarand monstflags 1 changespritestat THISACTOR 1
getactor[THISACTOR].statnum temp
ifvare temp 1
{
	ifspritepal 1 // frozen
	{
		setactor[THISACTOR].mdflags 2 
		//strength 1
	}
	else
	setactor[THISACTOR].mdflags 0
}
else setactor[THISACTOR].mdflags 2 // inactive

ifvarand monstflags 4096
{
  ifrnd 16 setvar peractor1 0
  ifcansee
	//ifpdistl 8192
  {
	ifmove TROOPWALKVELS { setvar peractor1 26 move TROOPWALKVELSBACK faceplayer } else
	ifmove TROOPRUNVELS { setvar peractor1 26 move TROOPRUNVELSBACK faceplayer } else
	ifmove LIZWALKVEL { setvar peractor1 26 move LIZWALKVELBACK faceplayer } else
	ifmove LIZRUNVEL { setvar peractor1 26 move LIZRUNVELBACK faceplayer } else
	ifmove LIZJUMPVEL { setvar peractor1 26 move LIZJUMPVELBACK jumptoplayer }
	ifmove OCTAWALKVELS { setvar peractor1 26 move OCTAWALKVELSBACK faceplayer } else
	ifmove OCTAUPVELS { setvar peractor1 26 move OCTAUPVELSBACK faceplayer } else
	ifmove PIGWALKVELS { setvar peractor1 26 move PIGWALKVELSBACK faceplayer } else
	ifmove PIGRUNVELS { setvar peractor1 26 move PIGRUNVELSBACK faceplayer } else
	ifmove PALBOSS1RUNVELS { setvar peractor1 26 move PALBOSS1RUNVELSBACK faceplayer } else
	ifmove BOSS1WALKVELS { setvar peractor1 26 move BOSS1WALKVELSBACK faceplayer } else
	ifmove BOSS1RUNVELS { setvar peractor1 26 move BOSS1RUNVELSBACK faceplayer } else
	ifmove PALBOSS2RUNVELS { setvar peractor1 26 move PALBOSS2RUNVELSBACK faceplayer } else
	ifmove BOSS2WALKVELS { setvar peractor1 26 move BOSS2WALKVELSBACK faceplayer } else
	ifmove BOSS2RUNVELS { setvar peractor1 26 move BOSS2RUNVELSBACK faceplayer } else
	ifmove PALBOSS3RUNVELS { setvar peractor1 26 move PALBOSS3RUNVELSBACK faceplayer } else
	ifmove BOSS3WALKVELS { setvar peractor1 26 move BOSS3WALKVELSBACK faceplayer } else
	ifmove BOSS3RUNVELS { setvar peractor1 26 move BOSS3RUNVELSBACK faceplayer } else
	ifmove BOSS4WALKVELS { setvar peractor1 26 move BOSS4WALKVELSBACK faceplayer } else
	ifmove COMMGETUPVELS { ifai AICOMMSPIN nullop else { setvar peractor1 26 move COMMGETUPVELSBACK faceplayer } } else
	ifmove COMMGETVELS { ifai AICOMMSPIN nullop else { setvar peractor1 26 move COMMGETVELSBACK faceplayer } } else
	ifmove COMMSLOW { setvar peractor1 26 move COMMSLOWBACK faceplayer } else
	ifmove TANKFORWARD { setvar peractor1 26 move TANKFORWARDBACK faceplayer } else
	ifmove NEWBEASTWALKVEL { setvar peractor1 26 move NEWBEASTWALKVELBACK faceplayer } else
	ifmove NEWBEASTRUNVEL { setvar peractor1 26 move NEWBEASTRUNVELBACK faceplayer } else
	ifmove NEWBEASTJUMPVEL { setvar peractor1 26 move NEWBEASTJUMPVELBACK jumptoplayer }
	ifvare peractor1 26 ifrnd 192 setvar peractor1 0
  }
	
}
ifvarand monstflags 8192
{
	setvar temp 0
	ifaction ATROOPJETPACK setvar temp 1
	ifaction ATROOPJETPACKILL setvar temp 1
	ifaction ALIZJUMP setvar temp 1
	ifaction ALIZFALL setvar temp 1
	ifaction ANEWBEASTJUMP setvar temp 1
	ifaction ANEWBEASTFALL setvar temp 1
	ifvare temp 0
	{
		setactor[THISACTOR].htcgg 0
		state getfloorz
	    getactor[THISACTOR].z mz
	    subvarvar z mz
		getsector[THISACTOR].lotag tempb
	    ifvare tempb 1 subvar monstflags 8192 else
	    ifvarn monstatus 0 ifvarl hp 1 subvar monstflags 8192 
		iffloordistl 8 ifawayfromwall ifvarl z 2048
		{
			getactor[THISACTOR].x initx
			getactor[THISACTOR].y inity
			getactor[THISACTOR].z initz
			ifvarg peractor1 0 subvar peractor1 1
		}
		else
		{
			updatesectorz initx inity initz temp
			ifvarn temp -1
			{
				setactor[THISACTOR].x initx
				setactor[THISACTOR].y inity
				setactor[THISACTOR].z initz
				changespritesect THISACTOR temp
				setvar peractor1 27
			}
		}
	}
}
break

case RECON

ifvare monstatus 0
{
	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 RECONDP
ifvarand monstflags 1 changespritestat THISACTOR 1
//ifvarg locators 0 changespritestat THISACTOR 1
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 RPG
case RPGNOAIM

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
			}
		}
	}
}
ifvare effects YES
{
	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
		}
	}
}
break

case COOLEXPLOSION1

getactor[THISACTOR].statnum temp
ifvare temp 4
{
	addvar countvar 1
	ifvarg countvar 78
	{
		setactor[THISACTOR].xrepeat 0
		setactor[THISACTOR].yrepeat 0
		killit
	}
	findnearactorz BOTALLY 768 8192 spriteid
	ifvare spriteid -1 ifvarn playerally 0
	{
		findnearactorz SHOOTME 1280 10240 temp
		ifvarn temp -1 getactorvar[temp].myspawner spriteid
	}
	
	ifvarn spriteid -1
	{
		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
ifvarn target -1
state guideit
break

case FIREBULLET
ifvare countvar 0
{
	getactor[THISACTOR].yvel temp
	ifvarl temp 3 // bounced once
	{
		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 { addvar picnum 1 setactor[THISACTOR].picnum picnum }
		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
{
	ifrnd 32 state random_wall_jibs
	ifvare effects YES ifrnd 48 //96
	{ 
		espawn NEWBLOOD1
		getactor[THISACTOR].pal pal
		setactor[RETURN].pal pal
	}
	state checkfloordist
	ifvarl temp 2048
	{
		setvar mtype 1
		addvar picnum 1
		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 { 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 JIBS1
case JIBS2
case JIBS3
case JIBS4
case JIBS5
ifvare mtype 0
{
	ifrnd 32 state random_wall_jibs
	ifvare effects YES ifrnd 48 //96
	{
		espawn NEWBLOOD1
		getactor[THISACTOR].pal pal
		setactor[RETURN].pal pal
	}
	state checkfloordist
	ifvarl temp 2048
	{
		getactor[THISACTOR].picnum picnum
		setvar mtype 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 { 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

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

endevent


onevent EVENT_KILLIT

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

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

case FIRELASER
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 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
endswitch
	
ifactor RPGNOAIM { ifvare weap 1 cactor RPG setvar peractor1 2 }
ifactor RPG
{
	ifvare effects YES 
	{
		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
			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 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[mysector].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[mysector].ceilingstat tempb
		   ifvarand tempb 1 nullop else ifvarand tempb 2 nullop else
		   {
			   state scorchfloor
			   setactorvar[RETURN].hitag 1
		   } 
		   // ceiling decal 
		}
 	}
 	setvar RETURN 0

}


endevent

onevent EVENT_CHEATGETJETPACK

ifvare akimbo -1 state changeakimbo
ifvare usemossberg YES
orvar ALTSHOTGUN 1
else orvar ALTSHOTGUN 16
orvar ALTSHOTGUN 2
setvar MP5INCLIP 30
setvar SHOTGUNCLIP 8

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 
	}
	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
ifmultiplayer nullop else
ifvarvare lastinput timer nullop else
{
	setvarvar lastinput timer
	
	ifvare menutoggle 0 
	{
		sound INTO_MENU 
		setvar menutoggle 1 
	} 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 ifvare lighting 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

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

ifp pshrunk nullop else
ifvare superkicking 0 ifvarg kickenergy 130
{
	 setvar temp 0
	 ifvarg fhold 1 setvar temp 1
	 ifvarg ftap 0 setvar temp 1
	 ifvarg btap 0 { setvar temp 1 setvar spinkick 1 getplayer[THISACTOR].ang dodgeang }
	 ifvarg bhold 0 { setvar temp 1 setvar spinkick 1 getplayer[THISACTOR].ang dodgeang }
	 getplayer[THISACTOR].somethingonplayer tempb
	 ifvarn tempb -1 setvar temp 0
	 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 superkicking 0 setvar RETURN -1

state checksuperkick

endevent


onevent EVENT_DISPLAYROOMS

ifvarg backview 0
{
	switch backview
	
	case 52 addvar cameraang 128 break
	case 51 addvar cameraang 256 break
	case 50 addvar cameraang 384 break
	case 49 addvar cameraang 512 break
	case 48 addvar cameraang 640 break
	case 47 addvar cameraang 768 break
	case 46 addvar cameraang 896 break
	
	case 7 addvar cameraang 896 break
	case 6 addvar cameraang 768 break
	case 5 addvar cameraang 640 break
	case 4 addvar cameraang 512 break
	case 3 addvar cameraang 384 break
	case 2 addvar cameraang 256 break
	case 1 addvar cameraang 128 break
	
	default addvar cameraang 1024 break
	
	endswitch
}
endevent


onevent EVENT_JUMP

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
	sound DUKE_GRUNT
}
	

endevent

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

onevent EVENT_CROUCH
//ifvarg underwater 0 setvar RETURN -1
endevent

onevent EVENT_PROCESSINPUT

ifsound PIPEBOMB_EXPLODE
{
	stopsound PIPEBOMB_EXPLODE
	randvar 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
	randvar 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

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 
{
	
 	ifvare CURRWEAP 1 ifvare KICKBACKPIC 0 ifvarvarl botclip WEAPON1_CLIP
	{
		getplayer[THISACTOR].ammo_amount 1 tempb
		ifvarg akimbo -2 ifvarl akimbo 2 ifvarvarg tempb botclip
		{
				ifvare akimbo -1 setvar WEAPON1_RELOAD 27 else
				ifvare akimbo 0 setvar WEAPON1_RELOAD 27 
				else setvar WEAPON1_RELOAD 48
				setplayer[THISACTOR].reloading 1
				setplayer[THISACTOR].kickback_pic 9
				sound EJECT_CLIP
				setvar PISTOLRELOAD 1
				setvar reloadonce 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
		}	
	}
	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
	{
		getplayer[THISACTOR].weapon_pos temp
		ifvare temp 0
		{
			getplayer[THISACTOR].ammo_amount 4 temp
			ifvarg temp 0
			{
				setplayer[THISACTOR].kickback_pic 1
				setvar WEAPON4_FIRESOUND WHOOSH	
			}
		}
	}
}
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
		}
	}
	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 sleeping 0 { setvar RETURN -1 break }
ifvarn mantling 0 { setvar RETURN -1 break }
ifvarn menutoggle 0 { setvar RETURN -1 break }
ifvare CURRWEAP 0 state checksuperkick
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 useakimbo YES
{
	ifvare CURRWEAP 1
	{
		ifvarg akimbo 1 setvar RETURN -1
		ifvarl akimbo -1 setvar RETURN -1
	}
}

ifvare CURRWEAP 1
	ifvarl botclip 1 setvar RETURN -1

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 3 ifvare usemp5 YES
	ifvarl MP5INCLIP 1 setvar RETURN -1 


endevent

state sidekickcoords

ifoutside getsector[THISACTOR].ceilingshade shade else
getsector[THISACTOR].floorshade shade

	ifvarl superkicking 4
	{
		setvar picnum 3523
		//setvar shade 16
		setvar angvar 0
		switch superkicking
		
		case 1
		setvar digy 187
		setvar digx 160
		break
		case 2
		setvar digy 184
		setvar digx 140
		break
		case 3
		setvar digy 182
		setvar digx 120
		break
		endswitch

	}
	else ifvarl superkicking 8
	{
		//setvar shade 10
		setvar picnum 3524
		switch superkicking
		case 4
			setvar digx 110
			setvar digy 200
			setvar angvar 64
		break
		case 5
		
			setvar digx 90
			setvar digy 200
			setvar angvar 28
		break
		case 6
		
			setvar digx 70
			setvar digy 198
			setvar angvar 20
		break
		
		case 7
			setvar digx 77
			setvar digy 192
			setvar angvar 12
		break
	    endswitch
	}
	else
	{
		//setvar shade 6
		setvar picnum 3525
		switch superkicking
		
		case 8
			setvar digx 150
			setvar digy 185
			setvar angvar 0
		break
		
		case 9
			setvar digx 155
			setvar digy 180
			setvar angvar 2032
		break
		
		case 10
			setvar digx 160
			setvar digy 175
			setvar angvar 2016
		break
		
		case 11
		case 12
			setvar digx 170
			setvar digy 170
			setvar angvar 0
		break
		
		endswitch
	}
ends

state spinkickcoords

ifoutside getsector[THISACTOR].ceilingshade shade else
getsector[THISACTOR].floorshade shade

	ifvarl superkicking 4
	{
		setvar picnum 3523
		//setvar shade 16
		setvar angvar 0
		switch superkicking
		case 1
		ifvare superkickdone 1 setvar digx 300 else	
		setvar digx 160
		setvar digy 187
		break
		case 2
		ifvare superkickdone 1 setvar digx 290 else
		setvar digx 140	
		setvar digy 184

		break
		case 3
		ifvare superkickdone 1 setvar digx 280 else			
		setvar digx 120
		setvar digy 182
		break
		endswitch

	}
	else ifvarl superkicking 9
	{
		//setvar shade 10
		setvar picnum 3524
		switch superkicking
		case 4
			ifvare superkickdone 1 setvar digx 270 else			
			setvar digx 65
			setvar digy 200
			setvar angvar 64
		break
		case 5
			ifvare superkickdone 1 setvar digx 260 else			
			setvar digx 68
			setvar digy 200
			setvar angvar 28
		break
		case 6
			ifvare superkickdone 1 setvar digx 250 else			
			setvar digx 72
			setvar digy 198
			setvar angvar 20
		break
		
		case 7
			ifvare superkickdone 1 setvar digx 240 else		
			setvar digx 76
			setvar digy 194
			setvar angvar 12
		 break
		case 8
			ifvare superkickdone 1 setvar digx 230 else		
			setvar digx 80
			setvar digy 190
			setvar angvar 12
		break
	    endswitch
	}
	else
	{
		//setvar shade 6
		setvar picnum 3525
		switch superkicking
		
		case 9
			ifvare superkickdone 1 setvar digx 220 else	
			setvar digx 100
			setvar digy 185
			setvar angvar 0
		break
		
		case 10
			ifvare superkickdone 1 setvar digx 205 else
			setvar digx 120
			setvar digy 165
			setvar angvar 2032
		break
		
		case 11
			ifvare superkickdone 1 setvar digx 190 else
			setvar digx 140
			setvar digy 170
			setvar angvar 2016
		break
		
		case 12
			ifvare superkickdone 1 setvar digx 175 else
			setvar digx 160
			setvar digy 165
			setvar angvar 0
		break
		
		case 13
			setvar digx 170
			setvar digy 165
			setvar angvar 0
		break
		
		endswitch
	}
ends


state adjustrightpos
subvarvar digx looking_angSR1
addvarvar digy looking_arc
subvarvar digy gun_pos
addvarvar digx weapon_xoffset
ends

state adjustleftpos

ifvarn weapswitch 0 { state adjustrightpos break }
addvarvar digx looking_angSR1
addvarvar digy looking_arc
subvarvar digy gun_pos
subvarvar digx weapon_xoffset
addvar digx 22
ends


state idleakimbo

// LEFTPISTOL
setvar digx 90
setvar digy 244
ifvarg C 4 subvar digy 16
state adjustleftpos
ifvarn akimbo 0 ifvarn akimbo 1
{
	setvarvar temp akimbo
	ifvarl akimbo -1 
	{ 
		mulvar temp -1 
		setvar tempb 10
		subvarvar tempb temp 
		setvarvar temp tempb 
	}
	mulvar temp 6
	addvarvar digy temp
}
setvar picnum 2524
setvar orientation 4
rotatesprite digx digy digz 1024 picnum shade pal orientation 0 0 xdim ydim

// RIGHT PISTOL
setvar orientation 0
setvar digx 90
setvar digy 244
ifvarg C 4 subvar digy 16
state adjustrightpos
addvar digx 120
ifvarn akimbo 0 ifvarn akimbo 1
{
	ifvarl akimbo -1 subvar digx 42
	setvarvar temp akimbo
	mulvar temp 5
	subvarvar digx temp
	ifvarl digx 195 setvar digx 195
}
rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim

ends

state initweapondisplay
 setvar digx 140
 setvar digy 230
 setvar digz 28672
 setvar angvar 0
 setvar orientation 0

subvarvar digx looking_angSR1
addvarvar digy looking_arc
subvarvar digy gun_pos
addvarvar digx weapon_xoffset

ifvare CURRWEAP 2 
{
	subvar digy 285
	ifvare digy 0 setvar digy 1
	divvar digy 2
	addvar digy 230
}

ifoutside getsector[THISACTOR].ceilingshade shade else
getsector[THISACTOR].floorshade shade
getsector[THISACTOR].floorpal pal
ends

state displayshells

ifvare SHOTGUNCLIP 0 break
setvar pal 0
setvar orientation 0
setvar picnum 8613
setvar digx 10
setvar digy 150
setvar digz 6144
setvar shade 15

rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
setvarvar tempb SHOTGUNCLIP
setvar temp 0
whilevarn tempb 0
{
	  rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
	  addvar digx 10
	  subvar tempb 1
	  addvar temp 1
	  ifvare temp 4
	  {
		  subvar digy 10 subvar digx 40
	  }
	  
	  break
}

ends

state displaydbshotgun

state initweapondisplay

setvar digz 131072

ifvare weaponcount 0 setvar picnum 8826
else 
{
// first display firing sequence, then IF there is ammo, go through the reload animation

// beginning of firing sequence
// firing and return to center takes 16 ticks

	//ifvare WEAPON2_SHOOTS NOTHING { state dbmeleedisplay break }

	ifvarl weaponcount 4
	{
		setvar picnum 8826
	} else
	ifvarl weaponcount 16
	{
		ifvarl weaponcount 8 // muzzleflash
		{
			setvar shade 0
			subvar digy 80
			setvar orientation 1
			ifvarg weaponcount 5 setvar orientation 33
			setvar digz 40960
			setvar picnum 8831
			displayrandvar angvar 2047
			rotatesprite digx digy digz angvar picnum shade pal orientation 0 0 xdim ydim
			addvar digx 30
			displayrandvar angvar 2047
			rotatesprite digx digy digz angvar picnum shade pal orientation 0 0 xdim ydim
			state initweapondisplay
			setvar shade 0
			setvar digz 131072
		}
		setvar picnum 8827
	}
	else
	setvarvar picnum dbpicnum // depends on ammo left
	
}

rotatesprite digx digy digz angvar picnum shade pal orientation 0 0 xdim ydim

ends

state displaymossberg

state initweapondisplay
setvar digz 131072

//the repeating part of the reload animation takes 17 ticks total
// SHOTGUNCLIP is 0 when reloading begins; add 1 to it each time the repeating animation plays
// then when the reload is over

ifvare FAKERELOAD 0
{
	ifvarl weaponcount 2
	setvar picnum 8840
	else 
	{
		ifvarl weaponcount 8 // muzzleflash
		{
			setvar shade 0
			addvar digx 25
			subvar digy 70
			setvar orientation 1
			ifvarg weaponcount 4 setvar orientation 33
			setvar digz 40960
			setvar picnum 8831
			displayrandvar angvar 128
			subvar angvar 64
			rotatesprite digx digy digz angvar picnum shade pal orientation 0 0 xdim ydim
			
			state initweapondisplay
			setvar shade 0
			setvar digz 131072
		}
		setvar picnum 8841
	}
	
}
else

ifvarn FAKERELOAD 0 setvarvar picnum reloadpicnum
rotatesprite digx digy digz angvar picnum shade pal orientation 0 0 xdim ydim

state displayshells

ends

state displaypistolbullets

ifvare botclip 0 break
setvar pal 0
setvar orientation 0
setvar picnum SHELL
setvar digx 5
setvar digy 152
setvar digz 16384
setvar shade 0

rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
setvarvar tempb botclip
setvar temp 0
whilevarn tempb 0
{
	  rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
	  addvar digx 4
	  subvar tempb 1
	  addvar temp 1
	  ifvare temp 6 { subvar digy 4 subvar digx 24 }
	  else ifvare temp 12 { subvar digy 4 subvar digx 24 }
	  else ifvare temp 18 { subvar digy 4 subvar digx 24 }
	  else ifvare temp 24 { subvar digy 4 subvar digx 24 }
	  
	  break
}

ends


state displaymp5bullets
ifvare MP5INCLIP 0 break
setvar pal 0
setvar orientation 0
setvar picnum SHELL
setvar digx 5
setvar digy 152
setvar digz 16384
setvar shade 0

rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
setvarvar tempb MP5INCLIP
setvar temp 0
whilevarn tempb 0
{
	  rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
	  addvar digx 4
	  subvar tempb 1
	  addvar temp 1
	  ifvare temp 6 { subvar digy 4 subvar digx 24 }
	  else ifvare temp 12 { subvar digy 4 subvar digx 24 }
	  else ifvare temp 18 { subvar digy 4 subvar digx 24 }
	  else ifvare temp 24 { subvar digy 4 subvar digx 24 }
	  
	  break
}

ends

state displaymp5

state initweapondisplay

setvar digz 131072

ifvarg FAKERELOAD 0 
{
	ifvarl FAKERELOAD 40 setvar picnum 8837 else
	setvar picnum 8838
	ifvarg FAKERELOAD 47 // vertical position correction, so it ends up in the idle position after reload
	{
		setvarvar temp FAKERELOAD
		subvar temp 47
		addvarvar digy temp
	}
}
else
ifvare weaponcount 0
setvar picnum 8835
else 
ifvare WEAPON3_SHOOTS NOTHING setvar picnum 8839 else
{
	displayrandvar temp 8
	subvar temp 4
	addvarvar digx temp
		ifvarl weaponcount 3 // muzzleflash
		{
			setvar shade 0
			addvar digx 15
			subvar digy 60
			setvar orientation 1
			ifvarg weaponcount 5 setvar orientation 33
			setvar digz 32768
			setvar picnum 8831
			displayrandvar angvar 2047
			rotatesprite digx digy digz angvar picnum shade pal orientation 0 0 xdim ydim
			state initweapondisplay
			setvar digz 131072
			ifvare weaponcount 1 setvar shade -127
		}
	setvar picnum 8836 // regular firing
}
// 8837 RELOAD part 1
// 8838 RELOAD part 2
// 8839 COLDCOCK

rotatesprite digx digy digz angvar picnum shade pal orientation 0 0 xdim ydim

state displaymp5bullets

ends

state displaydukeballs

setvar pal 0
setvar orientation 0
gametextz 2822 565 122 1091 0 7 0 0 0 xdim ydim 24576
setvarvar temp dukeballselected
addvar temp 1
digitalnumberz 2837 315 122 temp 0 7 0 0 0 xdim ydim 24576
rotatesprite 300 140 67584 0 183 0 pal orientation 0 0 xdim ydim

setvarvar picnum dukeballpics[dukeballselected]
ifvare picnum 0
{
	gametextz 2822 582 136 1092 0 0 0 0 0 xdim ydim 40960
	gametextz 2822 580 148 1093 0 2 1 0 0 xdim ydim 24576
	digitalnumberz 2837 302 151 dukeballstrength 0 2 1 0 0 xdim ydim 24576
}
else
{
	setvarvar pal dukeballpals[dukeballselected]
	setvar orientation 2
	rotatesprite 300 140 16384 0 picnum 0 pal orientation 0 0 xdim ydim
}

ends

state displaykicks
// superkick display
getplayer[THISACTOR].over_shoulder_on temp
ifvarn superkicking 0 ifvare temp 0
{

	setvar orientation 0
	//setvar pal 0
	getsector[THISACTOR].floorpal pal
	setvar angvar 0
	//setvar digz 34816
	setvar digz 32768
	ifvare spinkick 0 state sidekickcoords
	else state spinkickcoords
	getuserdef[THISACTOR].screen_size C
	ifvarg C 4 subvar digy 16
	rotatesprite digx digy digz angvar picnum shade orientation pal 0 0 xdim ydim
}
ends

onevent EVENT_DRAWWEAPON




setvar temp MANTLING
ifvare temp YES ifvarn mantling 0 { setvar RETURN -1 break }

ifvarg superkicking 0 
{ 
	state displaykicks 
	ifvare currentweapon 1 state displaypistolbullets
	ifvare currentweapon 2 ifvare usemossberg YES state displayshells
	ifvare currentweapon 3 ifvare usemp5 YES state displaymp5bullets
	setvar RETURN -1 
	break
}

ifvarn holding -1 ifvare gravitysprite -1
{
	setvar RETURN -1 break 
}

ifvare currentweapon 1 state displaypistolbullets


ifvare currentweapon 2
{
	ifvarand ALTSHOTGUN 4 state displaydbshotgun else
	ifvare usemossberg NO break else
	state displaymossberg
	setvar RETURN -1
}
ifvare currentweapon 3 ifvare usemp5 YES
{
	setvar RETURN -1
	state displaymp5
}
ifvare CURRWEAP 8 ifvare dukemon YES
{
	getplayer[THISACTOR].ammo_amount 8 temp
	ifvare temp 0 { setvar RETURN -1 break }
	state displaydukeballs
}

ifvare useakimbo YES nullop else break

getsector[THISACTOR].floorshade shade
getsector[THISACTOR].floorpal pal
setvar digz 65536
getuserdef[THISACTOR].screen_size C

ifvare currentweapon 1 ifvarn akimbo -1 ifvarn akimbo 0
{
	setvar RETURN -1
	
	switch weaponcount
	case 0 case 1 // idle frame
		state idleakimbo
	break
	

	case 2 case 3 // right gun fires
		setvar digx 90
		setvar digy 244
		ifvarg C 4 subvar digy 16
		state adjustleftpos
		setvar picnum 2524 // LEFTPISTOL
		setvar orientation 4
		rotatesprite digx digy digz 1024 picnum shade pal orientation 0 0 xdim ydim
		setvar picnum 2525 // RIGHT PISTOL FIRING
		ifvare weaponcount 3 addvar picnum 1
		setvar orientation 0
		setvar digx 90
		setvar digy 244
		ifvarg C 4 subvar digy 16
		state adjustrightpos
		addvar digx 120
		setvar shade -127
		rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
	break
	
	case 4 case 5
	state idleakimbo
	break
	
		
	case 6 case 7 // left gun is firing
		setvar digx 90
		setvar digy 244
		ifvarg C 4 subvar digy 16
		state adjustleftpos
		setvar picnum 2525 // LEFTPISTOL
		ifvare weaponcount 7 addvar picnum 1
		setvar orientation 4
		setvar shade -127
		rotatesprite digx digy digz 1024 picnum shade pal orientation 0 0 xdim ydim
		setvar picnum 2524 // RIGHT PISTOL
		setvar orientation 0
		setvar digx 90
		setvar digy 244
		ifvarg C 4 subvar digy 16
		state adjustrightpos
		addvar digx 120
		getsector[THISACTOR].floorshade shade
		rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
	break
	
	case 8 state idleakimbo break
	
	case 9 case 10 case 11 case 12 case 13 case 14 case 15 case 16 case 17
	case 18 case 19 case 20 case 21 case 22 case 23 case 24 case 25 case 26
		setvar digx 90
		setvar digy 238
		ifvarg C 4 subvar digy 14
		state adjustrightpos
		setvar orientation 4
		ifvarl weaponcount 13 // LEFT PISTOL IS GOING DOWN
		{
			setvar picnum 2524 // LEFTPISTOL
			setvarvar temp weaponcount
			subvar temp 7
			mulvar temp 6
			addvarvar digy temp
			rotatesprite digx digy digz 1024 picnum shade pal orientation 0 0 xdim ydim
		}
		else ifvarg weaponcount 17 // clip hand and clip for reloading the right pistol
		{
			addvar digx 70
			addvar digy 122
			setvarvar temp weaponcount
			mulvar temp 5
			subvarvar digy temp
			setvar orientation 0
			ifvarl weaponcount 21 setvar picnum 2531 else
			setvar picnum 2532
			rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
			
			ifvarg weaponcount 20 ifvarl weaponcount 24 // the clip
			{
				setvar picnum 2530
				addvar digx 20
				rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
			}
		}
		setvar digx 90
		setvar digy 238
		ifvarg C 4 subvar digy 14
		state adjustrightpos
		setvar picnum 2528 // RIGHT PISTOL RELOAD 1
		ifvarg weaponcount 15
		{
			setvar picnum 2529 
			subvar digy 40
			addvarvar digy weaponcount
		}
		setvar orientation 0
		addvar digx 120
		rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
	break
	
	case 27 case 28 case 29 case 30 case 31 case 32 case 33 case 34 case 35 case 36
	case 37 case 38 case 39 case 40 case 41 case 42 case 43 
	case 44 case 45
	//case 46 case 47 case 48
	
		setvar digx 90
		setvar digy 238
		ifvarg C 4 subvar digy 14
		state adjustrightpos
		setvar orientation 4
		ifvarl weaponcount 32  // right pistol is going down
		{
			setvar picnum 2524 // RIGHT PISTOL
			setvar orientation 0
			addvar digx 120
			setvarvar temp weaponcount
			subvar temp 26
			mulvar temp 6
			addvarvar digy temp
			rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
		}
		else ifvarg weaponcount 36 // clip hand and clip for reloading left pistol
		{
			setvar picnum 2532
			addvar digx 40
			setvarvar temp weaponcount
			//subvar temp 26
			subvar temp 19
			mulvar temp 5
			addvar digy 120
			subvarvar digy temp
			ifvarl weaponcount 40 setvar picnum 2531 else
			setvar picnum 2532
			rotatesprite digx digy digz 1024 picnum shade pal orientation 0 0 xdim ydim
			
			ifvarg weaponcount 39 ifvarl weaponcount 43 // the clip
			{
				setvar picnum 2530
				subvar digx 10
				subvar digy 10
				rotatesprite digx digy digz 1024 picnum shade pal orientation 0 0 xdim ydim
			}
			
		}
		setvar digx 90
		setvar digy 238
		ifvarg C 4 subvar digy 14
		state adjustrightpos
		
		setvar picnum 2528 // LEFT PISTOL RELOAD 1
		ifvarg weaponcount 34
		{
			setvar picnum 2529 // LEFT PISTOL RELOAD 2
			subvar digy 59
			addvarvar digy weaponcount
		}
		setvar orientation 4
		rotatesprite digx digy digz 1024 picnum shade pal orientation 0 0 xdim ydim
	break
	
	default
		state idleakimbo
	break
	
	endswitch
}

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
	{
		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_RETURNTOCENTER


getplayer[THISACTOR].hard_landing temp
ifvare temp 0
{
	setvar RETURN -1
	
	ifvarn FAKERELOAD 0 setvar RETURN -1
	ifvarn PISTOLRELOAD 0 setvar RETURN -1
	ifvare gravgun YES ifvare CURRWEAP 11 setvar RETURN -1
	
	ifvare CURRWEAP 7 ifvarn devshotty NO
	{
		
		getplayer[THISACTOR].weapon_pos temp
		ifvare temp 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

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
	{
		mulvar ANGRANGE 2
		mulvar ZRANGE 2
	}
}
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
{
	ifvare usemp5 YES 
	{
		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
{
	setvar ANGRANGE 64
	setvar ZRANGE 512
}
ifvare CURRWEAP 11 ifvare gravgun YES
{
	setvar ANGRANGE 1
	setvar ZRANGE 1
}
endevent

state shadepulse
setvarvar temp timer
shiftvarl temp 7
sin tempb temp
shiftvarr tempb 11
setvarvar shade tempb
ends

onevent EVENT_DISPLAYCROSSHAIR

ifvarn menutoggle 0 setvar RETURN -1

endevent

state quotedisplay

// ifvare quotestyle 0
// {
// 	getplayer[THISACTOR].fta temp
// 	getplayer[THISACTOR].ftq tempb
// 	ifvarg temp 0
// 	{
// 		ifvare tempb 9
// 		{
// 			setplayer[THISACTOR].fta 0
// 			setvar temp 9
// 			state enterquotearray
// 		}
// 		else ifvare tempb 80
// 		{
// 			setplayer[THISACTOR].fta 0
// 		}
// 	}
// 	setvarvar temp ftscalearray[0]
// 	ifvarg temp 0
// 	{
// 		setvar tempc 0
// 		whilevarn tempc 5
// 		{
// 			setvarvar temp ftscalearray[tempc]
// 			ifvarg temp 0
// 			{
// 				setvar pal 0
// 				setvar orientation 0
// 				setvar tempd 32767 //65536
// 				setvarvar tempb framerate
// 				ifvare tempb 0 setvar tempb 60
// 				divvarvar tempd tempb
// 				subvarvar temp tempd
// 				ifvarl temp 0 setvar temp 0
// 				setarray ftscalearray[tempc] temp
// 				setvarvar digy temp
// 				shiftvarr digy 12
// 				//subvar digy 5	
// 				setvarvar tempe ftqarray[tempc]
// 				ifvarl temp 49152 setvar temp 49152 // 32768
// 				gametextz 2822 320 digy tempe 0 pal orientation 0 0 xdim ydim temp
// 			}
// 			addvar tempc 1
// 		}
// 	}
// }

ifvarg fta 0
{
	
	setvar orientation 0
	setvar digy 5
	getplayer[THISACTOR].fta temp
	ifvarg temp 0 addvar digy 10
	setvarvar shade fta
	modvar shade 25
	ifvarl shade 13 mulvar shade 2 else
	ifvare shade 13 setvar shade 24 else
	{ subvar shade 12 setvar temp 13 subvarvar temp shade mulvar temp 2 setvarvar shade temp }
	ifvarl fta 27
	{
		ifvarg shade 2 orvar orientation 1
		ifvarg shade 12 orvar orientation 32
	}
	gametext 2822 320 digy ftq shade 0 orientation 0 0 xdim ydim
	ifvarl fta 26 ifvare shade 24 setvar fta 0
}

ifvarn quoterid -1
{
	setvar digx 160
	setvar digy 100
	getactorvar[quoterid].initx mx
	ifvare mx 0 setvar digx 320 else
	addvarvar digx mx
	getactorvar[quoterid].inity my
	addvarvar digy my
	getactorvar[quoterid].hitag temp
	getactor[quoterid].pal pal
	getactor[quoterid].cstat tempb
	ifvarand tempb 512 setvar orientation 33 else ifvarand tempb 2 setvar orientation 1 else setvar orientation 0
	getactorvar[quoterid].initz digz
	gametextz 2822 320 digy temp 0 pal orientation 0 0 xdim ydim digz
}
ifvarn quoteridpic -1
{
	setvar digx 160
	setvar digy 100
	getactorvar[quoteridpic].initx mx
	//ifvare mx 0 setvar digx 320 else
	addvarvar digx mx
	getactorvar[quoteridpic].inity my
	addvarvar digy my
	getactorvar[quoteridpic].hitag temp
	getactor[quoteridpic].pal pal
	getactor[quoteridpic].cstat tempb
	ifvarand tempb 512 setvar orientation 33 else ifvarand tempb 2 setvar orientation 1 else setvar orientation 0
	getactorvar[quoteridpic].initz digz
	getactor[quoteridpic].ang angvar
	addvar angvar 512
	rotatesprite digx digy digz angvar temp 0 pal orientation 0 0 xdim ydim
}

ends

onevent EVENT_DISPLAYMENUREST
getplayer[THISACTOR].gm temp
ifvarand temp 4 nullop else
rotatesprite 40 190 8192 0 3504 0 0 0 0 0 xdim ydim

endevent

onevent EVENT_DISPLAYREST

//debugging var display
//    setvar digx 150
//    setvar digy 14
//    setvar picnum 3010
//    digitalnumber picnum digx digy debugvar shade pal orientation 0 0 xdim ydim
//    addvar digy 8
//    digitalnumber picnum digx digy debugvarb shade pal orientation 0 0 xdim ydim
//    addvar digy 8
//    digitalnumber picnum digx digy debugvarc shade pal orientation 0 0 xdim ydim
//    addvar digy 8
//    digitalnumber picnum digx digy debugvard shade pal orientation 0 0 xdim ydim
//   addvar digy 8
//   digitalnumber picnum digx digy debugvare shade pal orientation 0 0 xdim ydim
//   addvar digy 8
//   digitalnumber picnum digx digy debugvarf shade pal orientation 0 0 xdim ydim

ifvarl timer 260
	gametextz 2822 595 5 1013 0 0 0 0 0 xdim ydim 32768

state quotedisplay

ifvarn menutoggle 0
{
	setvar digx 160
	setvar digy 90
	setvar digz 40960 //32768
	setvar shade 0
	setvar pal 0
	setvar orientation 0
	// make the background optional
	//rotatesprite digx digy digz 0 3497 shade pal 33 0 0 xdim ydim
	ifvare menutoggle 1 // main menu
	{
		rotatesprite 128 32 16384 0 3504 0 0 0 0 0 xdim ydim
		setvar picnum 2822 // regular font
		ifvare menuitem 0 state shadepulse else setvar shade 0
		gametextz picnum 170 50 1017 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 1 state shadepulse else setvar shade 0
		gametextz picnum 170 60 1018 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 2 state shadepulse else setvar shade 0
		gametextz picnum 170 70 1019 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 3 state shadepulse else setvar shade 0
		gametextz picnum 170 80 1020 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 4 state shadepulse else setvar shade 0
		gametextz picnum 170 90 1021 shade 0 orientation 0 0 xdim ydim 40960
		// menunag YES or NO
		ifvare menunag YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 90 temp shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 5 state shadepulse else setvar shade 0 // restore DUKE PLUS defaults
		gametextz picnum 170 100 1070 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 6 state shadepulse else setvar shade 0 // restore CLASSIC defaults
		gametextz picnum 170 110 1080 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 7 state shadepulse else setvar shade 0
		gametextz picnum 170 120 1022 shade 2 orientation 0 0 xdim ydim 40960 // return to game
		gametextz picnum 220 152 1066 0 2 orientation 0 0 xdim ydim 40960 // instructions
		gametextz picnum 220 160 1057 0 2 orientation 0 0 xdim ydim 40960 // instructions
		
	} else
	ifvare menutoggle 2 // weapons submenu
	{
		//gametextz picnum x y quote shade pal orientation 0 0 xdim ydim scale
		setvar picnum 2822 // regular font
		gametextz picnum 170 33 1023 shade 0 orientation 0 0 xdim ydim 65536
		
		// akimbo pistols YES or NO
		ifvare menuitem 10 state shadepulse else setvar shade 0
		gametextz picnum 170 50 1024 shade 0 orientation 0 0 xdim ydim 40960
		ifvare useakimbo YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 50 temp shade 0 orientation 0 0 xdim ydim 40960
		// mossberg YES or NO
		ifvare menuitem 11 state shadepulse else setvar shade 0
		gametextz picnum 170 60 1025 shade 0 orientation 0 0 xdim ydim 40960
		ifvare usemossberg YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 60 temp shade 0 orientation 0 0 xdim ydim 40960
		// mp5 YES or NO
		ifvare menuitem 12 state shadepulse else setvar shade 0
		gametextz picnum 170 70 1026 shade 0 orientation 0 0 xdim ydim 40960
		ifvare usemp5 YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 70 temp shade 0 orientation 0 0 xdim ydim 40960
		// alt RPG YES or NO
		ifvare menuitem 13 state shadepulse else setvar shade 0
		gametextz picnum 170 80 1027 shade 0 orientation 0 0 xdim ydim 40960
		ifvare usebigrox YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 80 temp shade 0 orientation 0 0 xdim ydim 40960
		// mindblast on alt SHRINKER YES or NO
		ifvare menuitem 14 state shadepulse else setvar shade 0
		gametextz picnum 170 90 1081 shade 0 orientation 0 0 xdim ydim 40960
		ifvare usemindblast YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 90 temp shade 0 orientation 0 0 xdim ydim 40960
		// gravity gun YES or NO
		ifvare menuitem 15 state shadepulse else setvar shade 0
		gametextz picnum 170 100 1028 shade 0 orientation 0 0 xdim ydim 40960
		ifvare gravgun YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 100 temp shade 0 orientation 0 0 xdim ydim 40960
		// dev shotty YES or NO
		ifvare menuitem 16 state shadepulse else setvar shade 0
		gametextz picnum 170 110 1085 shade 0 orientation 0 0 xdim ydim 40960
		ifvarn devshotty 0 setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 110 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// dukemon YES or NO
		ifvare menuitem 17 state shadepulse else setvar shade 0
		gametextz picnum 170 120 1095 shade 0 orientation 0 0 xdim ydim 40960
		ifvare dukemon YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 120 temp shade 0 orientation 0 0 xdim ydim 40960
		// knockback distance
		ifvare menuitem 18 state shadepulse else setvar shade 0
		gametextz picnum 170 130 1030 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 130 knockdist shade 0 orientation 0 0 xdim ydim 40960
		// exit menu
		ifvare menuitem 19 state shadepulse else setvar shade 0
		gametextz picnum 170 140 1058 shade 2 orientation 0 0 xdim ydim 40960
	} else
	ifvare menutoggle 3 // abilities submenu
	{
		//gametextz picnum x y quote shade pal orientation 0 0 xdim ydim scale
		//setvar picnum 2908 // red font
		setvar picnum 2822 // regular font
		gametextz picnum 170 33 1033 shade 0 orientation 0 0 xdim ydim 65536
		
		ifvare menuitem 20 state shadepulse else setvar shade 0
		gametextz picnum 170 50 1034 shade 0 orientation 0 0 xdim ydim 40960
		// real running YES or NO
		ifvare slowrunaccel YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 50 temp shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 21 state shadepulse else setvar shade 0
		gametextz picnum 170 60 1035 shade 0 orientation 0 0 xdim ydim 40960
		// mantling YES or NO
		ifvare canmantle YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 60 temp shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 22 state shadepulse else setvar shade 0
		gametextz picnum 170 70 1036 shade 0 orientation 0 0 xdim ydim 40960
		// dodging YES or NO
		ifvare candodge YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 70 temp shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 23 state shadepulse else setvar shade 0
		gametextz picnum 170 80 1037 shade 0 orientation 0 0 xdim ydim 40960
		// grabbing YES or NO
		ifvare cangrab YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 80 temp shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 24 state shadepulse else setvar shade 0
		gametextz picnum 170 90 1038 shade 0 orientation 0 0 xdim ydim 40960
		// store health YES or NO
		ifvare storehealth YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 90 temp shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 25 state shadepulse else setvar shade 0
		gametextz picnum 170 100 1039 shade 0 orientation 0 0 xdim ydim 40960
		// max medkit
		digitalnumberz 2837 240 100 maxmedkit shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 26 state shadepulse else setvar shade 0
		gametextz picnum 170 110 1040 shade 0 orientation 0 0 xdim ydim 40960
		// store health YES or NO
		ifvare steroidkicks YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 110 temp shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 27 state shadepulse else setvar shade 0
		gametextz picnum 170 120 1041 shade 0 orientation 0 0 xdim ydim 40960
		// holoduke lightning YES or NO
		ifvare holodukelightning YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 120 temp shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 28 state shadepulse else setvar shade 0
		gametextz picnum 170 130 1042 shade 0 orientation 0 0 xdim ydim 40960
		// goggles reveal dip switch patterns YES or NO
		ifvare goggleswitches YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 130 temp shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 29 state shadepulse else setvar shade 0
		gametextz picnum 170 140 1058 shade 2 orientation 0 0 xdim ydim 40960
		
	} else
	ifvare menutoggle 4 // monsters submenu
	{
		//gametextz picnum x y quote shade pal orientation 0 0 xdim ydim scale
		setvar picnum 2822 // regular font
		gametextz picnum 170 33 1043 shade 0 orientation 0 0 xdim ydim 65536
		
		ifvare menuitem 30 state shadepulse else setvar shade 0
		gametextz picnum 170 50 1044 shade 0 orientation 0 0 xdim ydim 40960
		// monster life bars YES or NO
		ifvare lifebars YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 50 temp shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 31 state shadepulse else setvar shade 0
		gametextz picnum 170 60 1045 shade 0 orientation 0 0 xdim ydim 40960
		// random attributes
		digitalnumberz 2837 240 60 randomize shade 0 orientation 0 0 xdim ydim 40960
		
		// damage inflicted by monsters
		ifvare menuitem 32 state shadepulse else setvar shade 0
		gametextz picnum 170 70 1068 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 70 mdamage shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 33 state shadepulse else setvar shade 0
		gametextz picnum 170 80 1069 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 80 pdamage shade 0 orientation 0 0 xdim ydim 40960
		
		// monster in-fighting
		ifvare menuitem 34 state shadepulse else setvar shade 0
		gametextz picnum 170 90 1087 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 90 infighting shade 0 orientation 0 0 xdim ydim 40960
		
		// bots YES or NO
		ifvare menuitem 35 state shadepulse else setvar shade 0
		gametextz picnum 170 100 1029 shade 0 orientation 0 0 xdim ydim 40960
		ifvare usebots YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 100 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// double monsters YES or NO
		ifvare menuitem 36 state shadepulse else setvar shade 0
		gametextz picnum 170 110 1098 shade 0 orientation 0 0 xdim ydim 40960
		ifvare doubled YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 110 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// pigcops with db shotguns
		ifvare menuitem 37 state shadepulse else setvar shade 0
		gametextz picnum 170 120 1104 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 120 killerpigs shade 0 orientation 0 0 xdim ydim 40960
		
		// return to main menu
		ifvare menuitem 38 state shadepulse else setvar shade 0
		gametextz picnum 170 130 1058 shade 2 orientation 0 0 xdim ydim 40960
		setvar shade 0
		//gametextz picnum 105 120 1046 shade 0 orientation 0 0 xdim ydim 40960
		
	} else
	ifvare menutoggle 5 // effects submenu
	{
		//gametextz picnum x y quote shade pal orientation 0 0 xdim ydim scale
		setvar picnum 2822 // regular font
		gametextz picnum 170 33 1047 shade 0 orientation 0 0 xdim ydim 65536
		// damage effects YES or NO
		ifvare menuitem 40 state shadepulse else setvar shade 0
		gametextz picnum 170 50 1048 shade 0 orientation 0 0 xdim ydim 40960
		ifvare effects YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 50 temp shade 0 orientation 0 0 xdim ydim 40960
		// weather type RAIN or SNOW
		ifvare menuitem 41 state shadepulse else setvar shade 0
		gametextz picnum 170 60 1049 shade 0 orientation 0 0 xdim ydim 40960
		ifvarl raining 0 setvar temp 1056 else setvar temp 1055
		gametextz picnum 470 60 temp shade 0 orientation 0 0 xdim ydim 40960
		// rain color
		ifvare menuitem 42 state shadepulse else setvar shade 0
		gametextz picnum 170 70 1050 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 70 rainpal shade rainpal orientation 0 0 xdim ydim 40960
		// rain transparency
		ifvare menuitem 43 state shadepulse else setvar shade 0
		gametextz picnum 170 80 1051 shade 0 orientation 0 0 xdim ydim 40960
		ifvarand raincstat 512 setvar temp 1063 else ifvarand raincstat 2 setvar temp 1062
		else setvar temp 1061
		gametextz picnum 470 80 temp shade 0 orientation 0 0 xdim ydim 40960
		// rain amount
		ifvare menuitem 44 state shadepulse else setvar shade 0
		gametextz picnum 170 90 1052 shade 0 orientation 0 0 xdim ydim 40960
		setvarvar temp raining ifvarl temp 0 mulvar temp -1
		digitalnumberz 2837 240 90 temp shade 0 orientation 0 0 xdim ydim 40960
		// rain radius
		ifvare menuitem 45 state shadepulse else setvar shade 0
		gametextz picnum 170 100 1065 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 100 rainradius shade 0 orientation 0 0 xdim ydim 40960
		// map mirroring
		ifvare menuitem 46 state shadepulse else setvar shade 0
		gametextz picnum 170 110 1096 shade 0 orientation 0 0 xdim ydim 40960
		ifvare mirrored YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 110 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// map scaling 2X
		ifvare menuitem 47 state shadepulse else setvar shade 0
		gametextz picnum 170 120 1097 shade 0 orientation 0 0 xdim ydim 40960
		ifvare scaled YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 120 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// DP sounds
		ifvare menuitem 48 state shadepulse else setvar shade 0
		gametextz picnum 170 130 1105 shade 0 orientation 0 0 xdim ydim 40960
		ifvare dpsounds YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 130 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// quote style
		ifvare menuitem 49 state shadepulse else setvar shade 0
		gametextz picnum 170 140 1122 shade 0 orientation 0 0 xdim ydim 40960
		ifvare quotestyle 1 setvar temp 1119 else ifvare quotestyle 0 setvar temp 1121
		else setvar temp 1120
		gametextz picnum 470 140 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// return to main menu
		ifvare menuitem 50 state shadepulse else setvar shade 0
		gametextz picnum 170 150 1058 shade 2 orientation 0 0 xdim ydim 40960
		
		
	}
	ifvarn menutoggle 1
	{
		// instructions
		gametextz picnum 170 162 1031 0 7 orientation 0 0 xdim ydim 32768 //40960
		//gametextz picnum 220 170 1032 0 2 orientation 0 0 xdim ydim 40960
	}
	setvar digx 65
	setvar digz 16384
	setvar shade 0
	setvar pal 0
	setvar orientation 0
	switch menuitem
		case 0
		case 10
		case 20
		case 30
		case 40
		setvar digy 49
		break
		case 1
		case 11
		case 21
		case 31
		case 41
		setvar digy 59
		break
		case 2
		case 12
		case 22
		case 32
		case 42
		setvar digy 69
		break
		case 3
		case 13
		case 23
		case 33
		case 43
		setvar digy 79
		break
		case 4
		case 14
		case 24
		case 34
		case 44
		setvar digy 89
		break
		case 5
		case 15
		case 25
		case 35
		case 45
		setvar digy 99
		break
		case 6
		case 16
		case 26
		case 36
		case 46
		setvar digy 109
		break
		case 7
		case 17
		case 27
		case 37
		case 47
		setvar digy 119
		break
		case 18
		case 28
		case 38
		case 48
		setvar digy 129
		break
		case 19
		case 29
		case 49
		setvar digy 139
		break
		case 50
		setvar digy 149
		break
	endswitch
	rotatesprite digx digy digz 0 headframe shade pal orientation 0 0 xdim ydim
	
}
else ifvare menunag YES
{
	setvarvar temp totalclock
	subvarvar temp ttime
	ifvarn temp 0
	{
		ifvarl temp 0 setvar temp 1
		setvarvar ttime totalclock 
		ifvarg nagpos -1500 subvarvar nagpos temp else setvar nagpos 900
		ifvarg nagpos 319 ifvarl nagpos 322 setvar nagpos 319
	}
	gametextz 2822 nagpos 12 1067 0 0 0 0 0 xdim ydim 65536
}

			
setvar temp OVERHEAT ifvarn usemp5 YES
ifvare temp YES ifvare holding -1 ifvare mantling 0
{
	getuserdef[THISACTOR].drawweapon temp
	getplayer[THISACTOR].knuckle_incs tempb
	getplayer[THISACTOR].newowner tempc
	ifvarg totalclock 1024 ifvarg tempb 0 setvar temp 0
	ifvare temp 1 ifvarg chaingunheat 0 
	ifvare tempc -1 // ifvarl tempd 60
	ifvare currentweapon 3
	{
		setvar digy 164
		setvar digx 3
		setvar digz 16384
		setvar orientation 0
		setvar pal 7
		
		setvarvar tempb chaingunheat
		shiftvarr tempb 5
		setvarvar tempc digx
		addvarvar tempc tempb
		ifvarg chaingunheat 800
		{
			getplayer[THISACTOR].player_par mx
			shiftvarl mx 8
			sin my mx
			shiftvarr my 11
			setvarvar shade my
		} else setvar shade 0
		setvar temp 0
		whilevarn temp 1
		{
			  ifvarvarg digx tempc setvar temp 1
			  rotatesprite digx digy digz 0 199 shade pal orientation 0 0 xdim ydim
			  addvar digx 1
			  break
		}
		ifvarg chaingunheat 300
		{
			subvar digy 1
			ifvarl chaingunheat 500 setvar orientation 33 else ifvarl chaingunheat 650 setvar orientation 1
			setvar pal 0
			setvar digx 8
			setvar digz 22528
			setvar picnum 2908
			setvar temp 1009
			gametextz picnum digx digy temp shade pal orientation 0 0 xdim ydim digz
			// gametextz <tilenum> <x> <y> <quote> <shade> <pal> <orientation> <x1> <y1> <x2> <y2> <z>
		}
		
/*
		setvar digz 30720 // 32768
		ifvarn weaponcount 0 addvar digz 3072 // 5120
		setvar digx 194
		setvar digy 234
		subvarvar digx looking_angSR1
		addvarvar digy looking_arc
		subvarvar digy gun_pos
		switch weaponcount
		case 1 addvar digy 1 break
		case 2 addvar digy 2 subvar digx 1 break
		case 3 addvar digy 3 break
		case 4 addvar digy 4 subvar digx 1 break
		case 5 addvar digy 3 break
		case 6 addvar digy 2 subvar digx 1 break
		case 7 addvar digy 1 break
		case 8 addvar digy 1 subvar digx 1 break
		case 9 addvar digy 0 break
		case 10 addvar digy -1 subvar digx 1 break
		case 11 addvar digy -1 break
		case 12 addvar digy -2 subvar digx 1 break
		endswitch
		ifvare tempd 8 subvar digy 17
		ifvarg tempd 11
		{
			ifvare tempd 20 addvar digy 1
			ifvarg tempd 20 ifvarl tempd 48 addvar digy 2
			ifvare tempd 48 addvar digy 1
			ifvare tempd 56 subvar digy 1
			subvar digy 11
			divvar tempd 2
			subvarvar digy tempd
			
		}
		addvarvar digx weapon_xoffset
 		
		ifvarg chaingunheat 800
		{
			getplayer[THISACTOR].player_par temp
			shiftvarl temp 8
			sin tempb temp
			shiftvarr tempb 11
			setvarvar shade tempb
		}
		else setvar shade -127
		

		ifvarg chaingunheat 900 setvar pal 150 else
		ifvarg chaingunheat 800 setvar pal 151 else
		ifvarg chaingunheat 700 setvar pal 152 else
		ifvarg chaingunheat 600 setvar pal 153 else
		ifvarg chaingunheat 500 setvar pal 154 else
		ifvarg chaingunheat 400 setvar pal 155 else
		ifvarg chaingunheat 300 setvar pal 156 else
		ifvarg chaingunheat 200 setvar pal 157 else
		ifvarg chaingunheat 100 setvar pal 158 else
		setvar pal 159
		ifvare tempd 8 
			ifvarg digy 165 setvar orientation 33
		
		else setvar orientation 1
		rotatesprite digx digy digz 0 8010 shade pal orientation 0 0 xdim ydim
*/

	}
}

getplayer[THISACTOR].airleft tempb
getplayer[THISACTOR].scuba_on tempc
ifvarl tempb 390 ifvarg tempb 0 ifvare tempc 0
{
	setvar digy 10
	setvar digx 30
	setvar digz 16384
	setvar orientation 0
	setvar pal 1
	
	
	divvar tempb 4
	setvarvar tempc digx
	addvarvar tempc tempb
	setvar temp 0
	whilevarn temp 1
	{
		  ifvarvarg digx tempc setvar temp 1
		  rotatesprite digx digy digz 0 199 0 pal orientation 0 0 xdim ydim
		  addvar digx 1
		  break
	}
	setvar pal 0
	setvar digz 32768
	setvar digx 20
	setvar picnum 2868
    rotatesprite digx digy digz 0 picnum 0 pal orientation 0 0 xdim ydim
    setvar picnum 2839
    setvar digx 24
    setvar digz 20480 //16384
    rotatesprite digx digy digz 0 picnum 0 pal orientation 0 0 xdim ydim
}

ifvarl kickenergy KENERGY
{
	setvar digx 4
	setvar digy 135
	//getuserdef[THISACTOR].screen_size temp
	//ifvarg temp 4 subvar digy 16
	setvar digz 16384
	setvar orientation 0
	ifvarl kickenergy 130 setvar pal 4 else
	setvar pal 8
	setvarvar tempb kickenergy
	shiftvarr tempb 5
	setvarvar tempc digx
	addvarvar tempc tempb
	setvar temp 0
	whilevarn temp 1
	{
		  ifvarvarg digx tempc setvar temp 1
		  rotatesprite digx digy digz 0 199 0 pal orientation 0 0 xdim ydim
		  addvar digx 1
		  break
	}
	subvar digy 3
	gametextz 2822 9 digy 1123 0 7 0 0 0 xdim ydim 24576
	
}

ifvarg numallies 0
{
	
	rotatesprite 315 5 12288 0 1501 0 0 0 0 0 xdim ydim
	setvar pal 8
	digitalnumber 3010 307 6 numallies 0 pal 0 0 0 xdim ydim
}

ifvarn botselected -1
{
	minitext 80 5 1006 0 1
	minitext 84 12 1007 0 1
}
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
	ifvare temp 1
	{
		setactor[spriteid].picnum LIGHTBUG2
		sizeat 3 3
		changespritestat spriteid 1
	}
	break
	endswitch
	addvar spriteid 1
}
ends

onevent EVENT_ENTERLEVEL

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

state initsprites

endevent

state nocodecheck1

ifvare mirrored YES
	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 nocodecheck2

ifvare mirrored YES
	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 2
					}
				}
			}
		}
	}
}

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



// gamevar checkstatnum 0 0
// gamevar statnum 0 0

onevent EVENT_LOADACTOR

// ifvare checkstatnum 0
// {
// 	setvar checkstatnum 1
// 	setvar spriteid 0
// 	whilevarn spriteid 16384
// 	{
// 		getactor[spriteid].statnum statnum
// 		ifvarg statnum 1024 { addlogvar statnum setvar statnum -1 } else
// 		ifvarl statnum 0 { addlogvar statnum setvar statnum -1 }
// 		ifvare statnum -1
// 		{
// 			addlogvar spriteid
// 			getactor[spriteid].x x
// 			addlogvar x
// 			getactor[spriteid].y y
// 			addlogvar y
// 		}
// 		addvar spriteid 1
// 	}
// }

ifvare DONE NO
{
	state redefinequotes
	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
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
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
setvar weight WEIGHT2
setvar bouncesound METALTHUD
orvar initcstat 256
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 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
state nocodecheck2
orvar initcstat 256
break

case RECON
case RECONDP
state eventloadactorstate
break

case RESPAWN
case EGG
case LIZTROOP
case LIZTROOPSTAYPUT
case LIZTROOPSHOOT
case LIZTROOPJETPACK
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 ROTATEGUN
case BOSS1
case BOSS1STAYPUT
case BOSS2
case BOSS3
case NEWBEAST
case NEWBEASTSTAYPUT
case NEWBEASTHANG
case NEWBEASTJUMP
case BOSS4
case BOSS4STAYPUT
case SHARK
case MINIBEAST
orvar initcstat 256
state nocodecheck1
state eventloadactorstate 
ifvare doubled YES state duplicate
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
}

endevent