
state mapitemload

getactor[THISACTOR].pal mtype

ends

eventloadactor RESPAWN { getactor[THISACTOR].extra mtype } enda

eventloadactor DIPSWITCH { state mapitemload } enda
eventloadactor 163 { state mapitemload } enda
eventloadactor DIPSWITCH2 { state mapitemload } enda
eventloadactor 165 { state mapitemload } enda
eventloadactor TECHSWITCH { state mapitemload } enda
eventloadactor 167 { state mapitemload } enda
eventloadactor DIPSWITCH3 { state mapitemload } enda
eventloadactor 169 { state mapitemload } enda

eventloadactor 1337 // helicopter
{ 
	clipdist 255 
} 
enda 

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

eventloadactor ACCESSSWITCH
{
	getactor[THISACTOR].pal pal
	espawn ACCESSSWITCH
	setactor[RETURN].pal pal
	setactor[RETURN].cstat 32808
	setactor[RETURN].xrepeat 255
	setactor[RETURN].yrepeat 255
	setactorvar[RETURN].myspawner THISACTOR
}
enda

eventloadactor ACCESSSWITCH2
{
	getactor[THISACTOR].pal pal
	espawn ACCESSSWITCH
	setactor[RETURN].pal pal
	setactor[RETURN].cstat 32804
	setactor[RETURN].xrepeat 255
	setactor[RETURN].yrepeat 255
	setactorvar[RETURN].myspawner THISACTOR
}
enda

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

// 0 DEFAULT
// 1 WOOD
// 2 TIN
// 3 GRATE
// 4 GRASS
// 5 TILE
// 6 CARPET
// 7 CONCRETE
// 8 SNOW
// 9 WATER
// 10 ELECTRONIC
// 11 ORGANIC

gamevar STEPSOUNDFX 0 1
gamevar FLOORTEX 0 1

state CHECKSTEPS

setvar STEPSOUNDFX 0

switch FLOORTEX

case 0 setvar STEPSOUNDFX 0 break

case 70 case 370 case 735 case 745 case 749 case 821 case 822 case 879 case 880 case 884
case 1188 case 1200 case 1201 case 4110 case 4111 case 4303 case 4428
// DC steps
case 3684 case 3685 case 3691

setvar STEPSOUNDFX 1 break

case 150 case 151 case 152 case 153 case 154 case 155 case 156 case 157 case 158 case 159
case 182 case 195 case 196 case 216 case 218 case 220 case 221 case 222 case 223 case 224
case 226 case 227 case 231 case 232 case 242 case 243 case 244 case 257 case 258 case 259
case 278 case 283 case 284 case 285 case 286 case 287 case 288 case 289 case 290 case 291
case 292 case 294 case 295 case 296 case 300 case 302 case 303 case 309 case 311 case 312 
case 313 case 314 case 315 case 317 case 318 case 319 case 322 case 327 case 342 case 344 
case 345 case 346 case 347 case 348 case 350 case 354 case 365 case 366 case 369 case 378 
case 379 case 380 case 381 case 382 case 383 case 384 case 385 case 392 case 393 case 394 
case 395 case 396 case 397 case 399 case 400 case 412 case 413 case 418 case 419 case 420 
case 441 case 442 case 447 case 448 case 449 case 450 case 451 case 452 case 453 case 454 
case 455 case 456 case 457 case 458 case 459 case 460 case 467 case 469 case 470 case 471 
case 513 case 514 case 515 case 609 case 665 case 709 case 711 case 715 case 717 case 736 
case 737 case 738 case 739 case 754 case 755 case 756 case 767 case 795 case 797 case 798 
case 829 case 843 case 883 case 886 case 946 case 947 case 948 
case 1024 case 1097 case 1098 case 1099 case 1102 case 1103
case 1107 case 1108 case 1109 case 1110 case 1117 case 1118 case 1119 case 1120 case 1124
case 1144 case 1173 case 1178 case 1179 case 1187 case 1190 case 4097 case 4098
case 4099 case 4105 case 4106 case 4108 case 4109 case 4117 case 4118 case 4119 case 4162
case 4163 case 4164 case 4165 case 4168 case 4201 case 4202 case 4206 case 4276 case 4277
case 4278 case 4279 case 4282 case 4283 case 4284 case 4285 case 4286 case 4287 case 4288
case 4300 case 4301 case 4302 case 4304 case 4305 case 4308 case 4309 case 4310 case 4330
case 4331 case 4334 case 4335 case 4349 case 4350

// DC steps
case 3693 case 3694 case 3727 case 3779

setvar STEPSOUNDFX 2 break

case 183 case 710 case 915 case 4154 case 4155
// DC steps
case 3712 case 3732

setvar STEPSOUNDFX 3 break

case 803 setvar STEPSOUNDFX 4 break

case 186 case 187 case 188 case 189 case 190 case 191 case 192 case 332 case 720 case 857 case 4102
case 246
// DC steps
case 3692

setvar STEPSOUNDFX 5 break

case 545 case 898 case 899 case 900 case 1218 case 1219
// DC steps
case 3604 case 3612 case 3613 case 3614 case 3615 case 3616

setvar STEPSOUNDFX 6 break

case 181 case 184 case 197 case 207 case 209 case 236 case 237 
case 238 case 239 case 240 case 241 case 251 case 252 case 331 
case 334 case 335 case 349 case 367 case 368 case 372 
case 376 case 377 case 414 case 417 case 429 case 430 case 431 case 432 
case 433 case 434 case 435 case 437 case 461 case 465 case 466 case 468 
case 478 case 718 case 723 case 724 case 725 case 734 case 742 
case 743 case 747 case 748 case 750 case 757 case 759 case 760 
case 761 case 763 case 764 case 770 case 772 case 773 case 775 case 780 
case 781 case 782 case 783 case 790 case 793 case 794 case 796 case 800 
case 801 case 802 case 804 case 805 case 812 case 814 case 815 case 816 
case 817 case 818 case 819 case 823 case 824 case 825 case 827 case 828 
case 852 case 853 case 859 case 876 case 887 case 893 case 894 
case 895 case 1169 case 1170 case 1171 case 1182 case 1183 case 1184 case 1185 
case 1186 case 1189 case 1191 case 1193 case 1204 case 1205 case 1279 case 2922 
case 3381 case 3384 case 3385 case 3386 case 3387 case 3394 case 3395 case 3396 
case 3398 case 3407 case 4112 case 4151 case 4152 case 4190 case 4208 
case 4210 case 4211 case 4212 case 4213 case 4214 case 4215 case 4216 case 4217 
case 4218 case 4219 case 4220 case 4221 case 4222 case 4223 case 4234 case 4235 
case 4236 case 4255 case 4259 case 4319 case 4320 case 4321 
case 4322 case 4323 case 4332 case 4333 case 5065 case 5066 case 5067 case 5068 
case 5069 case 5070 case 5071 case 5072 case 5073 case 5074 case 5075 case 5076 
case 5077 case 5078 case 5083

setvar STEPSOUNDFX 7 break

case 3416
getsector[THISACTOR].floorpal temp
ifvare temp 0 setvar STEPSOUNDFX 8
else ifvare temp 6 setvar STEPSOUNDFX 4
else setvar STEPSOUNDFX 7
break

case 336 case 337 case 338 case 889 case 890 case 891 case 892

setvar STEPSOUNDFX 9 break

case 203 case 268 case 269 case 270 case 271 case 272 case 273 case 274
case 293 case 297 case 298 case 299 case 357 case 358 case 359 
case 360 case 361 case 362 case 363 case 426 case 427 case 428
case 806 case 4127 case 4130 case 4131 case 4132 case 4133 case 4134
case 4135 case 4136 case 4137 case 4138 case 4139 case 4140
case 4141 case 4142 case 4143 case 4144 case 4145 case 4146 case 4147
case 4924 case 4932

ifactor BULLETHOLE setvar STEPSOUNDFX 10 else
ifactor SHOTSPARK1 setvar STEPSOUNDFX 10 else
ifactor 1 setvar STEPSOUNDFX 10 else
ifactor 2 setvar STEPSOUNDFX 10 else
setvar STEPSOUNDFX 7

break

case 1116 case 1130 case 1131 case 1137 case 1139 case 1140 case 1141
case 5079 case 5080 case 5099 case 5102
setvar STEPSOUNDFX 11

break

endswitch

ends

state HITMETALSOUND

randvar temp 4
switch temp
case 0
	sound HITMETAL break
case 1
	sound HITMETAL2 break
case 2
	sound HITMETAL3 break
case 3
	sound HITMETAL4 break
case 4
	sound HITMETAL5 break

endswitch


ends

state HITSTONESOUND

randvar temp 4
switch temp
case 0
	sound HITSTONE break
case 1
	sound HITSTONE2 break
case 2
	sound HITSTONE3 break
case 3
	sound HITSTONE4 break
case 4
	sound HITSTONE5 break
	
endswitch

ends

state WOODHITSOUND

randvar temp 4
switch temp
case 0
	sound HITWOOD break
case 1
	sound HITWOOD2 break
case 2
	sound HITWOOD3 break
case 3
	sound HITWOOD4 break
case 4
	sound HITWOOD5 break

endswitch


ends

state HITDIRTSOUND

randvar temp 2
switch temp
case 0
	sound HITDIRT break
case 1
	sound HITDIRT2 break
case 2
	sound HITDIRT3 break

endswitch


ends

state HITWATERSOUND

randvar temp 2
switch temp
case 0
	sound HITWATER break
case 1
	sound HITWATER2 break
case 2
	sound HITWATER3 break

endswitch


ends

state shootscrap

getactor[THISACTOR].ang angvar
addvar angvar 1024
randvar temp 480
ifrnd 128 mulvar temp -1
addvarvar angvar temp
setactor[THISACTOR].ang angvar
randvar zdist 2048
ifrnd 128 mulvar zdist -1
subvar zdist 1024
ezshootvar zdist holoweap
randvar temp 24
ifvare holoweap NEWSCRAP3 addvar temp 12
setthisprojectile[RETURN].vel temp
ifvare holoweap NEWSCRAP3
{
	setactor[RETURN].xrepeat 18
	setactor[RETURN].yrepeat 12	
}
else ifvare holoweap NEWSCRAP4
{
	setactor[RETURN].xrepeat 24
	setactor[RETURN].yrepeat 16
}
ends

state sparkstate

randvar monstatus 2
addvar monstatus 1
setvar loop 0
getactor[THISACTOR].ang dodge
whilevarvarn loop monstatus
{
	addvar loop 1
	randvar angvar 2047
	setactor[THISACTOR].ang angvar
	randvar zdist 3072
	ifrnd 128 mulvar zdist -1
	zshoot zdist SPARKPROJ
}
setactor[THISACTOR].ang dodge	
ends

state sparkstate2

randvar monstatus 2
addvar monstatus 1
setvar loop 0
getactor[THISACTOR].ang dodge
whilevarvarn loop monstatus
{
	addvar loop 1
	randvar angvar 2047
	setactor[THISACTOR].ang angvar
	randvar zdist 3072
	ifrnd 128 mulvar zdist -1
	subvar zdist 512
	zshoot zdist SPARKPROJ2
}
setactor[THISACTOR].ang dodge	
ends

state BULLETHITSOUNDS

switch STEPSOUNDFX
case 0
break

case 1
case 5
	state WOODHITSOUND
	setvar holoweap NEWSCRAP4
	ifrnd 128 state shootscrap
	
	break
case 2
case 3
	state HITMETALSOUND 
	state sparkstate
	break
	
case 4
case 8
	state HITDIRTSOUND
 break

case 7
case 10
	state HITSTONESOUND
	setvar holoweap NEWSCRAP3
	ifrnd 128 state shootscrap 
	break
case 9
	state HITWATERSOUND break
case 11
    sound HITFLESH 
    spritepal 6
	guts JIBS6 1
    break

endswitch

ends

state normalpistol

setvar holoweap 2
setvar WEAPON1_SHOOTS 2595
setvar WEAPON1_RELOAD 27

ifvarg pdamage 140 setvar WEAPON1_FIRESOUND PISTOL2 else 
ifvarg pdamage 100 setvar WEAPON1_FIRESOUND PISTOL3 else
setvar WEAPON1_FIRESOUND PISTOL_WEAK
setvar WEAPON1_FIREDELAY 2
setvar WEAPON1_TOTALTIME 7

ifvarg special 0
{
	setvar WEAPON1_SHOOTS APROUND2
	setvar WEAPON1_FIRESOUND PISTOL2
}

ifp ponsteroids
{
	setvar WEAPON1_TOTALTIME 4
	setvar WEAPON1_RELOAD 16
}
ends

state altpistol

setvar holoweap 12
setvar WEAPON1_SHOOTS BOMBDART
setvar WEAPON1_FIRESOUND DART_FIRE
setvar WEAPON1_FIREDELAY 4
setvar WEAPON1_TOTALTIME  20

ifp ponsteroids
{
	setvar WEAPON1_TOTALTIME 10
}

ends

state normalshotgun

setvar holoweap 3
setvar WEAPON2_SHOOTS 2613
setvar WEAPON2_SHOTSPERBURST 7
ifvarg pdamage 120 setvar WEAPON2_FIRESOUND SHOTGUN2 else
setvar WEAPON2_FIRESOUND 109
setvar WEAPON2_TOTALTIME 31
setvar WEAPON2_SPAWNTIME 24

ifvarg special 0
{ 
	 subvar special SPECIAL2_AMOUNT
	 setvar WEAPON2_SHOOTS FLAK
	 setvar WEAPON2_SHOTSPERBURST 14
	 setvar WEAPON2_FIRESOUND SHOTGUN2
}

ifp ponsteroids
{
	setvar WEAPON2_TOTALTIME 16
	setvar WEAPON2_SPAWNTIME 12
}
		
ends

state altshotgun

setvar holoweap 13
setvar WEAPON2_SHOOTS ALTSHOTGUN
setvar WEAPON2_SHOTSPERBURST 3
setvar WEAPON2_FIRESOUND ACID_FIRE
setvar WEAPON2_TOTALTIME 31
setvar WEAPON2_SPAWNTIME 24

ifp ponsteroids
{
	setvar WEAPON2_TOTALTIME 16
	setvar WEAPON2_SPAWNTIME 12
}

ends

state normalchaingun

setvar holoweap 4
setvar WEAPON3_SHOOTS 2536
setvar WEAPON3_SHOTSPERBURST 0
ifvarg pdamage 120 setvar WEAPON3_FIRESOUND M16FIRE else
setvar WEAPON3_FIRESOUND 6

ifvarg special 0
{
	 setvar WEAPON3_SHOOTS APROUND
	 setvar WEAPON3_FIRESOUND M16FIRE
}

ifp ponsteroids setvar WEAPON3_SHOTSPERBURST 2

ends

state altchaingun

setvar holoweap 14
setvar WEAPON3_SHOOTS FLAK
setvar WEAPON3_SHOTSPERBURST 0
setvar WEAPON3_FIRESOUND FLAK_FIRE
setvar WEAPON3_TOTALTIME 12

ifp ponsteroids setvar WEAPON3_SHOTSPERBURST 2

ends

state normalrpg

setvar holoweap 5
setvar WEAPON4_SHOOTS 2605

ifvarg pdamage 120 setvar WEAPON4_FIRESOUND MISSILE2 else
setvar WEAPON4_FIRESOUND RPG_SHOOT

ifvarg special 0
{
	 setvar WEAPON4_SHOOTS HLROCKET
	 setvar WEAPON4_FIRESOUND GRENADE_FIRE
}

setvar WEAPON4_TOTALTIME 20
ifp ponsteroids setvar WEAPON4_TOTALTIME 12

ends

state altrpg

setvar holoweap 5
setvar WEAPON4_SHOOTS CANNONBALLPROJ

setvar WEAPON4_FIRESOUND CANNONFIRE
setvar WEAPON4_TOTALTIME 32

ifp ponsteroids setvar WEAPON4_TOTALTIME 16

ends

state normalpipebomb

setvar holoweap 6
setvar pipeon 1
setvar PIPEBOMB_CONTROL 1

ends

state altpipebomb

setvar holoweap 16
setvar pipeon 0
setvar PIPEBOMB_CONTROL 2
setvar GRENADE_LIFETIME 260

ends

state normalshrinker

setvar holoweap 7
setvar WEAPON6_SHOOTS 2556
setvar WEAPON6_FIRESOUND 0
setvar WEAPON6_FIREDELAY 3
setvar WEAPON6_TOTALTIME 12
setvar WEAPON6_SPAWNTIME 0
setvar WEAPON6_SPAWN 0

ifvarg special 0
{
	setvar holoweap 11
	setvar WEAPON6_SHOOTS BFG
	setvar WEAPON6_FIRESOUND BFG_FIRE
	setvar WEAPON6_SPAWNTIME 3
	setvar WEAPON6_FIREDELAY 6
	setvar WEAPON6_TOTALTIME 15
	setvar WEAPON6_SPAWN TRANSPORTERSTAR
}

ends

state altshrinker
setvar holoweap 17
setvar WEAPON11_FIREDELAY 5
setvar WEAPON11_TOTALTIME 26

ifp ponsteroids
{
	setvar WEAPON11_FIREDELAY 3
	setvar WEAPON11_TOTALTIME 15
}
ends

state normaldevastator

setvar holoweap 8

ifvarn ONCAR 0
{
	setvar WEAPON7_FIRESOUND PISTOL2
	setvar WEAPON7_SHOTSPERBURST 2
	setvar WEAPON7_FIREDELAY 2
	setvar WEAPON7_TOTALTIME 3
	setvar WEAPON7_SHOOTS EXPLOSIVEBULLET
	setvar WEAPON7_FLAGS 4232 // ADD 4160 = ammo perburst + shotgun shells
	setvar WEAPON7_SPAWNTIME 4
    setvar WEAPON7_SPAWN 2535
    ifvare sideswitch 0 setvar sideswitch 1 else setvar sideswitch 0
    break
}


setvar WEAPON7_SHOTSPERBURST 2
setvar WEAPON7_SHOOTS 2605
ifvarg pdamage 120 setvar WEAPON7_FIRESOUND MISSILE2 else
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


ifvare sideswitch 0 setvar sideswitch 1 else setvar sideswitch 0

ifvarg special 0
{
	setvar WEAPON7_SHOTSPERBURST 5
	setvar WEAPON7_SHOOTS SHOTGUN
	setvar WEAPON7_FIRESOUND SHOTGUN3
	setvar WEAPON7_FLAGS 4224
	setvar WEAPON7_SPAWNTIME 4
    setvar WEAPON7_SPAWN 2535
    setvar WEAPON7_INITIALSOUND -1  
}



ifp ponsteroids
{
	setvar WEAPON7_FIREDELAY 2
	setvar WEAPON7_TOTALTIME 3
}

ends

state altdevastator

setvar holoweap 18
ifvare sideswitch 0 { setvar WEAPON7_SHOOTS BLASTER setvar sideswitch 1 }
  	    else { setvar WEAPON7_SHOOTS BLASTER2 setvar sideswitch 0 }

setvar WEAPON7_SHOTSPERBURST 1
setvar WEAPON7_FIRESOUND BLASTERSND
setvar WEAPON7_FIREDELAY 3
setvar WEAPON7_TOTALTIME 5

ifp ponsteroids
{
	setvar WEAPON7_FIREDELAY 2
	setvar WEAPON7_TOTALTIME 3
}

ends

state normaltrip

setvar holoweap 9
setvar tripon 1

ends

state altrip

setvar holoweap 19
setvar tripon 0
 
ends


state normalfreezer

setvar holoweap 20
setvar WEAPON9_SHOOTS LIGHTNINGBOLT
setvar WEAPON9_TOTALTIME 6
setvar WEAPON9_FIRESOUND 351
setvar WEAPON9_FLAGS 20
setvar WEAPON9_SHOTSPERBURST 0

//setvar holoweap 10
//setvar WEAPON9_SHOOTS 1641
//setvar WEAPON9_FIRESOUND 10
//setvar WEAPON9_FLAGS 20

ifvarg special 0
{
	 //setvar WEAPON9_SHOOTS CHILLBLAST2
	 //setvar WEAPON9_FIRESOUND CHILLING
	 setvar WEAPON9_SHOOTS FIRELASER2
	 setvar WEAPON9_FIRESOUND SPFREEZEFIRE
	 setvar WEAPON9_SHOTSPERBURST 5
}

ifp ponsteroids setvar WEAPON9_FLAGS 12


ends

state altfreezer

//setvar holoweap 20
//setvar WEAPON9_SHOOTS LIGHTNINGBOLT
//setvar WEAPON9_FIRESOUND 351
//setvar WEAPON9_FLAGS 20

//ifp ponsteroids setvar WEAPON9_FLAGS 12

setvar holoweap 15
setvar WEAPON9_SHOOTS RAILSLUG
setvar WEAPON9_FIRESOUND RAIL_FIRE
setvar WEAPON9_TOTALTIME 26
setvar WEAPON9_FLAGS 0
setvar WEAPON9_SHOTSPERBURST 0

ifp ponsteroids setvar WEAPON9_TOTALTIME 12

ends

state updatescores

ifvare updatehiscore -1 break
getuserdef[THISACTOR].player_skill temp
ifvare temp 4 ifvarl score 4000 break

switch VOLUME
case 0
ifvarvarg score ep1hi1
{
	setvarvar ep1hi3 ep1hi2
	setvarvar ep1hi2 ep1hi1
	setvarvar ep1hi1 score
	savegamevar ep1hi1
	savegamevar ep1hi2
	savegamevar ep1hi3
}
else ifvarvarg score ep1hi2
{
	setvarvar ep1hi3 ep1hi2
	setvarvar ep1hi2 score
	savegamevar ep1hi2
	savegamevar ep1hi3
}
else ifvarvarg score ep1hi3
{
	setvarvar ep1hi3 score
	savegamevar ep1hi3
}

break

case 1
ifvarvarg score ep2hi1
{
	setvarvar ep2hi3 ep2hi2
	setvarvar ep2hi2 ep2hi1
	setvarvar ep2hi1 score
	savegamevar ep2hi1
	savegamevar ep2hi2
	savegamevar ep2hi3
}
else ifvarvarg score ep2hi2
{
	setvarvar ep2hi3 ep2hi2
	setvarvar ep2hi2 score
	savegamevar ep2hi2
	savegamevar ep2hi3
}
else ifvarvarg score ep2hi3
{
	setvarvar ep2hi3 score
	savegamevar ep2hi3
}

break

case 2
ifvarvarg score ep3hi1
{
	setvarvar ep3hi3 ep3hi2
	setvarvar ep3hi2 ep3hi1
	setvarvar ep3hi1 score
	savegamevar ep3hi1
	savegamevar ep3hi2
	savegamevar ep3hi3
}
else ifvarvarg score ep3hi2
{
	setvarvar ep3hi3 ep3hi2
	setvarvar ep3hi2 score
	savegamevar ep3hi2
	savegamevar ep3hi3
}
else ifvarvarg score ep3hi3
{
	setvarvar ep3hi3 score
	savegamevar ep3hi3
}
break

case 3
ifvarvarg score ep1hi1
{
	setvarvar ep4hi3 ep4hi2
	setvarvar ep4hi2 ep4hi1
	setvarvar ep4hi1 score
	savegamevar ep4hi1
	savegamevar ep4hi2
	savegamevar ep4hi3
}
else ifvarvarg score ep4hi2
{
	setvarvar ep4hi3 ep4hi2
	setvarvar ep4hi2 score
	savegamevar ep4hi2
	savegamevar ep4hi3
}
else ifvarvarg score ep4hi3
{
	setvarvar ep4hi3 score
	savegamevar ep4hi3
}
break

case 4
ifvarvarg score ep5hi1
{
	setvarvar ep5hi3 ep5hi2
	setvarvar ep5hi2 ep5hi1
	setvarvar ep5hi1 score
	savegamevar ep5hi1
	savegamevar ep5hi2
	savegamevar ep5hi3
}
else ifvarvarg score ep5hi2
{
	setvarvar ep5hi3 ep5hi2
	setvarvar ep5hi2 score
	savegamevar ep5hi2
	savegamevar ep5hi3
}
else ifvarvarg score ep1hi3
{
	setvarvar ep5hi3 score
	savegamevar ep5hi3
}
break

case 5
ifvarvarg score ep6hi1
{
	setvarvar ep6hi3 ep6hi2
	setvarvar ep6hi2 ep6hi1
	setvarvar ep6hi1 score
	savegamevar ep6hi1
	savegamevar ep6hi2
	savegamevar ep6hi3
}
else ifvarvarg score ep6hi2
{
	setvarvar ep6hi3 ep6hi2
	setvarvar ep6hi2 score
	savegamevar ep6hi2
	savegamevar ep6hi3
}
else ifvarvarg score ep6hi3
{
	setvarvar ep6hi3 score
	savegamevar ep6hi3
}
break

case 6
ifvarvarg score ep7hi1
{
	setvarvar ep7hi3 ep7hi2
	setvarvar ep7hi2 ep7hi1
	setvarvar ep7hi1 score
	savegamevar ep7hi1
	savegamevar ep7hi2
	savegamevar ep7hi3
}
else ifvarvarg score ep7hi2
{
	setvarvar ep7hi3 ep7hi2
	setvarvar ep7hi2 score
	savegamevar ep7hi2
	savegamevar ep7hi3
}
else ifvarvarg score ep7hi3
{
	setvarvar ep7hi3 score
	savegamevar ep7hi3
}
break

endswitch

savegamevar complete
setvar updatehiscore -1

ends


state resetupgradevars
// actually, this resets a bunch of vars when the player dies, not just upgrade related
setvar updatehiscore 0
setvar dodge 0
setvar dodgeagain 0
setvar pheal 0
setvar kickimpact 0
setvar lastring 0
setvar superkicking 0
setvar superkickdone 0
setvar camerasprite -1
setvar holosphere 0
setvar nukepart 5
setvar barrierlevel 0
setvar gogglelevel 0
setvar combolevel 0
setvar headshot 0
setvar special 0

setvar weap0lev 60
setvar weap1lev 60
setvar weap2lev 60
setvar weap3lev 60
setvar weap4lev 60
setvar weap5lev 60
setvar weap6lev 60
setvar weap7lev 60
setvar weap8lev 100
setvar weap9lev 60

setvar weap0xp 0
setvar weap1xp 0
setvar weap2xp 0
setvar weap3xp 0
setvar weap4xp 0
setvar weap5xp 0
setvar weap6xp 0
setvar weap7xp 0
setvar weap8xp 0
setvar weap9xp 0

getuserdef[THISACTOR].player_skill temp
ifvare temp 4
{
	// setvar tipfield 131071 tips not reset when player dies
	setvar tempb 0
	ifvarn complete 0
	{
		switch VOLUME
		case 0 ifvarand complete 1 setvar tempb 1 break
		case 1 ifvarand complete 2 setvar tempb 1 break
		case 2 ifvarand complete 4 setvar tempb 1 break
		case 3 ifvarand complete 8 setvar tempb 1 break
		case 4 ifvarand complete 16 setvar tempb 1 break
		case 5 ifvarand complete 32 setvar tempb 1 break
		case 6 ifvarand complete 64 setvar tempb 1 break
		endswitch
	}
		setplayer[THISACTOR].gotweapon 2 1
		setplayer[THISACTOR].ammo_amount 2 10
		ifvare tempb 1
		{
			setvar score STARTSCORE3
			setvar skillpoint STARTSKILL3
			setvar lastscoredisp STARTSCORE3
			setvar nukepart 30
		}
		else
		{
			setvar score STARTSCORE2
			setvar skillpoint STARTSKILL2
			setvar lastscoredisp STARTSCORE2
			setvar nukepart 30
		}
}
else
{
		setvar score 0
		setvar lastscoredisp 0
		setvar skillpoint STARTSKILL
}
setvar maxhealth MAXPLAYERHEALTH
setactor[THISACTOR].extra maxhealth
setvar maxarmor MAXPLAYERATOMICHEALTH
setplayer[THISACTOR].firstaid_amount 50
setvar holomult 20
setvar dreduction 100
setvar running RUNNINGSPEED
setvar leglevel 0
setvar menutoggle 0
setvar limits 0
setvar MAXLOAD 2999
setvar gogglelimit 1500
setvar holodukelimit 3000
setvar firstaidlimit 125
setvar stamina MAXSTAMINA
	smaxammo 1 204
	smaxammo 2 30
	smaxammo 3 200
	smaxammo 4 26
	smaxammo 5 26
	smaxammo 6 26
	smaxammo 7 99
	smaxammo 8 7
	smaxammo 9 99
	smaxammo 11 26
	
setvar message 0
setvar messagetime 0
setvar tipfield 0
setvar tipdisplay 0
setvar ONCAR 0
setvar mouseoy 100
setvar mousey 100
ends


state upgradehealth

addvar maxhealth 10
addvar maxarmor 20


getplayer[THISACTOR].i tempc  // also increase current health
getactor[tempc].extra tempb
addvar tempb 10
setactor[tempc].extra tempb

sound INTRUDER_ALERT
palfrom 31 0 31 63

ends

state upgradeholohp

subvar holomult 1
sound INTRUDER_ALERT
palfrom 31 0 31 63

ends

state buyammo

sound AMMO_MAX
palfrom 31 0 31 63
getplayer[THISACTOR].curr_weapon tempc
switch tempc
case 0
case 1 
	spawn AMMO
	break
	
case 2
	spawn SHOTGUNAMMO
	break
	
case 3
	spawn BATTERYAMMO
	break
	
case 4
	spawn RPGAMMO
	break
	
case 5
case 10
	spawn HBOMBAMMO
	break
	
case 6
case 11
	spawn CRYSTALAMMO
	break
	
case 7
	spawn DEVISTATORAMMO
	break
	
case 8
	spawn TRIPBOMBSPRITE
	break
	
case 9
	spawn FREEZEAMMO
	break


endswitch

ends


state upgradespeed

addvar running 4782
setplayer[THISACTOR].runspeed running
ends


state upgradelegs
addvar leglevel 1
ifvare leglevel 3 state upgradespeed
sound INTRUDER_ALERT
palfrom 31 0 31 63
ends

state upgradelimit

palfrom 31 0 31 63

addvar limits 1
// stamina recover and oxygen supply are handled on the fly
ifvare limits 2
{
	mulvar gogglelimit 2
	mulvar holodukelimit 2
	mulvar firstaidlimit 2
}
ifvare limits 3 setvar MAXLOAD 5499
ifvare limits 4 // increase ammo max
{
	
	smaxammo 1 408
	smaxammo 2 60
	smaxammo 3 400
	smaxammo 4 52
	smaxammo 5 52
	smaxammo 6 52
	smaxammo 7 198
	smaxammo 8 16
	smaxammo 9 198
	smaxammo 11 52
}

switch limits
case 1 sound DUKE_GETWEAPON1 break
case 2 sound DUKE_GETWEAPON3 break
case 3 sound BONUS_SPEECH4 break
case 4 sound DUKE_GETWEAPON6 break
endswitch

ends

state upgradedreduction

sound INTRUDER_ALERT
palfrom 31 0 31 63
subvar dreduction 5

ends

state upgradebarrier

ifvare combolevel 0 setvar combolevel 1
addvar barrierlevel 1
sound SHIELD_UPGRADE
palfrom 31 0 31 63
ends

state upgradecombo
ifvare combolevel 0 { state upgradebarrier break }
addvar combolevel 1
sound LASERTRIP_ONWALL
palfrom 31 0 31 63
ends

state upgradegoggles

addvar gogglelevel 1
setvar hweapcount 26
sound DIMENSION_SHIFT

ends

state randexplosions

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

ifrnd 128
{
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].z z
	randvar temp 2048
	ifrnd 128 mulvar temp -1
	addvarvar x temp
	randvar temp 2048
	ifrnd 128 mulvar temp -1
	addvarvar y temp
	randvar temp 8192
	subvarvar z temp
	updatesectorz x y z temp
	ifvarn temp -1
	{
	
		espawn SMALLEXPLOSION
		ifrnd 160 sound BOOM
		else sound PIPEBOMB_EXPLODE
		
		setactor[RETURN].x x
		setactor[RETURN].y y
		setactor[RETURN].z z
	}
}

ends

state randgetweapsnds
  ifrnd 64
    globalsound DUKE_GETWEAPON1
  else
    ifrnd 96
      globalsound DUKE_GETWEAPON2
  else
    ifrnd 128
      globalsound DUKE_GETWEAPON3
  else
    ifrnd 140
      globalsound DUKE_GETWEAPON4
  else
    globalsound DUKE_GETWEAPON6
ends

state upgradedamage

addvar pdamage 10
state randgetweapsnds 
palfrom 31 0 31 63
ends

state healthcost

ifvarl maxhealth 70 setvar cost 5
else ifvarl maxhealth 100 setvar cost 6
else ifvarl maxhealth 130 setvar cost 7
else ifvarl maxhealth 140 setvar cost 8
else ifvarl maxhealth 150 setvar cost 9
else ifvarl maxhealth 160 setvar cost 10
else ifvarl maxhealth 170 setvar cost 11
else ifvarl maxhealth 180 setvar cost 12
else ifvarl maxhealth 190 setvar cost 13
else ifvarl maxhealth 200 setvar cost 14
else ifvarl maxhealth 210 setvar cost 15
else ifvarl maxhealth 220 setvar cost 16
else ifvarl maxhealth 230 setvar cost 18
else ifvarl maxhealth 240 setvar cost 20
else ifvarl maxhealth 250 setvar cost 22
else setvar cost 25

ends

state holocost // LOL

 switch holomult

  case 20: setvar cost 1 break
  case 19: setvar cost 2 break
  case 18: setvar cost 3 break
  case 17: setvar cost 4 break
  case 16: setvar cost 5 break
  case 15: setvar cost 6 break
  case 14: setvar cost 8 break
  case 13: setvar cost 10 break
  case 12: setvar cost 12 break
  case 11: setvar cost 14 break
  case 10: setvar cost 16 break
  case 9: setvar cost 18 break
  case 8: setvar cost 20 break
  case 7: setvar cost 22 break
  case 6: setvar cost 24 break
  case 5: setvar cost 26 break
  case 4: setvar cost 28 break
  case 3: setvar cost 30 break

 endswitch

ends

state barriercost

 switch barrierlevel

  case 0: setvar cost 5 break
  case 1: setvar cost 10 break
  case 2: setvar cost 20 break
  case 3: setvar cost 30 break
  //case 4: setvar cost 30 break
 
 endswitch

ends

state combocost

switch combolevel
case 0: setvar cost 5 break
case 1: setvar cost 6 break
case 2: setvar cost 7 break
case 3: setvar cost 8 break
case 4: setvar cost 9 break
endswitch

ends

state legcost

switch leglevel
 case 0: setvar cost 4 break
 case 1: setvar cost 8 break
 case 2: setvar cost 16 break
 case 3: setvar cost 32 break
endswitch
ends

state limitcost

switch limits
 case 0: setvar cost 10 break
 case 1: setvar cost 15 break
 case 2: setvar cost 20 break
 case 3: setvar cost 25 break
endswitch
ends


state gogglecost

switch gogglelevel
 case 0: setvar cost 5 break
 case 1: setvar cost 10 break
 case 2: setvar cost 15 break
endswitch

ends

state dreductioncost

switch dreduction
case 100 setvar cost 5 break
case 95 setvar cost 6 break
case 90 setvar cost 8 break
case 85 setvar cost 10 break
case 80 setvar cost 13 break
case 75 setvar cost 16 break
case 70 setvar cost 20 break
case 65 setvar cost 25 break
case 60 setvar cost 30 break
case 55 setvar cost 35 break
case 50 setvar cost 40 break
case 45 setvar cost 45 break
case 40 setvar cost 50 break
case 35 setvar cost 55 break
case 30 setvar cost 60 break
case 25 setvar cost 70 break
case 20 setvar cost 85 break
case 15 setvar cost 100 break
endswitch
ends


state clearlists
ifvarvare THISACTOR D1 { setvar D1 -1 break }
ifvarvare THISACTOR D2 { setvar D2 -1 break }
ifvarvare THISACTOR D3 { setvar D3 -1 break }

ifvarvare THISACTOR M1 { setvar M1 -1 break }
ifvarvare THISACTOR M2 { setvar M2 -1 break }
ifvarvare THISACTOR M3 { setvar M3 -1 break }
ends

state deadlist

ifvarvare THISACTOR D1 break
ifvarvare THISACTOR D2 break // exit if already on dead list
ifvarvare THISACTOR D3 break
	
ifvare D1 -1 { setvarvar D1 THISACTOR break }
else
ifvare D2 -1 { setvarvar D2 THISACTOR break }
else
setvarvar D3 THISACTOR // if this state is still executing, then this is safe to do
ends

state difficulty

getuserdef[THISACTOR].player_skill tempb

getactor[THISACTOR].extra temp

ifvare tempb 2 { mulvar temp 3 divvar temp 2 }
ifvare tempb 3 { mulvar temp 2 }
ifvare tempb 4 { mulvar temp 3 }

setactor[THISACTOR].extra temp

ends


state stopanimation
setvar spriteid 0
whilevarn spriteid 16384
{
	getactor[spriteid].statnum temp
	ifvarn temp 1024
	{
		getactor[spriteid].picnum tilenum
		ifvarg tilenum 1519 ifvarl tilenum 1544 // DUKE JIBS
		setactor[spriteid].mdflags 2
		ifvarg tilenum 1744 ifvarl tilenum 1780 // HEADJIB1, ARMJIB1, LEGJIB1
		setactor[spriteid].mdflags 2 // ANIMATION OFF
		ifvarg tilenum 2200 ifvarl tilenum 2213 // LIZMANHEAD1, LIZMANARM1, LIZMANLEG1
		setactor[spriteid].mdflags 2 // ANIMATION OFF
		ifvarg tilenum 2244 ifvarl tilenum 2270 // JIBS1, JIBS2, JIBS3, JIBS4, JIBS5
		setactor[spriteid].mdflags 2 // ANIMATION OFF
		ifvarg tilenum 2285 ifvarl tilenum 2294 // JIBS6
		setactor[spriteid].mdflags 2 // ANIMATION OFF
	 	ifvarg tilenum 2389 ifvarl tilenum 2419 // SCRAPS
	 	setactor[spriteid].mdflags 2 // ANIMATION OFF
 	}
 	addvar spriteid 1
}
ends


onevent EVENT_ENTERLEVEL

setvarvar raining rainstart
setvar rainstart 0
ifvarn startflag 0
setvar startflag 1

state stopanimation

endevent


onevent EVENT_RESETINVENTORY

setplayer[THISACTOR].firstaid_amount 50

ifvare startflag 0
{
	readgamevar ep1hi1
	readgamevar ep1hi2
	readgamevar ep1hi3
	readgamevar ep2hi1
	readgamevar ep2hi2
	readgamevar ep2hi3
	readgamevar ep3hi1
	readgamevar ep3hi2
	readgamevar ep3hi3
	readgamevar ep4hi1
	readgamevar ep4hi2
	readgamevar ep4hi3
	readgamevar ep5hi1
	readgamevar ep5hi2
	readgamevar ep5hi3
	readgamevar ep6hi1
	readgamevar ep6hi2
	readgamevar ep6hi3
	readgamevar ep7hi1
	readgamevar ep7hi2
	readgamevar ep7hi3
	readgamevar complete
	setvar nukepart 5
	
	getuserdef[THISACTOR].player_skill temp
	ifvare temp 4
	{
		setvar tempb 0
		setvar tipfield 131071
		ifvarn complete 0
		{
			switch VOLUME
			case 0 ifvarand complete 1 setvar tempb 1 break
			case 1 ifvarand complete 2 setvar tempb 1 break
			case 2 ifvarand complete 4 setvar tempb 1 break
			case 3 ifvarand complete 8 setvar tempb 1 break
			case 4 ifvarand complete 16 setvar tempb 1 break
			case 5 ifvarand complete 32 setvar tempb 1 break
			case 6 ifvarand complete 64 setvar tempb 1 break
			endswitch
		}
			ifvare tempb 1
			{
				setvar score STARTSCORE3
				setvar skillpoint STARTSKILL3
				setvar lastscoredisp STARTSCORE3
				setvar nukepart 30
			}
			else
			{
				setvar score STARTSCORE2
				setvar skillpoint STARTSKILL2
				setvar lastscoredisp STARTSCORE2
				setvar nukepart 30
			}
	}
	setvar startflag 1
}



setplayer[THISACTOR].holoduke_amount 1200
setplayer[THISACTOR].heat_amount 600
setvar currholo -1

endevent

state shadepulse
getplayer[THISACTOR].player_par temp
shiftvarl temp 7
sin tempb temp
shiftvarr tempb 11
setvarvar shade tempb
ends

state shieldbar
getactor[barrierup].extra tempb
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 5602 shade pal orientation ZERO ZERO xdim ydim
	  addvar digx 1
	  break
}
ends

state staminabar

setvarvar tempb stamina
divvar tempb 52
setvarvar tempc digx
addvarvar tempc tempb
setvar temp 0
whilevarn temp 1
{
	  ifvarvarg digx tempc setvar temp 1
	  rotatesprite digx digy digz 0 5601 shade pal orientation ZERO ZERO xdim ydim
	  addvar digx 1
	  break
}

ends

state lifebar
setvar pal 0
setvarvar tempb hp

ifvarg tempb 200 { setvar tilenum 5604 divvar tempb 4 }
else ifvarg tempb 100 { setvar tilenum 5601 divvar tempb 2 }
else 
{
	 setvar tilenum 5605
	 divvar tempb 2
}
setvarvar tempc digx
addvarvar tempc tempb
setvar temp 0
whilevarn temp 1
{
	  ifvarvarg digx tempc setvar temp 1
	  rotatesprite digx digy digz 0 tilenum shade pal orientation ZERO ZERO xdim ydim
	  addvar digx 1
	  break
}

ends

state armorbar
setvar digy 200
setvar pal 12
divvar tempb 3
setvarvar tempc digx
addvarvar tempc tempb
setvar temp 0
whilevarn temp 1
{
	  ifvarvarg digx tempc setvar temp 1
	  rotatesprite digx digy digz 0 5605 shade pal orientation ZERO ZERO xdim ydim
	  addvar digx 1
	  break
}

ends

state weightbar

ifvarvarl weight MAXLOAD setvar pal 12 else setvar pal 0
setvarvar tempb weight
divvar tempb 100 // 128
setvarvar tempc digx
addvarvar tempc tempb
setvar temp 0
whilevarn temp 1
{
	  ifvarvarg digx tempc setvar temp 1
	  rotatesprite digx digy digz 0 5605 shade pal orientation ZERO ZERO xdim ydim
	  addvar digx 1
	  break
}

ends

state xpbar

getplayer[THISACTOR].curr_weapon temp
switch temp
case 0 setvarvar tempb weap0xp break
case 1 setvarvar tempb weap1xp break
case 2 setvarvar tempb weap2xp break
case 3 setvarvar tempb weap3xp break
case 4 setvarvar tempb weap4xp break
case 5 case 10 setvarvar tempb weap5xp break
case 6 case 11 setvarvar tempb weap6xp break
case 7 setvarvar tempb weap7xp break
case 8 setvarvar tempb weap8xp break
case 9 setvarvar tempb weap9xp break
endswitch

switch pdamage
case 60 setvar tempc L0XP break // tempc is the length of the bar in XP
case 80 setvar tempc L1XP subvar tempc L0XP subvar tempb L0XP break // tempb is set to position in bar
case 100 setvar tempc L2XP subvar tempc L1XP subvar tempb L1XP break
case 120 setvar tempc L3XP subvar tempc L2XP subvar tempb L2XP break
case 140 setvar tempc L4XP subvar tempc L3XP subvar tempb L3XP break
case 160 setvar tempc L5XP subvar tempc L4XP subvar tempb L4XP break
case 180 setvar tempc L6XP subvar tempc L5XP subvar tempb L5XP break
case 200 setvar tempc L7XP subvar tempc L6XP subvar tempb L6XP break
case 220 setvar tempc L8XP subvar tempc L7XP subvar tempb L7XP break
case 240 setvar tempc L9XP subvar tempc L8XP subvar tempb L8XP break
case 260  break // MAX
endswitch

ifvare tempc 0 setvar tempc 1
mulvar tempb 50 // 50 is total length of full bar
divvarvar tempb tempc

setvarvar tempc digx
addvarvar tempc tempb
ifvarl tempb 1 break
setvar tilenum 5605

ifvarl pdamage 100 setvar tilenum 5604 else
// ifvarg xpmult 29 setvar pal 4 else // no XP, black
// ifvarg xpmult 24 setvar tilenum 5605 else // .25 XP, red
ifvarg xpmult 13 setvar tilenum 5601   // .50 XP, yellow
else setvar tilenum 5604			   // full XP, blue


ifvarg xpmult 13 state shadepulse
setvar temp 0
whilevarn temp 1
{
	ifvarvarg digx tempc setvar temp 1
	rotatesprite digx digy digz 0 tilenum shade pal orientation ZERO ZERO xdim ydim
	addvar digx 1
	break
}

ends


onevent EVENT_DRAWWEAPON

ifvare noreccam 1 { setvar RETURN -1 break }

ifvarn ONCAR 0 { setvar RETURN -1 break }

ifvarg menutoggle 0 setvar RETURN -1
ifvarg superkicking 0 setvar RETURN -1

endevent

onevent EVENT_DISPLAYCROSSHAIR

ifvare noreccam 1 { setvar RETURN -1 break }

ifvarg menutoggle 0 
{
	 setvar RETURN -1
	 
}


ifvarn target -1 ifvare menutoggle 0
{
	  setvar RETURN -1
	  state shadepulse
	  setvar orientation 1
	  setvar digx 159
	  setvar digy 100
	  setvar digz 16384
	  getuserdef[THISACTOR].screen_size temp
	  //ifvarn temp 0 ifvarn temp 4 subvar digy 12
	  rotatesprite digx digy digz 0 5603 shade 0 0 ZERO ZERO xdim ydim
}
  
endevent


state sidekickcoords
	ifvarl superkicking 4
	{
		setvar tilenum 5560
		setvar shade 16
		setvar angvar 0
		switch superkicking
		
		case 1
		setvar digy 187
		setvar digx 160
		break
		case 2
		setvar digy 184
		setvar digx 140
		break
		case 3
		setvar digy 182
		setvar digx 120
		break
		endswitch

	}
	else ifvarl superkicking 9
	{
		setvar shade 10
		setvar tilenum 5561
		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 75
			setvar digy 194
			setvar angvar 12
		 break
		case 8
			setvar digx 80
			setvar digy 190
			setvar angvar 12
		break
	    endswitch
	}
	else
	{	
		setvar shade 6
		setvar tilenum 5562
		switch superkicking
		
		case 9
			setvar digx 150
			setvar digy 185
			setvar angvar 0
		break
		
		case 10
			setvar digx 155
			setvar digy 180
			setvar angvar 2032
		break
		
		case 11
			setvar digx 160
			setvar digy 175
			setvar angvar 2016
		break
		
		case 12
		case 13
			setvar digx 170
			setvar digy 170
			setvar angvar 0
		break
		
		endswitch
	}
ends

state spinkickcoords
	ifvarl superkicking 4
	{
		setvar tilenum 5560
		setvar shade 16
		setvar angvar 0
		switch superkicking
		
		case 1
		ifvare superkickdone 1 setvar digx 300 else	
		setvar digx 160
		setvar digy 187
		break
		case 2
		ifvare superkickdone 1 setvar digx 290 else
		setvar digx 140	
		setvar digy 184

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

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

onevent EVENT_DISPLAYSBAR

setvar RETURN -1

endevent

onevent EVENT_DISPLAYROOMS

ifvare noreccam 1
{
	setvarvar camerax camxsaved
	setvarvar cameray camysaved
	setvarvar cameraz camzsaved
	setvarvar cameraang camangsaved
	setvarvar camerasect camsectsaved
	setvarvar camerahoriz camhorizsaved
}

ifvarn ONCAR 0 setvarvar cameradist lastcameradist


endevent

onevent EVENT_DISPLAYREST
setuserdef[THISACTOR].screen_size 3
// prevents player from bringing up the status bar, which would interfere with the custom HUD display

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
}

getplayer[THISACTOR].newowner temp
ifvarn temp -1 break
ifvare noreccam 1 break

ifvare ONCAR 2
{
	setvar digy 172
	setvar pal 0
	setvar digx 425
	setvar digz 32768
	setvar tilenum 2822
	setvar shade 0
	setvar temp 315
	gametextz tilenum digx digy temp shade pal 0 0 0 xdim ydim digz
	setvar temp 316
	addvar digx 125
	gametextz tilenum digx digy temp shade 2 0 0 0 xdim ydim digz
	subvar digx 125
	addvar digy 5
	setvar temp 307
	gametextz tilenum digx digy temp shade pal 0 0 0 xdim ydim digz
	setvar temp 311
	addvar digx 125
	gametextz tilenum digx digy temp shade 2 0 0 0 xdim ydim digz
	subvar digx 125
	addvar digy 5
	setvar temp 308
	gametextz tilenum digx digy temp shade pal 0 0 0 xdim ydim digz
	setvar temp 312
	addvar digx 125
	gametextz tilenum digx digy temp shade 2 0 0 0 xdim ydim digz
	subvar digx 125
	addvar digy 5
	setvar temp 309
	gametextz tilenum digx digy temp shade pal 0 0 0 xdim ydim digz
	setvar temp 313
	addvar digx 125
	gametextz tilenum digx digy temp shade 2 0 0 0 xdim ydim digz
	subvar digx 125
	addvar digy 5
	setvar temp 310
	gametextz tilenum digx digy temp shade pal 0 0 0 xdim ydim digz
	setvar temp 314
	addvar digx 125
	gametextz tilenum digx digy temp shade 2 0 0 0 xdim ydim digz
	subvar digx 125
	addvar digy 5
	setvar temp 317
	gametextz tilenum digx digy temp shade pal 0 0 0 xdim ydim digz
	setvar temp 318
	addvar digx 125
	gametextz tilenum digx digy temp shade 2 0 0 0 xdim ydim digz
}

ifvarn camerasprite -1
{
	// showview <x> <y> <z> <angle> <horiz> <sector> <scrn_x1> <scrn_y1> <scrn_x2> <scrn_y2>
	getplayer[THISACTOR].i spriteid
	getplayer[THISACTOR].posx x
    getplayer[THISACTOR].posy y
    getactor[camerasprite].x mx
    getactor[camerasprite].y my
    subvarvar mx x
    subvarvar my y
    getangle angvar mx my
    getactor[camerasprite].z mz
    subvar mz 3072
    getplayer[THISACTOR].posz z
    setvarvar digz mz
    addvarvar digz z
    divvar digz 2
    
    subvarvar mz z
    
    ldist xydist spriteid camerasprite
    divvar xydist 2 // new
    
    setvarvar digx x
	addvarvar digx xydist
	rotatepoint x y digx y angvar x y
    
    
    divvar xydist -4 // -8
    ifvare xydist 0 setvar xydist 1
    divvarvar mz xydist
    addvar mz 100
	// showview camerax cameray cameraz angvar mz camerasect 206 118 310 185
	showview x y cameraz angvar mz camerasect 206 118 310 185
}



// Next is the code for the Upgrade Menu

ifvare menutoggle 1
{

setvar shade 0
setvar pal 0
setvar digx 160
setvar digy 100
setvar digz 49152
setvar orientation 1
rotatesprite digx digy digz menubackang MENU_NUKEBACK shade pal orientation ZERO ZERO xdim ydim

setvar digz 32768
setvar digy 97
setvar orientation 1
rotatesprite digx digy digz 0 MENU_YELLOWBACK shade pal orientation ZERO ZERO xdim ydim
setvar orientation 0
setvar digz 36864 //40960
rotatesprite digx digy digz 0 MENU_BLACKBACK shade pal orientation ZERO ZERO xdim ydim

ifvare menuitem 0
{
	setvar tilenum 2908
    setvar temp 165
    gametext tilenum 220 100 temp 0 0 0 ZERO ZERO xdim ydim
}
setvar pal 0
setvar shade 0
// position 0; this is the 12 o'clock position
// MAX HEALTH UPGRADE ICON
setvar digx 160
//setvar digy 17
setvar digy 7
setvar digz 131072
setvar orientation 0
rotatesprite digx digy 49152 0 MENU_GLOW shade pal orientation ZERO ZERO xdim ydim
ifvare menuitem 1 state shadepulse else setvar shade 0
getuserdef[THISACTOR].screen_size temp
ifvarn temp 0 ifvarn temp 4 addvar digy 8
rotatesprite digx digy digz 0 100 shade pal orientation ZERO ZERO xdim ydim

ifvare menuitem 1
{
// first menu choice: increase max health
 
	setvar orientation 16
    setvar shade 0
    setvar temp 167
    setvar digx 235
    setvar digy 50
    setvar tilenum 2908
    setvar pal 0
    gametext tilenum digx digy temp shade pal orientation ZERO ZERO xdim ydim
    
 
    setvar digx 100
    setvar digy 80
    setvar pal 12
    setvar temp 126
    minitext digx digy temp shade pal
    setvar tilenum 3010
    setvar digx 215
    digitalnumber tilenum digx digy maxhealth shade pal orientation ZERO ZERO xdim ydim
    setvar digy 90
    setvar digx 100
    setvar temp 127
    minitext digx digy temp shade pal
    setvar digx 215
    digitalnumber tilenum digx digy maxarmor shade pal orientation ZERO ZERO xdim ydim
    setvar digx 100
    setvar digy 100
    setvar temp 128
    minitext digx digy temp shade pal
    setvar digx 215
    state healthcost
    digitalnumber tilenum digx digy cost shade pal orientation ZERO ZERO xdim ydim
	setvar orientation 0
}

// position 1; this is the 2 o'clock position
// HOLODUKE UPGRADE ICON
setvar pal 0
setvar digx 240
setvar digy 35
rotatesprite digx digy 49152 0 MENU_GLOW shade pal orientation ZERO ZERO xdim ydim
ifvare menuitem 2 { state shadepulse setvar digz 45056 } else { setvar digz 32768 setvar shade 0 }
rotatesprite digx digy digz 0 holoframe shade pal orientation ZERO ZERO xdim ydim // cycle 1348-51

// second menu choice:  UPGRADE DUKEBOT
ifvare menuitem 2 
{ 
	
   setvar orientation 16
   setvar shade 0
   setvar temp 168
   setvar digx 230
   setvar digy 50
   setvar tilenum 2908
   setvar pal 0
   gametext tilenum digx digy temp shade pal orientation ZERO ZERO xdim ydim
 
   setvar pal 12
   setvar shade 0
   // display the current level
   setvar digx 100
   setvar digy 80
   setvar temp 140
   minitext digx digy temp shade pal
   setvar tempb 20
   subvarvar tempb holomult
   setvar tilenum 3010
   setvar digx 215
   digitalnumber tilenum digx digy tempb shade pal orientation ZERO ZERO xdim ydim
   // display the cost
   setvar digx 100
   setvar digy 90
   setvar temp 128
   minitext digx digy temp shade pal
   setvar digx 215
   state holocost
   digitalnumber tilenum digx digy cost shade pal orientation ZERO ZERO xdim ydim
   setvar orientation 0
}
 
// position 2; this is the 3 o'clock position
// SPECIAL AMMO ICON
setvar pal 0
setvar digx 265
setvar digy 85
rotatesprite digx digy 49152 0 MENU_GLOW shade pal orientation ZERO ZERO xdim ydim
ifvare menuitem 3 { state shadepulse setvar digz 24576 }  else { setvar shade 0 setvar digz 16384 }
rotatesprite digx digy digz 0 MENU_AMMO shade pal orientation ZERO ZERO xdim ydim

// third menu choice purchase special ammo
ifvare menuitem 3 
{
   setvar orientation 16
   setvar shade 0
   setvar temp 169
   setvar digx 260
   setvar digy 50
   setvar tilenum 2908
   setvar pal 0
   gametext tilenum digx digy temp shade pal orientation ZERO ZERO xdim ydim
   
   setvar pal 12
   setvar shade 0
 
   getplayer[THISACTOR].curr_weapon tempb

   switch tempb
    case 0:
    case 1:  setvar tempc PISTOLAMMOAMOUNT setvar tilenum 21 break
    case 2:  setvar tempc SHOTGUNAMMOAMOUNT setvar tilenum 28 break
    case 3:  setvar tempc CHAINGUNAMMOAMOUNT setvar tilenum 22 break
    case 4:  setvar tempc RPGAMMOBOX setvar tilenum 23 break
    case 10:
    case 5:  setvar tempc HANDBOMBBOX setvar tilenum 26 break
    case 6:  setvar tempc CRYSTALAMMOAMOUNT setvar tilenum 25 break
    case 7:  setvar tempc DEVISTATORAMMOAMOUNT setvar tilenum 29 break
    case 8:  setvar tempc 1 setvar tilenum 27 break
    case 9:  setvar tempc FREEZEAMMOAMOUNT setvar tilenum 24 break
    case 11: setvar tempc CRYSTALAMMOAMOUNT setvar tilenum 32 break
   endswitch
   
   setvar digx 125
   setvar digy 80
   digitalnumber 3010 digx digy tempc shade pal orientation ZERO ZERO xdim ydim
   
   setvar temp 141
   setvar digx 135
   minitext digx digy temp shade pal
   
   setvar digx 180
   setvar digz 16384
   rotatesprite digx digy digz 0 tilenum shade pal orientation ZERO ZERO xdim ydim

   minitext 120 95 191 0 12
   setvar orientation 0
}

// position 3; this is the 4 o'clock position
// LEGS UPGRADE ICON
setvar pal 0
setvar digx 255
setvar digy 130
rotatesprite digx digy 49152 0 MENU_GLOW shade pal orientation ZERO ZERO xdim ydim
ifvare menuitem 4 { state shadepulse setvar digz 24576 } else { setvar shade 0 setvar digz 16384 }
rotatesprite digx digy digz 0 MENU_BOOTS shade pal orientation ZERO ZERO xdim ydim

// fourth menu choice: LEG UPGRADES
ifvare menuitem 4 
{ 
	
   setvar orientation 16
   setvar shade 0
   setvar temp 170
   setvar digx 270
   setvar digy 50
   setvar tilenum 2908
   setvar pal 0
   gametext tilenum digx digy temp shade pal orientation ZERO ZERO xdim ydim
   
   setvar digx 100
   setvar digy 80
   ifvarg leglevel 0 setvar pal 10 else setvar pal 1
    
	    setvar temp 193
	    minitext digx digy temp shade pal
    
   ifvarg leglevel 1 setvar pal 10 else setvar pal 1
     
	     setvar temp 183
	     setvar digy 88
	     minitext digx digy temp shade pal 
     
   ifvarg leglevel 2 setvar pal 10 else setvar pal 1
     
	     setvar digy 96
	     setvar temp 184
	     minitext digx digy temp shade pal
	     
   ifvarg leglevel 3 setvar pal 10 else setvar pal 1
   
   		 setvar digy 104
   		 setvar temp 182
   		 minitext digx digy temp shade pal
     
   setvar pal 12
   setvar digy 116
   setvar temp 128
   minitext digx digy temp shade pal
   setvar digx 215
   state legcost
   setvar tilenum 3010
   digitalnumber tilenum digx digy cost shade pal orientation ZERO ZERO xdim ydim
   setvar orientation 0
}

// position 4; this is the 5 o'clock position
// DAMAGE REDUCTION ICON
setvar pal 0
setvar digx 210
setvar digy 165
rotatesprite digx digy 49152 0 MENU_GLOW shade pal orientation ZERO ZERO xdim ydim
ifvare menuitem 5 { state shadepulse setvar digz 32768 } else { setvar shade 0 setvar digz 20480 }
rotatesprite digx digy digz 0 MENU_ARMOR shade pal orientation ZERO ZERO xdim ydim


// fifth menu choice: DEFENSE

ifvare menuitem 5 
{ 
	
   setvar orientation 16
   setvar shade 0
   setvar temp 149
   setvar digx 235
   setvar digy 50
   setvar tilenum 2908
   setvar pal 0
   gametext tilenum digx digy temp shade pal orientation ZERO ZERO xdim ydim
   
   setvar temp 145
   setvar digx 100
   setvar digy 80
   setvar pal 12
   minitext digx digy temp shade pal
   // display current damage reduction percentage
   setvar digx 215
   setvar tilenum 3010
   // dreduction is a number between 10 and 100, the percentage of enemy damage taken
   digitalnumber tilenum digx digy dreduction shade pal orientation ZERO ZERO xdim ydim
   // and the % sign
   setvar digx 222
   setvar temp 158
   minitext digx digy temp shade pal
   // display the cost
   setvar digy 90
   setvar digx 100
   setvar temp 128
   minitext digx digy temp shade pal
   state dreductioncost
   setvar digx 215
   digitalnumber tilenum digx digy cost shade pal orientation ZERO ZERO xdim ydim
   setvar orientation 0
}


// position 5; 7 o'clock position
// WEAPON DAMAGE UPGRADE ICON
setvar pal 0
setvar digx 110
setvar digy 165

rotatesprite digx digy 49152 0 MENU_GLOW shade pal orientation ZERO ZERO xdim ydim
ifvare menuitem 6 { state shadepulse setvar digz 14336 } else { setvar shade 0 setvar digz 10240 }
rotatesprite digx digy digz 0 MENU_BACKPACK shade pal orientation ZERO ZERO xdim ydim


// sixth menu choice:  upgrade limits
ifvare menuitem 6 
{
   setvar orientation 16
   setvar shade 0
   setvar temp 174
   setvar digx 260
   setvar digy 50
   setvar tilenum 2908
   setvar pal 0
   gametext tilenum digx digy temp shade pal orientation ZERO ZERO xdim ydim
   
   setvar digx 100
   setvar digy 80
   
   ifvarg limits 0 setvar pal 10 else setvar pal 1
    
	    setvar temp 211
	    minitext digx digy temp shade pal
    
   ifvarg limits 1 setvar pal 10 else setvar pal 1
     
	     setvar temp 212
	     setvar digy 88
	     minitext digx digy temp shade pal 
     
   ifvarg limits 2 setvar pal 10 else setvar pal 1
     
	     setvar digy 96
	     setvar temp 213
	     minitext digx digy temp shade pal
	     
   ifvarg limits 3 setvar pal 10 else setvar pal 1
     
	     setvar digy 104
	     setvar temp 214
	     minitext digx digy temp shade pal	     
	     
     
   setvar pal 12
   setvar digy 116
   setvar temp 128
   minitext digx digy temp shade pal
   setvar digx 215
   state limitcost
   setvar tilenum 3010
   digitalnumber tilenum digx digy cost shade pal orientation ZERO ZERO xdim ydim
   setvar orientation 0
}


// position 6; 8 o'clock position
// ENERGY SHIELD UPGRADE ICON
setvar pal 0
setvar digx 55
setvar digy 130
setvar shade 0

rotatesprite digx digy 20480 0 MENU_GLOW shade pal orientation ZERO ZERO xdim ydim
ifvare menuitem 7 { state shadepulse setvar digz 40960 } else { setvar shade 0 setvar digz 30720 }
setvar orientation 4
rotatesprite digx digy digz 1024 1502 shade pal orientation ZERO ZERO xdim ydim
setvar orientation 0
addvar digx 25
subvar digy 7
rotatesprite digx digy digz 0 MENU_SHIELD shade pal orientation ZERO ZERO xdim ydim

// seventh menu choice:  upgrade energy shield
ifvare menuitem 7 
{
	
   setvar orientation 16
   setvar shade 0
   setvar temp 205
   setvar digx 255
   setvar digy 50
   setvar tilenum 2908
   setvar pal 0
   gametext tilenum digx digy temp shade pal orientation ZERO ZERO xdim ydim
   
   setvar digx 100
   setvar digy 80
   ifvarg barrierlevel 0 setvar pal 10 else setvar pal 1
     
	    setvar temp 132
	    minitext digx digy temp shade pal
    
   ifvarg barrierlevel 1 setvar pal 10 else setvar pal 1
     
   		 setvar digy 88
	     setvar temp 156 //155
	     minitext digx digy temp shade pal
    
   ifvarg barrierlevel 2 setvar pal 10 else setvar pal 1
     
	     setvar digy 96
	     setvar temp 177 //156
	     minitext digx digy temp shade pal
     
   ifvarg barrierlevel 3 setvar pal 10 else setvar pal 1
     
	     setvar digy 104
	     setvar temp 157 //177
	     minitext digx digy temp shade pal

   setvar pal 12
   setvar digy 122
   setvar temp 128
   minitext digx digy temp shade pal
   setvar digx 215
   state barriercost
   setvar tilenum 3010
   digitalnumber tilenum digx digy cost shade pal orientation ZERO ZERO xdim ydim
   setvar orientation 0
}

// position 7; 9 o'clock position
// NUKE COMBO PIC
setvar pal 0
setvar shade 0
setvar digx 55
setvar digy 85
rotatesprite digx digy 49152 0 MENU_GLOW shade pal orientation ZERO ZERO xdim ydim
ifvare menuitem 8 { state shadepulse setvar digz 16384 } else { setvar shade 0 setvar digz 12288 }
rotatesprite digx digy digz 0 MENU_COMBO shade pal orientation ZERO ZERO xdim ydim

// eighth menu choice:  NUKE COMBOS
ifvare menuitem 8
{ 
   setvar orientation 16
   setvar shade 0
   setvar temp 185
   setvar digx 240
   setvar digy 50
   setvar tilenum 2908
   setvar pal 0
   gametext tilenum digx digy temp shade pal orientation ZERO ZERO xdim ydim
   
    setvar digx 100
    setvar digy 70
    setvar temp 180
    setvar tilenum 3010
   ifvarg combolevel 0 setvar pal 10 else setvar pal 1
    
	    setvar temp 205
	    minitext digx digy temp shade pal
    
   ifvarg combolevel 1 setvar pal 10 else setvar pal 1
     
	     setvar temp 186
	     setvar digy 78
	     minitext digx digy temp shade pal 
     
   ifvarg combolevel 2 setvar pal 10 else setvar pal 1
     
	     setvar digy 86
	     setvar temp 187
	     minitext digx digy temp shade pal
     

   ifvarg combolevel 3 setvar pal 10 else setvar pal 1
     
	     setvar digy 94
	     setvar temp 188
	     minitext digx digy temp shade pal
	     
   ifvarg combolevel 4 setvar pal 10 else setvar pal 1
   
   		 setvar digy 102
   		 setvar temp 209
   		 minitext digx digy temp shade pal
     

   setvar pal 12
   setvar digy 116
   setvar temp 128
   minitext digx digy temp shade pal
   setvar digx 215
   state combocost
   digitalnumber tilenum digx digy cost shade pal orientation ZERO ZERO xdim ydim
   
   // display key combinations for combos
   setvar digx 165
   setvar digy 70
   setvar pal 8
   setvar shade 0
   setvar temp 267
   minitext digx digy temp shade pal
   setvar tempb 0
   whilevarn tempb 4
   {
	   addvar tempb 1
	   addvar temp 1
	   addvar digy 8
	   minitext digx digy temp shade pal
   }
   setvar digx 214
   addvar digy 2
   rotatesprite digx digy 16384 0 59 shade 0 0 ZERO ZERO xdim ydim
   
   setvar orientation 0
   
}

// position 8; 10 o'clock position
// GOGGLES UPGRADE ICON
setvar pal 0
setvar digx 80
setvar digy 35
rotatesprite digx digy 49152 0 MENU_GLOW shade pal orientation ZERO ZERO xdim ydim
ifvare menuitem 9 { state shadepulse setvar digz 16384 } else { setvar shade 0 setvar digz 10240 }
rotatesprite digx digy digz 0 MENU_GOGGLES shade pal orientation ZERO ZERO xdim ydim

// ninth menu choice:  goggle upgrade
ifvare menuitem 9 
{ 
   setvar orientation 16
   setvar shade 0
   setvar temp 172
   setvar digx 230
   setvar digy 50
   setvar tilenum 2908
   setvar pal 0
   gametext tilenum digx digy temp shade pal orientation ZERO ZERO xdim ydim
   
    setvar digx 100
    setvar digy 80
    setvar pal 10
   ifvarg gogglelevel 0 setvar pal 10 else setvar pal 1
    
	    setvar temp 143
	    minitext digx digy temp shade pal
    
   ifvarg gogglelevel 1 setvar pal 10 else setvar pal 1
     
	     setvar temp 181
	     setvar digy 88
	     minitext digx digy temp shade pal 
     
   ifvarg gogglelevel 2 setvar pal 10 else setvar pal 1
     
	     setvar digy 96
	     setvar temp 144
	     minitext digx digy temp shade pal
     
   setvar pal 12
   setvar digy 116
   setvar temp 128
   minitext digx digy temp shade pal
   setvar digx 215
   state gogglecost
   setvar tilenum 3010
   digitalnumber tilenum digx digy cost shade pal orientation ZERO ZERO xdim ydim
   setvar orientation 0

}

// high score button display

setvar orientation 0
setvar digx 290
setvar digy 175
setvar digz 12288
ifvare menuitem 10 state shadepulse else
setvar shade 8
setvar pal 0
rotatesprite digx digy digz 0 5606 shade pal orientation ZERO ZERO xdim ydim

// help button display

setvar orientation 0
setvar digx 20
setvar digy 40
setvar digz 28672
ifvare menuitem 11 state shadepulse else
setvar shade 8
setvar pal 0
rotatesprite digx digy digz 0 HELP_BUTTON shade pal orientation ZERO ZERO xdim ydim

}
// end of Upgrade Menu code

// High Scores

ifvare menutoggle 2
{
	setvar orientation 0
	setvar digx 160
	setvar digy 100
	setvar digz 65536
	setvar shade 0
	setvar pal 0
	rotatesprite digx digy digz 0 3245 shade pal orientation ZERO ZERO xdim ydim
	
	// Main banner "HIGH SCORES"
   setvar orientation 16
   setvar temp 197
   setvar digx 250
   setvar digy 5
   setvar tilenum 2908
   gametext tilenum digx digy temp shade pal orientation ZERO ZERO xdim ydim
   
   // EPISODE 1
   setvar tilenum STARTALPHANUM
   ifvare VOLUME 0 setvar pal 8 else setvar pal 0
   gametext tilenum 40 25 198 shade pal orientation ZERO ZERO xdim ydim
    ifvarg ep1hi1 0
    {
	   	digitalnumber 2837 130 25 1 shade 8 orientation ZERO ZERO xdim ydim
	   	digitalnumber 3010 145 26 ep1hi1 shade 8 orientation ZERO ZERO xdim ydim
    }
    ifvarg ep1hi2 0
    {
   		digitalnumber 2837 155 34 2 shade 1 orientation ZERO ZERO xdim ydim
   		digitalnumber 3010 170 35 ep1hi2 shade 1 orientation ZERO ZERO xdim ydim
	}
	ifvarg ep1hi3 0
	{
		digitalnumber 2837 180 43 3 shade 2 orientation ZERO ZERO xdim ydim
		digitalnumber 3010 195 44 ep1hi3 shade 2 orientation ZERO ZERO xdim ydim
    }
    ifvarand complete 1 rotatesprite 10 23 4096 0 COMPLETED_STAR shade 0 orientation ZERO ZERO xdim ydim
   // EPISODE 2
   ifvare VOLUME 1 setvar pal 8 else setvar pal 0
   gametext tilenum 40 50 199 shade pal orientation ZERO ZERO xdim ydim
   
	ifvarg ep2hi1 0
	{
		 digitalnumber 2837 130 50 1 shade 8 orientation ZERO ZERO xdim ydim
		 digitalnumber 3010 145 51 ep2hi1 shade 8 orientation ZERO ZERO xdim ydim
	}
    ifvarg ep2hi2 0
    {
   		digitalnumber 2837 155 59 2 shade 1 orientation ZERO ZERO xdim ydim
   		digitalnumber 3010 170 60 ep2hi2 shade 1 orientation ZERO ZERO xdim ydim
	}
	ifvarg ep2hi3 0
	{
   		digitalnumber 2837 180 68 3 shade 2 orientation ZERO ZERO xdim ydim
  		digitalnumber 3010 195 69 ep2hi3 shade 2 orientation ZERO ZERO xdim ydim
	}
	ifvarand complete 2 rotatesprite 10 48 4096 0 COMPLETED_STAR shade 0 orientation ZERO ZERO xdim ydim
   // EPISODE 3
   ifvare VOLUME 2 setvar pal 8 else setvar pal 0
   gametext tilenum 40 75 200 shade pal orientation ZERO ZERO xdim ydim
   ifvarg ep3hi1 0
   {
   		digitalnumber 2837 130 75 1 shade 8 orientation ZERO ZERO xdim ydim
   		digitalnumber 3010 145 76 ep3hi1 shade 8 orientation ZERO ZERO xdim ydim
   }
   ifvarg ep3hi2 0
   {
	   digitalnumber 2837 155 83 2 shade 1 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 170 84 ep3hi2 shade 1 orientation ZERO ZERO xdim ydim
   }
   ifvarg ep3hi3 0
   {
	   digitalnumber 2837 180 92 3 shade 2 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 195 93 ep3hi3 shade 2 orientation ZERO ZERO xdim ydim
   }
   ifvarand complete 4 rotatesprite 10 73 4096 0 COMPLETED_STAR shade 0 orientation ZERO ZERO xdim ydim
   
   // EPISODE 4
   ifvare VOLUME 3 setvar pal 8 else setvar pal 0
   gametext tilenum 40 100 201 shade pal orientation ZERO ZERO xdim ydim
    ifvarg ep4hi1 0
    {
	   digitalnumber 2837 130 100 1 shade 8 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 145 101 ep4hi1 shade 8 orientation ZERO ZERO xdim ydim
	}
	ifvarg ep4hi2 0
	{
	   digitalnumber 2837 155 108 2 shade 1 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 170 109 ep4hi2 shade 1 orientation ZERO ZERO xdim ydim
	}
	ifvarg ep4hi3 0
	{
	   digitalnumber 2837 180 116 3 shade 2 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 195 117 ep4hi3 shade 2 orientation ZERO ZERO xdim ydim
	}
	ifvarand complete 8 rotatesprite 10 98 4096 0 COMPLETED_STAR shade 0 orientation ZERO ZERO xdim ydim
	
   // EPISODE 5
   ifvare VOLUME 4 setvar pal 8 else setvar pal 0
   gametext tilenum 40 125 202 shade pal orientation ZERO ZERO xdim ydim
   ifvarg ep5hi1 0
   {
	   digitalnumber 2837 130 125 1 shade 8 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 145 126 ep5hi1 shade 8 orientation ZERO ZERO xdim ydim
   }
   ifvarg ep5hi2 0
   {
	   digitalnumber 2837 155 133 2 shade 1 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 170 134 ep5hi2 shade 1 orientation ZERO ZERO xdim ydim
   }
   ifvarg ep5hi3 0
   {   
	   digitalnumber 2837 180 141 3 shade 2 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 195 142 ep5hi3 shade 2 orientation ZERO ZERO xdim ydim
   }
   ifvarand complete 16 rotatesprite 10 123 4096 0 COMPLETED_STAR shade 0 orientation ZERO ZERO xdim ydim
   
   // EPISODE 6
   ifvare VOLUME 5 setvar pal 8 else setvar pal 0
   gametext tilenum 40 150 203 shade pal orientation ZERO ZERO xdim ydim
   ifvarg ep6hi1 0
   {
	   digitalnumber 2837 130 150 1 shade 8 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 145 151 ep6hi1 shade 8 orientation ZERO ZERO xdim ydim
   }
   ifvarg ep6hi2 0
   {
	   digitalnumber 2837 155 158 2 shade 1 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 170 159 ep6hi2 shade 1 orientation ZERO ZERO xdim ydim
   }
   ifvarg ep6hi3 0
   {
	   digitalnumber 2837 180 166 3 shade 2 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 195 167 ep6hi3 shade 2 orientation ZERO ZERO xdim ydim
   }
   ifvarand complete 32 rotatesprite 10 148 4096 0 COMPLETED_STAR shade 0 orientation ZERO ZERO xdim ydim
   
   // EPISODE 7
   ifvare VOLUME 6 setvar pal 8 else setvar pal 0
   gametext tilenum 40 175 204 shade pal orientation ZERO ZERO xdim ydim
   ifvarg ep7hi1 0
   {
	   digitalnumber 2837 130 175 1 shade 8 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 145 176 ep7hi1 shade 8 orientation ZERO ZERO xdim ydim
   }
   ifvarg ep7hi2 0
   {
	   digitalnumber 2837 155 183 2 shade 1 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 170 184 ep7hi2 shade 1 orientation ZERO ZERO xdim ydim
   }
   ifvarg ep7hi3 0
   {
	   digitalnumber 2837 180 191 3 shade 2 orientation ZERO ZERO xdim ydim
	   digitalnumber 3010 195 192 ep7hi3 shade 2 orientation ZERO ZERO xdim ydim
   }
   ifvarand complete 64 rotatesprite 10 173 4096 0 COMPLETED_STAR shade 0 orientation ZERO ZERO xdim ydim

   break
}

ifvare menutoggle 3
{
	setvar orientation 0
	setvar digx 160
	setvar digy 100
	setvar digz 40960
	setvar shade 0
	setvar pal 0
	rotatesprite digx digy digz 0 DNWMD_HELP shade pal orientation ZERO ZERO xdim ydim
	
	break
}

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

	setvar orientation 0
	setvar pal 0
	setvar angvar 0
	setvar digz 34816
	ifvare spinkick 0 state sidekickcoords
	else state spinkickcoords

rotatesprite digx digy digz angvar tilenum shade orientation pal ZERO ZERO xdim ydim
}

//********************BASIC HUD DISPLAY ****************************

// display armor amount

setvar digx 3
setvar digy 200
setvar digz 8192
setvar orientation 21
setvar pal 7
setvar shade 0
getplayer[THISACTOR].shield_amount tempb

ifvarg tempb 0 state armorbar

getplayer[THISACTOR].shield_amount tempb
ifvarg tempb 49
 {
  setvar orientation 20
  setvar digx 3
  setvar digy 195
  setvar temp 38
  setvar pal 18
  minitext digx digy temp shade pal
 }


// display life bar

setvar digx 3
setvar digy 194
setvar digz 8192
setvar orientation 20
setvar shade 0
getactor[THISACTOR].extra hp
ifvarg hp 0 state lifebar
setvar pal 12

setvar digx 3
setvar digy 189
setvar temp 194
ifvarg hp 100 setvar pal 10
minitext digx digy temp shade pal
addvar digx 23
setvar tilenum 3010
setvar orientation 16
ifvarg hp 100 setvar pal 2
digitalnumber tilenum digx digy hp shade pal orientation ZERO ZERO xdim ydim

ifvare menutoggle 0 ifvare ONCAR 0
{


// display stamina bar

setvar digx 285
setvar digy 200
setvar digz 8192
setvar orientation 21
setvar pal 0
setvar shade 0

ifvarg stamina 26 state staminabar


  setvar orientation 20
  setvar digx 285
  setvar digy 195
  setvar temp 130
  setvar pal 18
  minitext digx digy temp shade pal
  
// display weight bar


setvar digx 285
setvar digy 194
setvar digz 8192
setvar orientation 21
setvar pal 0
setvar shade 0
ifvarg weight 260 state weightbar

  setvar orientation 20
  setvar digx 285
  setvar digy 189
  setvar temp 208
  setvar pal 10
  minitext digx digy temp shade pal
}

// display weapon level bar
ifvarn menutoggle 1 ifvarn menutoggle 2 ifvarn menutoggle 3
{
	setvar digx 120
	setvar digy 200
	setvar orientation 20
	setvar digz 8192
	setvar shade 0
	setvar pal 0
	ifvarl pdamage 240 state xpbar
	
	subvar digy 5
	setvar digx 120
	setvar temp 210
	setvar pal 12
	minitext digx digy temp shade pal
	setvar tilenum 3010
	setvarvar tempb pdamage
	subvar tempb 60
	divvar tempb 20
	setvar digx 168
	setvar digy 195
	setvar pal 12
	setvar orientation 16
	digitalnumber tilenum digx digy tempb shade pal orientation ZERO ZERO xdim ydim
}

// display force field strength

setvar digx 3
setvar digy 188
setvar digz 8192
setvar orientation 21
setvar pal 1
setvar shade 0
ifvarn barrierup -1
 {
  state shieldbar
  getactor[barrierup].extra tempb
  ifvarg tempb 99
  {
  setvar digx 3
  setvar digy 183
  setvar temp 173
  setvar pal 12
  minitext digx digy temp shade pal
  }
 }

// display ammo amount
getactor[THISACTOR].extra temp
ifvarg temp 0
{
	setvar digx 70
	setvar digy 196
	setvar digz 12288
	setvar orientation 16
	// first the ammo pic
	switch currentweapon
	 case 0
	 case 1 setvar tempb 40 subvar digz 4096
	 break
	 case 2 setvar tempb 49 
	 break
	 case 3 setvar tempb 41 
	 break
	 case 4 setvar tempb 44
	 break
	 case 5 
	 case 10
	 setvar tempb 47
	 break
	 case 11
	 case 6 setvar tempb 46 addvar digz 4096
	 break
	 case 7 setvar tempb 42 addvar digz 4096
	 break
	 case 8 setvar tempb 27 addvar digz 4096
	 break
	 case 9 setvar tempb 37 addvar digz 4096
	 break
	endswitch
	
	rotatesprite digx digy digz 0 tempb shade 0 0 ZERO ZERO xdim ydim
	setvar tilenum 3010
	setvar digx 82
	subvar digy 2
	setvar pal 12
	ifvare currentweapon 10 getplayer[THISACTOR].ammo_amount 5 temp else
	getplayer[THISACTOR].ammo_amount currentweapon temp
	digitalnumber tilenum digx digy temp shade pal orientation ZERO ZERO xdim ydim
	
	ifvarg special 0
	{
		setvar digx 92
		addvar digy 1
		setvar temp 195
		minitext digx digy temp shade pal
		setvar digx 108
		setvar pal 2
		digitalnumber tilenum digx digy special shade pal orientation ZERO ZERO xdim ydim
	}
}
// soul coin radar
ifvarn soulang -1 ifvarn menutoggle 1 ifvarn menutoggle 2
{
	ifvare soulsee 1 setvar pal 0 else setvar pal 17
	setvar orientation 1
	setvar shade 0
	setvar digx 245
	setvar digy 190
	rotatesprite digx digy souldist soulang MENU_ARROW shade pal orientation ZERO ZERO xdim ydim
}

// keycards
getplayer[THISACTOR].got_access tempc
ifvarn tempc 0 ifvare ONCAR 0
 {
	 setvar digz 16384
	 setvar orientation 16
	 setvar shade 0
// first bit is blue card, second bit is red card, third bit is yellow card
     ifvarand tempc 1
     {
	 setvar pal 0
	 setvar digx 260
	 setvar digy 193
     rotatesprite digx digy digz 0 60 shade pal orientation ZERO ZERO xdim ydim
     }
     ifvarand tempc 2
     {
	 setvar pal 21
	 setvar digx 267
	 setvar digy 186
	 rotatesprite digx digy digz 0 60 shade pal orientation ZERO ZERO xdim ydim
     }
     ifvarand tempc 4
     {
	 setvar pal 23
	 setvar digx 253
	 setvar digy 186
	 rotatesprite digx digy digz 0 60 shade pal orientation ZERO ZERO xdim ydim
     }
  }

// INVENTORY AMOUNT DISPLAY WHEN SELECTED BUT NOT IN USE
getplayer[THISACTOR].invdisptime temp
ifvarg temp 0
{
	setvar tilenum 3010
	setvar pal 0
	setvar shade 0
	//setvar digy 192
	setvar digy 160
	setvar digx 157
	setvar tempd 0

	setvar orientation 16
	getplayer[THISACTOR].inven_icon tempb
	switch tempb
	case 1 // firstaid kit
	getplayer[THISACTOR].firstaid_amount tempc
	break
	
	case 2 // steroids
	getplayer[THISACTOR].steroids_amount tempc
	divvar tempc 4
	break
	
	case 3 // holoduke
	getplayer[THISACTOR].holoduke_amount tempc
	divvar tempc 24
	break
	
	case 4 // jetpack
	getplayer[THISACTOR].jetpack_amount tempc
	divvar tempc 16
	break
	
	case 5 // goggles
	getplayer[THISACTOR].heat_amount tempc
	divvar tempc 12
	break
	
	case 6 // scuba
	getplayer[THISACTOR].scuba_amount tempc
	divvar tempc 64
	break
	
	case 7 // protective boots
	getplayer[THISACTOR].boot_amount tempc
	divvar tempc 2
	break
	endswitch
	
	
	digitalnumber tilenum digx digy tempc shade pal orientation ZERO ZERO xdim ydim
}
	

// INVENTORY ITEMS IN USE
// display steroids amount when in use
getplayer[THISACTOR].steroids_amount tempc
ifvarg tempc 0 ifvarl tempc 400
 {
	 setvar digx 8
	 setvar digy 50
	 setvar pal 0
	 setvar digz 24576
	 state shadepulse
	 setvar orientation 16
	 rotatesprite digx digy digz 0 55 shade 0 0 ZERO ZERO xdim ydim
	 setvar digy 60
	 setvar tilenum 3010
	 divvar tempc 4
	 digitalnumber tilenum digx digy tempc shade pal orientation ZERO ZERO xdim ydim
 }
// display goggle amount when in use
getplayer[THISACTOR].heat_on temp
ifvare temp 1
 {
	 getplayer[THISACTOR].heat_amount tempc
	 setvar digx 8
	 setvar digy 70
	 setvar pal 0
	 setvar digz 24576
	 state shadepulse
	 setvar orientation 16
	 rotatesprite digx digy digz 0 59 shade 0 0 ZERO ZERO xdim ydim
	 setvar digy 78
	 setvar tilenum 3010
	 divvar tempc 12
	 digitalnumber tilenum digx digy tempc shade pal orientation ZERO ZERO xdim ydim
 }
 // display jetpack amount when in use
ifp pjetpack
 {
	 getplayer[THISACTOR].jetpack_amount tempc
	 setvar digx 8
	 setvar digy 90
	 setvar pal 0
	 setvar digz 24576
	 state shadepulse
	 setvar orientation 16
	 rotatesprite digx digy digz 0 57 shade 0 0 ZERO ZERO xdim ydim
	 setvar digy 100
	 setvar tilenum 3010
	 divvar tempc 16
	 digitalnumber tilenum digx digy tempc shade pal orientation ZERO ZERO xdim ydim
 }
 
 ifvarn currholo -1 // display holobot health
  {
	  getactor[currholo].extra tempc
	  setvar digx 8
	  setvar digy 114
	  setvar digz 16384
	  setvar shade 0
	  setvar orientation 16
	  rotatesprite digx digy digz 0 1348 shade 0 0 ZERO ZERO xdim ydim
	  setvar digy 124
	  setvar tilenum 3010
	  digitalnumber tilenum digx digy tempc shade pal orientation ZERO ZERO xdim ydim
 }
 
// scuba amount when in use
getplayer[THISACTOR].scuba_on temp
ifvare temp 1
{
	getplayer[THISACTOR].scuba_amount tempc
	setvar digx 8
	setvar digy 135
	setvar digz 16384
	setvar shade 0
	setvar orientation 16
	rotatesprite digx digy digz 0 56 shade 0 0 ZERO ZERO xdim ydim
	setvar digy 144
	setvar tilenum 3010
	divvar tempc 64
	digitalnumber tilenum digx digy tempc shade pal orientation ZERO ZERO xdim ydim
} else // airleft display
{
	getplayer[THISACTOR].airleft tempb
	ifvarl tempb 390 ifvarg tempb 0
	{
		setvar digy 10
		setvar digx 45
		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 35
		setvar tilenum 2868
	    rotatesprite digx digy digz 0 tilenum 0 pal orientation 0 0 xdim ydim
	    setvar tilenum 2839
	    setvar digx 39
	    setvar digz 20480 //16384
	    rotatesprite digx digy digz 0 tilenum 0 pal orientation 0 0 xdim ydim
	}
}
	

// boots

ifvarg boot_on 0
{
	getplayer[THISACTOR].boot_amount tempc
	setvar digx 8
	setvar digy 156
	setvar digz 32768
	setvar shade 0
	setvar orientation 16
	rotatesprite digx digy digz 0 61 shade 0 0 ZERO ZERO xdim ydim
	setvar digy 165
	setvar tilenum 3010
	divvar tempc 2
	digitalnumber tilenum digx digy tempc shade pal orientation ZERO ZERO xdim ydim
}


// 	 debugging var display
//    setvar digx 150
//    setvar digy 14
//    setvar tilenum 3010
//    digitalnumber tilenum digx digy debugvar shade pal orientation ZERO ZERO xdim ydim
//    setvar digy 24
//    digitalnumber tilenum digx digy debugvarb shade pal orientation ZERO ZERO xdim ydim
//   setvar digy 32
//   digitalnumber tilenum digx digy debugvarc shade pal orientation ZERO ZERO xdim ydim


// if the nightvision goggles have just been turned on/off, display the transition effect

ifvarg hweapcount 0
{
	setvarvar temp hweapcount
	mulvar temp 160	
	rotatesprite 150 100 countvarb temp SWIRL 0 0 33 ZERO ZERO xdim ydim
}


// Display the word "score"

setvar digx 2
setvar digy 2
setvar orientation 26
setvar temp 175
setvar shade 0
setvar pal 0
minitext digx digy temp shade pal

// display the score with gradual increase
setvar digy 10
ifvarg score 9999 setvar digx 25
else
ifvarg score 999 setvar digx 20
else
ifvarg score 99 setvar digx 15
else
setvar digx 12
setvar tilenum 2837
setvar pal 1
ifvarvarg score lastscoredisp setvar pal 0 // do something to indicate score incrementing

digitalnumber tilenum digx digy lastscoredisp shade pal orientation ZERO ZERO xdim ydim

// Display the number of nuke coins

setvar tilenum 2837 
setvar digx 307
setvar digy 8
// setvar shade 0
setvar pal 0
// setvar tilenum DIGITALNUM

digitalnumber tilenum digx digy nukepart shade pal orientation ZERO ZERO xdim ydim

//  ...and the number of skill points

setvar digy 24
digitalnumber tilenum digx digy skillpoint shade pal orientation ZERO ZERO xdim ydim

ifvarg holosphere 0 // holosphere if on
   {
	   setvar digx 298
	   setvar digy 35
	   setvar temp 189
	   minitext digx digy temp shade pal
	   setvar digx 305
	   setvar digy 40
	   setvarvar tempb holosphere
	   divvar tempb 26
	   digitalnumber tilenum digx digy tempb shade pal orientation ZERO ZERO xdim ydim
   }
       
       
// Display the nuke icon next to the word "nuke"

ifvarl nukepart 5
setvar tilenum SPINNINGNUKEICON
 else setvar tilenum RESPAWNMARKERGREEN
setvar orientation 16
setvar digx 292
setvar digy 4
setvar digz 24576
setvar angvar 0
rotatesprite digx digy digz angvar tilenum shade orientation pal ZERO ZERO xdim ydim

// ...and quote 125 "NUKE" next to nukepart, quote 152 "SKILL" next to skill points

setvar pal 0

setvar digx 299
setvar digy 2
setvar temp 125

minitext digx digy temp shade pal
// gametext tilenum digx digy temp shade pal orientation ZERO ZERO xdim ydim

setvar digx 295
setvar digy 18
setvar temp 152

minitext digx digy temp shade pal


// "HEADSHOT!" = quote 142

 getplayervar[THISACTOR].headshot tempb
 getplayer[THISACTOR].player_par tempc
 ifvarg tempc 48 addvar tempb 48
 ifvarvarg tempb tempc
 {

	 setvar digx 142
	 setvar digy 70
	 setvar temp 142
	 setvar pal 2

	 minitext digx digy temp shade pal
 }

// GAME TIP DISPLAY
ifvarn tipdisplay 0
{
	setvar orientation 0
	setvar digx 160
	setvar digy 50
	setvar digz 32768
	setvar shade 5
	setvar pal 0
	rotatesprite digx digy digz 0 MENU_TIPS shade pal orientation ZERO ZERO xdim ydim
	setvar shade 0
	
	// DISPLAY THE TIP
	
	
	ifvare tipdisplay 1 // WELCOME TO DNWMD
	{
		setvar digx 127
		setvar digy 20
		setvar pal 10
		setvar temp 218
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		addvar digy 8
		addvar temp 1
		minitext digx digy temp shade pal
		addvar digy 8
		addvar temp 1
		minitext digx digy temp shade pal
		addvar digy 8
		addvar temp 1
		minitext digx digy temp shade pal
	} else
	
	ifvare tipdisplay 2 // FIRST SKILL COIN IS SPAWNED
	{
		setvar digx 140
		setvar digy 20
		setvar pal 10
		setvar temp 223
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		addvar digy 8
		addvar temp 1
		minitext digx digy temp shade pal
		addvar digy 8
		addvar temp 1
		minitext digx digy temp shade pal
		addvar digy 8
		addvar temp 1
		minitext digx digy temp shade pal
		
		setvar digx 120
		setvar digy 34
		setvar pal 0
		rotatesprite digx digy 8192 1024 MENU_ARROW shade pal orientation ZERO ZERO xdim ydim
	} else
	
	ifvare tipdisplay 4 // Nuke Coins
	{
		setvar digx 140
		setvar digy 20
		setvar pal 10
		setvar temp 228
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		setvar tempb 0
	 	whilevarn tempb 4
	 	{
		 	addvar tempb 1
		 	addvar digy 8
		 	addvar temp 1
		 	minitext digx digy temp shade pal
	 	}
	} else
	
	ifvare tipdisplay 8 // HoloDuke Bot
	{
		setvar digx 133
		setvar digy 20
		setvar pal 10
		setvar temp 234
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		addvar digy 8
		addvar temp 1
		minitext digx digy temp shade pal
		addvar digy 8
		addvar temp 1
		minitext digx digy temp shade pal
	} else
	
	ifvare tipdisplay 16 // AMMO COINS
	{
		setvar digx 140
		setvar digy 20
		setvar pal 10
		setvar temp 238
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		setvar tempb 0
	 	whilevarn tempb 4
	 	{
		 	addvar tempb 1
		 	addvar digy 8
		 	addvar temp 1
		 	minitext digx digy temp shade pal
	 	}
	} else
	
	
	ifvare tipdisplay 32 // INVENTORY COIN
	{
		setvar digx 125
		setvar digy 20
		setvar pal 10
		setvar temp 244
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		addvar digy 8
		addvar temp 1
		minitext digx digy temp shade pal
	} else
	
	ifvare tipdisplay 64 // STEROIDS
	{
		setvar digx 143
		setvar digy 20
		setvar pal 10
		setvar temp 247
		minitext digx digy temp shade pal
	 	setvar pal 4
	 	setvar digx 100
	 	addvar digy 12
	 	addvar temp 1
	 	minitext digx digy temp shade pal
	
	 	setvar tempb 0
	 	whilevarn tempb 4
	 	{
		 	addvar tempb 1
		 	addvar digy 8
		 	addvar temp 1
		 	minitext digx digy temp shade pal
	 	}
	} else
	
	ifvare tipdisplay 128 // GOGGLES
	{
		setvar digx 110
		setvar digy 20
		setvar pal 10
		setvar temp 253
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		addvar digy 8
		addvar temp 1
		minitext digx digy temp shade pal
	} else
	
	ifvare tipdisplay 256 // DOUBLE JUMP
	{
		setvar digx 135
		setvar digy 20
		setvar pal 10
		setvar temp 256
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		setvar tempb 0
	 	whilevarn tempb 3
	 	{
		 	addvar tempb 1
		 	addvar digy 8
		 	addvar temp 1
		 	minitext digx digy temp shade pal
	 	}
	} else
	
	ifvare tipdisplay 512 // WEAPON LEVELS
	{
		setvar digx 135
		setvar digy 20
		setvar pal 10
		setvar temp 261
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		setvar tempb 0
	 	whilevarn tempb 4
	 	{
		 	addvar tempb 1
		 	addvar digy 8
		 	addvar temp 1
		 	minitext digx digy temp shade pal
	 	}
	} else
	
	ifvare tipdisplay 1024 // HEAD SHOTS
	{
		setvar digx 140
		setvar digy 20
		setvar pal 10
		setvar temp 272
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		setvar tempb 0
	 	whilevarn tempb 3
	 	{
		 	addvar tempb 1
		 	addvar digy 8
		 	addvar temp 1
		 	minitext digx digy temp shade pal
	 	}
	}
	
	ifvare tipdisplay 2048 // TREASURE CHESTS
	{
		setvar digx 130
		setvar digy 20
		setvar pal 10
		setvar temp 277
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		setvar tempb 0
	 	whilevarn tempb 4
	 	{
		 	addvar tempb 1
		 	addvar digy 8
		 	addvar temp 1
		 	minitext digx digy temp shade pal
	 	}
	}
	
	ifvare tipdisplay 4096 // WEIGHT LIMIT
	{
		setvar digx 133
		setvar digy 20
		setvar pal 10
		setvar temp 283
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		setvar tempb 0
	 	whilevarn tempb 4
	 	{
		 	addvar tempb 1
		 	addvar digy 8
		 	addvar temp 1
		 	minitext digx digy temp shade pal
	 	}
	}
	
	ifvare tipdisplay 8192 // BULLET IMMUNITY
	{
		setvar digx 133
		setvar digy 20
		setvar pal 10
		setvar temp 290
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		setvar tempb 0
	 	whilevarn tempb 2
	 	{
		 	addvar tempb 1
		 	addvar digy 8
		 	addvar temp 1
		 	minitext digx digy temp shade pal
	 	}
	}
	
	ifvare tipdisplay 16384 // EXPLOSIVE IMMUNITY
	{
		setvar digx 125
		setvar digy 20
		setvar pal 10
		setvar temp 294
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		setvar tempb 0
	 	whilevarn tempb 2
	 	{
		 	addvar tempb 1
		 	addvar digy 8
		 	addvar temp 1
		 	minitext digx digy temp shade pal
	 	}
	}
	
	ifvare tipdisplay 32768 // KICK IMMUNITY
	{
		setvar digx 135
		setvar digy 20
		setvar pal 10
		setvar temp 298
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		setvar tempb 0
	 	whilevarn tempb 2
	 	{
		 	addvar tempb 1
		 	addvar digy 8
		 	addvar temp 1
		 	minitext digx digy temp shade pal
	 	}
	}
	
	ifvare tipdisplay 65536 // ELEMENTAL IMMUNITY
	{
		setvar digx 125
		setvar digy 20
		setvar pal 10
		setvar temp 302
		minitext digx digy temp shade pal
		setvar pal 4
		setvar digx 100
		addvar digy 12
		addvar temp 1
		minitext digx digy temp shade pal
		setvar tempb 0
	 	whilevarn tempb 2
	 	{
		 	addvar tempb 1
		 	addvar digy 8
		 	addvar temp 1
		 	minitext digx digy temp shade pal
	 	}
	}
	
	// PRESS JUMP TO CONTINUE
	setvar digx 110
	setvar digy 83
	state shadepulse
	setvar temp 217
	setvar pal 10
	ifvare tipdisplay 1 { subvar digx 3 setvar temp 289 }
	minitext digx digy temp shade pal
}
 
 ifvarg menutoggle 0 ifvarl menutoggle 4
 {
	 setvarvar temp holoframe
	 addvar temp 52
	 setvar orientation 1
	 setvar digz 32768
	 rotatesprite mcoordx mcoordy digz cursorang temp shade 0 0 ZERO ZERO xdim ydim
 }

ifvarg messagetime 0 ifvare tipdisplay 0
{
	setvar orientation 16
    setvar shade 0
 
    ifvare message 215 setvar digx 160 else setvar digx 200
    setvar digy 50
    setvar tilenum 2908
    setvar pal 0
    gametext tilenum digx digy message shade pal orientation ZERO ZERO xdim ydim
}


endevent

onevent EVENT_TURNAROUND
// drop weapon

setvar RETURN -1
getplayer[THISACTOR].curr_weapon temp
ifvare temp 0 break
ifvare temp 10 break


switch temp
case 1 setvar tilenum FIRSTGUNSPRITE break
case 2 setvar tilenum SHOTGUNSPRITE break
case 3 setvar tilenum CHAINGUNSPRITE break
case 4 setvar tilenum RPGSPRITE break
case 5 setvar tilenum HBOMBAMMO break
case 6 
case 11
  setvar tilenum SHRINKERSPRITE break
case 7 setvar tilenum DEVISTATORSPRITE break
case 8 setvar tilenum TRIPBOMBSPRITE break
case 9 setvar tilenum FREEZESPRITE break
endswitch

setplayer[THISACTOR].gotweapon temp 0
ifvare temp 6 setplayer[THISACTOR].gotweapon 11 0
ifvare temp 11 setplayer[THISACTOR].gotweapon 6 0

espawnvar tilenum
setactorvar[RETURN].holoweap 1 // holoweap is being used as a flag to tell the weapon it was thrown
getplayer[THISACTOR].curr_weapon temp // temp was reset in EGS when the weapon spawned
getplayer[THISACTOR].ammo_amount temp tempb
ifvare tempb 0 setvar tempb -1
setactorvar[RETURN].hweapcount tempb // hweapcount is used to store the player's ammo
setplayer[THISACTOR].curr_weapon 0
setvar holoweap 0
setplayer[THISACTOR].ammo_amount temp 0
ifvarn barrierup -1 
{
	setactor[barrierup].cstat 2
	setactorvar[barrierup].countvar -4
}
setvar RETURN -1
endevent


onevent EVENT_MOVEFORWARD

setplayer[THISACTOR].runspeed running

addvar fpresstime 1

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

setvarvar fpresstime timer

endevent


onevent EVENT_MOVEBACKWARD

setvarvar temp running
mulvar temp 9
divvar temp 10
setplayer[THISACTOR].runspeed temp

addvar bpresstime 1

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


setvarvar bpresstime timer

endevent


state randtraj // randomize the trajectory of a projectile

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

onevent EVENT_STRAFELEFT

setvarvar temp running
mulvar temp 9
divvar temp 10
setplayer[THISACTOR].runspeed temp

addvar lpresstime 1

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

setvarvar lpresstime timer

endevent

onevent EVENT_STRAFERIGHT

setvarvar temp running
mulvar temp 9
divvar temp 10
setplayer[THISACTOR].runspeed temp

addvar rpresstime 1

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

setvarvar rpresstime timer

endevent

onevent EVENT_GETSHOTRANGE


ifvarn barrierup -1
   setactor[barrierup].cstat 2


getplayer[THISACTOR].curr_weapon temp

switch temp

case 1:
		getplayer[THISACTOR].horiz tempb
		ifvare hammo5 -1 setvarvar hammo2 tempb
		else
		ifvarvarl tempb hammo2 setvarvar hammo2 tempb // change goal horiz only if new one is lower
		addvar hammo3 6 // hammo3 stores the amount of kick (the amount to move the horiz up)
		addvar hammo4 6 // hammo4 stores the amount to move horiz back down (they move at diff rates)
		setvar hammo5 1 // this flag tells the player that the recoil state should be executed
		
		ifvarg special 0
		 {
			 subvar special SPECIAL1_AMOUNT
			 setvar ANGRANGE 2
			 setvar ZRANGE 2
		 }
		break



case 2: 
		getplayer[THISACTOR].horiz tempb
		ifvare hammo5 -1 setvarvar hammo2 tempb // hammo2 is the "goal" horizon, to be returned to later
		else
		ifvarvarl tempb hammo2 setvarvar hammo2 tempb // change goal horiz only if new one is lower
		addvar hammo3 2 // 2 for EACH shotgun pellet
		addvar hammo4 2
		setvar hammo5 1
		break


case 3: 
		getplayer[THISACTOR].horiz tempb
		ifvare hammo5 -1 setvarvar hammo2 tempb
		else
		ifvarvarl tempb hammo2 setvarvar hammo2 tempb
		addvar hammo3 3
		addvar hammo4 3
		setvar hammo5 1
		ifvarg special 0 subvar special SPECIAL3_AMOUNT
		ifvarg special 0 ifp ponsteroids subvar special SPECIAL3_AMOUNT
		ifvarl special 1 state normalchaingun
		break

	
case 7:
		ifvarg special 0
		{
		  addvar hammo8 1
		  ifvarvare hammo8 WEAPON7_SHOTSPERBURST
		  {
		     subvar special SPECIAL7_AMOUNT
		     setvar hammo8 0
		  }
		}
		break

case 9: 
		setvar ANGRANGE 1
		setvar ZRANGE 1
		
		getplayer[THISACTOR].horiz tempb
		ifvare hammo5 -1 setvarvar hammo2 tempb
		else
		ifvarvarl tempb hammo2 setvarvar hammo2 tempb
		addvar hammo3 8
		addvar hammo4 8
		setvar hammo5 1
		break
 


endswitch

endevent


state checkhitscan


ifvarn barrierup -1
{
	getactor[barrierup].xrepeat mx
	getactor[barrierup].yrepeat my
	setactor[barrierup].xrepeat 1
	setactor[barrierup].yrepeat 1
}

getplayer[THISACTOR].posx x
getplayer[THISACTOR].posy y
getplayer[THISACTOR].posz z
getplayer[THISACTOR].cursectnum mysector
getplayer[THISACTOR].ang angvar
getplayer[THISACTOR].horiz zdist
subvar zdist 100
getplayer[THISACTOR].horizoff temp
subvarvar zdist temp
mulvar zdist -2048
cos mycos angvar
sin mysin angvar

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


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

// setvarvar debugvar hitx
// setvarvar debugvarb hity
// setvarvar debugvarc hitz

ifvarn barrierup -1
{
	setactor[barrierup].xrepeat mx
	setactor[barrierup].yrepeat my
}

ends


//	TerminX method
// state checkhitscan

// ifvarn barrierup -1
// {
// 	getactor[barrierup].xrepeat mx
// 	getactor[barrierup].yrepeat my
// 	setactor[barrierup].xrepeat 1
// 	setactor[barrierup].yrepeat 1
// }

// getplayer[THISACTOR].posx x
// getplayer[THISACTOR].posy y
// getplayer[THISACTOR].posz z
// getplayer[THISACTOR].cursectnum mysector
// getplayer[THISACTOR].ang angvar

// cos mycos angvar
// sin mysin angvar

// getplayer[THISACTOR].pyoff temp
// addvarvar z temp
// addvar z -9674

// setvar tempb 101
// getplayer[THISACTOR].horiz temp
// subvarvar tempb temp
// getplayer[THISACTOR].horizoff temp
// subvarvar tempb temp

// shiftvarl tempb 11

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

// ifvarn barrierup -1
// {
// 	setactor[barrierup].xrepeat mx
// 	setactor[barrierup].yrepeat my
// }

// ends


state projectilehitscan

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

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

getactor[THISACTOR].z z
subvar z 6144
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].sectnum mysector
setvar zdist 0
cos mycos angvar
sin mysin angvar
ifvarn barrierup -1
{
	getactor[barrierup].xrepeat tempb
	setactor[barrierup].xrepeat 1
}
hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask
ifvarn barrierup -1
	  setactor[barrierup].xrepeat tempb
// temp will be set to 1 if the answer is yes, 0 otherwise
setvar temp 0
ifvarn hitsprite -1
 {
	 getactor[hitsprite].extra tempb
	 ifvarn tempb 0 
		   break
	   
 }
espawn NOTHING
setactor[RETURN].x hitx
setactor[RETURN].y hity
setactor[RETURN].z hitz
ldist xydist THISACTOR RETURN
ifvarg xydist 512 break

setvar temp 1

ends

state actorhitscan


// the sprite ID of the scanning actor has been put in spriteid before this state is called
getactor[spriteid].x x
getactor[spriteid].y y
getactor[spriteid].z z
getactor[spriteid].sectnum mysector
getactor[spriteid].ang angvar
// getactor[spriteid].zvel zdist
// zdist needs some calculation
setvar zdist 0

cos mycos angvar
sin mysin angvar

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

ends

state aimattarget

        getactor[target].x mx
        getactor[target].y my
        getactor[THISACTOR].x x
        getactor[THISACTOR].y y
        subvarvar mx x
        subvarvar my y
        getangle angvar mx my
        setactor[THISACTOR].ang angvar

ends

state checksight

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

ends

state generate_location

getplayer[THISACTOR].posx mx
getplayer[THISACTOR].posy my
getactor[THISACTOR].z mz
setvarvar xydist mx
randvar temp 5120 // the random component of the distance behind player
addvar temp 2048
addvarvar xydist temp
getplayer[THISACTOR].ang angvar
addvar angvar 512
randvar temp 1024 // the random component of the angle behind player
addvarvar angvar temp

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

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

ends

state teleport_behind

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

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

state spawninvis // chance to spawn invisible monsters!
ifactor SPIDERX break
ifactor INVISEGG break
ifactor NEWBEAST ifvare mtype 3 break

randvar temp 64
ifvarvarl temp mval
{
	ifvarl score 750 spawn INVISEGG else
	{
		ifrnd 232 spawn INVISEGG
		else spawn TREASURE_CHEST
 	}
}
else ifrnd 32 
{
	ifvarl score 1000 spawn INVISEGG else
	{
		ifrnd 232 spawn INVISEGG
		else spawn TREASURE_CHEST
	}
}

ends

state monstersubstitution

ifspawnedby TANK break 
else ifspawnedby RECON break
ifvarn mtype 0 break

   randvar temp 40000
   setvarvar tempb score
   addvar tempb 1000
   //ifvarg tempb 20000 setvar tempb 20000
   setvar tempc 0
   getuserdef[THISACTOR].player_skill tempd
   //ifvare tempd 4 setvar tempc 1 else
   
   ifai 0 ifvarvarg tempb temp setvar tempc 1
    ifvare tempc 1
  	{
		randvar temp 100
		// roll first, then create sub-categories based on score
		ifvarl temp 12
		{
			ifvarl score 1000 break
			spawn EVILDUKE
		}
		else ifvarl temp 25
		{
			ifvarl score 1500 break
			spawn ROBOMAN
		}
		else ifvarl temp 36
		{
			ifvarl score 400 break
			spawn MINIBOSS2

		}
		else ifvarl temp 49
		{
			ifvarl score 400 break
			spawn MINIBOSS3
		}
		else ifvarl temp 58
		{
			ifvarl score 500 break else
			ifvarl score 2000 spawn NEWBEAST
			else spawn SUPERBRAIN
		}
		else ifvarl temp 69
		{
			ifvarl score 2500
			{
				spawn DRONE
				spawn DRONE
			}
			else spawn DRONEDEV
		}
		else ifvarl temp 79
		{
			ifvarl score 500 break else
			ifvarl score 3000 spawn NEWBEAST
			else spawn SUPERBEAST
		}
		else ifvarl temp 89
		{
			ifvarl score 1500 break
			else spawn MINIBOSS1
		}
		else
		{
			ifvarl score 2000 break
			ifvarl score 4500 spawn ROBOMAN
			else ifvarl score 7000 spawn MECH1
			else
			{
				ifrnd 128 spawn MECH1
				else spawn MECH2
			}
		}
		
        sound TELEPORTER
        espawn TRANSPORTERSTAR
        getactor[THISACTOR].z z
        subvar z 8192
        setactor[RETURN].z z
        setactor[RETURN].xrepeat 96
        setactor[RETURN].yrepeat 96
        setactor[RETURN].pal 2
		getplayer[THISACTOR].max_actors_killed temp
		subvar temp 1
		setplayer[THISACTOR].max_actors_killed temp
		state clearlists
		killit  
	} // randomly replaces some monsters


ends

state boss1substitution

ifvarg score 5000 ifrnd 64 nullop else break

spawn MECH2
sound TELEPORTER
espawn TRANSPORTERSTAR
getactor[THISACTOR].z z
subvar z 8192
setactor[RETURN].z z
setactor[RETURN].xrepeat 96
setactor[RETURN].yrepeat 96
setactor[RETURN].pal 2
getplayer[THISACTOR].max_actors_killed temp
subvar temp 1
setplayer[THISACTOR].max_actors_killed temp
state clearlists
killit  

ends

state clone

break // this state is disabled pending fixes

ifvarg mtype 0 ifvarl mtype 4 break
setvarvar temp mval
mulvar temp 100

ifvarvarg score temp ifvare mtype 0 // score must be greater than mval * 100 for cloning to take place
{
	randvar temp 40000
	setvarvar tempb score
	ifvarg tempb 5000 setvar tempb 5000 // max of 1 in 8 chance of cloning
	ifvarvarg tempb temp
	{
		addvar mtype 4
		getactor[THISACTOR].picnum tilenum
		espawnvar tilenum // make first clone
		setactorvar[RETURN].mtype mtype
	}

}
 
ifvarg mtype 3 // monsters with mtype > 3 are clones, types 1 - 3 are specials
{
	ifvarg mtype 10 { setvar mtype 1 break }
	setvarvar tempb score
	setvarvar tempc mval
	mulvar tempc 48
	ifvarl tempc 900 setvar tempc 900     
	divvarvar tempb tempc
	ifvarvarl mtype tempb
	{ 
		getactor[THISACTOR].picnum tilenum
		espawnvar tilenum
		addvar mtype 1
		setactorvar[RETURN].mtype mtype
	}
}


ends

state calczdist

getactor[THISACTOR].z z
ifactor BOSS2 subvar z 16384

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

ends

state shootnova_at_player
		 
getplayer[THISACTOR].i target
state calczdist
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1
mulvar zdist 768
divvarvar zdist xydist // zdist now holds the desired z velocity 
ezshoot zdist NOVA
ifactor BOSS2 setactorvar[RETURN].mtype 2 else setactorvar[RETURN].mtype 1 // the weaker version
sound NOVA_FIRE
ends

state devastator_at_player

ifvarn currholo -1 ifvarvare currholo target nullop else
getplayer[THISACTOR].i target
state calczdist
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1
mulvar zdist 644 // multiplies zdist by the speed of the projectile
divvarvar zdist xydist // zdist now holds the desired z velocity
sound RPG_SHOOT
zshoot zdist CPUDEV
zshoot zdist CPUDEV
ends


state randshoot
randvar angvar 2047
setactor[THISACTOR].ang angvar
randvar zdist 3072
mulvar zdist -1
ends

state dropcoins // drops coins and adds to player's score based on the monsters value (mval)

setvarvar tempc mtype
ifvarg tempc 3 mulvar tempc 25 // mtypes >3 are for clones which don't drop as much stuff
setvar tempb 160
addvarvar tempb tempc
randvarvar temp tempb
ifvarvarl temp mval
spawn NUKECOIN

setvar tempb 128
addvarvar tempb tempc
randvarvar temp tempb
ifvarvarl temp mval 
{
	setvar tempb 0
	ifvarl mval 15 setvar tempb 1
	else
	{
		setvarvar tempd mval
		ifvarg loop 1 divvarvar tempd loop
		ifvarvarl temp tempd setvar tempb 1
	}
	ifvare tempb 1
	{
		spawn SKILLCOIN
		
	}
}

setvar tempb 96
addvarvar tempb tempc
randvarvar temp tempb
ifvarvarl temp mval
spawn INVENCOIN

setvar tempb 352
addvarvar tempb tempc
randvarvar temp tempb
ifvarvarl temp mval
spawn AMMOCOIN

addvar loop 1
ifvarl loop 4 state dropcoins // go through the loop 4 times total

ends

state addscore // must be called immediately after dropcoins

setvar monstatus 2 // means monster is now considered dead
ifvare mval BOSSVAL ifvare lotag 0 
{
	espawn BOSSCOIN
	setactorvar[RETURN].myspawner THISACTOR
}
state spawninvis

ifvare mval -1 quote 153

addvarvar score mval

ifwasweapon KNEE 
{
	ifvarg kickxp 40 setvar mval 0 else
	ifvarg kickxp 30 divvar mval 4 else
	ifvarg kickxp 15 divvar mval 2
	
	addvarvar weap0xp mval
	setvar temp 0
	switch weap0lev // is it time for the kick to level up?

	case 60 ifvarg weap0xp L0XP setvar temp 1 break
	case 80 ifvarg weap0xp L1XP setvar temp 1 break
	case 100 ifvarg weap0xp L2XP setvar temp 1 break
	case 120 ifvarg weap0xp L3XP setvar temp 1 break
	case 140 ifvarg weap0xp L4XP setvar temp 1 break
	case 160 ifvarg weap0xp L5XP setvar temp 1 break
	case 180 ifvarg weap0xp L6XP setvar temp 1 break
	case 200 ifvarg weap0xp L7XP setvar temp 1 break
	case 220 ifvarg weap0xp L8XP setvar temp 1 break
	case 240 ifvarg weap0xp L9XP setvar temp 1 break
	case 260 break // top level
	endswitch
	ifvare temp 1
	{
		globalsound SHIELD_UPGRADE
		palfrom 40 63 63 63
		addvar weap0lev 20
		setvar messagetime 52
	    setvar message 216
	}
} 
else
{
	ifvarl pdamage 100 nullop else
	//ifvarg xpmult 29 setvar mval 0 else
	//ifvarg xpmult 24 divvar mval 4 else
	ifvarg xpmult 13 divvar mval 2
	
	getplayer[THISACTOR].curr_weapon temp
	switch temp
	case 1 addvarvar weap1xp mval break
	case 2 addvarvar weap2xp mval break
	case 3 addvarvar weap3xp mval break
	case 4 addvarvar weap4xp mval break
	case 5 case 10 addvarvar weap5xp mval break
	case 6 case 11 addvarvar weap6xp mval break
	case 7 addvarvar weap7xp mval break
	case 8 addvarvar weap8xp mval break
	case 9 addvarvar weap9xp mval break
	endswitch
}

setvar mval -1 // safeguard against dead monsters using dropcoins again and dropping more coins

ends

state checkdart

ifwasweapon LIGHTNINGBOLT
{
	ifvarand immunity 8 nullop else
	{
		ifrnd 8 spawn STICKYFIRE
		ifvarn M1 -1 { espawn LSHOOTER setactorvar[RETURN].target M1 setvar M1 -1 }
		ifvarn M2 -1 { espawn LSHOOTER setactorvar[RETURN].target M2 setvar M2 -1 }
		ifvarn M3 -1 { espawn LSHOOTER setactorvar[RETURN].target M3 setvar M3 -1 }
		ifrnd 64 setactor[THISACTOR].htpicnum RPG else setactor[THISACTOR].htpicnum SHOTSPARK1   
	}
}


	ifvarg darthit 0 ifvarn darthit 260
	{
		sound PIPEBOMB_EXPLODE
		switch pdamage
		case 40
		case 60 hitradius 3584 20 30 40 50 break
		case 80 hitradius 3584 30 45 60 75 break
		case 100 hitradius 3584 50 70 90 110 break
		case 120 hitradius 3584 70 95 120 145 break
		case 140 hitradius 3584 90 115 140 170 break
		case 160 hitradius 3584 110 140 170 200 break
		case 180 hitradius 3584 130 170 210 250 break
		case 200 hitradius 3584 150 200 250 300 break
		case 220 hitradius 3584 180 230 300 350 break
		case 240 hitradius 3584 210 260 350 400 break
		case 260 hitradius 3584 250 300 400 450 break
		endswitch
		
		getactor[THISACTOR].htextra temp
		addvarvar temp pdamage
		setactor[THISACTOR].htextra temp
		setactor[THISACTOR].htpicnum RADIUSEXPLOSION
		spawn BIGEXPLOSION
		palfrom 33 63 63 63
		quote 151
		ifrnd 128 spawn BURNING else spawn BURNING2
		setactor[THISACTOR].shade 0 // because it has been pulsing
		setvar darthit 0
	}
			
ends

// state gradualturn
// // assumes target is set

// 	    getactor[target].x mx
//         getactor[target].y my
//         getactor[THISACTOR].x x
//         getactor[THISACTOR].y y
//         subvarvar mx x
//      	subvarvar my y
//         getangle angvar mx my
// 		setvarvar zdist angvar // saves the correct angle in zdist
// 		getactor[THISACTOR].ang tempb
// 		subvarvar angvar tempb // diff between angle to target and actual angle

// 		ifvarg angvar 1024 subvar angvar 2048
// 		else
// 		ifvarl angvar -1024 addvar angvar 2048
// 		// angvar is now how many degrees THISACTOR needs to turn
// 		// + for clockwise, - for counterclockwise
// 		setvarvar temp angvar
// 		ifvarl temp 0 mulvar temp -1
// 		ifvarl temp 33 setactor[THISACTOR].ang zdist
// 		else
// 		{
// 		   ifvarg angvar 0 addvar tempb 32
// 		   else ifvarl angvar 0 subvar tempb 32
// 		   setactor[THISACTOR].ang tempb
// 		}
// ends

state gradualturn
// assumes target is set

getactor[target].x mx
getactor[target].y my
getactor[THISACTOR].x x
getactor[THISACTOR].y y
subvarvar mx x
subvarvar my y
getangle angvar mx my
getactor[THISACTOR].ang tempb
getincangle tempd angvar tempb

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

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

setactor[THISACTOR].ang tempb

ends

state recontilt

 // tilt code thanks to Hunter_Rus for initial version
  getactor[THISACTOR].ang angvar
  getincangle temp angvar hammo2
  
  setvarvar hammo2 angvar
  shiftvarl temp 20
  divvar temp 18768
  ifvarg temp  256 setvar temp  256 else
  ifvarl temp -256 setvar temp -256 
  // added this code to make it smoother 
  getactor[THISACTOR].roll hammo3
  ifvarvarg temp hammo3 
  {
	  addvar hammo5 1 // counter
	  ifvarg hammo5 1
	  {
	  	addvar hammo3 24
	  	ifvarvarg hammo3 temp setvarvar hammo3 temp
  	  }
  }
  else ifvarvarl temp hammo3
  {
	  subvar hammo5 1
	  ifvarl hammo5 -1
	  {
	  	subvar hammo3 24
	  	ifvarvarl hammo3 temp setvarvar hammo3 temp
  	  }
  }
  setactor[THISACTOR].roll hammo3
  ifvarg hammo5 2 setvar hammo5 2
  ifvarl hammo5 -2 setvar hammo5 -2
  
ends


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

state changetodecal

setvar tilenum BULLETHOLE
getactor[myspawner].htg_t 6 hitwall
getwall[hitwall].picnum FLOORTEX
state CHECKSTEPS

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

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

onevent EVENT_EGS

getactor[THISACTOR].statnum temp
ifvare temp 4
{
	 getactor[THISACTOR].xvel initx
	 getactor[THISACTOR].zvel initz
	 
	 getactor[THISACTOR].owner tempb
	 getactorvar[tempb].barrierup barrierup
	 ifvarn barrierup -1 
	 {
	   	setactor[barrierup].cstat 2
	   	setactorvar[barrierup].countvar -2 //0
	   	//ifactor HLROCKET setactorvar[barrierup].countvar -2
	   	ifactor FIRELASER2 setactorvar[barrierup].countvar -4
	 }
	 
}

getactor[THISACTOR].picnum temp

switch temp

	case BULLETHOLE

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

	break

	case INVISEGG
	case SKILLCOIN
	case SPIDERX
	setactor[THISACTOR].cstat 32768
	ifactor SPIDERX addvar spiders 1
	break

	case JIBS3
	case JIBS4
	case JIBS5
	case JIBS6
	ifspawnedby SPIDERX
	getactor[THISACTOR].owner myspawner
	ifvarn myspawner -1
	{
		getactor[myspawner].pal tempb
		setactor[THISACTOR].pal tempb
	}
	break
	
	case MININUKE
	randvar countvar 5
	break
	
	case BLASTRAIL
	ifspawnedby BLASTRAIL nullop else
	{
		getactor[THISACTOR].owner myspawner
		ifvarn myspawner -1
		{
			getactor[myspawner].xvel xvel
			getactor[myspawner].zvel zvel
			addlogvar xvel
			addlogvar zvel
			shiftvarr xvel 1
			shiftvarr zvel 1
			mulvar zvel -1
			getactor[myspawner].ang angvar
			addvar angvar 1024
			getactor[THISACTOR].x x
			getactor[THISACTOR].y y
			getactor[THISACTOR].z z
			addvarvar z zvel
			setvarvar mx x
			addvarvar mx xvel
			rotatepoint x y mx y angvar digx digy
			espawn BLASTRAIL
			setactor[RETURN].x digx
			setactor[RETURN].y digy
			setactor[RETURN].z z
			getactor[THISACTOR].htpicnum temp
			setactor[RETURN].htpicnum temp
		}
	}
	break
	
	case WALLDART
	case RINGTHING
	getactor[THISACTOR].owner myspawner
	ifvarn myspawner -1
	{
		getactor[myspawner].pitch angvar
		setactor[THISACTOR].pitch angvar
	}
	break
	
	case SPIT
	ifspawnedby NEWBEAST
	{
		getactor[THISACTOR].xvel xvel
		mulvar xvel 2
		setactor[THISACTOR].xvel xvel
		state randtraj
		getactor[THISACTOR].zvel zvel
		subvar zvel 1024
		setactor[THISACTOR].zvel zvel
		setactor[THISACTOR].pal 6
	}

	case HEALBOLT
	ifspawnedby MINIBOSS4 { state randtraj state randtraj }
	break
	
	case SEEKER
	getactor[THISACTOR].z z
	subvar z 8192
	ifspawnedby BOSS2 subvar z 8192
	ifspawnedby BOSS3 subvar z 8192
	setactor[THISACTOR].z z
	break
	
	case NOVABLAST
	getactor[THISACTOR].owner myspawner
	getactorvar[myspawner].mtype mtype
	break
	
	case POKEBALLG
	getactor[THISACTOR].owner myspawner
	getactorvar[myspawner].hitag hitag
	break

	case FLESH1
	case FLESH2
	case FLESH3
	case BRAIN 
	case SPINE
	case LIZHEAD
	case LIZARM
	case LIZLEG
	case PIGHEAD
	case PIGUPPER
	case PIGUPPER2
	case PIGLOWER
	case PIGLOWER2
	case TROOPHEAD
	case TROOPARM
	case TROOPLEG
	ifvarl temp 3880
	{
	    getactor[THISACTOR].mdzoff temp
		subvar temp 512
		setactor[THISACTOR].mdzoff temp
		getactor[THISACTOR].mdyoff temp
		addvar temp 16
		setactor[THISACTOR].mdyoff temp
    }
	ifspritepal 22 nullop else
	{
		getactor[THISACTOR].owner spriteid
		ifvarn spriteid -1
		{
			getactor[spriteid].pal pal
			setthisprojectile[THISACTOR].pal pal
			setactor[THISACTOR].pal pal
		}
	}
	
	randvar hammo2 96
	randvar hammo3 42
	randvar hammo4 48
	randvar countvarb 13
	addvar countvarb 13
	ifrnd 128 mulvar hammo2 -1
	ifrnd 128 mulvar hammo3 -1
	ifrnd 128 mulvar hammo4 -1
	setvar mtype -66
	// add code for burning jibs:  check htpicnum of owner, if explosive, setvar then transfer to ground jib
	break
	
	case NEWSCRAP1
	case NEWSCRAP2
	case NEWSCRAP3
	case NEWSCRAP4
	case NEWSCRAP5
	case NEWSCRAP6
	case SHOTSPARK1
	setvar mtype -66
	break
	
	case BLOODPOOL
	cactor NEWBLOOD1
	//setvar tempb 2
	//ifrnd 128 addvar tempb 4
	//ifrnd 128 addvar tempb 8
	//setactor[THISACTOR].cstat tempb
	//randvar monstx 42
	//addvar monstx 18
	//setactor[THISACTOR].xrepeat monstx
	//randvar monsty 42
	//addvar monsty 18
	//setactor[THISACTOR].yrepeat monsty
	break
	
	case HLROCKET
	
	ifspawnedby APLAYER
	{
	  	ifvarg special 0 subvar special SPECIAL4_AMOUNT
	  	getplayer[THISACTOR].i myspawner
  	} else
	getactor[THISACTOR].owner myspawner
	
		 
	break
	
	case FIREBULLET
	ifspawnedby BOSS3 state randtraj
	break
	
	case CHILLBLAST2
	case FIRELASER3
	state randtraj
	ifspawnedby APLAYER
	{
      ifvarg special 0 
	      subvar special SPECIAL9_AMOUNT
	  else state normalfreezer
    }
	      
    break
    
	case NOVA
	ifp pducking nullop else ifspawnedby APLAYER 
	{		
		getactor[THISACTOR].z z
		addvar z 4096 // so it doesn't come out too high
		setactor[THISACTOR].z z
	}
	break
	
	case MAGMA
	state randtraj
	getactor[THISACTOR].xrepeat tempb
	mulvar tempb -170
	setactor[THISACTOR].mdzoff tempb
	break

	case BFG
	getactor[THISACTOR].xrepeat tempb
	mulvar tempb -170
	setactor[THISACTOR].mdzoff tempb
	ifspawnedby APLAYER
		 subvar special SPECIAL6_AMOUNT
	break
	
	case BLASTER
	case BLASTER2
	getactor[THISACTOR].z z
	addvar z 1536
	ifspawnedby APLAYER addvar z 1536
	setactor[THISACTOR].z z
	break

	case BLASTER3
	getactor[THISACTOR].z z
	addvar z 1536
	setactor[THISACTOR].z z
	state randtraj
	getactor[THISACTOR].owner hammo2
	break
	
	case BLASTER4
	getactor[THISACTOR].owner myspawner
	getactorvar[myspawner].countvarb countvarb // 0 for left side, 1 for right side
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].z z
	getactor[myspawner].picnum tilenum
	setvarvar xydist x
	getactor[THISACTOR].ang angvar
	ifvare tilenum DRONEDEV 
	{
		addvar xydist 1536 //1024
		ifvare countvarb 0 subvar angvar 64 else addvar angvar 64
	  	addvar z 8192
  	}
	else ifvare tilenum MECH2 
	{
		addvar xydist 768
		ifvare countvarb 0 subvar angvar 32 else addvar angvar 96
		subvar z 3840
	}
	setactor[THISACTOR].z z
	rotatepoint x y xydist y angvar mx my
	setactor[THISACTOR].x mx
	setactor[THISACTOR].y my
	break
	
	case FIRELASER
	ifspawnedby BOSS3
	{
		getactor[THISACTOR].z z
		subvar z 2048
		setactor[THISACTOR].z z
		state randtraj
	}

	break

	case FIRELASER2
	ifspawnedby APLAYER
	{
		getactor[THISACTOR].z z
		addvar z 2048
		setactor[THISACTOR].z z
		state randtraj
	}
		
	getactor[THISACTOR].owner spriteid
	getactor[spriteid].picnum tempb
	ifvare tempb MINIBOSS2
	{
		getactor[THISACTOR].z z
		addvar z 2048
		setactor[THISACTOR].z z
	}
	break


	case TRIPBOMB
		getactor[THISACTOR].owner tempb
		ifvare tempb -1 setvar tempc -1 else
		getactor[tempb].picnum tempc
		
		
		ifvare tempc APLAYER
		{
			addvar weap8xp 10
			setvar tempd 0
			ifvare tripon 0 setvar tempd 1
			ifvarg special 0 setvar tempd 1
			ifvare tempd 1
			{
				setactor[THISACTOR].picnum DTRIP
				setactor[THISACTOR].xrepeat 8
				setactor[THISACTOR].yrepeat 8
			}
		}
	break
		

	case CPUDEV

		state randtraj
		getactor[THISACTOR].xvel xvel
		getactor[THISACTOR].zvel zvel
		setvarvar tempb zvel
		//shiftvarl tempb 4
		mulvar tempb 14
		ifvare xvel 0 setvar xvel 1
		divvarvar tempb xvel
		setactor[THISACTOR].pitch tempb
		break

	case FLAMETHROWER
		state randtraj
		break

	case HEAVYHBOMB
		ifspawnedby APLAYER
		 {
		    ifvare pipeon 0
			{
				setvar mval -2
				getplayer[THISACTOR].ammo_amount 5 tempb
				subvar tempb 2
				setplayer[THISACTOR].ammo_amount 5 tempb
				getactor[THISACTOR].xrepeat x
				getactor[THISACTOR].yrepeat y
				mulvar x 2
				mulvar y 2
				setactor[THISACTOR].xrepeat x
				setactor[THISACTOR].yrepeat y
				getactor[THISACTOR].xvel xvel
				mulvar xvel 2
				setactor[THISACTOR].xvel xvel
			}
		  else
		    ifvarg special 0
		    {
			    setvar mval -3 // special ammo pipe
			    subvar special SPECIAL5_AMOUNT
		    }
		}
		break
		
	case RPGNOAIM
	case SLOWBULLET
	case ACIDBULLET
		ifactor SLOWBULLET state randtraj
		ifactor ACIDBULLET state randtraj
		getactor[THISACTOR].xvel xvel
		getactor[THISACTOR].zvel zvel
		setvarvar tempb zvel
		//shiftvarl tempb 4
		mulvar tempb 14
		ifvare xvel 0 setvar xvel 1
		divvarvar tempb xvel
		setactor[THISACTOR].pitch tempb
		break

	case RPG ifspawnedby PIGCOP state randtraj

		// code for setting recoil vars
		    ifspawnedby APLAYER
			{
			
			getactor[THISACTOR].owner mtype
			getactor[mtype].yvel spriteid
			
			getplayer[spriteid].horiz tempb
			getactorvar[mtype].hammo5 hammo5
			getactorvar[mtype].hammo2 hammo2
			getactorvar[mtype].hammo3 hammo3
			getactorvar[mtype].hammo4 hammo4

			ifvare hammo5 -1 setvarvar hammo2 tempb
			else
			ifvarvarl tempb hammo2 setvarvar hammo2 tempb // change goal horiz only if new one is lower
			addvar hammo3 2 // hammo3 stores the amount of kick (the amount to move the horiz up)
			addvar hammo4 2 // hammo4 stores the amount to move horiz back down (they move at diff rates)
			getplayer[spriteid].curr_weapon loop
			ifvare loop 4 { addvar hammo3 6 addvar hammo4 6 } else // DEVASTATOR ROCKET
			setvar immunity 2 // nothing to do with recoil; this prevents rocket from spawning a large scorch
			setvar hammo5 1 // this flag tells the player that the recoil state should be executed
			
			setactorvar[mtype].hammo5 hammo5
			setactorvar[mtype].hammo2 hammo2
			setactorvar[mtype].hammo3 hammo3
			setactorvar[mtype].hammo4 hammo4
			}
			getactor[THISACTOR].xvel xvel
			getactor[THISACTOR].zvel zvel
			setvarvar tempb zvel
			//shiftvarl tempb 4
			mulvar tempb 14
			ifvare xvel 0 setvar xvel 1
			divvarvar tempb xvel
			setactor[THISACTOR].pitch tempb

		break

	
	case FLAK 
	
		state randtraj

		ifspawnedby APLAYER
			
			{
				
				ifp pducking nullop else
				  {
				  getactor[THISACTOR].z z
				  addvar z 2048 // so it doesn't come out of the chaingun too high
				  setactor[THISACTOR].z z
    			  }

				getactor[THISACTOR].owner mtype
				getactor[mtype].yvel spriteid
			
				getplayer[spriteid].horiz tempb
				getactorvar[mtype].hammo5 hammo5
				getactorvar[mtype].hammo2 hammo2
				getactorvar[mtype].hammo3 hammo3
				getactorvar[mtype].hammo4 hammo4

				ifvare hammo5 -1 setvarvar hammo2 tempb
				else
				ifvarvarl tempb hammo2 setvarvar hammo2 tempb // change goal horiz only if new one is lower
				
				ifvare tempc 2 addvar hammo3 2 else // don't kick as much if fired from shotgun
				addvar hammo3 3 // hammo3 stores the amount of kick (the amount to move the horiz up)
				addvar hammo4 3 // hammo4 stores the amount to move horiz back down (they move at diff rates)
				setvar hammo5 1 // this flag tells the player that the recoil state should be executed
			
				setactorvar[mtype].hammo5 hammo5
				setactorvar[mtype].hammo2 hammo2
				setactorvar[mtype].hammo3 hammo3
				setactorvar[mtype].hammo4 hammo4

			}
			

		break
	
	case BOMBDART

			getactor[THISACTOR].z z
			addvar z 1024 // so it doesn't come out of the pistol too high
			setactor[THISACTOR].z z
			
			// get player id of owner
			getactor[THISACTOR].owner mtype
			getactor[mtype].yvel spriteid

			// code for setting recoil vars
			getplayer[spriteid].horiz tempb
			getactorvar[mtype].hammo5 hammo5
			getactorvar[mtype].hammo2 hammo2
			getactorvar[mtype].hammo3 hammo3
			getactorvar[mtype].hammo4 hammo4

			ifvare hammo5 -1 setvarvar hammo2 tempb
			else
			ifvarvarl tempb hammo2 setvarvar hammo2 tempb // change goal horiz only if new one is lower
			addvar hammo3 12 // hammo3 stores the amount of kick (the amount to move the horiz up)
			addvar hammo4 12 // hammo4 stores the amount to move horiz back down (they move at diff rates)
			setvar hammo5 1 // this flag tells the player that the recoil state should be executed
			
			setactorvar[mtype].hammo5 hammo5
			setactorvar[mtype].hammo2 hammo2
			setactorvar[mtype].hammo3 hammo3
			setactorvar[mtype].hammo4 hammo4

			getactor[THISACTOR].xvel xvel
			getactor[THISACTOR].zvel zvel
			setvarvar tempb zvel
			mulvar tempb 14
			ifvare xvel 0 setvar xvel 1
			divvarvar tempb xvel
			setactor[THISACTOR].pitch tempb
	
		break
		
	case BOSS3
	ifspawnedby RESPAWN setvar hitag 1
	break
	
	case MECH2
	ifspawnedby RESPAWN 
	{
		getactor[THISACTOR].owner tempb
		getactorvar[tempb].mtype lotag
	}
	break
	
	case ACCESSSWITCH
	case ACCESSSWITCH2
	spriteflags 4
	setactor[THISACTOR].shade -100
	break

endswitch		


endevent


onevent EVENT_USENIGHTVISION

getplayer[THISACTOR].heat_amount temp

ifvarg temp 10 { sound DIMENSION_SHIFT setvar hweapcount 26 } // hweapcount is length of time transition will take

endevent

state setholotarg  // make target of holobot and various other things

ifactor NEWBEAST ifvare mtype 3 ifvare goggles 0 break

ifvarn currholo -1 ifvarn monstatus 2
{
  	getactorvar[currholo].target temp
  	ifvare temp -1
  	{
		getactor[THISACTOR].z z
		subvar z 8192
		setactor[THISACTOR].z z
		getactor[currholo].z mz
		subvar mz 8192
		setactor[currholo].z mz
		canseespr THISACTOR currholo holocansee
		addvar z 8192
		addvar mz 8192
		setactor[THISACTOR].z z
		setactor[currholo].z mz
		ifvare holocansee 1 setactorvar[currholo].target THISACTOR
		else
	  	ifcansee setactorvar[currholo].target THISACTOR
	}
}

ifvarg gunally 0
{
	findnearactor ROTATEGUNALLY 16384 temp
	ifvarn temp -1
	{
	  canseespr THISACTOR temp tempb
	  ifvare tempb 1
		ifvarn monstatus 2 setactorvar[temp].target THISACTOR
		
	}
}

ifcansee
{
	ifvarvare THISACTOR M1 break
	ifvarvare THISACTOR M2 break // exit if already on target list
	ifvarvare THISACTOR M3 break
	ifvare M1 -1 { setvarvar M1 THISACTOR break }
	else
	ifvare M2 -1 { setvarvar M2 THISACTOR break }
	else
	setvarvar M3 THISACTOR
}

ends

state drop_ammo
  ifrnd SPAWNAMMOODDS
    spawn AMMO
ends

state drop_battery
  ifrnd SPAWNAMMOODDS
    spawn BATTERYAMMO
ends
state drop_sgshells
  ifrnd SPAWNAMMOODDS
    spawn SHOTGUNAMMO
ends
state drop_shotgun
  ifrnd SPAWNAMMOODDS
    spawn SHOTGUNSPRITE
ends
state drop_chaingun
  ifrnd SPAWNAMMOODDS
  {
    ifrnd 32
    {
	  ifactor LIZMAN ifvare mtype 1 spawn FREEZESPRITE else
      spawn CHAINGUNSPRITE
    }
    else
    {
	  ifactor LIZMAN ifvare mtype 1 spawn FREEZEAMMO else
      spawn BATTERYAMMO
    }
  }
ends

state ricochetsound
iffloordistl 1 break
 randvar spriteid 100
   ifvarl spriteid 20 sound RICOCHET2
   else ifvarl spriteid 40 sound RICOCHET3
   else ifvarl spriteid 60 sound RICOCHET4
   else ifvarl spriteid 80 sound PISTOL_RICOCHET
   else sound RICOCHET5
ends


state flakdamage // tempb is damage

getactor[THISACTOR].picnum tilenum
switch tilenum

case DRONE
case TANK
case ROBOMAN
case MECH1
case MECH2
case DRONEDEV
case ROTATEGUN
case ROTATEGUNALLY
break

case BOSS2
case MINIBOSS2
case BOSS3
case MINIBOSS3
mulvar tempb 3
divvar tempb 2
setactor[THISACTOR].htextra tempb
break

default
mulvar tempb 2
setactor[THISACTOR].htextra tempb
break

endswitch

ends

state upgradeweapon

// tempb holds the current weapon
// pdamage holds the level of the current weapon

addvar pdamage 20
switch tempb
case 0 setvarvar weap0lev pdamage break
case 1 setvarvar weap1lev pdamage break
case 2 setvarvar weap2lev pdamage break
case 3 setvarvar weap3lev pdamage break
case 4 setvarvar weap4lev pdamage break
case 5
case 10 setvarvar weap5lev pdamage break
case 6
case 11 setvarvar weap6lev pdamage break
case 7 setvarvar weap7lev pdamage break
case 8 setvarvar weap8lev pdamage break
case 9 setvarvar weap9lev pdamage break
endswitch

globalsound SHIELD_UPGRADE
palfrom 40 63 63 63
setvar messagetime 52
ifvare tempb 0 setvar message 216 else setvar message 215

ends

state weaplevel

switch tempb
case 0 setvarvar pdamage weap0lev setvarvar tempc weap0xp break
case 1 setvarvar pdamage weap1lev setvarvar tempc weap1xp break
case 2 setvarvar pdamage weap2lev setvarvar tempc weap2xp break
case 3 setvarvar pdamage weap3lev setvarvar tempc weap3xp break
case 4 setvarvar pdamage weap4lev setvarvar tempc weap4xp break
case 5
case 10 setvarvar pdamage weap5lev setvarvar tempc weap5xp break
case 6
case 11 setvarvar pdamage weap6lev setvarvar tempc weap6xp break
case 7 setvarvar pdamage weap7lev setvarvar tempc weap7xp break
case 8 setvarvar pdamage weap8lev setvarvar tempc weap8xp break
case 9 setvarvar pdamage weap9lev setvarvar tempc weap9xp break
endswitch


// tempc holds the current weapon's XP

switch pdamage // is it time for the weapon to level up?

case 60 ifvarg tempc L0XP state upgradeweapon break
case 80 ifvarg tempc L1XP state upgradeweapon break
case 100 ifvarg tempc L2XP state upgradeweapon break
case 120 ifvarg tempc L3XP state upgradeweapon break
case 140 ifvarg tempc L4XP state upgradeweapon break
case 160 ifvarg tempc L5XP state upgradeweapon break
case 180 ifvarg tempc L6XP state upgradeweapon break
case 200 ifvarg tempc L7XP state upgradeweapon break
case 220 ifvarg tempc L8XP state upgradeweapon break
case 240 ifvarg tempc L9XP state upgradeweapon break
case 260 break // top level
endswitch

// determines experience penalty, if any
// the higher xpmult, the greater the XP penalty

	setvarvar xpmult pdamage
	mulvar xpmult 80
	setvarvar tempb weap1lev
	addvarvar tempb weap2lev
	addvarvar tempb weap3lev
	addvarvar tempb weap4lev
	addvarvar tempb weap5lev
	addvarvar tempb weap6lev
	addvarvar tempb weap7lev
	addvarvar tempb weap8lev
	addvarvar tempb weap9lev
	subvarvar tempb pdamage
	ifvare tempb 0 setvar tempb 1
	divvarvar xpmult tempb
	
	setvarvar kickxp weap0lev
	mulvar kickxp 80
	setvarvar tempb weap1lev
	addvarvar tempb weap2lev
	addvarvar tempb weap3lev
	addvarvar tempb weap4lev
	addvarvar tempb weap5lev
	addvarvar tempb weap6lev
	addvarvar tempb weap7lev
	addvarvar tempb weap8lev
	addvarvar tempb weap9lev
	subvarvar tempb weap0lev
	ifvare tempb 0 setvar tempb 1
	divvarvar kickxp tempb
	
// the higher temp, the less XP

ends

move SHRUNKVELS 32
action ATROOPWALKING   0  4  5  1   12
action ATROOPJETPACK  40  1  5  1  1
action ATROOPSUFFERING  59  2  1  1   21
ai AITROOPSHRUNK   ATROOPWALKING   SHRUNKVELS fleeenemy

action ATROOPFLINTCH  50  1  1  1  6
action BOSS1FLINTCH       50 1  1  1  1
action BOSS2FLINTCH       40 1  1  1  1
action BOSS3FLINTCH       40 1  1  1  1
action BOSS4FLINTCH       40 1  1  1  1
action MINIBOSS2FLINTCH       30 1  1  1  1
action MINIBOSS4FLINTCH       30 1  1  1  1
action ANEWBEASTFLINTCH   71  1  1  1  1


state monsterai

getactor[THISACTOR].extra hp

ifvarg peractor6 0
{
	cos xvel dodgeang
	sin yvel dodgeang
	setvarvar temp peractor6
	ifvarg temp 1024 setvar temp 1024
	mulvarvar xvel temp
	mulvarvar yvel temp
	shiftvarr xvel 13
	shiftvarr yvel 13
	setvar zvel 0
	movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN
	shiftvarr peractor6 1
	ifvarl peractor6 4 setvar peractor6 0
}

ifvarn bfgid -1
{
	dist temp THISACTOR bfgid
	ifvarl temp 14336 spawn BFGIMPACT
}

// code for shade cycling when hit by bombdart

ifvarg darthit 0
{
	state shadepulse
	setactor[THISACTOR].shade shade
}


ifvarl monstatus 1 // if the monster has not yet been seen
{   
    ifvare monstatus -1 // this next block can be used for extra initialization stuff
	{
		ifvarg hp 5
		{
			ifactor ROTATEGUN nullop else
			{
				espawn LIFEBAR
				setactorvar[RETURN].myspawner THISACTOR
			}
			setvar temp 0
			getactor[THISACTOR].picnum tilenum
			switch tilenum
			case BOSS1 case BOSS1STAYPUT case BOSS1SHOOT case BOSS1LOB
			case BOSS2 case BOSS3 case BOSS4 case BOSS4STAYPUT 
			ifspritepal 0 setvar temp 1
			break
			endswitch
			ifvare temp 0
			{
				// next code determines immunities
				setvarvar temp score
				divvar temp 200 // chance of immunity is 1% per 200 points
				ifvarl temp 1 setvar temp 1
				randvar tempb 100
				ifactor ROTATEGUN nullop else
				ifvarvarl tempb temp
				{
					// assign immunity
					randvar temp 3
					ifvare temp 0 orvar immunity 1 else
					ifvare temp 1 orvar immunity 2 else
					ifvare temp 2 orvar immunity 4 else
					ifvare temp 3 orvar immunity 8
					setactorvar[RETURN].immunity immunity
				}
			}
			
		}
		setvar monstatus 0
		ifspawnedby RESPAWN nullop else
		setactor[THISACTOR].statnum 2
	}
  
    ifcansee setvar monstatus 1

}
else ifvare monstatus 1
{
	 ifvarl hp 1 setactor[THISACTOR].extra 1
}
else ifvare monstatus 2
ifwasweapon FIREBULLET
{
	spriteflags 7
	setactor[THISACTOR].shade 25
}

// code for cannonball squishing
// code for burning

ifvarg fireinmap 0 ifvare railed 0
{
	ifvarg nuclear 0 subvar nuclear 1
	ifactor NEWBEAST ifvare mtype 2 nullop
	else ifactor LIZMAN ifvare mtype 2 nullop else
	ifvare nuclear 0
	{
		findnearactorz STICKYFIRE 768 8192 temp
		ifvare temp -1 findnearactorz BIGFIRE 768 8192 temp
		ifvarn temp -1
		{
			soundonce COOKINGDEEPFRIER
		   	setvarvar tempc weap2lev
		   	ifactor LIZMAN ifvare mtype 1
		   	{
			   	mulvar tempc 2
			   	spawn NEWSMOKE
		   	}
			divvar tempc 50 ifvarl tempc 1 setvar tempc 1
			ifvarg hp 0
			{
				  subvarvar hp tempc
				  ifvarl hp 1 
				  {
				      setactor[THISACTOR].extra 0
				      strength 0
				      setactor[THISACTOR].htextra 5
				      setactor[THISACTOR].htpicnum FIREBULLET
				  }
			  	  else setactor[THISACTOR].extra hp
			}
	
			getactorvar[temp].mtype tempb
			ifvarl tempb 40
			{
				ifrnd 32 spawn BURNING
			   	espawn STICKYFIRE
				addvar tempb 1
				setactorvar[RETURN].mtype tempb
				setactorvar[RETURN].myspawner THISACTOR
				getactor[THISACTOR].picnum tempb
				setactorvar[RETURN].monstatus tempb
			   	setvar nuclear 5
			}
	   }
	}
}


// code for various weapon hit effects

ifvarg superkicking 0 ifvare kickimpact 0 ifvare monstatus 1
{
	ifp pfacing
		ifpdistl 1792
			ifcansee
				ifcanshoottarget
	{
		getplayer[THISACTOR].i spriteid
		setactorvar[spriteid].dodge 0
		ifvarg superkicking 7
		{
			ifvare spinkick 0 setvar kickimpact 1
			sound WHACK
			addvar stamina 20
			ifvarg stamina MAXSTAMINA setvar stamina MAXSTAMINA
			setvarvar tempb weap0lev
			ifp ponground ifvarl leglevel 4
			divvar tempb 2
			
			addvar tempb 10
			setactor[THISACTOR].htpicnum KNEE
			setactor[THISACTOR].htextra tempb
			ifvarand immunity 4 nullop else
			{
				divvar tempb 4
				setvarvar tempc tempb
				ifvarg kickxp 40 setvar tempc 0 else
				ifvarg kickxp 30 divvar tempc 4 else
				ifvarg kickxp 15 divvar tempc 2
				ifvare spinkick 0
				{
					addvarvar pheal tempb
					ifvarg tempc 0
					{
						addvarvar weap0xp tempc
						setvarvar tempd pdamage
						setvar tempb 0
						state weaplevel
						setvarvar pdamage tempd
					}
				}
				getplayer[THISACTOR].i spriteid
				setactor[THISACTOR].htowner spriteid
			}
		}
	}
}
ifaction ANULLACTION break // regular objects don't do the rest

getactor[THISACTOR].htextra tempb
ifvarg tempb 0
{
	getactor[THISACTOR].htpicnum temp
	switch temp
	case CHILLBLAST
	case CHILLBLAST2
	case FREEZENOAIM
	   setactor[THISACTOR].htpicnum FREEZEBLAST
	break
	case FLAK
	state flakdamage 
	break
	case RPG
	case RPGNOAIM
	case RADIUSEXPLOSION
	case HLROCKET
	case CANNONBALLPROJ
	getactor[THISACTOR].xvel xvel
	mulvar xvel -1
	setactor[THISACTOR].xvel xvel
	break
	endswitch
	
       

	// code for HEALBOLT to act as healing bolt on monsters
	ifvare temp HEALBOLT
	{
		setactor[THISACTOR].htextra 0
		getactor[THISACTOR].extra hp
		ifvarl hp 1000 addstrength 10
		break
	}

	// code for red newbeast magma and flamethrower immunity
	ifactor NEWBEAST ifvare mtype 2
	{
		ifvare temp MAGMA
		{ setvar tempb 1 setactor[THISACTOR].htextra tempb }
		ifvare temp FLAMETHROWER
		{ setvar tempb 1 setactor[THISACTOR].htextra tempb }
	}

	ifvare temp RAILSLUG
	{
		ifvare railed 0 setvar railed 19
		ifvarg railed 0 ifvarl railed 20 { setactor[THISACTOR].htextra 0 break }
	}
		

	ifvare headshot 1
	{
	 	setvar headshot 0
	 	getplayer[THISACTOR].player_par tempc
	 	getplayer[THISACTOR].i spriteid
	 	setactorvar[spriteid].headshot tempc // for the player, headshot triggers text display
	 	mulvar tempb 2
	 	guts JIBS2 1
  	 	guts JIBS3 2
  	 	guts JIBS4 3
  	 	guts JIBS5 2
  	 	guts JIBS6 3
	}
		
	// Damage multiplier code
	getactor[THISACTOR].htowner spriteid
	ifvarn spriteid -1 getactor[spriteid].picnum temp
	else setvar temp -1
	ifvare temp APLAYER
	{
		getactor[spriteid].yvel tempc
		getplayervar[tempc].pdamage temp
		mulvarvar tempb temp
		divvar tempb 100
		setactor[THISACTOR].htextra tempb
	}
	
	ifvarn immunity 0
	{
		getactor[THISACTOR].htpicnum tilenum
		ifvarand immunity 1 // bullets
		{
			switch tilenum
			case SHOTSPARK1 case FLAK case RAILSLUG case SLOWBULLET
			case APROUND
			setactor[THISACTOR].htextra -1
			ifcansee ifpdistl 10240 sound NODAMAGE
			ifvarand tipfield 8192 nullop else ifvare tipdisplay 0
			{
				ifcansee ifvare ONCAR 0 ifp palive
				{
					// BULLET IMMUNITY
					setvar menutoggle 4
					setvar tipdisplay 8192
					orvar tipfield 8192
					setvar messagetime 26
					globalsound EXITMENUSOUND
				}
			}
			break
			endswitch
		}
		ifvarand immunity 2 // explosives
		{
			switch tilenum
			case RADIUSEXPLOSION case RPG case MININUKE case RPGNOAIM
			case HLROCKET case CPUDEV case BFG case CANNONBALLPROJ case NOVA
			setactor[THISACTOR].htextra -1
			ifcansee ifpdistl 10240 sound NODAMAGE
			ifvarand tipfield 16384 nullop else ifvare tipdisplay 0
			{
				ifcansee ifvare ONCAR 0 ifp palive
				{
					// EXPLOSIVE IMMUNITY
					setvar menutoggle 4
					setvar tipdisplay 16384
					orvar tipfield 16384
					setvar messagetime 26
					globalsound EXITMENUSOUND
				}
			}
			break
			endswitch
		}
		ifvarand immunity 4 // kicks
		{
			switch tilenum
			case KNEE case SUPERKICK
			setactor[THISACTOR].htextra -1
			ifcansee ifpdistl 10240 sound NODAMAGE
			ifvarand tipfield 32768 nullop else ifvare tipdisplay 0
			{
				ifcansee ifvare ONCAR 0 ifp palive
				{
					// KICK IMMUNITY
					setvar menutoggle 4
					setvar tipdisplay 32768
					orvar tipfield 32768
					setvar messagetime 26
					globalsound EXITMENUSOUND
				}
			}
			break
			endswitch
		}
		ifvarand immunity 8 // elements
		{
			switch tilenum
			case FREEZEBLAST case ACIDBULLET case FIREBULLET case ALTSHOTGUN
			case LIGHTNINGBOLT case FIRELASER case FIRELASER2 case FIRELASER3
			case BLASTER case BLASTER2 case BLASTER3 case BLASTER4
			case FLAMETHROWER case MAGMA case SHRINKSPARK
			setactor[THISACTOR].htextra -1
			setactor[THISACTOR].htpicnum SHOTSPARK1
			ifcansee ifpdistl 10240 sound NODAMAGE
			ifvarand tipfield 65536 nullop else ifvare tipdisplay 0
			{
				ifcansee ifvare ONCAR 0 ifp palive
				{
					// ELEMENTAL IMMUNITY
					setvar menutoggle 4
					setvar tipdisplay 65536
					orvar tipfield 65536
					setvar messagetime 26
					globalsound EXITMENUSOUND
				}
			}
			break
			endswitch
		}
	}
	// knockback code
	
		getactor[THISACTOR].htextra temp
		getactor[THISACTOR].htpicnum tilenum
		setvar tempd 0
		ifvarl mval BOSSVAL setvar tempd 1
		ifvarn tilenum FREEZEBLAST setvar tempd 1
		ifvarg temp 0 ifvare tempd 1
		{
			// new knockback code
			ifactor ROTATEGUN nullop else
			{
				getactor[THISACTOR].htang dodgeang // the angle monster will move in
				setvarvar peractor6 temp // temp is damage
				mulvar peractor6 13 // peractor6 is the knockback force
				setvarvar temp hp
				ifvarl temp 10 setvar temp 10
				shiftvarl temp 1
				subvarvar peractor6 temp
				setvar tempc 0
				ifactor BOSS1 setvar tempc 1
				ifactor BOSS2 setvar tempc 1
				ifactor BOSS3 setvar tempc 1
				ifactor BOSS4 setvar tempc 1
				ifactor TANK setvar tempc 1
				ifactor MECH1 setvar tempc 1
				ifactor MECH2 setvar tempc 1
				ifvare tempc 1
				{
					ifvare tilenum SHOTSPARK1 shiftvarr peractor6 1
					shiftvarr peractor6 1
				}
				ifvare monstatus 2 shiftvarr peractor6 1
				ifvarl peractor6 0 setvar peractor6 0
			}
			
		}
}

ends

state smallboulder

getactor[THISACTOR].xrepeat x
divvar x 2
randvar tempb 5000
mulvar tempb -1
ezshoot tempb MAGMA
setactor[RETURN].xrepeat x
setactor[RETURN].yrepeat x
randvar angvar 2047
setactor[RETURN].ang angvar
setactorvar[RETURN].mtype 1
ifactor ROLLBOULDER setthisprojectile[RETURN].pal 30
setthisprojectile[RETURN].spawns SMALLEXPLOSION
setthisprojectile[RETURN].extra 20

ends

state breakboulder

addvar loop 1
state smallboulder
ifvarl loop 4 state breakboulder
ends

action FIREBREATHFRAME1 1 1 1 1 4
action FIREBREATHFRAME2 2 1 1 1 4
action FIREBREATHFRAME3 3 1 1 1 4
action FIREBREATHFRAME4 4 1 1 1 4
action FIREBREATHFRAME5 5 1 1 1 4
action FIREBREATHFRAME6 6 1 1 1 4

useractor notenemy FLAMETHROWER 0 FIREBREATHFRAME1 enda


onevent EVENT_GAME

ifvarg menutoggle 0 
{ 
	ifvarn monstatus 2 { sleeptime 1 break } 
} // monsters don't activate while menu is on
else ifactor HOLOBOT setactor[THISACTOR].statnum 1

getactor[THISACTOR].statnum temp
ifvare temp 4
{
	getactor[THISACTOR].picnum tilenum
	switch tilenum
	case SPARKPROJ 
	case SPARKPROJ2
	
		getactor[THISACTOR].xrepeat x
		getactor[THISACTOR].yrepeat y
		ifvarg x 1 subvar x 1
		ifvarg y 1 subvar y 1
		setactor[THISACTOR].xrepeat x
		setactor[THISACTOR].yrepeat y
	break
	
	case NEWSCRAP1
	case NEWSCRAP2
	case NEWSCRAP3
	case NEWSCRAP4
	case NEWSCRAP5
	case NEWSCRAP6
	getactor[THISACTOR].pitch temp
	addvar temp 16
	ifvarg temp 2047 subvar temp 2048
	setactor[THISACTOR].pitch temp
	break
	endswitch

	ifvarn mtype -66
	{
		ifcansee
	 	setvar barriergrow 78
		addvar countvarc 1
		setvarvar spriteid THISACTOR
		getactor[THISACTOR].cstat revives
		setactor[THISACTOR].cstat 32768
		state projectilehitscan
		setactor[THISACTOR].cstat revives
		ifvarn hitsprite -1
		{
			getactor[hitsprite].picnum tilenum
			ifactor SHOTSPARK1 nullop else
			ifvare tilenum BARRIER
			{
				ldist xydist THISACTOR hitsprite
				ifvarl xydist 896 setactorvar[hitsprite].target THISACTOR
			}
			else ifvare tilenum DRONEDEV
			{
				setactorvar[hitsprite].hammtarg THISACTOR
			}
			else ifvare tilenum EVILDUKE ifvarg countvarc 2
			{
				setactorvar[hitsprite].hammtarg THISACTOR
			}	
		}
	}
	ifactor SLOWBULLET ifvare goggles 1 { setactor[THISACTOR].pal 6 spawn FRAMEEFFECT1 }
	ifvarg holosphere 0
	{
		findnearactorz HOLOSPHERE 4096 32768 spriteid
		ifvarn spriteid -1
		{
			 getactor[THISACTOR].owner tempb
			 ifvare tempb -1 setvar tilenum -1 else
			 getactor[tempb].picnum tilenum
			 ifvarn tilenum APLAYER ifvarn tilenum HOLOBOT ifvarn tilenum ROTATEGUNALLY
			 ifvarn nuclear 1
			 {
				   setvar nuclear 1
				   setvarvar xvel initx
				   divvar xvel 4
				   setvarvar zvel initz
				   divvar zvel 4
				   setactor[THISACTOR].xvel xvel
				   setactor[THISACTOR].zvel zvel
				   spawn LASER3IMPACT
				   ifvarg holosphere 1 subvar holosphere 1
			 }
		 }
		 else ifvare nuclear 1
		 {
			 setvar nuclear 0
			 setactor[THISACTOR].xvel initx
			 setactor[THISACTOR].zvel initz
			 spawn LASER3IMPACT
		 }
	}
	else ifvare nuclear 1
	{
		setvar nuclear 0
		setactor[THISACTOR].xvel initx
		setactor[THISACTOR].zvel initz
		spawn LASER3IMPACT
	}
}

ifvarg railed 0 subvar railed 1
ifvarg darthit 1 subvar darthit 1
ifvare darthit 12 sound LASERTRIP_ARMING
ifvare darthit 1
{
		getactor[THISACTOR].extra tempb
		sound PIPEBOMB_EXPLODE

		ifvarl pdamage 80
		{
			subvar tempb 80
			hitradius 3584 20 40 60 80
		}
				
		else ifvarl pdamage 120
		{
			subvar tempb 100
			hitradius 3584 25 50 75 100
		}

		else ifvarl pdamage 160
		{
			subvar tempb 125
			hitradius 3584 30 60 90 115
		}

		else ifvarl pdamage 200
		{
			subvar tempb 150
			hitradius 3584 35 70 100 125
		}

		else
		{
			subvar tempb 200
			hitradius 3584 40 80 125 150
		}

		ifvarl tempb 1 setvar tempb 0
		setactor[THISACTOR].extra tempb

		spawn BIGEXPLOSION
		palfrom 33 63 63 63
		quote 151
		ifrnd 128 spawn BURNING else spawn BURNING2
		setvar darthit 0
		setactor[THISACTOR].shade 0 // because it has been pulsing
			
// 		ifvare tempb 0
// 		{
// 			state standard_jibs
// 			sound SQUISHED
// 			addkills 1
// 			state clearlists
// 			state dropcoins
// 			state addscore
// 			setactor[THISACTOR].xrepeat 0
// 			killit
// 		}
}

ifvare NOCODE 1 break

getactor[THISACTOR].picnum temp

switch temp

	case RAINSPRITE 
	case SKYCAR_CRASHED
	case SKYCAR_FLY
	case CAR_BLOCKER
	case SMALLEXPLOSION
	case BIGEXPLOSION
	case EXPLOSION2
	case SMALLSMOKE
	case NEWSMOKE
	case LIFEBAR
	case RAILTRAIL2
	case ICEBLOCK
	case BONUSRING
	case BIGBOMB
	case INVISEGG
	sleeptime 0
	changespritestat THISACTOR 1
	break

	case DIPSWITCH
	case DIPSWITCH2
	case DIPSWITCH3
	case TECHSWITCH
	
	ifvare goggles 1
	{
		getactor[THISACTOR].hitag hitag
		ifvare hitag 1 setactor[THISACTOR].pal 6
		else setactor[THISACTOR].pal mtype
	}
	else setactor[THISACTOR].pal mtype
			
	break
	
	case 163 case 165 case 167 case 169
	
	ifvare goggles 1
	{
		getactor[THISACTOR].hitag hitag
		ifvare hitag 0 setactor[THISACTOR].pal 6
		else setactor[THISACTOR].pal mtype
	}
	else setactor[THISACTOR].pal mtype
	break

	case SPIT
	ifspawnedby NEWBEAST ifrnd 8 spawn ACIDCLOUD
	break

	case SEENINE
	case FIREEXT
	case OOZFILTER
	case CANWITHSOMETHING
	case CANWITHSOMETHING2
	case CANWITHSOMETHING3
	case CANWITHSOMETHING4
	case VASE
	case FIREBARREL
	case FIREVASE
	
	ifvarg superkicking 0 ifvare kickimpact 0
	{
		ifp pfacing
			ifpdistl 1536
				ifcansee
		{
			ifvarg superkicking 7
			{
				soundonce WHACK
				setactor[THISACTOR].htpicnum KNEE
				setactor[THISACTOR].htextra 10	
			}
		}
	}
	break
	
	
	case SHELL
	case SHOTGUNSHELL
	iffloordistl 1
	{
		getactor[THISACTOR].statnum tempb
		ifvarn tempb 1
		{
			ifactor SHELL { addvar temp 1 setactor[THISACTOR].picnum temp }
			changespritestat THISACTOR 1
		}
	}
	break

	case BLASTER4
	ifvare countvar 1
		setactor[THISACTOR].cstat 0
	ifvare countvar 0 setvar countvar 1
	break
	
	case POKEBALL
	ifvare countvar 0
	{
		setvar countvar 1
		getactor[THISACTOR].xrepeat tempb
		mulvar tempb -32
		setactor[THISACTOR].mdzoff tempb
	}
	getactor[THISACTOR].pitch tempb
	addvar tempb 160
	ifvarg tempb 2047 subvar tempb 2048
	setactor[THISACTOR].pitch tempb
	getactor[THISACTOR].pal tempb
	ifvare tempb 0 setvar tempb 6 else setvar tempb 0
	setactor[THISACTOR].pal tempb
	break

	case COOLEXPLOSION1

    ifspawnedby BOSS2 
    { 
	    spawn FRAMEEFFECT1 
	    state randtraj 
	    state randtraj 
	}
	break
	
	case FLAMETHROWER
	ifvare countvar 6 action FIREBREATHFRAME2
	ifvare countvar 9 action FIREBREATHFRAME3
	ifvare countvar 12 action FIREBREATHFRAME4
	ifvare countvar 15 action FIREBREATHFRAME5
	ifvare countvar 18 action FIREBREATHFRAME6
	ifvare countvar 21 { action FIREBREATHFRAME2 setvar countvar 6 }
	addvar countvar 1
	break
	
	case CANNONBALLPROJ
	setvarvar spriteid THISACTOR
	state projectilehitscan
	break
	
	case HEALBOLT
	spawn FRAMEEFFECT1
	break

	case FLESH1
	case FLESH2
	case FLESH3
	case BRAIN 
	case SPINE
	case LIZHEAD
	case LIZARM
	case LIZLEG
	case PIGHEAD
	case PIGUPPER
	case PIGUPPER2
	case PIGLOWER
	case PIGLOWER2

	case TROOPHEAD
	case TROOPARM
	case TROOPLEG
		
	addvar countvar 1
	ifvarvarl countvar countvarb 
	{
	 	ifrnd 96
	 	{ 
			espawn NEWBLOOD1
			ifvare mtype 1 setactor[RETURN].pal 6
		}
	}
	else ifrnd 32 
	{ 
		espawn NEWBLOOD1
		ifvare mtype 1 setactor[RETURN].pal 6
	}

	getactor[THISACTOR].pitch my
	addvarvar my hammo2
	ifvarg my 2047 subvar my 2048
	setactor[THISACTOR].pitch my
	getactor[THISACTOR].roll mx
	addvarvar mx hammo3
	ifvarg mx 2047 subvar mx 2048
	setactor[THISACTOR].roll mx

	
	ifrnd 16 state random_wall_jibs

	getactor[THISACTOR].yvel tempb
	ifvare tempb 1
	{
		getactor[THISACTOR].picnum tilenum
		addvar tilenum 1
		setactor[THISACTOR].picnum tilenum
		setactor[THISACTOR].statnum 1
		setactor[THISACTOR].zvel 0
		setactor[THISACTOR].pitch 0
		setactor[THISACTOR].roll 0
		ifspritepal 22 nullop else
		ifrnd 128 soundonce JIBLAND else soundonce JIBLAND2
	}
		
	break
	
	// dead body sprites
	case 677 // EGG
	case 1734 // LIZTROOP
	case 1855 // OCTABRAIN
	case 1957 // COMMANDER
	case 2060 // PIGCOP
	case 2185 // LIZMAN
	case 2685 // BOSS1
	case 2758 // BOSS2
	case 2809 // BOSS3
	case 4689 // NEWBEAST
	case 4789 // BOSS4
	getactor[THISACTOR].htextra tempb
	ifvarg tempb 0
	{
		sound SQUISHED
		ifvare temp 2185 cactor LIZMAN
		ifvare temp 4689 { cactor NEWBEAST spritepal 6 }
		ifvare temp 4789 { cactor BOSS4 spritepal 6 }
		state standard_jibs
		killit
	}
	break
	
	case CHILLBLAST2
	case CHILLTRAIL
	randvar tempb 2048
	setactor[THISACTOR].roll tempb
	break
	
	case BLOODPOOL
	ifonwater killit

	break
	
	case HLROCKET
	
	ifoutside
	{
		getactor[THISACTOR].sectnum mysector
		getactor[THISACTOR].zvel zvel
		ifvarn mysector -1 ifvarl zvel 0
		{
			divvar zvel -4
			ifvarn zvel 0
			{
				getactor[THISACTOR].x x
				getactor[THISACTOR].y y
				getactor[THISACTOR].z z
				getceilzofslope mysector x y mz // z is the return var
				subvarvar z mz
				divvarvar z zvel
				ifvarl z 2 ifawayfromwall 
				{
					setvar immunity 2
					killit
				}
			}
		}
	}
	
	findnearspritez LIGHTNINGBOLT 768 6144 spriteid
	ifvarn spriteid -1	
	{
	  spawn EXPLOSION2
	  hitradius 1536 25 35 50 70
	  setactor[THISACTOR].xrepeat 0
	  setactor[THISACTOR].yrepeat 0
	  killit
	}
	
	addvar countvar 1
	ifvarg countvar 7
	{
		espawn ROCKETHALO
		setactorvar[RETURN].myspawner THISACTOR
		ifvare countvar 8 ifvare mtype 0
	    {
		    sound WHOOSH
		    setvar mtype 1
		    setactor[THISACTOR].xrepeat 12
		    setactor[THISACTOR].yrepeat 12
		    getactor[THISACTOR].xvel xvel
		    getactor[THISACTOR].zvel zvel
		    setvar loop 0
		    whilevarn loop 10
		    {
			    addvar loop 1
			    eshoot HLROCKET
			    setactorvar[RETURN].mtype 1
			    setactor[RETURN].xrepeat 12
			    setactor[RETURN].yrepeat 12
			    setactor[RETURN].zvel zvel
			    setactor[RETURN].xvel xvel
			    setactorvar[RETURN].countvar 9
			    setactorvar[RETURN].myspawner myspawner
			    setactorvar[RETURN].target target
		    }
		    
	    }
	   ifvarn target -1 state guideit
	   else
	   ifvarn myspawner -1 // the rest of the code...
	   {
		   getactorvar[myspawner].target target
		      
// 		    ifvare target -1
// 		    {
// 			   getactorvar[myspawner].hitsector hitsector
// 			   getactorvar[myspawner].hitx hitx
// 			   getactorvar[myspawner].hity hity
// 			   getactorvar[myspawner].hitz hitz
// 			   getactorvar[myspawner].hitsprite hitsprite
// 			   setvar tempd -1
// 			   ifvarn hitsprite -1
// 			   {
// 			      getactor[hitsprite].extra hp
// 			      getactor[hitsprite].statnum tempb
// 			      getactor[hitsprite].picnum tempd
// 			       ifvare tempb 1 ifvarg hp 0
// 			         ifvarvarn hitsprite THISACTOR ifvarn tempd BARRIER ifvarn tempd ROCKETHALO
// 			          setvarvar target hitsprite
// 			   }
// 		    }
// 		  
// 		   ifvare target -1 ifvarvarn hitsprite THISACTOR ifvarn tempd ROCKETHALO
// 		    {
// 			   getactor[THISACTOR].x x
// 			   getactor[THISACTOR].y y
// 			   getactor[THISACTOR].z z
// 			   subvarvar hitz z
// 			   ifvarl hitz 1024 ifvarg hitz -1024 nullop else
// 			   {
// 				     setvarvar temp x
// 					 subvarvar temp hitx
// 					 mulvarvar temp temp
// 						
// 					 setvarvar tempb y
// 					 subvarvar tempb hity
// 					 mulvarvar tempb tempb
// 						
// 					 addvarvar temp tempb
// 					 sqrt temp temp
// 					 setvarvar xydist temp

// 				     mulvar hitz 960
// 				     ifvare xydist 0 setvar xydist 1
// 				     divvarvar hitz xydist
// 				     setactor[THISACTOR].zvel hitz
// 			   }
// 			   
// 		   	   subvarvar hitx x
// 		       subvarvar hity y
// 		       getangle angvar hitx hity
// 		      	       
// 		       getactor[THISACTOR].ang tempb
// 		       
// 			   getincangle tempd angvar tempb
// 				
// 				ifvarl tempd 33 ifvarg tempd -33
// 				setactor[THISACTOR].ang angvar
// 				else
// 				{
// 					ifvarl tempd 0 
// 						addvar tempb 32
// 					else
// 					ifvarg tempd 0 
// 						subvar tempb 32
// 	
// 					setactor[THISACTOR].ang tempb
// 				}

// 			} // end of last ifvare target -1 condition
		} // end of big else
		
		ifvare mtype 1 state randtraj

	} // end of ifvarg countvar 10 condition
	
	getactor[THISACTOR].xvel xvel
	getactor[THISACTOR].zvel zvel
	setvarvar tempb zvel
	//shiftvarl tempb 4
	mulvar tempb 14
	ifvare xvel 0 setvar xvel 1
	divvarvar tempb xvel
	setactor[THISACTOR].pitch tempb
	break
	
case BFG

 	getactor[THISACTOR].pitch temp
	addvar temp 84
	ifvarg temp 2047 subvar temp 2048
	setactor[THISACTOR].pitch temp
	getactor[THISACTOR].roll temp
	addvar temp 96
	ifvarg temp 2047 subvar temp 2048
	setactor[THISACTOR].roll temp
	break


 case MAGMA
 
	ifrnd 32 spawn STICKYFIRE
	getactor[THISACTOR].pitch temp
	addvar temp 64
	ifvarg temp 2047 subvar temp 2048
	setactor[THISACTOR].pitch temp

	getactor[THISACTOR].yvel tempb
	ifvare tempb 10 setvar countvar 10
	else
	ifvarvarl tempb countvar
	{
		setvarvar countvar tempb
		getactor[THISACTOR].zvel zdist
		ifvarl zdist 0 divvar zdist 2
		setactor[THISACTOR].zvel zdist
	}
	ifvare countvar 1 ifvare mtype 0
	{
		state breakboulder
		spawn EXPLOSION2
		sound PIPEBOMB_EXPLODE
		setvar mtype 1
	}
	break

case DTRIP

	setvarvar spriteid THISACTOR
	state actorhitscan
	
	ifvare mtype 0 ifvare tripon 1 ifvarg special 0
    {
		subvar special SPECIAL8_AMOUNT
		setvar mtype 1
    }
	
	ifvarn hitsprite -1 ifvarg loop 26
	{ 
		getactor[hitsprite].statnum tempb
		getactor[hitsprite].picnum tilenum
		ifvare tilenum APLAYER setvar tempb 1
        ifvare tilenum BARRIER setvar tempb 0
		ifvare tempb 1
		{
			setactor[THISACTOR].statnum 1
			setvar loop 0
		}
	}
	addvar loop 1
	break

case FIRELASER2

	ifspawnedby APLAYER 
	{
		state randtraj
		spawn FRAMEEFFECT1
	}
	else
	ifvarg loop 13
	{
		getactor[THISACTOR].ang angvar
		ifrnd 128 addvar angvar 32 else subvar angvar 32
		setactor[THISACTOR].ang angvar
		setvar loop 0
	}
	getactor[THISACTOR].xrepeat tempc
	ifrnd 96
	{
		ifvarl tempc 128 addvar tempc 1
		setactor[THISACTOR].xrepeat tempc
		setactor[THISACTOR].yrepeat tempc
		getactor[THISACTOR].extra tempc
		ifvarl tempc 50 addvar tempc 1
		setactor[THISACTOR].extra tempc
	}
	
	addvar loop 1
	
		
	break

	
case FLAK

	getactor[THISACTOR].yvel tempb
	ifvare tempb 4 setvar mtype 4
	else
	ifvarvarl tempb mtype
	{
		setvarvar mtype tempb
		state ricochetsound
	}
	break


case HEAVYHBOMB

   addvar countvar 1
   getplayer[THISACTOR].i spriteid
   ldist xydist THISACTOR spriteid
   ifvare mval -2
   {
   		ifvarg countvar 26
   		{
	   		ifvarl xydist RETRIEVEDISTANCE
		   		setvar countvar 53
		}
	    ifvarg countvar 52 ifvare countvarb 0
		{
			setvar countvarb 1
			debris SCRAP1 4
			spawn DTPIPESTUFF
			setvar loop 0
			setactor[THISACTOR].xrepeat 0
			setactor[THISACTOR].yrepeat 0
		}
   }
   ifvare mval -3
   {
	   ifvarg countvar 26
	     ifvarl xydist RETRIEVEDISTANCE
	       ifcanseetarget
	   {
		   getactor[spriteid].z mz
		   getactor[THISACTOR].z z
		   subvarvar mz z
		   ifvarl mz 0 mulvar mz -1
		   ifvarl mz 9216
		   {
			   globalsound DUKE_GET
	  		   palfrom 16 0 32
	  		   addweapon HANDBOMB_WEAPON 1
	  		   addvar special SPECIAL5_AMOUNT
	  		   setactor[THISACTOR].xrepeat 0
			   setactor[THISACTOR].yrepeat 0
		   }
	   } else
   
	   ifvarg pipefire 0
	   {
		     debris SCRAP1 4
		     sound GRENADE_BOOM
		     setvar pipefire 0
		     espawn ICEPIPE
		     setactor[RETURN].owner myspawner
		     setactor[THISACTOR].xrepeat 0
		     setactor[THISACTOR].yrepeat 0
	   }
   }
    
    ifvarg pipefire 0 setvar pipefire 0
	break



case LIZTROOP

	getactor[THISACTOR].statnum temp
	ifvare temp 1
	{
		ifspritepal 1 // frozen
			setactor[THISACTOR].mdflags 2
		else
		   setactor[THISACTOR].mdflags 0
	}
	
	ifvare monstatus -1 
	{
		//ifpdistl 10240 changespritestat THISACTOR 1
		//ifcansee 
		changespritestat THISACTOR 1
	}
	ifai AITROOPSHRUNK nullop
	else 
	ifvare goggles 1
		ifvare monstatus 1
	{
		cstat 257 
		sizeat 41 40 
	}
	ifaction ATROOPSUFFERING nullop else
		ifvare monstatus 2 cstat 0
		
	break


case MININUKE
	ifvarg countvar 5
	{
		spawn BIGEXPLOSION
		setvar countvar 0					
	}
	addvar countvar 1
	break


case OCTABRAIN

	getactor[THISACTOR].statnum temp
	ifvare temp 1
	{
		ifspritepal 1 // frozen
			setactor[THISACTOR].mdflags 2
		else
		   setactor[THISACTOR].mdflags 0
	}
	
	ifvare monstatus -1 
	{
		//ifpdistl 10240 changespritestat THISACTOR 1
		//ifcansee 
		changespritestat THISACTOR 1
	}
	getactor[THISACTOR].extra tempb
	ifvare goggles 1 { ifvarg tempb 0 cstat 257 else cstat 256 }
break


case RPG
case RPGNOAIM
case CPUDEV

	espawn ROCKETHALO
	setactorvar[RETURN].myspawner THISACTOR


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


	ifspawnedby MINIBOSS2 state randtraj
	findnearspritez LIGHTNINGBOLT 768 6144 spriteid
	ifvarn spriteid -1
	{
	  spawn EXPLOSION2
	  ifactor CPUDEV hitradius 1536 5 10 15 20
	  else
	  hitradius 1536 20 30 45 60
	  setactor[THISACTOR].picnum RPG
	  changespritestat THISACTOR 1
	}
	break


case RECON
	
	ifvare countvar 0 ifcansee
	{
		 changespritestat THISACTOR 1
		 setvar mval RECONVAL
		 ifvarg score 2500 ifrnd 64 cactor RECONDP
	     setvar countvar 1
	}
	ifvarg countvar 0 state monsterai
	state setholotarg
	state checkdart
	ifcansee ifrnd 1 ifrnd 64
	{
		  sound RPG_SHOOT
		  shoot RPG
	}
	getactor[THISACTOR].extra hp
	ifvarl hp 1 ifvare countvar 1
	{
		state dropcoins
		state addscore
		setvar countvar 2
	}
	state recontilt
	break


case BLASTER
case BLASTER2
	
	ifvare target -1
	{
		setvarvar spriteid THISACTOR
		state projectilehitscan
		
		ifvarn hitsprite -1 // attempt to acquire target
		{
			getactor[hitsprite].picnum temp
			ifvarn temp HOLOBOT ifvarn temp BARRIER
			{
				  getactor[hitsprite].statnum tempb
				  ifvare temp APLAYER setvar tempb 1
				  ifvare tempb 1
				  {
				     getactor[hitsprite].extra hp
				     ifvarg hp 0			       
				       setvarvar target hitsprite
				  }
			}
		}
					
	}
	ifvarn target -1
		state guideit	
	break

case BLASTER3

ifvare target -1
{
		setvarvar spriteid THISACTOR
		state projectilehitscan
		
		ifvarn hitsprite -1 ifvarvarn hitsprite hammo2 // attempt to acquire target
		{
		    getactor[hitsprite].picnum tempb
		    ifvare tempb APLAYER setvarvar target hitsprite
		     else
		   ifvare tempb HOLOBOT setvarvar target hitsprite
		     else
		   ifvare tempb BARRIER setvarvar target hitsprite
		     else
		   ifvare tempb ROTATEGUNALLY setvarvar target hitsprite
		}
			      
}		 			
else 
	state guideit	

break


case PIGCOP
case PIGCOPSTAYPUT 
case PIGCOPDIVE
case LIZTROOPSTAYPUT
case LIZTROOPDUCKING 
case LIZTROOPJETPACK
case LIZTROOPSHOOT
case LIZMAN
case LIZMANSTAYPUT 
case LIZMANJUMP 
case COMMANDER
case COMMANDERSTAYPUT
case DRONE
case NEWBEAST
case NEWBEASTSTAYPUT 
case NEWBEASTJUMP 
case NEWBEASTHANG
case TANK
case ROTATEGUN
case ROBOMAN
case MECH2

getactor[THISACTOR].statnum temp
ifvare temp 1
{
	ifspritepal 1 // frozen
		setactor[THISACTOR].mdflags 2
	else
	   setactor[THISACTOR].mdflags 0
}
	
	
ifvare monstatus -1 
	changespritestat THISACTOR 1
	
break


case EVILDUKE
  
  ifvare mtype 1
  {
	
  	ifvare goggles 1 // if goggles on...
	 {
		changespritestat THISACTOR 1
		setactor[THISACTOR].cstat 257
	 }

     else // if goggles off...
	 { 
			cstat 32768 
			changespritestat THISACTOR 0 
	 }	
   }

   break
   
case CACTUS
	ifvare mtype 2 killit
break

case ACCESSSWITCH
case ACCESSSWITCH2
ifvarn myspawner -1
{
	getactor[myspawner].picnum tilenum
	setactor[THISACTOR].picnum tilenum
}
break

case CAMERA1
getplayer[THISACTOR].newowner spriteid
ifvarvare spriteid THISACTOR
{
	ifvare mtype 1
	{
		setvar noreccam 1
		getactor[THISACTOR].x camxsaved
		getactor[THISACTOR].y camysaved
		getactor[THISACTOR].z camzsaved
		getactor[THISACTOR].ang camangsaved
		getactor[THISACTOR].sectnum camsectsaved
		setvar camhorizsaved 100
		setplayer[THISACTOR].newowner -1
	}
}
break

default
ifvare darthit 0
setvar NOCODE 1 else setvar NOCODE 0
break

endswitch

endevent

state setnuke

subvar nukepart 5
setvar nukehold 0
setvar nukecount 0
spawn DUKENUKE
sound LASERTRIP_ONWALL

ends

state useactions

ifvarn menutoggle 0 ifvarn menutoggle 4
{
	getplayer[THISACTOR].player_par temp
    addvar upresstime 1

    ifvarvare temp upresstime nullop else
	{
		ifvare menuitem 1 
		{  
			state healthcost
			ifvarvarl skillpoint cost nullop else // choose health upgrade
			{
				subvarvar skillpoint cost
				state upgradehealth
			}
		}
		ifvare menuitem 2
		{
			state holocost
			ifvarvarl skillpoint cost nullop else ifvarg holomult 2 // choose holobot health multiplier upgrade
			{
				subvarvar skillpoint cost
				state upgradeholohp
			}
		}

		ifvare menuitem 3 ifvarg nukepart 1
		{
			ifvarvarg weight MAXLOAD quote 207 else
			{
				subvar nukepart 2
				state buyammo
			}
		}

		ifvare menuitem 4
		{
			state legcost
		    ifvarvarl skillpoint cost nullop else ifvarl leglevel 4
		   // leg upgrade
			{
				subvarvar skillpoint cost
				state upgradelegs
			}
		}

		ifvare menuitem 5 
		{ 
			state dreductioncost
			ifvarvarl skillpoint cost nullop else ifvarg dreduction 10 // choose dreduction upgrade
			{
				subvarvar skillpoint cost
				state upgradedreduction
			}
		}


		ifvare menuitem 6
		{
			state limitcost
			
			ifvarvarl skillpoint cost nullop else ifvarl limits 4
			{
				subvarvar skillpoint cost
				state upgradelimit
			}
		}


		ifvare menuitem 7
		{
			state barriercost
			ifvarvarl skillpoint cost nullop else ifvarl barrierlevel 4 // choose barrier upgrade
			{
				subvarvar skillpoint cost
				state upgradebarrier
			}
		}
			
		ifvare menuitem 8 
		{
			state combocost
			ifvarvarl skillpoint cost nullop else ifvarl combolevel 5 // choose nuke combo upgrade
			{
				subvarvar skillpoint cost
				state upgradecombo
		    }
		}
			
		ifvare menuitem 9
		{
			state gogglecost
			ifvarvarl skillpoint cost nullop else ifvarl gogglelevel 3
			{
				   state upgradegoggles
				   subvarvar skillpoint cost
			}
		}
		
		ifvare menuitem 10 
		{
			ifvare menutoggle 1 setvar menutoggle 2
			else setvar menutoggle 1
		}
		
		ifvare menuitem 11
		{
			ifvare menutoggle 1 setvar menutoggle 3
			else setvar menutoggle 1
		}
	}

		setvarvar upresstime temp		
}

else
{
	ifvarg nukepart 4 
		ifvarg combolevel 2
			ifp pducking
	{
			getplayer[THISACTOR].player_par temp
			ifvarvare temp nukecount addvar nukehold 1 else setvar nukehold 0
			setvarvar nukecount temp addvar nukecount 1
			ifvarg nukehold 25 state setnuke
	}
	
}
ends


onevent EVENT_USE

state useactions

endevent


onevent EVENT_HOLODUKEON

setvar eventholodukeon 1
setvar RETURN -1

endevent


onevent EVENT_USEMEDKIT

getplayer[THISACTOR].i temp
getactor[temp].extra hp
getplayer[THISACTOR].firstaid_amount tempc
ifvarvarl hp maxhealth ifvarg tempc 0
{
	setvarvar tempb maxhealth
	subvarvar tempb hp // tempb now holds the amount you need to heal
	ifvarvarl tempc tempb // if there isn't enough medkit to heal completely
	{
		addvarvar pheal tempc // add what you have to player's health
		setplayer[THISACTOR].firstaid_amount 0 // and set medkit to zero
	}

	else // else if there is enough medkit for a full heal
	{
		subvarvar tempc tempb // subtract amount to be healed from medkit
		setplayer[THISACTOR].firstaid_amount tempc
		addvarvar pheal tempb // and set player to heal full
	}

	sound DUKE_USEMEDKIT
}
	


setvar RETURN -1

endevent

onevent EVENT_JUMP

setvar RETURN -1

endevent

onevent EVENT_PROCESSINPUT

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

ifvarn ONCAR 0 break

ifvarand bits 1
{
	
	getplayer[THISACTOR].player_par temp
	addvar jpresstime 1
	ifvare menutoggle 4
	{
		setvarvar jpresstime temp
		ifvare messagetime 0 ifvarn tipdisplay 1
		{
			setvar menutoggle 0
			setvar tipdisplay 0
			sound EXITMENUSOUND
		}
		break
	}
	
	ifp pjetpack nullop else
	{
	    getplayer[THISACTOR].jetpack_amount tempc
	    ifvarvare temp jpresstime ifvare doublejumpflag 0 nullop else
		{
			ifp ponground
			{
				setplayer[THISACTOR].jumping_counter MID
				ifvarg dodge 0
			    {
					setvar doublejumpflag 1
			    	addvar dodge 13
			    	sound DUKE_GRUNT
			    	subvar stamina 52
			    	ifvarl stamina 0 setvar stamina 0
		        }
		    }	
			else ifvare doublejumpflag 0 ifvarg stamina 65
			{
				setvar doublejumpflag 1 
				subvar stamina 52
				setplayer[THISACTOR].jumping_counter MID
				getplayer[THISACTOR].poszv tempb
				divvar tempb 5
				setplayer[THISACTOR].poszv tempb
				ifp pjetpack nullop else sound DUKE_GRUNT 
			}
			else ifvare doublejumpflag 1 ifvarvarn temp jpresstime ifvarg tempc 0
			{
				setvar doublejumpflag 2
				sound DUKE_JETPACK_ON
			}
			ifvare doublejumpflag 2
			{
				soundonce DUKE_JETPACK_IDLE
				
				ifvarg tempc 0
				{
					subvar tempc 1
					setplayer[THISACTOR].jetpack_amount tempc
		
					getplayer[THISACTOR].poszv tempb
					subvar tempb 400
					setplayer[THISACTOR].poszv tempb
					getplayer[THISACTOR].falling_counter tempb
					ifvarg tempb 10 subvar tempb 2
					else
					ifvarg tempb 0 subvar tempb 1
					setplayer[THISACTOR].falling_counter tempb
				}
			}
		}
	}
	setvarvar jpresstime temp
}
else
ifvarn menutoggle 0 
  ifvarand bits 4 
{
	getplayer[THISACTOR].player_par tempb
	ifvarvarn tempb upresstime addvar upresstime 1
    ifvarvare tempb upresstime nullop else
    {
		state useactions
		getplayer[THISACTOR].player_par upresstime
	}
}

ifvare noreccam 1 
{
	ifvarand bits 1 setvar noreccam 0
	ifvarand extbits 2 setvar noreccam 0
	ifvarand extbits 4 setvar noreccam 0
	ifvarand extbits 8 setvar noreccam 0
}


endevent


onevent EVENT_LOOKRIGHT

ifvarn ONCAR 0 { setvar RETURN -1 break }
ifvare noreccam 1 { setvar RETURN -1 break }

setvar RETURN -1
getplayer[THISACTOR].player_par temp
addvar mpresstime 1

ifvare menutoggle 4 
{
	setvarvar mpresstime temp
	ifvare messagetime 0 ifvare tipdisplay 1
	{
		setvar menutoggle 1
		setvar tipdisplay 0
		sound EXITMENUSOUND
	}
	break
}

ifvarvare temp mpresstime nullop else
{
	ifvare menutoggle 0 
	{
		setvar menutoggle 1
		getplayer[THISACTOR].ang mouseox
		getplayer[THISACTOR].horiz mouseoy
	}
	else setvar menutoggle 0
	sound EXITMENUSOUND
}

setvarvar mpresstime temp
endevent


onevent EVENT_QUICKKICK

ifvarn superkicking 0 setvar RETURN -1

ifp pshrunk nullop else
ifvarg leglevel 1 ifvare superkicking 0 ifvarg stamina 130 ifvare tipdisplay 0
{
	 subvar stamina 78
	 setvar temp 0
	 ifvarg fhold 1 setvar temp 1
	 ifvarg ftap 0 setvar temp 1
	 ifvarg btap 0 { setvar temp 1 setvar spinkick 1 getplayer[THISACTOR].ang dodgeang }
	 ifvarg bhold 0 { setvar temp 1 setvar spinkick 1 getplayer[THISACTOR].ang dodgeang }
	 getplayer[THISACTOR].somethingonplayer tempb
	 ifvarn tempb -1 setvar temp 0
	 ifvare temp 1
	 {
		setvar RETURN -1
		setvar superkicking 1
		ifvare dodge 0
		{
			getplayer[THISACTOR].ang dodgeang
			setvar dodge 10
		}
		getplayer[THISACTOR].horiz tempb
	  	ifvare hammo5 -1 setvarvar hammo2 tempb
	  	else
	  	ifvarvarl tempb hammo2 setvarvar hammo2 tempb // change goal horiz only if new one is lower
	  	ifvarl hammo3 10
	  	{
	  		addvar hammo3 20 // hammo3 stores the amount of kick (the amount to move the horiz up)
	  		addvar hammo4 20 // hammo4 stores the amount to move horiz back down (they move at diff rates)
  		}
	  	setvar hammo5 1 // this flag tells the player that the recoil state should be executed
  	}
	 
}

endevent


onevent EVENT_FIRE

ifvarg menutoggle 0 { setvar RETURN -1 break }
ifvare noreccam 1 { setvar RETURN -1 break }

getplayer[THISACTOR].curr_weapon temp

ifvare temp 11 
{
	getplayer[THISACTOR].kickback_pic tempb
	ifvare tempb 0
	{
		setplayer[THISACTOR].curr_weapon 6
		setvar temp 6
	}
}

switch temp
 case 0:
    ifvarn superkicking 0 setvar RETURN -1
    getplayer[THISACTOR].quick_kick tempc
    ifp pshrunk nullop else
 	ifvarg leglevel 1 ifvare superkicking 0 ifvare tempc 0 ifvarg stamina 130 ifvare tipdisplay 0
 	{
	 	setvar tempb 0
	 	subvar stamina 78
	 	ifvarg ftap 0 setvar tempb 1
	 	ifvarg fhold 1 setvar tempb 1
	 	ifvarg btap 0 { setvar tempb 1 setvar spinkick 1 getplayer[THISACTOR].ang dodgeang }
	 	ifvarg bhold 0 { setvar tempb 1 setvar spinkick 1 getplayer[THISACTOR].ang dodgeang }
	 	ifvare tempb 1
	 	{
		 	setvar RETURN -1
		 	setvar superkicking 1
		 	ifvare dodge 0
			{
				getplayer[THISACTOR].ang dodgeang
				setvar dodge 10
			}
	    	getplayer[THISACTOR].horiz tempb
	  		ifvare hammo5 -1 setvarvar hammo2 tempb
	  		else
	  		ifvarvarl tempb hammo2 setvarvar hammo2 tempb // change goal horiz only if new one is lower
	  		ifvarl hammo3 10
	  		{
	  			addvar hammo3 20 // hammo3 stores the amount of kick (the amount to move the horiz up)
	  			addvar hammo4 20 // hammo4 stores the amount to move horiz back down (they move at diff rates)
  			}
	  		setvar hammo5 1 // this flag tells the player that the recoil state should be executed
  		}
 	}
 case 1: state normalpistol break
 case 2: state normalshotgun break
 case 3: state normalchaingun break
 case 4: state normalrpg
	   break
 case 5: state normalpipebomb
		break
 case 6: state normalshrinker
       getplayer[THISACTOR].ammo_amount 6 tempb
	   subvar tempb 1
	   setplayer[THISACTOR].ammo_amount 11 tempb
	   break
 case 7: state normaldevastator
	   break
 case 8: state normaltrip break
 case 9: state normalfreezer break
 case 10: setvar pipefire 2
		break
 
endswitch

endevent

state killslime

getplayer[THISACTOR].somethingonplayer spriteid
ifvarn spriteid -1
{
	getinput[THISACTOR].bits tempc
	orvar tempc 4
	setinput[THISACTOR].bits tempc
}

ends

onevent EVENT_LOOKUP

setvar RETURN -1
ifvarn ONCAR 0 break
ifvarg menutoggle 0 break
ifvare noreccam 1 break

getplayer[THISACTOR].curr_weapon temp

ifvare temp 1
{
	state altpistol	
	getplayer[THISACTOR].ammo_amount 1 tempb
	ifvarg tempb 7
	{
		getplayer[THISACTOR].kickback_pic tempc
		ifvare tempc 0
		{
			subvar tempb 7
			setplayer[THISACTOR].ammo_amount 1 tempb
			setplayer[THISACTOR].kickback_pic 1
			state killslime
		}
				
	}
		
}

ifvare temp 2
{
	state altshotgun
	getplayer[THISACTOR].ammo_amount 2 tempc
	ifvarg tempc 1
	{
		getplayer[THISACTOR].kickback_pic tempb
		ifvare tempb 0 
		{
			setplayer[THISACTOR].kickback_pic 1
			subvar tempc 1
			setplayer[THISACTOR].ammo_amount 2 tempc
			state killslime
		}
	}
}

ifvare temp 3
{
	state altchaingun
	getplayer[THISACTOR].ammo_amount 3 tempc
	ifvarg tempc 0
	{
		getplayer[THISACTOR].kickback_pic tempb
		ifvare tempb 0
		{
			setplayer[THISACTOR].kickback_pic 1
			state killslime
		}
		
	}
}

ifvare temp 4
{
	state altrpg
	getplayer[THISACTOR].ammo_amount 4 tempb
	ifvarg tempb 1
	{
		getplayer[THISACTOR].kickback_pic tempc
		ifvare tempc 0 
		{ 
			subvar tempb 1
			setplayer[THISACTOR].ammo_amount 4 tempb
			setplayer[THISACTOR].kickback_pic 1
			state killslime
		}
	}
}

ifvare temp 5
{
	state altpipebomb
	getplayer[THISACTOR].ammo_amount 5 tempb
	ifvarg tempb 2
	{
		getplayer[THISACTOR].kickback_pic tempb
		ifvare tempb 0
			setplayer[THISACTOR].kickback_pic 1		
	}
}

ifvare temp 6 
{
	getplayer[THISACTOR].kickback_pic tempb
	ifvare tempb 0
    {
		setplayer[THISACTOR].curr_weapon 11
		getplayer[THISACTOR].ammo_amount 11 tempc
		ifvarg tempc 2
		{
			getplayer[THISACTOR].kickback_pic tempb
			ifvare tempb 0
			{
				  state altshrinker
				  setplayer[THISACTOR].kickback_pic 1
				  subvar tempc 2
				  setplayer[THISACTOR].ammo_amount 11 tempc
				  subvar tempc 1
				  setplayer[THISACTOR].ammo_amount 6 tempc
				  state killslime
			}
		}
	}
}

ifvare temp 7
{
	getplayer[THISACTOR].ammo_amount 7 tempb
	ifvarg tempb 0
	{
		getplayer[THISACTOR].kickback_pic tempb
		ifvare tempb 0
		{
			state altdevastator
			setplayer[THISACTOR].kickback_pic 1
			getplayer[THISACTOR].hbomb_hold_delay tempc
			ifvare tempc 0 setvar tempc 1 else setvar tempc 0
			setplayer[THISACTOR].hbomb_hold_delay tempc
			state killslime
		}
	}
}

ifvare temp 8
{
	setvar tempc 0
	state checkhitscan
	ifvarn hitwall -1
	{
		espawn NOTHING
		setactor[RETURN].x hitx
		setactor[RETURN].y hity
		setactor[RETURN].z hitz
		ldist xydist THISACTOR RETURN
		ifvarl xydist 256
		{
			state altrip
			getplayer[THISACTOR].ammo_amount 8 tempb
			ifvarg tempb 0 ifvare dtripflag 0
			{
				getplayer[THISACTOR].kickback_pic tempb
				ifvare tempb 0 
				{
					setplayer[THISACTOR].kickback_pic 1
					setvar dtripflag 26
				}
			}
		} // end of ifvarl xydist 1024 condition
	} // end of ifvarn hitwall -1 condition
}

ifvare temp 9 
{
	state altfreezer
	getplayer[THISACTOR].ammo_amount 9 tempc
	ifvarg tempc 2
	{
		getplayer[THISACTOR].kickback_pic tempb
		ifvare tempb 0
		{
			subvar tempc 2
			setplayer[THISACTOR].ammo_amount 9 tempc
			setplayer[THISACTOR].kickback_pic 1
			setvar railflag 1
			state killslime
		}		
	}

}

ifvare temp 11
{
	getplayer[THISACTOR].ammo_amount 11 tempc
	ifvarg tempc 1
	{
		getplayer[THISACTOR].kickback_pic tempb
		ifvare tempb 0
		{
			state altshrinker
			setplayer[THISACTOR].kickback_pic 1
			subvar tempc 1
			setplayer[THISACTOR].ammo_amount 11 tempc
			subvar tempc 1
			setplayer[THISACTOR].ammo_amount 6 tempc
			state killslime
		}
	}
		 
}


endevent

state scorchfloor

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

ends

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

setvarvar temp x
subvarvar temp hitx
mulvarvar temp temp
	
setvarvar tempb y
subvarvar tempb hity
mulvarvar tempb tempb
	
addvarvar temp tempb
sqrt temp temp

setvarvar xydist temp
ends

state rocketdeath
	ifvarn immunity 2
	{
		setvar countvar 0
		getactor[THISACTOR].ang holoweap
		whilevarn countvar 24
		{
			addvar countvar 1
			ifactor HLROCKET addvar countvar 2
			randvar zdist 8192 subvar zdist 6144 
			ifrnd 128 ezshoot zdist NEWSCRAP3 else 
				ezshoot zdist NEWSCRAP6
			ifrnd 128
			setthisprojectile[RETURN].trail SMALLSMOKE
			randvar temp 128
			addvar temp 160
			setthisprojectile[RETURN].vel temp
			addvar holoweap 85
			ifactor HLROCKET addvar holoweap 170
			setactor[THISACTOR].ang holoweap
		}
		ifrnd 64 spawn BURNING else ifrnd 64 spawn BURNING2
	}
	getactor[THISACTOR].htmovflag temp
	ifvare temp 0 break
	// hit something
	addvar temp 16384
    ifvarl temp 16384 ifvarg temp -1 // hit a sprite
        break 
    
    getactor[THISACTOR].htmovflag hitwall
	andvar hitwall 49152
	ifvare hitwall 32768
	{
		getactor[THISACTOR].htmovflag hitwall
		andvar hitwall 16383 // temp is now the wall ID that it hit
		getwall[hitwall].overpicnum temp
		ifvare temp BIGFORCE break
		ifvare temp W_FORCEFIELD break
		getwall[hitwall].cstat temp
		ifvarand temp 128 { setvar RETURN 0 break } // break on transparent
		//ifvarand temp 16 { setvar RETURN 0 break } // break on masking
		setvarvar hammtarg hitwall
		getactor[THISACTOR].z z
		subvar z 3072
		setactor[THISACTOR].z z
		setvarvar spriteid THISACTOR
		state projectilehitscan
		setvar temp 0
		ifvarn hitsprite -1 setvar temp 1
		ifvarvare hitwall hammtarg setvar temp 1
		ifvare temp 1
		{
			addvar z 6144
			setactor[THISACTOR].z z
			state projectilehitscan
			setvar temp 0
			ifvarn hitsprite -1 setvar temp 1
			ifvarvare hitwall hammtarg setvar temp 1
			ifvare temp 1
			{
				subvar z 3072
				setactor[THISACTOR].z z
				state projectilehitscan
				setvarvar hitwall hammtarg
				getwall[hitwall].x x
				getwall[hitwall].y y
				getwall[hitwall].point2 tempb
				
				getwall[tempb].x mx
				getwall[tempb].y my
				subvarvar x mx
				subvarvar y my
			    getangle z x y
			    addvar z 512
			    setactor[THISACTOR].ang z
			    getactor[THISACTOR].x x
			    getactor[THISACTOR].y y
			    state pythagoras
			    ifvarl xydist 512
		    	{
				    espawn SCORCH
				    getactor[THISACTOR].xrepeat x
				    ifvarl x 14 setactorvar[RETURN].initx x
				    setactor[RETURN].x hitx
				    setactor[RETURN].y hity
				    setactor[RETURN].z hitz
				    
				    subvar z 1024
					cos xvel z
					sin yvel z
					shiftvarr xvel 10
					shiftvarr yvel 10
					setvar zvel 0
					movesprite RETURN xvel yvel zvel CLIPMASK0 temp
				    
				    setvar temp 144
					ifrnd 128 orvar temp 4
					ifrnd 128 orvar temp 8
					setactor[RETURN].cstat temp
					setactorvar[RETURN].target hitwall
				}
			}
		}
		break
	}
	setvarvar spriteid THISACTOR
	state projectilehitscan
	ifvarl hitsector 0 break
	ifvarg hitsector 4095 break

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

state dartdeath

getactor[THISACTOR].htmovflag temp
ifvarn temp 0
{
	addvar temp 16384
    ifvarl temp 16384 ifvarg temp -1 // hit a sprite
    {
	    getactorvar[temp].darthit darthit
	    ifvare darthit 0
	    {
		    globalsound EXITMENUSOUND
		    quote 150
		    setactorvar[temp].darthit 260
	    }
    } else
    {
	    getactor[THISACTOR].htmovflag hitwall
		andvar hitwall 49152
		ifvare hitwall 32768
		{
			getactor[THISACTOR].htmovflag hitwall
			andvar hitwall 16383 // temp is now the wall ID that it hit
			getwall[hitwall].overpicnum temp
			ifvare temp BIGFORCE break
			ifvare temp W_FORCEFIELD break
		    setvarvar spriteid THISACTOR
		    state projectilehitscan
		    espawn WALLDART
		    globalsound EXITMENUSOUND
		    setactor[RETURN].x hitx
		    setactor[RETURN].y hity
		    setactor[RETURN].z hitz
		    break
	    }
	    setvarvar spriteid THISACTOR
		state projectilehitscan
		ifvarl hitsector 0 break
		ifvarg hitsector 4095 break
	
		getceilzofslope hitsector hitx hity temp
	    setvarvar z hitz
	    subvarvar z temp
	    shiftvarr z 8
	    subvar z 1
	    setvarvar mz z
	    getflorzofslope hitsector hitx hity z
	    setvarvar temp hitz
	    subvarvar z temp
	    shiftvarr z 8
	    subvar z 1
	    
	    ifvarl z 1
	    {
		    getsector[mysector].floorstat tempb
		    ifvarand tempb 1 break else ifvarand tempb 2 break else
		    {
			    espawn WALLDART
			    globalsound EXITMENUSOUND
			    setactor[RETURN].x hitx
			    setactor[RETURN].y hity
			    setactor[RETURN].z hitz
		    }
		    
		} else
	    ifvarl mz 0 
	    {
		   getsector[mysector].ceilingstat tempb
		   ifvarand tempb 1 break else ifvarand tempb 2 break else
		   {
			   espawn WALLDART
			   globalsound EXITMENUSOUND
			   setactor[RETURN].x hitx
			   setactor[RETURN].y hity
			   setactor[RETURN].z hitz
		   }
    	}
		    
	    
	}
}
ends

state cannondeath

getactor[THISACTOR].htmovflag temp
	ifvare temp 0 
	{
		setvar RETURN 0 
		sound PIPEBOMB_EXPLODE 
		spawn EXPLOSION2  
		setvarvar temp pdamage
	    mulvar temp 2
	    hitradiusvar 1792 pdamage pdamage temp temp
	    spritepal 4
	    debris SCRAP1 5
	    debris SCRAP3 5
	    debris SCRAP6 5
	    break
	}
	// hit something
	addvar temp 16384
    ifvarl temp 16384 ifvarg temp -1 // hit a sprite
    {
	    setactor[temp].htpicnum RPG
	    getactorvar[temp].monstatus tempc
	    ifvarn tempc -1
	    {
		    switch pdamage
		    case 40 setvar tempb 50 break
		    case 60 setvar tempb 75 break
		    case 80 setvar tempb 100 break
		    case 100 setvar tempb 130 break
		    case 120 setvar tempb 165 break
		    case 140 setvar tempb 200 break
		    case 160 setvar tempb 250 break
		    case 180 setvar tempb 300 break
		    case 200 setvar tempb 350 break
		    case 220 setvar tempb 400 break
		    case 240 setvar tempb 450 break
		    case 260 setvar tempb 500 break
		    endswitch
		    getactor[temp].extra hp
		    ifvarvarg tempb hp setvar RETURN 1 else
		    setvar RETURN 0
    	}
    	else setvar RETURN 0
	    
    } else
    setvar RETURN 0
    ifvare RETURN 0 
    {
	    sound PIPEBOMB_EXPLODE 
	    spawn EXPLOSION2 
	    setvarvar temp pdamage
	    mulvar temp 2
	    hitradiusvar 1792 pdamage pdamage temp temp
	    spritepal 4
	    debris SCRAP1 5
	    debris SCRAP3 5
	    debris SCRAP6 5
	}
ends

onevent EVENT_KILLIT

getactor[THISACTOR].picnum tilenum
switch tilenum

case SPIDERX
	subvar spiders 1
	setvar RETURN 0
break

case RPG
case RPGNOAIM
case HLROCKET
	state rocketdeath
	setvar RETURN 0
break

case CANNONBALLPROJ
state cannondeath
break

case BOMBDART
state dartdeath
setvar RETURN 0
break
	
default	
setvar RETURN 0
break

endswitch


endevent

gamevar randomstart 0 0

onevent EVENT_LOADACTOR

readgamevar randomstart
addvar randomstart 1
andvar randomstart 65535
setvarvar temp randomstart
xorvar temp 43690
whilevarn temp 0
{
ifrnd 1 { }
subvar temp 1
}
savegamevar randomstart

endevent