
state autosave

ifvare VOLUME 6 break
ifphealthl 50 nullop else
ifp ponground
{
	save 9
	userquote 1058
	setvarvar lastspeechtime timer
}

ends

state changeakimbo

ifvarl akimbo 1
{
	setvar akimbo 9 // countdown timer for moving guns into correct position
	setvar WEAPON1_CLIP 24
	setvar WEAPON1_RELOAD 48
	setvar WEAPON1_FIREDELAY 2
	setvar WEAPON1_TOTALTIME 8
	setvar WEAPON1_FLAGS 68
	setvar WEAPON1_SPAWNTIME 2
	setvar WEAPON1_SPAWN 2533
	setvar WEAPON1_INITIALSOUND 0
	setvar WEAPON1_SOUND2TIME 0
	setvar WEAPON1_SOUND2SOUND 0
	setvar WEAPON1_RELOADSOUND1 4
	setvar WEAPON1_RELOADSOUND2 5
	ifvarn botclip 0
	{
		getplayer[THISACTOR].ammo_amount 1 tempb
		mulvar botclip 2
		ifvarvarg botclip tempb setvarvar botclip tempb
		// this code does nothing if the state is called from FIRSTGUNSPRITE, but that's ok
	}
}
else
{
	setvar akimbo -9
	setvar WEAPON1_CLIP 12
	setvar WEAPON1_RELOAD 27
	setvar WEAPON1_FIREDELAY 2
	setvar WEAPON1_TOTALTIME 6
	setvar WEAPON1_FLAGS 4
	setvar WEAPON1_SPAWNTIME 2
	setvar WEAPON1_SPAWN 2533
	setvar WEAPON1_INITIALSOUND 0
	setvar WEAPON1_SOUND2TIME 0
	setvar WEAPON1_SOUND2SOUND 0
	setvar WEAPON1_RELOADSOUND1 4
	setvar WEAPON1_RELOADSOUND2 5
	ifvarn botclip 0 ifvarg timer 1
	{
		setvarvar temp botclip
		divvar botclip 2
	}
		
		
}

ends

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

state savestatus

setvarvar savgogglevel gogglevel
setvarvar savbotlevel botlevel
setvarvar savsteroidlevel steroidlevel
setvarvar savnukes nukes
setvarvar savnukelevel nukelevel
setvarvar savmaxmedkit maxmedkit
getplayer[THISACTOR].holoduke_amount savholoduke_amount
getplayer[THISACTOR].firstaid_amount savfirstaid_amount
getplayer[THISACTOR].heat_amount savheat_amount
getplayer[THISACTOR].scuba_amount savscuba_amount
getplayer[THISACTOR].shield_amount savshield_amount
getplayer[THISACTOR].holoduke_amount savholoduke_amount
getplayer[THISACTOR].steroids_amount savsteroids_amount
getplayer[THISACTOR].boot_amount savboot_amount
getplayer[THISACTOR].max_player_health savmaxplayerhealth
getplayer[THISACTOR].max_shield_amount savmaxshield

getplayer[THISACTOR].max_ammo_amount 1 savmaxammo1
getplayer[THISACTOR].max_ammo_amount 2 savmaxammo2
getplayer[THISACTOR].max_ammo_amount 3 savmaxammo3
getplayer[THISACTOR].max_ammo_amount 4 savmaxammo4
getplayer[THISACTOR].max_ammo_amount 5 savmaxammo5
getplayer[THISACTOR].max_ammo_amount 6 savmaxammo6
getplayer[THISACTOR].max_ammo_amount 7 savmaxammo7
getplayer[THISACTOR].max_ammo_amount 8 savmaxammo8
getplayer[THISACTOR].max_ammo_amount 9 savmaxammo9
getplayer[THISACTOR].max_ammo_amount 11 savmaxammo11

setvarvar savweapxp0 weapxp0
setvarvar savweapxp1 weapxp1
setvarvar savweapxp2 weapxp2
setvarvar savweapxp3 weapxp3
setvarvar savweapxp4 weapxp4
setvarvar savweapxp5 weapxp5
setvarvar savweapxp6 weapxp6
setvarvar savweapxp7 weapxp7
setvarvar savweapxp8 weapxp8
setvarvar savweapxp9 weapxp9
setvarvar savweapxp10 weapxp10
setvarvar savweapxp11 weapxp11
setvarvar savscore score
setvarvar savrand randomize
setvarvar savrawrand rawrandomize

setvarvar savweaptotal weaptotal

setvarvar savweaplev0 weaplev0
setvarvar savweaplev1 weaplev1
setvarvar savweaplev2 weaplev2
setvarvar savweaplev3 weaplev3
setvarvar savweaplev4 weaplev4
setvarvar savweaplev5 weaplev5
setvarvar savweaplev6 weaplev6
setvarvar savweaplev7 weaplev7
setvarvar savweaplev8 weaplev8
setvarvar savweaplev9 weaplev9
setvarvar savweaplev10 weaplev10
setvarvar savweaplev11 weaplev11

setvarvar savweapup0 weapup0
setvarvar savweapup1 weapup1
setvarvar savweapup2 weapup2
setvarvar savweapup3 weapup3
setvarvar savweapup4 weapup4
setvarvar savweapup5 weapup5
setvarvar savweapup6 weapup6
setvarvar savweapup7 weapup7
setvarvar savweapup8 weapup8
setvarvar savweapup9 weapup9
setvarvar savweapup10 weapup10
setvarvar savweapup11 weapup11

ends

// state savescore

// ifvare scoresaved YES break

// // atthighscores 60
// // elements 0-9 are scores for episode 1
// // elements 10-19 are scores for episode 2
// // etc.

// // set I to the part of array corresponding to the top score of the episode
// setvarvar I VOLUME
// mulvar I 10
// setvarvar K I
// addvar K 10
// setvar J 0

// whilevarn J 10
// {
// 	ifvarvare gameid attgameids[I]
// 	{
// 		// copy the lower scores up
// 		setvarvar A I
// 		addvar A 1
// 		whilevarvarn A K
// 		{
// 			setarray atthighscores[I] atthighscores[A]
// 			setarray attgameids[I] attgameids[A]
// 			addvar I 1
// 			addvar A 1
// 		}
// 		setvar J 9
// 		setarray atthighscores[K] 0
// 		setarray attgameids[K] -1
// 	}
// 	addvar J 1
// 	addvar I 1
// }

// setvarvar I VOLUME
// mulvar I 10
// setvarvar K I
// addvar K 9
// setvar J 0
// setvar C 0 // save flag

// whilevarn J 10
// {
// 	ifvarvarg score atthighscores[I]
// 	{
// 		setvar C YES
// 		readarrayfromfile atthighscores 1068
// 		ifvare J 9 
// 		{
// 			setarray atthighscores[I] score
// 			setarray attgameids[I] gameid
// 		}
// 		else
// 		{
// 			setvarvar B K
// 			setvarvar A K
// 			subvar A 1
// 			whilevarvarn B I
// 			{
// 				setarray atthighscores[B] atthighscores[A]
// 				setarray attgameids[B] attgameids[A]
// 				subvar A 1
// 				subvar B 1
// 			}
// 			setarray atthighscores[I] score
// 			setarray attgameids[I] gameid
// 			setvar J 9
// 		}
// 	}
// 	addvar J 1
// 	addvar I 1
// }



// ifvare C YES
// {
// 	resizearray atthighscores 60
// 	writearraytofile atthighscores 1068
// 	setvar scoresaved YES
// }

// ends

state savescore

ifvare scoresaved YES break

// atthighscores 60

// set I to the part of array corresponding to the top score of the episode
setvar I 0
setvar K 30
setvar J 0

readarrayfromfile atthighscores 1068
readarrayfromfile attgameids 1132
whilevarn J 30
{
	ifvarvare gameid attgameids[I]
	{
		// copy the lower scores up
		setvarvar A I
 		addvar A 1
		whilevarvarn A K
		{
			setarray atthighscores[I] atthighscores[A]
			setarray attgameids[I] attgameids[A]
			addvar I 1
			addvar A 1
		}
		setvar J 29
		setarray atthighscores[J] 0
		setarray attgameids[J] 0
	}
	addvar J 1
	addvar I 1
}

setvar I 0
setvar K 29
setvar J 0
setvar C 0 // save flag

whilevarn J 30
{
	ifvarvarg score atthighscores[I]
	{
		setvar C YES
		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
		}
		ifvare J 29 
		{
			setarray atthighscores[I] score
			setarray attgameids[I] gameid
		}
		else
		{
			setvarvar B K
			setvarvar A K
			subvar A 1
			whilevarvarn B I
			{
				setarray atthighscores[B] atthighscores[A]
				setarray attgameids[B] attgameids[A]
				subvar A 1
				subvar B 1
			}
			setarray atthighscores[I] score
			setarray attgameids[I] gameid
			setvar J 29
		}
	}
	addvar J 1
	addvar I 1
}

ifvare C YES
{
	resizearray atthighscores 60
	writearraytofile atthighscores 1068
	writearraytofile attgameids 1132
	setvar scoresaved YES
}

ends

state restorestatus

setvar menutoggle 0
setvar rage FULLRAGE
state normaldev
setvarvar gogglevel savgogglevel
setvarvar botlevel savbotlevel
setvarvar steroidlevel savsteroidlevel
setvarvar maxmedkit savmaxmedkit
setvarvar nukes savnukes
setvarvar nukelevel savnukelevel
setplayer[THISACTOR].holoduke_amount savholoduke_amount
setplayer[THISACTOR].firstaid_amount savfirstaid_amount
setplayer[THISACTOR].heat_amount savheat_amount
setplayer[THISACTOR].scuba_amount savscuba_amount
setplayer[THISACTOR].shield_amount savshield_amount
setplayer[THISACTOR].holoduke_amount savholoduke_amount
setplayer[THISACTOR].steroids_amount savsteroids_amount
setplayer[THISACTOR].boot_amount savboot_amount
setplayer[THISACTOR].max_player_health savmaxplayerhealth
setplayer[THISACTOR].max_shield_amount savmaxshield

setplayer[THISACTOR].max_ammo_amount 1 savmaxammo1
setplayer[THISACTOR].max_ammo_amount 2 savmaxammo2
setplayer[THISACTOR].max_ammo_amount 3 savmaxammo3
setplayer[THISACTOR].max_ammo_amount 4 savmaxammo4
setplayer[THISACTOR].max_ammo_amount 5 savmaxammo5
setplayer[THISACTOR].max_ammo_amount 6 savmaxammo6
setplayer[THISACTOR].max_ammo_amount 7 savmaxammo7
setplayer[THISACTOR].max_ammo_amount 8 savmaxammo8
setplayer[THISACTOR].max_ammo_amount 9 savmaxammo9
setplayer[THISACTOR].max_ammo_amount 11 savmaxammo11

setvarvar weapxp0 savweapxp0
setvarvar weapxp1 savweapxp1
setvarvar weapxp2 savweapxp2
setvarvar weapxp3 savweapxp3
setvarvar weapxp4 savweapxp4
setvarvar weapxp5 savweapxp5
setvarvar weapxp6 savweapxp6
setvarvar weapxp7 savweapxp7
setvarvar weapxp8 savweapxp8
setvarvar weapxp9 savweapxp9
setvarvar weapxp10 savweapxp10
setvarvar weapxp11 savweapxp11
setvarvar score savscore
setvarvar randomize savrand
setvarvar rawrandomize savrawrand
setvar scoresaved NO

setvarvar weaptotal savweaptotal

setvarvar weaplev0 savweaplev0
setvarvar weaplev1 savweaplev1
setvarvar weaplev2 savweaplev2
setvarvar weaplev3 savweaplev3
setvarvar weaplev4 savweaplev4
setvarvar weaplev5 savweaplev5
setvarvar weaplev6 savweaplev6
setvarvar weaplev7 savweaplev7
setvarvar weaplev8 savweaplev8
setvarvar weaplev9 savweaplev9
setvarvar weaplev10 savweaplev10
setvarvar weaplev11 savweaplev11

setvarvar weapup0 savweapup0
setvarvar weapup1 savweapup1
setvarvar weapup2 savweapup2
setvarvar weapup3 savweapup3
setvarvar weapup4 savweapup4
setvarvar weapup5 savweapup5
setvarvar weapup6 savweapup6
setvarvar weapup7 savweapup7
setvarvar weapup8 savweapup8
setvarvar weapup9 savweapup9
setvarvar weapup10 savweapup10
setvarvar weapup11 savweapup11

ifvarl weaplev1 1 setvar WEAPON1_TOTALTIME 7
ifvare useakimbo YES ifvarl weaplev1 3
{
	setvar akimbo 1
	state changeakimbo
	setvar useakimbo NO 
	setvar akimbo -1
}
ifvarl weaplev1 2 setvar WEAPON1_FIRESOUND PISTOL3 else
ifvarl weaplev1 5 setvar WEAPON1_FIRESOUND DPPISTOLFIRE else
setvar WEAPON1_FIRESOUND STRONGPISTOL
ifvarl weaplev2 3 setvar WEAPON2_SHOTSPERBURST 7 else
ifvarl weaplev2 5 setvar WEAPON2_SHOTSPERBURST 8 else
ifvarl weaplev2 6 setvar WEAPON2_SHOTSPERBURST 9 else
setvar WEAPON2_SHOTSPERBURST 10

ifvarl weaplev3 5 setvar WEAPON3_FLAGS 73812
ifvarl weaplev4 1 setvar WEAPON4_TOTALTIME 26
ifvarl weaplev4 2 setvar WEAPON4_FIRESOUND RPG_SHOOT else
setvar WEAPON4_FIRESOUND ROCKETFIRE
ifvarl weaplev6 5 setprojectile[SHRINKRADIUSPROJ].HITRADIUS 2048

ifvarl weaplev9 5 setprojectile[ICEBEAM].extra 34
ifvarl weaplev10 6 setprojectile[POWBEAM].extra 32
ifvarl weaplev11 1 setvar WEAPON11_SHOTSPERBURST 0 else
ifvarl weaplev11 3 setvar WEAPON11_SHOTSPERBURST 2 else
setvar WEAPON11_SHOTSPERBURST 3

ends

gamevar savehack 0 0

state startrandomlevel

setvar temp 0
ifvare truevolume 3 setvar temp 1 else
ifvarl truelevel VOL1LEVELS setvar temp 1 // requisite number of levels not completed yet
ifvare temp 1
{
	setvarvar tempb LEVEL
	ifvarn menutoggle 5 // do not subtract 1 if this is the abort mission option
	subvar tempb 1 // the level just completed
	setvar tempc 1
	whilevarn tempb 0 // generate bit from level number
	{
		shiftvarl tempc 1
		subvar tempb 1
	}
	// add bit to list of completed levels
	ifvare VOLUME 0 { orvarvar completed tempc orvarvar recentmaps tempc savegamevar recentmaps } else
	ifvare VOLUME 1 { orvarvar completed2 tempc orvarvar recentmaps2 tempc savegamevar recentmaps2 } else
	ifvare VOLUME 2 { orvarvar completed3 tempc orvarvar recentmaps3 tempc savegamevar recentmaps3 } else
	ifvare VOLUME 3 { orvarvar completed4 tempc orvarvar recentmaps4 tempc savegamevar recentmaps4 }
	setvar tempb 1
	randvar newvolume 3 // the VOLUME number of next map to be chosen
	setvar M 0
	whilevarn tempb 0
	{
		ifvare truevolume 3 randvar newlevel 30 else
		randvar newlevel VOL1MAPS // pick a new level number
		addvar newlevel 1 // to avoid loading start.map
		setvarvar tempc newlevel
		setvar tempd 1
		whilevarn tempc 0
		{
			shiftvarl tempd 1
			subvar tempc 1
		}
		// avoid recently played maps, even if played in prior games
		ifvare newvolume 0 setvarvar K recentmaps else
		ifvare newvolume 1 setvarvar K recentmaps2 else
		ifvare newvolume 2 setvarvar K recentmaps3 else
		setvarvar K recentmaps4
		ifvarvarand K tempd nullop else
		{
			ifvare newvolume 0 setvarvar K completed else
			ifvare newvolume 1 setvarvar K completed2 else
			ifvare newvolume 2 setvarvar K completed3 else
			setvarvar K completed4
			ifvarvarand K tempd nullop // ths level has been completed already
			else
			setvar tempb 0
		}
		addvar M 1
		ifvarg M 999 
		{ 
			setvar M 0 setvar recentmaps 0 setvar recentmaps2 0 setvar recentmaps3 0 setvar recentmaps4 0 
			ifvare truevolume 3
			{
				ifvare VOLUME 0 setvar completed 0 else
				ifvare VOLUME 1 setvar completed2 0 else
				ifvare VOLUME 2 setvar completed3 0 else
				setvar completed4 0
			}
		} // failsafe
	}
	startlevel newvolume newlevel
	
}

ends

state resetammo

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

setvar botclip 0
setvar MINIGUNAMMO 0
ifvarand ALTCHAINGUN 2
{
	xorvar ALTCHAINGUN 2
	setvar WEAPON3_SHOTSPERBURST 0
	setvar WEAPON3_FIREDELAY 3
	ifvare dpsounds YES
	setvar WEAPON3_FIRESOUND DPCHAINGUNFIRE else
	setvar WEAPON3_FIRESOUND CHAINGUN_FIRE
	setvar WEAPON3_SHOOTS CHAINGUN
	setvar WEAPON3_TOTALTIME 12
	ifvarg weaplev3 4 setvar WEAPON3_FLAGS 73804 else
	setvar WEAPON3_FLAGS 73812
	setvar WEAPON3_CLIP 0
	setvar WEAPON3_SPAWNTIME 0
	setvar WEAPON3_RELOADSOUND1 4
	setvar WEAPON3_RELOADSOUND2 5
}


shiftvarl LASERAMMO 1
addvarvar score LASERAMMO
setvar LASERAMMO 0

getplayer[THISACTOR].ammo_amount 1 tempb
addvarvar score tempb
setplayer[THISACTOR].ammo_amount 1 48
setplayer[THISACTOR].curr_weapon 1

getplayer[THISACTOR].ammo_amount 2 tempb
shiftvarl tempb 1
addvarvar score tempb
setplayer[THISACTOR].ammo_amount 2 0

getplayer[THISACTOR].ammo_amount 3 tempb
addvarvar score tempb
setplayer[THISACTOR].ammo_amount 3 0

getplayer[THISACTOR].ammo_amount 4 tempb
shiftvarl tempb 3
addvarvar score tempb
setplayer[THISACTOR].ammo_amount 4 0

getplayer[THISACTOR].ammo_amount 5 tempb
shiftvarl tempb 3
addvarvar score tempb
setplayer[THISACTOR].ammo_amount 5 0

getplayer[THISACTOR].ammo_amount 6 tempb
shiftvarl tempb 3
addvarvar score tempb
setplayer[THISACTOR].ammo_amount 6 0

getplayer[THISACTOR].ammo_amount 7 tempb
shiftvarl tempb 2
addvarvar score tempb
setplayer[THISACTOR].ammo_amount 7 0

getplayer[THISACTOR].ammo_amount 8 tempb
shiftvarl tempb 4
addvarvar score tempb
setplayer[THISACTOR].ammo_amount 8 0

getplayer[THISACTOR].ammo_amount 9 tempb
shiftvarl tempb 2
addvarvar score tempb
setplayer[THISACTOR].ammo_amount 9 0

getplayer[THISACTOR].ammo_amount 11 tempb
shiftvarl tempb 2
addvarvar score tempb
setplayer[THISACTOR].ammo_amount 11 0

setplayer[THISACTOR].gotweapon 2 0
setplayer[THISACTOR].gotweapon 3 0
setplayer[THISACTOR].gotweapon 4 0
setplayer[THISACTOR].gotweapon 5 0
setplayer[THISACTOR].gotweapon 6 0
setplayer[THISACTOR].gotweapon 7 0
setplayer[THISACTOR].gotweapon 8 0
setplayer[THISACTOR].gotweapon 9 0
setplayer[THISACTOR].gotweapon 11 0
setvar ALTCHAINGUN 0
setplayer[THISACTOR].jetpack_amount 0
ends

onevent EVENT_DISPLAYBONUSSCREEN

ifvare savehack NO
{
	setvar savehack YES
	state savestatus
	ifvarl VOLUME 4 state resetammo else
	ifvare VOLUME 6 state resetammo
}

	ifvare newvolume -1
	ifvarl VOLUME 4
	ifvarn firstmap 2
	{
		state startrandomlevel
	}

endevent

state jib_sounds

ifrnd SWEARFREQUENCY
{
  setplayer[THISACTOR].sound_pitch 0

  randvar temp 17
  switch temp
  case 0 globalsound JIBBED_ACTOR12 break
  case 1 globalsound JIBBED_ACTOR1 break
  case 2 globalsound JIBBED_ACTOR9 break
  case 3 globalsound JIBBED_ACTOR14 break
  case 4 globalsound SMACKED break
  case 5 globalsound JIBBED_ACTOR2 break
  case 6 globalsound MDEVSPEECH break
  case 7 globalsound JIBBED_ACTOR5 break
  case 8 globalsound JIBBED_ACTOR11 break
  case 9 globalsound JIBBED_ACTOR13 break
  case 10 globalsound JIBBED_ACTOR3 break
  case 11 globalsound JIBBED_ACTOR8 break
  case 12 globalsound JIBBED_ACTOR6 break
  case 13 globalsound JIBBED_ACTOR4 break
  case 14 globalsound JIBBED_ACTOR10 break
  case 15 globalsound JIBBED_ACTOR15 break
  case 16 globalsound JIBBED_ACTOR7 break
  case 17 globalsound YIPPEE1 break
  default break
  endswitch
}
ends

state dukepainsounds

ifphealthl YELLHURTSOUNDSTRENGTHMP
{
  ifrnd 64
    globalsound DUKE_LONGTERM_PAIN2
  else
    ifrnd 64
      globalsound DUKE_LONGTERM_PAIN3
  else
    ifrnd 64
      globalsound DUKE_LONGTERM_PAIN4
  else
    globalsound DUKE_DEAD
}
else
{
  ifrnd 64
    globalsound DUKE_LONGTERM_PAIN5
  else ifrnd 64
    globalsound DUKE_LONGTERM_PAIN6
  else ifrnd 64
    globalsound DUKE_LONGTERM_PAIN7
  else
    globalsound DUKE_LONGTERM_PAIN8
}
ends

state imonfire

	subvar burning 1
	ifvarg burning 2048 setvar burning 2048
	
	ifactor APLAYER
	{
		getplayer[THISACTOR].boot_amount temp
		ifvarg temp 0
		{
			subvar temp 1
			setplayer[THISACTOR].boot_amount temp
			subvar burning 3
			ifvarl burning 0 setvar burning 0
		}
		getplayer[THISACTOR].shield_amount temp
		ifvarg temp 0
		{
			subvar temp 1
			setplayer[THISACTOR].shield_amount temp
			subvar burning 2
			ifvarl burning 0 setvar burning 0
		}
	}
	
	ifinwater setvar burning 0
	ifonwater ifvarg burning 1 subvar burning 1
	ifvarl sprite[THISACTOR].htextra 1
	ifvarand timer 1
	{
		ifactor APLAYER ifrnd 128 state dukepainsounds
		
		setvarvar temp burning
		shiftvarr temp 7
		ifvarg temp 8 setvar temp 8
		ifactor APLAYER ifvarg temp 4 setvar temp 4
		ifvarl temp 1 setvar temp 1
		subvarvar burning temp
		ifvarl burning 0 setvar burning 0
		ifvarg temp 0
		{
			setactor[THISACTOR].htextra temp
			setactor[THISACTOR].htpicnum BURNING
			setactor[THISACTOR].htowner player[THISACTOR].i
			addvar temp 1
			ifvarvarl sprite[THISACTOR].extra temp
			{
				getactor[THISACTOR].htflags temp
				orvar temp 4
				setactor[THISACTOR].htflags temp
				getsector[THISACTOR].floorshade shade
				addvar shade 12 ifvarg shade 30 setvar shade 30
				setactor[THISACTOR].shade shade
			}
		}
		
	}

	getactor[THISACTOR].picnum tempc
	espawn STICKYFIRE
	setactorvar[RETURN].monstatus tempc
	setactorvar[RETURN].myspawner THISACTOR
	espawn STICKYFIRE
	setactorvar[RETURN].monstatus tempc
	setactorvar[RETURN].myspawner THISACTOR
	ifvarg burning 260
	{
		espawn STICKYFIRE
		setactorvar[RETURN].monstatus tempc
		setactorvar[RETURN].myspawner THISACTOR
	}
	ifvarn monstatus 0
		soundonce COOKINGDEEPFRIER
	
ends

state pigheadshoot
  randvar angvar 2048
  setactor[THISACTOR].ang angvar
  randvar zdist 4096
  mulvar zdist -1
  ezshoot zdist PIGHEAD
  setthisprojectile[RETURN].pal pal
 ends

state piguppershoot
  randvar angvar 2048
  setactor[THISACTOR].ang angvar
  randvar zdist 4096
  mulvar zdist -1
  ezshoot zdist PIGUPPER
  setthisprojectile[RETURN].pal pal
  randvar angvar 2048
  setactor[THISACTOR].ang angvar
  randvar zdist 4096
  mulvar zdist -1
  ezshoot zdist PIGUPPER2
  setthisprojectile[RETURN].pal pal
 ends

state piglowershoot
  randvar angvar 2048
  setactor[THISACTOR].ang angvar
  randvar zdist 4096
  mulvar zdist -1
  ezshoot zdist PIGLOWER
  setthisprojectile[RETURN].pal pal
  randvar angvar 2048
  setactor[THISACTOR].ang angvar
  randvar zdist 4096
  mulvar zdist -1
  ezshoot zdist PIGLOWER2
  setthisprojectile[RETURN].pal pal
 ends

state pig_body_jibs

 getactor[THISACTOR].pal pal
  
 getactor[THISACTOR].z z
 subvar z 9216
 setactor[THISACTOR].z z
 state pigheadshoot

 addvar z 2048
 setactor[THISACTOR].z z
 state piguppershoot

 addvar z 4096
 setactor[THISACTOR].z z
 state piglowershoot

ends


action FEMANIMATE

action ANULLACTION 0
action JIBSPROJFRAME1 -1 1 1 1 8
action JIBSPROJFRAME2 0 1 1 1 8
action JIBSPROJFRAME3 1 1 1 1 8
action JIBSPROJFRAME4 2 1 1 1 8

actor JIBSPROJ1 0 JIBSPROJFRAME2 enda
actor JIBSPROJ2 0 JIBSPROJFRAME2 enda
actor JIBSPROJ3 0 JIBSPROJFRAME2 enda
actor JIBSPROJ4 0 JIBSPROJFRAME2 enda
actor JIBSPROJ5 0 JIBSPROJFRAME2 enda
actor LIZMANHEADPROJ 0 JIBSPROJFRAME2 enda
actor LIZMANARMPROJ 0 JIBSPROJFRAME2 enda
actor LIZMANLEGPROJ 0 JIBSPROJFRAME2 enda
actor TROOPHEADPROJ 0 JIBSPROJFRAME2 enda
actor TROOPARMPROJ 0 JIBSPROJFRAME2 enda
actor TROOPLEGPROJ 0 JIBSPROJFRAME2 enda


// state randsquishsound

// randvar temp 3
// switch temp
// case 0 setvar tempc SQUISHED break
// case 1 setvar tempc NEWGIB1 break
// case 2 setvar tempc NEWGIB3 break
// case 3 setvar tempc NEWGIB4 break
// endswitch
// espawn SOUNDMAKER
// setactorvar[RETURN].peractor1 tempc

// ends

state aimjib

randvar xvel 64
addvar xvel 32
randvar zdist 512
addvar zdist 512
mulvar zdist -1

setvarvar tempc bleeding
ifvarl tempc 96 setvar tempc 96
ifvarg tempc 200
{
	subvar tempc 200
	shiftvarr tempc 1
	addvar tempc 200
}
ifvare weap SHOTSPARK1 shiftvarr tempc 1

randvar tempb 48
addvar tempb 16
mulvarvar tempb tempc
shiftvarr tempb 1
subvarvar zdist tempb

randvar tempb 96
addvar tempb 32
mulvarvar tempc tempb
shiftvarr tempc 6
addvarvar xvel tempc


ends

state setjib

getactor[THISACTOR].pal pal
ifvarg pal 9 setvar pal 0
ifvarl burning 0
setthisprojectile[RETURN].pal 1 else
setthisprojectile[RETURN].pal pal
setactor[RETURN].xvel xvel


randvar angvar 2047
setactor[RETURN].ang angvar
getactor[THISACTOR].xrepeat x
getactor[THISACTOR].yrepeat y
ifvare sprite[RETURN].picnum JIBSPROJ2 // eyeball
{
	shiftvarr x 1
	shiftvarr y 1
}
setthisprojectile[RETURN].xrepeat x
setthisprojectile[RETURN].yrepeat y
setactor[RETURN].xrepeat x
setactor[RETURN].yrepeat y
ifrnd 128
{
	setactor[RETURN].cstat 132
	setthisprojectile[RETURN].cstat 132
}

randvar temp 96
ifrnd 128 mulvar temp -1
setactorvar[RETURN].peractor1 temp

ifactor EGG setthisprojectile[RETURN].trail -1
ifaction FEMANIMATE setactorvar[RETURN].countvarb 12

ends

state standard_jibs

ifactor EGG spritepal 6
guts JIBS6 6


state aimjib
ezshoot zdist JIBSPROJ2
state setjib
state aimjib
ezshoot zdist JIBSPROJ2
state setjib
state aimjib
ezshoot zdist JIBSPROJ3
state setjib
state aimjib
ezshoot zdist JIBSPROJ3
state setjib
state aimjib
ezshoot zdist JIBSPROJ3
state setjib
state aimjib
ezshoot zdist JIBSPROJ3
state setjib
state aimjib
ezshoot zdist JIBSPROJ4
state setjib
state aimjib
ezshoot zdist JIBSPROJ4
state setjib
state aimjib
ezshoot zdist JIBSPROJ4
state setjib

ifactor EGG break

state aimjib
ezshoot zdist JIBSPROJ5
state setjib
state aimjib
ezshoot zdist JIBSPROJ5
state setjib
state aimjib
ezshoot zdist JIBSPROJ1
state setjib

ifspritepal 6 nullop else
spawn BLOODPOOL

state jib_sounds

ifvarn rendmode 0
{
	ifactor PIGCOP state pig_body_jibs else
	ifactor PIGCOPDIVE state pig_body_jibs
}

   
   
ends

state standard_pjibs

state aimjib
ezshoot zdist JIBSPROJ1
state setjib

 state aimjib
ezshoot zdist JIBSPROJ3
state setjib
state aimjib
ezshoot zdist JIBSPROJ3
state setjib
state aimjib
ezshoot zdist JIBSPROJ4
state setjib

state aimjib
ezshoot zdist JIBSPROJ5
state setjib

//  guts JIBS6 2
  
  guts DUKETORSO 1
  guts DUKELEG 2
  guts DUKEGUN 1
  ifactor APLAYER money 1
ends

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

state headhitstate

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

// wackplayer

ends

state random_ooz
  ifrnd 128
    spawn OOZ2
  else
    spawn OOZ
ends

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

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

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

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

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

action PSKICKING 40 2 5 1 30

move PSTOPED
move PSHRINKING // used as a var only

action ALLYPGROW  75  1   1   1   10

move ALLYSTOP 0
ai AIBOTGROW ALLYPGROW ALLYSTOP geth

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

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

move TROOPWALKVELS 72
move TROOPWALKVELSBACK -72
move TROOPJETPACKVELS 64 -84
move TROOPJETDEADVELS 256 -144
move TROOPJETDEADFALL 96 -14
move TROOPJETPACKILLVELS 192 -38
move TROOPRUNVELS 108
move DONTGETUP
move SHRUNKVELS 32

ai AITROOPSEEKENEMY  ATROOPWALKING   TROOPWALKVELS seekplayer
ai AITROOPSEEKPLAYER ATROOPWALKING   TROOPWALKVELS seekplayer
ai AITROOPFLEEING  ATROOPWALKING   TROOPWALKVELS fleeenemy
ai AITROOPFLEEINGBACK ATROOPWALKINGBACK   TROOPWALKVELSBACK faceplayer
ai AITROOPDODGE    ATROOPRUNNING   TROOPRUNVELS  dodgebullet
ai AITROOPSHOOTING   ATROOPSHOOT   STOPPED  faceplayer
ai AITROOPDUCKING  ATROOPDUCK    STOPPED  faceplayer
ai AITROOPJETPACK  ATROOPJETPACK   TROOPJETPACKVELS seekplayer
ai AITROOPSHRUNK   ATROOPWALKING   SHRUNKVELS fleeenemy
ai AITROOPHIDE     ATROOPABOUTHIDE STOPPED faceplayer
ai AITROOPGROW     ATROOPGROW    DONTGETUP faceplayerslow
ai AITROOPMEDIC    ATROOPRUNNING TROOPRUNVELS  geth
ai AITROOPJETDEAD  ATROOPJETDEAD TROOPJETDEADVELS geth getv

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


move PIGWALKVELS 72
move PIGRUNVELS 108

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

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


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

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

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

move LIZWALKVEL 72
move LIZRUNVEL 192
move LIZJUMPVEL 184
move LIZWALKVELBACK -72
move LIZRUNVELBACK  -192
move LIZJUMPVELBACK -184

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

move BABYBEASTVEL 128
move NEWBEASTWALKVEL 182
move NEWBEASTRUNVEL 256
move NEWBEASTDASHVEL 480
move NEWBEASTJUMPVEL 264

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

action ANEWBEASTHANG      0  1  5

action ANEWBEASTHANGDEAD      -1  1  5

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

action ATANKSPIN   0 1 7 1 4
action ATANKSHOOTING 7 2 7 1 10
action ATANKWAIT 0 1 7 1 1
action ATANKDESTRUCT 0 1 7 1 1
action ATANKDEAD 0 1 7 1 1
// move TANKVEL horiz vert
move TANKFORWARD 100

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

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

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

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

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

ai AIBOSS3SEEKENEMY ABOSS3WALK BOSS3WALKVELS seekplayer
ai AIBOSS3RUNENEMY ABOSS3RUN BOSS3RUNVELS faceplayerslow
ai AIBOSS3LOBENEMY ABOSS3LOB STOPPED faceplayer
ai AIBOSS3DYING ABOSS3DYING STOPPED geth // faceplayer
ai AIBOSS3PALSHRINK ABOSS3WALK SHRUNKVELS furthestdir
ai AIBOSS3GROW BOSS3GROW STOPPED faceplayerslow


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

move PALBOSS2SHRUNKRUNVELS 32
move PALBOSS2RUNVELS 256
move BOSS2WALKVELS 192
move BOSS2RUNVELS 256
move BOSS2SPRINT 320
move BOSS2JUMPVELS 400 -100
move BOSS2FALL 400

ai AIBOSS2SEEKENEMY ABOSS2WALK BOSS2WALKVELS seekplayer
ai AIBOSS2RUNENEMY ABOSS2RUN BOSS2RUNVELS faceplayerslow
ai AIBOSS2SHOOTENEMY ABOSS2SHOOT STOPPED faceplayersmart
ai AIBOSS2LOBBED ABOSS2LOB STOPPED faceplayer
ai AIBOSS2DYING ABOSS2DYING STOPPED geth // faceplayer
ai AIBOSS2PALSHRINK ABOSS2WALK SHRUNKVELS furthestdir
ai AIBOSS2GROW BOSS2GROW STOPPED faceplayerslow
ai AIBOSS2JUMP ABOSS2JUMP BOSS2JUMPVELS jumptoplayer
ai BOSS2PAUSED ABOSS2LOB STOPPED geth

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

move BOSS4WALKVELS 128
move BOSS4RUNVELS 256

ai AIBOSS4LAYEGGS ABOSS4WALK BOSS4WALKVELS randomangle geth
ai AIBOSS4SHOOT ABOSS4ABOUTTOSHOOT STOPPED faceplayer
ai AIBOSS4DYING ABOSS4DYING STOPPED geth // faceplayer
ai AIBOSS4GROW BOSS4GROW STOPPED faceplayerslow


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

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

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

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

action AMECH2STANDING      0     1    8    1    10
action AMECH2WALKING       8     4    8    1    20
action AMECH2RUNNING       8     4    8    1    12
action AMECH2THINK         48    1    8    1    26
action AMECH2JUMP          92    1    8    1    20
action AMECH2FALL          100   1    8    1    20

action AMECH2SHOOTING1     48    2    8    -1    10
action AMECH2SHOOTING2     64    2    8    -1    10
action AMECH2DYING         72    20    1    1    16
action AMECH2LYINGDEAD     90    1
action AMECH2FROZEN         0    1    8

move MECH2WALKVEL 160
move MECH2RUNVEL 320
move MECH2HOVERVEL 192 -16
move MECH2FALLVEL 320 20
move MECH2JUMPVEL 480 -64
move MECH2UPVEL 96 -64
move MECH2LANDVEL 192 -8

ai AIMECH2FLYUP AMECH2JUMP MECH2UPVEL seekplayer
ai AIMECH2GETENEMY AMECH2WALKING MECH2WALKVEL seekplayer
ai AIMECH2CHARGEENEMY AMECH2JUMP MECH2RUNVEL seekplayer
ai AIMECH2FLEENEMY AMECH2WALKING MECH2WALKVEL fleeenemy
ai AIMECH2SHOOT1 AMECH2SHOOTING1 STOPPED faceplayerslow
ai AIMECH2SHOOT2 AMECH2SHOOTING2 STOPPED faceplayersmart
ai AIMECH2JUMPENEMY AMECH2JUMP MECH2JUMPVEL jumptoplayer
ai AIMECH2THINK AMECH2THINK STOPPED faceplayerslow
ai AIMECH2HEAL AMECH2THINK STOPPED geth
ai AIMECH2DYING AMECH2DYING STOPPED faceplayer
ai AIMECH2WAIT AMECH2THINK STOPPED geth

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

state checkhitscan


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

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

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

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

hitscan player[THISACTOR].posx player[THISACTOR].posy player[THISACTOR].posz mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask

ifvare pipethrow YES
{
	ifvare player[THISACTOR].rapid_fire_hold YES // pipebomb ready to be thrown
	{
		ifvarl weapcount 192 addvar weapcount 8 // 4
		ifp pducking nullop else
		{
			setvar countvar 0
			setvar xvel  192
			addvarvar xvel weapcount
			divvar zdist 56
			getplayer[THISACTOR].posx x
			getplayer[THISACTOR].posy y
			getplayer[THISACTOR].posz z
			whilevarn countvar 130
			{
				setvarvar digx x
				addvarvar digx xvel
				subvar xvel 5
				ifvarl xvel 0 setvar xvel 0
				rotatepoint x y digx y angvar x y
				espawn LOBTRAIL
				updatesectorz x y z temp
				ifvare temp -1 setvar countvar 129 else
				changespritesect RETURN temp
				setactor[RETURN].x x
				setactor[RETURN].y y
				setactor[RETURN].z z
				setactorvar[RETURN].countvar countvar
				addvarvar z zdist
				addvar zdist 264
				addvar countvar 1
			}
		}
	}
	else ifvare KICKBACKPIC 0 setvar weapcount 0
}

setvarvar scannedsprite hitsprite

ends

state projectilehitscan
// the sprite ID of the scanning projectile has been put in spriteid before this state is called

getactor[spriteid].ang angvar
getactor[spriteid].zvel zvel
getactor[spriteid].xvel xvel
shiftvarl zvel 14
ifvare xvel 0 setvar xvel 1
divvarvar zvel xvel
cos mycos angvar
sin mysin angvar
hitscan sprite[spriteid].x sprite[spriteid].y sprite[spriteid].z sprite[spriteid].sectnum mycos mysin zvel hitsector hitwall hitsprite hitx hity hitz clipmask
ends


state raincode

setvar tempe 0
setvar countvar 0
setvarvar countvarb raining
ifvarl countvarb 0 mulvar countvarb -1
//   ifmultiplayer nullop else
//   {
//   	ifvarl framerate 2 setvar countvarb 1
//   	ifvarvarg countvarb framerate setvarvar countvarb framerate
//   }

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

ends

state dodgecode

 cos xvel dodgeang
 sin yvel dodgeang

 ifvarg superkicking 0
 {
     ifvarg weaplev0 5
     {
	     mulvar xvel 384
	     mulvar yvel 384
     }
     else ifvarg weaplev0 2
     {
	     shiftvarl xvel 8
	     shiftvarl yvel 8
     }
     else
     {
	     mulvar xvel 192
	     mulvar yvel 192
     }
     ifp pducking { divvar xvel 3 divvar yvel 3 }
     ifvare spinkick 1
     {
	     divvar xvel 3
	     divvar yvel 3
 	 }
 	else
 	ifvarn kicktarg -1
 	{
	 	ifvarn sprite[kicktarg].statnum 1 setvar kicktarg -1
	 	else
	 	{
		 	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
	 	}
 	}
     
     
 }
 else
 {
     mulvar xvel 480
     mulvar yvel 480
 }
 setplayer[THISACTOR].posxv xvel
 setplayer[THISACTOR].posyv yvel

subvar dodge 1

ends

state changeminigun

getplayer[THISACTOR].ammo_amount 3 temp
setplayer[THISACTOR].ammo_amount 3 MINIGUNAMMO
setvarvar MINIGUNAMMO temp

ifvarand ALTCHAINGUN 2
{
	subvar ALTCHAINGUN 2
	setvar WEAPON3_SHOTSPERBURST 0
	setvar WEAPON3_FIREDELAY 3
	ifvare dpsounds YES
	setvar WEAPON3_FIRESOUND DPCHAINGUNFIRE else
	setvar WEAPON3_FIRESOUND CHAINGUN_FIRE
	setvar WEAPON3_SHOOTS CHAINGUN
	setvar WEAPON3_TOTALTIME 12
	ifvarg weaplev3 4 setvar WEAPON3_FLAGS 73804 else
	setvar WEAPON3_FLAGS 73812
	setvar WEAPON3_CLIP 0
	setvar WEAPON3_SPAWNTIME 0
	setvar WEAPON3_RELOADSOUND1 4
	setvar WEAPON3_RELOADSOUND2 5
}
else
{
	orvar ALTCHAINGUN 2
	setvar WEAPON3_SHOTSPERBURST 2
	setvar WEAPON3_SHOOTS SHOTSPARK1
	setvar WEAPON3_FIRESOUND BOS1_ATTACK1 // MINIGUN_FIRE
	setvar WEAPON3_FLAGS 84
	setvar WEAPON3_FIREDELAY 2
	setvar WEAPON3_TOTALTIME 12
	// setvar WEAPON3_FIRESOUND DPCHAINGUNFIRE
	setvar WEAPON3_FLAGS 73812
	setvar WEAPON3_CLIP 0
	setvar WEAPON3_SPAWNTIME 0
	setvar WEAPON3_RELOADSOUND1 4
	setvar WEAPON3_RELOADSOUND2 5
}


ends

state resetweaponstate

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

setvar botclip 0

setvar LASERAMMO 0

ends

state normalfreeze

setvar WEAPON9_SHOTSPERBURST 0
setvar WEAPON9_SHOOTS FREEZEBLAST
setvar WEAPON9_FIRESOUND CAT_FIRE
setvar WEAPON9_FIREDELAY 3
setvar WEAPON9_TOTALTIME 5
setvar WEAPON9_FLAGS 65536
setvar WEAPON9_SPAWNTIME 0
setvar WEAPON9_SPAWN 0
setvar WEAPON9_INITIALSOUND CAT_FIRE

ends

state togglefreezer

sound SWITCH_ON
ifvare altfreeze NO
{
	setvar altfreeze YES
	setvar WEAPON9_SHOOTS ICEBEAM
	setvar WEAPON9_FIRESOUND ICEBEAMSND
	setvar WEAPON9_INITIALSOUND -1
	setvar WEAPON9_TOTALTIME 10
	setvar WEAPON9_SHOTSPERBURST 1
}
else
{
	setvar altfreeze NO
	setvar WEAPON9_SHOOTS FREEZEBLAST
	setvar WEAPON9_FIRESOUND CAT_FIRE
	setvar WEAPON9_INITIALSOUND CAT_FIRE
	setvar WEAPON9_TOTALTIME 5
	setvar WEAPON9_SHOTSPERBURST 0
}

ends


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

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

state mirror

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

setvar I 0
whilevarvarn I NUMWALLS
{
    setvarvar A I
    getwall[I].point2 B
    setvarvar K I
    whilevarvarn A B
    {
        addvar K 1
        ifvarvare K NUMWALLS setvarvar B A
        else
        getwall[K].point2 B
        
    }
    ifvarvarn K NUMWALLS
    {
	    setvarvar A K
	    setvarvar J I
	    setvarvar L K
	    subvarvar L J
	    divvar L 2
	    addvar J 1
	    whilevarn L 0
	    {
	        state swapwall
	        setarray SWAPWALLS[J] K
	        setarray SWAPWALLS[K] J
	        addvar J 1
	        addvar K -1
	        addvar L -1
	    }
	
	    setvarvar J I
	    whilevarvarn I A
	    {
	        setvarvar K I
	        addvar K 1
	        getwall[J].x B
	        getwall[J].y C
	        getwall[K].x D
	        getwall[K].y E
	        setwall[J].x D
	        setwall[J].y E
	        setwall[K].x B
	        setwall[K].y C
	
	        addvar I 1
	    }
    }

    addvar I 1
}

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

    addvar I 1
}

ends

state superkickcode

	ifvarn player[THISACTOR].somethingonplayer -1 
	{
		orvar bits 4
		setinput[THISACTOR].bits bits
	}
	
	ifvare superkicking 1 { getplayer[THISACTOR].posz initz ifp pducking nullop else addvar initz 1536 }
	getplayer[THISACTOR].posz z
	ifvarvarl z initz
	setplayer[THISACTOR].posz initz
	
	ifvare spinkick 1 ifvare superkickdone 0
	{
		getplayer[THISACTOR].oang angvar
		ifvare reversekick YES { subvar angvar 232 ifvarg rofbonus 0 subvar angvar 192 } else
		{ addvar angvar 232 ifvarg rofbonus 0 addvar angvar 192 }
		setplayer[THISACTOR].ang angvar
	}
	
	ifvare superkickdone 1 ifvarl superkicking 4 nullop else
	{
		getplayer[THISACTOR].rotscrnang temp
		ifvare reversekick YES addvar temp 36 else
		subvar temp 36
		setplayer[THISACTOR].rotscrnang temp
	}
	ifvare superkickdone 0 
	{
		addvar superkicking 1
		ifvarg rofbonus 0 { ifvare superkicking 7 ifvare kickimpact 0 sound KICKOUT addvar superkicking 1 }
		ifvarg superkicking 6 ifvare spinkick 1 
		{
			shoot KNEE shoot KNEE
			ifvarg rofbonus 0 { shoot KNEE shoot KNEE }
//			getplayer[THISACTOR].i spriteid
// 			getplayer[THISACTOR].ang angvar
// 			ifvare reversekick YES subvar angvar 96 else addvar angvar 96
// 			setplayer[THISACTOR].ang angvar
// 			setactor[spriteid].ang angvar
// 			shoot KNEE
// 			ifvare reversekick YES subvar angvar 96 else addvar angvar 96
// 			setplayer[THISACTOR].ang angvar
// 			setactor[spriteid].ang angvar
// 			shoot KNEE
// 			
// 			ifvare reversekick YES addvar angvar 192 else subvar angvar 192
// 			setplayer[THISACTOR].ang angvar
// 			setactor[spriteid].ang angvar
		}
		else ifvarg superkicking 7 ifvarl superkicking 10 { shoot KNEE ifvarg rofbonus 0 shoot KNEE }
		ifvare superkicking 7 ifvare kickimpact 0 sound KICKOUT
	}
	else 
	{
		subvar superkicking 1
		ifvarg rofbonus 0 { subvar superkicking 1 ifvarl superkicking 2 setvar superkicking 0 }
		ifvarl superkicking 1 setvar kickimpact 0
	}
	ifvarl superkicking 1 { setvar superkickdone 0 setvar spinkick 0 setvar kicktarg -1 }
	// ifvare spinkick 1 
	ifvarg superkicking 9 setvar superkickdone 1

ends

state kludges

ifvarg rofbonus 0
{
	subvar rofbonus 1
	getplayer[THISACTOR].kickback_pic temp
	ifvarg temp 0
	{
		addvar temp 1
		switch CURRWEAP
		case 0 ifvarvarg temp WEAPON0_FIREDELAY { setplayer[THISACTOR].kickback_pic temp } break
		case 1 
		ifvarvarg temp WEAPON1_FIREDELAY 
			{ 
				ifvarl akimbo 1 addvar temp 1
				setplayer[THISACTOR].kickback_pic temp 
				ifvare akimbo YES ifvare temp 5
				{
					getplayer[THISACTOR].ammo_amount 1 tempb
					subvar tempb 1
					setplayer[THISACTOR].ammo_amount 1 tempb
					soundvar WEAPON1_FIRESOUND 
					shootvar WEAPON1_SHOOTS
				}
			} 
			break
		case 2 ifvarvarg temp WEAPON2_FIREDELAY { setplayer[THISACTOR].kickback_pic temp } break
		case 3 
		    ifvarand timer 1 ifvarg player[THISACTOR].ammo_amount 3 1
			{
				getplayer[THISACTOR].ammo_amount 3 tempb
				subvar tempb 1
				setplayer[THISACTOR].ammo_amount 3 tempb
				soundvar WEAPON3_FIRESOUND 
				shootvar WEAPON3_SHOOTS
			}
			break
		case 4 ifvarvarg temp WEAPON4_FIREDELAY { setplayer[THISACTOR].kickback_pic temp } break
		case 5 break
		case 6 ifvarvarg temp WEAPON4_FIREDELAY { setplayer[THISACTOR].kickback_pic temp } break
		case 7 
		ifvarand timer 2 ifvarg player[THISACTOR].ammo_amount 7 1
			{
				getplayer[THISACTOR].ammo_amount 7 tempb
				subvar tempb 1
				setplayer[THISACTOR].ammo_amount 7 tempb
				soundvar WEAPON7_FIRESOUND 
				shootvar WEAPON7_SHOOTS
				ifvare WEAPON7_SHOOTS SHOTSPARK1 { shoot SHOTSPARK1 shoot SHOTSPARK1 shoot SHOTSPARK1 }
			}
		break
		case 8 break
		case 9
		ifvare WEAPON9_SHOOTS FREEZEBLAST
		{
		ifvarand timer 1 ifvarg player[THISACTOR].ammo_amount 9 1
			{
				getplayer[THISACTOR].ammo_amount 9 tempb
				subvar tempb 1
				setplayer[THISACTOR].ammo_amount 9 tempb
				soundvar WEAPON9_FIRESOUND 
				shootvar WEAPON9_SHOOTS
			}
		}
		else
		{
			ifvarvarg temp WEAPON2_FIREDELAY { setplayer[THISACTOR].kickback_pic temp }
		}
		break
		case 11 
		
			setvar WEAPON11_FIREDELAY 2
			setvar WEAPON11_TOTALTIME 6
			ifvare temp 5
			ifvarg player[THISACTOR].ammo_amount 11 1
			{
				getplayer[THISACTOR].ammo_amount 11 tempb
				subvar tempb 1
				setplayer[THISACTOR].ammo_amount 11 tempb
				soundvar WEAPON11_FIRESOUND 
				shootvar WEAPON11_SHOOTS
			}
		break
		
		endswitch
	}
	
	ifvare rofbonus 0
	{
		setvar WEAPON11_FIREDELAY 3
		setvar WEAPON11_TOTALTIME 5
	}
}

// rof mod on shotty
ifvare CURRWEAP 2 ifvarg weaplev2 5
{
	getplayer[THISACTOR].kickback_pic temp
	ifvarg temp 0
	{
		addvar temp 1
		ifvarvarg temp WEAPON2_FIREDELAY setplayer[THISACTOR].kickback_pic temp
	}
}

// WAR OF ATTRITION MODE STUFF
ifvare VOLUME 6
{
	ifvarg wavetime 0
	{
		ifvare player[THISACTOR].timebeforeexit 0
		{
			subvar wavetime 1
			ifvare wavetime 0 globalsound WAVESTART else
			{
				setvarvar announcetime wavetime
				setvar announce 1150
				setvarvar temp wavetime
				setvarvar tempb wavetime
				modvar tempb 30
				ifvare tempb 0 globalsound COUNTDOWN
				divvar temp 30
				addvarvar announce temp
			}
		}
		else { setplayer[THISACTOR].fta 0 soundonce ENDSEQVOL3SND3 }
		ifvare wavetime 0 
		{
			addvar wave 1
			// if there are any monsters left, strip them of mval so they don't end the next wave prematurely		
			headspritestat spriteid 1
			whilevarn spriteid -1
			{
				setactorvar[spriteid].mval 0
				nextspritestat spriteid spriteid
			}
		
			switch wave
			case 0 case 1 case 2 case 24 case 26
			setvar mdeaths 20
			setvar wavemax 6
			break
			
			case 3 case 4 case 5 case 6
			case 8
			setvar mdeaths 20
			setvar wavemax 5
			break
			
			case 7
			setvar mdeaths 6
			setvar wavemax 3
			break
			
			case 9
			setvar mdeaths 10
			setvar wavemax 2
			break
			
			case 10 case 13
			setvar mdeaths 4
			setvar wavemax 3
			break
					
			case 14
			setvar mdeaths 2
			setvar wavemax 2
			break
					
			case 15 case 28
			setvar mdeaths 30
			setvar wavemax 10
			break
			
			case 16 case 19 case 12
			setvar mdeaths 25
			setvar wavemax 6
			break
			
			case 17 case 23 case 11
			setvar mdeaths 25
			setvar wavemax 7
			break
			
			case 18
			setvar mdeaths 12
			setvar wavemax 3
			break
			
			case 20
			setvar mdeaths 15
			setvar wavemax 4
			break
			
			case 21
			setvar mdeaths 8
			setvar wavemax 3
			break
			
			case 22
			setvar mdeaths 25
			setvar wavemax 15
			break
			
			case 25
			setvar mdeaths 15
			setvar wavemax 6
			break
			
			case 27
			setvar mdeaths 10
			setvar wavemax 3
			break
						
			case 29
			setvar mdeaths 40
			setvar wavemax 8
			break
			
			case 30
			setvar mdeaths 50
			setvar wavemax 10
			break
			
			case 31
			setvar mdeaths 60
			setvar wavemax 10
			break
			
			case 32
			setvar mdeaths 9
			setvar wavemax 9
			break
					
			default setvar mdeaths 30
			setvar wavemax 10
			break
			endswitch
			
			
			ifvare saveoption YES
			{
				save 9
				userquote 1058
			}
			ifvare wave 1
			starttrackvar LEVEL
			else
			ifvare wave 8
			starttrackvar LEVEL
			else
			ifvare wave 11
			starttrackvar LEVEL
			else
			ifvare wave 15
			starttrackvar LEVEL
			else
			ifvare wave 22
			starttrackvar LEVEL
			else
			ifvare wave 29
			starttrackvar LEVEL
		}	
	}
	else // IN MID WAVE
	{
		headspritestat spriteid 2
		whilevarn spriteid -1
		{
			ifvare actorvar[spriteid].monstatus 1
			{
				changespritestat spriteid 1
				setactor[spriteid].httimetosleep 3000
			}
			nextspritestat spriteid spriteid
		}
		
		headspritestat spriteid 1
		setvar mpoints 0
		whilevarn spriteid -1
		{
			ifvare sprite[spriteid].picnum MSPAWNER
			ifvarn actorvar[spriteid].peractor1 0
			addvar mpoints 1
			
			ifvarg actorvar[spriteid].mval 0
			addvar mpoints 1
			
			nextspritestat spriteid spriteid
		}
		

		setvarvar mleft mdeaths
		subvarvar mleft mpoints
		
		ifvarg mleft 0
		ifvarvarg wavemax mpoints
		{
			setvarvar tempb totalspawners
			subvar tempb 1
			randvarvar temp tempb
			setvarvar spriteid mspawners[temp]
			ifvare actorvar[spriteid].peractor1 0
			{
				changespritestat spriteid 1
				setactor[spriteid].httimetosleep 30000
				setactorvar[spriteid].peractor1 1
				setactorvar[spriteid].inithp mleft
			}
		}
		
		
		

	}

	// monster search and angle determination

		setvar souldist 999999
		setvar soultarg -1
		headspritestat tempb 1
		whilevarn tempb -1
		{
			ifvarg actorvar[tempb].mval 0
			{
				dist temp THISACTOR tempb
				ifvarvarl temp souldist { setvarvar soultarg tempb setvarvar souldist temp }
			}
			nextspritestat tempb tempb
		}
		shiftvarr souldist 9
		ifvarn soultarg -1
		{
			getactor[soultarg].picnum soulpic
			ifvare soulpic RECONDP setvar soulpic RECON
			getactor[soultarg].x mx
	        getactor[soultarg].y my
	        subvarvar mx player[THISACTOR].posx
	     	subvarvar my player[THISACTOR].posy
	        getangle soulang mx my
			subvarvar soulang player[THISACTOR].ang // diff between angle to target and actual angle
			ifvarl sprite[soultarg].cstat 0 setvar soulsee NO else
			canseespr soultarg THISACTOR soulsee
 		}
 		
		ifvarg announcetime 0 subvar announcetime 1
}

// weapon damage adjustments
setvar pdamage 100

setvar temp 0
ifvare picnum KNEE setvarvar temp weaplev0 else
ifvarg tripbombing 0 setvarvar temp weaplev8 else
{
	switch CURRWEAP
	case 0 ifvare LASERAMMO 0 setvarvar temp weaplev0 else setvarvar temp weaplev10 break
	case 1 setvarvar temp weaplev1 ifvarg temp 5 addvar pdamage 25 break
	case 2 setvarvar temp weaplev2 break
	case 3 setvarvar temp weaplev3 ifvarg temp 5 addvar pdamage 25 break
	case 4 setvarvar temp weaplev4 break
	case 5 case 10 setvarvar temp weaplev5 break
	case 6 setvarvar temp weaplev6 break
	case 7 setvarvar temp weaplev7 break
	case 8 setvarvar temp weaplev8 break
	case 9 setvarvar temp weaplev9 break
	case 11 setvarvar temp weaplev11 break
	endswitch
}

ifvarg temp 6 // extra damage from advanced weapon level
{
	subvar temp 6
	mulvar temp 25
	addvarvar pdamage temp
}

ifp ponsteroids ifvarg steroidlevel 0
{
	setvarvar tempb steroidlevel
	shiftvarl tempb 2
	addvarvar pdamage tempb
}

ifvarg weaptotal 11
{
	getplayer[THISACTOR].weapon_pos temp
	ifvarn temp 0
	{
		ifvarl temp 0 ifvarg temp -9 subvar temp 1 else
		ifvarg temp 1 subvar temp 1
		setplayer[THISACTOR].weapon_pos temp
	}
}

ifvarg weaptotal 71 
ifvare CURRWEAP 1
ifvarvarl player[THISACTOR].ammo_amount 1 player[THISACTOR].max_ammo_amount 1
{
	setvarvar temp timer
	modvar temp 15
	ifvare temp 0
	{
		getplayer[THISACTOR].ammo_amount 1 temp
		addvar temp 1
		setplayer[THISACTOR].ammo_amount 1 temp
	}
}


ifvare moretalk YES
ifvarl activemonsters 0 // meaning that a monster was recently killed
{
	addvar activemonsters 1
	ifvare activemonsters 0 
	{
		ifvarg kickasscount 3
		{
			getplayer[THISACTOR].player_par temp
			subvarvar temp lastspeechtime
			ifvarg temp 900
			{
				ifphealthl 50 
				{
					randvar temp 3
					ifvare temp 0
					globalsound PAYBKSND else
					ifvare temp 1
					globalsound HADIT else
					ifvare temp 2
					globalsound THATWASFUN else
					ifvare temp 3
					globalsound BRINGITON
				}
				else
				{
					randvar temp 4
					ifvare temp 0
					globalsound ICAMEISAW else
					ifvare temp 1
					globalsound THATWASFUN else
					ifvare temp 2
					globalsound ALLUGOT else
					ifvare temp 3
					globalsound BRINGITON else
					ifvare temp 4
					globalsound ILOOKGOOD
				}
				setvar kickasscount 0
				ifvare burning 0
				ifvare saveoption YES
				state autosave
			}
		}
		else subvar kickasscount 1
	}
}

// autosave failsafe
ifvare saveoption YES
ifvare burning 0
ifvarg sprite[THISACTOR].extra 50
{
	setvarvar temp timer
	subvarvar temp lastspeechtime
	ifvarg temp 18000	
		state autosave	
}
ifvarg tauntcount 0
{
	subvar tauntcount 1
	ifvare tauntcount 0 globalsoundvar taunt
}

ifvarl player[THISACTOR].player_par 2
{
	setvar newvolume -1
	ifvare truevolume -1 setvarvar truevolume VOLUME
	setvar GMCHECK 0
	ifvarl VOLUME 4
	ifvare firstmap NO
	ifvare sector[THISACTOR].floorpal 4
	{
		readgamevar randomstart
		addvar randomstart 1
		andvar randomstart 65535
		setvarvar temp randomstart
		xorvar temp 43690
		whilevarn temp 0
	    {
	    ifrnd 1 nullop
	    subvar temp 1
	    }
	    savegamevar randomstart
	    setvar rainstart 0
		randvar temp VOL1MAPS
		addvar temp 1 // to avoid loading start.map
		randvar tempb 3
		startlevel tempb temp
		setvar firstmap YES
		break
	}
	else
	ifvare truevolume 3
    {
	    getuserdef[THISACTOR].player_skill temp
		ifvarl temp 3
		{
			setuserdef[THISACTOR].player_skill 3
			quote 1133
		}
	}
	ifvare VOLUME 6
	{
// 		getuserdef[THISACTOR].player_skill temp
// 		ifvarl temp 3
// 		{
// 			setuserdef[THISACTOR].player_skill 3
// 			quote 1133
// 		}
		starttrack 8
	}
	setvar invicon 1
	setvar chainsparksprite -1
	setvar mybot -1
	setvar stealth 3072
	ifvarn rainstart 0
	setvarvar raining rainstart		
	setvar lastspeechtime -1500	
	
	setvar rainstart 0
	setvar temp 99
	whilevarn temp -1
	{
		setarray ptrails[temp] -1
		subvar temp 1
	}
	setactor[THISACTOR].extra player[THISACTOR].max_player_health
	ifvarl truevolume 4
	setplayer[THISACTOR].shield_amount player[THISACTOR].max_shield_amount
}


ifvarand player[THISACTOR].gm 8
ifvare GMCHECK 0
{
	setvar GMCHECK 1
	state savestatus
	ifvarl VOLUME 4
	{
		state resetammo
		setactor[THISACTOR].extra player[THISACTOR].max_player_health
	}
	else ifvare VOLUME 6
	{
		state resetammo
		setactor[THISACTOR].extra player[THISACTOR].max_player_health
	}
	ifvarl truevolume 4
	setplayer[THISACTOR].jetpack_amount 0
	// addvar randomize 1
	addvar truelevel 1
	ifvarl truevolume 3
	ifvarn firstmap 2
	{
		ifvarl truelevel VOL1LEVELS // requisite number of levels not completed yet
		{
// 			setvarvar tempb LEVEL
// 			subvar tempb 1 // the level just completed
// 			setvar tempc 1
// 			whilevarn tempb 0 // generate bit from level number
// 			{
// 				shiftvarl tempc 1
// 				subvar tempb 1
// 			}
// 			// add bit to list of completed levels
// 			ifvare VOLUME 0 orvarvar completed tempc else
// 			ifvare VOLUME 1 orvarvar completed2 tempc else
// 			ifvare VOLUME 2  orvarvar completed3 tempc
// 			setvar tempb 1
// 			randvar newvolume 2 // the VOLUME number of next map to be chosen
// 			whilevarn tempb 0
// 			{
// 				randvar newlevel VOL1MAPS // pick a new level number
// 				addvar newlevel 1 // to avoid loading start.map
// 				setvarvar tempc newlevel
// 				setvar tempd 1
// 				whilevarn tempc 0
// 				{
// 					shiftvarl tempd 1
// 					subvar tempc 1
// 				}
// 				ifvare newvolume 0 setvarvar K completed else
// 				ifvare newvolume 1 setvarvar K completed2 else
// 				setvarvar K completed3
// 				ifvarvarand K tempd nullop // ths level has been completed already
// 				else
// 				setvar tempb 0
// 			}
// 			setvarvar L VOLUME
// 			startlevel newvolume newlevel
			setuserdef[THISACTOR].display_bonus_screen YES
			
		}
		else // start the final boss level
		{
			setvar temp VOL1MAPS
			addvar temp 2
			startlevel truevolume temp
			setuserdef[THISACTOR].display_bonus_screen YES
			setvar firstmap 2
		}
	}
}


setvar tempb 8192
setvarvar temp gogglevel
mulvar temp 640
subvarvar tempb temp
ifvarl tempb 128 setvar tempb 128
addvar tempb 384 // tempb is now the base stealth value
setvarvar tempd tempb
shiftvarr tempd 1 // tempd is the minimum stealth value
setvarvar tempc tempd
mulvar tempc 10 // tempc is the maximum stealth value

ifvarvarl stealth tempb { addvar stealth 128 ifvarvarg stealth tempb setvarvar stealth tempb }
else
ifvarvarg stealth tempb 
{
	subvar stealth 128
	setvarvar tempe gogglevel
	shiftvarl tempe 2
	subvarvar stealth tempe
	ifp pducking { ifvarvarl stealth tempd setvarvar stealth tempd } else 
	ifvarvarl stealth tempb setvarvar stealth tempb 
}

ifvarn CURRWEAP 0
ifvarn KICKBACKPIC 0 { addvar stealth 256 ifvarvarg stealth tempc setvarvar stealth tempc } else
ifvarn LASERFIRE 0 { addvar stealth 256 ifvarvarg stealth tempc setvarvar stealth tempc } else
ifp pducking { subvar stealth 160 ifvarvarl stealth tempd setvarvar stealth tempd } else
ifp prunning { addvar stealth 160 ifvarvarg stealth tempc setvarvar stealth tempc }
ifp pshrunk { setvarvar stealth tempd }
	

ifvarl timer 200
getkeyname 1065 11 2

ifvarn menutoggle 0
{
	addvar cursorang 37
	getkeyname 1065 11 2
	setplayer[THISACTOR].knuckle_incs 0
	setplayer[THISACTOR].movement_lock 31
	setactor[THISACTOR].htextra -1
	setplayer[THISACTOR].kickback_pic 0
	
	getplayer[THISACTOR].ang temp
	getplayer[THISACTOR].oang tempb
	getincangle angvar temp tempb
	divvar angvar 3
	subvarvar cursorx angvar
	setplayer[THISACTOR].ang player[THISACTOR].oang
	ifvarl cursorx 0 setvar cursorx 0
	ifvarg cursorx 320 setvar cursorx 320
	
	getplayer[THISACTOR].horiz temp
	getplayer[THISACTOR].ohoriz tempb
	subvarvar temp tempb
	getuserdef[THISACTOR].mouseflip tempc
	ifvare tempc 0
	addvarvar cursory temp
	else
	subvarvar cursory temp
	ifvarl cursory 0 setvar cursory 0
	ifvarg cursory 200 setvar cursory 200
	
	// menutoggle 1 == menu up, nothing selected
	// 2 == show upgrades selected
	// 3 == high scores selected
	// 4 == restart mission selected
	// 5 == resume game selected
	// 6 == autosave option selected
	// 12 == upgrade history screen
	// 13 == high score screen
	
	ifvarl menutoggle 10
	{
		ifvarg cursorx 124 ifvarl cursorx 196
		ifvarg cursory 5 ifvarl cursory 55
		{
			setvar menutoggle 4
			ifhitspace { state resetammo setvar menutoggle 0 startlevel VOLUME LEVEL break } else
			ifvarand bits 4 { state resetammo setvar menutoggle 0 startlevel VOLUME LEVEL break }
		}
		else
		ifvarg cursorx 124 ifvarl cursorx 196
		ifvarg cursory 70 ifvarl cursory 120
		ifvarl VOLUME 4
		{
			setvar menutoggle 5
			ifvarg restarts 0
			{
				ifhitspace { state resetammo state restorestatus subvar restarts 1 state startrandomlevel setvar menutoggle 0 break } else
				ifvarand bits 4 { state resetammo state restorestatus subvar restarts 1 state startrandomlevel setvar menutoggle 0 break }
			}
		}
		else
		ifvarg cursorx 25 ifvarl cursorx 75
		ifvarg cursory 75 ifvarl cursory 125
		{
			setvar menutoggle 2
			ifhitspace setvar menutoggle 12 else
			ifvarand bits 4 setvar menutoggle 12
		}
		else
		ifvarg cursorx 230 ifvarl cursorx 310
		ifvarg cursory 75 ifvarl cursory 125
		{
			setvar menutoggle 3
			ifhitspace 
			{ 
				setvar menutoggle 13 
				readarrayfromfile atthighscores 1068
				readarrayfromfile attgameids 1132
			} else
			ifvarand bits 4 
			{ 
				setvar menutoggle 13 
				readarrayfromfile atthighscores 1068
				readarrayfromfile attgameids 1132
			}
		}
		else
		ifvarg cursorx 9 ifvarl cursorx 91
		ifvarg cursory 155 ifvarl cursory 175
		{
			setvar menutoggle 6
			
			ifhitspace
			{
				ifvarvarn lastinput timer
				{
					sound SWITCH_ON ifvare saveoption NO setvar saveoption YES else setvar saveoption NO savegamevar saveoption 
				}
				setvarvar lastinput timer
				addvar lastinput 1
			} 
			else
			ifvarand bits 4 
			{ 
				ifvarvarn lastinput timer
				{
					sound SWITCH_ON ifvare saveoption NO setvar saveoption YES else setvar saveoption NO savegamevar saveoption 
				}
				setvarvar lastinput timer
				addvar lastinput 1
			}
				
			
			
		}		
		else
		ifvarg cursorx 229 ifvarl cursorx 311
		ifvarg cursory 155 ifvarl cursory 175
		{
			setvar menutoggle 7
			
			ifhitspace
			{
				ifvarvarn lastinput timer
				{
					sound SWITCH_ON ifvare mirroroption NO setvar mirroroption YES else setvar mirroroption NO savegamevar mirroroption 
				}
				setvarvar lastinput timer
				addvar lastinput 1
			} 
			else
			ifvarand bits 4 
			{ 
				ifvarvarn lastinput timer
				{
					sound SWITCH_ON ifvare mirroroption NO setvar mirroroption YES else setvar mirroroption NO savegamevar mirroroption  
				}
				setvarvar lastinput timer
				addvar lastinput 1
			}
				
			
			
		}
		
		else setvar menutoggle 1
	}
	
	
	
	setplayer[THISACTOR].horiz 100
	ifp palive nullop else setvar menutoggle 0
	ifvare menutoggle 0 setplayer[THISACTOR].movement_lock 0
	break
}


ifvare player[THISACTOR].heat_on YES
flash



ifonwater 
ifvarn rendmode 0
{
  setvar RETURN -1
  ifrnd 32 spawn WATERCIRCLE else
  ifaction PRUN spawn WATERCIRCLE else
  ifaction PRUNBACK spawn WATERCIRCLE else
  ifaction PWALK spawn WATERCIRCLE else
  ifaction PWALKBACK spawn WATERCIRCLE else
  ifaction PAKICKING spawn WATERCIRCLE else
  ifaction PCRAWLING spawn WATERCIRCLE
}


ifvarn chainsparksprite -1
{
	ifvarn sprite[chainsparksprite].statnum 1024
	{
		getplayer[THISACTOR].posx x
		getplayer[THISACTOR].posy y
		getplayer[THISACTOR].posz z
		getplayer[THISACTOR].cursectnum mysector
		
		setvarvar mx sprite[chainsparksprite].x
		addvar mx 384
		rotatepoint sprite[chainsparksprite].x sprite[chainsparksprite].y mx sprite[chainsparksprite].y sprite[chainsparksprite].ang digx digy
		updatesector digx digy temp
		ifvarn temp -1
		{
			setplayer[THISACTOR].posx digx
			setplayer[THISACTOR].posy digy
			getactor[chainsparksprite].z digz
			subvar digz 2048
			setplayer[THISACTOR].posz digz
			
			addvar digz 8192
			getplayer[THISACTOR].i I
			setsprite I digx digy digz
			changespritesect I temp
			setplayer[THISACTOR].cursectnum temp
			
			ifvare CURRWEAP 1
			addvar botclip 1 // this extra bullet does not come from the clip
			shoot SHOTSPARK1		
			
			setplayer[THISACTOR].posx x
			setplayer[THISACTOR].posy y
			setplayer[THISACTOR].posz z
			setplayer[THISACTOR].cursectnum mysector
			addvar z 8192
			setsprite I x y z
			changespritesect I mysector
		}
	}
	setvar chainsparksprite -1
}

ifvarg quikpipe 0
{
	addvar quikpipe 1
	ifvare quikpipe 6
	{
		getplayer[THISACTOR].ammo_amount 5 temp
		ifvarg temp 0
		{
			subvar temp 1
			setplayer[THISACTOR].ammo_amount 5 temp
			espawn HEAVYHBOMB
			setactor[RETURN].xvel 480
			setactor[RETURN].htg_t 7 40
			setactor[RETURN].htg_t 0 1
			setactor[RETURN].htg_t 6 1
			getplayer[THISACTOR].ang angvar
			setactor[RETURN].ang angvar
			getplayer[THISACTOR].posz mz
			addvar mz 2048
			setactor[RETURN].z mz
			getplayer[THISACTOR].horiz temp
			subvar temp 100
			mulvar temp -32
			subvar temp 512
			setactor[RETURN].zvel temp
			getactor[THISACTOR].x x
			getactor[THISACTOR].y y
			setvarvar mx x
			addvar mx 256
			rotatepoint x y mx y angvar mx my
			setactor[RETURN].x mx
			setactor[RETURN].y my
		}
		
	}
	ifvare quikpipe 19 setvar quikpipe 0
}

getplayer[THISACTOR].boot_amount temp
ifvarvarl temp lastbootamount setvar bootsinuse 32
setvarvar lastbootamount temp
ifvarg bootsinuse 0 subvar bootsinuse 1
ifvarg helmflash 0 subvar helmflash 1
ifvarg invmsg 0 subvar invmsg 1
ifvarg beamhit 0 subvar beamhit 1
ifvarg fta 0 subvar fta 1
ifvarg tripbombing 0 subvar tripbombing 1
ifvarg upmsgtime 0 subvar upmsgtime 1
ifvarg smokecount 0 subvar smokecount 1
ifvarg eshield 0 { subvar eshield 1 ifvare eshield 0 stopactorsound THISACTOR SHIELDON else soundonce SHIELDON }
ifvarg xpbonus 0 subvar xpbonus 1
ifvarg burning 0 state imonfire
ifvarg LASERFIRE 0 
{
	addvar LASERFIRE 1
	ifvare LASERFIRE 4 setvar weap -1
	ifvarg rofbonus 0 { addvar LASERFIRE 1 ifvare LASERFIRE 4 setvar weap -1 }
	ifvarg weaplev10 4 { ifvarg LASERFIRE 7 setvar LASERFIRE 0 } else
	ifvarg weaplev10 2 { ifvarg LASERFIRE 10 setvar LASERFIRE 0 } else
	ifvarg weaplev10 1 { ifvarg LASERFIRE 7 setvar LASERFIRE 0 } else
	ifvarg LASERFIRE 10 setvar LASERFIRE 0
}

ends

state placetripbomb2

getactor[THISACTOR].ang angvar
addvar angvar 1024
setvarvar mx player[THISACTOR].posx
addvar mx 256
rotatepoint player[THISACTOR].posx player[THISACTOR].posy mx player[THISACTOR].posy angvar x y

espawn TRIPBOMB2
setsprite RETURN x y tripz

setactorvar[RETURN].myspawner triphack
setactorvar[RETURN].peractor5 sprite[triphack].picnum
getactor[THISACTOR].ang angvar
			
getincangle angvar1 angvar sprite[triphack].ang
setactorvar[RETURN].peractor1 angvar1

setactorvar[RETURN].mtype 256

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

getactor[THISACTOR].z z
setactor[RETURN].z z

getactor[triphack].z z
subvarvar z tripz
ifvarl z 0 setvar z 0
setactorvar[RETURN].initz z

ifvarn sprite[triphack].picnum TANK
ifvarn sprite[triphack].picnum DRONE
ifvarn sprite[triphack].picnum ROTATEGUN
ifvarn sprite[triphack].picnum MECH2
sound ALIEN_SWITCH1 else sound LASERTRIP_ONWALL

ends

move TRAILPROBE 160

state enter_ptrail

setvar temp 0
setvar spriteid -1
whilevarn temp 100
{
	setvarvar tempb ptrails[temp]
	ifvare tempb -1 // empty spot
	{
		setarray ptrails[temp] THISACTOR
		ifvarn spriteid -1 // should be the previous trail sprite
		{
			ldist xydist THISACTOR spriteid
			ifvarl xydist 512 move TRAILPROBE randomangle
		}
		setvar temp 99
	}
	else setvarvar spriteid tempb
	addvar temp 1
}

ends

state exit_ptrail

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

ifvarn mybot -1
{
	getactorvar[mybot].bouncesound temp
	ifvarn temp -1 subvar temp 1
	setactorvar[mybot].bouncesound temp
}

ends


useractor notenemy PLAYERTRAIL 0
sleeptime -1
ifmove 0
{
	spriteflags 16
	setvar playerally -1
	cstat 32768
	move INIT
	sizeat 4 4
	state enter_ptrail
	getactor[THISACTOR].x initx
	getactor[THISACTOR].y inity
	getactor[THISACTOR].z initz
}
else ifmove INIT
{
	setactor[THISACTOR].x initx
	setactor[THISACTOR].y inity
	setactor[THISACTOR].z initz
}
else ifmove TRAILPROBE
{
	ifnotmoving { move TRAILPROBE randomangle addvar countvar 1 }
	ifcount 52 move INIT
	ifvarg countvar 3 move INIT
}
ifcount 520 { state exit_ptrail killit }

enda

state playertrailcode

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


ends



move PGROWINGPOP        // Used only as a variable

actor APLAYER MAXPLAYERHEALTH PSTAND 0 0

setvar playerally -1

// ifvarg leech 49 
// {
// 	addphealth 1 
// 	subvar leech 50
// 	ifvarl weaptotal 60 
// 	subvar leech 50
// }

ifvarg leech 65
{
	addphealth 1
	subvar leech 65
}

ifp ponsteroids 
{
	ifvarn VOLUME 6 ifvarl rofbonus 3 setvar rofbonus 3
	inittimer 80
	setvarvar temp steroidlevel
	ifvarl temp 11 shiftvarl temp 3 else
	ifvarl temp 21
	{
		shiftvarl temp 2
		addvar temp 80
	}
	else
	{
		shiftvarl temp 1
		addvar temp 120
	}
	addvar temp 10
	ifvarvarl sprite[THISACTOR].extra temp // ifphealthl MAXPLAYERHEALTH
	addphealth 1
}
else 
	inittimer 120


state checkhitscan
state kludges


//ifvarg numallies 0 state playertrailcode
//else
//ifvare smartmonsters YES
state playertrailcode


getplayer[THISACTOR].curr_weapon CURRWEAP
getplayer[THISACTOR].kickback_pic KICKBACKPIC

ifvarl superkicking 0 // kick timer
{
	addvar superkicking 1
	ifvare superkicking 0
	{
		setvar superkicking 1
		ifrnd 128 setvar reversekick YES else setvar reversekick NO
		ifvarg rofbonus 0 subvar kickenergy 52
		ifvarg weaplev0 3 subvar kickenergy 104 else
		subvar kickenergy 156
		ifinwater nullop else
		{
			ifvarn kicktarg -1
		 	{
			 	ifvarn sprite[kicktarg].statnum 1 setvar kicktarg -1
			 	else
			 	{
				 	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 5 else
			setvar dodge 10
		}
		ifvare CURRWEAP 0
		setplayer[THISACTOR].kickback_pic 0
	}
}
ifvarg superkicking 0 state superkickcode
ifvarl kickenergy KENERGY addvar kickenergy 1

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

ifvare CURRWEAP 3
{
	ifvare player[THISACTOR].ammo_amount 3 0
	ifvarg MINIGUNAMMO 0
	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
		
	}
	ifvarand ALTCHAINGUN 2 nullop else
	{		
		setvar miniguncount 0 
		setvar grenadecounter 0 
	}
}

ifvare CURRWEAP 8
{
	ifvare KICKBACKPIC 4
	ifvarn triphack -1
	{
		// spawn it
		setvar temp 1
		ifvarn sprite[triphack].statnum 1 ifvarn sprite[triphack].statnum 2 setvar temp 0 else
		ifvarn actorvar[triphack].monstatus 1 setvar temp 0
		else
		{
			dist xydist THISACTOR triphack
			ldist xydist2 THISACTOR triphack
			ifvarg xydist 1792 setvar temp 0
			ifvarg xydist2 1024 setvar temp 0
		}
		ifvare temp 0
		{
			getplayer[THISACTOR].ammo_amount 8 tempb
			addvar tempb 1
			setplayer[THISACTOR].ammo_amount 8 tempb
		}
		else
		state placetripbomb2
		setvar triphack -1
	}
	else
	ifvarand bits 4
	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
		}
	}
}
else setvar triphack -1
			
ifvare miniguncount 0 
{
	setvar gunframe 6208 
	stopactorsound THISACTOR MINISPINSLOW
	stopactorsound THISACTOR MINISPINFAST
}

ifp palive
{

	ifvare CURRWEAP 7
	{
		ifvarl weaplev7 2
		{
			setvar temp RUNNINGSPEED
			shiftvarr temp 3
			setvar tempb RUNNINGSPEED
			subvarvar tempb temp
			setplayer[THISACTOR].runspeed tempb
		}
		else setplayer[THISACTOR].runspeed RUNNINGSPEED
	}
	else
	ifvare CURRWEAP 4 
	{
		
		ifvarl weaplev4 2
		{
			setvar temp RUNNINGSPEED
			shiftvarr temp 3
			setvar tempb RUNNINGSPEED
			subvarvar tempb temp
			setplayer[THISACTOR].runspeed tempb
		}
		else setplayer[THISACTOR].runspeed RUNNINGSPEED
		
	}
	else setplayer[THISACTOR].runspeed RUNNINGSPEED
	
	ifvare CURRWEAP 5 setvarvar PIPEBOMB_CONTROL pipecontrol
	
	ifvare CURRWEAP 3 
	{
		ifvarand ALTCHAINGUN 4 // switching chainguns
		{
			getplayer[THISACTOR].weapon_pos temp
			ifvare temp -9 { state changeminigun subvar ALTCHAINGUN 4 }
		}
		ifvarand ALTCHAINGUN 2
		{
			ifvarl player[THISACTOR].ammo_amount 3 1 ifvarand bits 4
			{
				ifvarvarl lastinput timer soundonce WEAPEMPTY
				setvarvar lastinput timer addvar lastinput 1
			}
			ifp palive
			ifvare CURRWEAP 3
			{
// 				ifvare player[THISACTOR].ammo_amount 3 0 ifvarg grenades 0
// 				{
// 					setplayer[THISACTOR].ammo_amount 3 1
// 					ifvarn KICKBACKPIC 0
// 					{
// 						setvar KICKBACKPIC 0
// 						setplayer[THISACTOR].kickback_pic 0
// 					}
// 				}
// 				
				ifvarn grenadecounter 0
				{
					ifvare grenadecounter 3
					{
						shoot MORTER2
						sound RPG_SHOOT
					}
					addvar grenadecounter 1
					ifvarg grenadecounter 25 setvar grenadecounter 0
				}
				ifvarn miniguncount 0 
				{
					ifvare gunframe 6208 setvar gunframe 6209 else
					ifvare gunframe 6209 setvar gunframe 6210 else
					ifvare gunframe 6210 setvar gunframe 6211 else
					ifvare gunframe 6211 setvar gunframe 6209 else
					setvar gunframe 6209
					
					ifvarl miniguncount MAXSPIN
					{
						stopactorsound THISACTOR MINISPINFAST
						soundonce MINISPINSLOW
					} else
					{
						stopactorsound THISACTOR MINISPINSLOW
						soundonce MINISPINFAST
					}
				}
				
			    ifvarand bits 4
			       addvar miniguncount 1
			    else
			    {
				   ifvarg miniguncount MINIFIRECOUNT setvar miniguncount MINIFIRECOUNT
				   ifvarg miniguncount 0 subvar miniguncount 1
			    }
				   
				ifvarn KICKBACKPIC 0
				{
					ifvarl miniguncount MINIFIRECOUNT 
						setplayer[THISACTOR].kickback_pic 0
					else ifvare KICKBACKPIC 11
					{
						setvar KICKBACKPIC 2
						getplayer[THISACTOR].ammo_amount 3 temp
						ifvare temp 0 setvar KICKBACKPIC 0
						setplayer[THISACTOR].kickback_pic KICKBACKPIC
					}
				}
				ifvarg miniguncount MINISPEEDCOUNT 
				{
					setvar WEAPON3_FLAGS 76
					ifvarg miniguncount MAXSPIN setvar miniguncount MAXSPIN
				} else
				setvar WEAPON3_FLAGS 84 
			}
			
		}
		else
		{
			getplayer[THISACTOR].ammo_amount 3 tempb
			ifvare tempb 0 ifvarand bits 4 
			{
				ifvarvarl lastinput timer soundonce WEAPEMPTY
				setvarvar lastinput timer addvar lastinput 1
			}

		}
	}
	
	ifvare CURRWEAP 1
	{
		ifvarn PISTOLRELOAD 0
		{
			getplayer[THISACTOR].ammo_amount 1 tempb
			subvarvar tempb botclip // tempb is the amount of ammo you have in excess of what is in clip
			setvarvar PISTOLRELOAD KICKBACKPIC
			ifvare akimbo -1 setvar temp 26 
			else ifvare akimbo 0 setvar temp 26 
			else setvar temp 47
			ifvare PISTOLRELOAD 0 setvar temp 0 // failsafe
			ifvarvare PISTOLRELOAD temp
			{
				ifvare akimbo -1 setvar tempc 12 else
				ifvare akimbo 0 setvar tempc 12 
				else setvar tempc 24 // CLIP SIZE
				subvarvar tempc botclip // tempc is now how much room is in the clip
				ifvarvarl tempb tempc // if you have less ammo than what the clip can hold
					addvarvar botclip tempb
				else
				{
					ifvare akimbo -1 setvar botclip 12 
					else ifvare akimbo 0 setvar botclip 12 
					else setvar botclip 24
				}
				
			}
		}
		else
		{
			getplayer[THISACTOR].ammo_amount 1 tempb
			ifvare tempb 0 
			ifvarand bits 4
			{
				ifvarvarl lastinput timer soundonce WEAPEMPTY
				setvarvar lastinput timer addvar lastinput 1
			}
			
			ifvarn player[THISACTOR].last_weapon 0
			ifvare botclip 0 ifvarg akimbo -2 ifvarl akimbo 2 ifvarg tempb 0
			ifvare player[THISACTOR].weapon_pos 0
			{
				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
			}
			else
			setvar WEAPON1_RELOAD 0
			
		}
			
	}
				
}

ifvarg monallies 0 subvar monallies 1

setplayer[THISACTOR].inven_icon invicon

// regeneration code
ifp palive
{
	getplayer[THISACTOR].max_player_health temp
	divvar temp 10
	ifvarvarl sprite[THISACTOR].extra temp
	{
		addvar regen 1
		ifvarg regen 29
		{
			addphealth 1
			sound DUKE_HARTBEAT
			setvar regen 0
			subvar score 100
		}
	}
}
	

// damage reduction code
getactor[THISACTOR].htextra temp
getuserdef[THISACTOR].god tempb
ifvare tempb YES setvar temp 0
ifvarg temp 0
{
	// adjust for difficulty level
	getuserdef[THISACTOR].player_skill tempc
	ifvare tempc 1 { shiftvarr temp 1 setactor[THISACTOR].htextra temp } else
	ifvare tempc 2 { mulvar temp 3 shiftvarr temp 2 setactor[THISACTOR].htextra temp }
	
	getactor[THISACTOR].htowner spriteid
	ifvarn spriteid -1 ifvarvarn spriteid THISACTOR
	{
		getactorvar[spriteid].playerally picnum
		ifvarn picnum 0
		{
			setvar temp -1
			setactor[THISACTOR].htextra -1
		}		
	}
	ifvare sprite[THISACTOR].htpicnum FREEZENOAIM
	{
		setvar temp -1
		setactor[THISACTOR].htextra -1
	}
	ifvare sprite[THISACTOR].htpicnum SHRAPNEL
	{
		setvar temp -1
		setactor[THISACTOR].htextra -1
	}
	ifvare sprite[THISACTOR].htpicnum STARPROJ
	{
		shiftvarr temp 1
		setactor[THISACTOR].htextra temp
	}
	ifvarg temp 0
	{
		ifvarg eshield 0
		{
			sound HITSHIELD
			setvar burning 0
			setvar temp -1
			setactor[THISACTOR].htextra -1
			stopsound PISTOL_BODYHIT
		}
		else
		{
			ifp ponsteroids ifvarg steroidlevel 0
			{
				setvarvar tempb steroidlevel
				ifvarl tempb 6
				shiftvarl tempb 2
				else ifvarl tempb 10
				{
					subvar tempb 5
					shiftvarl tempb 1
					addvar tempb 20
				}
				else
				{
					subvar tempb 10
					addvar tempb 30
				}
				ifvarg tempb 90 setvar tempb 90
				setvar tempc 100
				subvarvar tempc tempb
				mulvarvar temp tempc
				divvar temp 100
				setactor[THISACTOR].htextra temp
			}
			getplayer[THISACTOR].shield_amount tempb
			ifvarg tempb 0
			ifvarn sprite[THISACTOR].htpicnum INKBLAST ifvarn sprite[THISACTOR].htpicnum SPIT
			{
				// sound HITARMOR
				shiftvarr temp 1
				ifvarl temp 1 setvar temp 1
				else subvarvar tempb temp
				setactor[THISACTOR].htextra temp
				ifvarl tempb 0 setvar tempb 0
				setplayer[THISACTOR].shield_amount tempb
				setvar helmflash 20
			}
			ifvarvarg temp sprite[THISACTOR].extra
			ifvare picnum 0
			{
				ifvare sprite[spriteid].picnum BOTALLY globalsound EWASTED else
				ifvare sprite[spriteid].picnum BOTALLYCROUCH globalsound EWASTED
			}
		}
	}
	addvar temp 1
	ifvare rage FULLRAGE
	ifvarvarg temp sprite[THISACTOR].extra
	//ifvarvarn sprite[THISACTOR].htowner THISACTOR
	//ifvarn sprite[THISACTOR].htpicnum RADIUSEXPLOSION
	{
		subvar score 5000
		state dukepainsounds
		ifvarl score 0 setvar score 0
		subvar rage 1
		ifvarg weaptotal 59 strength 100 else
		strength 30
		setactor[THISACTOR].htextra -1
	}
}

ifvarg rage 0 ifvarl rage FULLRAGE // rage mode
ifp palive
{
	setvar hudcolor 12
	setvar burning 0
	ifvare rage 260
	{
		randvar tempb 3
		ifvare tempb 0 sound ASSKICKTIME else
		ifvare tempb 1 sound HADIT else
		ifvare tempb 2 sound DUKE_KILLED5 else
		ifvare tempb 3 sound BRINGITON
	}
	subvar rage 1
	setactor[THISACTOR].htextra -1
	ifvarl sprite[THISACTOR].extra 30
	strength 30
	ifvarg weaptotal 59 
	{ 
		ifvarl sprite[THISACTOR].extra 100 strength 100 
		ifvarand timer 1 addvar rage 1
		ifvare rage FULLRAGE subvar rage 1
	}
	ifvare rage 0 
		sound DUKE_GASP
	else
	{
		addvar rageang 314
		ifvarg weaptotal 59 addvar pdamage 200
		addvar pdamage 100
	}
}
else ifvarg sprite[THISACTOR].htextra 0 setvar hudcolor 6
else ifvarl sprite[THISACTOR].extra 31 setvar hudcolor 2
else ifvarl sprite[THISACTOR].extra 61 setvar hudcolor 23
else ifvarl sprite[THISACTOR].extra 91 setvar hudcolor 8 else
setvar hudcolor 1


setvar monstatus 1

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

ifvarg fpress 0 subvar fpress 1
ifvarg bpress 0 subvar bpress 1


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

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


getplayer[THISACTOR].player_par timer


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

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

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

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

ifvarg dodge 0 state dodgecode



ifp pdead nullop
 else 
  state stepsoundstuff
  

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

ifvarn raining 0 state raincode

  ifaction 0
    action PSTAND
  

  ifaction PFROZEN
  {
    cstat 257

    fall

    palfrom 16 0 0 24

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

        sound GLASS_BREAKING
        spawn ATOMICHEALTH

        getlastpal

        move 1
        break
      }
    }
    else
    {
      cstat 32768
      // quote 13
      setvar fta 100
	  setvar ftq 13
      ifvare truevolume 3 { state savescore setvar menutoggle 13 } else
      ifhitspace
      {
        action PSTAND
        resetplayer
      }
      break
    }

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

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

    break
  }

  ifdead
  {
    ifaction PGROWING
    {
      ifmove PGROWINGPOP
      {
        // quote 13
        setvar fta 100
	    setvar ftq 13
        ifvare truevolume 3 { state savescore setvar menutoggle 13 } else
        ifhitspace
        {
          action 0
          resetplayer
        }
        break
      }
      else
      {
        ifcount 32
        {
          sound SQUISHED
          palfrom 48 64

          state standard_pjibs

          guts JIBS4 20
          guts JIBS6 20
          move PGROWINGPOP
          cstat 32768
          tossweapon

          hitradius 2048 60 70 80 90

        }
        else
          sizeto MAXXSTRETCH MAXYSTRETCH
      }
      break
    }

    ifsquished
      palfrom 32 63 63 63
    else
      fall

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

    ifaction PLYINGDEAD
    {
      ifactioncount 3
        move PSTOPED
      //quote 13
      setvar fta 100
	  setvar ftq 13
      ifvare truevolume 3 { state savescore setvar menutoggle 13 } else
      ifhitspace
      {
        action PSTAND
        spawn DUKELYINGDEAD
        resetplayer
      }
      break
    }

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

    ifaction PEXPLODEAD
    {
      // quote 13
      setvar fta 100
	  setvar ftq 13
      ifvare truevolume 3 { state savescore setvar menutoggle 13 } else
      ifhitspace
      {
        resetplayer
        action PSTAND
      }
      break
    }
    ifaction PEXPLODE
    {
      ifactioncount 5
      {
        action PEXPLODEAD
        spawn BLOODPOOL
      }
      break
    }

    ifp pshrunk
    {
      state standard_pjibs
      spawn BLOODPOOL

      sound SQUISHED
      sound DUKE_DEAD

      cstat 32768         // Hide the sprite

      action PLYINGDEAD
    }
    else
    {
	  
	  ifinwater
      {
        action PLYINGDEAD
        spawn WATERBUBBLE
        spawn WATERBUBBLE
      }
      else
      {
        action PEXPLODE
        state standard_pjibs
        cstat 32768
        sound SQUISHED
        sound DUKE_DEAD
      }
    }

    tossweapon

    break
  }

  ifsquished
  {
    strength -1
    sound SQUISHED
    state random_ooz
    break
  }

  ifp ponsteroids
  {
    ifp pstanding nullop
    else
      spawn FRAMEEFFECT1
  }

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

      ifwasweapon GROWSPARK
      {
        palfrom 48 48
        action PGROWING
        count 0
        move 0
        sound ACTOR_GROWING
        cstat 0
        break
      }
    }
    else
    {
	  setplayer[THISACTOR].sound_pitch 0
      ifmultiplayer
      {
        ifphealthl YELLHURTSOUNDSTRENGTHMP
        {
          ifrnd 64
            sound DUKE_LONGTERM_PAIN2
          else
            ifrnd 64
              sound DUKE_LONGTERM_PAIN3
          else
            ifrnd 64
              sound DUKE_LONGTERM_PAIN4
          else
            sound DUKE_DEAD
        }
        else
        {
          ifrnd 64
            sound DUKE_LONGTERM_PAIN5
          else ifrnd 64
            sound DUKE_LONGTERM_PAIN6
          else ifrnd 64
            sound DUKE_LONGTERM_PAIN7
          else
            sound DUKE_LONGTERM_PAIN8
        }
      }
      else
      {
        ifphealthl YELLHURTSOUNDSTRENGTH
        {
          ifrnd 74
            sound DUKE_LONGTERM_PAIN2
          else
            ifrnd 8
              sound DUKE_LONGTERM_PAIN3
          else
            sound DUKE_LONGTERM_PAIN4
        }
        ifrnd 128
          sound DUKE_LONGTERM_PAIN
      }
    }
    ifstrength TOUGH
    {
      state headhitstate
      sound DUKE_GRUNT
      ifp pstanding
        action PFLINTCHING
    }

    ifwasweapon RPG
    {
      ifrnd 32
        spawn BLOOD
      ifdead
        state standard_pjibs
      palfrom 48 52
      break
    }
    ifwasweapon RADIUSEXPLOSION
    {
      ifrnd 32
        spawn BLOOD
      ifdead
        state standard_pjibs
      palfrom 48 52
      break
    }
    ifwasweapon FIREEXT
    {
      ifrnd 32
        spawn BLOOD
      ifdead
        state standard_pjibs
      palfrom 48 52
      break
    }
    ifwasweapon GROWSPARK
    {
      palfrom 48 52
      sound EXPANDERHIT
      break
    }
    ifwasweapon SHRINKSPARK
    {
      palfrom 48 0 48
      move PSHRINKING // used as a var only.
      sound ACTOR_SHRINKING
      cstat 0
      break
    }
    ifwasweapon SHOTSPARK1
      palfrom 24 48
    ifwasweapon STARPROJ
      palfrom 28 48
    ifwasweapon ICESHARD
      palfrom 28 24 0 48
    ifwasweapon FIREBALLPROJ
      palfrom 32 48
    ifwasweapon FIREBULLET
      palfrom 32 48
    ifwasweapon ELECTROPROJ
      palfrom 40 63 63 63
    ifwasweapon BIGFIRELASER
      palfrom 50 48 0 10
    ifwasweapon RAILSLUG_WEAK
      palfrom 32 48
    ifwasweapon COMETPROJ
      palfrom 32 42 16 16
    ifwasweapon INKBLAST
    {
      palfrom 40 0 0 0
      getplayer[THISACTOR].posxv xvel
      shiftvarr xvel 1
      getplayer[THISACTOR].posyv yvel
      shiftvarr yvel 1
      setplayer[THISACTOR].posxv xvel
      setplayer[THISACTOR].posyv yvel
    }
    ifwasweapon FREEZEBLAST
    ifvare rage 0
    {
      palfrom 48 0 0 48
      ifdead
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action PFROZEN
        break
      }
    }
    ifwasweapon COOLEXPLOSION1
      palfrom 48 48 0 48
    ifwasweapon KNEE
      palfrom 16 32
    ifwasweapon FIRELASER
      palfrom 32 32

    ifdead
    {
      action PTHROWNBACK
      tossweapon
    }

    state random_wall_jibs

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

  ifaction PFLINTCHING
  {
    ifactioncount 2
      action PSTAND
    break
  }

  ifinwater
  {
    ifaction PTREDWATER
    {
      ifp pwalking prunning
        action PSWIMMINGGO
    }
    else
      ifp pstanding pwalkingback prunningback
        action PTREDWATER
    else
    {
      ifaction PSWIMMING
      {
        ifrnd 4
          spawn WATERBUBBLE
        ifactioncount 4
          action PSWIMMINGWAIT
      }
      else
        ifaction PSWIMMINGWAIT
      {
        ifactioncount 2
          action PSWIMMINGGO
      }
      else
        ifaction PSWIMMINGGO
      {
        ifactioncount 2
          action PSWIMMING
      }
      else
        action PTREDWATER
    }

    ifrnd 4
      spawn WATERBUBBLE // For effect

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

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

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

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

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


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

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

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

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