
// setdefname attrition.def
setcfgname att.cfg
setgamename ATTRITION
                       
include attrition/attcons/ATTDEFS.CON
include attrition/attcons/ATTUSER.CON
include attrition/attcons/LIGHTS.CON
include attrition/attcons/ATTHUD.CON
include attrition/attcons/ATTPLAYER.CON
include attrition/attcons/ATTRAND.CON
include attrition/attcons/ATTMON.CON
include attrition/attcons/ATTWAR.CON

state eventloadactorstate
ifspritepal 1 spritepal 20
getactor[THISACTOR].xvel droptile
getactor[THISACTOR].extra temp
ifvarn temp -1 setvarvar monstflags temp
ifvarn randomize 0 state randomizestate
state setmonval
ends


state dpbloodstate
ifvarn sector[THISACTOR].floorslope 0 killit
ifp ponground ifpdistl 844
{
	setplayer[THISACTOR].footprintcount 3
	setplayer[THISACTOR].footprintshade sprite[THISACTOR].shade
	getactor[THISACTOR].pal pal
	ifvare pal 0 setvar pal 2
	ifvare pal 22 setvar pal 2
	setplayer[THISACTOR].footprintpal pal
}
ifvare VOLUME 6 
{
	ifcount 5400 killit else
	ifcount 5100 cstator 512 else
	ifcount 4800 cstator 2
}
ends

move SPARKDRIFT 80
spritenoshade BFGIMPACT2
spritenopal BFGIMPACT2
action BFGIMP2FRAMES 0 4 1 1 10
useractor notenemy BFGIMPACT2 0 BFGIMP2FRAMES

ifmove 0
{
	sound BFGIMP2SND
	move SPARKDRIFT faceplayer
	cstat 130
	sizeat 32 32
	ifrnd 128 cstator 4
	ifrnd 128 cstator 8
}

ifactioncount 4 killit


enda

spritenoshade BFGBEAMTRAIL
spritenopal BFGBEAMTRAIL
action BFGBEAMFRAMES 0 9 1 1 2
useractor notenemy BFGBEAMTRAIL 0 BFGBEAMFRAMES

ifmove 0
{
	move INIT
	cstat 130
	//cstator 16
	sizeat 14 14
	ifrnd 128 cstator 4
	ifrnd 128 cstator 8
	ifrnd 128 
	spritepal 33
}

ifspritepal 33 spritepal 0 else spritepal 33
ifactioncount 9 killit

enda

useractor notenemy SHRAPNELSPAWNER 0

setvar countvar 0
whilevarn countvar 5
{
	addvar countvar 1
	randvar angvar 2047
	setactor[THISACTOR].ang angvar
	randvar zvel 4096
	subvar zvel 3072
	ezshoot zvel SHRAPNEL
	setactor[RETURN].owner player[THISACTOR].i
	setactor[RETURN].htowner player[THISACTOR].i
}
killit

enda

move COMTRAILMOV 512 0
useractor notenemy COMETRAIL 0

ifmove 0
{
	move COMTRAILMOV geth getv
	sizeat 16 16
	cstat 128
	getactor[THISACTOR].ang angvar
	randvar temp 128
	subvar temp 64
	addvarvar angvar temp
	setactor[THISACTOR].ang angvar
	randvar peractor1 2048
	subvar peractor1 1024
	addvarvar initz peractor1
	shiftvarr initx 1
}
else sizeto 0 0

setactor[THISACTOR].zvel initz
setactor[THISACTOR].xvel initx
ifnotmoving killit
ifvarn sprite[target].statnum 4 setvar target -1
ifvarn target -1
state gradualturn

getactor[THISACTOR].ang angvar
randvar temp 64
subvar temp 32
addvarvar angvar temp
setactor[THISACTOR].ang angvar

enda


state startfires

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

ends

state wakeupmonsters

headspritestat spriteid 2
whilevarn spriteid -1
{
	ifvarand actorvar[spriteid].monstflags 2048
	state wakemon
	nextspritestat spriteid spriteid
}

ends

state spawnflashes
spawn BLINDINGFLASH
spawn BLINDINGFLASH
spawn BLINDINGFLASH
spawn BLINDINGFLASH
spawn BLINDINGFLASH
spawn BLINDINGFLASH
spawn BLINDINGFLASH
spawn BLINDINGFLASH
spawn BLINDINGFLASH
spawn BLINDINGFLASH
spawn BLINDINGFLASH
spawn BLINDINGFLASH
spawn BLINDINGFLASH
spawn BLINDINGFLASH
// stun nearby monsters
headspritestat spriteid 1
whilevarn spriteid -1
{
	ifvare actorvar[spriteid].monstatus 1
	{
		getactor[THISACTOR].z z
		getactor[spriteid].z mz
		subvarvar mz z
		ifvarl mz 32768 ifvarg mz -32768
		{
			ldist xydist THISACTOR spriteid
			ifvarl xydist 6144
			{
				getactorvar[spriteid].stun tempb
				addvar tempb 60
				setvar tempc 150
				getactor[spriteid].extra tempd
				shiftvarr tempd 2
				subvarvar tempc tempd
				ifvarg tempc 0 addvarvar tempb tempc
				setactorvar[spriteid].stun tempb
				ifvarl sprite[spriteid].htextra 1
				{
					setactor[spriteid].htextra 1
					setactor[spriteid].htpicnum BLINDINGFLASH
					setactor[spriteid].htowner player[THISACTOR].i
				}
			}
		}
	}
	nextspritestat spriteid spriteid
}
ends

state tripbomb2blow

spawn EXPLOSION2
sound LASERTRIP_EXPLODE
setvar tripbombing 2
hitradius TRIPBOMBBLASTRADIUS 30 60 90 120
ifvare actorvar[myspawner].monstatus 1
{
	setactor[myspawner].htpicnum RADIUSEXPLOSION
	setvarvar temp weaplev8
	shiftvarl temp 5
	addvar temp 100
	setactor[myspawner].htextra temp
	setactor[myspawner].htowner player[THISACTOR].i
}
ifvarg weaplev8 2
state startfires
ifvarg weaplev8 0
{
	state spawnflashes
	ifvarg weaplev8 5 state spawnflashes
	ifvarg weaplev8 3 
	{
		ifvarg weaplev8 5 setvar countvar 20 else
		setvar countvar 10 
		ifvarg weaplev8 4 setvar peractor1 1 
	}
	else { setvar countvar 4 setvar peractor1 0 }
	whilevarn countvar 0
	{
		espawn BOMBLET
		setactorvar[RETURN].peractor1 peractor1
		setactorvar[RETURN].myspawner player[THISACTOR].i
		subvar countvar 1
		ifvarg weaplev8 5 spawn MININUKE
	}
	setvar peractor1 0
}

killit

ends

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

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

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


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

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

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

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

enda


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

useractor notenemy BULLETWOUND 0

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

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

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

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

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

// ifcount 390 killit
enda

eventloadactor SECTOREFFECTOR
getactor[THISACTOR].sectnum mysector
getactor[THISACTOR].lotag lotag
getactor[THISACTOR].hitag hitag
getactor[THISACTOR].xvel initx
getactor[THISACTOR].yvel inity
getactor[THISACTOR].zvel initz

ifvare lotag 114
{
	// initx starting tile minus 1
	// inity last tile plus 1
	// initz number to add
	
	setvar spriteid 0
	whilevarn spriteid 16384
	{
		getactor[spriteid].picnum picnum
		ifvarvarg picnum initx ifvarvarl picnum inity
		{
			addvarvar picnum initz
			setactor[spriteid].picnum picnum
		}
		addvar spriteid 1
	}

	setvar spriteid 0
	whilevarvarn spriteid NUMSECTORS
	{
		getsector[spriteid].floorpicnum picnum
		ifvarvarg picnum initx ifvarvarl picnum inity
		{
			addvarvar picnum initz
			setsector[spriteid].floorpicnum picnum
		}
		getsector[spriteid].ceilingpicnum picnum
		ifvarvarg picnum initx ifvarvarl picnum inity
		{
			addvarvar picnum initz
			setsector[spriteid].ceilingpicnum picnum
		}
		addvar spriteid 1
	}
	setvar spriteid 0
	whilevarvarn spriteid NUMWALLS
	{
		getwall[spriteid].picnum picnum
		ifvarvarg picnum initx ifvarvarl picnum inity
		{
			addvarvar picnum initz
			setwall[spriteid].picnum picnum
		}
		getwall[spriteid].overpicnum picnum
		ifvarvarg picnum initx ifvarvarl picnum inity
		{
			addvarvar picnum initz
			setwall[spriteid].overpicnum picnum
		}
		addvar spriteid 1
	}
	cstat 32768
	cactor SMALLSMOKE
}

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 CAMERA1 
{
	getactor[THISACTOR].extra monstflags
	ifvare monstflags -1 setvar monstflags 0
	setactor[THISACTOR].extra -1
} 
enda


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

state itemquote

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

ends

state turnoffmodels

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

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

state killshield

ifspritepal 0 spritepal 1
ifspritepal 22 spritepal 7
ifspritepal 10 spritepal 2
ifspritepal 14 spritepal 8
ifspritepal 16 spritepal 1
ifspritepal 17 spritepal 1
ifspritepal 21 spritepal 2
ifspritepal 24 spritepal 2
ifspritepal 23 spritepal 7

ifvare countvar 0
{
	lotsofglass 30
	globalsound GLASS_BREAKING
}
setactorvar[myspawner].myshield -1
killit
ends

action PLASSHIELDFRAMES 0 4 1 1 1
useractor notenemy PLASMASHIELD 300 PLASSHIELDFRAMES
ifmove 0
{
	move INIT
	cstat 403
	sizeat 14 18
	setactor[THISACTOR].pal sprite[myspawner].pal
	getactor[myspawner].extra hp
	shiftvarl hp 1
	ifvarg hp 300
	setactor[THISACTOR].extra hp
}

getactor[THISACTOR].xrepeat digx
getactor[THISACTOR].yrepeat digy
ifvarl digx 14 addvar digx 1
ifvarl digy 18 addvar digy 1
setactor[THISACTOR].xrepeat digx
setactor[THISACTOR].yrepeat digy

ifvarl sprite[myspawner].cstat 0
setvar tempc 0 else
ifvarvare sprite[THISACTOR].sectnum sprite[myspawner].sectnum setvar tempc 1 else
canseespr THISACTOR myspawner tempc

ifvare tempc 0 
cstat 32768 
else
ifvarg countvar 0
{
	cstat 643
	subvar countvar 1
	sizeto 7 9
	sizeto 7 9
}
else cstat 403


ifvare actorvar[myspawner].monstatus 2 state killshield
ifvare sprite[myspawner].statnum 1024 state killshield
ifvare actorvar[myspawner].mval 0 state killshield
ifvarl sprite[myspawner].yrepeat 20 state killshield

ifhitweapon 
{
	ifdead
		state killshield
	else
	sound HITSHIELD
}

getactor[myspawner].x x
getactor[myspawner].y y
getactor[myspawner].z z
subvar z 6144
getactor[myspawner].ang angvar
setactor[THISACTOR].ang angvar

setvarvar mx x
addvar mx 480

rotatepoint x y mx y angvar mx my
setsprite THISACTOR mx my z

enda


spritenoshade SCORCH

useractor notenemy SCORCH 0

ifspritepal 3 break

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

	ifvarn initx 0 sizeat 4 4 else
	sizeat 16 16

	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].sectnum mysector
	ifvare lotag 1 
	{
		ifonwater killit else
		state fitsector 
		break 
	}
	ifvare hitag 1 { state fitsector break }
	getwall[target].nextsector target2
	
	ifvarn target2 -1
	{
		setvar tempb 0
    	getsector[target2].lotag temp
    	switch temp
    	case 3
    	case 16    // ELEVATOR PLATFORM DOWN
		case 17    // ELEVATOR PLATFORM UP
		case 18    // ELEVATOR DOWN
		case 19    // ELEVATOR UP
    	case 20    // CEILING DOOR
	    case 21    // FLOOR DOOR
	    case 22    // SPLIT DOOR
	    case 23    // SWING DOOR
	    case 26    // SPLIT STAR TREK DOOR
	    case 28    // DROP FLOOR
	    case 29    // TEETH DOOR
	    case  9    // STAR TREK DOORS
	    case 25    // SLIDE DOOR
	    case 27    // BRIDGE
	    case 30    // ROTATE RISE BRIDGE
	    case 31    // 2 WAY TRAIN
	    setvar tempb 1
	    break
	    default break
	    endswitch
	    ifvare tempb 1 killit
	    
	   	headspritesect spriteid target2
	   	whilevarn spriteid -1
	   	{
		   	ifvare sprite[spriteid].picnum SECTOREFFECTOR
		   	{
			   	getactor[spriteid].lotag tempc
			   	switch tempc
			   	case 11
			   	case 13
			   	case 15
			   	case 19
			   	case 21
			   	case 22
			   	case 25
			   	case 31
			   	case 32
			   	setvar tempb 1
			   	break
			   	endswitch
		   	}
	   		nextspritesect spriteid spriteid
	   		ifvare tempb 1 setvar spriteid -1
   		}
   		ifvare tempb 1 killit
	}
	
	
	getactor[THISACTOR].ang angvar
	cos mycos angvar
	sin mysin angvar
	subvar angvar 512
	setvarvar mx x
	addvar mx 512
	rotatepoint x y mx y angvar digx digy
	updatesectorz digx digy sprite[THISACTOR].z tempd
	ifvare tempd -1 setvar xydist 1 else
	{
		hitscan digx digy sprite[THISACTOR].z tempd mycos mysin 0 hitsector hitwall hitsprite hitx hity hitz clipmask
		state pythagoras
	}
	ifvarl xydist 896
	{
		addvar angvar 1024
		rotatepoint x y mx y angvar digx digy
		updatesectorz digx digy sprite[THISACTOR].z tempd
		ifvare tempd -1 setvar xydist 1 else
		{
			hitscan digx digy sprite[THISACTOR].z tempd mycos mysin 0 hitsector hitwall hitsprite hitx hity hitz clipmask
			state pythagoras
		}
	}
	

	ifvarg xydist 896
	{
		// calculate distance to wallpoint
		// calculate distance to wallpoint2
		// if either ditance is short, shrink accordingly
		setvar xydist2 8192
		getwall[target].x hitx
		getwall[target].y hity
		state pythagoras	
		setvarvar xydist2 xydist
		getwall[target].point2 currwall
		getwall[currwall].x hitx
		getwall[currwall].y hity
		state pythagoras   
	 	ifvarvarl xydist2 xydist setvarvar xydist xydist2
		
		ifvarl xydist 768
		{
			divvar xydist 28
			getactor[THISACTOR].xrepeat digx
			ifvarvarl xydist digx
			setactor[THISACTOR].xrepeat xydist
			ifvarl xydist 3 killit
		}
	}
	
	
	getwall[target].nextsector temp
	ifvarn temp -1
	{
		getsector[temp].floorz mz
		getactor[THISACTOR].z z
		ifvarvarl mz z
		{
			subvarvar z mz
			ifvarl z 6144
			{
				shiftvarr z 28
				getactor[THISACTOR].yrepeat y
				ifvarvarl z y
				setactor[THISACTOR].yrepeat z
				ifvarl z 3 killit
			}
		}
		getsector[temp].ceilingz mz
		ifvarvarg mz z
		{
			subvarvar mz z
			shiftvarr mz 9
			getactor[THISACTOR].yrepeat y
			ifvarvarl mz y
			setactor[THISACTOR].yrepeat mz
		}
				
	}
	ifvarn target -1
	{
		getwall[target].shade shade
		ifvarl shade 0 setvar shade 0
		addvar shade 5
		setactor[THISACTOR].shade shade
	}
	
	ifvare lotag 0 ifvare hitag 0 
		ifawayfromwall killit
	
}

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

ifcount 1800 killit
ifcount 1500 cstator 512
ifcount 1200 cstator 2


enda

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

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

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

spritenoshade STICKYFIRE
useractor notenemy STICKYFIRE 0

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

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

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

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

move NUKE1 64 -256
move NUKE2 160 -192
move NUKE3 296 -128
move NUKE4 416 -64
move NUKE5 512 0
move NUKE6 416 64
move NUKE7 296 128
move NUKE8 160 192
move NUKE9 64 256

state nukeit
hitradius 2048 14 20 26 32
sound PIPEBOMB_EXPLODE
cactor 3458
spawn EXPLOSION2
cactor MININUKE
killit
ends

actor MININUKE 0
cstat 32768

ifcount 1 nullop 
else
{
	ifrnd 28 move NUKE5 geth randomangle
	else
	{
		ifrnd 128 // move up
		{
			 ifrnd 128
			 {
				 ifrnd 128 move NUKE1 geth getv randomangle else
				 move NUKE2 geth getv randomangle
			 }
			 else
			 {
				 ifrnd 128 move NUKE3 geth getv randomangle else
				 move NUKE4 geth getv randomangle
			 }
		}
		else // move down
		{
			ifrnd 128
			 {
				 ifrnd 128 move NUKE6 geth getv randomangle else
				 move NUKE7 geth getv randomangle
			 }
			 else
			 {
				 iffloordistl 8 ifrnd 64
				 {
					 ifrnd 128 move NUKE3 geth getv randomangle else
					 move NUKE4 geth getv randomangle
				 }
				 else
				 {
				 	ifrnd 128 move NUKE8 geth getv randomangle else
				 	move NUKE9 geth getv randomangle
			 	}
			 }
		}
	}
}
ifcount 2 ifrnd 16
{
	resetcount
	spawn EXPLOSION2
	hitradius 1560 14 20 26 32
}
ifcount 1 ifrnd 4 state nukeit
ifcount 2 ifrnd 8 state nukeit
ifcount 3 ifrnd 16 state nukeit
ifcount 4 ifrnd 32 state nukeit
ifcount 6 state nukeit

enda

move EXPLINEMOVE 768

actor EXPLINE 0

ifmove 0
{
	move EXPLINEMOVE geth
	cstat 32768
	sizeat 2 2
}
setactor[THISACTOR].ang peractor1

ifcount 3
{
	resetcount
 	spawn EXPLOSION2
 	sound PIPEBOMB_EXPLODE
 	setvar tripbombing 2
 	hitradius PIPEBOMBRADIUS 35 70 105 140
	subvar countvar 1
	ifvarl countvar 1 killit
}

enda


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


useractor notenemy METALHOLE 0
ifmove 0
{
	sizeat 3 3
	cstator 2
	move INIT
	insertspriteq
	eqspawn INNERHOLE
	{
		getactor[THISACTOR].cstat temp
		subvar temp 2
		setactor[RETURN].cstat temp
		setactor[RETURN].xrepeat 3
		setactor[RETURN].yrepeat 3
		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
{
	iffloordistl 2 sizeat 6 3 else
	sizeat 4 4
	cstator 2
	move INIT
	insertspriteq
	eqspawn 6281
	
	getactor[THISACTOR].cstat temp
	subvar temp 2
	setactor[RETURN].cstat temp
	setactor[RETURN].xrepeat 4
	setactor[RETURN].yrepeat 4
	getactor[THISACTOR].ang angvar
	setactor[RETURN].ang angvar
	
}
enda


state guideit
// assumes that target is set
	
state gradualturn
getactor[THISACTOR].z z
getactor[target].z mz
setvarvar zdist mz
subvarvar zdist z
getactor[target].extra hp
ifvarg hp 0 subvar zdist 8192 // seek down to feet if dead to dispose of body
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1
shiftvarl zdist 9 // multiplies zdist by 512
divvarvar zdist xydist // zdist now holds the desired z vel
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

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

ifinwater
{
	ifmove SHELLSTOP nullop else
	{
		ifmove SHELLROLL3 nullop else
		move SHELLROLL3 geth
	}
}

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

ifmove SHELLBOUNCE ifcount 6
{
	move SHELLBOUNCE2 geth
	resetcount
}

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


ifmove SHELLROLL1 ifcount 22 { move SHELLROLL2 geth resetcount }
ifmove SHELLROLL2 ifcount 16 { move SHELLROLL3 geth resetcount }
ifmove SHELLROLL3 
  ifcount 12
    ifrnd 32 
{
	 setactor[THISACTOR].mdflags 2
     move SHELLSTOP
     ifactor 2534 action SHELLSTOPPED
     ifrnd 128 cstat 388
     
     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 780 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
	ifinwater
	{
		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



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

useractor notenemy SSHELLGROUND 0 state shellcode enda // shotgunshell

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

spritenoshade BLOODPOOL

state jibcode

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

ifactor PIGHEADG
{
	getactor[THISACTOR].zvel temp
	ifvarg temp 0 setvar mtype 1 // falling
	ifvare mtype 1 ifvare temp 0 ifvare peractor4 0
	{
		ifrnd 128 sound JIBLAND else sound JIBLAND2
		setvar mtype 0
	}
	state moveitem
	
}

fall

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

action JIBMODELFRAME1 4026 1 1 1 1

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


setvar temp 0
ifactor 1770 setvar temp 1
ifactor 2203 setvar temp 1
ifvare temp 1
{
	state moveitem
}
else
{
	addvar countvar 1
	ifvare countvar 208 cstator 2
	ifvare countvar 234 cstator 512
	ifvarg countvar 260 killit
}
fall

ifhitweapon ifdead
{
	guts JIBS6 2 
	killit 
}


ends

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


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

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

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



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

action RAINSPLASH -3821 9 1 1 3

move SNOWFALL 16 16
move SNOWFALL2 16 20

spritenopal RAINSPRITE
useractor notenemy RAINSPRITE 0
fall

ifinwater killit 

ifaction RAINFRAME
{
	// sizeto 8 42
	sizeto 16 64
	iffloordistl 2 action RAINSPLASH else
	ifnotmoving action RAINSPLASH
} else
ifaction RAINSPLASH 
{
	sizeat 16 16
	ifactioncount 9 killit
}
else
ifaction 0
{
	cstator 8192
	setactor[THISACTOR].mdflags 1
	spriteflags 16
	ifoutside nullop else killit
	action RAINFRAME
	sizeat 8 15
	setactor[THISACTOR].zvel 2048
	setactor[THISACTOR].pal rainpal
	ifvarand raincstat 512 cstator 514 else
	ifvarand raincstat 2 cstator 2
}
else
{
	ifnotmoving killit
	iffloordistl 4 killit
	ifvarvarg sprite[THISACTOR].z player[THISACTOR].posz
	ifpdistg 16384 killit
}

enda

useractor notenemy SNOWSPRITE 0 

fall
ifinwater killit 

ifmove 0
{
	cstator 8192
	spriteflags 16
	setactor[THISACTOR].mdflags 1
	ifoutside nullop else killit
	ifrnd 128
	move SNOWFALL geth getv randomangle
	else move SNOWFALL2 geth getv randomangle
	ifrnd 128 cstator 4
	ifrnd 128 cstator 8
	ifvarand raincstat 2 cstator 2
	randvar x 3 addvar x 3
	randvar y 3 addvar y 3
	setactor[THISACTOR].xrepeat x
	setactor[THISACTOR].yrepeat y
}

ifnotmoving killit
iffloordistl 4 killit
ifvarvarg sprite[THISACTOR].z player[THISACTOR].posz
ifpdistg 16384 killit

enda

action WATERSPLASH3FRAMES -165 5 1 1 9

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

ifactioncount 5 killit

enda

move INKMOVE 644


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

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

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

enda

action BOTMARKERFRAME -5 1 1 1 1

useractor notenemy BOTMARKER 0 BOTMARKERFRAME

spritepal 4
cstat 2
sizeat 42 36
ifcount 1 killit

enda


action TARGHEAD -1845 1 1
useractor notenemy SHOOTME 0
ifmove 0
{
	move INIT
	sizeat 32 32
	cstat 32768
	setactor[THISACTOR].pal sprite[myspawner].pal
}
sleeptime -1
setactor[THISACTOR].z sprite[myspawner].z
setactor[THISACTOR].y sprite[myspawner].y
setactor[THISACTOR].x sprite[myspawner].x
getactorvar[myspawner].playerally playerally
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
default 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

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  35  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 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 AIBOTSEEKPLAYER ALLYPRUN ALLYRUNVEL seekplayer
ai AIBOTSTOPPED ALLYPSTAND ALLYSTOP geth
ai AIBOTWANDER ALLYPWALK ALLYWALKVEL randomangle
ai AIBOTFACEPLAYER ALLYPRUN ALLYRUNVEL faceplayer
ai AIBOTDODGE ALLYPRUN ALLYSTOP geth
ai AIBOTDYING ALLYPTHROWNBACK ALLYSTOP geth
ai AIBOTSWIM ALLYPSWIMMING ALLYWALKVEL seekplayer
ai AIBOTJET ALLYPJPHOUVER ALLYJETUP faceplayerslow getv
ai AIBOTMEDIC ALLYPRUN ALLYRUNVEL geth
ai AIBOTFLINTCH ALLYPFLINTCHING ALLYSTOP geth
ai AIBOTCHARGE ALLYPRUN ALLYRUNVEL geth // allies only
ai AIBOTFROZEN ALLYPFROZEN ALLYSTOP geth
//ai AIBOTGROW ALLYPFLINTCHING ALLYSTOP geth
ai AIBOTSHRUNK ALLYPRUN BOTSHRUNKVELS randomangle

state botflintchstate

ifcount 10 ifvare stun 0 { cactor BOTALLY ai AIBOTSTOPPED }

ends

state botchecksight

ifvarvare target THISACTOR { setvar target -1 break }

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

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

ends

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

state botexitarray

//ifvare playerally -1
ifvarvare mybot THISACTOR
{
	setvar mybot -1
	setplayer[THISACTOR].holoduke_amount 0
}
ends

state botfindtarget

setvar target -1

ifvare playerally -1 // ally
{
	findnearactorz SHOOTME 4096 32768 spriteid
	ifvarn spriteid -1 getactorvar[spriteid].myspawner target
	ifvarn target -1 state validatetarget
	ifvarn target -1 break
	
	findnearactorz SHOOTME 8192 65536 spriteid
	ifvarn spriteid -1 getactorvar[spriteid].myspawner target
	ifvarn target -1 state validatetarget
	ifvarn target -1 break
	
	findnearactorz SHOOTME 12288 98304 spriteid
	ifvarn spriteid -1 getactorvar[spriteid].myspawner target
	ifvarn target -1 state validatetarget
	ifvarn target -1 break
	
	findnearactorz SHOOTME 18432 147456 spriteid
	ifvarn spriteid -1 getactorvar[spriteid].myspawner target
	ifvarn target -1 state validatetarget
	
	findnearactorz SHOOTME 32768 262144 spriteid
	ifvarn spriteid -1 getactorvar[spriteid].myspawner target
	ifvarn target -1 state validatetarget
}
else // enemy
{
	ifvarg canseeplayer 0 ifvarg canshootplayer 0 ifpdistl 8192 ifrnd 160 
	{
		getplayer[THISACTOR].i target
		break
	}
	ifvarn mybot -1
	{
		dist temp THISACTOR mybot
		ifvarl temp 32768 { setvarvar target mybot 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
			}
		}
	}
	ifvare target -1 ifvarg canseeplayer 0 ifvarg canshootplayer 0 ifpdistl 16384 getplayer[THISACTOR].i target
}

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
}

setvar countvar 4
ifrnd 64 ifvarand monstflags 512 { espawn GROWSPRITEICON setactorvar[RETURN].peractor4 13 subvar countvar 1 }
ifrnd 96 ifvarand monstflags 256 { espawn DEVISTATORAMMO setactorvar[RETURN].peractor4 13 subvar countvar 1 }
ifrnd 96 ifvarand monstflags 128 { espawn FREEZESPRITE setactorvar[RETURN].peractor4 13 subvar countvar 1  }
ifrnd 96 { ifrnd 64 spawn HOLODUKE else spawn ATOMICHEALTH subvar countvar 1 }
ifrnd 96 ifvarg countvar 0 ifvarand monstflags 64 { espawn RPGAMMO setactorvar[RETURN].peractor4 13 subvar countvar 1 }
ifrnd 128 ifvarg countvar 0 ifvarand monstflags 32 { espawn CHAINGUNSPRITE setactorvar[RETURN].peractor4 13 subvar countvar 1 }
ifrnd 128 ifvarg countvar 0 ifvarand monstflags 16 { espawn SHOTGUNSPRITE setactorvar[RETURN].peractor4 13 subvar countvar 1 }
ifvarg countvar 0 { espawn FIRSTGUNSPRITE setactorvar[RETURN].peractor4 13 subvar countvar 1 }


ends

state botfrozenstate
 
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
      ifvare superkicking 0
       ifspritepal 1
        pkick

    ifcount THAWTIME ifvarg burning -1
    {
	  cactor BOTALLY
      ai AIBOTSTOPPED
      // strength 1
      ifspritepal 1 getlastpal
      setactor[THISACTOR].htextra -1
      setactor[THISACTOR].htpicnum -1
      break
    }
    else
      ifcount FROZENDRIPTIME
        ifactioncount 26
          resetactioncount

    ifhitweapon
    {
	    ifwasweapon FREEZEBLAST { ifdead strength 0 break }
	    ifwasweapon FREEZENOAIM { ifdead strength 0 break }
	    ifdead
	    {
		    
		    ifvarn playerally -1 state standard_jibs else
		    lotsofglass 30
		    state standard_pjibs
	        sound GLASS_BREAKING
	
			 state botdrop
			 ifvarvare mybot THISACTOR
			 userquote 1002
			 //ifvarn playerally -1 
			 ifvarvarn mybot THISACTOR
			 state specialdeath else
			 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
    ifvare playerally -1
    findnearactor3d SHOOTME SQUISHABLEDISTANCE spriteid
    else
    {
	    ifpdistl SQUISHABLEDISTANCE getplayer[THISACTOR].i spriteid else
	    findnearactor3d SHOOTMEALLY SQUISHABLEDISTANCE spriteid
    }
    ifvarn spriteid -1
    {
	    globalsound SQUISHED
	    state standard_pjibs
	    spawn BLOODPOOL
	    globalsound DUKE_DEAD
	    userquote 1004
	    ifvarvarn mybot THISACTOR state specialdeath else
	    state botexitarray
	    // ifvarn playerally -1 state specialdeath
	    killit
    }
  }
    
ends

state botdyingstate

setvar command 0

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
ifactor BOTALLYCROUCH spawn BULLETFLASHLOW else
spawn BULLETFLASH
state shelleject
sound PISTOL_FIRE
state calczdist

shiftvarl zdist 8
divvarvar zdist xydist
zshoot zdist SHOTSPARK1
zshoot zdist SHOTSPARK1
ends

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

ends

state chaingunfire
ifactor BOTALLYCROUCH spawn BULLETFLASHLOW else
spawn BULLETFLASH
sound CHAINGUN_FIRE
state shelleject
subvar ammo 1
state calczdist

shiftvarl zdist 8
divvarvar zdist xydist
zshoot zdist SHOTSPARK1
zshoot zdist SHOTSPARK1
ends

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

state devistatorfire

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
ezshoot zdist RPGNOAIM
ifvare playerally 0 setthisprojectile[RETURN].extra 15 else
setthisprojectile[RETURN].extra 20
setthisprojectile[RETURN].trail -1
setactor[RETURN].extra 25
setactor[RETURN].xrepeat 7
setactor[RETURN].yrepeat 7

randvar tempb 16
getactor[RETURN].ang angvar
ifrnd 128 addvarvar angvar tempb else subvarvar angvar tempb
setactor[RETURN].ang angvar
randvar tempb 1024
getactor[RETURN].zvel zdist
subvar tempb 640
addvarvar zdist tempb
setactor[RETURN].zvel zdist

subvar ammo 3

ends

state freezerfire
sound CAT_FIRE
subvar ammo 2

ifvarvare target player[THISACTOR].i shoot FREEZEBLAST else
{
	state calczdist
	mulvar zdist 644
	divvarvar zdist xydist
	zshoot zdist FREEZENOAIM
}

ends

state expanderfire
ifactor BOTALLYCROUCH spawn BULLETFLASHLOW else
spawn BULLETFLASH
sound EXPANDERSHOOT

subvar ammo 3
state calczdist

shiftvarl zdist 8
divvarvar zdist xydist
zshoot zdist GROWSPARK
ifrnd 128 zshoot zdist GROWSPARK

ends


state switchweapon
ifvarl ammo 1 
{
	setvar weap 2 break
}
ifvarand monstflags 256 ifrnd 128
{
	dist xydist2 THISACTOR target
	subvar xydist2 512
	ifvarg xydist2 RPGBLASTRADIUS { setvar weap 8 break }
}
else
ifvarand monstflags 64 ifrnd 128
{
	dist xydist2 THISACTOR target
	subvar xydist2 384
	ifvarg xydist2 RPGBLASTRADIUS { setvar weap 5 break }
}

ifvarand monstflags 512 ifrnd 128 { setvar weap 11 break }
ifvarand monstflags 128 ifrnd 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 }
ifvarand monstflags 256 ifvarg xydist2 RPGBLASTRADIUS { setvar weap 8 break }
ifvarand monstflags 64 ifvarg xydist2 RPGBLASTRADIUS { setvar weap 5 break }
ifvarand monstflags 512 { setvar weap 11 break }
ifvarand monstflags 128 { setvar weap 10 break }
setvar weap 2

ends


state botfiringcode

state visibilitycheck
ifvare target -1 break


ifvare weap 0 state switchweapon

switch weap

	case 2  // pistol
		ifvarl botclip 1
		{
		   ifvare weapcount 3 sound EJECT_CLIP
		   ifvare weapcount 12 sound INSERT_CLIP
		   ifvarg weapcount 27 
		   {
			    setvar weapcount 0
		   		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
		ifvarg weapcount 2 
		{
			state chaingunfire // else state flakfire
			setvar weapcount 0
		}
		
		break	
		
	case 5  // RPG
		ifvare weapcount 4 
		{
			state rpgfire 
			//else state railgunfire 
		}
		ifvarg weapcount 19
		  setvar weapcount 0 
		
		break

	case 8 // DEVISTATOR
	    ifvarg weapcount 2
	    {
		    state devistatorfire
		    setvar weapcount 0
	    }
	    break
	
	 case 10  // freezer
	 
	 	ifvare weapcount 2
		 	  state freezerfire

		ifvarg weapcount 4 
		{ 
			setvar weapcount 0 
			ifvare sprite[target].pal 1 setvar weap 2 else
			ifvarl actorvar[target].burning 0 setvar weap 2
		}
	break
	
	case 11 // expander
	   ifvarg weapcount 4
	   {
		   state expanderfire
		   setvar weapcount 0
	   }
	break
	default break
	endswitch
	
addvar weapcount 1	

ends

state botdodgestate

ifvare command 1
{
	ifawayfromwall
	ifvarvare sprite[THISACTOR].sectnum initz
	{
		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 command 1 ifvarn RETURN 0 setvar command 0

ifvare botdodge 0 
{
	//ifaction ALLYPJPHOUVER ai AIBOTJET else 
	ai AIBOTSTOPPED
	ifrnd 184 
	{
		cactor BOTALLYCROUCH 
		action ALLYPDUCKING 
	}
}

ends

state checkbotdodge

	ifvare botdodge 0
	{
		getactor[THISACTOR].picnum picnum
		cactor PIGCOP
		ifvare playerally -1
		{
			findnearactorz BOTALLY 3072 16384 spriteid
			ifvare spriteid -1 findnearactor SHOOTME 3072 spriteid
			ifvare spriteid -1 ifvare CURRWEAP 10 findnearspritez HEAVYHBOMB 4096 10240 spriteid
		}
		else
		{
			setvar spriteid -1
			ifvare spriteid -1 ifvare CURRWEAP 10 findnearspritez HEAVYHBOMB 4096 10240 spriteid
			ifvare spriteid -1 ifvarn command 1
			ifpdistl 4096 getplayer[THISACTOR].i spriteid
			ifvare spriteid -1 findnearactor SHOOTMEALLY 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 startdodge

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

ends

state botstoppedstate

ifvarand monstflags 1024 break

	ifvarn target -1
	{
		state checkbotdodge
		ifvare botdodge 0 ifvare playerally 0
		ifvarn command 1
		ifvarvare scannedsprite THISACTOR
		ifrnd 32
		state startdodge
		else
		ifvarn playerally 0
		{
			ldist xydist THISACTOR target
			ifvarg xydist 5120 { cactor BOTALLY ai AIBOTCHARGE }
		}
	}
	else
	{
		ifvare CURRWEAP 10 { state checkbotdodge ifai AIBOTDODGE break }
		
		ifvarn playerally -1
		{
			ifcount 20
			{
				cactor BOTALLY
				ai AIBOTSEEKPLAYER
			}
			break
		}

		ifpdistg 1560 ifvarn command 1 // not patrolling
		ifcount 30
		{
			getplayer[THISACTOR].cursectnum temp
			getactor[THISACTOR].sectnum mysector
			ifvarvarn temp mysector
			{
				cactor BOTALLY
				ai AIBOTSEEKPLAYER
				break
			}
			ifpdistg 4096 ifcansee
			ifvare playerally -1
			{
				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 eviltrail


// use player waypoints to follow him
// player trail code

ifvarn bouncesound -1
{
	ifvare ptrailtimer 0 ifvarg bouncesound 0 subvar bouncesound 1
	setvarvar spriteid ptrails[bouncesound]
	ifvare spriteid -1 setvar bouncesound -1 else
	ifvarn sprite[spriteid].picnum PLAYERTRAIL setvar bouncesound -1
	ifvarn bouncesound -1
	{
		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
				ifvarn sprite[spriteid].picnum PLAYERTRAIL { setvar bouncesound -1 setvar tempb 100 }
				ifvarn bouncesound -1
				{
					ldist tempd THISACTOR spriteid
					ifvarl tempd 384 
					{
						addvar tempb 1 
						ifvare tempb 100 setvar bouncesound -1
						// newbeast and lizman should jump here if the waypoint tells them
					}
					else { setvarvar bouncesound tempb setvar tempb 100 }
				}
			}
			ifvare bouncesound 100 setvar bouncesound -1 
		}
		else
		{
			ifnotmoving
			ifvarn weapcount -1 ifvare botdodge 0 ifvare peractor6 0
			{
				getactor[THISACTOR].ang peractor5
				setvar temp 512 ifrnd 128 mulvar temp -1
				addvarvar peractor5 temp
				setvar botdodge 26
			}
			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
			
			ifvare target -1
			setactor[THISACTOR].ang angvar
			
			ifmove ALLYSTOP nullop else
			ifvarg canseeplayer 0 nullop else
			{
				setvar temp 256
				getactor[THISACTOR].xvel xvel
				ifvarg xvel -1 ifvarvarl xvel temp
				setactor[THISACTOR].xvel temp
			}				
		}
		ifnotmoving ifrnd 32 ifvarn bouncesound -1
		{
			operate
// 			ifrnd 64 iffloordistl 8
// 			{
// 				ifactor LIZMAN ai AILIZJUMPENEMY
// 				ifactor NEWBEAST ai AINEWBEASTJUMPENEMY
// 			}
			state validatetrail
			ifvare tempc 0 setvar bouncesound -1
		}
	}
}

else
ifvare target -1 	
// find the player trail
	{
	setvarvar spriteid ptrails[lasttrail]
	ifvarn spriteid -1 ifvarn sprite[spriteid].picnum PLAYERTRAIL setvar spriteid -1
	ifvarn spriteid -1
	{
		state validatetrail
		ifvare tempc 1
		{
			setvarvar bouncesound lasttrail
			setvar lasttrail 100
		}
	}
	subvar lasttrail 1
	ifvare lasttrail -1 setvar lasttrail 99
	}
ends

state botseekplayerstate

	ifaction ALLYPJUMPING nullop else ifaction ALLYPFALLING nullop else
	{
		ifvare CURRWEAP 10 { state checkbotdodge ifai AIBOTDODGE break }
		ifvarn target -1 
		{
			setvar bouncesound -1
			ai AIBOTSTOPPED 
			ifrnd 184 
			{ 
				cactor BOTALLYCROUCH 
				action ALLYPDUCKING 
			}
			break 
		}
		ifvare playerally -1
		ifpdistl 1560 ifcansee
		{
			setvar bouncesound -1
			ai AIBOTSTOPPED 
			ifrnd 160 
			{ 
				cactor BOTALLYCROUCH 
				action ALLYPDUCKING 
			}
			break 
		}
	}
	
	ifactornotstayput
	state botjumpcode
	
	ifvare command 1 break
	
	// player trail code
	ifvarn playerally -1 { state eviltrail break }
	
	ifvarn bouncesound -1
	{
		setvarvar spriteid ptrails[bouncesound]
		ifvare spriteid -1 { setvar bouncesound -1 move ALLYRUNVEL seekplayer }
		else
		{
			ldist tempd THISACTOR spriteid
			ifvarl tempd 512 
			{
				addvar bouncesound 1
				setvarvar tempb bouncesound
				whilevarn tempb 100
				{
					setvarvar spriteid ptrails[tempb]
					ifvare spriteid -1 { setvar bouncesound -1 setvar tempb 100 } else
					{
						ldist tempd THISACTOR spriteid
						ifvarl tempd 384 
						{ 
							addvar tempb 1 
							ifvare tempb 100 setvar bouncesound -1
							getactorvar[spriteid].mtype temp
							ifvare temp 1 iffloordistl 4
							{
								 cactor BOTALLY
								 action ALLYPJUMPING
								 move ALLYJUMPVEL geth getv
							}
						}
						else { setvarvar bouncesound tempb setvar tempb 100 }
					}
				}
				ifvare bouncesound 100 setvar bouncesound -1 
			}
			else
			{
				getactor[spriteid].x mx
				getactor[spriteid].y my
				getactor[THISACTOR].x x
				getactor[THISACTOR].y y
				subvarvar mx x
				subvarvar my y
				getangle angvar mx my
				setactor[THISACTOR].ang angvar
			}
		}
	}
	else
	ifactornotstayput
 	{
		setvar temp 99
		whilevarn temp -1
		{
			setvarvar spriteid ptrails[temp]
			ifvarn spriteid -1
			{
				canseespr THISACTOR spriteid tempc
				ifvare tempc 1
				{
					ldist tempd THISACTOR spriteid
					ifvarg tempd 1024
					{
						getactor[spriteid].x mx
						getactor[spriteid].y my
						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
		}
 	}
	
ends

state botwanderstate


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

state botfaceplayerstate


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

ifcansee nullop else ifaction ALLYPRUN ifrnd 8 ai AIBOTSEEKPLAYER

ends

state botswimstate

ifinwater nullop else
{
	ai AIBOTSEEKPLAYER
	action ALLYPJUMPING
	move ALLYJUMPVEL geth getv
	count 20
	break
}

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

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


ends

state botchargestate

// AIBOTCHARGE

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

ldist xydist THISACTOR target
ifvarl xydist 2560 ai AIBOTSTOPPED
else ifcount 150 ai AIBOTSTOPPED

ends

state botjetstate

espawn SMALLSMOKE
setactorvar[RETURN].peractor1 1
setactor[RETURN].cstat 32768

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

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

ends

state healally

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

ends

state botmedicstate

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


ends

state checkhealth

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

ifvarl ammo 1 break
getactor[THISACTOR].extra hp
ifvarl hp 70
{
	addvar hp 30
	subvar ammo 30
	setactor[THISACTOR].extra hp
	sound DUKE_USEMEDKIT
	espawn FIRSTAID
	setactorvar[RETURN].myspawner THISACTOR
	ifvarl ammo 1 break
}
ifcansee ifphealthl 70
{
	cactor BOTALLY
	ai AIBOTMEDIC
	setvar target -1
	getplayer[THISACTOR].i target2
	break
}

ends

state botpatrolstate

ifinwater { setvar command 0 break }

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

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

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

// temp now = xydistance to patrol point


setvar tempc 0
getactor[THISACTOR].sectnum tempd
ifawayfromwall nullop else // prevents bot from leaving the sector and falling off a cliff
setvar tempc 1
ifvarvarn initz sprite[THISACTOR].sectnum setvar tempc 1
ifvare tempc 1
{
	ifai AIBOTDODGE nullop else ai AIBOTDODGE
	setvarvar mx initx
	setvarvar my inity
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	subvarvar mx x
	subvarvar my y
	getangle peractor1 mx my
	//setactor[THISACTOR].ang peractor1
	setvar botdodge 4
	
}


ends

state botgoodbye

ifvarn playerally -1 break

ifvarvare mybot THISACTOR setvar mybot -1
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 checkbothit

	ifvarand monstflags 1024 xorvar monstflags 1024
	//ifvare playerally -1
	ifvarvare mybot THISACTOR
	{
		getplayer[THISACTOR].holoduke_amount hp
		shiftvarl bleeding 3
		
		setvar temp 100
		setvarvar tempb botlevel
		shiftvarl tempb 3
		ifvarg tempb 96 setvar tempb 96
		subvarvar temp tempb
		mulvarvar bleeding temp
		divvar bleeding 100
		
		
		subvarvar hp bleeding
		ifvarl hp -1 setvar hp -1
		setactor[THISACTOR].extra hp
		setplayer[THISACTOR].holoduke_amount hp
	}
	  ifvare playerally 0 soundonce EPAIN
	  else
	  {
	    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
        }
    }
    ifvarand monstflags 16384 nullop else
	ifwasweapon SHRINKSPARK
	{
		sound ACTOR_SHRINKING
		cactor BOTALLY
		ai AIBOTSHRUNK
		cstat 0
		break
	}
	ifdead
	{
      ifvare playerally 0
      {
		  ifwasweapon FREEZEBLAST
	      {
	        spritepal 1
	        strength 0
	        cactor BOTALLY      
	        ai AIBOTFROZEN
	        sound SOMETHINGFROZE
	        state icesmoke
	        break
	      }
	      ifwasweapon FREEZENOAIM
	      {
	        spritepal 1
	        strength 0
	        cactor BOTALLY
	        ai AIBOTFROZEN
	        sound SOMETHINGFROZE
	        state icesmoke
	        break
	      }
	      ifwasweapon GROWSPARK
		  {
		     cstat 0
		      sound ACTOR_GROWING
		      cactor BOTALLY
		      ai AIBOTGROW
		      setvar target -1
		      break
		  }
      }
        
		setvar monstatus 2
		ifvare playerally -1
		sound DUKE_DEAD
		else
		sound EDYING
		cactor BOTALLYCROUCH
		ifvarvare mybot THISACTOR
		{
			setplayer[THISACTOR].holoduke_amount 0
			state botgoodbye
		}
		else
		{
			state botdrop
			state specialdeath
			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
		
	}
	else ifvare playerally 0
	{
		ifrnd 32
		ifvarn sprite[THISACTOR].htpicnum BULLETWOUND
		{
			cactor BOTALLYCROUCH
			ai AIBOTFLINTCH
			setvar botdodge 0
		}
		else ifvarg stun 0
		{
			cactor BOTALLYCROUCH
			ai AIBOTFLINTCH
			setvar botdodge 0
			ifvarand monstflags 16384 ifvarg stun 10 setvar stun 10
			ifvarand monstflags 2 ifvarg stun 40 setvar stun 40
		}
	}

ends

state botallycode


ifmove 0
{
	spriteflags 3
	
	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
	{
		ifvarand monstflags 256 spritepal 10 // devistator
		else
		ifvarand monstflags 64 spritepal 21 // RPG
		else
		ifvarand monstflags 128 spritepal 12 // freezer
		else
		ifvarand monstflags 32 spritepal 23 // chaingun
		else
		ifvarand monstflags 512 spritepal 22 // expander
		else
		ifvarand monstflags 16 spritepal 16 // shotgun
		else spritepal 14
	}
	
	ifvare playerally -1
	{
		setvarvar ammo botlevel
		addvar ammo 2
		shiftvarl ammo 4
		ifspawnedby APLAYER
		ifvarvarn mybot THISACTOR
		setvarvar mybot THISACTOR
		else ifvarand monstflags 2 strength 600
		
		ifvarvare mybot THISACTOR
		{
			// 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
		}
		
	}
	else 
	{
		ifvarand monstflags 2 strength 600 else
		strength 300
		ifvarn VOLUME 6
		orvar monstflags 1024 // wait
		getactor[THISACTOR].x initx
		getactor[THISACTOR].y inity
		getactor[THISACTOR].sectnum initz
		soundonce EPREPDIE
		
		ifvarg randomize 14000 // ultimate
		{
			setvarvar temp randomize
			subvar temp 9000
			randvar tempb 100000
			ifvarvarl tempb temp
			{
				strength 1200
				spritepal 50
				sizeat 48 40
				setvar monstflags 864
				orvar monstflags 16384
				setvar mval 1200
			}
		}
		ifvare VOLUME 6 ifvare wave 30
		{
			strength 1200
			spritepal 50
			sizeat 48 40
			setvar monstflags 864
			orvar monstflags 16384
			setvar mval 1200
		}
	}
}

//ifvarn playerally -1
ifvarvarn mybot THISACTOR 
{
	ifvarand monstflags 1024
	ifvarg canseeplayer 0 xorvar monstflags 1024
	state monsterai
}
else //ifvarvare mybot THISACTOR
{
	getplayer[THISACTOR].holoduke_amount hp
	setactor[THISACTOR].extra hp
	ifvare hp 0 { state botgoodbye break }
	ifvare command 666 { state botgoodbye break }
}

fall

ifvarl ammo 200 ifrnd 8 { addvar ammo 1 ifvarand monstflags 16384 addvar ammo 1 }
ifvarg targetlock 0 ifrnd 208 subvar targetlock 1
getsector[THISACTOR].floorpicnum FLOORTEX
state CHECKSTEPS
ifaction ALLYPRUN ifactioncount 2 state stepsounds

ifvarl burning 0 { state botfrozenstate break }

ifai AIBOTDYING { state botdyingstate break }
ifai AIBOTFROZEN { state botfrozenstate break }
ifai AIBOTSHRUNK { state botshrunkstate break }
ifai AIBOTGROW { state genericgrowcode 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 AIBOTSEEKPLAYER state botseekplayerstate else
ifai AIBOTSTOPPED state botstoppedstate else
ifai AIBOTCHARGE state botchargestate else
ifai AIBOTWANDER state botwanderstate else
ifai AIBOTFACEPLAYER state botfaceplayerstate else
ifai AIBOTDODGE state botdodgestate else
ifai AIBOTSWIM state botswimstate else
ifai AIBOTJET state botjetstate else
ifai AIBOTFLINTCH 
{
	state botflintchstate
	ifhitweapon state checkbothit
	break
}

ifvare playerally 0
ifvarg canseeplayer 0 ifrnd 1 ifvare position 0
{
	randvar temp 3
	ifvare temp 0 soundonce EUGLY else
	ifvare temp 1 soundonce EHURTS2BU else
	ifvare temp 2 soundonce EDIE else
	ifvare temp 3 soundonce EPREPDIE
	setvar position 78
}
ifvarg position 0 subvar position 1


// ifai AIBOTMEDIC state botmedicstate
// else setvar target2 -1


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


ifai AIBOTSWIM nullop else 
ifinwater
{
	cactor BOTALLY 
	ai AIBOTSWIM 
}


ifai AIBOTJET nullop 
else ifvarn command 1
ifcansee 
{
  ifp pjetpack 
    ifvarn command 1
      ai AIBOTJET
      
  else ifp phigher
  {
	  getplayer[THISACTOR].posz mz
	  getactor[THISACTOR].z z
	  subvarvar z mz
	  ifvarg z 32768 ai AIBOTJET
  }
}

ifinwater nullop else ifgapzl 48
{
	setvar botdodge 0
	ifai AIBOTDODGE
	{
		ifvare playerally -1 ai AIBOTFACEPLAYER 
		else ai AIBOTSEEKPLAYER
	}
	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
}

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

ifvarg botdodge 0 subvar botdodge 1

ifvarand monstflags 8
{
	addvar mtype 1
	ifvarg mtype 25 { state checkhealth setvar mtype 0 }
}

addvar countvar 1
// ifvare playerally -1 ifvarn target2 -1 nullop else // medical bots on the way to heal someone do not find new targets
ifvarg countvar 25
{
	setvar countvar 0
	state botfindtarget
	ifvarn target -1
	{
	  ifvarl ammo 1 setvar weap 2 else ifrnd 64
	  state switchweapon
	  state visibilitycheck
  	}
}


getactor[THISACTOR].htextra bleeding
ifvarg bleeding 0
ifvare playerally -1
{
	getactor[THISACTOR].htowner spriteid
	ifvarn spriteid -1
	{
		getactor[spriteid].picnum picnum
		{
			
			ifvarn picnum APLAYER
			{
				ifvare target -1 setvarvar target spriteid
			}
			else
			{
				setvar bleeding 0
				setactor[THISACTOR].htextra -1
			}
		}
	}
}

ifhitweapon state checkbothit

ifvarn playerally -1 break

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

ends

useractor notenemy BOTALLY 140

ifvarn lotag 1 break

state botallycode
enda

useractor notenemy BOTALLYCROUCH 140
ifvarn lotag 1 break
state botallycode
enda

useractor notenemy NOTHING 0 killit enda



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

action CIRCLE_ANIMATION 0 9 1 1 9

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

  ifactioncount 9 killit
enda


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

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

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



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

useractor notenemy LASERIMPACT 0

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

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

enda

useractor notenemy ROCKETHALO 0

ifvare countvar 0
{
	ifspawnedby FIRELASER 
	{
		sizeat 12 12 
		state sparkstate
	} else
	ifspawnedby BIGFIRELASER sizeat 16 16
	else
	ifvare myspawner -1 sizeat 9 9
	else
	{
		getactor[myspawner].xrepeat x
		shiftvarr x 1
		//ifvarl x 9 setvar x 9
		setactor[THISACTOR].xrepeat x
		setactor[THISACTOR].yrepeat x
	}
	ifvare rendmode 0
	{
		getactor[THISACTOR].xrepeat x
		shiftvarr x 1
		setactor[THISACTOR].xrepeat x
		setactor[THISACTOR].yrepeat x
	}
}
cstat 642

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

useractor notenemy SHRINKERHALO 0

cstat 130
ifrnd 128 cstator 4
ifrnd 128 cstator 8
sizeat 64 64
ifcount 1 killit

enda

spritenoshade BULLETFLASH
spritenoshade BULLETFLASHLOW
action BULFLS 0 3 1 1 5

state bulletflashcode
setactor[THISACTOR].shade -127
sizeat 16 16
ifactioncount 3 killit
ends

useractor notenemy BULLETFLASH 0 BULFLS state bulletflashcode enda
useractor notenemy BULLETFLASHLOW 0 BULFLS state bulletflashcode enda


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


action BLIMPWAITTORESPAWN

state blimphitstate
  cstat 0
  spawn FIRSTGUNSPRITE
  spawn EXPLOSION2

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

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

actor BLIMP 1

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

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



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


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

state moveitem

fall

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

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

state jibfood
  sound SQUISHED
  guts JIBS6 3
  killit
ends

state breakobject

state moveitem

getactor[THISACTOR].cstat temp
ifvarand temp 16 nullop else
ifvarand temp 32 nullop else
ifvarn sprite[THISACTOR].picnum METER

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

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

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

      fall
  }

ends

state potcode

	setvar bouncesound BOUNCEMETALSND
	
	state moveitem
	

  fall
  strength 0
  ifhitweapon
  {
    state HITMETALSOUND
  	state sparkstate 
  }

ends

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


action ABURGERROTS 0 1 5

useractor notenemy 851 WEAK setvar bouncesound PIPEBOMB_BOUNCE state breakobject enda

useractor notenemy DUKEBURGER PIRATEGALSTRENGTH ABURGERROTS setvar bouncesound FOODLAND state breakobject enda

useractor notenemy MOP WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy BROOM WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy WETFLOOR WEAK setvar bouncesound ENDSEQVOL2SND4 state breakobject enda

useractor notenemy DESKLAMP WEAK setvar bouncesound PIPEBOMB_BOUNCE state breakobject enda

useractor notenemy DUKECUTOUT WEAK state breakobject enda

useractor notenemy FETUSJIB WEAK state breakobject enda

useractor notenemy HATRACK WEAK setvar bouncesound PIPEBOMB_BOUNCE state breakobject enda

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

useractor notenemy COFFEEMACHINE WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy TEDDYBEAR WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy TOPSECRET WEAK state breakobject enda

useractor notenemy ROBOTMOUSE ROBOTMOUSESTRENGTH setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy MAN PIRATEGALSTRENGTH state breakobject enda

useractor notenemy MAN2 PIRATEGALSTRENGTH state breakobject enda

useractor notenemy WOMAN PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE1A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE2A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE3A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE4A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE5A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE6A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy ROBOTPIRATE PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATEHALF TOUGH state breakobject enda

useractor notenemy CHESTOFGOLD WEAK state breakobject enda

useractor notenemy ROBOTDOG PIRATEGALSTRENGTH state breakobject enda

useractor notenemy ROBOTDOG2 TOUGH setvar bouncesound WHINING_DOG state breakobject enda

useractor notenemy PLEASEWAIT  setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy FOODOBJECT1 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT2 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT3 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT4 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT5 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT6 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT7 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT8 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT9 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT10 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT11 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT12 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT13 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT14 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT15 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT16 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT17 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT18 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT19 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FOODOBJECT20 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy JOLLYMEAL WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy GUMBALLMACHINE WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy GUMBALLMACHINEBROKE WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy POLICELIGHTPOLE TOUGH setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy CLOCK WEAK setvar bouncesound PIPEBOMB_BOUNCE state breakobject enda

useractor notenemy MAILBAG WEAK state breakobject enda

useractor notenemy FEATHEREDCHICKEN WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy SKINNEDCHICKEN WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy HEADLAMP WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy DOLPHIN1 DOLPHINSTRENGTH state breakobject enda

useractor notenemy DOLPHIN2 DOLPHINSTRENGTH state breakobject enda

useractor notenemy SNAKEP MEDIUMSTRENGTH setvar bouncesound FOODLAND state breakobject enda

useractor notenemy DONUTS WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy GAVALS WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy GAVALS2 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy CUPS WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy DONUTS2 WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy FLOORBASKET WEAK setvar bouncesound ENDSEQVOL2SND4 state breakobject enda

useractor notenemy METER WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy DESKPHONE WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy MACE WEAK setvar bouncesound FOODLAND state breakobject enda

useractor notenemy SHOPPINGCART WEAK setvar bouncesound BOUNCEMETALSND state breakobject enda

useractor notenemy COFFEEMUG WEAK setvar bouncesound PIPEBOMB_BOUNCE state breakobject enda

useractor notenemy POT3 WEAK state breakobject enda

useractor notenemy SUSHIPLATE1 WEAK state breakobject enda

useractor notenemy SUSHIPLATE2 WEAK state breakobject enda

useractor notenemy SUSHIPLATE3 WEAK state breakobject enda

useractor notenemy SUSHIPLATE4 WEAK state breakobject enda

useractor notenemy SUSHIPLATE5 WEAK state breakobject enda

useractor notenemy BOX WEAK state breakobject enda

useractor notenemy AMERICANFLAG TOUGH setvar bouncesound ENDSEQVOL2SND4 state breakobject enda


action DPHYDROBROKE 1 1 1
useractor notenemy DPHYDROPLANT WEAK
cstator 256

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

enda


action EXPBARRELFRAME     0   2   1   1   10
actor EXPLODINGBARREL 26

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
    action EXPBARRELFRAME
  
    
    state moveitem

	getactor[THISACTOR].zvel temp
	ifvarg temp 0 setvar mtype 1 // falling
	ifvare mtype 1 ifvare temp 0 { soundvar bouncesound setvar mtype 0 }

  fall
  
enda

action BURNING_FLAME  0   12   1   1   2
move BURNING_VELS 

state burningstate

  sleeptime 300


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

   ifpdistg 10240
     break

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

    ifvare peractor1 1 sizeto 26 26 else
    sizeto 52 52

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

ends

actor BURNING WEAK BURNING_FLAME
  state burningstate
enda

actor BURNING2 WEAK BURNING_FLAME
  state burningstate
enda

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

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

action FOUNTAINIDLE -1
action FOUNTAINFLOW 0 3 1 1 6

useractor notenemy WATERFOUNTAIN2 15

ifaction 0 action FOUNTAINIDLE

ifhitweapon ifdead
{
	cactor WATERFOUNTAINBROKE
	spawn TOILETWATER
	sound VENT_BUST
	break
}

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

ifaction FOUNTAINFLOW ifactioncount 12 action FOUNTAINIDLE

enda 

action WOODENHORSEFRAME  0   1   4
action WOODENFALLFRAME  122  1   5

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

state moveitem

	getactor[THISACTOR].zvel temp
	ifvarg temp 0 setvar mtype 1 // falling
	ifvare mtype 1 ifvare temp 0 { soundvar bouncesound setvar mtype 0 }


  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
  {
	
    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 THISACTOR MAXSPRITES killit
ifvarl framerate 20 killit

  ifmove 0
  {
	  ifvare monstatus 1 killit
	  ifinwater { spawn WATERBUBBLE killit break }
	  ifspawnedby SHOTSPARK1
	  {
		  getactor[THISACTOR].owner spriteid
		  ifvarn spriteid -1
		  {
			  getactorvar[spriteid].mtype temp
			  ifvare temp 1 { ifrnd 32 guts JIBS6 1 killit break }
		  }
		  ifonwater iffloordistl 16 killit
	  }
      
    ifvare peractor1 1
    {
	  
		 getactor[THISACTOR].z z
		 subvar z 3072
		 setactor[THISACTOR].z z
	 	 cstat 514
     	 move ENGINE_SMOKE geth getv randomangle
      
    }
  	action 0 setvar mtype 1 
  	changespritestat THISACTOR 1 
  	cactor NEWSMOKE
  	break 
    // code below this line does nothing
    

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

move SMOKEMOVE 0 -14
move SMOKEMOVE3 32 -32
move SMOKEMOVE4 16 -32
move SMOKEMOVE5 0 -32

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

useractor notenemy NEWSMOKE 0

ifvarg THISACTOR MAXSPRITES killit
ifvarl framerate 20 killit

ifmove 0
{
	ifvare rendmode 0 cstator 514
	ifrnd 128 cstator 8
	ifrnd 128 cstator 4

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

ifaction NEWSMOKEA ifactioncount 8 cstator 512
	         
ifactioncount 12 killit

ifpdistl 1596
    ifspawnedby RPG
      killit

//   ifinwater
//   { 
//     spawn WATERBUBBLE
//     killit
//   }
  
enda

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

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

ifactioncount 12 killit
enda

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

ifactioncount 12 killit

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

useractor notenemy POISONGASMAKER 0

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

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


enda

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

move SPAWNED_BLOOD

actor NUKEBARRELDENTED WEAK
  cactor NUKEBARREL
  action BARREL_DENTED
enda

actor NUKEBARRELLEAKED WEAK
  cactor NUKEBARREL
  action BARREL_DENTED2
enda


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

actor NUKEBARREL MEDIUMSTRENGTH

setvar bouncesound METALTHUD
state moveitem

	getactor[THISACTOR].zvel temp
	ifvarg temp 0 setvar mtype 1 // falling
	ifvare mtype 1 ifvare temp 0 { soundvar bouncesound setvar mtype 0 }

  ifsquished
  {
    debris SCRAP1 32
    spawn BLOODPOOL
    state random_ooz
    killit
  }
  //ifvarand monstflags 1 
  
  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
state moveitem


getactor[THISACTOR].zvel temp
ifvarg temp 0 setvar mtype 1 // falling
ifvare mtype 1 ifvare temp 0 { soundvar bouncesound setvar mtype 0 }



  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

ifcount 1 nullop else 
 ifvare peractor1 1 
 {
	 shoot SHRINKRADIUSPROJ
	 ifvarg weaplev6 5 spawn VORTEXOFDOOM
 }
  ifactioncount 4
    killit
enda

move AWAYFROMWALL 24
spritenoshade VORTEXOFDOOM
useractor notenemy VORTEXOFDOOM 0

ifmove 0
{
	cstator 130
	spritepal 8
	move AWAYFROMWALL faceplayer
	setvar peractor1 1
}
ifcount 208
{
	cstator 512
	sizeto 0 0
	sizeto 0 0
	setvar peractor1 0
}
else
{
	getactor[THISACTOR].x initx
	getactor[THISACTOR].y inity
	ifcount 156 { sizeto 0 0 sizeto 0 0 }
	else { sizeto 64 64 sizeto 64 64 sizeto 64 64 }
	
	headspritestat spriteid 1
	whilevarn spriteid -1
	{
		ifvare actorvar[spriteid].monstatus 1
		{
			setvarvar temp weaplev6
			shiftvarl temp 9
			addvar temp 5120
			dist xydist THISACTOR spriteid
			ifvarvarl xydist temp
			{
				setvarvar mx initx
				setvarvar my inity
				getactor[spriteid].x x
				getactor[spriteid].y y
				subvarvar mx x
				subvarvar my y
				getangle angvar mx my
				ifvarg xydist 1024
				addvar angvar 448
				
				cos xvel angvar
				sin yvel angvar
				setvarvar temp xydist
				shiftvarr temp 6
				ifvarl temp 32 setvar temp 32
				divvarvar xvel temp
				divvarvar yvel temp

				setvar zvel 0

				movesprite spriteid xvel yvel 0 CLIPMASK0 RETURN
				getactor[THISACTOR].z z
				addvar z 2048
				getactor[spriteid].z mz
				ifvarvarl z mz { subvar mz 1024 setactor[spriteid].zvel -2048 } else
				ifvarvarg z mz { addvar mz 1024 setactor[spriteid].zvel 2048 }
				setactor[spriteid].z mz
				
				
				ifvarl xydist 1280
				ifvarg sprite[spriteid].xrepeat 16
				ifvarn sprite[spriteid].htpicnum SHRINKSPARK
				{
					setactor[spriteid].htpicnum SHRINKSPARK
					ifvarl sprite[spriteid].htextra 2 setactor[spriteid].htextra 2
					setactor[spriteid].htowner player[THISACTOR].i
				}
			}
		}
		nextspritestat spriteid spriteid
	}
}

enda


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

ifactorsound THISACTOR PIPEBOMB_EXPLODE
{
	getactor[THISACTOR].picnum picnum
	stopactorsound THISACTOR PIPEBOMB_EXPLODE
	displayrandvar temp 4
	ifvarl temp 2 sound PIPEBOMB_EXPLODE2 else
	ifvare temp 2 sound NEW_EXPLODE else
	ifvare temp 3 sound NEW_EXPLODE2 else
	sound NEW_EXPLODE3
}
ifactorsound THISACTOR RPG_EXPLODE
{
	getactor[THISACTOR].picnum picnum
	stopactorsound THISACTOR RPG_EXPLODE
	displayrandvar temp 4
	ifvarl temp 2 sound RPG_EXPLODE2 else
	ifvare temp 2 sound NEW_EXPLODE else
	ifvare temp 3 sound NEW_EXPLODE2 else
	sound NEW_EXPLODE3
}

ifcount 1 nullop else
{
	
// 	ifvarn sprite[THISACTOR].htpicnum DUKECAR
// 	{
// 		randvar temp 3
// 		ifvare temp 0 
// 		{
// 			ifspawnedby RPG { ifinwater globalsound RPG_EXPLODE2 else sound RPG_EXPLODE2 }
// 			else { ifinwater globalsound PIPEBOMB_EXPLODE2 else sound PIPEBOMB_EXPLODE2 }
// 		}
// 		ifvare temp 1 { ifinwater globalsound NEW_EXPLODE else sound NEW_EXPLODE } else
// 		ifvare temp 2 { ifinwater globalsound NEW_EXPLODE2 else sound NEW_EXPLODE2 } else
// 		ifvare temp 3 { ifinwater globalsound NEW_EXPLODE3 else sound NEW_EXPLODE3 }
// 	}
	

	
	ifrnd 128 action EXPLOSION_FRAMES2 else action EXPLOSION_FRAMES3
	ifspawnedby RPG
	move AWAYFROMWALL faceplayer else
	ifspawnedby HEAVYHBOMB
	move AWAYFROMWALL faceplayer
	
	// ifvare smartmonsters YES 
	state wakeupmonsters
	ifrnd 128 cstator 4
	ifrnd 128 cstator 8
	ifspawnedby HEAVYHBOMB
	{
		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
		}
	}
	ifspawnedby MININUKE
	{
		sizeat 24 24
		cstator 128
	}
	ifspawnedby BOMBLET
		sizeat 16 16
	
	ifspawnedby FIREBALLPROJ 
	{
		sizeat 16 16
		cstator 128
		ifrnd 64 spawn BURNING else ifrnd 64 spawn BURNING2
	}
	ifspawnedby BIGBOMB
	{
		sizeat 64 64
		hitradius 3072 30 40 50 60
		espawn SCORCH
		state getfloorz
		setactor[RETURN].z z
		setactor[RETURN].cstat 32
		setactorvar[RETURN].lotag 1
	}
			
	ifvare peractor1 1 
		sizeat 80 80
	
	ifvare weap 1 sizeat 16 16
	ifvare weap 8 sizeat 8 8
	
	// size hack to compensate for tilefromtexture
	getactor[THISACTOR].xrepeat x
	shiftvarl x 1 divvar x 3
	setactor[THISACTOR].xrepeat x
	getactor[THISACTOR].yrepeat y
	shiftvarl y 1 divvar y 3
	setactor[THISACTOR].yrepeat y
}

ifcount 18 nullop else ifcount 17
{
	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
}

  ifactioncount 20
    killit
    
  
enda

actor EXPLOSION2BOT 1 EXPLOSION_FRAMES

  ifactioncount 20
    killit
enda

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

actor FLOORFLAME 0 FFLAME_FR

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



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

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

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


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

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


state lifebarcode

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

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


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

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

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

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

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

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

useractor notenemy LIFEBAR 0
state lifebarcode
enda

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

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

state randgetweapsnds

ifactor LASERPISTOL
ifvarl LASERAMMO 31
ifvarl weapxp10 100 { globalsound ALIENTECH break }
globalsound GUNPICK
  ifrnd 64
    globalsound DUKE_GETWEAPON1
  else
    ifrnd 96
      globalsound DUKE_GETWEAPON2
  else
    ifrnd 128
      globalsound DUKE_GETWEAPON3
  else
    ifrnd 140
      globalsound DUKE_GETWEAPON4
  else
    globalsound DUKE_GETWEAPON6
ends

state getweaponcode

  state randgetweapsnds

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


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

state quikget
  ifactor AMMO
    globalsound AMMOPICK
  else
  ifactor SHOTGUNAMMO
    globalsound SHOTPICK
  else
  ifactor BATTERYAMMO
    globalsound CHAINPICK
  else
   ifactor RPGAMMO
    globalsound RPGPICK
  else
   ifactor CRYSTALAMMO
    globalsound SHRINKPICK
  else
  ifactor DEVISTATORAMMO
    globalsound RPGPICK
  else
  ifactor FREEZEAMMO
    globalsound FREEZEPICK
  else
  ifactor GROWAMMO
    globalsound GROWPICK
  else
  ifactor ATOMICHEALTH
    globalsound GETATOMICHEALTH
  else
  ifactor SHIELD
    globalsound ARMORPICK
  else
    globalsound DUKE_GET
  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
	getactor[THISACTOR].cstat tempb
	orvar tempb 257
	ifvarand tempb 16 xorvar tempb 16
	ifvarand tempb 32 xorvar tempb 32
	setactor[RETURN].cstat tempb
	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

shiftvarr xvel 3
shiftvarr yvel 3
movesprite RETURN xvel yvel 0 CLIPMASK0 temp
ends


actor AMMOPACK
sizeat 40 40
  fall
state moveitem
setactor[THISACTOR].shade -60

    ifp pshrunk nullop
    else
      // ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
              ifcanseetarget
      {
	    ifrnd 128
	    {
	        globalsound AMMO_MAX
	        setvar RETURN 1052 state itemquote
	        
	
	        getplayer[THISACTOR].max_ammo_amount 1 tempb
	        addvar tempb 12
	        setplayer[THISACTOR].max_ammo_amount 1 tempb
	        
	        getplayer[THISACTOR].max_ammo_amount 2 tempb
	        addvar tempb 3
	        setplayer[THISACTOR].max_ammo_amount 2 tempb
	        
	        getplayer[THISACTOR].max_ammo_amount 3 tempb
	        addvar tempb 20
	        setplayer[THISACTOR].max_ammo_amount 3 tempb
	        
	        getplayer[THISACTOR].max_ammo_amount 4 tempb
	        addvar tempb 1
	        setplayer[THISACTOR].max_ammo_amount 4 tempb
	        
	        getplayer[THISACTOR].max_ammo_amount 5 tempb
	        addvar tempb 1
	        setplayer[THISACTOR].max_ammo_amount 5 tempb
	        
	        getplayer[THISACTOR].max_ammo_amount 6 tempb
	        addvar tempb 1
	        setplayer[THISACTOR].max_ammo_amount 6 tempb
	                
	        getplayer[THISACTOR].max_ammo_amount 7 tempb
	        addvar tempb 8
	        setplayer[THISACTOR].max_ammo_amount 7 tempb
	        
	        getplayer[THISACTOR].max_ammo_amount 8 tempb
	        addvar tempb 1
	        setplayer[THISACTOR].max_ammo_amount 8 tempb
	
	        getplayer[THISACTOR].max_ammo_amount 9 tempb
	        addvar tempb 8
	        setplayer[THISACTOR].max_ammo_amount 9 tempb
	        
	
	        getplayer[THISACTOR].max_ammo_amount 11 tempb
	        addvar tempb 3
	        setplayer[THISACTOR].max_ammo_amount 11 tempb
	    
	        ifspawnedby AMMOPACK
	          state getcode
	        else
	          state quikget
         }
         else
         {
	         setvar RETURN 1060 state itemquote
	         globalsound ENDSEQVOL2SND5
	         randvar temp 9
	         switch temp
	         case 0 spawn AMMO break
	         case 1 spawn SHOTGUNAMMO break
	         case 2 spawn BATTERYAMMO break
	         case 3 spawn RPGAMMO break
	         case 4 spawn CRYSTALAMMO break
	         case 5 spawn GROWAMMO break
	         case 6 spawn DEVISTATORAMMO break
	         case 7 spawn FREEZEAMMO break
	         case 8 spawn TRIPBOMBSPRITE break
	         case 9 spawn LASERPISTOL break
	         endswitch
	         
	         killit
         }
         
      }
enda

actor STEROIDS
  fall
  state moveitem
  
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  ifvare mtype 1
  {
	  cstator 2
	  spriteflags 64
	  ifspritepal 0 spritepal 6
	  else spritepal 0
  }
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk
      nullop
    else
      //ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
   {
	   ifvare mtype 1
	   {
		   globalsound IMP_AMMO
		   palfrom 40 30 50 20
		   addvar steroidlevel 1
		   setvar RETURN 1056 state itemquote
		   ifvarl player[THISACTOR].steroids_amount 50
		   addinventory GET_STEROIDS 50
		   killit
		   break
	   }
      
	   ifpinventory GET_STEROIDS STEROID_AMOUNT   
      {
        addinventory GET_STEROIDS STEROID_AMOUNT
        setvar invicon 2
		setvar invmsg 78
        setvar RETURN 37 state itemquote
        ifspawnedby STEROIDS
          state getcode
        else
          state quikget
      }
   }


enda

actor BOOTS
  fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  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 invicon 7
		setvar invmsg 78
        setvar RETURN 6 state itemquote
        ifspawnedby BOOTS
          state getcode
        else
          state quikget
      }

enda

actor ESHIELDSPRITE

  fall
  sizeat 42 42
  ifspritepal 0 spritepal 10 else ifspritepal 10 spritepal 16 else ifspritepal 16 spritepal 23 else spritepal 0
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768

  ifvarg rage 0 ifvarl rage FULLRAGE nullop
  else
    ifp pshrunk
      nullop
    else
    ifvare eshield 0
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
              ifcanseetarget
      {
	    setvar RETURN 1047 state itemquote
        globalsound ESHIELDPICK
        setvar eshield 600
        palfrom 40 50 50 63
        killit
      }

enda

spriteshadow ROFSPRITE
spritenopal ROFSPRITE
actor ROFSPRITE

fall
sizeat 32 32
cstat 16
spritepal 10
getactor[THISACTOR].ang angvar
addvar angvar 31
setactor[THISACTOR].ang angvar
state moveitem

  setactor[THISACTOR].mdflags 16
  setvar position 32768

    ifp pshrunk
      nullop
    else
    ifvare rofbonus 0
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
              ifcanseetarget
      {
	    setvar RETURN 1046 state itemquote
        globalsound ROFPICK
        setvar rofbonus 1800
        palfrom 40 50 50 63
        killit
      }

enda

spriteshadow XPSPRITE
spritenopal XPSPRITE
actor XPSPRITE

fall
sizeat 32 32
cstat 16
spritepal 14
getactor[THISACTOR].ang angvar
addvar angvar 31
setactor[THISACTOR].ang angvar
state moveitem

  setactor[THISACTOR].mdflags 16
  setvar position 32768

    ifp pshrunk
      nullop
    else
    ifvare xpbonus 0
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
              ifcanseetarget
      {
	    setvar RETURN 1045 state itemquote
        globalsound XPICK
        setvar xpbonus 1800
        palfrom 40 50 63 50
        killit
      }


enda

actor HEATSENSOR

  fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare mtype 1
  {
	  cstator 2
	  ifspritepal 6 spritepal 0 else spritepal 6
	  spriteflags 64
  }
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk
      nullop
  else
    // ifp palive
      ifcount 6
        ifpdistl RETRIEVEDISTANCE
          // ifpinventory GET_HEATS HEAT_AMOUNT
            ifcanseetarget
      {
	      
	    ifvare mtype 1
	    {
		    globalsound GOGGPICK
		    getplayer[THISACTOR].heat_amount temp
		    addvar temp 480
		    ifvarg temp HEAT_AMOUNT setvar temp HEAT_AMOUNT
		    setplayer[THISACTOR].heat_amount temp
		    addvar gogglevel 1
		    palfrom 32 0 48 0
		    setvar RETURN 1048 state itemquote
		    killit
	    }
	    ifpinventory GET_HEATS HEAT_AMOUNT nullop else break
	    
        addinventory GET_HEATS HEAT_AMOUNT
        setvar invicon 5
		setvar invmsg 78
        setvar RETURN 101 state itemquote
        ifspawnedby HEATSENSOR
          state getcode
        else
          state quikget
      }

enda

actor SHIELD
  fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare mtype 1
  {
	  cstator 2
	  ifspritepal 6 spritepal 0 else spritepal 6
	  spriteflags 64
  }
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      // ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
           ifcanseetarget
{
 	ifvare mtype 1
    {
	    globalsound ARMORPICK
	    getplayer[THISACTOR].max_shield_amount temp
	    addvar temp 5
	    setplayer[THISACTOR].max_shield_amount temp
	    getplayer[THISACTOR].shield_amount tempb
	    addvar tempb 20
	    ifvarvarg tempb temp setvarvar tempb temp
	    setplayer[THISACTOR].shield_amount tempb
	    palfrom 24 10 40 10
	    setvar RETURN 1051 state itemquote
	    killit
    }
      ifpinventory GET_SHIELD SHIELD_AMOUNT 
      {
	   
		ifvare sprite[THISACTOR].htpicnum LIZMAN setactor[THISACTOR].htpicnum PIGCOP
        ifspawnedby PIGCOP
        {
          ifrnd 128
            addinventory GET_SHIELD PIG_SHIELD_AMOUNT1
          else
            addinventory GET_SHIELD PIG_SHIELD_AMOUNT2
          setvar RETURN 104 state itemquote
          globalsound ARMORPICK
          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
  fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  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 invicon 6
		setvar invmsg 78
        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

ifvare mtype 1
{
	ifspritepal 0 spritepal 6 else spritepal 0
	spriteflags 64
	cstator 2
}
  fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      // ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
   {
	   ifvare mtype 1
	   {
		   globalsound GETATOMICHEALTH
		   palfrom 40 0 30 50
		   getplayer[THISACTOR].holoduke_amount temp

		   setvar RETURN 1055 
		   addvar botlevel 1
		   addvar temp 300
	       
	       // ifvarg temp HOLODUKE_AMOUNT setvar temp HOLODUKE_AMOUNT
	       setvarvar tempb botlevel
	       shiftvarl tempb 7
	       addvar tempb HOLODUKE_AMOUNT
	       ifvarvarg temp tempb setvarvar temp tempb
	       setplayer[THISACTOR].holoduke_amount temp
		   state itemquote
		   killit
	   }
	   
       ifpinventory GET_HOLODUKE HOLODUKE_AMOUNT
          ifcanseetarget
      {
        // addinventory GET_HOLODUKE HOLODUKE_AMOUNT
        setvarvar tempb botlevel
	    shiftvarl tempb 7
	    addvar tempb HOLODUKE_AMOUNT
	    ifvarvare player[THISACTOR].holoduke_amount tempb break
	    
	    getplayer[THISACTOR].holoduke_amount temp
	    addvar temp HOLODUKE_AMOUNT
	    ifvarvarg temp tempb setvarvar temp tempb
	    setplayer[THISACTOR].holoduke_amount temp
        
        setvar invicon 3
		setvar invmsg 78
        setvar RETURN 51 state itemquote
        ifspawnedby HOLODUKE
          state getcode
        else
          state quikget
      }
   }

enda

actor JETPACK
  fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  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 invicon 4
		setvar invmsg 78
        setvar RETURN 41 state itemquote
        ifspawnedby JETPACK
          state getcode
        else
          state quikget
      }

enda

actor ACCESSCARD
  fall
  
  setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  ifvarn peractor4 0 setvar mtype 1 // was dropped
  ifvare mtype 1 ifpdistl 8192 quote 1124
  //state moveitem
  //
  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

  fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
              ifvarvarl player[THISACTOR].ammo_amount 1 player[THISACTOR].max_ammo_amount 1
      {
	    ifvare CURRWEAP 0 ifvarg LASERAMMO 0
	    {
		    // this hack is necessary for preventing the addammo from switching the player to pistol
		    getplayer[THISACTOR].ammo_amount 1 temp
		    addvar temp PISTOLAMMOAMOUNT
		    ifvarvarg temp player[THISACTOR].max_ammo_amount 1 
		      getplayer[THISACTOR].max_ammo_amount 1 temp
		    setplayer[THISACTOR].ammo_amount 1 temp
	    }
	    else
        addammo PISTOL_WEAPON PISTOLAMMOAMOUNT
        setvar RETURN 65 state itemquote
        ifspawnedby AMMO
          state getcode
        else
          state quikget
      }

enda

actor FREEZEAMMO
  fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  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
  fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
               ifvarvarl player[THISACTOR].ammo_amount 2 player[THISACTOR].max_ammo_amount 2
      {
	      
	    ifvare CURRWEAP 0 ifvarg LASERAMMO 0
	    {
		    // this hack is necessary for preventing the addammo from switching the player to pistol
		    getplayer[THISACTOR].ammo_amount 2 temp
		    addvar temp SHOTGUNAMMOAMOUNT
		    ifvarvarg temp player[THISACTOR].max_ammo_amount 2
		      getplayer[THISACTOR].max_ammo_amount 2 temp
		    setplayer[THISACTOR].ammo_amount 2 temp
	    }
	    else
        
        addammo SHOTGUN_WEAPON SHOTGUNAMMOAMOUNT
        setvar RETURN 69 state itemquote
        ifspawnedby SHOTGUNAMMO
          state getcode
        else
          state quikget
      }

enda

actor AMMOLOTS
  fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  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
   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  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
   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  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 BATTERYAMMO

   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarand ALTCHAINGUN 2
	    {
		    setvarvar temp MINIGUNAMMO
		    addvar temp 1
		    ifvarvarg temp player[THISACTOR].max_ammo_amount 3 break
		    addvar MINIGUNAMMO CHAINGUNAMMOAMOUNT
		    ifvarvarg MINIGUNAMMO player[THISACTOR].max_ammo_amount 3
		    setvarvar MINIGUNAMMO player[THISACTOR].max_ammo_amount 3
	    }
	    else
	    ifvare CURRWEAP 0 ifvarg LASERAMMO 0
	    {
		    ifvarvarl player[THISACTOR].ammo_amount 3 player[THISACTOR].max_ammo_amount 3 nullop else break
		    // this hack is necessary for preventing the addammo from switching the player to pistol
		    getplayer[THISACTOR].ammo_amount 3 temp
		    addvar temp CHAINGUNAMMOAMOUNT
		    ifvarvarg temp player[THISACTOR].max_ammo_amount 3
		      getplayer[THISACTOR].max_ammo_amount 3 temp
		    setplayer[THISACTOR].ammo_amount 3 temp
	    }
	    else      
        addammo CHAINGUN_WEAPON CHAINGUNAMMOAMOUNT
        setvar RETURN 63 state itemquote
      	
        ifspawnedby BATTERYAMMO
          state getcode
        else
          state quikget
      }

enda

action BFGAMMOFRAME 6175 1 1 1 1

actor DEVISTATORAMMO
   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  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
   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else ifp palive
      ifpdistl RETRIEVEDISTANCE
        ifcount 6
          ifcanseetarget
          	ifvarvarl player[THISACTOR].ammo_amount 4 player[THISACTOR].max_ammo_amount 4
      {
	      
	    ifvare CURRWEAP 0 ifvarg LASERAMMO 0
	    {
		    // this hack is necessary for preventing the addammo from switching the player to pistol
		    getplayer[THISACTOR].ammo_amount 4 temp
		    addvar temp RPGAMMOBOX
		    ifvarvarg temp player[THISACTOR].max_ammo_amount 4
		      getplayer[THISACTOR].max_ammo_amount 4 temp
		    setplayer[THISACTOR].ammo_amount 4 temp
	    }
	    else
        
        addammo RPG_WEAPON RPGAMMOBOX
        setvar RETURN 64 state itemquote
        ifspawnedby RPGAMMO
          state getcode
        else
          state quikget
      }

enda

actor HBOMBAMMO
   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  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
   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  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 SHOTGUNSPRITE

   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        ifspawnedby PIGCOP
        {
          addweapon SHOTGUN_WEAPON 0
          ifrnd 64
            addammo SHOTGUN_WEAPON 4
          else ifrnd 64
            addammo SHOTGUN_WEAPON 3
          else ifrnd 64
            addammo SHOTGUN_WEAPON 2
          else
            addammo SHOTGUN_WEAPON 1
        }
        else
        { 
          addweapon SHOTGUN_WEAPON SHOTGUNAMMOAMOUNT      	  
          setvar RETURN 57 state itemquote
        }

        ifspawnedby SHOTGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }

enda

actor MINIGUNSPRITE

sizeat 32 32
 fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  

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

enda

state healingbonus

getplayer[THISACTOR].i spriteid
getactor[spriteid].extra tempb

getplayer[THISACTOR].max_player_health tempc
subvarvar tempc tempb
ifvarvarg tempc hp { setvarvar tempc hp setvar hp 0 }
else subvarvar hp tempc
ifvarg tempc 29 { addphealth 30 subvar tempc 30 getactor[spriteid].extra tempb }
else ifvarg tempc 9 { addphealth 10 subvar tempc 10 getactor[spriteid].extra tempb }
addvarvar tempb tempc
setactor[spriteid].extra tempb


ends

actor SIXPAK
   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
    
  ifvare inithp 0 
  {
	  setvar inithp 1 
	  setvar hp 30
	  setvarvar temp maxmedkit
	  subvar temp FIRSTAID_MAX
	  ifvarg temp 290 setvar temp 290
	  addvarvar hp temp
  }

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
              ifcanseetarget
      {
	    getplayer[THISACTOR].i spriteid
	    ifvarvarl sprite[spriteid].extra player[THISACTOR].max_player_health
	    {
		    //addphealth 30
		    state healingbonus
		    setvar RETURN 62 state itemquote
		    ifvarg hp 0
		    {
				globalsound DUKE_GET
	  			palfrom 16 0 32
	  			setvarvar temp hp
	  			shiftvarr temp 2
	  			addvar temp 6
	  			setactor[THISACTOR].xrepeat temp
	  			setactor[THISACTOR].yrepeat temp
	  			break
			}
		    ifspawnedby SIXPAK
          		state getcode
        	else
          		state quikget
		} 
		else
	    {
		    getplayer[THISACTOR].firstaid_amount temp
		    setvarvar tempb maxmedkit
		    subvar tempb 1
		    ifvarvarg temp tempb break
		    
		    setvarvar tempc maxmedkit
		    subvarvar tempc player[THISACTOR].firstaid_amount
		    
		    ifvarvarg tempc hp { setvarvar tempc hp setvar hp 0 }
		    else { subvarvar hp tempc }
		    getplayer[THISACTOR].firstaid_amount tempb
		    addvarvar tempb tempc
		    setplayer[THISACTOR].firstaid_amount tempb
			
		    setvar invicon 1
		    setvar invmsg 78
	        setvar RETURN 62 state itemquote
	        ifvarg hp 0
		    {
				globalsound DUKE_GET
	  			palfrom 16 0 32
	  			setvarvar temp hp
	  			shiftvarr temp 2
	  			addvar temp 6
	  			setactor[THISACTOR].xrepeat temp
	  			setactor[THISACTOR].yrepeat temp
	  			break
			}
	        ifspawnedby SIXPAK
	          state getcode
	        else
	          state quikget
	        killit
        }
        
      }

enda

state iconstate

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

useractor notenemy HEALTHICON 0

sizeat 32 32
ifcount 1 killit

enda

state iconstate

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

useractor notenemy CONFUSEICON 0

sizeat 128 128
ifcount 1 killit

enda

actor COLA

   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  
  ifvare inithp 0 
  {
	  setvar inithp 1 
	  setvar hp 10
	  setvarvar temp maxmedkit
	  subvar temp FIRSTAID_MAX
	  shiftvarr temp 1
	  ifvarg temp 90 setvar temp 90
	  addvarvar hp temp
  }
    
  ifvare mtype 1 // raises max health
  {
	  cstator 2
	  ifspritepal 0 spritepal 6 else spritepal 0
	  spriteflags 64
  }
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      // ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
              ifcanseetarget
      {
	    ifvare mtype 1
	    {
		    globalsound TROOPHEAL
		    getplayer[THISACTOR].max_player_health temp
		    ifvarl temp 999
		    addvar temp 1
		    setplayer[THISACTOR].max_player_health temp
		    addphealth 10
		    palfrom 24 10 40 10
		    ifvarl temp 999
		    {
		    	setvar RETURN 1050 state itemquote
	    	}
		    killit
	    }
	    getplayer[THISACTOR].i spriteid
	    ifvarvarl sprite[spriteid].extra player[THISACTOR].max_player_health
	    {
		    //addphealth 10
		    state healingbonus
		    setvar RETURN 61 state itemquote
		    ifvarg hp 0
		    {
				globalsound DUKE_GET
	  			palfrom 16 0 32
	  			setvarvar temp hp
	  			shiftvarr temp 2
	  			addvar temp 6
	  			setactor[THISACTOR].xrepeat temp
	  			setactor[THISACTOR].yrepeat temp
	  			break
			}
		    ifspawnedby COLA
          		state getcode
        	else
          		state quikget
		} 
		else
	    {
		    getplayer[THISACTOR].firstaid_amount temp
		    setvarvar tempb maxmedkit
		    subvar tempb 1
		    ifvarvarg temp tempb break
		    
		    setvarvar tempc maxmedkit
		    subvarvar tempc player[THISACTOR].firstaid_amount
		    
		    ifvarvarg tempc hp { setvarvar tempc hp setvar hp 0 }
		    else { subvarvar hp tempc }
		    getplayer[THISACTOR].firstaid_amount tempb
		    addvarvar tempb tempc
		    setplayer[THISACTOR].firstaid_amount tempb
			
		    setvar invicon 1
		    setvar invmsg 78
	        setvar RETURN 61 state itemquote
	        ifvarg hp 0
		    {
				globalsound DUKE_GET
	  			palfrom 16 0 32
	  			setvarvar temp hp
	  			shiftvarr temp 2
	  			addvar temp 6
	  			setactor[THISACTOR].xrepeat temp
	  			setactor[THISACTOR].yrepeat temp
	  			break
			}
	        ifspawnedby COLA
	          state getcode
	        else
	          state quikget
	        killit
        }
        
      }

enda

useractor notenemy DUKENUKE

ifmove 0
{
	move INIT
	cstat 32768
	setvar countvar 2
	palfrom 52 63 63 63
	quake 40
	setvar weapcount 30
	setvarvar temp nukelevel
	shiftvarl temp 1
	addvarvar weapcount temp
}

setvar countvarb 4 // 8
randvar ammo 512 // 256
setactor[THISACTOR].ang ammo
whilevarn countvarb 0
{
	randvar zdist 12288
	subvar zdist 8192
	ezshoot zdist DUKENUKEPROJ
	setthisprojectile[RETURN].range countvar
	addvar ammo 512 // 256
	setactor[THISACTOR].ang ammo
	subvar countvarb 1
}

addvar countvar 1
ifvarvarg countvar weapcount killit

headspritestat spriteid 1
whilevarn spriteid -1
{
	ifvare actorvar[spriteid].monstatus 1
	{
		dist xydist THISACTOR spriteid
		setvar temp 8
		addvarvar temp nukelevel
		mulvar temp 768
		ifvarvarl xydist temp
		{
			shiftvarr temp 2
			ifvarvarl xydist temp
			{
				ifvarl sprite[spriteid].htextra 2
				{
					shiftvarr temp 7
					setactor[spriteid].htextra temp
					setactor[spriteid].htpicnum RPG
					setactor[spriteid].htang ammo
					setactor[spriteid].htowner player[THISACTOR].i
				}
				spawn BLINDINGFLASH
				getactorvar[spriteid].stun tempb
				addvar tempb 30
				setvar tempc 100
				getactor[spriteid].extra tempd
				shiftvarr tempd 2
				subvarvar tempc tempd
				ifvarg tempc 0 addvarvar tempb tempc
				setactorvar[spriteid].stun tempb
			}
			setvarvar mx initx
			setvarvar my inity
			getactor[spriteid].x x
			getactor[spriteid].y y
			subvarvar mx x
			subvarvar my y
			getangle angvar mx my
			
			cos xvel angvar
			sin yvel angvar
			
			setvarvar temp xydist
			shiftvarr temp 6
			ifvarl temp 32 setvar temp 32
			divvarvar xvel temp
			divvarvar yvel temp		
			movesprite spriteid xvel yvel 0 CLIPMASK0 RETURN
		}
	}
	nextspritestat spriteid spriteid
}

enda

useractor notenemy DUKENUKE2

randvar zdist 8192 subvar zdist 6144 
ifrnd 128 ezshoot zdist NEWSCRAP3 else 
ezshoot zdist NEWSCRAP6
randvar temp 128
addvar temp 160
setthisprojectile[RETURN].vel temp


espawn EXPLOSION2
setactor[RETURN].xrepeat 96
setactor[RETURN].yrepeat 96

// sound?
setvar temp 20
setvar tempb 30
setvar tempc 45
setvar tempd 60
setvarvar L nukelevel
shiftvarl L 2
addvarvar temp L
addvarvar tempb L
addvarvar tempc L
addvarvar tempd L
hitradiusvar 3584 temp tempb tempc tempd
headspritestat spriteid 6
whilevarn spriteid -1
{
	getactor[spriteid].picnum picnum
	switch picnum
	case CRACK1 case CRACK2 case CRACK3 case CRACK4
	setactor[spriteid].htextra -1
	setactor[spriteid].htpicnum picnum
	break
	default break
	endswitch
	nextspritestat spriteid spriteid
}
killit

enda

move NUKERISE 0 -16

state nukecode

ifcount 52 spawn BLINDINGFLASH

ifmove NUKERISE nullop else move NUKERISE getv
ifcount 77 nullop else ifcount 76
{ soundonce LASERTRIP_ARMING
  state spawnflashes
}
ifcount 90
{
	globalsound IMP_BOOM
	espawn DUKENUKE
	setactor[RETURN].cstat 32768
	killit
}

ends

actor ATOMICHEALTH

  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
  ifvare mtype 2 // DUKE NUKE!!
  {
	  ifspritepal 0 ifvarand timer 1 spritepal 6
	  else spritepal 0
	  sizeto 255 255
	  sizeto 255 255
	  ifvare peractor4 0
	  state nukecode
	  break
  }
  
  ifvare peractor1 0 fall
  ifvare mtype 1
  {
	  ifspritepal 0 ifvarand timer 1 spritepal 6
	  else spritepal 0
	  sizeat 64 64
	
	iffloordistl 48
	ifvare peractor1 0 
	{
		randvar peractor1 1560 // random timer offset and get off the ground
		addvar peractor1 1
		getactor[THISACTOR].z initz
	}
	ifvare peractor4 0
	ifvarn peractor1 0
	{
		setactor[THISACTOR].z initz
		setvarvar temp timer
		addvarvar temp peractor1
		shiftvarl temp 6
		sin tempb temp
		shiftvarr tempb 4
		getactor[THISACTOR].z z
		subvarvar z tempb
		setactor[THISACTOR].z z
		
		iffloordistl 64 nullop else
		setvar peractor1 0
	}
	
	
  }
    

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      //ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
              ifcanseetarget
      {
	    ifvare mtype 1
	    {
		    ifvarg nukes 2 break
		    setvar RETURN 1054 state itemquote
		    addvar nukes 1
		    globalsound IMP_UP
		    palfrom 50 40 63 40
		    killit
	    }
	    //ifphealthl MAXPLAYERATOMICHEALTH 
	    getplayer[THISACTOR].i spriteid
	    getplayer[THISACTOR].max_player_health temp
	    shiftvarl temp 1
	    ifvarvarl sprite[spriteid].extra temp
	    {
		    addphealth 50
		    setvarvar tempb maxmedkit
		    subvar tempb FIRSTAID_AMOUNT
		    shiftvarr tempb 1 ifvarg tempb 150 setvar tempb 150
		    whilevarn tempb 0
		    {
			    addphealth 10
			    subvar tempb 10
			    ifvarl tempb 0 setvar tempb 0
		    }
		    setvar RETURN 19 state itemquote
		    ifspawnedby ATOMICHEALTH
          		state getcode
        	else
          		state quikget
		} 
		else
	    {
		    getplayer[THISACTOR].firstaid_amount temp
		    setvarvar tempb maxmedkit
		    subvar tempb 1
		    ifvarvarg temp tempb break
		    subvar tempb FIRSTAID_AMOUNT
		    shiftvarr tempb 1 ifvarg tempb 150 setvar tempb 150
		    addvar temp 50 addvarvar temp tempb
		    ifvarvarg temp maxmedkit setvarvar temp maxmedkit
		    setplayer[THISACTOR].firstaid_amount temp
		    setvar invicon 1
		    setvar invmsg 78
	        setvar RETURN 19 state itemquote
	        ifspawnedby ATOMICHEALTH
	          state getcode
	        else
	          state quikget
	        killit
        }
      }

enda

actor FIRSTAID
  ifvarn myspawner -1 { state iconstate break }
   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768

  ifvare inithp 0 { setvar inithp 1 ifvare mtype 1 setvar hp 20 else setvarvar hp maxmedkit }
  
  ifvare mtype 1
  {
	  cstator 2
	  ifspritepal 0 spritepal 6
	  else spritepal 0
  }

  
  ifmove RESPAWN_ACTOR_FLAG state respawnit
  else
    ifp pshrunk nullop
    else
      // ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            //ifpinventory GET_FIRSTAID FIRSTAID_AMOUNT
              ifcanseetarget
      {
	    ifvare mtype 1 addvar maxmedkit 2
	          
	    getplayer[THISACTOR].firstaid_amount temp
	    setvarvar tempb maxmedkit
	    subvar tempb 1
	    ifvarvarg temp tempb break
	    
	    setvarvar tempc maxmedkit
	    subvarvar tempc player[THISACTOR].firstaid_amount
	    

	    ifvarvarg tempc hp { setvarvar tempc hp setvar hp 0 }
	    else { subvarvar hp tempc }
	    getplayer[THISACTOR].firstaid_amount tempb
	    addvarvar tempb tempc
	    setplayer[THISACTOR].firstaid_amount tempb
	    
	    setvar invicon 1
	    
		setvar invmsg 78
        //addinventory GET_FIRSTAID FIRSTAID_AMOUNT
        ifvare mtype 1 setvar RETURN 1053 else
        setvar RETURN 3
        state itemquote
		ifvarn mtype 1 ifvarg hp 0
		{
			globalsound DUKE_GET
  			palfrom 16 0 32
  			setvarvar temp hp
  			shiftvarr temp 2
  			addvar temp 6
  			setactor[THISACTOR].xrepeat temp
  			setactor[THISACTOR].yrepeat temp
  			break
		}
        ifspawnedby FIRSTAID
          state getcode
        else
          state quikget
        killit
      }

enda

actor FIRSTGUNSPRITE
   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768

    

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

useractor notenemy LASERPISTOL 0
  sizeat 32 32
   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768

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

action RIPPLE 0 9 1 -1 6

useractor notenemy REVERSERIPPLE 0

ifvare lotag 0 break

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

enda

action PIPEFRAME -1 1 1 1 1

actor TRIPBOMBSPRITE

   fall
  state moveitem
      setactor[THISACTOR].mdflags 16
  setvar position 32768

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        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 CHAINGUNSPRITE

   fall
  state moveitem
    setactor[THISACTOR].mdflags 16
  setvar position 32768
    

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

        ifvare player[THISACTOR].gotweapon 3 YES
		ifvarand ALTCHAINGUN 2
	    {
		    ifvarvarg MINIGUNAMMO player[THISACTOR].max_ammo_amount 3 break
		    addvar MINIGUNAMMO CHAINGUNAMMOAMOUNT
		    ifvarvarg MINIGUNAMMO player[THISACTOR].max_ammo_amount 3
		    setvarvar MINIGUNAMMO player[THISACTOR].max_ammo_amount 3
	    }
	    else
        addweapon CHAINGUN_WEAPON CHAINGUNAMMOAMOUNT
        setvar RETURN 54 state itemquote
    	
    	orvar ALTCHAINGUN 8
        ifspawnedby CHAINGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
    
enda

actor SHRINKERSPRITE
   fall
  state moveitem
  setactor[THISACTOR].mdflags 16
  setvar position 32768

  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
        
        setvar RETURN 60 state itemquote
    	
        ifspawnedby SHRINKERSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
  
enda

actor GROWSPRITEICON
	sizeat 32 32
   fall
  state moveitem
      setactor[THISACTOR].mdflags 16
  setvar position 32768

  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
        
        setvar RETURN 60
        state itemquote
        ifspawnedby GROWSPRITEICON
          state getweaponcode
        else
          state quikweaponget
      }
      
enda

actor FREEZESPRITE
   fall
  state moveitem
      setactor[THISACTOR].mdflags 16
  setvar position 32768

  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
//    fall
//   state moveitem
//     

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

actor DEVISTATORSPRITE
   fall
  state moveitem
     setactor[THISACTOR].mdflags 16
  setvar position 32768 

  ifmove RESPAWN_ACTOR_FLAG state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
       ifgotweaponce 0
          break
        addweapon DEVISTATOR_WEAPON 30 // 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
  

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

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

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

ends

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

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

      sound STEPNIT

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

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

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

state femcode

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

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

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

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

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

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
          break
      }

      lotsofglass 30
	  state standard_jibs
      sound GLASS_BREAKING
      ifrnd 84
        spawn BLOODPOOL
      respawnhitag

      ifrnd 128
        sound DUKE_HIT_STRIPPER1
      else
        sound DUKE_HIT_STRIPPER2

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

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

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

        move 0
        spritepal 1
        strength 0

        sound SOMETHINGFROZE
		state icesmoke
        break
      }

      ifrnd 128
        sound DUKE_HIT_STRIPPER1
      else
        sound DUKE_HIT_STRIPPER2

      respawnhitag
      state standard_jibs
      state random_wall_jibs
      spawn BLOODPOOL

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

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

      ifactor TOUGHGAL
          state toughgalspeech
      else sound SQUISHED

      guts JIBS6 1
    }
  }
ends

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

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

state toughgaltalk
  ifp pfacing
    ifpdistl 1280
      ifhitspace
        state toughgalspeech
ends

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

actor TOUGHGAL MANWOMANSTRENGTH TOUGHGALANIM
  state toughgaltalk
  state femcode
enda

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

actor MIKE
  ifp pfacing
    ifpdistl 1280
      ifhitspace
        mikesnd
enda

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

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

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

state checkfloordist

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

ends




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

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

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

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

  addvar z 512
  setactor[THISACTOR].ang z
ends

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

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

enda

state makewound

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

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

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

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

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

ifvare CURRWEAP 1 setvarvar tempb weaplev1 else
ifvare CURRWEAP 2 setvarvar tempb weaplev2 else
ifvare CURRWEAP 3 setvarvar tempb weaplev3 else
ifvare CURRWEAP 7 setvarvar tempb weaplev7 else
setvar tempb 3
shiftvarl tempb 1
setactorvar[RETURN].countvarb tempb
ifvare CURRWEAP 3 ifvarg weaplev3 3 setactorvar[RETURN].pal 8
ends

state bullethitsprite
switch picnum
case FIREBALLPROJ
setactor[temp].yvel 0
break
case WATERTILE2
case WATERFLOW
spawn WATERSPLASH3
sound ITEM_SPLASH
break
case POWBALL
ifspawnedby APLAYER ifvare CURRWEAP 0    
	 setactor[temp].yvel 0
break
case NEWBEASTCORPSE
case BOSS4CORPSE
 spritepal 6
 espawn JIBS6
 setactor[RETURN].xrepeat 32
 setactor[RETURN].yrepeat 32
case EGGCORPSE
case LIZTROOPCORPSE
case OCTABRAINCORPSE
case COMMANDERCORPSE
case PIGCOPCORPSE
case LIZMANCORPSE
case BOSS1CORPSE
case BOSS1CORPSENOGUN
case BOSS2CORPSE
case BOSS3CORPSE
 espawn JIBS6
 setactor[RETURN].xrepeat 32
 setactor[RETURN].yrepeat 32
 setvar mtype 1 
 ifrnd 128 sound HITFLESH else sound HITFLESH2
break
case PIGCOP
case PIGCOPDIVE
case LIZTROOP
case LIZTROOPDUCKING
case LIZMAN
case COMMANDER
case OCTABRAIN
case NEWBEAST
case BOSS1
case BOSS2
case BOSS3
case BOSS4
case BOTALLY
case BOTALLYCROUCH

ifrnd 128 sound HITFLESH else sound HITFLESH2
ifvare actorvar[temp].monstatus 1
{
   espawn BLOODIMPACT2
   getactor[THISACTOR].htg_t 8 temp
   getactor[temp].picnum picnum
   ifvare picnum NEWBEAST setactor[RETURN].pal 6 else
   ifvare picnum BOSS4 setactor[RETURN].pal 6
   
   // setactor[temp].ang actorvar[spriteid].lastang
   // bullet wound spawning code
   ifspawnedby APLAYER
   {
	ifvare CURRWEAP 1 ifvarg weaplev1 1 state makewound else
	ifvare CURRWEAP 2 ifvarg weaplev2 3 state makewound else
	ifvare CURRWEAP 3 ifvarg weaplev3 1 state makewound else
	ifvare CURRWEAP 7 ifvarg weaplev7 4 state makewound
   }
}	

break

case APLAYER
ifvarg eshield 0 state sparkstate else
ifrnd 128 sound HITFLESH else sound HITFLESH2
break

case ROTATEGUN
case TANK
case MECH2
case DRONE
case RECONDP
ifvare CURRWEAP 3 ifvarg weaplev3 3 state makewound
state sparkstate
state HITMETALSOUND
break

case RECON
state HITMETALSOUND
state sparkstate
break

case PLASMASHIELD
state sparkstate
break
default break
endswitch
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
      
    }
    else
      ifcount 2 nullop
      else
        ifonwater
          spawn WATERSPLASH2
  }
  
  ifcount 1 nullop else
  {
	  ifspawnedby STARPROJ { sizeat 16 16 break }
	  //ifvare smartmonsters YES 
	  state wakeupmonsters
	  ifvare sprite[THISACTOR].yvel ICEBEAM 
	  {
		  	getactor[THISACTOR].htg_t 8 temp // temp = hitsprite
	  		ifvarn temp -1
	  		setactor[temp].htpicnum FREEZEBLAST
	  		
			ifvarg weaplev9 3 setvar countvar 12 else
			setvar countvar 8
			setvar peractor1 0
			whilevarn countvar 0
			{
				randvar zdist 8192
				subvar zdist 4096
				setactor[THISACTOR].ang peractor1
				ezshoot zdist FREEZENOAIM
				setactorvar[RETURN].mtype 1
				ifvarg weaplev9 3 addvar peractor1 170 else
				addvar peractor1 256
				subvar countvar 1
			}
	  		break
  	  }
  	  ifvare sprite[THISACTOR].yvel POWBEAM
  	  {
	  	  getactor[THISACTOR].htg_t 8 temp // temp = hitsprite
	  	  ifvarn temp -1
	  	  {
	  	  	setactor[temp].htpicnum POWBEAM
	  	  	getactor[temp].mdflags tempb
	  	 	orvar tempb 16
	  	  	setactor[temp].mdflags tempb
	  	  	setvar beamhit 10
  	  	  }
  	  }
  	  //ifvare sprite[THISACTOR].yvel CHAINGUN
  	  //ifvarg weaplev3 2
  	  //spawn SHRAPNELSPAWNER
  	  
	  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
			// ifspawnedby APLAYER
			{
				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
			// ifspawnedby APLAYER
			{
				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
	  {
		  ifspawnedby APLAYER
		  {
			  ifvare sprite[THISACTOR].yvel CHAINGUN
			  ifvarg weaplev3 2
			  setvarvar chainsparksprite THISACTOR
			  
			  else
			  ifvare CURRWEAP 1
			  ifvarg weaplev1 3
			  setvarvar chainsparksprite THISACTOR
			  
		  }
	  
	       getactor[temp].picnum picnum
	       state bullethitsprite
	       
	   }
   }
enda


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

state shotflashcode

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

}
ifactioncount 2
  killit

ends

state shotflashcode3

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

}
ifactioncount 2
  killit

ends

state shotflashcode5

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

}
ifactioncount 2
  killit

ends

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


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

useractor notenemy CANNONBALL CANNONBALLSTRENGTH

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

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

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

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

enda


define CANNONBALLS 1818
define CANNONBALLSSTRENGTH 10
move CANNONBALLSVEL

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


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

useractor enemy CANNON CANNONSTRENGTH // fall

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

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

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

useractor notenemy HOTMEAT TOUGH
  ifaction 0
  {
    action ANULLACTION
    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

action CORPSEFROZEN 0 1 1

state corpsepickupcode

state moveitem

fall

ends

state checkpview

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


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

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

ends

state corpsemovecode

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

ends

state corpsecode

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


ends

state boss3corpsecode

strength 1000
setvar burning 512
state imonfire
soundonce FIRE_CRACKLE

ifcount 211 nullop else ifcount 210
{
	globalsound IMP_BOOM
	spawn DUKENUKE
}

ifcount 270
{
	espawn BOSS2
	setactorvar[RETURN].pal 17
	setactor[RETURN].xrepeat 96
	setactor[RETURN].yrepeat 80
	ifvarl truelevel VOL1LEVELS setactorvar[RETURN].monstflags 2450 else
	setactorvar[RETURN].monstflags 2460
	setactorvar[RETURN].mtype 1
	setactorvar[RETURN].mval BOSSVAL
	palfrom 63 63 63 63
	globalsound ALIEN_TALK1
	state standard_jibs
	killit
}


// state corpsecode

ends

useractor notenemy EGGCORPSE 0 state corpsecode enda
useractor notenemy LIZTROOPCORPSE 0 state corpsecode enda
useractor notenemy OCTABRAINCORPSE 0 state corpsecode enda
useractor notenemy COMMANDERCORPSE 0 state corpsecode enda
useractor notenemy PIGCOPCORPSE 0 state corpsecode enda
useractor notenemy LIZMANCORPSE 0 state corpsecode enda
useractor notenemy BOSS1CORPSE 0 state corpsecode enda
useractor notenemy BOSS1CORPSENOGUN 0 state corpsecode enda
useractor notenemy BOSS2CORPSE 0 state corpsecode enda
useractor notenemy BOSS3CORPSE 0 ifvare mtype 1 state boss3corpsecode else state corpsecode enda
useractor notenemy NEWBEASTCORPSE 0 state corpsecode enda
useractor notenemy BOSS4CORPSE 0 state corpsecode enda


action ICETRAILSOFT -154 1 1 1 1
spritenoshade ICEBEAMTRAIL
useractor notenemy ICEBEAMTRAIL 0


ifmove 0
{
	getactor[THISACTOR].owner spriteid
	getactorvar[spriteid].shotpitch shotpitch
	angoff 512
	setactor[THISACTOR].roll shotpitch
	move INIT
	ifvare rendmode 0 { action ICETRAILSOFT cstator 128 sizeat 16 16 spritepal 12 } else
	sizeat 64 64
}

ifcount 6 killit
ifcount 4 
{
	spawn SNOWSPRITE
	sizeto 0 0
	sizeto 0 0
	sizeto 0 0
}

enda

spritenoshade POWTRAIL
useractor notenemy POWTRAIL 0

ifmove 0
{
	getactor[THISACTOR].owner spriteid
	getactorvar[spriteid].shotpitch shotpitch
	setactor[THISACTOR].shade -127
	move INIT
	cstat 0
	sizeat 64 64
	ifvare rendmode 0 { cstator 128 sizeat 8 8 }
	angoff 512
	setactor[THISACTOR].roll shotpitch
}

ifvarn rendmode 0
{
	sizeto 0 0
	sizeto 0 0
	sizeto 0 0
	sizeto 0 0
}
else ifvarand timer 1 sizeto 0 0

ifcount 6 cstator 2
ifcount 12 cstator 512


enda

spritenoshade POWTRAIL2
useractor notenemy POWTRAIL2 0

ifmove 0
{
	headspritestat spriteid 1
	whilevarn spriteid -1
	{
		ifvarn actorvar[spriteid].mval 0
		getactorvar[spriteid].shotpitch shotpitch
		ifvarn shotpitch 0 setvar spriteid -1
		else nextspritestat spriteid spriteid
	}
	setactor[THISACTOR].shade -127
	move INIT
	cstat 0
	sizeat 64 64
	ifvare rendmode 0 { cstator 128 sizeat 8 8 }
	angoff 512
	setactor[THISACTOR].roll shotpitch
}
ifvarn rendmode 0
{
	sizeto 0 0
	sizeto 0 0
	sizeto 0 0
	sizeto 0 0
}
else ifvarand timer 1 sizeto 0 0

ifcount 6 cstator 2
ifcount 12 cstator 512


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

action POWEXPSOFTFRAMES -1201 9 1 1 8

spritenoshade POWEXPLOSION

useractor notenemy POWEXPLOSION 0

addvar countvar 1
ifmove 0
{ 
	spritepal 2
	state wakeupmonsters
	flash
	ifvare mtype 0
	{
		setvar intensity 1000
		setvar tempd 0
		state spawnpointlight
	}
	quake 26
	move INIT randomangle
	cstator 130 // 642
	ifvare rendmode 0 
	{
		action POWEXPSOFTFRAMES 
		cstator 16
		sizeat 32 32 
		setactor[THISACTOR].shade -127 
	}
	else
	sizeat 8 8
	setvar countvarb 13
	ifvarg weaplev10 5 ifvare peractor1 0 addvar countvarb 10
	getactor[THISACTOR].x initx
	getactor[THISACTOR].y inity
	getactor[THISACTOR].z initz
}
else
{
	addvar intensity 256
	ifvarg intensity 16384 setvar intensity 16384
	sizeto 255 255
	sizeto 255 255
	sizeto 255 255
	randvar angvar 2047
	setactor[THISACTOR].ang angvar
	ifvare peractor1 1
	{
		cstat 32768
		espawn BLINDINGFLASH
		setactorvar[RETURN].mtype 1
		spawn MININUKE
	}
	else ifvarn rendmode 0
	{
	 	randvar zdist 16384
	 	ifrnd 128 mulvar zdist -1
	 	espawn SPARK3
	 	setvarvar z initz
	 	addvarvar z zdist
	 	setactor[RETURN].z z
	 	setactor[RETURN].pal 2
 	}
 	ifvare rendmode 0
 	ifvare mtype 0
 	{
 		espawn POWEXPLOSION
		setactorvar[RETURN].mtype 1
	}
	
}

ifvarvarg countvar countvarb 
{
	ifvarn rendmode 0
	{
		whilevarn countvar 0
		{
			subvar countvar 1
			getactor[THISACTOR].x x
			getactor[THISACTOR].y y
			getactor[THISACTOR].z z
			randvar temp 2560
			ifrnd 128 mulvar temp -1
			addvarvar x temp
			randvar temp 2560
			ifrnd 128 mulvar temp -1
			addvarvar y temp
			randvar temp 16384
			ifrnd 128 mulvar temp -1
			addvarvar z temp
			updatesectorz x y z temp
			ifvarn temp -1
			{
				espawn NEWSMOKE
				setactor[RETURN].x x
				setactor[RETURN].y y
				setactor[RETURN].z z
			}
		}
	}
	killit
}

ifcount 3 ifvare mtype 0
{
	resetcount
	ifvarvarl countvar countvarb
	{
		espawn POWEXPLOSION
		setactorvar[RETURN].mtype 1
		setactorvar[RETURN].peractor1 peractor1
	}

	setvarvar temp countvar
	shiftvarl temp 7
	addvar temp 256
	hitradiusvar temp 30 40 50 60
	headspritestat spriteid 6
	whilevarn spriteid -1
	{
		getactor[spriteid].picnum picnum
		switch picnum
		case CRACK1 case CRACK2 case CRACK3 case CRACK4
		setactor[spriteid].htextra -1
		setactor[spriteid].htpicnum picnum
		break
		default break
		endswitch
		nextspritestat spriteid spriteid
	}
	headspritestat spriteid 1
	whilevarn spriteid -1
	{
		ifvare sprite[spriteid].picnum SHOOTME
		{
			dist xydist THISACTOR spriteid
			ifvarvarl xydist temp
			{
				getactorvar[spriteid].myspawner tempb
				ifvarn tempb -1
				ifvarl sprite[tempb].htextra 100
				{
					setactor[tempb].htextra 45
					setactor[tempb].htpicnum RADIUSEXPLOSION
					setactor[tempb].htowner player[THISACTOR].i
				}
			}
		}
		nextspritestat spriteid spriteid
	}
}

enda

define BOMBLET 941

action BOMBLETSTOPPED 0 1 1 1
action BOMBLETFAST 0 4 1 1 3
action BOMBLETMEDIUM 0 4 1 1 5
action BOMBLETSLOW 0 4 1 1 7
move BOMBINIT 132 -48
move BOMBATTACK 128
move BOMBROLL 116
move BOMBROLL2 96
move BOMBROLL3 48

state bombblow
spawn EXPLOSION2
sound PIPEBOMB_EXPLODE
hitradius 1664 18 26 34 42
ifvarvare myspawner player[THISACTOR].i
{
	getplayer[THISACTOR].i spriteid
	ifvare sprite[spriteid].htpicnum RADIUSEXPLOSION
	{
		setactor[spriteid].htpicnum -1
		setactor[spriteid].htextra -1
	}
}
killit

ends

actor BOMBLET 0 BOMBLETFAST

fall
ifmove 0
{
	cstator 256
	sizeat 32 32
	move BOMBINIT geth getv randomangle
	ifvare peractor1 1 setvar playerally -1
}


ifmove BOMBINIT ifcount 8
{
	ifrnd 96
	{
		move BOMBROLL geth
		action BOMBLETMEDIUM
	}
	else ifrnd 128
	{
		move BOMBROLL2 geth
		action BOMBLETMEDIUM
	}
	else
	{
		move BOMBROLL3 geth
		action BOMBLETSLOW
	}
	setactor[THISACTOR].htextra -1
	setactor[THISACTOR].htpicnum -1
}



ifhitweapon 
{
	ifwasweapon SHOTSPARK1
	state bombblow
	ifvarg countvar 26
	state bombblow
	strength 0
}

ifvare peractor1 1
ifvare target -1
state montargetsearch

ifvare peractor1 2
ifvare target -1 ifcansee
getplayer[THISACTOR].i target

ifvarn target -1
{
	ifmove BOMBINIT
	{
		 ifcount 8 
		 {
			 move BOMBATTACK geth
			 action BOMBLETFAST
		 }
	}
	else
	ifmove BOMBATTACK
	{
		iffloordistl 8 ifcount 10
		ifnotmoving // ifvarvarl sprite[target].z sprite[THISACTOR].z
		{
			ifvare peractor1 2 move BOMBINIT faceplayerslow getv
			else
			move BOMBINIT geth getv
			action BOMBLETFAST
		}
	}
	else 
	{
		ifvare peractor1 2 move BOMBATTACK faceplayerslow
		else
		move BOMBATTACK geth
		action BOMBLETFAST
	}
	ifvare peractor1 2
	{
		ifpdistl 644 state bombblow
	}
	else
	{
		state gradualturn
		ifvarn sprite[target].statnum 1 setvar target -1 else
		ifvarn actorvar[target].monstatus 1 setvar target -1
		ifvarn target -1
		{
			dist xydist THISACTOR target
			ifvarl xydist 644 state bombblow
		}
	}
	ifvare peractor1 2 addvar countvar 1
	ifvarg countvar 260 state bombblow
	break
}

ifnotmoving state bombblow

ifcount 26 
{
	ifrnd 6 state bombblow
}


ifcount 100 { move STOPPED action BOMBLETSTOPPED }

enda

spritenoshade BLINDINGFLASH
move FLASHMOVE 1024
move STAY
useractor notenemy BLINDINGFLASH 0

ifmove 0
{
	ifvare mtype 1 move STAY else
	move FLASHMOVE randomangle
	cstat 32768
	getactor[THISACTOR].z z
	randvar zdist 12288
	iffloordistl 16
	addvar zdist 2048
	subvarvar z zdist
	setactor[THISACTOR].z z
	setactor[THISACTOR].shade -127
}



ifmove STOPPED
{
	sizeto 255 255
	sizeto 255 255
	sizeto 255 255
	sizeto 255 255
	sizeto 255 255
	sizeto 255 255
	sizeto 255 255
	sizeto 255 255
	ifrnd 16 flash
	ifvare sprite[THISACTOR].cstat 128 cstat 32768 else
	cstat 128
}
else
{
	ifcount 2 ifrnd 64 move STOPPED
	ifcount 9 move STOPPED
	ifmove STOPPED
	{
		randvar x 32
		addvar x 1
		setactor[THISACTOR].xrepeat x
		setactor[THISACTOR].yrepeat x
		//sizeat 2 2
		cstat 128
		flash
		ifcansee
		{
			findplayer xydist
			setvar xydist2 8192
			subvarvar xydist2 xydist
			ifvarg xydist2 0
			{
				shiftvarr xydist2 7
				addvar xydist2 16
				ifvarg xydist2 63 setvar xydist2 63
				ifvarvarl player[THISACTOR].pals_time xydist2
				setplayer[THISACTOR].pals_time xydist2
				setplayer[THISACTOR].pals 0 63
				setplayer[THISACTOR].pals 1 63
				setplayer[THISACTOR].pals 2 63
			}
			
		}
	}
	break
}

ifvare mtype 1 { ifcount 16 killit } else
ifcount 10 killit

enda

useractor notenemy POWBALLINNER 0
ifcount 1 killit
enda

useractor notenemy POWBALLOUTER 0
ifcount 1 killit
enda

useractor notenemy POWBALLMID 0
ifcount 1 killit
enda

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

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

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

action FIRELASERACTION 4701 1 1 1 1

onevent EVENT_EGS


ifspawnedby RESPAWN
{
	getactor[THISACTOR].owner temp
	ifvarn temp -1
	{
		getactor[temp].pal pal
		setactor[THISACTOR].pal pal
		getactor[temp].cstat tempb
		ifvarand tempb 1 cstator 1
		ifvarand tempb 4 cstator 4
		ifvarand tempb 8 cstator 8
		ifvarand tempb 256 cstator 256
		getactorvar[temp].monstflags monstflags
		getactorvar[temp].droptile droptile
		getactorvar[temp].mysector tempb
		setactor[THISACTOR].htactorstayput tempb
	}
}



getactor[THISACTOR].picnum picnum

switch picnum


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


  case RAINSPRITE 
  case PLAYERTRAIL
  spriteflags 128
  sleeptime -1
  break
	
  case HEAVYHBOMB
  
  ifspawnedby APLAYER
  {
	  getactor[THISACTOR].xvel xvel
	  getplayer[THISACTOR].i spriteid
	  getactorvar[spriteid].weapcount temp
	  mulvar temp 9 divvar temp 5
	  ifinwater shiftvarr temp 1
	  addvarvar xvel temp
	  setactor[THISACTOR].xvel xvel
	  setactorvar[spriteid].weapcount 0
	  setvarvar myspawner player[THISACTOR].i
  }

  break
  
  case TRIPBOMB
  ifspawnedby APLAYER
	  setvarvar mtype weaplev8

  break
  
  case SMALLSMOKE
  getactor[THISACTOR].owner spriteid
  ifvarn spriteid -1
  {
	  ifvare sprite[spriteid].picnum SHOTSPARK1
	  ifvarn sprite[spriteid].htg_t 8 -1
	  {
		 getactor[spriteid].htg_t 8 temp
		 getactorvar[temp].monstatus monstatus
		 ifvare monstatus 1 cstator 32768
	  }
	  
  }
  break
   
  case MORTER
  getactor[THISACTOR].owner spriteid
  ifvarn spriteid -1
  getactorvar[spriteid].target target
  ifvarn target -1
  ifvarn sprite[target].picnum APLAYER
  {
	  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 SHRINKSPARK

 ifspawnedby APLAYER ifvare altshrinker 1 
 {
	 setactor[THISACTOR].extra 2 
	 setvar mtype 1 
	 spritepal 6
 }
 
 ifvarg weaplev6 1 ifspawnedby APLAYER setvar peractor1 1

 break
 
 case SHRINKEREXPLOSION
 
 ifspawnedby APLAYER ifvare altshrinker 1 
 {
	 setactor[THISACTOR].extra 2 
	 setvar mtype 1 
	 spritepal 6
 }
 getactor[THISACTOR].owner spriteid
 ifvarn spriteid -1 getactorvar[spriteid].peractor1 peractor1

 break

 case SPARKPROJ
 setactor[THISACTOR].xrepeat 3
 setactor[THISACTOR].yrepeat 3
 break
 
 case POWBALL
 setvar tempd 0
 setvar intensity 3072
 state spawnpointlight
 ifspawnedby APLAYER nullop else setvar peractor1 1
 break
 
 case POWEXPLOSION
 getactor[THISACTOR].owner spriteid
 getactorvar[spriteid].peractor1 peractor1
 break

 case BOTALLY setvar lotag 1 
 ifspawnedby MSPAWNER
 {
	 state randomizestate
	 state setmonval
 }
 break
 
 case MINIBEAST
 setvar mtype 1
 cactor NEWBEAST
 strength TROOPSTRENGTH
 sizeat 20 20 
 cstator 257
 break
 
	case LIZTROOP
	case LIZTROOPSTAYPUT
	case LIZTROOPSHOOT
	case LIZTROOPJETPACK
	case LIZTROOPRUNNING
	case LIZTROOPONTOILET
	case LIZTROOPJUSTSIT
	case LIZTROOPDUCKING
	case OCTABRAIN
	case OCTABRAINSTAYPUT
	case DRONE
	case COMMANDER
	case COMMANDERSTAYPUT
	case TANK
	case MECH2
	case PIGCOP
	case PIGCOPSTAYPUT
	case PIGCOPDIVE
	case LIZMAN
	case LIZMANSTAYPUT
	case LIZMANJUMP
	case LIZMANSPITTING
	case ROTATEGUN
	case BOSS1
	case BOSS1STAYPUT
	case BOSS2
	case BOSS3
	case BOSS4
	case BOSS4STAYPUT
	case BOSS2PALRESPAWN
	case BOSS3PALRESPAWN
	case SHARK
	case NEWBEAST
	case NEWBEASTSTAYPUT
	case NEWBEASTHANG
	case NEWBEASTJUMP
	ifspawnedby RESPAWN
	state randomizestate
	else ifspawnedby MSPAWNER
	state randomizestate
	state setmonval
	break
	
	
	case GREENSLIME
	setvar mval 10
	break
		
		
 case RECON
 case RECONDP
 case EGG
 ifspawnedby RESPAWN
 state randomizestate
 else ifspawnedby MSPAWNER
 state randomizestate
 state setmonval
 sizeat 48 48
 cstator 257
 
 break

case EXPLOSION2

ifspawnedby RPG
{
	getactor[THISACTOR].owner spriteid
	getactorvar[spriteid].peractor1 peractor1
	getactor[spriteid].owner tempb
	ifvarn tempb -1 ifvare sprite[tempb].picnum APLAYER
	{
		ifvare CURRWEAP 4 
		{
			ifvarg weaplev4 2
			state startfires
			ifvarg weaplev4 4
			{
				spawn MININUKE
				spawn MININUKE
				spawn MININUKE
				spawn MININUKE
				spawn MININUKE
				spawn MININUKE
				spawn MININUKE
				spawn MININUKE
				spawn MININUKE
			}
		}
	}
}
ifspawnedby RPGNOAIM
{
	getactor[THISACTOR].owner temp
	getactor[temp].owner spriteid
	getactorvar[spriteid].weap weap
}
ifspawnedby HEAVYHBOMB
{
	getactor[THISACTOR].owner spriteid
	getactorvar[spriteid].myspawner tempb
	ifvarn tempb -1 ifvare sprite[tempb].picnum APLAYER
	{
		ifvarg weaplev5 2
		state startfires
		ifvarg weaplev5 0
		{
			ifvarg weaplev5 1 state spawnflashes
			ifvarg weaplev5 5 state spawnflashes
			ifvarg weaplev5 3 
			{ 
				ifvarg weaplev5 5 setvar countvar 20 else
				setvar countvar 10 
				ifvarg weaplev5 4 setvar peractor1 1 
			}
			else { setvar countvar 4 setvar peractor1 0 }
			whilevarn countvar 0
			{
				espawn BOMBLET
				setactorvar[RETURN].peractor1 peractor1
				setactorvar[RETURN].myspawner player[THISACTOR].i
				subvar countvar 1
				ifvarg weaplev5 5 spawn MININUKE
			}
			setvar peractor1 0
		}
	}
	
}
ifspawnedby TRIPBOMB
{
	getactor[THISACTOR].owner myspawner
	ifvarn myspawner -1
	{
		getactor[myspawner].owner spriteid
		ifvare sprite[spriteid].picnum APLAYER 
			setvar tripbombing 2
		
		getactorvar[myspawner].mtype mtype
		ifvarg mtype 0 
		{
			ifvarg mtype 4
			{
				setvar countvar 10
				setvar peractor1 1
				whilevarn countvar 0
				{
					espawn BOMBLET
					setactorvar[RETURN].peractor1 peractor1
					setactorvar[RETURN].myspawner player[THISACTOR].i
					subvar countvar 1
				}
				setvar peractor1 0
				ifvarg mtype 5
				{
				    getactor[myspawner].ang A
				    setactor[THISACTOR].extra 30
				    setvar peractor1 0
				    whilevarn peractor1 10
				    {
					    addvar peractor1 1
					    eshoot RPGNOAIM
					    setactor[RETURN].ang A
					    setactorvar[RETURN].weap 1
						setactor[RETURN].extra 32
					    setactor[RETURN].xrepeat 12
					    setactor[RETURN].yrepeat 12
					    setactor[RETURN].htpicnum APLAYER
					    setactor[RETURN].htowner player[THISACTOR].i
					    setactor[RETURN].owner player[THISACTOR].i
				    }
				    setvar peractor1 0
			    }
			}
			espawn EXPLINE
			setactorvar[RETURN].countvar mtype
			getactor[myspawner].ang A
			setactor[RETURN].ang A
			setactorvar[RETURN].peractor1 A
			setvar mtype 0
			state spawnflashes
		}
		

	}
}
break

case SHOOTME cstat 32768 
break

case 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
	    ifvarn temp -1
	    changespritesect THISACTOR temp
	    getactor[THISACTOR].ang angvar
	    ifvarg angvar 1024 setvar temp 1536
	    else setvar temp 512
	    subvarvar temp angvar
	    mulvar temp 2
	    addvarvar angvar temp
	    setactor[THISACTOR].ang angvar
	    setplayer[THISACTOR].ang angvar
    }
    
    setvar DONE 0
}
break


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

break

case FIREBALLPROJ
ifvare rendmode 4 ifvarg framerate 20
{
 setvar tempd 2
 setvar pal 2
 setvar intensity 3072
 state spawnpointlight
}
getactor[THISACTOR].ang angvar
addvar angvar 1024
setactor[THISACTOR].ang angvar
getactor[THISACTOR].zvel zvel
mulvar zvel -1
setactor[THISACTOR].zvel zvel

ifspawnedby BOSS2 
randvar temp 128 
else randvar temp 160 
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

randvar tempb 1024
getactor[THISACTOR].zvel zvel
subvarvar zvel tempb
setactor[THISACTOR].zvel zvel

break

case FIREBULLET
ifvare rendmode 4 ifvarg framerate 24
{
 setvar tempd 2
 setvar pal 2
 setvar intensity 1280
 state spawnpointlight
}
state randtraj
randvar temp 256
addvar temp 128
getprojectile[FIREBULLET].offset tempb
ifvarg tempb 0 mulvar temp -1
setprojectile[FIREBULLET].offset temp
ifspawnedby APLAYER
{
	getactor[THISACTOR].z z
	addvar z 2048
	setactor[THISACTOR].z z
	getactor[THISACTOR].zvel zvel
	subvar zvel 512
	setactor[THISACTOR].zvel zvel
	setvar playerally -1
	ifvarg weaplev3 2
	{
		ifvarg weaplev3 5 setactor[THISACTOR].extra 15 else
		ifvarg weaplev3 2 setactor[THISACTOR].extra 12
	}
}
break

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

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

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

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


randvar peractor1 96
ifrnd 128 mulvar peractor1 -1

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

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

case DUKETORSO
case DUKEGUN
case DUKELEG

randvar peractor1 96
addvar peractor1 1
ifrnd 128 mulvar peractor1 -1

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

case PIGHEAD
case PIGUPPER
case PIGUPPER2
case PIGLOWER
case PIGLOWER2

randvar peractor1 96
ifrnd 128 mulvar peractor1 -1

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

case JIBS6

ifspawnedby SMALLSMOKE { getactor[THISACTOR].z z addvar z 4096 setactor[THISACTOR].z z  }
getactor[THISACTOR].owner spriteid
ifvarn spriteid -1
{
	getactor[spriteid].pal pal
	ifvare pal 0 ifvare sprite[spriteid].picnum EGG setvar pal 6
	setactor[THISACTOR].pal pal
	

	
	ifvarl sprite[THISACTOR].xrepeat 20 
	{
		setactor[THISACTOR].xrepeat sprite[spriteid].xrepeat
		setactor[THISACTOR].yrepeat sprite[spriteid].yrepeat
		randvar xvel 36
		setactor[THISACTOR].xvel xvel
		randvar angvar 2047
		setactor[THISACTOR].ang angvar
	}

}
break

case FIRELASER

  action FIRELASERACTION
  ifvare rendmode 0 spritepal 2
  

  ifvarl framerate 25 setactor[THISACTOR].htflags 256

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

case BIGFIRELASER

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

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

case MORTER2
getactor[THISACTOR].zvel zvel
subvar zvel 1536
setactor[THISACTOR].zvel zvel

ifvare rendmode 4 ifvarg framerate 24
{
 setvar tempd 2
 setvar intensity 2048
 setvar pal 2
 state spawnpointlight
}

break

case RPG
case RPGNOAIM

    ifspawnedby APLAYER
    {
	    getplayer[THISACTOR].curr_weapon temp
	    ifvare temp 7 setvar peractor1 2 
		ifvare CURRWEAP 4
	    ifvarg weaplev4 1
	    {
		    getactor[THISACTOR].xvel xvel
		    mulvar xvel 3 shiftvarr xvel 1
		    setactor[THISACTOR].xvel xvel
		    getactor[THISACTOR].zvel zvel
		    mulvar zvel 3 shiftvarr zvel 1
		    setactor[THISACTOR].zvel zvel
		    ifvarg weaplev4 3
		    {
			    getactor[THISACTOR].extra temp
			    shiftvarl temp 2 divvar temp 3
			    setactor[THISACTOR].extra temp
		    }
			    
		}
		ifvare CURRWEAP 7
		ifvarg weaplev7 3
		{
			getactor[THISACTOR].extra temp
		    shiftvarl temp 2 divvar temp 3
		    setactor[THISACTOR].extra temp
		}
    }
    
	ifspawnedby BOSS2 
	{
		setvar peractor1 2
		ifactor RPGNOAIM
		{
			
			getactor[THISACTOR].owner spriteid
			getactor[spriteid].pal pal
			ifvare pal 0
			{
				getactor[THISACTOR].z z
				addvar z 5120
				setactor[THISACTOR].z z
			}
			getactor[THISACTOR].ang angvar
			randvar temp 128 ifrnd 128 mulvar temp -1
			addvarvar angvar temp
			setactor[THISACTOR].ang angvar
			getactor[THISACTOR].xrepeat x
			getactor[THISACTOR].yrepeat y
			mulvar x 4
			mulvar y 4
			setthisprojectile[THISACTOR].xrepeat x
			setthisprojectile[THISACTOR].yrepeat y
		}
	}
	
	ifspawnedby BOSS3
	{
		setvar peractor1 2
		getactor[THISACTOR].owner temp
		getactor[temp].pal pal
		ifvarn pal 0 
		{
			getactor[THISACTOR].z z
			ifactor RPG
			addvar z 3072 else
			ifactor RPGNOAIM subvar z 3072
			setactor[THISACTOR].z z
		}
	}
	
	ifspawnedby ROTATEGUN
	{
		setactor[THISACTOR].xrepeat 10
		setactor[THISACTOR].yrepeat 10
	}
	
	ifactor RPG { ifvarl framerate 20 setactor[THISACTOR].htflags 256 }
	else
	ifvare rendmode 4 ifvarg framerate 19
	{
	 setvar tempd 2
	 setvar pal 7
	 setvar intensity 1560
	 state spawnpointlight
	}
	
break

case MEGAROCKET
getactor[THISACTOR].ang lastang
setvar WEAPON4_SHOOTS RPG

ifvare rendmode 4
{
 setvar tempd 0
 setvar intensity 6144
 setvar pal 23
 state spawnpointlight
}
 
break

case ROCKETHALO
cstat 32768
break

case BLOODPOOL

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

break

case NEWSPLASH
case WATERCIRCLE
spriteflags 16
break

case WATERSPLASH2
case WATERSPLASH3
ifspritepal 0
ifvarn rendmode 0
{
	spawn NEWSPLASH 
	spritepal 40 
	cstator 32768 
	//killit
} 
break

case BULLETFLASH

getactor[THISACTOR].owner spriteid
ifvarn spriteid -1
{
	getactor[spriteid].x mx
	addvar mx 384
	rotatepoint sprite[spriteid].x sprite[spriteid].y mx sprite[spriteid].y sprite[spriteid].ang digx digy
	setsprite THISACTOR digx digy sprite[spriteid].z
}
ifrnd 128 cstator 4
ifrnd 128 cstator 8

break

case POWTRAIL
case POWTRAIL2
cstat 32768
sizeat 1 1
break
default break

endswitch


endevent

// onevent EVENT_SPAWN

// getactor[THISACTOR].picnum picnum
// switch picnum

// case COLA
// case SIXPAK
// case ATOMICHEALTH
// case HEAVYHBOMB
// case AMMO
// case SHOTGUNAMMO
// case BATTERYAMMO
// case RPGAMMO
// case HBOMBAMMO
// case CRYSTALAMMO
// case DEVISTATORAMMO
// case FREEZEAMMO
// case TRIPBOMBSPRITE
// case GROWAMMO
// case SHIELD
// case FIRSTGUNSPRITE
// case SHOTGUNSPRITE
// case CHAINGUNSPRITE
// case RPGSPRITE
// case SHRINKERSPRITE
// case DEVISTATORSPRITE
// case FREEZESPRITE
// case GROWSPRITEICON
// case FIRSTAID
// case BOOTS
// case HOLODUKE
// case HEATSENSOR
// case JETPACK
// case AIRTANK
// case STEROIDS

// setactor[THISACTOR].mdflags 16
// setvar position 32768 // floats on shallow water
// 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 flipit

switch picnum

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

ifvare NOCODE 2 setvar NOCODE 1

ends

state bounceshield
ifvare sprite[hitsprite].picnum PLASMASHIELD
ifvare command -1
ifvare sprite[hitsprite].cstat 403
{
	dist xydist THISACTOR hitsprite
	ifvarl xydist 1024
	{
		setvar command 1
	    getactor[hitsprite].ang angvar
	    getactor[THISACTOR].ang temp
		    getincangle tempc angvar temp
		    subvarvar angvar tempc
		    addvar angvar 1024
		    setactor[THISACTOR].ang angvar
	    sound HITSHIELD2
    }
}
ends

gamevar lightsoff 0 0

// EVENT CODE
onevent EVENT_GAME

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

ifvare motionblur YES
{
	changespritestat THISACTOR 1
	setactor[THISACTOR].xrepeat lotag
	setactor[THISACTOR].yrepeat hitag
	addvar countvar 1
	ifvarg countvar 3
	killit
}

getactor[THISACTOR].picnum picnum

switch picnum

case APLAYER
ifvarvare THISACTOR player[THISACTOR].holoduke_on
{
	cstat 32768
	ifvarn mybot -1
	setsprite THISACTOR sprite[mybot].x sprite[mybot].y sprite[mybot].z
}
break

case LIZTROOP
case LIZTROOPSTAYPUT
case LIZTROOPSHOOT
case LIZTROOPJETPACK
case LIZTROOPRUNNING
case LIZTROOPDUCKING
ifvarand monstflags 256 { sizeat 48 42 addstrength 100 setvar NOCODE 1 }
break

case RECONDP
changespritestat THISACTOR 1
sleeptime -1
break

case MORTER2

ifvare sprite[THISACTOR].statnum 4
{
	getactor[THISACTOR].xvel xvel
	subvar xvel 5
	setactor[THISACTOR].xvel xvel
	
	setvarvar spriteid THISACTOR
	state projectilehitscan
	state bounceshield
}

break

case FREEZEBLAST 
ifspawnedby APLAYER ifvarg weaplev9 0
{
	spawn SNOWSPRITE spawn SNOWSPRITE
}
setvarvar spriteid THISACTOR
state projectilehitscan
state bounceshield
break

case BIGFIRELASER

 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
	 randvar temp 32
	 subvar temp 16
	 addvarvar angvar temp
	 setactor[THISACTOR].ang angvar
	 setvar target -1
  }

break

case FREEZENOAIM
ifvare mtype 1
{
	addvar countvar 1
	ifvarg countvar 10
	{
		espawn SMALLSMOKE
		setactor[RETURN].pal 1
		killit
	}
}
setvarvar spriteid THISACTOR
state projectilehitscan
state bounceshield
break

case COMETPROJ
ifvare target -1
state trackplayer
else state tracktarget
espawn COMETRAIL
setactorvar[RETURN].initz sprite[THISACTOR].zvel
setactorvar[RETURN].initx sprite[THISACTOR].xvel
setactorvar[RETURN].target THISACTOR

getactor[THISACTOR].ang angvar
randvar temp 96
subvar temp 48
addvarvar angvar temp
setactor[THISACTOR].ang angvar
break

case HEAVYHBOMB

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

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

break

case BLOODPOOL

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


case SECTOREFFECTOR

ifvare mirrored YES 
{
	ifvarn mysector -1 setactor[THISACTOR].sectnum mysector
// 	ifvare lotag 24 // conveyer belt
// 	{
// 		getactor[THISACTOR].yvel yvel
// 		divvar yvel -64
// 		getsector[THISACTOR].floorxpanning mx
// 		addvarvar mx yvel
// 		ifvarg mx 255 subvar mx 256 else
// 		ifvarl mx 0 addvar mx 256
// 		//addlogvar mx
// 		setsector[THISACTOR].floorxpanning mx
// 	}
}

ifvare lotag 49 // point light
{
	ifvarn myspawner -1
	{
		getactorvar[myspawner].intensity intensity
		setactor[THISACTOR].hitag intensity
		getactor[myspawner].statnum temp
		ifvare temp 1024 killit
		getactor[myspawner].picnum temp
		ifvarvarn temp mtype killit
		getactor[myspawner].x x
		getactor[myspawner].y y
		getactor[myspawner].z z
		ifvare mtype APLAYER subvar z 8192
		updatesectorz x y z mysector
		ifvarn mysector -1
		{
			changespritesect THISACTOR mysector
			getflorzofslope mysector x y mz
			getceilzofslope mysector x y digz
			setvarvar temp mz
			subvarvar mz z
			ifvarl mz 4096 
			{
				setvarvar z temp 
				subvar z 4096 
				ifvarvarl z digz setvarvar z digz
			}
		}
		
		setsprite THISACTOR x y z				
	}
}
else
ifvare lotag 666 // death floor
{
	headspritesect spriteid sprite[THISACTOR].sectnum
	whilevarn spriteid -1
	{
		ifvarvarg sprite[spriteid].z sprite[THISACTOR].z
		{
			setvar temp 0
			ifvare sprite[spriteid].picnum APLAYER
			{
				getuserdef[THISACTOR].god tempb
				ifvare tempb NO
					addphealth -1000
			}
			else setactorvar[spriteid].canseeplayer -4000
		}
		nextspritesect spriteid spriteid
	}
}
else ifvare mirrored NO setvar NOCODE 1
	
break

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

case NEWSCRAP1
case NEWSCRAP2
case NEWSCRAP3
case NEWSCRAP4
case NEWSCRAP5
case NEWSCRAP6

ifvarg THISACTOR MAXSPRITES killit
getactor[THISACTOR].pitch temp
addvar temp 16
setactor[THISACTOR].pitch temp
addvar countvar 1

ifvarl sprite[THISACTOR].yvel 3
{
	ifvarl sprite[THISACTOR].zvel -2048
	setactor[THISACTOR].zvel -2048
}

break

case SPARKPROJ  
ifvarg THISACTOR MAXSPRITES killit
addvar countvar 1
ifvarg countvar 5 sizeat 2 2
ifvarg countvar 12 sizeat 1 1
break

case DIPSWITCH
case DIPSWITCH2
case DIPSWITCH3
case TECHSWITCH
case ALIENSWITCH
case FRANKENSTINESWITCH

	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


break

case 163 case 165 case 167 case 169
case 1143 case 141

	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



break


case RECON

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

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

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

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

setvarvar spriteid THISACTOR
state projectilehitscan
state bounceshield
break

case POWBALL
espawn POWBALLINNER
setactor[RETURN].cstat 128
setactor[RETURN].xrepeat 8
setactor[RETURN].yrepeat 8
setactor[RETURN].pal 2
espawn POWBALLOUTER
setactor[RETURN].cstat 642
setactor[RETURN].xrepeat 32
setactor[RETURN].yrepeat 32
setactor[RETURN].pal 2
espawn POWBALLMID
setactor[RETURN].cstat 130
setactor[RETURN].xrepeat 16
setactor[RETURN].yrepeat 16
setactor[RETURN].pal 2
ifvarg sprite[THISACTOR].yvel 1
setactor[THISACTOR].yvel 1
break

case SHRINKSPARK
ifspawnedby APLAYER
ifvarg weaplev6 1
spawn SHRINKERHALO

setvarvar spriteid THISACTOR
state projectilehitscan
state bounceshield
break

case RPG
case RPGNOAIM
case MEGAROCKET

getactor[THISACTOR].zvel zvel
divvar zvel 50
setactor[THISACTOR].pitch zvel

ifvare peractor1 -1 killit

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

espawn ROCKETHALO
setactorvar[RETURN].myspawner THISACTOR


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

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

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

ifspawnedby APLAYER
ifvare CURRWEAP 7
ifvarg weaplev7 2
{
	addvar countvar 1
	ifvarg countvar 3
	{
		ifvarn target -1 state tracktarget
		else
		{
			findnearactorz SHOOTME 4096 32768 spriteid
			ifvare spriteid -1
			findnearactorz SHOOTME 8192 65536 spriteid
			ifvarn spriteid -1
			{
				getactorvar[spriteid].myspawner target
				canseespr THISACTOR target temp
				ifvare temp 0 setvar target -1
				else
				{
					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
					getactor[THISACTOR].ang tempb
					getincangle tempd angvar tempb
					ifvarg tempd 320 setvar target -1 else
					ifvarl tempd -320 setvar target -1
				}
			}
		}
	}
}

ifvare mtype 1
{
	ifvarn target -1 state tracktarget
	else
	ifvare playerally 0
	state trackplayer
}
	

break

// case COOLEXPLOSION1

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

case FIREBALLPROJ

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

case STARPROJ

ifvarn sprite[THISACTOR].htmovflag 0
{
	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].picnum FLOORTEX
		state CHECKSTEPS
		state BULLETHITSOUNDS
	}
}
setvarvar spriteid THISACTOR
state projectilehitscan
state bounceshield

break

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

case ELECTROPROJ
ifvare sprite[THISACTOR].statnum 4
{
	setvar temp 0
	ifrnd 128 orvar temp 4
	ifrnd 128 orvar temp 8
	setactor[THISACTOR].cstat temp
	setvarvar spriteid THISACTOR
	state projectilehitscan
	state bounceshield
}
break

case SHELL
case SHOTGUNSHELL

state getfloorz
getactor[THISACTOR].z mz
subvarvar z mz
ifvarl z 512
{
	getactor[THISACTOR].statnum tempb
	ifvarn tempb 1
	{
		ifactor SHELL cactor 2534
		ifactor SHOTGUNSHELL cactor SSHELLGROUND
		changespritestat THISACTOR 1
		setvar NOCODE 1
	}
}

ifspritepal 30 // reverses shell direction when fired from left pistol
{
	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

ifvarg THISACTOR MAXSPRITES killit

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

	state checkfloordist
	ifvarl temp 2048
	{
		setvar mtype 1
		setvar NOCODE 1
		getactor[THISACTOR].picnum picnum
		addvar picnum 1
		espawnvar picnum
		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 PIGHEAD
case PIGUPPER
case PIGUPPER2
case PIGLOWER
case PIGLOWER2

ifvarg THISACTOR MAXSPRITES killit

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

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

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

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

case JIBSPROJ1
case JIBSPROJ2
case JIBSPROJ3
case JIBSPROJ4
case JIBSPROJ5

case LIZMANHEADPROJ
case LIZMANARMPROJ
case LIZMANLEGPROJ

case TROOPHEADPROJ
case TROOPARMPROJ
case TROOPLEGPROJ

ifvarg THISACTOR MAXSPRITES killit

ifvare sprite[THISACTOR].statnum 4
{
	getactor[THISACTOR].pitch temp
	addvarvar temp peractor1
	setactor[THISACTOR].pitch temp
	getactor[THISACTOR].roll temp
	addvarvar temp peractor1
	setactor[THISACTOR].roll temp
	
	ifvarl framerate 30 setthisprojectile[THISACTOR].trail -1
	
	ifvare countvar 0
	{
		ifrnd 128 cstator 4
		ifspritepal 1 
		{
			setthisprojectile[THISACTOR].trail -1 
			setvar mtype -1 
		}
	}

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

break

case JIBS1
case JIBS2
case JIBS3
case JIBS4
case JIBS5

ifvarg THISACTOR MAXSPRITES killit
ifvare mtype 0
{
	ifspritepal 0 ifspawnedby EGG spritepal 6
	getactor[THISACTOR].pitch temp
	addvarvar temp peractor1
	setactor[THISACTOR].pitch temp
	getactor[THISACTOR].roll temp
	addvarvar temp peractor1
	setactor[THISACTOR].roll temp
}
break

case JIBS6
ifvarg THISACTOR MAXSPRITES killit
break

case DUKETORSO
case DUKEGUN
case DUKELEG

ifvarg THISACTOR MAXSPRITES killit
ifvarn peractor1 0
spawn JIBS6

break

default

	ifvare timer 1 ifvare mirrored YES
		state flipit
	ifvare motionblur NO	
	setvar NOCODE 1 
	break
	
endswitch

endevent

onevent EVENT_HOLODUKEON


ifvarg player[THISACTOR].holoduke_amount 0
{
	ifvarn mybot -1
	setactorvar[mybot].command 666
	
	espawn BOTALLY
	setvarvar mybot RETURN
	setactorvar[RETURN].playerally -1
	randvar pal 3
	ifvare pal 0 setactor[RETURN].pal 16 else
	ifvare pal 1 setactor[RETURN].pal 22 else
	ifvare pal 2 setactor[RETURN].pal 23 else
	//ifvare pal 3 setactor[RETURN].pal 10 else
	//ifvare pal 4 setactor[RETURN].pal 21 else
	ifvare pal 3 setactor[RETURN].pal 12
	
	setvarvar temp botlevel
	shiftvarr temp 1
	addvar temp 1
	setvar tempc 0
	whilevarn temp 0
	{
		randvarvar tempb temp
		switch tempb
		case 0 break
		case 1 orvar tempc 16 break
		case 2 orvar tempc 128 break
		case 3 orvar tempc 32 break
		case 4 orvar tempc 512 break
		case 5 orvar tempc 64 break
		case 6 orvar tempc 256 break
		default
		randvar tempd 2
		ifvare tempd 0 orvar tempc 512 else
		ifvare tempd 1 orvar tempc 64 else
		orvar tempc 256
		break
		endswitch
		subvar temp 1
	}
	setactorvar[RETURN].monstflags tempc
	
			ifvarand monstflags 256 spritepal 10 // devistator
		else
		ifvarand monstflags 64 spritepal 21 // RPG
		else
		ifvarand monstflags 128 spritepal 12 // freezer
		else
		ifvarand monstflags 32 spritepal 23 // chaingun
		else
		ifvarand monstflags 512 spritepal 22 // expander
		else
		ifvarand monstflags 16 spritepal 16 // shotgun
		else spritepal 14
	
	setactor[RETURN].htpicnum APLAYER
	setvar RETURN 0
	getplayer[THISACTOR].holoduke_amount temp
	ifvarg temp 104
	{
		subvar temp 52
		setplayer[THISACTOR].holoduke_amount temp
	}
}


endevent

onevent EVENT_HOLODUKEOFF

ifvarn mybot -1 setactorvar[mybot].command 666

endevent


state cannondeath

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

state megadeth
setvar countvar 0
getactor[THISACTOR].ang position
whilevarn countvar 32
{
	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 32
	addvarvar position temp
	setactor[THISACTOR].ang position
	spawn MININUKE
	spawn MININUKE
}
spawn EXPLOSION2
globalsound RPG_EXPLODE
state spawnflashes
state spawnflashes
state startfires
cactor MEGAROCKET
quake 26
ends


onevent EVENT_KILLIT

ifvarg mval 0 ifvarg timer 1 { state specialdeath setvar RETURN 0 }

ifvare sprite[THISACTOR].statnum 4 // a projectile
ifvare command -1
{
	getactor[THISACTOR].htmovflag spriteid
	ifvarn spriteid 0
	{
		addvar spriteid 16384
	    ifvarl spriteid 16384 ifvarg spriteid -1 
	    {
		    ifvare sprite[spriteid].cstat 403
		    ifvare sprite[spriteid].picnum PLASMASHIELD
		    {
			    sound HITSHIELD2
			    setactor[spriteid].htextra -1
			    setactor[spriteid].htpicnum -1
			    setvar command 1
			    getactor[spriteid].ang angvar
			    getactor[THISACTOR].ang temp
	 		    getincangle tempc angvar temp
	 		    subvarvar angvar tempc
	 		    addvar angvar 1024
	 		    setactor[THISACTOR].ang angvar
			    setvar RETURN 1
			    break
		    }
	    }
    }
}

getactor[THISACTOR].picnum picnum
switch picnum

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
	setvar RETURN 0
}

break

case FIREBULLET

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



case STARPROJ
getactor[THISACTOR].htmovflag temp
addvar temp 16384
ifvarl temp 16384 ifvarg temp -1
{
	setactor[THISACTOR].htg_t 8 temp
	getactor[temp].picnum picnum
	state bullethitsprite
	setvar RETURN 0
}
break

case FREEZEBLAST
getactor[THISACTOR].htmovflag spriteid
ifvarn spriteid 0
{
	addvar spriteid 16384
	ifvarl spriteid 16384 ifvarg spriteid -1
	{
		espawn TRANSPORTERSTAR
		setactor[RETURN].pal 1
	}
	ifspawnedby APLAYER
	ifvarg weaplev9 0
	{
		ifvarg weaplev9 3 setvar countvar 12 else
		setvar countvar 8
		setvar peractor1 0
		whilevarn countvar 0
		{
			randvar zdist 8192
			subvar zdist 4096
			setactor[THISACTOR].ang peractor1
			ezshoot zdist FREEZENOAIM
			setactorvar[RETURN].mtype 1
			ifvarg weaplev9 3 addvar peractor1 170 else
			addvar peractor1 256
			subvar countvar 1
		}
	}
}
setvar RETURN 0
break

case DPCANNONBALL
state cannondeath
break

case RECON
setvarvar tempd mval
state addscore
break
default break
endswitch

ifactor ICESHARD
{
	spritepal 12
	lotsofglass 4
	getactor[THISACTOR].htmovflag temp
	ifvarn temp 0
	{
		// hit something
		addvar temp 16384
		ifvarl temp 16384 ifvarg temp -1 
		{
		    // hit a sprite
		    ifvarg weaplev9 5
			ifvare sprite[temp].statnum 1
	        ifspawnedby APLAYER
	        ifvarg countvarb -1
	        {
		        setvar countvarb -1
		        getactor[THISACTOR].x mx
		        addvar mx 384
		        rotatepoint sprite[THISACTOR].x sprite[THISACTOR].y mx sprite[THISACTOR].y sprite[THISACTOR].ang digx digy
		        setsprite THISACTOR digx digy sprite[THISACTOR].z
		        setvar target -1
		        setvar RETURN 1
		        break 
	        }
	        else setvar RETURN 0
		    break 
		}
	}
	
	sound GLASSCRACKSND
	setvar RETURN 0 
	break
}

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

		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
	        ifvare sprite[temp].statnum 1
	        ifspawnedby APLAYER ifvare peractor1 2 ifvarg weaplev7 4
	        {
		        spawn BURNING spawn BURNING2
		        ifvarg weaplev7 5 ifvarg countvarb -1
		        {
			        setvar countvarb -1
			        getactor[THISACTOR].x mx
			        addvar mx 384
			        rotatepoint sprite[THISACTOR].x sprite[THISACTOR].y mx sprite[THISACTOR].y sprite[THISACTOR].ang digx digy
			        setsprite THISACTOR digx digy sprite[THISACTOR].z
			        getactor[THISACTOR].xvel xvel
			        shiftvarr xvel 1
			        setactor[THISACTOR].xvel xvel
			        getactor[THISACTOR].zvel zvel
			        shiftvarr zvel 1
			        setactor[THISACTOR].zvel zvel
			        setvar target -1
			        setvar RETURN 1
			        break
		        }
	        }
	        ifvare peractor1 3
	        {
		        ifvarl sprite[temp].extra 300 ifvare actorvar[temp].monstatus 1
		        {
			        getactor[THISACTOR].x mx
			        addvar mx 384
			        rotatepoint sprite[THISACTOR].x sprite[THISACTOR].y mx sprite[THISACTOR].y sprite[THISACTOR].ang digx digy
			        setsprite THISACTOR digx digy sprite[THISACTOR].z
			        setvar target -1
			        setactor[THISACTOR].ang lastang
			        setvar RETURN 1
			        cactor MEGAROCKET
			        break
		        }
		        else state megadeth
		    }
	        setvar RETURN 0 
	        break 
	    }
	    else ifvare peractor1 3 
	    {
		    state megadeth
		    setvar RETURN 0
		    break
	    }
        getactor[THISACTOR].htmovflag hitwall
		andvar hitwall 49152
		ifvare hitwall 32768
		{
            
			getactor[THISACTOR].htmovflag hitwall
			andvar hitwall 16383 // temp is now the wall ID that it hit
			// stop if there is a lotag 13 SE in the nextsector of hitwall
			getwall[hitwall].nextsector temp
			ifvarg temp -1
			{
				setvar tempc 0
				headspritesect spriteid temp
				whilevarn spriteid -1
				{
					getactor[spriteid].statnum picnum
					ifvare picnum 3 // SE
					{
						getactor[spriteid].lotag tempb
						ifvare tempb 13 // NO SCORCH
							setvar tempc 1
					}
					nextspritesect spriteid spriteid
				}
				ifvare tempc 1 { setvar RETURN 0 break }
			}
			getwall[hitwall].overpicnum temp
			ifvare temp BIGFORCE { setvar RETURN 0 break }
			ifvare temp W_FORCEFIELD { setvar RETURN 0 break }
			getwall[hitwall].cstat temp
			ifvarand temp 128 { setvar RETURN 0 break } // break on transparent
			ifvarand temp 16 { setvar RETURN 0 break } // break on masking
			setvarvar peractor1 hitwall
			getactor[THISACTOR].z z
			subvar z 3072
			setactor[THISACTOR].z z
			setvarvar spriteid THISACTOR
			state projectilehitscan
			setvar temp 0
			ifvarn hitsprite -1 
			{
				getactor[hitsprite].picnum picnum
				ifvare picnum SCORCH { setvar RETURN 0 break }
				setvar temp 1
			}
			ifvarvare hitwall peractor1 setvar temp 1
			ifvare temp 1
			{
				addvar z 6144
				setactor[THISACTOR].z z
				state projectilehitscan
				setvar temp 0
				ifvarn hitsprite -1 ifvarn sprite[hitsprite].picnum SCORCH setvar temp 1
				ifvarvare hitwall peractor1 setvar temp 1
				ifvare temp 1
				{
					subvar z 3072
					setactor[THISACTOR].z z
					state projectilehitscan
					setvarvar hitwall peractor1
					getwall[hitwall].x x
					getwall[hitwall].y y
					getwall[hitwall].point2 tempb
					
					getwall[tempb].x mx
					getwall[tempb].y my
					subvarvar x mx
					subvarvar y my
				    getangle z x y
				    addvar z 512
				    setactor[THISACTOR].ang z
				    getactor[THISACTOR].x x
				    getactor[THISACTOR].y y
				    state pythagoras
				    ifvarl xydist 384
			    	{
					    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
					    setvar temp 144
						ifrnd 128 orvar temp 4
						ifrnd 128 orvar temp 8
						setactor[RETURN].cstat temp
						setactorvar[RETURN].target hitwall
					}
				}
			}
			setvar RETURN 0
			break
		    
		}
		setvarvar spriteid THISACTOR
		state projectilehitscan
		ifvarl hitsector 0 { setvar RETURN 0 break }
		ifvarg hitsector 4095 { setvar RETURN 0 break }

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

}


endevent

state invenleftstate

setplayer[THISACTOR].invdisptime 0
ifvare player[THISACTOR].firstaid_amount 0
ifvare player[THISACTOR].steroids_amount 0
ifvare player[THISACTOR].holoduke_amount 0
ifvare player[THISACTOR].jetpack_amount 0
ifvare player[THISACTOR].heat_amount 0
//ifvare player[THISACTOR].scuba_amount 0
//ifvare player[THISACTOR].boot_amount 0
ifvare nukes 0 break

getplayer[THISACTOR].inven_icon invicon
subvar invicon 1
ifvarl invicon 0 setvar invicon 7
setvar temp 0
whilevarn temp 1 // loop stops when valid choice found
{
	switch invicon
	case 0
	ifvarg nukes 0 setvar temp 1
	break
	case 1
	ifvarg player[THISACTOR].firstaid_amount 0
		setvar temp 1
	break
	case 2
	ifvarg player[THISACTOR].steroids_amount 0
		setvar temp 1
	break
	case 3
	ifvarg player[THISACTOR].holoduke_amount 0
		setvar temp 1
	break
	case 4
	ifvarg player[THISACTOR].jetpack_amount 0
		setvar temp 1
	break
	case 5
	ifvarg player[THISACTOR].heat_amount 0
		setvar temp 1
	break
// 	case 6
// 	ifvarg player[THISACTOR].scuba_amount 0
// 		setvar temp 1
// 	break
// 	case 7
// 	ifvarg player[THISACTOR].boot_amount 0
// 		setvar temp 1
//	break
	default break
	endswitch
	ifvare temp 0
	{
		subvar invicon 1
		ifvarl invicon 0 setvar invicon 5 // 7
	}
}

setplayer[THISACTOR].inven_icon invicon
setvar invmsg 78

ends

onevent EVENT_INVENTORYLEFT
setvar RETURN -1
state invenleftstate
endevent

onevent EVENT_INVENTORYRIGHT

setvar RETURN -1
setplayer[THISACTOR].invdisptime 0
ifvare player[THISACTOR].firstaid_amount 0
ifvare player[THISACTOR].steroids_amount 0
ifvare player[THISACTOR].holoduke_amount 0
ifvare player[THISACTOR].jetpack_amount 0
ifvare player[THISACTOR].heat_amount 0
// ifvare player[THISACTOR].scuba_amount 0
// ifvare player[THISACTOR].boot_amount 0
ifvare nukes 0 break

getplayer[THISACTOR].inven_icon invicon
addvar invicon 1
ifvarg invicon 7 setvar invicon 0
setvar temp 0
whilevarn temp 1 // loop stops when valid choice found
{
	switch invicon
	case 0
	ifvarg nukes 0 setvar temp 1
	break
	case 1
	ifvarg player[THISACTOR].firstaid_amount 0
		setvar temp 1
	break
	case 2
	ifvarg player[THISACTOR].steroids_amount 0
		setvar temp 1
	break
	case 3
	ifvarg player[THISACTOR].holoduke_amount 0
		setvar temp 1
	break
	case 4
	ifvarg player[THISACTOR].jetpack_amount 0
		setvar temp 1
	break
	case 5
	ifvarg player[THISACTOR].heat_amount 0
		setvar temp 1
	break
// 	case 6
// 	ifvarg player[THISACTOR].scuba_amount 0
// 		setvar temp 1
// 	break
// 	case 7
// 	ifvarg player[THISACTOR].boot_amount 0
// 		setvar temp 1
// 	break
	default break
	endswitch
	ifvare temp 0
	{
		addvar invicon 1
		ifvarg invicon 5 setvar invicon 0
	}
}

setplayer[THISACTOR].inven_icon invicon
setvar invmsg 78

endevent

onevent EVENT_INVENTORY

	ifvare invicon 0 ifvarg nukes 0
	{
		globalsound PREP2DIE
		espawn ATOMICHEALTH
		setactorvar[RETURN].peractor4 26
		getplayer[THISACTOR].horiz zvel
		subvar zvel 100
		mulvar zvel -80
		ifvarl zvel -6144 setvar zvel -6144
		ifvarg zvel 6144 setvar zvel 6144
		setactor[RETURN].zvel zvel
		setactorvar[RETURN].mtype 2
		setactor[RETURN].ang player[THISACTOR].ang
		subvar nukes 1
	}

	switch invicon
	case 0 ifvare nukes 0 state invenleftstate
	break
	case 1 ifvare player[THISACTOR].firstaid_amount 0 state invenleftstate
	break
	case 2
	ifvarl player[THISACTOR].steroids_amount 400 state invenleftstate
	break
	case 3
	ifvare player[THISACTOR].holoduke_amount 0 state invenleftstate
	break
	case 4
	ifvare player[THISACTOR].jetpack_amount 0 state invenleftstate
	break
	case 5
	ifvare player[THISACTOR].heat_amount 0 state invenleftstate
	break
	case 6
	case 7
	state invenleftstate
	break
// 	case 6
// 	ifvare player[THISACTOR].scuba_amount 0 state invenleftstate
// 	break
// 	case 7
// 	ifvare player[THISACTOR].boot_amount 0 state invenleftstate
// 	break
 	default break
	endswitch
	
endevent

gamevar chwep 0 1

onevent EVENT_PREVIOUSWEAPON
 setvar chwep 1
endevent

onevent EVENT_NEXTWEAPON
 setvar chwep 2
endevent

onevent EVENT_SELECTWEAPON

ifvarn player[THISACTOR].kickback_pic 0
{
	setvar RETURN -1
	break
}
ifvarl weaptotal 12
ifvarn player[THISACTOR].weapon_pos 0
{
	setvar RETURN -1
	break
}

ifvare useakimbo YES setvar weapswitch 26
ifvare CURRWEAP 8 setvarvar PIPEBOMB_CONTROL pipecontrol

ifvare player[THISACTOR].ammo_amount 3 0
ifvarg MINIGUNAMMO 0
ifvare player[THISACTOR].gotweapon 3 YES
ifvarand ALTCHAINGUN 1
ifvare player[THISACTOR].weapon_pos 0
ifvarn CURRWEAP 3
state changeminigun

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

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

endevent

onevent EVENT_CHEATGETJETPACK

ifvare useakimbo YES
ifvare akimbo -1 state changeakimbo

orvar ALTCHAINGUN 1
orvar ALTCHAINGUN 8
getplayer[THISACTOR].max_ammo_amount 3 MINIGUNAMMO
setvar botclip 12
setvar LASERAMMO 100
setvar nukes 3
endevent

onevent EVENT_MOVEFORWARD

setvar fpress 2

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

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

addvar lpresstime 1

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

endevent

onevent EVENT_STRAFERIGHT

addvar rpresstime 1

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

endevent

definegamefuncname 11 ATTRITION_MENU
// Look Up

onevent EVENT_LOOKUP
setvar RETURN -1
addvar lastinput 1
ifvarvarg lastinput timer setvarvar lastinput timer
ifvarvare lastinput timer nullop else
{
	setvarvar lastinput timer
	ifvare menutoggle 0 
	{		
		sound INTO_MENU 
		setvar menutoggle 1 	
	} else
	{
		sound EXITMENUSOUND
		setvar menutoggle 0
		setplayer[THISACTOR].movement_lock 0
	}
}

endevent

definegamefuncname 18 QUICK_PIPEBOMB

onevent EVENT_AIMDOWN

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

setvar RETURN -1
endevent

state checksuperkick

ifp pshrunk nullop else
ifvare superkicking 0 ifvarg kickenergy 130
{
	 setvar temp 0
	 ifvarand extbits 1 setvar temp 1
	 ifvarand extbits 2 { setvar temp 1 setvar spinkick 1 getplayer[THISACTOR].ang dodgeang }
	 ifvare temp 1
	 {
		setvar RETURN -1
		setvar superkicking 1
		ifrnd 128 setvar reversekick YES else setvar reversekick NO
		ifvarg rofbonus 0 subvar kickenergy 52 else
		ifvarg weaplev0 3 subvar kickenergy 104 else
		subvar kickenergy 156
		ifinwater nullop else
		ifvare dodge 0
		{
			getplayer[THISACTOR].ang dodgeang
			ifvarg rofbonus 0 setvar dodge 5 else
			setvar dodge 10
		}
  	}
	 
}

ends

state kickcombo
 
 ifvarg kickenergy 130
 ifvare superkickdone YES
 ifvarl superkicking 3
 {
	 ifvare spinkick NO setvar spinkick YES else setvar spinkick NO
	 setvar superkickdone 0
	 setvar kickimpact 0
	 ifvare reversekick YES setvar reversekick NO else setvar reversekick YES
	 setvar superkicking 1
	 ifvarg rofbonus 0 subvar kickenergy 52 else
	 ifvarg weaplev0 3 subvar kickenergy 104 else
	 subvar kickenergy 156
	 ifvarn kicktarg -1
	 {
		getactor[kicktarg].x mx
		getactor[kicktarg].y my
		subvarvar mx player[THISACTOR].posx
		subvarvar my player[THISACTOR].posy
		getangle angvar mx my
		setplayer[THISACTOR].ang angvar
	 }
	 getplayer[THISACTOR].ang dodgeang
	 ifvarg rofbonus 0 setvar dodge 3 else
	 setvar dodge 6
 }

ends

onevent EVENT_QUICKKICK

ifvarn superkicking 0
{
	 setvar RETURN -1
	 ifvarg weaplev0 0 
	 ifvare player[THISACTOR].somethingonplayer -1 state kickcombo
}

state checksuperkick

endevent


onevent EVENT_JUMP

ifvarn menutoggle 0 { setvar RETURN -1 break }

ifvarn mybot -1
{
	setvarvar tempd RETURN
	espawn PLAYERTRAIL
	getplayer[THISACTOR].posz z
	addvar z 4096
	setactor[RETURN].z z
	setvar ptrailtimer 0 
	setactorvar[RETURN].mtype 1
	setvarvar RETURN tempd
}

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

	

endevent

onevent EVENT_PROCESSINPUT

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


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


ifvarand bits 262144 // altfire/reload
{
	ifvarn player[THISACTOR].somethingonplayer -1 
	{
		orvar bits 4
		setinput[THISACTOR].bits bits
	}
	
	ifvare CURRWEAP 0 ifvarg LASERAMMO 4
	ifvarg weaplev10 0
	{
		ifvare LASERCHARGE 0 { ifvarg rofbonus 0 setplayer[THISACTOR].sound_pitch 1024 sound CHARGESND ifvarg rofbonus 0 setplayer[THISACTOR].sound_pitch 0 }
		ifvarg LASERCHARGE 26 soundonce CHARGEHOLD
		ifvarl LASERCHARGE 52 
		addvar LASERCHARGE 1
		ifvarg rofbonus 0 addvar LASERCHARGE 1
	}
 	ifvare CURRWEAP 1 ifvare KICKBACKPIC 0 ifvarvarl botclip WEAPON1_CLIP
 	ifvare player[THISACTOR].weapon_pos 0
	{
		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
				ifvare player[THISACTOR].reloading 0
				{
					setplayer[THISACTOR].reloading 1
					setplayer[THISACTOR].kickback_pic 9
				}
				sound EJECT_CLIP
				setvar PISTOLRELOAD 1
		}
	}
	
	ifvare CURRWEAP 2 ifvarg weaplev2 1 ifvare KICKBACKPIC 0 
	ifvare player[THISACTOR].weapon_pos 0 ifvarg player[THISACTOR].ammo_amount 2 0
	{
		setplayer[THISACTOR].kickback_pic 1
		setvar WEAPON2_SHOOTS STARPROJ
		setvar WEAPON2_FIRESOUND FLAKFIRE
	}

	ifvare CURRWEAP 3
	ifvare player[THISACTOR].weapon_pos 0
	{
		ifvarand ALTCHAINGUN 2
		{
			ifvarg player[THISACTOR].ammo_amount 3 9
			ifvare grenadecounter 0
			{
				getplayer[THISACTOR].ammo_amount 3 temp
				subvar temp 10
				setplayer[THISACTOR].ammo_amount 3 temp
				setvar grenadecounter 1
			}
		}
		else ifvarg weaplev3 0 ifvare KICKBACKPIC 0 ifvarg player[THISACTOR].ammo_amount 3 0
		{
			setplayer[THISACTOR].kickback_pic 1
			setvar WEAPON3_SHOOTS FIREBULLET
			setvar WEAPON3_FIRESOUND RPG_SHOOT
			setvar WEAPON3_FLAGS 8276
			ifvarg weaplev3 4 setvar WEAPON3_SHOTSPERBURST 2
		}
	}
	
	ifvare CURRWEAP 4 ifvarg weaplev4 5 ifvare KICKBACKPIC 0
	ifvare player[THISACTOR].weapon_pos 0
	ifvarg player[THISACTOR].ammo_amount 4 1
	{
		setplayer[THISACTOR].kickback_pic 1
		sound MISSILE2
		setvar WEAPON4_SHOOTS MEGAROCKET
		getplayer[THISACTOR].ammo_amount 4 temp
		subvar temp 1
		setplayer[THISACTOR].ammo_amount 4 temp
	}
	
	ifvare CURRWEAP 8 ifvare KICKBACKPIC 0
	ifvare player[THISACTOR].weapon_pos 0
	ifvarg player[THISACTOR].ammo_amount 8 0
	ifvarn scannedsprite -1
	ifvare actorvar[scannedsprite].monstatus 1
	ifvarl sprite[scannedsprite].statnum 3
	ifvarg sprite[scannedsprite].statnum 0
	{
		dist xydist THISACTOR scannedsprite
		ldist xydist2 THISACTOR scannedsprite
		ifvarl xydist2 768 ifvarl xydist 1280
		{
			setplayer[THISACTOR].kickback_pic 1
			setvarvar triphack scannedsprite
			setvarvar tripz hitz // this should be the player's current z hitscan coord
		}
	}
	
	ifvare CURRWEAP 9 ifvarg weaplev9 1 ifvare KICKBACKPIC 0
	ifvare player[THISACTOR].weapon_pos 0
	ifvarg player[THISACTOR].ammo_amount 9 0
	{
		setplayer[THISACTOR].kickback_pic 1
		setvar WEAPON9_SHOOTS ICESHARD
		setvar WEAPON9_FIRESOUND SHARDSHOOTSND
		ifvarg weaplev9 4 setvar WEAPON9_SHOTSPERBURST 5 else
		ifvarg weaplev9 3 setvar WEAPON9_SHOTSPERBURST 4 else
		setvar WEAPON9_SHOTSPERBURST 3
		setvar WEAPON9_TOTALTIME 9		
	}
}
else 
{
	ifvarand ALTCHAINGUN 2 nullop else
	ifvare WEAPON3_SHOOTS FIREBULLET
	{
		setvar temp 0
		ifvarand bits 4 setvar temp 1
		ifvare KICKBACKPIC 0 setvar temp 1
		ifvare temp 1
		{
			setvar WEAPON3_SHOOTS CHAINGUN
			setvar WEAPON3_FIRESOUND DPCHAINGUNFIRE
			ifvarg weaplev3 4 setvar WEAPON3_FLAGS 73804 else
			setvar WEAPON3_FLAGS 73812
		}
	}
	ifvarg LASERCHARGE 25 ifvare CURRWEAP 0
	{
		setvar weap BIGFIRELASER
		setvar LASERFIRE 1
		ifvarg weaplev10 3 { shoot POWBALL sound IMP_ALTFIRE subvar LASERAMMO 10 } else
		{ shoot BIGFIRELASER sound BLASTERSND subvar LASERAMMO 5 }
		ifvarl LASERAMMO 0 setvar LASERAMMO 0
	}
	ifvarg LASERCHARGE 0
	{
		setvar LASERCHARGE 0
		stopsound CHARGESND
		stopsound CHARGEHOLD
	}
	ifvarand bits 4
	{
		ifvare CURRWEAP 9
		{
			ifvarg weaplev9 2
			{
				setvar WEAPON9_SHOOTS ICEBEAM
				setvar WEAPON9_FIRESOUND ICEBEAMSND
				setvar WEAPON9_INITIALSOUND -1
				setvar WEAPON9_TOTALTIME 10
				setvar WEAPON9_SHOTSPERBURST 1
			}
			else state normalfreeze
		}
	}
}
	  
endevent

onevent EVENT_FIRE

ifvarn menutoggle 0 { setvar RETURN -1 break }

ifvare CURRWEAP 3
	ifvarand ALTCHAINGUN 2 break // no need to check the rest

ifvare CURRWEAP 2
{
	setvar WEAPON2_SHOOTS SHOTGUN // returning it to normal
	ifvarg weaplev2 2 setvar WEAPON2_FIRESOUND SHOTGUN2 else
	setvar WEAPON2_FIRESOUND SHOTGUN_FIRE
}

ifvare CURRWEAP 3 //ifvare WEAPON3_SHOOTS FIREBULLET
{
	setvar WEAPON3_SHOOTS CHAINGUN
	ifvarl weaplev3 2 setvar WEAPON3_FIRESOUND CHAINGUN_FIRE else
	ifvarl weaplev3 4 setvar WEAPON3_FIRESOUND MP5FIRE else
	setvar WEAPON3_FIRESOUND DPCHAINGUNFIRE
	ifvarg weaplev3 4 setvar WEAPON3_FLAGS 73804 else
	setvar WEAPON3_FLAGS 73812
	setvar WEAPON3_SHOTSPERBURST 0
}
	

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


ifvare CURRWEAP 0 
{
	ifvarg LASERFIRE 0 { setvar RETURN -1 break }
	ifvarg LASERAMMO 0 
	{
		ifvarg LASERCHARGE 25
		{
			ifvarg weaplev10 3 { shoot POWBALL sound IMP_ALTFIRE subvar LASERAMMO 10 } else
			{ shoot BIGFIRELASER sound BLASTERSND subvar LASERAMMO 5 }
			
			setvar LASERCHARGE 0
			
			ifvarl LASERAMMO 0 setvar LASERAMMO 0
		} 
		else
		{
			ifvarg weaplev10 2 { shoot POWBEAM ifvarg weaplev10 5 sound IMP_SHOOT else sound PRED_ATTACK } else
			{ shoot FIRELASER sound PRED_ATTACK2 }
			subvar LASERAMMO 1
			ifvare LASERAMMO 1 ifvarg player[THISACTOR].ammo_amount 1 0 ifvare player[THISACTOR].gotweapon 1 YES setplayer[THISACTOR].curr_weapon 1
		}
		setvar LASERFIRE 1 
		setvar RETURN -1 
		break
	}
	state checksuperkick
	ifvarn superkicking 0
	{
		 setvar RETURN -1
		 ifvarg weaplev0 0 ifvare player[THISACTOR].somethingonplayer -1 state kickcombo
	}
}



endevent



definegamefuncname 41 ALTFIRE
// Center View

onevent EVENT_NEWGAME

// readgamevar saveoption
// readgamevar mirroroption
// they will read as 0 if not played yet, making them off by default

readgamevar recentmaps
addlogvar recentmaps
setvar temp 1073741824
setvar C 0
whilevarn temp 0
{
	ifvarvarand recentmaps temp addvar C 1
	shiftvarr temp 1
}
addlogvar C
ifvarg C 25 { setvar recentmaps 0 savegamevar recentmaps }

readgamevar recentmaps2
addlogvar recentmaps2
setvar temp 1073741824
setvar C 0
whilevarn temp 0
{
	ifvarvarand recentmaps2 temp addvar C 1
	shiftvarr temp 1
}
addlogvar C
ifvarg C 25 { setvar recentmaps2 0 savegamevar recentmaps2 }

readgamevar recentmaps3
addlogvar recentmaps3
setvar temp 1073741824
setvar C 0
whilevarn temp 0
{
	ifvarvarand recentmaps3 temp addvar C 1
	shiftvarr temp 1
}
addlogvar C
ifvarg C 25 { setvar recentmaps3 0 savegamevar recentmaps3 }
setvar C 0

readgamevar randomstart
gettimedate temp tempb tempc tempd tempe A B C
shiftvarl tempe 17
shiftvarl tempd 14
shiftvarl tempc 10
shiftvarl tempb 6
setvarvar gameid tempe
addvarvar gameid tempd
addvarvar gameid tempc
addvarvar gameid tempb
addvarvar gameid temp

ifvare gameid 0 setvar gameid 1
readgamevar finished
readarrayfromfile atthighscores 1068
readarrayfromfile attgameids 1132
ifvare atthighscores[0] 0 // no high scores set yet
{
	setarray atthighscores[0] 100000
	setarray atthighscores[1] 90000
	setarray atthighscores[2] 80000
	setarray atthighscores[3] 70000
	setarray atthighscores[4] 60000
	setarray atthighscores[5] 50000
	setarray atthighscores[6] 40000
	setarray atthighscores[7] 30000
	setarray atthighscores[8] 25000
	setarray atthighscores[9] 20000
	setarray atthighscores[10] 15000
	setarray atthighscores[11] 10000
	setarray atthighscores[12] 9000
	setarray atthighscores[13] 8000
	setarray atthighscores[14] 7000
	setarray atthighscores[15] 6000
	setarray atthighscores[16] 5000
}
	


setvar WEAPON1_TOTALTIME 7

smaxammo 1 180
smaxammo 2 30
smaxammo 3 180
smaxammo 4 30
smaxammo 5 30
smaxammo 6 30
smaxammo 7 80
smaxammo 8 10
smaxammo 9 80
smaxammo 11 50

// example xpcaps1[0] is the amount of xp you need to exceed for weapon 1, level 0 in order to make it level 1
setarray xpcaps0[0] 1000
setarray xpcaps0[1] 2500
setarray xpcaps0[2] 6000
setarray xpcaps0[3] 12500
setarray xpcaps0[4] 23000
setarray xpcaps0[5] 35000
setarray xpcaps0[6] 50000
setarray xpcaps0[7] 70000
setarray xpcaps0[8] 100000
setarray xpcaps0[9] 150000
setarray xpcaps0[10] 200000
setarray xpcaps0[11] 9999999


setarray xpcaps1[0] 2500
setarray xpcaps1[1] 6000
setarray xpcaps1[2] 12500
setarray xpcaps1[3] 23000
setarray xpcaps1[4] 38000
setarray xpcaps1[5] 60000
setarray xpcaps1[6] 82000
setarray xpcaps1[7] 120000
setarray xpcaps1[8] 170000
setarray xpcaps1[9] 250000
setarray xpcaps1[10] 350000
setarray xpcaps1[11] 9999999


setarray xpcaps2[0] 5000
setarray xpcaps2[1] 12500
setarray xpcaps2[2] 23000
setarray xpcaps2[3] 38000
setarray xpcaps2[4] 60000
setarray xpcaps2[5] 100000
setarray xpcaps2[6] 150000
setarray xpcaps2[7] 200000
setarray xpcaps2[8] 250000
setarray xpcaps2[9] 350000
setarray xpcaps2[10] 500000
setarray xpcaps2[11] 9999999

setarray xpcaps3[0] 3500
setarray xpcaps3[1] 9000
setarray xpcaps3[2] 20000
setarray xpcaps3[3] 40000
setarray xpcaps3[4] 70000
setarray xpcaps3[5] 110000
setarray xpcaps3[6] 150000
setarray xpcaps3[7] 200000
setarray xpcaps3[8] 250000
setarray xpcaps3[9] 350000
setarray xpcaps3[10] 500000
setarray xpcaps3[11] 9999999

setarray xpcaps4[0] 5000
setarray xpcaps4[1] 12500
setarray xpcaps4[2] 25000
setarray xpcaps4[3] 45000
setarray xpcaps4[4] 70000
setarray xpcaps4[5] 100000
setarray xpcaps4[6] 150000
setarray xpcaps4[7] 200000
setarray xpcaps4[8] 250000
setarray xpcaps4[9] 350000
setarray xpcaps4[10] 500000
setarray xpcaps4[11] 9999999

setarray xpcaps5[0] 2000
setarray xpcaps5[1] 5000
setarray xpcaps5[2] 10000
setarray xpcaps5[3] 18500
setarray xpcaps5[4] 30000
setarray xpcaps5[5] 50000
setarray xpcaps5[6] 80000
setarray xpcaps5[7] 120000
setarray xpcaps5[8] 170000
setarray xpcaps5[9] 250000
setarray xpcaps5[10] 350000
setarray xpcaps5[11] 9999999

setarray xpcaps6[0] 1500
setarray xpcaps6[1] 3500
setarray xpcaps6[2] 7000
setarray xpcaps6[3] 12000
setarray xpcaps6[4] 20000
setarray xpcaps6[5] 30000
setarray xpcaps6[6] 50000
setarray xpcaps6[7] 80000
setarray xpcaps6[8] 120000
setarray xpcaps6[9] 170000
setarray xpcaps6[10] 250000
setarray xpcaps6[11] 9999999

setarray xpcaps7[0] 4000
setarray xpcaps7[1] 9000
setarray xpcaps7[2] 18000
setarray xpcaps7[3] 30000
setarray xpcaps7[4] 50000
setarray xpcaps7[5] 70000
setarray xpcaps7[6] 100000
setarray xpcaps7[7] 150000
setarray xpcaps7[8] 200000
setarray xpcaps7[9] 270000
setarray xpcaps7[10] 350000
setarray xpcaps7[11] 9999999

setarray xpcaps8[0] 600
setarray xpcaps8[1] 1800
setarray xpcaps8[2] 4000
setarray xpcaps8[3] 8000
setarray xpcaps8[4] 16000
setarray xpcaps8[5] 25000
setarray xpcaps8[6] 50000
setarray xpcaps8[7] 80000
setarray xpcaps8[8] 120000
setarray xpcaps8[9] 170000
setarray xpcaps8[10] 250000
setarray xpcaps8[11] 9999999

setarray xpcaps9[0] 2000
setarray xpcaps9[1] 6000
setarray xpcaps9[2] 12500
setarray xpcaps9[3] 23000
setarray xpcaps9[4] 38000
setarray xpcaps9[5] 60000
setarray xpcaps9[6] 100000
setarray xpcaps9[7] 150000
setarray xpcaps9[8] 200000
setarray xpcaps9[9] 270000
setarray xpcaps9[10] 350000
setarray xpcaps9[11] 9999999

setarray xpcaps10[0] 1500
setarray xpcaps10[1] 4000
setarray xpcaps10[2] 8000
setarray xpcaps10[3] 15000
setarray xpcaps10[4] 25000
setarray xpcaps10[5] 40000
setarray xpcaps10[6] 60000
setarray xpcaps10[7] 90000
setarray xpcaps10[8] 130000
setarray xpcaps10[9] 180000
setarray xpcaps10[10] 240000
setarray xpcaps10[11] 9999999

setarray xpcaps11[0] 1000
setarray xpcaps11[1] 3000
setarray xpcaps11[2] 8000
setarray xpcaps11[3] 15000
setarray xpcaps11[4] 25000
setarray xpcaps11[5] 40000
setarray xpcaps11[6] 60000
setarray xpcaps11[7] 100000
setarray xpcaps11[8] 150000
setarray xpcaps11[9] 220000
setarray xpcaps11[10] 300000
setarray xpcaps11[11] 9999999

endevent

onevent EVENT_RESETWEAPONS

state resetweaponstate

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_WEAPKEY4

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

onevent EVENT_RETURNTOCENTER

ifvarn player[THISACTOR].hard_landing 0 break

setvar RETURN -1

ifvarg weaplev7 0
ifvare CURRWEAP 7
ifvare player[THISACTOR].weapon_pos 0
ifvare player[THISACTOR].kickback_pic 0
{
	ifvare devshotty 1 
	{
		quote 1083
		setvar devshotty 2 
		ifvarg weaplev7 5 setvar WEAPON7_SHOTSPERBURST 8 else
		ifvarg weaplev7 3 setvar WEAPON7_SHOTSPERBURST 7 else 
		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
	}
}

endevent

onevent EVENT_GETSHOTRANGE

ifvare CURRWEAP 0
ifvare superkicking 0
{
	setvar ANGRANGE 1
	setvar ZRANGE 1
}
ifvare CURRWEAP 1
{
 	ifvarg botclip 0 subvar botclip 1
	
	setvar ANGRANGE PISTOLSPREAD
	ifvarl ANGRANGE 4 setvar ANGRANGE 4
	setvarvar temp ANGRANGE
	shiftvarl temp 3
	setvarvar ZRANGE temp
	
	ifvare useakimbo YES ifvarg akimbo 0
	{
		mulvar ANGRANGE 2
		mulvar ZRANGE 2
	}
}
else
ifvare CURRWEAP 2
{
	setvar ANGRANGE SHOTGUNSPREAD
	ifvarl weaplev2 2 shiftvarl ANGRANGE 1
	ifvarl ANGRANGE 4 setvar ANGRANGE 4
	setvarvar temp ANGRANGE
	shiftvarl temp 3
	setvarvar ZRANGE temp
}
else
ifvare CURRWEAP 3
{
	ifvarn chainsparksprite -1
	{
		setvar ANGRANGE 1
		setvar ZRANGE 1
	}
	else
	ifvarand ALTCHAINGUN 2 // using battlelord minigun
	{
		
		// change spread depending on current speed
	}
	else
	{
		setvar ANGRANGE CHAINGUNSPREAD
		ifvarl ANGRANGE 4 setvar ANGRANGE 4
		ifvarl weaplev3 1 shiftvarl ANGRANGE 1
		setvarvar temp ANGRANGE
		shiftvarl temp 3
		setvarvar ZRANGE temp
	}
	
}

ifvare CURRWEAP 9 ifvare WEAPON9_SHOOTS ICEBEAM
{
	setvar ANGRANGE 1
	setvar ZRANGE 1
}

else ifvare player[THISACTOR].over_shoulder_on YES
{
	espawn SHOTSPARK2
	getplayer[THISACTOR].horiz temp
	setactorvar[RETURN].position temp
}



	
endevent



state initsprites
setvar spriteid 0
whilevarn spriteid 16384
{

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

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



onevent EVENT_ENTERLEVEL

setvar raining 0
setvar ONCE 0
state initsprites

endevent

onevent EVENT_RESETPLAYER

setvar quikpipe 0
setvar activemonsters 0
setvar kickasscount 0
setvar tauntcount 0
setvar lastspeechtime -1500
setvar weapcount 0
setvar ftap 0
setvar btap 0
setvar ltap 0
setvar rtap 0
setvar fpresstime 0
setvar bpresstime 0
setvar lpresstime 0
setvar rpresstime 0
setvar superkicking 0
setvar superkickdone 0
setvar kickenergy KENERGY
setplayer[THISACTOR].runspeed RUNNINGSPEED

setvar ONCE 1
setvar target 0

setvar clearlocators 1

ifvarand ALTCHAINGUN 2 nullop else
setvar WEAPON3_FIRESOUND DPCHAINGUNFIRE



setplayer[THISACTOR].sound_pitch 0

// reset ptrail array
setvar temp 0
whilevarn temp 100
{
	setarray ptrails[temp] -1
	addvar temp 1
}

state restorestatus
	
endevent


state nocodecheck2

getactor[THISACTOR].extra temp
ifvare temp -1
{
	getactor[THISACTOR].hitag temp
	ifvare temp 0
	{
		getactor[THISACTOR].lotag temp
		ifvare temp 0
		{
			getactor[THISACTOR].xvel temp
			ifvare temp 0
			{
				getactor[THISACTOR].yvel temp
				ifvare temp 0
				{
					getactor[THISACTOR].zvel temp
					ifvare temp 0
					{
						ifvare lotag 0 ifvare hitag 0
						ifvare monstflags 0
						ifvare droptile 0
						setvar NOCODE 2
					}
				}
			}
		}
	}
}

ends

state nocodecheck1

ifvare mirrored YES
{
	state nocodecheck2
	break
}

getactor[THISACTOR].extra temp
ifvare temp -1
{
	getactor[THISACTOR].hitag temp
	ifvare temp 0
	{
		getactor[THISACTOR].lotag temp
		ifvare temp 0
		{
			getactor[THISACTOR].xvel temp
			ifvare temp 0
			{
				getactor[THISACTOR].yvel temp
				ifvare temp 0
				{
					getactor[THISACTOR].zvel temp
					ifvare temp 0
					{
						ifvare lotag 0 ifvare hitag 0
						ifvare monstflags 0
						ifvare droptile 0
						setvar NOCODE 1
					}
				}
			}
		}
	}
}

ends

state FIND_CENTER_OF_SECTOR
// also calculates area of sector

whilevarvarn currwall numwalls
{
	getwall[wallpoint].x WALLX
	getwall[wallpoint].y WALLY
	ifvare currwall 0 
	{
		setvarvar SMALLX WALLX setvarvar BIGX WALLX 
		setvarvar SMALLY WALLY setvarvar BIGY WALLY
	}
	else
	{
		ifvarvarl WALLX SMALLX setvarvar SMALLX WALLX else
		ifvarvarg WALLX BIGX setvarvar BIGX WALLX
		
		ifvarvarl WALLY SMALLY setvarvar SMALLY WALLY else
		ifvarvarg WALLY BIGY setvarvar BIGY WALLY
	}
	
	addvar wallpoint 1
	addvar currwall 1
}

subvarvar BIGX SMALLX
subvarvar BIGY SMALLY
ifvarl BIGX 0 mulvar BIGX -1
ifvarl BIGY 0 mulvar BIGY -1
setvarvar x BIGX
shiftvarr x 3
setvarvar y BIGY
shiftvarr y 3
setvarvar area x
mulvarvar area y
shiftvarr area 9
ifvarg area 1280 setvar area 1280

ends

//gamearray custom 6000

state setweather

// custom art check
// setvar spriteid 0
// whilevarn spriteid 16384
// {
// 	getactor[spriteid].picnum picnum
// 	ifvarg picnum 3583 ifvarl picnum 4096 setarray custom[picnum] picnum
// 	addvar spriteid 1
// }
// setvar tempd 6666
// addlogvar tempd

// setvar spriteid 0
// whilevarvarn spriteid NUMSECTORS
// {
// 	getsector[spriteid].floorpicnum picnum
// 	ifvarg picnum 3583 ifvarl picnum 4096 setarray custom[picnum] picnum
// 	getsector[spriteid].ceilingpicnum picnum
// 	ifvarg picnum 3583 ifvarl picnum 4096 setarray custom[picnum] picnum
// 	addvar spriteid 1
// }
// setvar tempd 6666
// addlogvar tempd
// setvar spriteid 0
// whilevarvarn spriteid NUMWALLS
// {
// 	getwall[spriteid].picnum picnum
// 	ifvarg picnum 3583 ifvarl picnum 4096 setarray custom[picnum] picnum
// 	getwall[spriteid].overpicnum picnum
// 	ifvarg picnum 3583 ifvarl picnum 4096 setarray custom[picnum] picnum
// 	addvar spriteid 1
// }

// setvar spriteid 3584
// whilevarn spriteid 4096
// {
// 	setvarvar temp custom[spriteid]
// 	ifvarn temp 0 addlogvar temp
// 	addvar spriteid 1
// }

ifvarn rainstart 0 break

// check for weather conditions
// if it finds enough sprites that indicate rain, then raining is set
setvar tempd 0
setvar spriteid 0
whilevarn spriteid 16384
{
	ifvarn sprite[spriteid].statnum 1024
	{
		getactor[spriteid].sectnum temp
		ifvarg temp -1 ifvarvarl temp NUMSECTORS
		{
			getsector[temp].ceilingstat tempb
			ifvarand tempb 1
			{
				ifvare sprite[spriteid].picnum WATERDRIP
				addvar tempd 1
				ifvare sprite[spriteid].picnum NATURALLIGHTNING
				addvar tempd 2				
				ifvare sprite[spriteid].picnum MUSICANDSFX
				ifvare sprite[spriteid].lotag RAIN
				addvar tempd 5
			}
		}		
	}
	addvar spriteid 1
}
ifvarg tempd 10
{
	randvar rainstart 32
	addvar rainstart 32
	break
}
		
setvar spriteid 0
setvar tempd 0
setvar tempe 0
whilevarvarn spriteid NUMSECTORS
{
	getsector[spriteid].ceilingstat temp
	ifvarand temp 1
	{
		getsector[spriteid].floorpal tempb
		ifvare tempb 0
		{
			getsector[spriteid].floorpicnum picnum
			setvar tempc 0
			ifvare picnum 3416 setvar tempc 1
			ifvare picnum 241 ifvarl sector[spriteid].floorshade 8 setvar tempc 1
			ifvare tempc 1
			{
				addvar tempe 1
				getsector[spriteid].wallptr wallpoint // get the firstwall of the sector
				getsector[spriteid].wallnum numwalls // get the number of walls in the sector
				setvar currwall 0
				state FIND_CENTER_OF_SECTOR
				// mx, my is the center point
				// BIGX is the x length of sector
				// BIGY is the y length of sector
				addvarvar tempd area
				//addlogvar area
			}
		}
	}
	addvar spriteid 1
}
//addlogvar tempd
ifvarg tempd 1500
ifvarg tempe 9 // must have at least 10 "snow" sectors
{
	randvar rainstart 16
	addvar rainstart 16
	mulvar rainstart -1
}
		

ends

gamevar grasscount 0 0
state spawngrass
	getsector[A].wallptr wallpoint // get the firstwall of the sector
	getsector[A].wallnum numwalls // get the number of walls in the sector
	setvar currwall 0
	state FIND_CENTER_OF_SECTOR
	// mx, my is the center point
	// BIGX is the x length of sector
	// BIGY is the y length of sector
	
	ifvarg B 8192
	{ 
		ifvarg grasscount 1024 shiftvarr area 1 // reduce grass if lots of sprites
		ifvarg grasscount 2048 shiftvarr area 1
	}
	shiftvarr area 2
	setvar tempe 0
	whilevarvarn tempe area
	{
		randvarvar tempb BIGX
		randvarvar tempc BIGY
		setvarvar x SMALLX
		setvarvar y SMALLY
		addvarvar x tempb
		addvarvar y tempc
		updatesector x y tempd
		ifvarvare A tempd
		{
			addvar tempe 1
			addvar grasscount 1
			randvar tempd 2
			addvar tempd 6250
			espawnvar tempd
			ifvarn sector[A].floorslope 0
			{
				getflorzofslope A x y z
				ifrnd 128
				setactor[RETURN].cstat 2 else
				setactor[RETURN].cstat 6	
			}
			else 
			{
				getsector[A].floorz z
				setactor[RETURN].cstat 16
			}
			setsprite RETURN x y z
			changespritestat RETURN 1
			setactor[RETURN].xrepeat 12
			randvar tempc 4 addvar tempc 12
			setactor[RETURN].yrepeat tempc
			randvar angvar 2047
			setactor[RETURN].ang angvar
		}
		ifvarvarl tempe area
		addvar tempe 1
	}
	
ends

state assessvalue

switch picnum

case COLA
addvar B 100
break

case TOILET
case WATERFOUNTAIN
case STALL
case HYDRENT
addvar B 100
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp setvarvar B temp
break
case SIXPAK
case JOLLYMEAL
addvar B 300
break
case ATOMICHEALTH
addvar B 500
break
case HEAVYHBOMB
addvar B 50
break
case AMMO
addvar B 150
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 15 }
break
case SHOTGUNAMMO
addvar B 400
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 40 }
break
case BATTERYAMMO
addvar B 300
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 30 }
break
case RPGAMMO
addvar B 600
break
case HBOMBAMMO
addvar B 500
break
case CRYSTALAMMO
addvar B 500
break
case DEVISTATORAMMO
addvar B 550
break
case FREEZEAMMO
addvar B 350
break
case TRIPBOMBSPRITE
addvar B 75
break
case GROWAMMO
addvar B 350
break
case SHIELD
addvar B 600
break
case FIRSTGUNSPRITE
addvar B 600
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 60 }
break
case SHOTGUNSPRITE
addvar B 600
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 60 }
break
case CHAINGUNSPRITE
addvar B 600
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 60 }
break
case RPGSPRITE
addvar B 1200
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 120 }
break
case SHRINKERSPRITE
addvar B 1000
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 100 }
break
case DEVISTATORSPRITE
addvar B 1200
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 120 }
break
case FREEZESPRITE
addvar B 800
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 80 }
break
case GROWSPRITEICON
addvar B 1000
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 100 }
break
case FIRSTAID
addvar B 800
break
case BOOTS
addvar B 200
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 20 }
break
case HOLODUKE
addvar B 1000
break
case HEATSENSOR
addvar B 400
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 40 }
break
case JETPACK
addvar B 300
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 30 }
break
//case AIRTANK
//addvar B 200
//break
case STEROIDS
addvar B 600
setvarvar temp B
addvar C 1
subvarvar B C
ifvarvarl B temp { setvarvar B temp addvar B 60 }
break

case EGG
addvar A 20
break
case GREENSLIME
addvar A 10
break

case LIZTROOP
case LIZTROOPSHOOT
case LIZTROOPJETPACK
case LIZTROOPRUNNING
case LIZTROOPONTOILET
case LIZTROOPJUSTSIT
case LIZTROOPDUCKING
addvar A TROOPVAL
ifvare sprite[spriteid].pal 21 addvar A 50
break

case LIZTROOPSTAYPUT
addvar A TROOPVAL
ifvare sprite[spriteid].pal 21 addvar A 50
addvar A 50
break

case OCTABRAIN
case OCTABRAINSTAYPUT
addvar A OCTAVAL
break

case DRONE
addvar A DRONEVAL
break

case COMMANDER
addvar A COMMVAL
break

case COMMANDERSTAYPUT
addvar A COMMVAL
addvar A 200
break

case TANK
addvar A RECONVAL
break

case MECH2
addvar A BOSSPALVAL
addvar A BOSSPALVAL
break

case PIGCOP
addvar A PIGVAL
break

case PIGCOPSTAYPUT
case PIGCOPDIVE
addvar A PIGVAL
addvar A 100
break

case LIZMAN
case LIZMANJUMP
case LIZMANSPITTING
addvar A LIZVAL
break

case LIZMANSTAYPUT
addvar A LIZVAL
addvar A 100
break

case ROTATEGUN
addvar A TURRVAL
break

case BOSS1
case BOSS1STAYPUT
case BOSS2
case BOSS3
case BOSS4
case BOSS4STAYPUT
ifvare sprite[spriteid].pal 0 addvar A BOSSVAL else
addvar A BOSSPALVAL
break

case SHARK
case FIRE
case FIRE2
addvar A 10 break

case RECON
case RECONDP
addvar A RECONVAL
break

// case SEENINE
// addvar A 15
// break

case NATURALLIGHTNING
addvar A 200
break

endswitch

ends

onevent EVENT_LOADACTOR

ifvare DONE NO
{
	setvar savehack NO
	setvar newvolume -1
	setvar GMCHECK 0 // redundant safety measures
	// 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
    
	state redefinequotes
	ifvare mirroroption YES
	ifrnd 128
	{
		setvar mirrored YES
		state mirror
	}
	else
	setvar mirrored NO
 	
	state setweather
	setvar spriteid 0
	whilevarvarn spriteid NUMSECTORS
	{
		ifvare sector[spriteid].lotag 2
		{
			ifvarl sector[spriteid].floorpal 2
			{
				setsector[spriteid].floorpal 140
				setsector[spriteid].ceilingpal 140
			}
			else
			ifvare sector[spriteid].floorpal 2
			{
				// setsector[spriteid].floorpal 27
				setsector[spriteid].ceilingpal 130
			}
			else
			ifvarg sector[spriteid].floorpal 6
			ifvarl sector[spriteid].floorpal 9
			{
				setsector[spriteid].floorpal 131
				setsector[spriteid].ceilingpal 131
			}
		}
		addvar spriteid 1
	}
	// make mirrors indestructible
	setvar spriteid 0
	whilevarvarn spriteid NUMWALLS
	{
		getwall[spriteid].picnum picnum
		ifvare picnum MIRROR setwall[spriteid].pal 4 
		getwall[spriteid].overpicnum picnum
		ifvare picnum MIRROR setwall[spriteid].pal 4
		addvar spriteid 1
	}
	ifmultiplayer nullop else
	ifvarn rendmode 4
	{
		setvar spriteid 0
		setvar B 0
		whilevarn spriteid 16384
		{
			ifvare sprite[spriteid].statnum 1024 { setvarvar B spriteid setvar spriteid 16383 }
			addvar spriteid 1
		}
		setvar A 0
		whilevarvarn A NUMSECTORS
		{
			ifvare sector[A].floorpicnum 803
			ifvare sector[A].floorpal 0
			state spawngrass 
			else
			{
				getsector[A].ceilingstat temp
				ifvarand temp 1
				{
					getsector[A].floorpicnum picnum
					switch picnum 
						// case 803
						case 1219
						ifvare sector[A].floorpal 0
						state spawngrass
						break
						case 3416
						case 241
						ifvare sector[A].floorpal 6
						state spawngrass
						break
						
						default break
					endswitch
				}
			}
			addvar A 1
			ifvarg grasscount 6000 setvarvar A NUMSECTORS // failsafe
			
		}
		addlogvar grasscount
		setvar grasscount 0

	}
	ifvarn VOLUME 6
	{
		// next we assess the difficulty of the level
		// add up all the base monster values, multiply by 10, then divide by the value of the items
		setvar A 0 // total monster values
		setvar B 0 // total item values
		setvar C 0 // diminishing marginal utility
		setvar maprating 0 // overall difficulty rating
		setvar spriteid 0
		whilevarn spriteid 16384
		{
			ifvarn sprite[spriteid].statnum 1024
			{
				getactor[spriteid].picnum picnum
				ifvare picnum RESPAWN getactor[spriteid].hitag picnum else
				ifvare picnum CANWITHSOMETHING getactor[spriteid].lotag picnum else
				ifvare picnum CANWITHSOMETHING2 getactor[spriteid].lotag picnum else
				ifvare picnum CANWITHSOMETHING3 getactor[spriteid].lotag picnum else
				ifvare picnum CANWITHSOMETHING4 getactor[spriteid].lotag picnum
				state assessvalue
			}
			addvar spriteid 1
		}

	
		setvarvar maprating A
		mulvar maprating 1000
		divvarvar maprating B
		addlogvar maprating // map rating is now determined
		
		// determine adjusted randomize value based on rawrandomize and maprating
		setvarvar D maprating
		subvar D 600
		ifvarl D 0 mulvar D -1
		setvarvar temp rawrandomize
		mulvarvar temp D
		sqrt temp tempb
		setvarvar randomize rawrandomize
		ifvarg maprating 600 subvarvar randomize tempb else addvarvar randomize tempb
		ifvarl randomize 1000 setvar randomize 1000
		addlogvar randomize
	}
	else
	{
		setvar maprating 600
		setvar totalspawners 0
		setvar spriteid 0
		whilevarn spriteid 200
		{
			setarray mspawners[spriteid] -1
			addvar spriteid 1
		}
	}
	
	setvar DONE YES
}

getactor[THISACTOR].pal pal
getactor[THISACTOR].picnum picnum

switch picnum

case MSPAWNER
addvar totalspawners 1
cstat 32768
setvar spriteid 0
whilevarn spriteid 200
{
	ifvare mspawners[spriteid] -1
	{
		setarray mspawners[spriteid] THISACTOR
		setvar spriteid 200
	}
	else addvar spriteid 1
}

break

case HYDROPLANT
cactor DPHYDROPLANT
state nocodecheck2
setvar bouncesound GENERICBOUNCE
break

case RECON
case RECONDP
ifvare VOLUME 6 killit else
state eventloadactorstate
break


case EGG
case LIZTROOP
case LIZTROOPSTAYPUT
case LIZTROOPSHOOT
case LIZTROOPJETPACK
case LIZTROOPRUNNING
case LIZTROOPONTOILET
case LIZTROOPJUSTSIT
case LIZTROOPDUCKING
case OCTABRAIN
case OCTABRAINSTAYPUT
case DRONE
case COMMANDER
case COMMANDERSTAYPUT
case TANK
case MECH2
case PIGCOP
case PIGCOPSTAYPUT
case PIGCOPDIVE
case LIZMAN
case LIZMANSTAYPUT
case LIZMANJUMP
case LIZMANSPITTING
case ROTATEGUN
case BOSS1
case BOSS1STAYPUT
case BOSS2
case BOSS3
case BOSS4
case BOSS4STAYPUT
case SHARK
// case MINIBEAST
// case FEM1
// case FEM2
// case FEM3
// case FEM4
// case FEM5
// case FEM6
// case FEM7
// case FEM8
// case FEM9
// case FEM10
// case TOUGHGAL
// case NAKED1
// case PODFEM1
// case BLOODYPOLE
// case FEM6PAD

ifvare VOLUME 6 killit else
{
	state nocodecheck1
	state eventloadactorstate 
	getactor[THISACTOR].owner temp
	ifvare temp 1
	{
		getactor[THISACTOR].sectnum temp
		setactor[THISACTOR].htactorstayput temp
	}
}
break

case COLA
case SIXPAK
case ATOMICHEALTH
case HEAVYHBOMB
case AMMO
case SHOTGUNAMMO
case BATTERYAMMO
case RPGAMMO
case HBOMBAMMO
case CRYSTALAMMO
case DEVISTATORAMMO
case FREEZEAMMO
case TRIPBOMBSPRITE
case GROWAMMO
case SHIELD
case FIRSTGUNSPRITE
case SHOTGUNSPRITE
case CHAINGUNSPRITE
case RPGSPRITE
case SHRINKERSPRITE
case DEVISTATORSPRITE
case FREEZESPRITE
case GROWSPRITEICON
case FIRSTAID
case BOOTS
case HOLODUKE
case HEATSENSOR
case JETPACK
case AIRTANK
case STEROIDS
ifvare VOLUME 6
spritepal 0
break

case RESPAWN
getactor[THISACTOR].extra temp
ifvarn temp -1 setvarvar monstflags temp
getactor[THISACTOR].xvel droptile
getactor[THISACTOR].owner temp
ifvare temp 1
	getactor[THISACTOR].sectnum mysector
break

case GREENSLIME
setvar mval 10
break

case NUKEBUTTON
ifvarn sprite[THISACTOR].pal 0
ifvarn sprite[THISACTOR].lotag 0
{
	setactor[THISACTOR].lotag 32767
	spritepal 0
}
break

case NEWBEAST
case NEWBEASTSTAYPUT
case NEWBEASTHANG
case NEWBEASTJUMP
sizeat 40 40
ifvare VOLUME 6 killit else
{
	state nocodecheck1
	state eventloadactorstate
}
break

case DIPSWITCH
case DIPSWITCH2
case DIPSWITCH3
case TECHSWITCH
case ALIENSWITCH
case FRANKENSTINESWITCH
case 163 case 165 case 167 case 169
case 1143 case 141
ifvarn sprite[THISACTOR].lotag 0
{
	getactor[THISACTOR].htflags temp
	orvar temp 64
	setactor[THISACTOR].htflags temp
}

	state nocodecheck1
break

case 6324 // DBSHOTGUN from DP
cactor SHOTGUNSPRITE
break

default
	state nocodecheck1
break
endswitch


endevent