
state camcloser
	cos xvel angvar
	sin yvel angvar
	mulvarvar xvel xydist
	mulvarvar yvel xydist
	divvarvar xvel framerate
	divvarvar yvel framerate
	shiftvarr xvel 13
	shiftvarr yvel 13

	movesprite viewcam xvel yvel 0 CLIPMASK0 RETURN
	ifvarn RETURN 0 
	{
		setactor[viewcam].x x
		setactor[viewcam].y y
		getplayer[THISACTOR].posz digz
		setactor[viewcam].z digz
		movesprite viewcam xvel yvel 0 CLIPMASK0 RETURN
 		ifvarn RETURN 0
 		setactorvar[viewcam].countvar 2
	}
ends

state viewcamposition

	getplayer[THISACTOR].i spriteid
	getactor[viewcam].x x
	getactor[viewcam].y y
	getactor[viewcam].z z
	
	getplayer[THISACTOR].posx digx
	getplayer[THISACTOR].posy digy
	getplayer[THISACTOR].posz digz
	
	
	ldist xydist viewcam spriteid
	getactor[spriteid].cstat temp
	ifvarl xydist 1024
	{
		orvar temp 514
		setactor[spriteid].cstat temp
	}
	else
	{
		ifvarand temp 512 xorvar temp 512
		setactor[spriteid].cstat temp
	}
	
	setvarvar temp xydist
	shiftvarl temp 1
	subvarvar digz temp
	
	updatesectorz x y z temp
	ifvare temp -1 getactor[viewcam].sectnum temp
	ifvarn temp -1
	{
		getflorzofslope temp x y tempb
		subvar tempb 4096
		ifvarvarg digz tempb setvarvar digz tempb
		
		getceilzofslope temp x y tempb
		addvar tempb 4096
		ifvarvarl digz tempb setvarvar digz tempb
		
		setactor[viewcam].z digz
		changespritesect viewcam temp
	}
	else setactor[viewcam].z digz
	
	subvarvar digx x
	subvarvar digy y
	getangle angvar digx digy
	setactor[viewcam].ang angvar
	getplayer[THISACTOR].posx digx
	getplayer[THISACTOR].posy digy
	
	setvar tempc 1
	updatesectorz scanx scany scanz tempb
	getactor[viewcam].sectnum mysector
	ifvarg tempb -1 ifvarg mysector -1 ifvarl tempb 4096 ifvarl mysector 4096
		cansee x y z mysector scanx scany scanz tempb tempc
	ifvarg xydist 3072 setvar tempc 0
	ifvare tempc 0
	ifvarg xydist 512
		state camcloser
	else	
	ifvarand extbits 2 ifvarl xydist 1536
	{
		setvarvar angvar1 angvar
		addvar angvar1 1024
		cos xvel angvar1
		sin yvel angvar1
		shiftvarl xvel 10
		shiftvarl yvel 10
		divvarvar xvel framerate
		divvarvar yvel framerate
		divvarvar xvel xydist
		divvarvar yvel xydist

		movesprite viewcam xvel yvel 0 CLIPMASK0 RETURN
		ifvarn RETURN 0
		{
			setactor[viewcam].x x
			setactor[viewcam].y y
			setactor[viewcam].z z
		}
	}
	
 	getplayer[THISACTOR].ang angvar1
	getactor[viewcam].ang angvar
	getincangle angvar2 angvar1 angvar
	setvarvar temp tolerance
	mulvar temp -1
	ifvarvarg angvar2 temp ifvarvarl angvar2 tolerance // the cam is facing the player's back, which is good
	{
		setvar tolerance CAMTOLERANCE1
		subvarvar x digx
		subvarvar y digy
		getangle rotcam x y // angle of player facing the camera
		setvar distlock -1
	}
	else // the cam is facing the player's front, which is bad
	// ifvarl xydist 4096 // attempt to swivel the camera around the player
	
	ifvare spinkick 0
	{
		setvar tolerance CAMTOLERANCE2
		ifvare distlock -1
		ldist distlock viewcam spriteid
		ifvarg distlock 4096 setvar distlock 4096
		setvarvar temp framerate
		shiftvarr temp 2
		ifvarg temp 96 setvar temp 96
		setvarvar tempb angvar2
		divvarvar tempb temp
		ifvare tempb 0 { ifvarg angvar2 0 setvar tempb 1 else ifvarl angvar2 0 setvar tempb -1 }
		setvarvar angvar2 tempb
		
		ifvarg angvar2 16 setvar angvar2 16
		ifvarl angvar2 -16 setvar angvar2 -16
		subvarvar rotcam angvar2
		setvarvar X digx
		addvarvar X distlock
		rotatepoint digx digy X digy rotcam x y
		updatesectorz x y z temp
		ifvarn temp -1
		{
			// now we use movesprite to move to the new coords
			getactor[viewcam].x mx
			getactor[viewcam].y my
			setvarvar X x
			setvarvar Y y
			subvarvar X mx
			subvarvar Y my
			getangle angvar X Y
			cos xvel angvar
			sin yvel angvar
			shiftvarr xvel 7
			shiftvarr yvel 7
			movesprite viewcam xvel yvel 0 CLIPMASK0 RETURN
			ifvarn RETURN 0
			{
				ifvarg distlock 640 subvar distlock 32
				setvar tolerance CAMTOLERANCE1 
				setactor[viewcam].x mx
				setactor[viewcam].y my
				ifvarg xydist 384
				  state camcloser
			}
			else
			{
					setactor[viewcam].x x
					setactor[viewcam].y y
					setactor[viewcam].z z
					changespritesect viewcam temp
			}
		}
		else 
		{
			ifvarg distlock 640 subvar distlock 32
			setvar tolerance CAMTOLERANCE1
			ifvarg xydist 384
			state camcloser
		}

	}
	
	
	
    getactor[viewcam].x camerax
    getactor[viewcam].y cameray
    getactor[viewcam].z cameraz
    getactor[viewcam].sectnum camerasect
    ifvare camerasect -1 getplayer[THISACTOR].cursectnum camerasect

    getplayer[THISACTOR].i spriteid
    getplayer[THISACTOR].posz digz
//     ifvarn superkicking 0
//     {
// 		getplayer[THISACTOR].posx digx
//  		getplayer[THISACTOR].posy digy
// 	}
// 	else
// 	{
// 		setvarvar digx scanx
// 		setvarvar digy scany
// 		ifp prunning nullop else
// 		ifvarn playertarg -1
// 		{
// 			getactor[playertarg].x digx
// 			getactor[playertarg].y digy
// 		}
// 		
// 	}

	getplayer[THISACTOR].posx digx
	getplayer[THISACTOR].posy digy
	
    subvarvar digx camerax
    subvarvar digy cameray
    getangle angvar1 digx digy
    ifvarn superkicking 0 setvarvar cameraang angvar1 else
    {
	    ldist xydist spriteid viewcam
	    ifvarl xydist 1 setvar xydist 1
	    getincangle angvar2 angvar1 cameraang
	    shiftvarr angvar2 1
	    subvarvar cameraang angvar2
    }
    
//     getplayer[THISACTOR].posx X
//     getplayer[THISACTOR].posy Y
// 	
//     subvarvar X camerax
//     subvarvar Y cameray
//     getangle angvar X Y
//     getincangle angvar2 angvar angvar1
//     mulvarvar angvar2 xydist
//     shiftvarr angvar2 13
//     ifvarl angvar2 1 setvar angvar2 1
//     subvarvar angvar1 angvar2
    
// 	getincangle temp cameraang lastcameraang
// 	ifvarl temp 2 ifvarg temp -2 nullop
// 	else
// 	{
// 		shiftvarr temp 2
// 		subvarvar lastcameraang temp
// 		setvarvar cameraang lastcameraang
// 	}


    subvarvar digz cameraz
    
    divvar xydist -8
    ifvare xydist 0 setvar xydist 1
    divvarvar digz xydist
    addvar digz 100
    getplayer[THISACTOR].horiz temp
    subvar temp 100
    shiftvarr temp 1
    addvarvar digz temp
    ifvarg digz 299 setvar digz 299
    ifvarl digz -199 setvar digz -199
    setvarvar camerahoriz digz
    setvarvar lastcameraang cameraang

ends

onevent EVENT_DISPLAYROOMS

ifvarn ONCAR 0 
	ifvarn camerasect -1
		setvarvar cameradist lastcameradist
else
setvarvar cameradist camzoomcontrol

ifvarg portalview 0
ifvarn portalcam -1
{
	getactor[portalcam].ang angvar
	
	getactorvar[portalcam].myspawner spriteid
	getactor[spriteid].ang tempc
	getplayer[screenpeek].ang tempb
	
	getincangle tempd tempc tempb
	addvarvar angvar tempd
	addvar angvar 1024
	
	getactorvar[portalcam].countvar temp
	ifvare temp -1 getplayer[screenpeek].horiz temp
	showview sprite[portalcam].x sprite[portalcam].y sprite[portalcam].z angvar temp sprite[portalcam].sectnum 0 0 319 199
}

ifvare perplayeronbike YES break


ifvarn camerasprite -1
{
	getactorvar[camerasprite].countvarb tempb
	ifvarand actorvar[camerasprite].monstflags 2 nullop else
	ifvarand actorvar[camerasprite].monstflags 16 ifvarl tempb 13 nullop else
	{
		getactor[camerasprite].x camerax
		getactor[camerasprite].y cameray
		getactor[camerasprite].z cameraz
		getactor[camerasprite].sectnum camerasect
		getactor[camerasprite].ang cameraang
		getactor[camerasprite].shade camerahoriz
		shiftvarl camerahoriz 1
		addvar camerahoriz 100
		break
	}
}

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




ifvarg framerate 0
ifvarn viewcam -1 state viewcamposition

endevent

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


onevent EVENT_ANIMATESPRITES

gettspr[THISACTOR].tsprstatnum temp
ifvare temp 10
{
	ifvarn viewcam -1
	{
	  gettspr[THISACTOR].tsprcstat temp
	  ifvarand temp 512 nullop else
	  {
		  ifvarand temp 2 
		      subvar temp 2
		  settspr[THISACTOR].tsprcstat temp
	  }
	}
}
else
{
	gettspr[THISACTOR].tsprpicnum picnum
	switch picnum
	case TEMPSPRITE
		gettspr[THISACTOR].tsprowner spriteid
		getactorvar[spriteid].monstflags temp
		settspr[THISACTOR].tsprpicnum temp
	break
	case EGGCORPSE
	case LIZTROOPCORPSE
	case OCTABRAINCORPSE
	case COMMANDERCORPSE
	case PIGCOPCORPSE
	case LIZMANCORPSE
	case BOSS1CORPSE
	case BOSS2CORPSE
	case BOSS3CORPSE
	case NEWBEASTCORPSE
	case BOSS4CORPSE
	gettspr[THISACTOR].tsprowner spriteid
	getactor[spriteid].yrepeat digy
	addvar digy 10
	settspr[THISACTOR].tspryrepeat digy
	break
	case BLOODPOOL
	gettspr[THISACTOR].tsprowner spriteid
	ifvare actorvar[spriteid].mtype 6
	settspr[THISACTOR].tsprpal 8
	break
	case SMOKEGUST
	  gettspr[THISACTOR].tsprowner spriteid
	  setvarvar mx camerax
	  setvarvar my cameray
	  subvarvar mx sprite[spriteid].x
	  subvarvar my sprite[spriteid].y
	  getangle angvar mx my
	  settspr[THISACTOR].tsprang angvar
	break
	default break
	endswitch
}

gettspr[THISACTOR].tsprowner spriteid
ifvarvare spriteid holding
ifvare player[THISACTOR].over_shoulder_on NO
{
	setvarvar digx camerax
	addvar digx 400
	rotatepoint camerax cameray digx cameray cameraang mx my
	settspr[THISACTOR].tsprx mx
	settspr[THISACTOR].tspry my
}
ifvarg beamhit 0
ifvare sprite[spriteid].htpicnum POWBEAM
{
	gettspr[THISACTOR].tsprpal temp
	ifvare temp 6 settspr[THISACTOR].tsprpal sprite[spriteid].pal else
	ifvarand timer 1 settspr[THISACTOR].tsprpal 6
	settspr[THISACTOR].tsprshade -127
}

// code to prevent items from disappearing in shallow water
ifvare actorvar[spriteid].position 32768
{

	getactor[spriteid].sectnum temp
	ifvarn temp -1
	{
		getsector[temp].lotag tempb
		ifvare tempb 1
		{
			getflorzofslope temp sprite[spriteid].x sprite[spriteid].y digz
			getactor[spriteid].z mz
			subvarvar digz mz
			ifvarl digz 1024 // on the floor
			{		
				setvarvar temp timer
				shiftvarl temp 5
				addvarvar temp spriteid
				sin tempb temp
				shiftvarr tempb 4
				getactor[spriteid].z mz
				
				subvarvar mz tempb
				subvar mz 4096
				settspr[THISACTOR].tsprz mz
			}
		}
	}
}
ifvare actorvar[spriteid].position 65536
{
	settspr[THISACTOR].tsprshade -127
	settspr[THISACTOR].tsprpal 6
}

endevent

onevent EVENT_DISPLAYCROSSHAIR

ifvarn menutoggle 0 setvar RETURN -1
ifvare perplayeronbike -1 ifvarn viewcam -1 setvar RETURN -1
ifvarn cannonid -1 setvar RETURN -1
ifvarn camerasprite -1 setvar RETURN -1
endevent

state quotedisplay

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

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

ends

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

endevent

onevent EVENT_DISPLAYSBAR
ifvarn ONCAR 0
setvar RETURN -1

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

state sidekickcoords

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

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

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

state spinkickcoords

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

	ifvarl superkicking 3
	{
		setvar picnum 6339
		setvar angvar 0
		switch superkicking
		case 1
		ifvare superkickdone 1 setvar digx 290 else
		setvar digx 140	
		setvar digy 184

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


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

state adjustleftpos

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


state idleakimbo

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

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

state initweapondisplay

ifvare currentweapon 3 ifvarand ALTCHAINGUN 2
{
	setvar digx 190
 	setvar digy 235
 	setvar digz 65536
}
else
{
 	setvar digx 140
 	setvar digy 230
 	setvar digz 28672
}

 setvar angvar 0
 setvar orientation 0

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

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

ifoutside getsector[THISACTOR].ceilingshade shade else
getsector[THISACTOR].floorshade shade
getsector[THISACTOR].floorpal pal
ifvarg pal 13 setvar pal 0
ends

state displayshells

ifvare SHOTGUNCLIP 0 break
setvar pal 0
setvar orientation 256
setvar picnum 8613
setvar digx 10
setvar digy 150
ifvarn perplayeronbike -1 { subvar digy 5 setvar digx 280 }
setvar digz 6144
setvar shade 15

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

ends

state displaydbshotgun

state initweapondisplay

setvar digz 131072

// setvar digz 65536 for 8bit

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

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

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

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

state displaymossberg

state initweapondisplay
setvar digz 131072

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


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

guniqhudid 3
rotatesprite digx digy digz angvar picnum shade pal orientation 0 0 xdim ydim
guniqhudid 0
state displayshells

ends

state displaypistolbullets

ifvare botclip 0 break
setvar pal 0
setvar orientation 256
ifvare depistols YES
setvar digz 20480
else 
setvar digz 16384

setvar picnum SHELL
setvar digx 5
setvar digy 152
ifvarn perplayeronbike -1 { subvar digy 5 setvar digx 280 }
setvar shade 0

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

ends


state displaymp5bullets
ifvare MP5INCLIP 0 break
setvar pal 0
setvar orientation 256
setvar picnum SHELL
setvar digx 5
setvar digy 152
ifvarn perplayeronbike -1 { subvar digy 5 setvar digx 280 }
setvar digz 16384
setvar shade 0

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

ends

state displaymp5

state initweapondisplay

setvar digz 131072

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

ends

state grenadeadjust
setvarvar temp grenadecounter
ifvarg temp 2 ifvarl temp 11
{
	ifvarl temp 7
	{
		mulvar temp 5144
		addvarvar digz temp
	} else
	{
		addvar digz 20576
		subvar temp 5
		mulvar temp 5144
		subvarvar digz temp
	}
}
ends

state displayminigun
	
	getplayer[screenpeek].ammo_amount 3 temp
	ifvarg miniguncount MINIFIRECOUNT ifvarg temp 1
	{
		setvar x 177
		setvar y 204
		setvar z 65536 
		subvarvar x looking_angSR1
		addvarvar y looking_arc
		subvarvar y gun_pos
		addvarvar x weapon_xoffset
		state grenadeadjust
		displayrandvar angvar 2048
		rotatesprite x y z angvar 6212 -127 0 33 0 0 xdim ydim
		addvar angvar 1024
		rotatesprite x y z angvar 6212 -127 0 33 0 0 xdim ydim
	}
 	state initweapondisplay
 	state grenadeadjust
	getplayer[screenpeek].ammo_amount 3 temp
	ifvarg miniguncount MINIFIRECOUNT ifvarg temp 0
	{
		setvar temp 0
		displayrandvar temp 3
		ifvarl temp 6 mulvar temp -1
		addvarvar digx temp
		displayrandvar temp 2
		ifvarl temp 4 mulvar temp -1
		addvarvar digy temp
	}
	ifvare miniguncount MAXSPIN
	{
		ifvare lastdispframe 6208 setvar lastdispframe 6209 else
		ifvare lastdispframe 6209 setvar lastdispframe 6210 else
		ifvare lastdispframe 6210 setvar lastdispframe 6211 else
		ifvare lastdispframe 6211 setvar lastdispframe 6209
		rotatesprite digx digy digz angvar lastdispframe shade pal orientation 0 0 xdim ydim
	}
	else
	{
		rotatesprite digx digy digz angvar gunframe shade pal orientation 0 0 xdim ydim
		setvarvar lastdispframe gunframe
	}
ends

state displaydukeballs

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

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

ends

state displaykicks
// superkick display
getplayer[THISACTOR].over_shoulder_on temp
ifvarn superkicking 0 ifvare temp 0
{
	setvar orientation 0
	setvar angvar 0
	//setvar digz 34816
	setvar digz 32768
	ifvare spinkick 0 state sidekickcoords
	else state spinkickcoords
	getuserdef[THISACTOR].screen_size C
	ifvarg C 4 subvar digy 16
	getplayer[THISACTOR].palookup pal
	rotatesprite digx digy digz angvar picnum shade pal orientation 0 0 xdim ydim
}
ends

state displayimpgun

 setvar digx 160
 setvar digy 190 // 220
 setvar digz 65536
 setvar angvar 0

setvarvar temp looking_angSR1
shiftvarr temp 1
subvarvar digx temp
addvarvar digy looking_arc
setvarvar temp gun_pos
shiftvarr temp 1
subvarvar digy temp
ifvare weaponcount 0 addvarvar digx weapon_xoffset
else addvar digx 12


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


ifvarg wow 0
{
	ifvarand gunparts 8 ifvarand gunparts 4
	setvar picnum 6843
	else ifvarand gunparts 4
	setvar picnum 6849
	else
	setvar picnum 6846
}
else
ifvare weaponcount 0
{
	ifvarand gunparts 8 ifvarand gunparts 4
	setvar picnum 6840
	else
	ifvarand gunparts 4
	setvar picnum 6847
	else
	setvar picnum 6844
}
else
{
	ifvarand gunparts 8 ifvarand gunparts 4
	{
		ifvare WEAPON7_SHOOTS POWBALL setvar picnum 6842 else
		setvar picnum 6841
	}
	else
	ifvarand gunparts 4
	setvar picnum 6848
	else
	setvar picnum 6845
}

guniqhudid 10
rotatesprite digx digy digz angvar picnum shade 0 0 0 0 xdim ydim

ends

state laserhud
ifvarg LASERCHARGE 0
{
	setvar digx 4
	setvar digz 16384
	setvar orientation 256
	ifvarg LASERCHARGE 25 
	{
		setvarvar temp timer
		ifvarand temp 1 setvar pal 6 else setvar pal 2
	}
	else setvar pal 2
	setvarvar tempb LASERCHARGE
	ifvarg tempb 26 setvar tempb 26
	setvarvar tempc digx
	addvarvar tempc tempb
	setvar temp 0
	whilevarn temp 1
	{
		  ifvarvarg digx tempc setvar temp 1
		  else
		  rotatesprite digx 145 digz 0 199 0 pal orientation 0 0 xdim ydim
		  addvar digx 1
		  break
	}
	gametextz 2822 9 142 1146 0 7 256 0 0 xdim ydim 24576
	
}

setvar digx 4
setvar digz 16384
setvar orientation 256
setvarvar tempb LASERAMMO
shiftvarr tempb 1
setvarvar tempc digx
addvarvar tempc tempb
setvar temp 0
whilevarn temp 1
{
	  ifvarvarg digx tempc setvar temp 1
	  else
	  rotatesprite digx 155 digz 0 199 0 7 orientation 0 0 xdim ydim
	  addvar digx 1
	  break
}
gametextz 2822 9 152 1147 0 7 orientation 0 0 xdim ydim 24576

ends

state displaylaserpistol

ifvarg LASERFIRE 1 ifvarl LASERFIRE 4 // display muzzleflash
ifvare weap BIGFIRELASER
{
	setvar digx 180
	setvar digy 240
	setvar angvar 0

	subvarvar digx looking_angSR1
	addvarvar digy looking_arc
	subvarvar digy gun_pos
	addvarvar digx weapon_xoffset
	subvar digy 51
	displayrandvar angvar 2047
	rotatesprite digx digy 98304 angvar 6152 0 0 0 0 0 xdim ydim
}

state laserhud


 setvar digx 175
 setvar digy 245
 setvar digz 65536
 setvar angvar 0
 setvar orientation 0

ifvare LASERFIRE 0
{
subvarvar digx looking_angSR1
addvarvar digy looking_arc
subvarvar digy gun_pos
addvarvar digx weapon_xoffset
}
else 
{
	subvar digy 65
	addvar digx 25
}

ifoutside getsector[THISACTOR].ceilingshade shade else
getsector[THISACTOR].floorshade shade
getsector[THISACTOR].floorpal pal
ifvare pal 4 { addvar shade 10 setvar pal 0 }

setvar picnum 6146

ifvarg LASERFIRE 1 //shooting
{
	ifvarl LASERFIRE 4
	{
		setvar picnum 6147
		ifvare LASERFIRE 2 
		{
			subvar digy 4
			addvar digz 4096
		}
		else
		{
			subvar digy 8
			addvar digz 8192
		}
		
	}
	else ifvarl LASERFIRE 8
	{
		ifvarl LASERFIRE 6 setvar picnum 6148
		else setvar picnum 6149
		setvar digz 73728
		subvar digy 8
		ifvare LASERFIRE 5
		{
			subvar digz 4096
			subvar digy 4
		}
		else ifvarg LASERFIRE 5
		{
			setvar digz 65536
			addvar digy 6 // 8
		}
	}
	
} else ifvarg LASERCHARGE 0
{
	setvar digz 69632
	displayrandvar temp 4
	subvar digx 2
	addvarvar digx temp
	displayrandvar temp 3
	addvar digy 1
	subvarvar digy temp
}

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


ends

state cannonhud
rotatesprite 160 100 81920 0 6172 0 0 0 0 0 xdim ydim
ends

state leftpistolshoots

		setvar digx 90
		setvar digy 244
		ifvarg C 4 subvar digy 16
		state adjustleftpos
		setvar picnum 2525 // LEFTPISTOL
		ifvare weaponcount 7 addvar picnum 1
		ifvare weaponcount 9 addvar picnum 1
		setvar orientation 4
		setvar shade -127
		guniqhudid 1
		rotatesprite digx digy digz 1024 picnum shade pal orientation 0 0 xdim ydim
		guniqhudid 5
		setvar picnum 2524 // RIGHT PISTOL
		setvar orientation 0
		setvar digx 90
		setvar digy 244
		ifvarg C 4 subvar digy 16
		state adjustrightpos
		addvar digx 120
		ifoutside getsector[THISACTOR].ceilingshade shade else
		getsector[THISACTOR].floorshade shade
		rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
		guniqhudid 0

ends

state rightpistolshoots

	setvar digx 90
	setvar digy 244
	ifvarg C 4 subvar digy 16
	state adjustleftpos
	guniqhudid 1
	setvar picnum 2524 // LEFTPISTOL
	setvar orientation 4
	rotatesprite digx digy digz 1024 picnum shade pal orientation 0 0 xdim ydim
	guniqhudid 5
	setvar picnum 2525 // RIGHT PISTOL FIRING
	ifvare weaponcount 3 addvar picnum 1
	setvar orientation 0
	setvar digx 90
	setvar digy 244
	ifvarg C 4 subvar digy 16
	state adjustrightpos
	addvar digx 120
	setvar shade -127
	rotatesprite digx digy digz 0 picnum shade pal orientation 0 0 xdim ydim
	guniqhudid 0

ends

onevent EVENT_DRAWWEAPON


ifvarn cannonid -1
{
	state cannonhud
	setvar RETURN -1
	break
}
ifvarn mantling 0 { setvar RETURN -1 break }
ifvarn ONCAR 0 { setvar RETURN -1 break }
ifvarn camerasprite -1 
{ 
	ifvarand actorvar[camerasprite].monstflags 2 nullop 
	else
	{
		setvar RETURN -1 
		break 
	}
}

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

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

ifvare currentweapon 0 
{
	ifvarg LASERAMMO 0 { state displaylaserpistol break }
	else
	ifvarg LASERFIRE 0 { state displaylaserpistol break }
}
ifvare currentweapon 1 state displaypistolbullets


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

ifvare useakimbo YES nullop else break

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

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

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

endevent

onevent EVENT_DISPLAYREST

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

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

state quotedisplay

ifvarn menutoggle 0
{
	setvar digx 160
	setvar digy 90
	setvar digz 40960 //32768
	setvar shade 0
	setvar pal 0
	setvar orientation 0
	// make the background optional
	// rotatesprite digx digy digz 0 6313 shade pal 33 0 0 xdim ydim
	ifvare menutoggle 1 // main menu
	{
		rotatesprite 128 32 16384 0 6320 0 0 0 0 0 xdim ydim
		setvar picnum 2822 // regular font
		ifvare menuitem 0 state shadepulse else setvar shade 0 // WEAPONS
		gametextz picnum 170 48 1017 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 1 state shadepulse else setvar shade 0 // ABILITIES
		gametextz picnum 170 56 1018 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 2 state shadepulse else setvar shade 0 // MONSTERS
		gametextz picnum 170 64 1019 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 3 state shadepulse else setvar shade 0 // EFFECTS
		gametextz picnum 170 72 1020 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 4 state shadepulse else setvar shade 0 // WEATHER
		gametextz picnum 170 80 1015 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 5 state shadepulse else setvar shade 0
		gametextz picnum 170 88 1150 shade 0 orientation 0 0 xdim ydim 40960
// 		gametextz picnum 170 88 1021 shade 0 orientation 0 0 xdim ydim 40960 // GAME SPEED
// 		digitalnumberz 2837 240 88 gamespeed_display shade 0 orientation 0 0 xdim ydim 40960
		
		ifvare menuitem 6 state shadepulse else setvar shade 0 // restore DUKE PLUS defaults
		gametextz picnum 170 96 1070 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 7 state shadepulse else setvar shade 0 // restore CLASSIC defaults
		gametextz picnum 170 104 1080 shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 8 state shadepulse else setvar shade 0
		gametextz picnum 170 112 1022 shade 2 orientation 0 0 xdim ydim 40960 // return to game
		gametextz picnum 220 152 1066 0 2 orientation 0 0 xdim ydim 40960 // instructions
		gametextz picnum 220 160 1057 0 2 orientation 0 0 xdim ydim 40960 // instructions
		
	} else
	ifvare menutoggle 2 // weapons submenu
	{
		//gametextz picnum x y quote shade pal orientation 0 0 xdim ydim scale
		setvar picnum 2822 // regular font
		gametextz picnum 170 33 1023 shade 0 orientation 0 0 xdim ydim 65536
		
		// karate kicks YES or NO
		ifvare menuitem 9 state shadepulse else setvar shade 0
		gametextz picnum 170 48 1125 shade 0 orientation 0 0 xdim ydim 40960
		ifvare karate YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 48 temp shade 0 orientation 0 0 xdim ydim 40960
		// akimbo pistols YES or NO
		ifvare menuitem 10 state shadepulse else setvar shade 0
		gametextz picnum 170 56 1024 shade 0 orientation 0 0 xdim ydim 40960
		ifvare useakimbo YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 56 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// de pistols YES or NO
		ifvare menuitem 11 state shadepulse else setvar shade 0
		gametextz picnum 170 64 1182 shade 0 orientation 0 0 xdim ydim 40960
		ifvare depistols YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 64 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// mossberg YES or NO
		ifvare menuitem 12 state shadepulse else setvar shade 0
		gametextz picnum 170 72 1025 shade 0 orientation 0 0 xdim ydim 40960
		ifvare usemossberg YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 72 temp shade 0 orientation 0 0 xdim ydim 40960
		// mp5 YES or NO
		ifvare menuitem 13 state shadepulse else setvar shade 0
		gametextz picnum 170 80 1026 shade 0 orientation 0 0 xdim ydim 40960
		ifvare usemp5 YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 80 temp shade 0 orientation 0 0 xdim ydim 40960
		// alt RPG YES or NO
		ifvare menuitem 14 state shadepulse else setvar shade 0
		gametextz picnum 170 88 1027 shade 0 orientation 0 0 xdim ydim 40960
		ifvare usebigrox YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 88 temp shade 0 orientation 0 0 xdim ydim 40960
		// better pipebomb throws YES or NO
		ifvare menuitem 15 state shadepulse else setvar shade 0
		gametextz picnum 170 96 1155 shade 0 orientation 0 0 xdim ydim 40960
		ifvare pipethrow YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 96 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// mindblast on alt SHRINKER YES or NO
		ifvare menuitem 16 state shadepulse else setvar shade 0
		gametextz picnum 170 104 1081 shade 0 orientation 0 0 xdim ydim 40960
		ifvare usemindblast YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 104 temp shade 0 orientation 0 0 xdim ydim 40960
		// gravity gun YES or NO
		ifvare menuitem 17 state shadepulse else setvar shade 0
		gametextz picnum 170 112 1028 shade 0 orientation 0 0 xdim ydim 40960
		ifvare gravgun YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 112 temp shade 0 orientation 0 0 xdim ydim 40960
		// use bfg YES or NO
		ifvare menuitem 18 state shadepulse else setvar shade 0
		gametextz picnum 170 120 1085 shade 0 orientation 0 0 xdim ydim 40960
		ifvarn usebfg 0 setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 120 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// dukemon YES or NO
		ifvare menuitem 19 state shadepulse else setvar shade 0
		gametextz picnum 170 128 1095 shade 0 orientation 0 0 xdim ydim 40960
		ifvare dukemon YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 128 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// Freezer Plus YES or NO
		ifvare menuitem 20 state shadepulse else setvar shade 0
		gametextz picnum 170 136 1160 shade 0 orientation 0 0 xdim ydim 40960
		ifvare altfreeze YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 136 temp shade 0 orientation 0 0 xdim ydim 40960
		
		
		// knockback distance
		ifvare menuitem 21 state shadepulse else setvar shade 0
		gametextz picnum 170 144 1030 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 144 knockdist shade 0 orientation 0 0 xdim ydim 40960
		// exit menu
		ifvare menuitem 22 state shadepulse else setvar shade 0
		gametextz picnum 170 152 1058 shade 2 orientation 0 0 xdim ydim 40960
	} else
	ifvare menutoggle 3 // abilities submenu
	{
		//gametextz picnum x y quote shade pal orientation 0 0 xdim ydim scale
		//setvar picnum 2908 // red font
		setvar picnum 2822 // regular font
		gametextz picnum 170 33 1033 shade 0 orientation 0 0 xdim ydim 65536
		// real running YES or NO
		ifvare menuitem 30 state shadepulse else setvar shade 0
		gametextz picnum 170 48 1034 shade 0 orientation 0 0 xdim ydim 40960
		ifvare slowrunaccel YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 48 temp shade 0 orientation 0 0 xdim ydim 40960
		// mantling YES or NO
		ifvare menuitem 31 state shadepulse else setvar shade 0
		gametextz picnum 170 56 1035 shade 0 orientation 0 0 xdim ydim 40960
		ifvare canmantle YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 56 temp shade 0 orientation 0 0 xdim ydim 40960
		// dodging YES or NO
		ifvare menuitem 32 state shadepulse else setvar shade 0
		gametextz picnum 170 64 1036 shade 0 orientation 0 0 xdim ydim 40960
		ifvare candodge YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 64 temp shade 0 orientation 0 0 xdim ydim 40960
		// grabbing YES or NO
		ifvare menuitem 33 state shadepulse else setvar shade 0
		gametextz picnum 170 72 1037 shade 0 orientation 0 0 xdim ydim 40960
		ifvare cangrab YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 72 temp shade 0 orientation 0 0 xdim ydim 40960
		// store health YES or NO
		ifvare menuitem 34 state shadepulse else setvar shade 0
		gametextz picnum 170 80 1038 shade 0 orientation 0 0 xdim ydim 40960
		ifvare storehealth YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 80 temp shade 0 orientation 0 0 xdim ydim 40960
		// max medkit
		ifvare menuitem 35 state shadepulse else setvar shade 0
		gametextz picnum 170 88 1039 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 242 88 maxmedkit shade 0 orientation 0 0 xdim ydim 40960
		// store health YES or NO
		ifvare menuitem 36 state shadepulse else setvar shade 0
		gametextz picnum 170 96 1040 shade 0 orientation 0 0 xdim ydim 40960
		ifvare steroidkicks YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 96 temp shade 0 orientation 0 0 xdim ydim 40960
		// holoduke lightning YES or NO
		ifvare menuitem 37 state shadepulse else setvar shade 0
		gametextz picnum 170 104 1041 shade 0 orientation 0 0 xdim ydim 40960
		ifvare holodukebot YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 104 temp shade 0 orientation 0 0 xdim ydim 40960
		// goggles reveal dip switch patterns YES or NO
		ifvare menuitem 38 state shadepulse else setvar shade 0
		gametextz picnum 170 112 1042 shade 0 orientation 0 0 xdim ydim 40960
		ifvare goggleswitches YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 112 temp shade 0 orientation 0 0 xdim ydim 40960
		// better armor YES or NO
		ifvare menuitem 39 state shadepulse else setvar shade 0
		gametextz picnum 170 120 1149 shade 0 orientation 0 0 xdim ydim 40960
		ifvare goodarmor YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 120 temp shade 0 orientation 0 0 xdim ydim 40960
		
		ifvare menuitem 40 state shadepulse else setvar shade 0
		gametextz picnum 170 128 1167 shade 0 orientation 0 0 xdim ydim 40960
		ifvare newjetpack YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 128 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// exit menu
		ifvare menuitem 41 state shadepulse else setvar shade 0
		gametextz picnum 170 136 1058 shade 2 orientation 0 0 xdim ydim 40960
		
	} else
	ifvare menutoggle 4 // monsters submenu
	{
		//gametextz picnum x y quote shade pal orientation 0 0 xdim ydim scale
		setvar picnum 2822 // regular font
		gametextz picnum 170 33 1043 shade 0 orientation 0 0 xdim ydim 65536
		
		ifvare menuitem 50 state shadepulse else setvar shade 0
		gametextz picnum 170 48 1044 shade 0 orientation 0 0 xdim ydim 40960
		// monster life bars YES or NO
		ifvare lifebars YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 48 temp shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 51 state shadepulse else setvar shade 0
		gametextz picnum 170 56 1045 shade 0 orientation 0 0 xdim ydim 40960
		// random attributes
		digitalnumberz 2837 240 56 randomize shade 0 orientation 0 0 xdim ydim 40960
		
		// damage inflicted by monsters
		ifvare menuitem 52 state shadepulse else setvar shade 0
		gametextz picnum 170 64 1068 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 64 mdamage shade 0 orientation 0 0 xdim ydim 40960
		ifvare menuitem 53 state shadepulse else setvar shade 0
		gametextz picnum 170 72 1069 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 72 pdamage shade 0 orientation 0 0 xdim ydim 40960
		
		// monster in-fighting
		ifvare menuitem 54 state shadepulse else setvar shade 0
		gametextz picnum 170 80 1087 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 80 infighting shade 0 orientation 0 0 xdim ydim 40960
		
		// use lasers YES or NO
		ifvare menuitem 55 state shadepulse else setvar shade 0
		gametextz picnum 170 88 1029 shade 0 orientation 0 0 xdim ydim 40960
		ifvare uselaser YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 88 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// double monsters YES or NO
		ifvare menuitem 56 state shadepulse else setvar shade 0
		gametextz picnum 170 96 1098 shade 0 orientation 0 0 xdim ydim 40960
		ifvare doubled YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 96 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// pigcops with db shotguns
		ifvare menuitem 57 state shadepulse else setvar shade 0
		gametextz picnum 170 104 1104 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 104 killerpigs shade 0 orientation 0 0 xdim ydim 40960
		
		// smart monsters
		ifvare menuitem 58 state shadepulse else setvar shade 0
		gametextz picnum 170 112 1064 shade 0 orientation 0 0 xdim ydim 40960
		ifvare smartmonsters YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 112 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// return to main menu
		ifvare menuitem 59 state shadepulse else setvar shade 0
		gametextz picnum 170 120 1058 shade 2 orientation 0 0 xdim ydim 40960
		setvar shade 0
		
	} else
	ifvare menutoggle 5 // effects submenu
	{
		//gametextz picnum x y quote shade pal orientation 0 0 xdim ydim scale
		setvar picnum 2822 // regular font
		gametextz picnum 170 33 1047 shade 0 orientation 0 0 xdim ydim 65536
		// damage effects YES or NO
		ifvare menuitem 70 state shadepulse else setvar shade 0
		gametextz picnum 170 48 1048 shade 0 orientation 0 0 xdim ydim 40960
		ifvare effects YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 48 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// map mirroring
		ifvare menuitem 71 state shadepulse else setvar shade 0
		gametextz picnum 170 56 1096 shade 0 orientation 0 0 xdim ydim 40960
		ifvare mirrored YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 56 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// map scaling 2X
		ifvare menuitem 72 state shadepulse else setvar shade 0
		gametextz picnum 170 64 1097 shade 0 orientation 0 0 xdim ydim 40960
		ifvare scaled YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 64 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// DP sounds
		ifvare menuitem 73 state shadepulse else setvar shade 0
		gametextz picnum 170 72 1105 shade 0 orientation 0 0 xdim ydim 40960
		ifvare dpsounds YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 72 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// quote style
		ifvare menuitem 74 state shadepulse else setvar shade 0
		gametextz picnum 170 80 1122 shade 0 orientation 0 0 xdim ydim 40960
		ifvare quotestyle 1 setvar temp 1119 else ifvare quotestyle 0 setvar temp 1121
		else setvar temp 1120
		gametextz picnum 470 80 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// hires blood
		ifvare menuitem 75 state shadepulse else setvar shade 0
		gametextz picnum 170 88 1127 shade 0 orientation 0 0 xdim ydim 40960
		ifvarand morefx 1 setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 88 temp shade 0 orientation 0 0 xdim ydim 40960
		gametextz picnum 340 88 1126 shade 0 orientation 0 0 xdim ydim 40960
		
		// water splashes
		ifvare menuitem 76 state shadepulse else setvar shade 0
		gametextz picnum 170 96 1128 shade 0 orientation 0 0 xdim ydim 40960
		ifvarand morefx 2 setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 96 temp shade 0 orientation 0 0 xdim ydim 40960
		gametextz picnum 340 96 1126 shade 0 orientation 0 0 xdim ydim 40960
		
		// pigcop jibs
		ifvare menuitem 77 state shadepulse else setvar shade 0
		gametextz picnum 170 104 1129 shade 0 orientation 0 0 xdim ydim 40960
		ifvarand morefx 4 setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 104 temp shade 0 orientation 0 0 xdim ydim 40960
		gametextz picnum 340 104 1126 shade 0 orientation 0 0 xdim ydim 40960
			
		// smoke
		ifvare menuitem 78 state shadepulse else setvar shade 0
		gametextz picnum 170 112 1130 shade 0 orientation 0 0 xdim ydim 40960
		ifvarand morefx 8 setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 112 temp shade 0 orientation 0 0 xdim ydim 40960
		gametextz picnum 340 112 1126 shade 0 orientation 0 0 xdim ydim 40960
		
		// enemy muzzleflashes
		ifvare menuitem 79 state shadepulse else setvar shade 0
		gametextz picnum 170 120 1159 shade 0 orientation 0 0 xdim ydim 40960
		ifvarand morefx 16 setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 120 temp shade 0 orientation 0 0 xdim ydim 40960
		gametextz picnum 340 120 1126 shade 0 orientation 0 0 xdim ydim 40960
		
		// view mode
		ifvare menuitem 80 state shadepulse else setvar shade 0
		gametextz picnum 170 128 1156 shade 0 orientation 0 0 xdim ydim 40960
		ifvare viewmode YES setvar temp 1158 else setvar temp 1157
		gametextz picnum 470 128 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// Duke Taunts Plus
		ifvare menuitem 81 state shadepulse else setvar shade 0
		gametextz picnum 170 136 1162 shade 0 orientation 0 0 xdim ydim 40960
		ifvare moretalk YES setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 136 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// Show or Disable character models
		ifvare menuitem 82 state shadepulse else setvar shade 0
		gametextz picnum 170 144 1164 shade 0 orientation 0 0 xdim ydim 40960
		ifvarand morefx 32 setvar temp 1054 else setvar temp 1053 // reversed on purpose
		gametextz picnum 470 144 temp shade 0 orientation 0 0 xdim ydim 40960
		
		// return to main menu
		ifvare menuitem 83 state shadepulse else setvar shade 0
		gametextz picnum 170 152 1058 shade 2 orientation 0 0 xdim ydim 40960
		
		
	} else
	ifvare menutoggle 6 // weather menu
	{
		setvar picnum 2822 // regular font
		gametextz picnum 170 33 1015 shade 0 orientation 0 0 xdim ydim 65536
		// weather type RAIN or SNOW
		ifvare menuitem 90 state shadepulse else setvar shade 0
		gametextz picnum 170 48 1049 shade 0 orientation 0 0 xdim ydim 40960
		ifvarl raining 0 setvar temp 1056 else setvar temp 1055
		gametextz picnum 470 48 temp shade 0 orientation 0 0 xdim ydim 40960
		// rain color
		ifvare menuitem 91 state shadepulse else setvar shade 0
		gametextz picnum 170 56 1050 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 56 rainpal shade rainpal orientation 0 0 xdim ydim 40960
		// rain transparency
		ifvare menuitem 92 state shadepulse else setvar shade 0
		gametextz picnum 170 64 1051 shade 0 orientation 0 0 xdim ydim 40960
		ifvarand raincstat 512 setvar temp 1063 else ifvarand raincstat 2 setvar temp 1062
		else setvar temp 1061
		gametextz picnum 470 64 temp shade 0 orientation 0 0 xdim ydim 40960
		// rain amount
		ifvare menuitem 93 state shadepulse else setvar shade 0
		gametextz picnum 170 72 1052 shade 0 orientation 0 0 xdim ydim 40960
		setvarvar temp raining ifvarl temp 0 mulvar temp -1
		digitalnumberz 2837 240 72 temp shade 0 orientation 0 0 xdim ydim 40960
		// rain radius
		ifvare menuitem 94 state shadepulse else setvar shade 0
		gametextz picnum 170 80 1065 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 80 rainradius shade 0 orientation 0 0 xdim ydim 40960
		
		// return to main menu
		ifvare menuitem 95 state shadepulse else setvar shade 0
		gametextz picnum 170 88 1058 shade 2 orientation 0 0 xdim ydim 40960
	} else
	ifvare menutoggle 7 // DUKEBOTS
	{
		setvar picnum 2822 // regular font
		gametextz picnum 170 33 1150 shade 0 orientation 0 0 xdim ydim 65536
		// quantity
		ifvare menuitem 110 state shadepulse else setvar shade 0
		gametextz picnum 170 48 1151 shade 0 orientation 0 0 xdim ydim 40960
		digitalnumberz 2837 240 48 numbots shade 0 orientation 0 0 xdim ydim 40960
		// respawn YES or NO
		ifvare menuitem 111 state shadepulse else setvar shade 0
		gametextz picnum 170 56 1152 shade 0 orientation 0 0 xdim ydim 40960
		ifvarand usebots 1 setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 56 temp shade 0 orientation 0 0 xdim ydim 40960
		// bots use pickups YES or NO
		ifvare menuitem 112 state shadepulse else setvar shade 0
		gametextz picnum 170 64 1153 shade 0 33 0 0 xdim ydim 40960
		ifvarand usebots 2 setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 64 temp shade 0 33 0 0 xdim ydim 40960
		// show lifebars
		ifvare menuitem 113 state shadepulse else setvar shade 0
		gametextz picnum 170 72 1044 shade 0 orientation 0 0 xdim ydim 40960
		ifvarand usebots 4 setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 72 temp shade 0 orientation 0 0 xdim ydim 40960
		// bot medics
		ifvare menuitem 114 state shadepulse else setvar shade 0
		gametextz picnum 170 80 1154 shade 0 orientation 0 0 xdim ydim 40960
		ifvarand usebots 8 setvar temp 1053 else setvar temp 1054
		gametextz picnum 470 80 temp shade 0 orientation 0 0 xdim ydim 40960
		// return to main menu
		ifvare menuitem 115 state shadepulse else setvar shade 0
		gametextz picnum 170 88 1058 shade 2 orientation 0 0 xdim ydim 40960
	}
	ifvarn menutoggle 1
	{
		// instructions
		gametextz picnum 170 162 1031 0 7 orientation 0 0 xdim ydim 32768 //40960
		//gametextz picnum 220 170 1032 0 2 orientation 0 0 xdim ydim 40960
	}
	setvar digx 65
	setvar digz 16384
	setvar shade 0
	setvar pal 0
	setvar orientation 0
	switch menuitem
		case 0
		case 9
		case 30
		case 50
		case 70
		case 90
		case 110
		setvar digy 47
		break
		case 1
		case 10
		case 31
		case 51
		case 71
		case 91
		case 111
		setvar digy 55
		break
		case 2
		case 11
		case 32
		case 52
		case 72
		case 92
		case 112
		setvar digy 63
		break
		case 3
		case 12
		case 33
		case 53
		case 73
		case 93
		case 113
		setvar digy 71
		break
		case 4
		case 13
		case 34
		case 54
		case 74
		case 94
		case 114
		setvar digy 79
		break
		case 5
		case 14
		case 35
		case 55
		case 75
		case 95
		case 115
		setvar digy 87
		break
		case 6
		case 15
		case 36
		case 56
		case 76
		case 96
		case 116
		setvar digy 95
		break
		case 7
		case 16
		case 37
		case 57
		case 77
		setvar digy 103
		break
		case 8
		case 17
		case 38
		case 58
		case 78
		setvar digy 111
		break
		case 18
		case 39
		case 59
		case 79
		setvar digy 119
		break
		case 19
		case 40
		case 60
		case 80
		setvar digy 127
		break
		case 20
		case 41
		case 81
		setvar digy 135
		break
		case 21
		case 82
		setvar digy 143
		break
		case 22
		case 83
		setvar digy 151
		break
		default break
	endswitch
	rotatesprite digx digy digz 0 headframe shade pal orientation 0 0 xdim ydim
	
}
else ifvare menunag YES
{
	setvarvar temp totalclock
	subvarvar temp ttime
	ifvarn temp 0
	{
		ifvarl temp 0 setvar temp 1
		setvarvar ttime totalclock 
		ifvarg nagpos -1500 subvarvar nagpos temp else setvar nagpos 900
		ifvarg nagpos 319 ifvarl nagpos 322 setvar nagpos 319
	}
	gametextz 2822 nagpos 12 1067 0 0 0 0 0 xdim ydim 65536
}


setvar temp OVERHEAT ifvarn usemp5 YES
ifvare temp YES ifvare holding -1 ifvare mantling 0
{
	getplayer[THISACTOR].knuckle_incs tempb
	getplayer[THISACTOR].newowner tempc
	ifvarg totalclock 1024 ifvarg tempb 0 setvar temp 0
	ifvarg chaingunheat 0 
	ifvare tempc -1 // ifvarl tempd 60
	ifvare currentweapon 3
	{
		setvar digy 164
		setvar digx 3
		setvar orientation 256
		setvar pal 7
		
		setvarvar tempb chaingunheat
		shiftvarr tempb 5
		setvarvar tempc digx
		addvarvar tempc tempb
		ifvarg chaingunheat 800
		{
			getplayer[THISACTOR].player_par mx
			shiftvarl mx 8
			sin my mx
			shiftvarr my 11
			setvarvar shade my
		} else setvar shade 0
		setvar temp 0
		whilevarn temp 1
		{
			  ifvarvarg digx tempc setvar temp 1
			  rotatesprite digx digy 16384 0 199 shade 7 orientation 0 0 xdim ydim
			  addvar digx 1
			  break
		}
		ifvarg chaingunheat 300
		{
			subvar digy 1
			ifvarl chaingunheat 500 setvar orientation 289 else ifvarl chaingunheat 650 setvar orientation 257
			gametextz 2908 8 digy 1009 shade 0 orientation 0 0 xdim ydim 22528
		}
	}
}

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

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

ifvarg numallies 0
{
	rotatesprite 313 8 12288 0 1501 0 0 512 0 0 xdim ydim
	setvar pal 8
	digitalnumber 3010 305 9 numallies 0 pal 512 0 0 xdim ydim
	ifvarg botwait 0 gametextz 2822 585 15 1181 0 7 512 0 0 xdim ydim 32768
}

ifvarg showsurvivors 0
{
	gametextz 2822 500 118 1189 0 12 512 0 0 xdim ydim 40960
	gametextz 2822 500 127 1190 0 13 512 0 0 xdim ydim 40960
	gametextz 2822 500 134 1191 0 13 512 0 0 xdim ydim 40960
	gametextz 2822 500 141 1192 0 13 512 0 0 xdim ydim 40960
	
	digitalnumberz 2837 310 127 rescued 0 12 512 0 0 xdim ydim 40960
	digitalnumberz 2837 310 134 survivors 0 12 512 0 0 xdim ydim 40960
	digitalnumberz 2837 310 141 survkilled 0 12 512 0 0 xdim ydim 40960
}

ifvarn botselected -1
{
	minitext 80 5 1006 0 1
	minitext 84 12 1007 0 1
}

ifvarn ONCAR 0
{
	rotatesprite 11 186 49152 0 COLA 0 4 33 0 0 xdim ydim
	rotatesprite 10 185 49152 0 COLA 0 0 0 0 0 xdim ydim
	getplayer[THISACTOR].last_extra temp
	digitalnumber 2930 46 191 temp 0 4 33 0 0 xdim ydim
	digitalnumber 2930 45 190 temp 0 0 0 0 0 xdim ydim
	ifvare ONCAR 2
	{
		setvar digy 172
		setvar digx 425
		setvar digz 32768
		setvar picnum 2822
		gametextz picnum digx digy 1139 0 0 0 0 0 xdim ydim digz
		addvar digx 125
		gametextz picnum digx digy 1140 0 2 0 0 0 xdim ydim digz
		subvar digx 125
		addvar digy 5
		gametextz picnum digx digy 1131 0 0 0 0 0 xdim ydim digz
		addvar digx 125
		gametextz picnum digx digy 1135 0 2 0 0 0 xdim ydim digz
		subvar digx 125
		addvar digy 5
		gametextz picnum digx digy 1132 0 0 0 0 0 xdim ydim digz
		addvar digx 125
		gametextz picnum digx digy 1136 0 2 0 0 0 xdim ydim digz
		subvar digx 125
		addvar digy 5
		gametextz picnum digx digy 1133 0 0 0 0 0 xdim ydim digz
		addvar digx 125
		gametextz picnum digx digy 1137 0 2 0 0 0 xdim ydim digz
		subvar digx 125
		addvar digy 5
		gametextz picnum digx digy 1134 0 0 0 0 0 xdim ydim digz
		addvar digx 125
		gametextz picnum digx digy 1138 0 2 0 0 0 xdim ydim digz
		subvar digx 125
		addvar digy 5
		gametextz picnum digx digy 1141 0 0 0 0 0 xdim ydim digz
		addvar digx 125
		gametextz picnum digx digy 1142 0 2 0 0 0 xdim ydim digz
		
		setvar digx 20
		setvar digy 14
		setvar digz 65536
		// gametextz picnum digx digy 1144 0 0 0 0 0 xdim ydim digz
		rotatesprite 20 12 20480 0 CLOCK 0 0 0 0 0 xdim ydim
		setvarvar temp timer
		divvar temp 26 // seconds
		modvar temp 60
		setvarvar tempb timer
		divvar tempb 1560 // minutes
		setvar digx 40
		digitalnumberz 2837 digx digy tempb 0 0 0 0 0 xdim ydim digz
		addvar digx 23
		ifvarl temp 10
		{
			subvar digx 5
			digitalnumberz 2837 digx digy 0 0 0 0 0 0 xdim ydim digz
			addvar digx 10
		}
		digitalnumberz 2837 digx digy temp 0 0 0 0 0 xdim ydim digz
		gametextz picnum 90 digy 1145 0 0 0 0 0 xdim ydim digz
		setvarvar temp skyspeed
		divvar temp 6
		digitalnumber 2837 80 192 temp 0 23 0 0 0 xdim ydim
		gametext 2822 190 192 1173 0 0 0 0 0 xdim ydim
		
	}
}

ifvarn camerasprite -1
{
	getactorvar[camerasprite].countvarb tempb
	ifvarand actorvar[camerasprite].monstflags 2
	{
		getactor[camerasprite].shade temp
		shiftvarl temp 1
		addvar temp 100
		showview sprite[camerasprite].x sprite[camerasprite].y sprite[camerasprite].z sprite[camerasprite].ang temp sprite[camerasprite].sectnum 206 118 310 185
	}
	else
	ifvarand actorvar[camerasprite].monstflags 16
	ifvarl tempb 13
	{
		getactor[camerasprite].shade temp
		shiftvarl temp 1
		addvar temp 100
		getactorvar[camerasprite].countvarb digx
		ifvare digx 0 setvar digx 1
		mulvar digx 26 // total view width
		getactorvar[camerasprite].countvarb digy
		ifvare digy 0 setvar digy 1
		mulvar digy 16 // total view height
		setvar mx 320
		subvarvar mx digx
		shiftvarr mx 1 // left x
		setvarvar xvel mx
		addvarvar xvel digx // right x
		setvar my 200
		subvarvar my digy
		shiftvarr my 1 // upper y
		setvarvar yvel my
		addvarvar yvel digy // lower y
		showview sprite[camerasprite].x sprite[camerasprite].y sprite[camerasprite].z sprite[camerasprite].ang temp sprite[camerasprite].sectnum mx my xvel yvel
	}
}
else
ifvare camerasprite -1
ifvare ONCAR 2
ifvarn rendmode 4
{
	// showview <x> <y> <z> <angle> <horiz> <sector> <scrn_x1> <scrn_y1> <scrn_x2> <scrn_y2>
	getplayer[THISACTOR].posz digz
	addvar digz 10240
	showview player[THISACTOR].posx player[THISACTOR].posy digz player[THISACTOR].ang -99 player[THISACTOR].cursectnum 235 115 315 165
}

ifvare ONCAR 0
ifvare player[THISACTOR].over_shoulder_on YES
{
	ifvare CURRWEAP 0 ifvarg LASERAMMO 0 state laserhud
	ifvare CURRWEAP 1 state displaypistolbullets
	ifvarand ALTSHOTGUN 4 nullop else ifvare CURRWEAP 2 ifvare usemossberg YES state displayshells
	ifvare CURRWEAP 3
	{
		ifvarand ALTCHAINGUN 2 nullop else
		ifvare usemp5 YES state displaymp5bullets
	}
	ifvare CURRWEAP 8 ifvare dukemon YES
	{
		getplayer[THISACTOR].ammo_amount 8 temp
		ifvare temp 0 { setvar RETURN -1 break }
		state displaydukeballs
	}
}
endevent

