
include dtdefs.con
include dtuser.con
include dtprojectiles.con
include dtvars.con
include dtgore.con
include dtstatesevents.con

spriteshadow SKYCAR_FLY
spriteshadow SKYCAR_CRASHED
spriteshadow HOLOBOT
spriteshadow ROTATEGUNALLY
spriteshadow NUKECOIN
spriteshadow BOSSCOIN
spriteshadow SKILLCOIN
spriteshadow INVENCOIN
spriteshadow AMMOCOIN
//spriteshadow MAGMA
spriteshadow BFG
//spriteshadow RPG
//spriteshadow RPGNOAIM
//spriteshadow HLROCKET
spriteshadow NOVA
spriteshadow POKEBALL
//spriteshadow FLESH1 
//spriteshadow FLESH1G 
//spriteshadow FLESH2 
//spriteshadow FLESH2G 
//spriteshadow FLESH3 
//spriteshadow FLESH3G 
//spriteshadow BRAIN 
//spriteshadow BRAING 
//spriteshadow SPINE 
//spriteshadow SPINEG 
//spriteshadow JIBSHOOTER 
//spriteshadow TROOPHEAD 
//spriteshadow TROOPHEADG 
//spriteshadow TROOPARM 
//spriteshadow TROOPARMG 
//spriteshadow TROOPLEG 
//spriteshadow TROOPLEGG 
//spriteshadow LIZHEAD 
//spriteshadow LIZHEADG 
//spriteshadow LIZARM 
//spriteshadow LIZARMG 
//spriteshadow LIZLEG 
//spriteshadow LIZLEGG 
//spriteshadow PIGHEAD 
//spriteshadow PIGHEADG 
//spriteshadow PIGLOWER 
//spriteshadow PIGLOWERG 
//spriteshadow PIGUPPER 
//spriteshadow PIGUPPERG 
//spriteshadow PIGUPPER2 
//spriteshadow PIGUPPER2G 
//spriteshadow PIGLOWER2 
//spriteshadow PIGLOWER2G 


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

state smokearound

espawn NEWSMOKE
setactor[RETURN].pal 8
setvar loop 0
getactor[THISACTOR].ang angvar
whilevarn loop 16
{
  addvar angvar 128
  setactor[THISACTOR].ang angvar
  randvar zdist 512
  mulvar zdist -1
  zshoot zdist SMOKESHOT
  addvar loop 1
  break
}

ends

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

state shelleject2
espawn SHOTGUNSHELL
setactor[RETURN].xrepeat 8
setactor[RETURN].yrepeat 8
getactor[THISACTOR].ang angvar
addvar angvar 512
setactor[RETURN].ang angvar
randvar temp 32
addvar temp 32
setactor[RETURN].xvel temp
ends

move INIT

state holosphereon
 
sound NITEVISION_ONOFF
setvar holosphere 780
espawn HOLOSPHERE
setactorvar[RETURN].myspawner THISACTOR

ends

action SHELLROLLING -1 2 1 1 6
action SHELLSTOPPED -1 1 1 1 1

move SHELLROLL1 48
move SHELLBOUNCE 48 -20
move SHELLBOUNCE2 48
move SHELLROLL2	32
move SHELLROLL3 16
move SHELLSTOP

state shellcode
fall

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

ifmove SHELLBOUNCE ifcount 6
{
	move SHELLBOUNCE2 geth
	resetcount
}

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

  
ifmove SHELLROLL1 ifcount 22 { move SHELLROLL2 geth resetcount }
ifmove SHELLROLL2 ifcount 16 { move SHELLROLL3 geth resetcount }
ifmove SHELLROLL3 
  ifcount 12
    ifrnd 32 
{
     move SHELLSTOP
     ifactor 2534 action SHELLSTOPPED
     ifrnd 128 cstat 388 //132
      
     getactor[THISACTOR].x x
     getactor[THISACTOR].y y
     getactor[THISACTOR].sectnum mysector
     getflorzofslope mysector x y z // z is the return var
     setactor[THISACTOR].z z
}

ifnotmoving
{
	getactor[THISACTOR].ang angvar
	addvar angvar 1024
	randvar temp 256
	ifrnd 128 mulvar temp -1
	addvarvar angvar temp
	setactor[THISACTOR].ang angvar
}

ifhitweapon
{
	ifactor 2534 espawn SHELL else
	espawn SHOTGUNSHELL 
	randvar temp 128
	setactor[RETURN].xvel temp
	killit
}

ifspawnedby APLAYER { ifcount 1560 killit }
else
ifcount 260 killit


ends

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

useractor notenemy SHOTGUNSHELL 0 state shellcode enda


useractor notenemy TREASURE_CHEST 0
fall

 getactor[THISACTOR].x x
 getactor[THISACTOR].y y
 getactor[THISACTOR].z z
 
ifmove 0
{
	move INIT
	sizeat 40 40
	espawn INVISBEAST
	setactorvar[RETURN].myspawner THISACTOR
	setvarvar myspawner RETURN
	getactor[THISACTOR].z monstz
	subvar monstz 4096
}

ifrnd 32
{
	  randvar temp 256
	  ifrnd 128 mulvar temp -1
	  setvarvar mx x
	  addvarvar mx temp
	  randvar temp 256
	  ifrnd 128 mulvar temp -1
	  setvarvar my y
	  addvarvar my temp
	  
	  espawn TRANSPORTERSTAR
	  setactor[RETURN].xrepeat 6
	  setactor[RETURN].yrepeat 6
	  setactor[RETURN].pal 8
	   
	  setactor[RETURN].x mx
	  setactor[RETURN].y my
	  setactor[RETURN].z monstz
}

ifvare goggles 1 
{
	cstat 0
	ifp palive
		//ifcansee
			ifpdistl 844
	{
		addvar score 100
		randvar temp 3
		addvar temp 2
		addvarvar nukepart temp
		ifvarg nukepart 30 setvar nukepart 30
		randvar temp 2
		addvar temp 1
		addvarvar skillpoint temp
		globalsound TREASURE_GRAB
		palfrom 48 0 48 48
		espawn TRANSPORTERSTAR
        getactor[THISACTOR].z z
        subvar z 8192
        setactor[RETURN].z z
        setactor[RETURN].xrepeat 96
        setactor[RETURN].yrepeat 96
		killit
	}
}
else cstat 32768

ifvarand tipfield 2048 nullop else
ifcansee ifvare tipdisplay 0 ifp palive ifvare ONCAR 0
{
	// FIRST TREASURE CHEST
	setvar menutoggle 4
	setvar tipdisplay 2048
	orvar tipfield 2048
	setvar messagetime 26
	globalsound EXITMENUSOUND
}

enda

state muzzflashstate
ifvare countvar 0
{
	setvar countvar 1
	sizeat 16 16 
	ifrnd 128 cstat 2 else cstat 6 
	getactor[THISACTOR].owner spriteid
	ifvare spriteid -1 killit
	getactor[spriteid].x x
	getactor[spriteid].y y
	getactor[spriteid].ang angvar
	setvarvar mx x
	addvar mx 512
	rotatepoint x y mx y angvar temp my
	setactor[THISACTOR].x temp
	setactor[THISACTOR].y my
}
ifactioncount 3 killit
ends

action MUZZLEFLASHFRAMES 0 3 1 1 4

useractor notenemy MUZZLEFLASH 0 MUZZLEFLASHFRAMES 
state muzzflashstate
enda

useractor notenemy MUZZLEFLASHLOW 0 MUZZLEFLASHFRAMES 
state muzzflashstate
enda

state freezebomb

hitradius PIPEBOMBRADIUS 2 2 2 2
setvar loop 0
whilevarn loop 5
{
	addvar loop 1
	randvar angvar 2047
	setactor[THISACTOR].ang angvar
	randvar zdist 5120
	mulvar zdist -1
	ezshoot zdist CHILLBLAST
	setactor[RETURN].owner myspawner
}
ends

useractor notenemy ICEPIPE
ifvare countvar 0 { getactor[THISACTOR].owner myspawner cstat 32768 }
addvar countvar 1
state freezebomb
ifvarg countvar 77 killit
soundonce CHILLING
enda

move CHILLMOVE
useractor notenemy CHILLTRAIL 0
ifmove 0 { sizeat 20 20 move CHILLMOVE }
sizeto 0 0
enda

action NTFRAMES -1   3   1   1   3
useractor notenemy NOVATRAIL 0
ifaction 0
{
	action NTFRAMES
 	cstat 514
 	sizeat 64 64
 	getactor[THISACTOR].z z
 	addvar z 256
 	setactor[THISACTOR].z z
}

ifactioncount 3 killit

enda

spritenoshade RAILHIT
action RAILFRAMES -1 6 1 1 4
move RAILMOVE 32

useractor notenemy RAILHIT TOUGH RAILFRAMES

ifmove 0
{
	move RAILMOVE faceplayer
	ifvare countvar 0
 	{
	 	cstator 128
		ifrnd 128 cstator 4
		sizeat 24 24
	}
 	else 
    {
	    ifvare mtype 0
	    {
	   		switch pdamage
	   		case 40 hitradius 2560 2 4 6 8 break
	   		case 50 hitradius 2560 3 6 9 12 break
	   		case 60 hitradius 2560 4 7 11 16 break
	   		case 70 hitradius 2560 5 8 12 18 break
	   		case 80 hitradius 2560 5 9 14 21 break
	   		case 90 hitradius 2560 6 10 16 24 break
	   		case 100 hitradius 2560 7 12 18 27 break
	   		case 110 hitradius 2560 8 13 19 30 break
	   		case 120 hitradius 2560 9 14 20 33 break
	   		case 130 hitradius 2560 10 15 22 36 break
	   		case 140 hitradius 2560 11 16 24 39 break
	   		case 150 hitradius 2560 12 18 26 42 break
	   		case 160 hitradius 2560 12 19 28 44 break
	   		case 170 hitradius 2560 13 21 30 46 break
	   		case 180 hitradius 2560 13 22 32 48 break
	   		case 190 hitradius 2560 14 23 34 50 break
	   		case 200 hitradius 2560 14 24 36 52 break
	   		case 220 hitradius 2560 16 26 42 56 break
	   		case 240 hitradius 2560 18 28 46 60 break
	   		case 260 hitradius 2560 20 32 50 70 break
	   		endswitch
   	     }
   	     else ifvare mtype 1 hitradius 2560 2 4 6 8
   	     else ifvare mtype 2 hitradius 2560 4 8 12 18
   
   		ifcansee flash
   		ifvare countvar 6 sound BOOM
   }
}


ifactioncount 6 killit
ifspawnedby NOVABLAST
{
  	randvar temp 2047
  	setactor[THISACTOR].ang temp
  	ifvare menutoggle 0 sleeptime 0
}
else
ifvarand tipfield 1024 nullop else
ifcount 6
  ifvare tipdisplay 0 ifp palive ifvare ONCAR 0
{
	// FIRST RAILGUN SHOT
	setvar menutoggle 4
	setvar tipdisplay 1024
	orvar tipfield 1024
	setvar messagetime 26
	globalsound EXITMENUSOUND
}
enda


useractor notenemy NOVABLAST 0
ifmove 0
{ 
	move RAILMOVE 
	cstat 32768
  	getactor[THISACTOR].z z
  	subvar z 4096
  	setactor[THISACTOR].z z
}

ifrnd 128
{
	addvar countvar 6
	espawn RAILHIT
	setactorvar[RETURN].countvar countvar
	setactorvar[RETURN].mtype mtype
	setactor[RETURN].xrepeat countvar
	setactor[RETURN].yrepeat countvar
	setactor[RETURN].cstat 146
}

else
{
	espawn RAILHIT
	setactorvar[RETURN].countvar 1
	setactorvar[RETURN].mtype mtype
	setactor[RETURN].xrepeat countvar
	setactor[RETURN].yrepeat countvar
	setactor[RETURN].cstat 658
}
ifcount 22 killit
enda

useractor notenemy FIRESPHERE 0
ifmove 0
{
	move CHILLMOVE
	sizeat 48 48
	cstat 642
	getactor[THISACTOR].z z
	addvar z 12288
	setactor[THISACTOR].z z
	
}
getactor[THISACTOR].cstat temp
ifvare temp 642 cstat 32768
else cstat 642
getactor[THISACTOR].ang angvar
addvar angvar 123
setactor[THISACTOR].ang angvar
ifcount 26 { sizeto 0 0 sizeto 0 0 }
else
{
	sizeto 128 128
	sizeto 128 128
	sizeto 128 128
	sizeto 128 128
}
enda

useractor notenemy HOLOSPHERE 0
ifvare countvar 0
{
	setvar countvar 1
	sizeat 72 72
	cstat 642
}
 
 ifvare holosphere 0 killit
 getactor[myspawner].x x
 getactor[myspawner].y y
 getactor[myspawner].z z
 updatesectorz x y z temp
 ifvarn temp -1
 changespritesect THISACTOR temp
 setactor[THISACTOR].x x
 setactor[THISACTOR].y y
 setactor[THISACTOR].z z
 
enda

spritenoshade LIFEBAR
useractor notenemy LIFEBAR 0

ifmove 0
{
	move INIT faceplayer
	sizeat 50 10
	cstat 0
	getactor[myspawner].extra hitsprite // stores the monster's initial hitpoints
	getactorvar[myspawner].mval mval
	ifvarl mval 1 killit
}

getactor[myspawner].statnum temp
ifvare temp 1024 killit

ifvarg gogglelevel 0
{
	ifpdistg 8192
	{
		getactorvar[myspawner].scanned scanned
		ifvare scanned 1 cstat 0 else cstat 32768
	}
	else
		ifp pfacing
	   		 cstat 0 
	    
	else cstat 32768
}
else cstat 32768

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

// bosses will require extra height
getactor[myspawner].picnum tilenum
switch tilenum
case BOSS1
case BOSS2
case BOSS4
subvar z 8192 
break

case MECH1
case MECH2
case MINIBOSS2
case MINIBOSS4
subvar z 6144 break

case ROBOMAN
subvar z 2048 break

case EVILDUKE
ifvare goggles 0
{
	getactorvar[myspawner].mtype temp
	ifvare temp 1 cstat 32768
}
break
case NEWBEAST
ifvare goggles 0
{
	getactorvar[myspawner].mtype temp
	ifvare temp 3 cstat 32768
}
break
case INVISEGG
case SPIDERX
ifvare goggles 0 cstat 32768
break
case LIZTROOP
ifvare goggles 0
{
	getactor[myspawner].cstat temp
	ifvarn temp 257 cstat 32768
}
break

case BOSS3
subvar z 8192
getactor[myspawner].cstat temp
ifvarand temp 256 nullop else cstat 32768
break

endswitch

getactor[myspawner].yrepeat temp
mulvar temp 384
subvarvar z temp
updatesectorz x y z mysector

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


getactor[myspawner].extra temp
ifvarvarg temp hitsprite setvarvar hitsprite temp
ifvarl temp 1 killit
ifvarvarl temp hp { spritepal 6 resetcount }
else ifcount 2 
{
	ifvare immunity 0 spritepal 10 else
	ifvarand immunity 1 spritepal 12 // bullet immune
	else ifvarand immunity 2 spritepal 7 // explosive immune
	else ifvarand immunity 4 spritepal 4 // kick immune
	else ifvarand immunity 8 { spritepal 6 setactor[THISACTOR].shade 12 } // elemental immune
}

setvarvar hp temp

setvarvar tempb hitsprite
divvar tempb 50
ifvarl tempb 1 setvar tempb 1
divvarvar temp tempb
ifvare tilenum SPIDERX divvar temp 2 // to prevent bar from being too long
ifvarl temp 1 setvar temp 1
setactor[THISACTOR].xrepeat temp

enda

useractor notenemy SMOKER 0

ifvare countvar 0     
{ 
	ifspawnedby SMOKEBOMB setvar mtype 1
	state smokearound
	setvar hammo2 128
	setvar hammo4 0
	setvar countvar 1
	getactor[THISACTOR].ang angvar
	
}
ifpdistl 8192 ifvare goggles 0
{
	soundonce STEAM_HISSING
	getplayer[THISACTOR].i spriteid
	ldist xydist THISACTOR spriteid
	mulvar xydist -1
	addvar xydist 8192
	ifvarl countvar 128
	{
		setvarvar hammo3 countvar
		mulvar hammo3 -1
		addvar hammo3 256
		divvarvar xydist hammo3
	}
		
	else ifvarl countvar 260 divvar xydist 128
	else 
	{
		ifvare hammo2 0 setvar hammo2 1
		divvarvar xydist hammo2
		addvar hammo2 1
	}
	ifvarg xydist 64 setvar xydist 64
	ifvare mtype 1 setplayer[THISACTOR].pals 0 18 else setplayer[THISACTOR].pals 0 48
	ifvare mtype 1 setplayer[THISACTOR].pals 1 64 else setplayer[THISACTOR].pals 1 48
	ifvare mtype 1 setplayer[THISACTOR].pals 2 18 else setplayer[THISACTOR].pals 2 48
	setplayer[THISACTOR].pals_time xydist
	ifvarg hammo4 13
	{
		setvar hammo4 0
		addphealth -1
		ifrnd 96 soundonce DUKE_LONGTERM_PAIN
	}
	addvar hammo4 1
}
	
addvar countvar 1
ifcount 130 { state smokearound resetcount }

ifvare countvar 388 killit
enda



useractor notenemy LSHOOTER 0

getactorvar[target].immunity immunity
ifvarand immunity 8 { killit break }
getactor[target].x mx
getactor[target].y my
getactor[target].z mz
espawn LIGHTNING_TRAIL2
setactor[RETURN].x mx
setactor[RETURN].y my
setactor[RETURN].z mz
killit
enda

useractor notenemy DTRIP TOUGH 

getplayer[THISACTOR].i spriteid
sound RPG_SHOOT

ifvare mtype 1
{
	
 	eshoot HLROCKET
 	setactorvar[RETURN].countvar 7
// 	setactor[RETURN].owner spriteid
// 	setactorvar[RETURN].target hitsprite
// 	setthisprojectile[RETURN].extra 300
// 	setthisprojectile[RETURN].hitradius 3072
// 	setthisprojectile[RETURN].spawns BIGEXPLOSION
	killit
}
eshoot RPGNOAIM 
setactor[RETURN].owner spriteid
setthisprojectile[RETURN].extra 200
setthisprojectile[RETURN].hitradius 3072
setthisprojectile[RETURN].spawns BIGEXPLOSION
	
killit 

enda

useractor notenemy GOOSPLAT 0

fall
spritepal 2
ifvare countvarb 0 sizeat 8 8 
ifcount 27 nullop else sizeto 32 32
iffloordistl 16 cstat 34 else cstat 18
ifvare countvarb 8
{
	espawn STICKYFIRE
	getactor[RETURN].x mx
	getactor[RETURN].y my
	randvar temp 192
    ifrnd 128 addvarvar mx temp else subvarvar mx temp
    randvar temp 192
	ifrnd 128 addvarvar my temp else subvarvar my temp
	setactor[RETURN].x mx
	setactor[RETURN].y my
	setvar countvarb 0
}
addvar countvarb 1

ifcount 130 sizeto 0 0

enda

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

useractor notenemy STICKYFIRE 0

setvar fireinmap 8

ifcount 1 nullop
  else 
    ifcount 0
	{
		ifrnd 128 action STICKYBURN else action STICKYBURN2
    	ifrnd 128 soundonce FIRE_CRACKLE
    	cstator 130
    	ifrnd 128 cstator 4
		randvar temp 10
		switch temp
		case 0: sizeat 2 5 break
    	case 1: sizeat 2 4 break
		case 2: sizeat 4 4 break
		case 3: sizeat 3 6 break
		case 4: sizeat 5 6 break
		case 5: sizeat 4 8 break
		case 6: sizeat 7 8 break
		case 7: sizeat 5 10 break
		case 8: sizeat 8 10 break
		case 9: sizeat 12 12 break
		case 10: sizeat 10 12 break
    	endswitch
		ifspawnedby GOOSPLAT setvar mtype 1

		ifvarg mtype 1
		{
			getactor[THISACTOR].xrepeat temp
			mulvar temp 2
			setactor[THISACTOR].xrepeat temp
			getactor[THISACTOR].yrepeat temp
			mulvar temp 2
			setactor[THISACTOR].yrepeat temp
		}
		ifvarn myspawner -1
		{
			randvar tempb 9216
		  	getactor[myspawner].z mz
		   	subvarvar mz tempb
		  	setactor[THISACTOR].z mz
	  	}
	}

ifvarn myspawner -1 ifvarg countvar 5
{
	setvar countvar 0
	getactor[myspawner].statnum temp
	ifvare temp 1024 setvar myspawner -1 else
	{
		getactor[myspawner].picnum temp
		ifvarvarn temp monstatus setvar myspawner -1 else
		{
			getactor[myspawner].x mx
			getactor[myspawner].y my
			randvar temp 128
		    ifrnd 128 addvarvar mx temp else subvarvar mx temp
		    randvar temp 128
			ifrnd 128 addvarvar my temp else subvarvar my temp
			setactor[THISACTOR].x mx
			setactor[THISACTOR].y my
		}
	}
}
addvar countvar 1

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

action GOOSPLASHFRAMES 0 6 1 1 6

useractor notenemy GOOSPLASH 0 GOOSPLASHFRAMES

cstat 2
spritepal 2
sizeat 40 40
ifactioncount 6 killit

enda

action BIGEXPLODE -10 24 1 1 4

useractor notenemy BIGEXPLOSION 0 BIGEXPLODE

sizeat 192 192
cstator 128

ifactioncount 24
{
   ifspawnedby MININUKE nullop else
   {
	   espawn NEWSMOKE
	   setactor[RETURN].xrepeat 128
	   setactor[RETURN].yrepeat 128
   }
   killit
}

   
enda

action BIGBURN -25 13 1 1 15
move MOVEFIRE 192

useractor notenemy BIGFIRE 0 BIGBURN
fall
ifcount 300 nullop else ifcount 16 setvar fireinmap 8

ifcount 1 nullop else
{
	cstat 32768
	sizeat 128 128
}

ifmove 0 ifcount 16
{
	cstat 130
	move MOVEFIRE geth
}
			
soundonce FIRE_CRACKLE
ifcount 260
	sizeto 0 0
else ifrnd 8 spawn LIGHTNING_TRAIL2
	
enda

spritenoshade RAILTRAIL
action RAILTRAILFRAMES -2 6 1 1 4
useractor notenemy RAILTRAIL TOUGH RAILTRAILFRAMES

ifvare countvar 0
{
	cstator 130
	ifrnd 128 cstator 4
	ifrnd 128 cstator 8
	sizeat 3 3
}

setvar countvar 1


ifactioncount 6 killit

enda


spritenoshade RAILTRAIL2
action RAILTRAILFRAMES2 -3 6 1 1 4

useractor notenemy RAILTRAIL2 TOUGH RAILTRAILFRAMES2

ifvare countvar 0
{
	cstator 130
	ifrnd 128 cstator 4
	ifrnd 128 cstator 8
	sizeat 3 3

	setvarvar spriteid THISACTOR

	state actorhitscan
	ifvarn hitsprite -1
	{
		ldist temp hitsprite THISACTOR
		getactorvar[hitsprite].railed railed
		ifvarl temp 312 ifvare railed 0
		{
			getactor[hitsprite].htpicnum hammo2
			getactor[hitsprite].htextra hammo3
			ifvare hammo2 RAILSLUG ifvarg hammo3 0 break
  
			getactor[hitsprite].cstat tempc

			ifvarn tempb BARRIER ifvarn tempc 2
			{
				setactor[hitsprite].htpicnum RAILSLUG
				setactor[hitsprite].htextra 140
				getplayer[THISACTOR].i spriteid
				setactor[hitsprite].htowner spriteid
				setactorvar[hitsprite].railed 20
			}
				  
		}
	}

}

setvar countvar 1

ifactioncount 6 killit

enda

useractor notenemy NOTHING 0
killit
enda

action SMALLEXPLODE -20 24 1 1 2

useractor notenemy SMALLEXPLOSION TOUGH SMALLEXPLODE

ifcount 1 nullop else
{
	ifspawnedby BFG cstat 514
	sizeat 12 12
	
	ifspawnedby HLROCKET
    {
      cstat 2
      sizeat 8 8
    }
    
    ifspawnedby FIREBULLET spawn BURNING
    
    ifspawnedby SHOTSPARK1 ifvarn ONCAR 0 { sound BOOM hitradius 1280 10 15 20 25 }
     
}
ifcount 21 killit
enda


move RINGMOVE
action RINGANIM 0 8 1 1 4

useractor notenemy RINGTHING 0 RINGANIM
ifcount 2 nullop else ifcount 1
{
	sizeat 24 24
	spritepal 2 
	cstat 128
	move RINGMOVE
	
	ifspawnedby BOMBDART ifvare dartstuck 0
	{
		setvarvar spriteid THISACTOR
		state actorhitscan
		//ifvarn hitsprite -1
		//{
		//	getactor[hitsprite].extra temp
		//	ifvarg temp 0 break
		//}
		setvar dartstuck 1
		espawn WALLDART
		setactor[RETURN].x hitx
		setactor[RETURN].y hity
		setactor[RETURN].z hitz
	}
}
ifactioncount 8 killit

enda

state shockwave_on_player

setactor[target].htpicnum RADIUSEXPLOSION
setactor[target].htowner myspawner
setactor[target].htextra 3
palfrom 30 63
wackplayer

ends

action STOMPWAVEFRAMES 0 9 1 1 12

useractor notenemy STOMPWAVE 0 STOMPWAVEFRAMES
ifmove 0
{
	getactor[THISACTOR].owner myspawner
	getactor[THISACTOR].z z
	subvar z 1536
	setactor[THISACTOR].z z
	cstat 34
	sizeat 192 192
	move RINGMOVE
	getplayer[THISACTOR].i target
	hitradius 6144 5 10 15 20
}

ifactioncount 9 killit
else ifp ponground
	ifcansee
{
	//ifactioncount 9
	//	ifpdistl 10240 
	//		state shockwave_on_player
	//else
	
	ifactioncount 8
		ifpdistl 10240
			state shockwave_on_player
	else
	ifactioncount 7
		ifpdistl 9216 
			state shockwave_on_player
	else
	ifactioncount 6
		ifpdistl 8192 
			state shockwave_on_player
	else
	ifactioncount 5
		ifpdistl 7168 
			state shockwave_on_player
	else
	ifactioncount 4
		ifpdistl 6144 
			state shockwave_on_player
	else
	ifactioncount 3
		ifpdistl 5120 
			state shockwave_on_player
	else
	ifactioncount 2
		ifpdistl 4096 
			state shockwave_on_player
	else	
	ifactioncount 1
		ifpdistl 3072 
			state shockwave_on_player
}
enda

eventloadactor BONUSRING
cstator 130
sizeat 160 160
spritepal 0
getactor[THISACTOR].lotag lotag
setactor[THISACTOR].lotag 0
getactor[THISACTOR].hitag hitag
setactor[THISACTOR].hitag 0
enda

spritenoshade BIGFLASH
useractor notenemy BIGFLASH 0
cstat 130
sizeat 160 160
ifcount 3 killit
enda

useractor notenemy BONUSRING 0

cstator 128

ifvare ONCAR 2
ifvarvare lastring lotag
{
	ifspritepal 6 spritepal 0 else spritepal 6
	
	setvar temp 0
	ifp pfacing
		ifpdistl 2560
	setvar temp 1
	
	ifpdistl 2048
	setvar temp 1
	ifvare temp 1
	{
		addvar lastring 1
		//palfrom 32 64 64 32
		spawn BIGFLASH
		globalsound SKILLCOIN_GRAB
		addvar score 1
		addvar pheal 5
		ifvarn hitag 0
		{
			addvarvar skillpoint hitag
			addvar pheal 45
			setvar message 319
			setvar messagetime 26
		}
		killit
	}
}

enda

action PORTALFRAMES 3 4 1 1 10
action PORTALFRAMESBACK 7 4 1 -1 10

useractor notenemy BATTLEPORTAL 0

//soundonce PORTALHUM
sizeto 40 40
ifmove 0
{
	cstat 144
	getactor[THISACTOR].z z
	subvar z 16384
	setactor[THISACTOR].z z
	action PORTALFRAMES
	move RINGMOVE spin
	espawn BATTLETEXT
	getactor[RETURN].z z
	subvar z 16384
	setactor[RETURN].z z
}

ifpdistl 8192
{
	getplayer[THISACTOR].i spriteid
	ldist xydist THISACTOR spriteid
	mulvar xydist -1
	addvar xydist 6144
	divvar xydist 128
	ifvarg xydist 64 setvar xydist 64
	ifvarl xydist 1 setvar xydist 1
	setplayer[THISACTOR].pals 0 63
	setplayer[THISACTOR].pals 1 20
	setplayer[THISACTOR].pals 2 40
	setplayer[THISACTOR].pals_time xydist
}

ifaction PORTALFRAMES
{
	ifactioncount 4 action PORTALFRAMESBACK
}
else ifactioncount 4 action PORTALFRAMES

ifcount 130 // portal activates at 130
{
	espawn TRANSPORTERSTAR
	setactor[RETURN].pal 2
	setactor[RETURN].xrepeat 6
	setactor[RETURN].yrepeat 6
	randvar temp 16384
	getactor[THISACTOR].z z
	addvar z 8192
	subvarvar z temp
	setactor[RETURN].z z
	randvar temp 768
	ifrnd 128 mulvar temp -1
	getactor[RETURN].x x
	addvarvar x temp
	setactor[RETURN].x x
	randvar temp 768
	ifrnd 128 mulvar temp -1
	getactor[RETURN].y y
	addvarvar y temp
	setactor[RETURN].y y
	ifpdistl 1024 setvar countvar 6
}

ifvarg countvar 1 subvar countvar 1
ifvare countvar 1 // startlevel VOLUME 11
endofgame 6

enda

useractor notenemy BATTLETEXT 0

sizeat 40 40

enda

useractor notenemy WALLDART 0

sizeat 4 4
cstat 256

ifcount 249 nullop else ifcount 248 soundonce LASERTRIP_ARMING

ifhitweapon count 260

ifcount 260
{
	sound PIPEBOMB_EXPLODE
	switch pdamage
	case 40 
	case 50
	case 60 hitradius 3584 20 30 40 50 break
	case 70
	case 80 hitradius 3584 30 45 60 75 break
	case 90 hitradius 3584 40 60 80 100 break
	case 100 hitradius 3584 50 70 90 110 break
	case 110 hitradius 3584 60 80 100 120 break
	case 120 hitradius 3584 70 95 120 145 break
	case 130 hitradius 3584 80 105 130 155 break
	case 140 hitradius 3584 90 115 140 165 break
	case 150 hitradius 3584 100 130 160 190 break
	case 160 hitradius 3584 110 140 170 200 break
	case 170 hitradius 3584 120 155 190 225 break
	case 180 hitradius 3584 130 170 210 250 break
	case 190 hitradius 3584 140 180 220 260 break
	case 200 hitradius 3584 150 195 240 280 break
	case 220 hitradius 3584 175 225 275 320 break
	case 240 hitradius 3584 200 250 290 350 break
	case 260 hitradius 3584 225 275 325 400 break
	endswitch
	
	
	
	spawn BIGEXPLOSION
	palfrom 33 63 63 63
	quote 151
	ifrnd 128 spawn BURNING else spawn BURNING2
	killit
}

enda

action STARIMPACT 3 4 1 -1 10

useractor notenemy PLASMA_IMPACT 0 STARIMPACT
ifcount 1 nullop
	else
{ 
	cstat 128
	sizeat 24 24
	ifspawnedby LIGHTNINGBOLT spawn LIGHTNING_TRAIL2
}
ifactioncount 4 killit
enda

state lightningcode

ifvare countvar 0
{
	sizeat 64 128
	ifrnd 128 cstat 0 else cstat 4
// 	switch pdamage
// 	case 60 hitradius 1536 3 3 4 6 break
// 	case 80 hitradius 1536 4 6 8 10 break
// 	case 100 hitradius 1536 6 8 10 12 break
// 	case 120 hitradius 1536 8 10 12 14 break
// 	case 140 hitradius 1536 10 14 18 22 break
// 	case 160 hitradius 1536 12 16 20 24 break
// 	case 180 hitradius 1536 14 18 22 26 break
// 	case 200 hitradius 1536 16 20 24 28 break
// 	case 220 hitradius 1536 18 24 30 36 break
// 	case 240 hitradius 1536 20 26 32 38 break
// 	case 260 hitradius 1536 22 30 38 46 break
// 	endswitch
	setvarvar tempb pdamage
	divvar tempb 10
	getactor[THISACTOR].sectnum mysector
	headspritesect spriteid mysector
	whilevarn spriteid -1
	{
		ifvarvarn spriteid THISACTOR
		{
			getactorvar[spriteid].monstatus temp
			ifvarn temp -1
			{
				dist xydist THISACTOR spriteid
				ifvarl xydist 1792
				{
					setactor[spriteid].htextra tempb
					ifrnd 128
					setactor[spriteid].htpicnum RADIUSEXPLOSION else
					setactor[spriteid].htpicnum FLAMETHROWER
					setactor[spriteid].htowner THISACTOR
				}
			}
		}
		nextspritesect spriteid spriteid	
	}
	
	sound 351
	ifrnd 8 spawn STICKYFIRE
}
getactor[THISACTOR].x x
getactor[THISACTOR].y y
randvar temp 256
ifrnd 128 addvarvar x temp else subvarvar x temp
randvar temp 256
ifrnd 128 addvarvar y temp else subvarvar y temp
setactor[THISACTOR].x x
setactor[THISACTOR].y y

ifactioncount 8 
{ 
	ifvarg framerate 30 spawn NEWSMOKE
	killit
}
setvar countvar 1

ends

action LIGHTNING2 2 1 1 1 1

useractor notenemy LIGHTNING_TRAIL2 0 LIGHTNING2

state lightningcode

enda

action LIGHTNING 1 1 1 1 1

useractor notenemy LIGHTNING_TRAIL 0 LIGHTNING

ifvare countvar 0
{ 
	sizeat 32 64
	ifrnd 128 cstat 32 else cstat 36
	palfrom 16 63 63 63
	getplayer[THISACTOR].ang angvar
	setactor[THISACTOR].ang angvar
}

ifactioncount 4 killit
setvar countvar 1

enda

action BFGANIM -5 4 1 1 10

useractor notenemy BFGIMPACT 0 BFGANIM

spritepal 7

ifvare countvarb 0
{
	ifspawnedby BFG 
	{
		sizeat 96 72 cstat 130
		espawn EXPLOSION2BOT
		setactor[RETURN].xrepeat 64
		setactor[RETURN].yrepeat 64
		palfrom 48 20 63 20 
		hitradius 10240 1 1 1 1 // for waking up nearby monsters
		setvarvar bfgid THISACTOR
	}
	else 
	{ 
		sizeat 64 48
		cstat 2
	}
}

ifvare countvarb 1
{
	ifspawnedby BFG nullop
	else ifpdistg 844
	{
	   switch pdamage
	   case 40 hitradius 768 50 50 50 50 break
	   case 50 hitradius 768 60 60 60 60 break
	   case 60 hitradius 768 75 75 75 75 break
	   case 70 hitradius 768 87 87 87 87 break
	   case 80 hitradius 768 100 100 100 100 break
	   case 90 hitradius 768 112 112 112 112 break
	   case 100 hitradius 768 125 125 125 125 break
	   case 110 hitradius 768 137 137 137 137 break
	   case 120 hitradius 768 150 150 150 150 break
	   case 130 hitradius 768 162 162 162 162 break
	   case 140 hitradius 768 175 175 175 175 break
	   case 150 hitradius 768 187 187 187 187 break
	   case 160 hitradius 768 200 200 200 200 break
	   case 170 hitradius 768 225 225 225 225 break
	   case 180 hitradius 768 250 250 250 250 break
	   case 190 hitradius 768 275 275 275 275 break
	   case 200 hitradius 768 300 300 300 300 break
	   case 220 hitradius 768 350 350 350 350 break
	   case 240 hitradius 768 425 425 425 425 break
	   case 260 hitradius 768 500 500 500 500 break
	 endswitch
 	}
	
}
ifvare countvarb 2
{
	ifspawnedby BFG setvar bfgid -1
	ifvarvare bfgid THISACTOR setvar bfgid -1
}
	

addvar countvarb 1
ifactioncount 4 killit

enda


state coinbounce

addvar countvar 1

fall

ifawayfromwall nullop 
   else ifvarg countvar 25 iffloordistl 8 ifnotmoving
{ 
   getactor[THISACTOR].ang temp
   ifrnd 128 addvar temp 768 else subvar temp 768
   setactor[THISACTOR].ang temp
   setvar countvar 0
}


iffloordistl 2
{
  randvar tempb 1024
  ifinwater addvar tempb 600 else addvar tempb 2048
  ifactor BOSSCOIN addvar tempb 768
  mulvar tempb -1
  setactor[THISACTOR].zvel tempb
}

getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z
updatesectorz x y z mysector
ifvare mysector -1
{
	getplayer[THISACTOR].posx mx
	getplayer[THISACTOR].posy my
	ifvarvarg mx x addvar x 1024 else subvar x 1024
	ifvarvarg my y addvar y 1024 else subvar y 1024
	setactor[THISACTOR].x x
	setactor[THISACTOR].y y
}
	

ends

state monspawn

sound BOOM
debris SCRAP1 8
spawn NEWSMOKE
ifvare hitag 1 spawn MINIBOSS3 else
spawn PIGCOP
spawn EXPLOSION2
killit

ends

move POKEBALLROLL 256

useractor notenemy POKEBALLG 0
fall
ifmove 0 
{
	sizeat 96 96 
	cstat 257 
	move POKEBALLROLL geth 
	getactor[THISACTOR].xrepeat tempb
	mulvar tempb -32
	setactor[THISACTOR].mdzoff tempb
	ifspawnedby BOSS3 setvar mtype 1
}

getactor[THISACTOR].pitch temp
addvar temp 160
setactor[THISACTOR].pitch temp
ifcount 130 ifrnd 2 state monspawn
ifnotmoving state monspawn
ifhitweapon state monspawn
ifspritepal 0 spritepal 6 else spritepal 0
enda

useractor notenemy DTPIPESTUFF TOUGH

sound VENT_BUST
spawn ROTATEGUNALLY
killit

enda

useractor notenemy BLASTRAIL 0

ifvare countvar 0 
{
	ifspawnedby BLASTER4 { sizeat 28 28 spritepal 0 }
	else sizeat 14 14
}
else
{
	getactor[THISACTOR].xrepeat x
	subvar x 1
	setactor[THISACTOR].xrepeat x
	setactor[THISACTOR].yrepeat x
}
addvar countvar 1
ifvare countvar 8 cstat 2
ifvare countvar 12 cstat 514

enda



useractor notenemy LASER3TRAIL 0

ifvare countvar 0 sizeat 12 10
ifvare countvar 2 cstat 2
ifvare countvar 4 sizeat 11 9
ifvare countvar 6 sizeat 10 8
ifvare countvar 8 sizeat 9 8
ifvare countvar 10 sizeat 8 7
ifvare countvar 12 sizeat 7 6
ifvare countvar 14 sizeat 6 5
ifvare countvar 16 sizeat 5 4
ifvare countvar 18 sizeat 4 4
ifvare countvar 19 cstat 514
ifvare countvar 20 sizeat 3 3
ifvare countvar 22 sizeat 2 2
ifvare countvar 24 sizeat 1 1
ifvare countvar 27 killit

addvar countvar 1

enda

useractor notenemy LASER3IMPACT 0

ifvare countvar 0 
{
	cstat 32768
	getactor[THISACTOR].z z
	addvar z 5120
	setactor[THISACTOR].z z
}

ifvare countvar 1
{
	cstat 2
	ifspawnedby BLASTER4 sizeat 88 72 else
	sizeat 44 36
}


ifvare countvar 5
{
	espawn NEWSMOKE
	getactor[RETURN].z mz
	subvar mz 4096
	setactor[RETURN].z mz
}
ifvare countvar 8 killit
			
addvar countvar 1

enda

move COINMOVE 96
action AMMOSPIN -1 7 1 1 8

useractor notenemy AMMOCOIN TOUGH
ifcount 1 nullop else
{
	action AMMOSPIN
	sizeat 32 32
	spritepal 2
	move COINMOVE randomangle
}

state coinbounce

ifpdistl 2048 ifcansee // vacuum code
     move COINMOVE faceplayer else
     
ifvare ONCAR 2 move COINMOVE faceplayer

else 
	move COINMOVE geth

    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
      {
	    ifvarand tipfield 16 nullop else ifvare tipdisplay 0 ifvare ONCAR 0 ifp palive
		{
			// FIRST AMMO COIN TIP
			setvar menutoggle 4
			setvar tipdisplay 16
			orvar tipfield 16
			setvar messagetime 26
			globalsound EXITMENUSOUND
		}
      	addvar ammocoins 1
	   	palfrom 32 0 32
       	globalsound AMMO_MAX
	   	quote 190
	   	killit		
      }
enda

action INVENSPIN -4 7 1 1 8

useractor notenemy INVENCOIN TOUGH
ifcount 1 nullop
 else
{
	sizeat 32 32
	spritepal 1
	action INVENSPIN
	move COINMOVE randomangle
}

state coinbounce

  ifpdistl 2048 ifcansee // vacuum code
     move COINMOVE faceplayer else
     
ifvare ONCAR 2 move COINMOVE faceplayer
     
   else
   	 move COINMOVE geth

    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
      {
	    ifvarand tipfield 32 nullop else ifvare tipdisplay 0 ifvare ONCAR 0 ifp palive
		{
			// FIRST INVEN COIN TIP
			setvar menutoggle 4
			setvar tipdisplay 32
			orvar tipfield 32
			setvar messagetime 26
			globalsound EXITMENUSOUND
		}
       	palfrom 32 0 32
       	globalsound GETATOMICHEALTH

		randvar temp 100
      
		ifvarl temp 33
		{
			getplayer[THISACTOR].firstaid_amount tempb
			addvar tempb 10
			ifvarvarg tempb firstaidlimit setvarvar tempb firstaidlimit
			setplayer[THISACTOR].firstaid_amount tempb
		}
		else ifvarl temp 67
		{
			getplayer[THISACTOR].heat_amount tempb
			addvar tempb 100 ifvarvarg tempb gogglelimit setvarvar tempb gogglelimit
			setplayer[THISACTOR].heat_amount tempb
		}
		else
		{
			getplayer[THISACTOR].holoduke_amount tempb
        	addvar tempb 100 ifvarvarg tempb holodukelimit setvarvar tempb holodukelimit
   			setplayer[THISACTOR].holoduke_amount tempb
		}

        quote 147
        killit
      }
enda

action SKILLSPIN -3 7 1 1 8


useractor notenemy SKILLCOIN TOUGH

ifvarn menutoggle 0 break

ifcount 1 nullop else
{
	sizeat 40 40
	action SKILLSPIN
	move COINMOVE randomangle
}

ifvare goggles 1 cstat 0 else cstat 32768

state coinbounce

ifvare goggles 0 move COINMOVE geth else
{
	ifcansee // vacuum code
	{
		move COINMOVE faceplayer
	} else
     
ifvare ONCAR 2 move COINMOVE faceplayer
		
}

addvar loop 1
ifvarg loop 2
{
	ifspritepal 0 spritepal 6
	 else
	  spritepal 0
	setvar loop 0
}

   ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcanseetarget
            ifvare goggles 1
  {
   	palfrom 32 0 32
   	globalsound SKILLCOIN_GRAB
   	addvar skillpoint 1
   	getplayer[THISACTOR].heat_amount temp
   	ifvarl temp 600
   	{
	   	addvar temp 60
  		setplayer[THISACTOR].heat_amount temp 
  	}
  	quote 146
  	killit
  }
enda

action NUKESPIN -1 7 1 1 8

useractor notenemy NUKECOIN TOUGH

ifcount 1 nullop
 else
{
	sizeat 32 32
	action NUKESPIN
	move COINMOVE randomangle
}


state coinbounce

ifpdistl 2048 ifcansee // vacuum code
      move COINMOVE faceplayer else
     
ifvare ONCAR 2 move COINMOVE faceplayer
     
else
	  move COINMOVE geth
	
  ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
	  	  		ifvarl nukepart 30
      {
       	palfrom 32 0 32
       	globalsound GETATOMICHEALTH
        addvar nukepart 1
        quote 125
        ifvarand tipfield 4 nullop else ifvare tipdisplay 0 ifp palive ifvare ONCAR 0
		{
			// FIRST NUKE COIN TIP
			setvar menutoggle 4
			setvar tipdisplay 4
			orvar tipfield 4
			setvar messagetime 26
			globalsound EXITMENUSOUND
		}
        killit
      }
enda

state bosscoinlite

addvar score 100
setplayer[THISACTOR].timebeforeexit 26

ends

action BOSSCOINSPIN 2 7 1 1 15

move BOSSCOINMOVE 16

useractor notenemy BOSSCOIN TOUGH BOSSCOINSPIN


state coinbounce
ifmove 0 
{
	action BOSSCOINSPIN
	move BOSSCOINMOVE geth
	sizeat 128 128
	ifvare lotag 42 sizeat 255 255
}

    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    
       	palfrom 48 0 32
       	globalsound GETATOMICHEALTH
        //addvar skillpoint 20
        quote 148
        ifspritepal 3 { state bosscoinlite killit break }
        addvar score 500
        switch VOLUME
        case 0 orvar complete 1 break
        case 1 orvar complete 2 break
        case 2 orvar complete 4 break
        case 3 orvar complete 8 break
        case 4 orvar complete 16 break
        case 5 orvar complete 32 break
        case 6 orvar complete 64 break
        endswitch
        state updatescores
        
// 		getuserdef[THISACTOR].player_skill temp
// 		ifvarg temp 2
// 		{
// 			setvar temp 0
// 			ifvarand complete 1 addvar temp 1
// 			ifvarand complete 2 addvar temp 1
// 			ifvarand complete 4 addvar temp 1
// 			ifvarand complete 8 addvar temp 1
// 			ifvarand complete 16 addvar temp 1
// 			ifvarand complete 32 addvar temp 1
// 			ifvarand complete 64 addvar temp 3 // normally 1, set to 3 until secret level enabled
//  			ifvarg temp 2 ifvare VOLUME 6 // battleportal from other volumes disabled for now
//  			{
//  				setactorvar[myspawner].lotag -1
//  				killit
//  				break
// 			}
// 		}
	
        endofgame 52
        killit
      }

enda

state nuclearflash
palfrom 63 63 63 63
quake 78
ends

action NUKEARMED -16 16 1 1 3
move NUKERISE 0 -32
move NUKESTOP 0 -16

useractor notenemy DUKENUKE TOUGH NUKEARMED
fall
setvar nukehold 0 // to prevent a second one from spawning
ifmove 0
{
	sizeat 128 128
	quote 192
	move NUKERISE geth getv
}


ifvarn currholo -1
{
	findnearactor HOLOBOT RETRIEVEDISTANCE temp
	
		ifvarn temp -1
		{
		   	getactorvar[temp].nuclear tempb
		   	ifvare tempb 0
			{
		  	 	setactorvar[temp].nuclear 666
		  	 	state nuclearflash
		 	 	globalsound SHIELD_UPGRADE
		 	 	killit
			}
		}
}
ifvare countvar 169 state nuclearflash

ifvarg countvar 174
{
	ifvare countvar 175 
	{
		cstat 32768
		wackplayer
		spawn BIGEXPLOSION
		// hitradius 32768 150 300 500 900
		sound NUKE_EXPLODE
		
		
		setvar spriteid 0
		whilevarn spriteid 16384
		{
			getactor[spriteid].picnum tilenum
			ifoutside
				ifvare tilenum CACTUS
			{
				getactor[spriteid].sectnum temp
				ifvarn temp -1
				{
					getsector[temp].ceilingstat tempb
					ifvarand tempb 1
					setactorvar[spriteid].mtype 2
				}
			} else
			{
				getactorvar[spriteid].monstatus temp
				ifvarn temp -1
				{
					canseespr THISACTOR spriteid tempb
					ifvare tempb 1
					{
						setactor[spriteid].htextra 500
						setactor[spriteid].htpicnum RADIUSEXPLOSION
						setactor[spriteid].htowner THISACTOR
					}
				}
			}
			addvar spriteid 1
		}
		
	}
	ifvare countvar 180 hitradius 32768 150 300 500 900
	ifvare countvar 185 
	{ 
		hitradius 32768 150 300 500 900 killit 
	}
} else
ifvarg countvar 158 // 166
{
	quake 52
	getplayer[THISACTOR].i spriteid
	getactor[THISACTOR].ang angvar
	eshoot MININUKE
	setactor[RETURN].owner spriteid
	spawn BIGFIRE
	addvar angvar 32
	setactor[THISACTOR].ang angvar
	spawn BIGFIRE
	addvar angvar 32
	setactor[THISACTOR].ang angvar
	spawn BIGFIRE
	addvar angvar 32
	setactor[THISACTOR].ang angvar
	spawn BIGFIRE
	addvar angvar 32
	setactor[THISACTOR].ang angvar
	
// 	eshoot MININUKE
// 	setactor[RETURN].owner spriteid
// 	spawn BIGFIRE
// 	addvar angvar 32
// 	setactor[THISACTOR].ang angvar
// 	spawn BIGFIRE
// 	addvar angvar 32
// 	setactor[THISACTOR].ang angvar
// 	spawn BIGFIRE
// 	addvar angvar 32
// 	setactor[THISACTOR].ang angvar
// 	spawn BIGFIRE
// 	addvar angvar 32
// 	setactor[THISACTOR].ang angvar
}
else
ifvarg countvar 130 { soundonce LASERTRIP_ARMING quote 137 }
else
ifvarg countvar 104 quote 136
else
ifvarg countvar 78 { ifmove NUKERISE move NUKESTOP getv quote 135 }
else
ifvarg countvar 52 quote 134
else
ifvarg countvar 26 quote 133

addvar countvar 1
enda

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

state aimatholobot

ifvarn currholo -1
{
	ldist xydist THISACTOR currholo
	ifvarl xydist FINDRANGE setvarvar target currholo else setvar target -1
}
else setvar target -1

ifvarn target -1
	state aimattarget
ends

state genericshrunkcode
  ifcount 32
  {
    ifpdistl SQUISHABLEDISTANCE
    { 
	    ifvarg mval 0 
	    { 
		    state dropcoins
		    state addscore
		    state clearlists
		} 
		pstomp
		ifactor ROBOMAN { spawn SMALLEXPLOSION sound PIPEBOMB_EXPLODE killit }
	}
   
	ifvarn currholo -1
	{
	    findnearactorz HOLOBOT SQUISHABLEDISTANCE 8192 temp
	    ifvarn temp -1
		{
			addkills 1
			sound SQUISHED
			state standard_jibs
			ifvarg mval 0 { state dropcoins state addscore }
			state clearlists
			killit
		}
	}
  }
  else
  {
    sizeto MINXSTRETCH MINYSTRETCH
    spawn FRAMEEFFECT1
  }
ends

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


action ASHARKCRUZING 0 8 5 1 24
action ASHARKFLEE  0 8 5 1 10
action ASHARKATACK   0 8 5 1 6
action ASHARKSHRUNK  0 8 5 1 24
action ASHARKGROW  0 8 5 1 24
action ASHARKFROZEN  0 1 5 1 24

move SHARKVELS 24
move SHARKFASTVELS 72
move SHARKFLEEVELS 40

actor SHARK SHARKSTRENGTH ASHARKCRUZING SHARKVELS randomangle geth

  state monsterai
  ifvarg menutoggle 0 break

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

    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
       ifvare superkicking 0
        pkick

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

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
        break

      state checkdart
      lotsofglass 30
      spritepal 22
      state standard_jibs
      sound GLASS_BREAKING
      addkills 1
      state clearlists
      killit
    }
    break
  }
  else
    ifaction ASHARKFLEE
  {
    ifcount 16
      ifrnd 48
    {
      action ASHARKCRUZING
      move SHARKVELS randomangle geth
    }
  }
  else
    ifaction ASHARKCRUZING
  {
    ifcansee
      ifcount 48
        ifrnd 2
          ifcanshoottarget
    {
      action ASHARKATACK
      move SHARKFASTVELS faceplayerslow getv break
    }
    ifcount 32
      ifnotmoving
    {
      ifrnd 128
        move SHARKVELS randomangle geth
      else
        move SHARKFASTVELS randomangle geth
    }
  }
  else
    ifaction ASHARKATACK
  {
    ifcount 4
    {
      ifpdistl 1280
      {
        ifp palive ifcanshoottarget
        {
          sound DUKE_GRUNT
          palfrom 32 32
          addphealth SHARKBITESTRENGTH
        }
        action ASHARKFLEE
        move SHARKFLEEVELS fleeenemy
      }
    }
    else
      ifnotmoving
    {
      ifcount 32
      {
        action ASHARKCRUZING
        move SHARKVELS randomangle geth
      }
    }
    else
      ifcount 48
        ifrnd 2
    {
      action ASHARKCRUZING
      move SHARKFASTVELS randomangle geth
    }
  }

  ifhitweapon
  {
    state checkdart
    ifdead
    {
      ifwasweapon GROWSPARK
      {
        move 0
        cstat 0
        action ASHARKGROW
        sound ACTOR_GROWING
        break
      }
      else
        ifwasweapon FREEZEBLAST
      {
        spritepal 1
        strength 0
        action ASHARKFROZEN
        sound SOMETHINGFROZE
      }
      else
      {
        sound SQUISHED
        guts JIBS6 5
        addkills 1
        state clearlists
        killit
      }
    }
    else
    {
      ifwasweapon SHRINKSPARK
      {
        action ASHARKSHRUNK
        sound ACTOR_SHRINKING
        move 0
        break
      }
      else
        ifwasweapon GROWSPARK
          sound EXPANDERHIT

      move SHARKVELS randomangle geth
    }
  }
enda


action BLIMPWAITTORESPAWN

state blimphitstate
  cstat 0
  spawn FIRSTGUNSPRITE
  spawn EXPLOSION2

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

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

actor BLIMP 1
	
	ifvarg menutoggle 0 break

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

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



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

move RESPAWN_ACTOR_FLAG
move MOUSEVELS 32

action RUBCANDENT 1 1 1 1 1

actor RUBBERCAN WEAK

ifvarn bfgid -1
{
	ldist temp THISACTOR bfgid
	ifvarl temp 10240 spawn BFGIMPACT
}
  ifvarg menutoggle 0 break
  ifaction RUBCANDENT
  {
    ifactioncount 16
    {
      strength 0
      action ANULLACTION
      break
    }
  }
  else
    ifhitweapon
  {
    ifwasweapon RADIUSEXPLOSION
    {
      state checkdart
      state rats
      ifrnd 48
        spawn BURNING
      debris SCRAP3 12
      killit
    }
    else
      {
      action RUBCANDENT
      state checkdart
      }
  }
enda

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

state jibfood
  sound SQUISHED
  guts JIBS6 3
  killit
ends

state breakobject

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

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

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


ends

action ABURGERROTS 0 1 5
useractor notenemy DUKEBURGER PIRATEGALSTRENGTH ABURGERROTS state breakobject enda

useractor notenemy MOP WEAK state breakobject enda

useractor notenemy BROOM WEAK state breakobject enda

useractor notenemy WETFLOOR WEAK state breakobject enda

useractor notenemy DESKLAMP WEAK state breakobject enda

// useractor notenemy DUKECUTOUT WEAK state breakobject enda

useractor notenemy HATRACK WEAK state breakobject enda

useractor notenemy GUNPOWDERBARREL TOUGH state breakobject enda

useractor notenemy COFFEEMACHINE WEAK state breakobject enda

useractor notenemy TEDDYBEAR WEAK state breakobject enda

useractor notenemy TOPSECRET WEAK state breakobject enda

useractor notenemy ROBOTMOUSE ROBOTMOUSESTRENGTH state breakobject enda

useractor notenemy MAN PIRATEGALSTRENGTH state breakobject enda

useractor notenemy MAN2 PIRATEGALSTRENGTH state breakobject enda

useractor notenemy WOMAN PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE1A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE2A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE3A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE4A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE5A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATE6A PIRATEGALSTRENGTH state breakobject enda

useractor notenemy ROBOTPIRATE PIRATEGALSTRENGTH state breakobject enda

useractor notenemy PIRATEHALF TOUGH state breakobject enda

useractor notenemy CHESTOFGOLD WEAK state breakobject enda

useractor notenemy ROBOTDOG PIRATEGALSTRENGTH state breakobject enda

useractor notenemy ROBOTDOG2 TOUGH state breakobject enda

useractor notenemy PLEASEWAIT state breakobject enda

useractor notenemy FOODOBJECT1 WEAK state breakobject enda

useractor notenemy FOODOBJECT2 WEAK state breakobject enda

useractor notenemy FOODOBJECT3 WEAK state breakobject enda

useractor notenemy FOODOBJECT4 WEAK state breakobject enda

useractor notenemy FOODOBJECT5 WEAK state breakobject enda

useractor notenemy FOODOBJECT6 WEAK state breakobject enda

useractor notenemy FOODOBJECT7 WEAK state breakobject enda

useractor notenemy FOODOBJECT8 WEAK state breakobject enda

useractor notenemy FOODOBJECT9 WEAK state breakobject enda

useractor notenemy FOODOBJECT10 WEAK state breakobject enda

useractor notenemy FOODOBJECT11 WEAK state breakobject enda

useractor notenemy FOODOBJECT12 WEAK state breakobject enda

useractor notenemy FOODOBJECT13 WEAK state breakobject enda

useractor notenemy FOODOBJECT14 WEAK state breakobject enda

useractor notenemy FOODOBJECT15 WEAK state breakobject enda

useractor notenemy FOODOBJECT16 WEAK state breakobject enda

useractor notenemy FOODOBJECT17 WEAK state breakobject enda

useractor notenemy FOODOBJECT18 WEAK state breakobject enda

useractor notenemy FOODOBJECT19 WEAK state breakobject enda

useractor notenemy FOODOBJECT20 WEAK state breakobject enda

useractor notenemy JOLLYMEAL WEAK state breakobject enda

useractor notenemy GUMBALLMACHINE WEAK state breakobject enda

useractor notenemy GUMBALLMACHINEBROKE WEAK state breakobject enda

useractor notenemy POLICELIGHTPOLE TOUGH state breakobject enda

useractor notenemy CLOCK WEAK state breakobject enda

useractor notenemy MAILBAG WEAK state breakobject enda

useractor notenemy FEATHEREDCHICKEN WEAK state breakobject enda

useractor notenemy SKINNEDCHICKEN WEAK state breakobject enda

useractor notenemy HEADLAMP WEAK state breakobject enda

useractor notenemy DOLPHIN1 DOLPHINSTRENGTH state breakobject enda

useractor notenemy DOLPHIN2 DOLPHINSTRENGTH state breakobject enda

useractor notenemy SNAKEP MEDIUMSTRENGTH state breakobject enda

useractor notenemy DONUTS WEAK state breakobject enda

useractor notenemy GAVALS WEAK state breakobject enda

useractor notenemy GAVALS2 WEAK state breakobject enda

useractor notenemy CUPS WEAK state breakobject enda

useractor notenemy DONUTS2 WEAK state breakobject enda

useractor notenemy FLOORBASKET WEAK state breakobject enda

useractor notenemy METER WEAK state breakobject enda

useractor notenemy DESKPHONE WEAK state breakobject enda

useractor notenemy MACE WEAK state breakobject enda

useractor notenemy SHOPPINGCART WEAK state breakobject enda

useractor notenemy COFFEEMUG WEAK state breakobject enda



state headhitstate

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

// wackplayer

ends


action EXPBARRELFRAME     0   2   1   1   15
actor EXPLODINGBARREL 26
  fall
	state monsterai
  ifvarg menutoggle 0 break
  ifaction EXPBARRELFRAME
  {
    ifactioncount 2
    {
      hitradius 1024 WEAKEST WEAK MEDIUMSTRENGTH TOUGH
      spawn EXPLOSION2
      debris SCRAP2 2
      sound PIPEBOMB_EXPLODE
      killit
    }
    break
  }
  ifsquished
  {
    debris SCRAP1 5
    killit
    break
  }
  ifhitweapon
    action EXPBARRELFRAME
enda

action BURNING_FLAME  0   12   1   1   2
move BURNING_VELS 

state burningstate

  sleeptime 300


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

  ifpdistg 10240
    break

  ifcount 128
  {
    ifspawnedby TIRE
    {
      ifactioncount 512 { ifvarg framerate 30 spawn NEWSMOKE killit }

      ifrnd 16
        sizeto 64 48
    }
    else
    {
      sizeto 8 8
      sizeto 8 8
      ifcount 192 { ifvarg framerate 30 spawn NEWSMOKE killit }
        
    }
  }
  else
  {
    ifmove 0
      move BURNING_VELS

    ifvare mtype 1 sizeto 26 26 else
    sizeto 52 52

    ifp palive
      ifpdistl 844
        ifrnd 32
          ifcansee
            ifvare mtype 0
    {
      soundonce DUKE_LONGTERM_PAIN
      addphealth -1
      palfrom 24 16
    }
  }

ends

actor BURNING WEAK BURNING_FLAME
  state burningstate
enda

actor BURNING2 WEAK BURNING_FLAME
  state burningstate
enda

action TOILETWATERFRAMES 0 4 1 1 1
actor TOILETWATER 0 TOILETWATERFRAMES
getplayer[THISACTOR].i temp
getactor[temp].extra hp

  ifpdistl 8192
  {
    soundonce WATER_GURGLE
    ifspawnedby TOILET
      sizeto 34 34
    else
    {
      ifspawnedby WATERFOUNTAINBROKE
        sizeto 6 15
      else
        ifspawnedby TOILETWATER
          nullop
      else
        sizeto 24 32
    }

    ifp palive
      ifpdistl RETRIEVEDISTANCE
        ifp pfacing
          ifactioncount 32
            //ifphealthl MAXPLAYERHEALTH
            ifvarl hp 100 ifvarvarl hp maxhealth  
              ifhitspace
                ifcansee
    {
      addphealth 1
      globalsound DUKE_DRINKING
      resetactioncount
    }
  }
enda

action WOODENHORSEFRAME  0   1   4
action WOODENFALLFRAME  122  1   5

actor HORSEONSIDE WEAKEST
  cactor WOODENHORSE
  action WOODENFALLFRAME
enda
actor WOODENHORSE WEAK WOODENHORSEFRAME
  fall
  ifhitweapon
  {
    ifdead
    {
      debris SCRAP1 4
      debris SCRAP2 3
      killit
    }
    else
      action WOODENFALLFRAME
  }
enda

state steamcode
  ifpdistl 6144
    soundonce STEAM_HISSING

  ifcount 20
    {
      resetcount
      ifp palive
        ifpdistl 1024
      {
        addphealth -1
        palfrom 16 16
      }
    }
  else
  {
    ifspawnedby STEAM
      break
    else
      ifspawnedby CEILINGSTEAM
        break

    sizeto 24 24
  }
ends

action STEAMFRAMES    0     5     1     1     1
actor STEAM 0 STEAMFRAMES
  state steamcode
enda

actor CEILINGSTEAM 0 STEAMFRAMES
  state steamcode
enda

actor WATERBUBBLEMAKER 0 0 randomangle
  ifpdistl 3084
    ifrnd 24
      spawn WATERBUBBLE
enda

action BUBBLE
action CRACKEDBUBBLE  1
move BUBMOVE       -10 -36
move BUBMOVEFAST     -10 -52

actor WATERBUBBLE 0 BUBBLE BUBMOVE getv geth randomangle

  ifaction CRACKEDBUBBLE
  {
    ifinwater
      ifrnd 192
        killit
    ifactioncount 7
      killit
  }
  else
  {
    ifcount 4
    {
      ifrnd 192
        move BUBMOVE getv geth randomangle
      else
        move BUBMOVEFAST getv geth randomangle
      resetcount

      ifrnd 84
        sizeat 8 10
      else
        ifrnd 84
          sizeat 10 8
      else
        sizeat 9 9
    }

    ifonwater
    {
      iffloordistl 8
        action CRACKEDBUBBLE
    }
    else
      ifactioncount 40
        action CRACKEDBUBBLE
  }
enda

move SMOKEVEL 8 -16
move ENGINE_SMOKE 64 -64
move SMOKESHOOTOUT -192
action SMOKEFRAMES 0 4 1 1 10
actor SMALLSMOKE 0 SMOKEFRAMES
  ifmove 0
  {
    ifspawnedby RECON
      move SMOKESHOOTOUT geth
    else
      ifspawnedby SECTOREFFECTOR
        move ENGINE_SMOKE geth getv
    else
      ifspawnedby FIREBULLET
        { spritepal 2 cstat 2 move SMOKEVEL geth faceplayer }
    else
      ifspawnedby APLAYER // should only be the case if the player has fired ALTSHOTGUN
        { 
	        ifrnd 208 killit else
	        {
		        sizeat 16 16
	        	spritepal 2 cstat 2 move SMOKEVEL geth faceplayer
        	}
	    }
    else
      move SMOKEVEL geth getv faceplayer
    ifspawnedby RPG
      cstat 2
  }
  ifpdistl 1596
    ifspawnedby RPG
      killit
  ifactioncount 4
    killit
  //Smoke code from gore mod
  // ifspawnedby RPG { spawn NEWSMOKE killit }
  // ifspawnedby KNEE { spawn NEWSMOKE killit }
  // ifspawnedby SHOTSPARK1 {  killit }
enda

// NEWSMOKE FROM GORE PACK MOD
move SMOKEMOVE 0 -14
move SMOKEMOVE2

// action NEWSMOKEA 0 1 1 1 20
action NEWSMOKEA 0 14 1 1 10

useractor notenemy NEWSMOKE 0

ifaction 0
{
	ifspawnedby SMOKESHOT spritepal 8
	// ifspawnedby SEEKER spritepal 2
	action NEWSMOKEA
	move SMOKEMOVE getv
	cstator 128
}

ifspawnedby BIGEXPLOSION sizeat 128 128
	else ifspawnedby EXPLOSION2 sizeat 64 64 else
	  ifspawnedby SMOKER sizeat 128 128 else
	   ifspawnedby NEWBEAST sizeat 128 128 else
	     ifspawnedby OCTABRAIN sizeat 128 128 else
	       ifspawnedby SMOKESHOT sizeat 192 192
	         else sizeat 40 40
	         
ifactioncount 14 killit

//  move SMOKEMOVE faceplayer getv
//   ifaction 0 
//   {
// 	  ifspawnedby SMOKESHOT spritepal 8
// 	  ifspawnedby SEEKER spritepal 2
// 	  action NEWSMOKEA 
//   }

//   ifspawnedby BIGEXPLOSION nullop
// 	else ifspawnedby EXPLOSION2 sizeto 40 40 else
// 	  ifspawnedby SMOKER sizeto 128 128 else
// 	   ifspawnedby NEWBEAST sizeto 128 128 else
// 	     ifspawnedby OCTABRAIN sizeto 128 128 else
// 	       ifspawnedby SMOKESHOT sizeto 128 128
// 	         else sizeto 20 20

  // ifactioncount 5 cstat 2 
//   ifspawnedby BIGEXPLOSION nullop
//      else ifspawnedby SMOKER nullop 
//          else ifspawnedby SMOKESHOT nullop 
//             else
// 	{
// 		ifactioncount 7 cstat 514
//   		ifactioncount 8 killit
// 	}
  //ifactioncount 16 cstat 514
  // ifactioncount 32 killit
  ifinwater
  { 
    spawn WATERBUBBLE spawn WATERBUBBLE spawn WATERBUBBLE spawn WATERBUBBLE
    killit
  }
enda

useractor notenemy ACIDCLOUD

ifmove 0
{
	spritepal 8
	move SMOKEMOVE faceplayer getv
}
sizeto 40 40
ifcount 130 killit else
ifcount 52 cstat 514 else
ifcount 26 cstat 2
addvar countvar 1
ifvarg countvar 12
{
	setvar countvar 0
	ifp palive
		ifcansee
			ifpdistl 1024
			{
				addphealth -1
				ifrnd 96 soundonce DUKE_LONGTERM_PAIN
				palfrom 30 10 63 10
			}
}
enda
		


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

move SPAWNED_BLOOD

actor NUKEBARRELDENTED WEAK
  cactor NUKEBARREL
  action BARREL_DENTED
enda

actor NUKEBARRELLEAKED WEAK
  cactor NUKEBARREL
  action BARREL_DENTED2
enda

state random_ooz
  ifrnd 128
    spawn OOZ2
  else
    spawn OOZ
ends

actor NUKEBARREL MEDIUMSTRENGTH

	state monsterai
  ifvarg menutoggle 0 break
  ifsquished
  {
    debris SCRAP1 32
    spawn BLOODPOOL
    state random_ooz
    killit
  }
  fall
  ifaction BARREL_DENTING
  {
    ifactioncount 2
    {
      debris SCRAP1 10
      ifrnd 2 spawn BLOODPOOL
      killit
    }
  }
  else
    ifhitweapon
  {
    ifdead
    {
      sound VENT_BUST

      ifrnd 128
        spawn BLOODPOOL
      action BARREL_DENTING
    }
    else
    {
      ifaction 0
        action BARREL_DENTED
      else
        ifaction BARREL_DENTED
      {
        action BARREL_DENTED2
        spawn BLOODPOOL
      }
      else
        ifaction BARREL_DENTED2
          action BARREL_DENTING
    }
  }
enda

state burningbarrelcode
  fall
  ifcount 32
  {
    resetcount
    ifp palive
      ifpdistl 1480
        ifp phigher
    {
      addphealth -1
      palfrom 16 16
      ifrnd 96
        sound DUKE_LONGTERM_PAIN
    }
  }
  ifhitweapon
  {
    sound VENT_BUST
    debris SCRAP1 10
    ifrnd 128
      spawn BURNING
    else
      spawn BURNING2
    killit
  }
ends

actor FIREBARREL
  state burningbarrelcode
enda
actor FIREVASE
  state burningbarrelcode
enda

action SHRINKERFRAMES 0 4 1 1 10
actor SHRINKEREXPLOSION 0 SHRINKERFRAMES
  ifactioncount 4
    killit
enda

action EXPLOSION_FRAMES 0 20 1 1  4
actor EXPLOSION2 1 EXPLOSION_FRAMES

ifactioncount 11 nullop else ifactioncount 10 spawn NEWSMOKE
ifactioncount 20 killit
ifcount 1 nullop else 
ifcount 0
{	

	ifspawnedby MAGMA
	{
		sizeat 12 12
		state smallboulder
		state smallboulder
		state smallboulder
		state smallboulder
		sizeat 36 36
	}
	ifspawnedby CANNONBALLPROJ debris SCRAP1 6
}
    
enda

actor EXPLOSION2BOT 1 EXPLOSION_FRAMES
  ifactioncount 20
    killit
enda

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

actor FLOORFLAME 0 FFLAME_FR
  ifaction FFLAME_FR
  {
    ifpdistl 1024
      hitradius 1024 WEAKEST WEAKEST WEAKEST WEAKEST
    ifactioncount 16
      action FFLAME
  }
  ifaction FFLAME
    ifrnd 4
  {
    action FFLAME_FR
    sound CAT_FIRE
    resetactioncount
  }
enda

state holozdist

getactor[THISACTOR].z z
getactor[target].z mz
setvarvar zdist mz
subvarvar zdist z
ends

state rpgatholo

ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1
mulvar zdist 644
divvarvar zdist xydist // zdist now holds the desired z velocity
sound RPG_SHOOT
ezshoot zdist RPGNOAIM
setthisprojectile[RETURN].extra 70
setactor[RETURN].extra 70
ends

state chainfireatholo
	
ldist tempb THISACTOR temp
ifvare tempb 0 setvar tempb 1
shiftvarl zdist 8
divvarvar zdist tempb // zdist now holds the desired z velocity
sound CHAINGUN_FIRE
ifvare holosphere 0 setvar tilenum CHAINGUN else setvar tilenum SLOWBULLET
zshootvar zdist tilenum
ends

state asatshooting

	state aimatholobot
	ifvarn target -1 
	{
		ifvare mtype 1
		{
			ifvare holosphere 0 setvar tilenum CHAINGUN else setvar tilenum SLOWBULLET
			ifvarn myspawner -1 { setactor[myspawner].cstat 1 }
			spawn MUZZLEFLASHLOW
			sound M16FIRE
			shootvar tilenum
			ifvarn myspawner -1 { setactor[myspawner].cstat 257 }
		}
		else
		{
			sound PRED_ATTACK
			shoot FIRELASER
		}	    
	}
	else
		{
        	// ifcansee
          	//  ifcanshoottarget
      	  // {
         	ifvare mtype 1
			{
				ifvare holosphere 0 setvar tilenum CHAINGUN else setvar tilenum SLOWBULLET
				ifvarn myspawner -1 { setactor[myspawner].cstat 1 }
				spawn MUZZLEFLASHLOW
				sound M16FIRE
				shootvar tilenum
				ifvarn myspawner -1 { setactor[myspawner].cstat 257 }
			}
			else
			{
				sound PRED_ATTACK
				shoot FIRELASER
			}	    
          // }
		}

ends

state asatshootcode

setvar temp 0
ifvare lotag 1 setvar temp 1
ifvarg score 10000 setvar temp 1
ifvarn myspawner -1 setvar temp 0
ifvare temp 1 // fast version
{
	ifcount 8
      resetcount
    else
      ifcount 6
    {
      ifcount 7 nullop
      else
      {
	    state asatshooting
      }
    }
    else
      ifcount 2
    {
      ifcount 3 nullop
      else
      {
		 state asatshooting
      }
    }
}
else
{

    ifcount 32
      resetcount
    else
      ifcount 16
    {
      ifcount 17 nullop
      else
      {
	    state asatshooting
      }
    }
    else
      ifcount 4
    {
      ifcount 5 nullop
      else
      {
		 state asatshooting
      }
    }
}
ends

eventloadactor ROTATEGUN { getactor[THISACTOR].extra lotag setactor[THISACTOR].extra -1 } enda

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

actor ROTATEGUN ROTTURRETSTRENGTH
// ASATSHOOTING TURRVEL faceplayer

ifvarn myspawner -1
{
	ifvare countvar 0
	{
		spritepal 17
		setvar mtype 1
		state difficulty
		setvar countvar 1
	}
	setvar tempb 0
	getactor[myspawner].statnum temp
	getactor[myspawner].extra tempc
	ifvare temp 1024 setvar tempb 1
	getactor[myspawner].picnum tilenum
	ifvarn tilenum DRONEDEV setvar tempb 1 // in case the ID was stolen by something else
	ifvarl tempc 1 setvar tempb 1
	ifvare tempb 1
	{
		setactor[THISACTOR].htextra 50
		setactor[THISACTOR].htpicnum RPG
	}
	getactor[myspawner].x mx
	getactor[myspawner].y my
	getactor[myspawner].z mz
	subvar mz 1536
	cstat 265
	
	setvarvar xydist mx
	addvar xydist 320
	getactor[myspawner].ang angvar
	//ifvare countvarb 0 subvar angvar 512 else addvar angvar 512
	ifvare countvarb 0 subvar angvar 832 else addvar angvar 832
	rotatepoint mx my xydist my angvar x y
	
	setactor[THISACTOR].x x
	setactor[THISACTOR].y y
	setactor[THISACTOR].z mz
}

state setholotarg
state monsterai
  ifvarg menutoggle 0 break
  ifaction 0
  {
    action ASATSHOOTING
    ifvare lotag 1 move TURRVEL faceplayersmart else
    move TURRVEL faceplayer
    setvar mval TURRVAL
    //ifvarg score 1000
    ifrnd 128 ifvarg score 500 ifvare myspawner -1 ifvarn lotag 1
    { setvar mtype 1 spritepal 17 }
  }
  else
    ifaction ASATNSPIN
  {
	getactor[THISACTOR].ang angvar
	ifrnd 128 addvar angvar 64 else subvar angvar 64
	setactor[THISACTOR].ang angvar
    ifactioncount 32
    {
      action ASATWAIT
      ifvare lotag 1 move TURRVEL faceplayersmart else
      move TURRVEL faceplayer
    }
  }
  else
    ifaction ASATSHOOTING
  {
    ifactioncount 12
      ifrnd 32
    {
      action ASATWAIT
      move 0
    }
    state asatshootcode
    
  }
  else
    ifaction ASATWAIT
  {
    ifactioncount 64
      ifrnd 32
        ifp palive
          ifcansee
    {
      action ASATSHOOTING
      ifvare lotag 1 move TURRVEL faceplayersmart else
      move TURRVEL faceplayer
    }
  }
  ifhitweapon
  {
   state checkdart
    ifdead
    {
      addkills 1
      sound LASERTRIP_EXPLODE
      debris SCRAP1 15
      spawn EXPLOSION2
	  ifvarg mval 0 { state dropcoins state addscore }
      state clearlists
      killit
    }
    else
    {
      action ASATNSPIN
      debris SCRAP1 4
    }
    move 0
  }
enda

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

action TRANSFOWARD 0  6  1  1  2
action TRANSBACK   5  6  1 -1  2
actor TRANSPORTERSTAR 0 TRANSFOWARD
  ifspawnedby FREEZENOAIM spritepal 1
  ifaction TRANSFOWARD
  {
    ifactioncount 6
      action TRANSBACK
  }
  else
    ifactioncount 6
      killit
enda

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

state checkweight

setvar weight 0

getplayer[THISACTOR].gotweapon 1 temp
ifvare temp 1
{
	addvar weight 50
	getplayer[THISACTOR].ammo_amount 1 temp
	addvarvar weight temp
}

getplayer[THISACTOR].gotweapon 2 temp
ifvare temp 1
{
	addvar weight 150
	getplayer[THISACTOR].ammo_amount 2 temp
	mulvar temp 2
	addvarvar weight temp
}

getplayer[THISACTOR].gotweapon 3 temp
ifvare temp 1
{
	addvar weight 250
	getplayer[THISACTOR].ammo_amount 3 temp
	addvarvar weight temp
}

getplayer[THISACTOR].gotweapon 4 temp
ifvare temp 1
{
	addvar weight 300
	getplayer[THISACTOR].ammo_amount 4 temp
	mulvar temp 20
	addvarvar weight temp
}

getplayer[THISACTOR].ammo_amount 5 temp
ifvarg temp 0
{
	mulvar temp 25
	addvarvar weight temp
}

getplayer[THISACTOR].gotweapon 6 temp
ifvare temp 1
{
	addvar weight 250
	getplayer[THISACTOR].ammo_amount 6 temp
	mulvar temp 5 
	addvarvar weight temp
}

getplayer[THISACTOR].gotweapon 7 temp
ifvare temp 1
{
	addvar weight 350
	getplayer[THISACTOR].ammo_amount 7 temp
	mulvar temp 4 
	addvarvar weight temp
}

getplayer[THISACTOR].ammo_amount 8 temp
ifvarg temp 0
{
	mulvar temp 10
	addvarvar weight temp
}

getplayer[THISACTOR].gotweapon 9 temp
ifvare temp 1
{
	addvar weight 250
	getplayer[THISACTOR].ammo_amount 9 temp
	mulvar temp 2
	addvarvar weight temp
}

getplayer[THISACTOR].firstaid_amount temp
ifvarg temp 0
{
	mulvar temp 2
	addvarvar weight temp
}

getplayer[THISACTOR].jetpack_amount temp
ifvarg temp 0
{
	divvar temp 4
	addvarvar weight temp
}

ifvarand tipfield 4096 nullop else 
ifvarvarg weight MAXLOAD
ifvare tipdisplay 0 ifp palive ifvare ONCAR 0
{
	// WEIGHT LIMIT
	setvar menutoggle 4
	setvar tipdisplay 4096
	orvar tipfield 4096
	setvar messagetime 26
	globalsound EXITMENUSOUND
}


ends

move WEAPMOVE // used as var for initialization
move WEAPFLY 160

state moveweapon

ifmove 0
{
	 clipdist 64
	 ifvare holoweap 1 
	 {
		 getplayer[THISACTOR].ang angvar
		 setactor[THISACTOR].ang angvar
		 move WEAPFLY geth
	 }
	 else
	 move WEAPMOVE
}

ifcount 26 move WEAPMOVE

ends

state getcode
  ifactor ATOMICHEALTH
    globalsound GETATOMICHEALTH
  else
    globalsound DUKE_GET
  palfrom 16 0 32
  ifrespawn
  {
    move RESPAWN_ACTOR_FLAG
    spawn RESPAWNMARKERRED
    cstat 32768
  }
  else
    killit
ends

state getweaponcode

  state randgetweapsnds

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


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

state quikget
  ifactor ATOMICHEALTH
    globalsound GETATOMICHEALTH
  else
    globalsound DUKE_GET
  palfrom 16 0 32
  killit
ends

state quikweaponget
  state randgetweapsnds
  palfrom 32 0 32
  ifgotweaponce 1
    break
  killit
ends


actor STEROIDS
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk
      nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifpinventory GET_STEROIDS STEROID_AMOUNT
              ifcanseetarget
      {
        addinventory GET_STEROIDS STEROID_AMOUNT
        quote 37
	  
        ifspawnedby STEROIDS
          state getcode
        else
          state quikget
      }
enda

actor BOOTS
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk
      nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifpinventory GET_BOOTS BOOT_AMOUNT
              ifcanseetarget
      {
        addinventory GET_BOOTS BOOT_AMOUNT
        quote 6
        ifspawnedby BOOTS
          state getcode
        else
          state quikget
      }
enda

actor HEATSENSOR
  getplayer[THISACTOR].heat_amount temp
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk
      nullop
  else
    ifp palive
      ifcount 6
        ifpdistl RETRIEVEDISTANCE
          ifvarvarl temp gogglelimit
          // ifpinventory GET_HEATS HEAT_AMOUNT
            ifcanseetarget
      {
        // addinventory GET_HEATS HEAT_AMOUNT
        addvar temp 1200
        ifvarvarg temp gogglelimit setvarvar temp gogglelimit
	  setplayer[THISACTOR].heat_amount temp
        quote 101
        ifspawnedby HEATSENSOR
          state getcode
        else
          state quikget
      }
enda

actor SHIELD

 getplayer[THISACTOR].shield_amount hp
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            // ifpinventory GET_SHIELD SHIELD_AMOUNT
            ifvarvarl hp maxarmor
              ifcanseetarget
      {
        ifspawnedby PIGCOP
        {
          ifrnd 128
            // addinventory GET_SHIELD PIG_SHIELD_AMOUNT1
            addvar hp PIG_SHIELD_AMOUNT1
          else
            // addinventory GET_SHIELD PIG_SHIELD_AMOUNT2
            addvar hp PIG_SHIELD_AMOUNT2
          ifvarvarg hp maxarmor setvarvar hp maxarmor
          setplayer[THISACTOR].shield_amount hp
          quote 104
          sound KICK_HIT
          palfrom 24 0 32
          killit
        }
        else
          // addinventory GET_SHIELD SHIELD_AMOUNT
          addvar hp SHIELD_AMOUNT
          ifvarvarg hp maxarmor setvarvar hp maxarmor
          setplayer[THISACTOR].shield_amount hp
        quote 38
        ifspawnedby SHIELD
          state getcode
        else
          state quikget
      }
enda


actor AIRTANK
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifpinventory GET_SCUBA SCUBA_AMOUNT
              ifcanseetarget
      {
        addinventory GET_SCUBA SCUBA_AMOUNT
        quote 39
        ifspawnedby AIRTANK
          state getcode
        else
          state quikget
      }
enda

action HOLODUKE_FRAMES 0 4 1 1 8
actor HOLODUKE 0 HOLODUKE_FRAMES
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            /* ifpinventory GET_HOLODUKE HOLODUKE_AMOUNT */
              ifcanseetarget
      {
        /* addinventory GET_HOLODUKE HOLODUKE_AMOUNT */
        getplayer[THISACTOR].holoduke_amount temp
        addvar temp 1
        
        ifvarvarg temp holodukelimit break
        addvar temp 2399  
        ifvarvarg temp holodukelimit setvarvar temp holodukelimit
        setplayer[THISACTOR].holoduke_amount temp
        quote 51
        ifspawnedby HOLODUKE
          state getcode
        else
          state quikget
      }
enda

actor JETPACK
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifpinventory GET_JETPACK JETPACK_AMOUNT
              ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        addinventory GET_JETPACK JETPACK_AMOUNT
        quote 41
        ifspawnedby JETPACK
          state getcode
        else
          state quikget
      }
enda

actor ACCESSCARD
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
        ifpinventory GET_ACCESS 0
          break
        addinventory GET_ACCESS 1
        quote 43
        state getcode
      }
enda

actor AMMO
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        addammo PISTOL_WEAPON PISTOLAMMOAMOUNT
        quote 65
        ifspawnedby AMMO
          state getcode
        else
          state quikget
      }
 ifvarn currholo -1
 {
	 findnearactorz HOLOBOT RETRIEVEDISTANCE 8192 temp
	   ifvarn temp -1
		   {
		   getactorvar[temp].hammo2 tempb
		   addvar tempb PISTOLAMMOAMOUNT
		   setactorvar[temp].hammo2 tempb
		   setactorvar[temp].hammtarg -1
	          	   sound INSERT_CLIP
		   killit
		   }
  }
enda

actor FREEZEAMMO
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        addammo FREEZE_WEAPON FREEZEAMMOAMOUNT
        quote 66
        ifspawnedby FREEZEAMMO
          state getcode
        else
          state quikget
      }
      
 ifvarn currholo -1
 {
	 findnearactorz HOLOBOT RETRIEVEDISTANCE 8192 temp
	
	   ifvarn temp -1
		   {
			   getactorvar[temp].hammo10 tempb
			   addvar tempb FREEZEAMMOAMOUNT
			   setactorvar[temp].hammo10 tempb
			   setactorvar[temp].hammtarg -1
		       sound GETATOMICHEALTH
			   killit
		   }
 }
enda

actor SHOTGUNAMMO
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        addammo SHOTGUN_WEAPON SHOTGUNAMMOAMOUNT
        quote 69
        ifspawnedby SHOTGUNAMMO
          state getcode
        else
          state quikget
      }
      
    ifvarn currholo -1
	{
	  findnearactorz HOLOBOT RETRIEVEDISTANCE 8192 temp
	   
	   ifvarn temp -1
		{
		   getactorvar[temp].hammo3 tempb
		   addvar tempb SHOTGUNAMMOAMOUNT
		   setactorvar[temp].hammo3 tempb
		   setactorvar[temp].hammtarg -1
	       sound SHOTGUN_COCK
		   killit
		}
	}
      
enda

actor AMMOLOTS
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifcount 6
          ifpdistl RETRIEVEDISTANCE
            ifcanseetarget
      {
	   ifvarvarg weight MAXLOAD { quote 207 break }
       addammo PISTOL_WEAPON 48
        quote 65
        ifspawnedby AMMOLOTS
          state getcode
        else
          state quikget
      }
 ifvarn currholo -1
 {
   findnearactorz HOLOBOT RETRIEVEDISTANCE 8192 temp

   ifvarn temp -1
	{
	   getactorvar[temp].hammo2 tempb
	   addvar tempb 48
	   setactorvar[temp].hammo2 tempb
	   setactorvar[temp].hammtarg -1
       sound INSERT_CLIP
	   killit
	}
  }
enda

actor CRYSTALAMMO
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        addammo SHRINKER_WEAPON CRYSTALAMMOAMOUNT
        addammo GROW_WEAPON CRYSTALAMMOAMOUNT
        quote 78
        ifspawnedby CRYSTALAMMO
          state getcode
        else
          state quikget
      }
  ifvarn currholo -1
  {
    findnearactorz HOLOBOT RETRIEVEDISTANCE 8192 temp
    ifvarn temp -1
	{
	   getactorvar[temp].hammo7 tempb
	   addvar tempb CRYSTALAMMOAMOUNT
	   setactorvar[temp].hammo7 tempb
	   setactorvar[temp].hammtarg -1
           	   sound GETATOMICHEALTH
	   killit
	}
  }
enda

actor GROWAMMO
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        addammo GROW_WEAPON CRYSTALAMMOAMOUNT
        addammo SHRINKER_WEAPON CRYSTALAMMOAMOUNT
        quote 78
        ifspawnedby GROWAMMO
          state getcode
        else
          state quikget
      }
enda

actor BATTERYAMMO
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        addammo CHAINGUN_WEAPON CHAINGUNAMMOAMOUNT
          quote 63
        ifspawnedby BATTERYAMMO
          state getcode
        else
          state quikget
      }
 ifvarn currholo -1
 {
	 findnearactorz HOLOBOT RETRIEVEDISTANCE 8192 temp
	
	   ifvarn temp -1
		{
		   getactorvar[temp].hammo4 tempb
		   addvar tempb CHAINGUNAMMOAMOUNT
		   setactorvar[temp].hammo4 tempb
		   setactorvar[temp].hammtarg -1
	           sound INSERT_CLIP
		   killit
		}
  }
enda

actor DEVISTATORAMMO
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        addammo DEVISTATOR_WEAPON DEVISTATORAMMOAMOUNT
        quote 14
        ifspawnedby DEVISTATORAMMO
          state getcode
        else
          state quikget
      }

ifvarn currholo -1
{
	findnearactorz HOLOBOT RETRIEVEDISTANCE 8192 temp
   	ifvarn temp -1
	{
	   getactorvar[temp].hammo8 tempb
	   addvar tempb DEVISTATORAMMOAMOUNT
	   setactorvar[temp].hammo8 tempb
	   setactorvar[temp].hammtarg -1
         sound INSERT_CLIP
	   killit
	}
}

enda

actor RPGAMMO
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else ifp palive
      ifpdistl RETRIEVEDISTANCE
        ifcount 6
          ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        addammo RPG_WEAPON RPGAMMOBOX
        quote 64
        ifspawnedby RPGAMMO
          state getcode
        else
          state quikget
      }
  ifvarn currholo -1
  {
    findnearactorz HOLOBOT RETRIEVEDISTANCE 8192 temp

    ifvarn temp -1
	 {
	   getactorvar[temp].hammo5 tempb
	   addvar tempb RPGAMMOBOX
	   setactorvar[temp].hammo5 tempb
	   setactorvar[temp].hammtarg -1
           sound INSERT_CLIP
	   killit
	 }
  }
enda

actor HBOMBAMMO

  state moveweapon
  fall
  ifmove RESPAWN_ACTOR_FLAG state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
            
     {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        ifgotweaponce 0
          break

        ifvarn hweapcount 0
        {
	        addweapon HANDBOMB_WEAPON 0
	        getplayer[THISACTOR].ammo_amount 5 temp
	        ifvarg hweapcount 0 addvarvar temp hweapcount
	        ifvarg temp MAXHANDBOMBAMMO setvar temp MAXHANDBOMBAMMO
	        setplayer[THISACTOR].ammo_amount 5 temp
        }
        else
        addweapon HANDBOMB_WEAPON HANDBOMBBOX
        quote 55

        ifspawnedby HBOMBAMMO
          state getweaponcode
        else
          state quikweaponget
      }

enda

actor RPGSPRITE

  state moveweapon
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        ifgotweaponce 0
          break
		
        ifvarn hweapcount 0
        {
	        addweapon RPG_WEAPON 0
	        getplayer[THISACTOR].ammo_amount 4 temp
	        ifvarg hweapcount 0 addvarvar temp hweapcount
	        ifvarg temp MAXRPGAMMO setvar temp MAXRPGAMMO
	        setplayer[THISACTOR].ammo_amount 4 temp
        }
        else
        addweapon RPG_WEAPON RPGAMMOBOX
        quote 56
        ifspawnedby RPGSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
 
                         
enda

actor SHOTGUNSPRITE

  state moveweapon
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        ifspawnedby PIGCOP
        {
          addweapon SHOTGUN_WEAPON 0
          ifrnd 64
            addammo SHOTGUN_WEAPON 4
          else ifrnd 64
            addammo SHOTGUN_WEAPON 3
          else ifrnd 64
            addammo SHOTGUN_WEAPON 2
          else
            addammo SHOTGUN_WEAPON 1
        }
        else
        {
          ifgotweaponce 0
            break
          ifvarn hweapcount 0
          {
	        addweapon SHOTGUN_WEAPON 0
	        getplayer[THISACTOR].ammo_amount 2 temp
	        ifvarg hweapcount 0 addvarvar temp hweapcount
	        ifvarg temp MAXRPGAMMO setvar temp MAXSHOTGUNAMMO
	        setplayer[THISACTOR].ammo_amount 2 temp
           }
          else
          addweapon SHOTGUN_WEAPON SHOTGUNAMMOAMOUNT
          quote 57
        }

        ifspawnedby SHOTGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }

  ifvarn currholo -1
  {
    findnearactorz HOLOBOT RETRIEVEDISTANCE 8192 temp

     ifvarn temp -1
	 {
	   getactorvar[temp].hammo3 tempb
	   addvar tempb 5
	   setactorvar[temp].hammo3 tempb
	   setactorvar[temp].hammtarg -1
         sound SHOTGUN_COCK
	   killit
	 }
   }
enda



actor SIXPAK

  getplayer[THISACTOR].i temp
  getactor[temp].extra hp
  addvarvar hp pheal

  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            // ifphealthl MAXPLAYERHEALTH
             ifvarvarl hp maxhealth
              ifcanseetarget
      {
		  subvarvar hp pheal
	        // addphealth 30
		  setvarvar tempb maxhealth
	        subvarvar tempb hp
		  ifvarg tempb 30 addvar pheal 30 else addvarvar pheal tempb
	        quote 62
	        ifspawnedby SIXPAK
	          state getcode
	        else
	          state quikget
      }
enda

actor COLA  // aka small health boost
  
  getplayer[THISACTOR].i temp
  getactor[temp].extra hp
  addvarvar hp pheal

  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            // ifphealthl MAXPLAYERHEALTH
		 ifvarvarl hp maxhealth
              ifcanseetarget
      {
		  subvarvar hp pheal
	        // addphealth 10
		  setvarvar tempb maxhealth
	        subvarvar tempb hp
		  ifvarg tempb 10 addvar pheal 10 else addvarvar pheal tempb
	        quote 61
	        ifspawnedby COLA
	          state getcode
	        else
	          state quikget
      }
enda

actor ATOMICHEALTH

  getplayer[THISACTOR].i temp
  getactor[temp].extra hp
  addvarvar hp pheal

  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            // ifphealthl MAXPLAYERATOMICHEALTH
            ifvarvarl hp maxarmor

              ifcanseetarget
      {
	        // addphealth 50
	      subvarvar hp pheal
		  addvar hp 50
		  ifvarvarg hp maxarmor setvarvar hp maxarmor
	        setactor[temp].extra hp
	
	        quote 19
	        ifspawnedby ATOMICHEALTH
	          state getcode
	        else
	          state quikget
      }
enda




actor FIRSTAID
  fall
  getplayer[THISACTOR].firstaid_amount temp
  ifmove RESPAWN_ACTOR_FLAG state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
           ifvarvarl temp firstaidlimit    // don't add if kit already at 250 or more
            /* ifpinventory GET_FIRSTAID FIRSTAID_AMOUNT */
              ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        /* addinventory GET_FIRSTAID FIRSTAID_AMOUNT */
        addvar temp 100
        ifvarvarg temp firstaidlimit setvarvar temp firstaidlimit
        setplayer[THISACTOR].firstaid_amount temp
        quote 3

        ifspawnedby FIRSTAID
          state getcode
        else
          state quikget
      }
enda


actor FIRSTGUNSPRITE

  state moveweapon
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        ifgotweaponce 0
          break
        ifvarn hweapcount 0
        {
	        addweapon PISTOL_WEAPON 0
	        getplayer[THISACTOR].ammo_amount 1 temp
	        ifvarg hweapcount 0 addvarvar temp hweapcount
	        ifvarg temp MAXPISTOLAMMO setvar temp MAXPISTOLAMMO
	        setplayer[THISACTOR].ammo_amount 1 temp
         }
        else
        addweapon PISTOL_WEAPON 48
        ifspawnedby FIRSTGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
enda


actor TRIPBOMBSPRITE
  state moveweapon
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
       {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        ifgotweaponce 0
          break
		ifvarn hweapcount 0
		{
			addweapon TRIPBOMB_WEAPON 0
			getplayer[THISACTOR].ammo_amount 8 temp
			ifvarg hweapcount 0 addvarvar temp hweapcount
			ifvarg temp MAXTRIPBOMBAMMO setvar temp MAXTRIPBOMBAMMO
			setplayer[THISACTOR].gotweapon 8 1
			setplayer[THISACTOR].ammo_amount 8 temp
		}
        else
        addweapon TRIPBOMB_WEAPON 1
        quote 58
        ifspawnedby TRIPBOMBSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
enda

actor CHAINGUNSPRITE

  state moveweapon
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
       {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        ifgotweaponce 0
          break

        ifvarn hweapcount 0
        {
	        addweapon CHAINGUN_WEAPON 0
	        getplayer[THISACTOR].ammo_amount 3 temp
	        ifvarg hweapcount 0 addvarvar temp hweapcount
	        ifvarg temp MAXCHAINGUNAMMO setvar temp MAXCHAINGUNAMMO
	        setplayer[THISACTOR].ammo_amount 3 temp
        }
        else
        addweapon CHAINGUN_WEAPON 50
        quote 54
        ifspawnedby CHAINGUNSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
enda



actor SHRINKERSPRITE

  state moveweapon
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        ifgotweaponce 0
          break
        ifvarn hweapcount 0
        {
	        addweapon SHRINKER_WEAPON 0
	        getplayer[THISACTOR].ammo_amount 6 temp
	        ifvarg hweapcount 0 addvarvar temp hweapcount
	        ifvarg temp MAXSHRINKERAMMO setvar temp MAXSHRINKERAMMO
	        setplayer[THISACTOR].ammo_amount 6 temp
	        setplayer[THISACTOR].ammo_amount 11 temp
        }
        else
        addweapon SHRINKER_WEAPON 10
        getplayer[THISACTOR].ammo_amount 6 temp
        setplayer[THISACTOR].ammo_amount 11 temp
        quote 60
        ifspawnedby SHRINKERSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
enda

actor FREEZESPRITE

  state moveweapon
  fall
  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
      {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        ifgotweaponce 0
          break

        ifvarn hweapcount 0
        {
	        addweapon FREEZE_WEAPON 0
	        getplayer[THISACTOR].ammo_amount 9 temp
	        ifvarg hweapcount 0 addvarvar temp hweapcount
	        ifvarg temp MAXFREEZEAMMO setvar temp MAXFREEZEAMMO
	        setplayer[THISACTOR].ammo_amount 9 temp
        }
        else
        addweapon FREEZE_WEAPON FREEZEAMMOAMOUNT
        quote 59
        ifspawnedby FREEZESPRITE
          state getweaponcode
        else
          state quikweaponget
      }
enda

actor DEVISTATORSPRITE

  state moveweapon
  fall
  ifmove RESPAWN_ACTOR_FLAG state respawnit
  else
    ifp pshrunk nullop
    else
      ifp palive
        ifpdistl RETRIEVEDISTANCE
          ifcount 6
            ifcanseetarget
       {
	    ifvarvarg weight MAXLOAD { quote 207 break }
        ifgotweaponce 0
          break
        ifvarn hweapcount 0
        {
	        addweapon DEVISTATOR_WEAPON 0
	        getplayer[THISACTOR].ammo_amount 7 temp
	        ifvarg hweapcount 0 addvarvar temp hweapcount
	        ifvarg temp MAXDEVISTATORAMMO setvar temp MAXDEVISTATORAMMO
	        setplayer[THISACTOR].ammo_amount 7 temp
        }
        else
        addweapon DEVISTATOR_WEAPON DEVISTATORAMMOAMOUNT
        quote 87
        ifspawnedby DEVISTATORSPRITE
          state getweaponcode
        else
          state quikweaponget
      }
enda

action FIRE_FRAMES   -1 14 1 1 1
move FIREVELS

state firestate

  ifaction 0
    ifrnd 16
    {
      action FIRE_FRAMES
      cstator 128
    }

  sleeptime 300         // Never let it fall to sleep

  ifspawnedby FIRE
  {
    ifgapzl 16
      break
  }
  else
    ifspawnedby FIRE2
  {
    ifgapzl 16
      break
  }

  ifinwater
    killit

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

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

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

ends

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

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

      sound STEPNIT

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



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

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

state femcode

  state monsterai
  ifvarg menutoggle 0 break
  ifactor NAKED1 nullop
  else
    ifactor FEM6 nullop
    else
    {
      fall
      ifactor BLOODYPOLE
        ifhitweapon
          state checkdart
          ifdead
      {
        state standard_jibs
        killit
      }
    }

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

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

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

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

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
          break
      }

      lotsofglass 30

      sound GLASS_BREAKING
      ifrnd 84
        spawn BLOODPOOL
      respawnhitag

      ifrnd 128
        sound DUKE_HIT_STRIPPER1
      else
        sound DUKE_HIT_STRIPPER2

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

  ifhitweapon
  {
    state checkdart
    ifdead
    {
      ifwasweapon GROWSPARK
      {
        cstat 0
        move 0
        sound ACTOR_GROWING
        action FEMGROW
        break
      }
      else ifwasweapon FREEZEBLAST
      {
        ifaction FEMSHRUNK
          break

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

        move 0
        spritepal 1
        strength 0

        sound SOMETHINGFROZE

        break
      }

      ifrnd 128
        sound DUKE_HIT_STRIPPER1
      else
        sound DUKE_HIT_STRIPPER2

      respawnhitag
      state standard_jibs
      state random_wall_jibs
      spawn BLOODPOOL

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

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

      ifactor TOUGHGAL
          state toughgalspeech
      else sound SQUISHED

      guts JIBS6 1
    }
  }
ends

state killme
  ifinwater nullop
  else
    ifp pfacing
      ifpdistl 1280
        ifhitspace
          soundonce KILLME
  ifcount 320 ifcansee ifrnd 1 ifrnd 8
	{
		sound LADY_SCREAM guts JIBS6 5
		spawn BLOODPOOL
		espawn NEWBEAST
		setactor[RETURN].xrepeat 20
		setactor[RETURN].yrepeat 20
		setactor[RETURN].pal 17
		setactor[RETURN].extra 75
		setactor[RETURN].cstat 257
		setactorvar[RETURN].mtype 1
		setactorvar[RETURN].mval BABYVAL
		killit
	}
ends

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

state toughgaltalk
  ifp pfacing
    ifpdistl 1280
      ifhitspace
        state toughgalspeech
ends

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

actor TOUGHGAL MANWOMANSTRENGTH TOUGHGALANIM
  state toughgaltalk
  state femcode
enda

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

actor MIKE
  ifp pfacing
    ifpdistl 1280
      ifhitspace
        mikesnd
enda





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

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

actor EGG TOUGH
  fall
  state monsterai
  ifvarg menutoggle 0 break
state setholotarg
  ifaction 0
  {
    ifvare mval -1 nullop else setvar mval EGGVAL
    ifcount 64
    {
      ifrnd 128
      {
        action EGGWAIT
        move 0
      }
      else
      {
        sound SLIM_HATCH
        action EGGOPEN1
      }
    }
  }
  else
    ifaction EGGOPEN1
      ifactioncount 4
        action EGGOPEN2
  else
    ifaction EGGOPEN2
      ifactioncount 4
    {
      spawn GREENSLIME
      action EGGOPEN3
    }
  else
    ifaction EGGGROW
      state genericgrowcode
  else
    ifaction EGGSHRUNK
      state genericshrunkcode
  else
    ifaction EGGFROZEN
  {
    ifcount THAWTIME
    {
      action 0
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      state checkdart
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      lotsofglass 30
      spritepal 22
      state standard_jibs

      sound GLASS_BREAKING
      ifrnd 84
        spawn BLOODPOOL

      addkills 1
      state clearlists
      killit
    }

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

    break
  }

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

      addkills 1

      sound SQUISHED
      ifvarg mval 0 { state dropcoins state addscore }
      state standard_jibs
      state clearlists
      killit
    }
    else
      ifwasweapon SHRINKSPARK
      {
        move 0
        sound ACTOR_SHRINKING
        action EGGSHRUNK
        break
      }

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

enda

state spawnspider

espawn SPIDERX
randvar temp 4
ifvare temp 0 setactor[RETURN].pal 1
ifvare temp 1 setactor[RETURN].pal 2
ifvare temp 2 setactor[RETURN].pal 4
ifvare temp 3 setactor[RETURN].pal 8
// temp 4 = pal 0 spider
getplayer[THISACTOR].max_actors_killed temp
addvar temp 1
setplayer[THISACTOR].max_actors_killed temp

ends

action INVISEGGOPEN1 -199 1 1 1 4
action INVISEGGOPEN2 -198 1 1 1 4
action INVISEGGOPEN3 -198 1 1 1 4
action INVISEGGWAIT  -200
action INVISEGGSTART -200
action INVISEGGFROZEN -199
action INVISEGGGROW -199
action INVISEGGSHRUNK -199


useractor notenemy INVISEGG TOUGH INVISEGGSTART
  fall
  ifaction INVISEGGSHRUNK nullop else ifvare mtype 0 sizeto 32 32
  ifvare goggles 1
  {
    cstat 257
    state monsterai
    ifvarg menutoggle 0 break
    state setholotarg
  }
   else cstat 32768

  ifaction INVISEGGSTART
  {
	ifvare hammo2 0
	{
		setvar hammo2 1
		ifrnd 128
		{
			randvar temp 30000
			ifvarvarl temp score
			{
				setvar mtype 1
				strength 200
				sizeat 64 64
			}
		}
		ifvare mtype 0 setvar mval INVISEGGVAL
		else setvar mval PIGVAL
	}
    ifvare goggles 0 { resetcount break }
    ifcount 64 ifcanseetarget
    {
      ifrnd 128
      {
        action INVISEGGWAIT
        move 0
      }
      else
      {
	    ifvare goggles 1
        sound SLIM_HATCH
        action INVISEGGOPEN1
      }
    }
  }
  else
    ifaction INVISEGGOPEN1
      ifactioncount 4
        action INVISEGGOPEN2
  else
    ifaction INVISEGGOPEN2
      ifactioncount 4
    {
      ifvarg score 500 ifrnd 32
      {
        espawn EVILDUKE
	  	setactorvar[RETURN].mtype 1
	  	ifvare mtype 1
	  	{
		  	espawn EVILDUKE
		  	setactorvar[RETURN].mtype 1
	  	}
	  }

		else 
		{
			state spawnspider
			ifvare mtype 1 state spawnspider
			ifvare mtype 1 state spawnspider
		
		}
      	action INVISEGGOPEN3
    }
  else
    ifaction INVISEGGGROW
      state genericgrowcode
  else
    ifaction INVISEGGSHRUNK
      state genericshrunkcode
  else
    ifaction INVISEGGFROZEN
  {
    ifcount THAWTIME
    {
      action INVISEGGOPEN3
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
       state checkdart
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      lotsofglass 30
	  spritepal 22
      state standard_jibs
      sound GLASS_BREAKING
      ifrnd 84
        spawn BLOODPOOL

      // addkills 1
      state clearlists
      killit
    }

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

    break
  }

  ifhitweapon
  {
    state checkdart
    ifdead
    {
      ifwasweapon FREEZEBLAST
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action INVISEGGFROZEN
        strength 0
        break
      }
      else
        ifwasweapon GROWSPARK
      {
        cstat 0
        move 0
        sound ACTOR_GROWING
        action INVISEGGGROW
        break
      }

      // addkills 1

      sound SQUISHED
      // ifvarg mval 0 { state dropcoins state addscore }
      state standard_jibs
      state clearlists
      killit
    }
    else
      ifwasweapon SHRINKSPARK
      {
	 /*
        move 0
        sound ACTOR_SHRINKING
        action INVISEGGSHRUNK
        break
	 */
	 // addkills 1

      sound SQUISHED
      // ifvarg mval 0 { state dropcoins state addscore }
      state standard_jibs
      state clearlists
      killit

      }

      ifwasweapon GROWSPARK
        sound EXPANDERHIT
  }
  else
    ifaction INVISEGGWAIT
  {
    ifcount 260
      ifrnd 2
    {
      ifaction INVISEGGSHRUNK
        break
      sound SLIM_HATCH
      action INVISEGGOPEN1
    }
  }

enda

actor KNEE KNEE_WEAPON_STRENGTH enda
actor SPIT SPIT_WEAPON_STRENGTH enda
actor CHAINGUN CHAINGUN_WEAPON_STRENGTH enda
actor SHOTGUN SHOTGUN_WEAPON_STRENGTH enda
actor FIRELASER FIRELASER_WEAPON_STRENGTH enda
actor HEAVYHBOMB HANDBOMB_WEAPON_STRENGTH enda
actor BOUNCEMINE BOUNCEMINE_WEAPON_STRENGTH enda
actor MORTER MORTER_WEAPON_STRENGTH enda
actor SHRINKSPARK SHRINKER_WEAPON_STRENGTH enda

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

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

state getfloordist
  getactor[THISACTOR].x x
  getactor[THISACTOR].y y
  updatesector x y mysector
  getflorzofslope mysector x y z
  getactor[THISACTOR].z temp
  subvarvar z temp
  shiftvarr z 8
  subvar z 1
ends

action WEAP2FRAMES 0  4  1  1  6
actor SHOTSPARK1 PISTOL_WEAPON_STRENGTH WEAP2FRAMES
  ifdead
    killit
  ifactioncount 4
    killit
  else
  {
    ifactioncount 3
    {
      ifinwater
      spawn WATERBUBBLE
    }
    else
      ifcount 2 nullop
      else
        ifonwater
          spawn WATERSPLASH2
  }

 ifspawnedby FLAK sizeat 16 16 else
 {
    // ifactioncount 3 spawn NEWSMOKE
    ifcount 1 nullop
    else
	{
		ifspawnedby APLAYER nullop else
		ifcansee
	 	setvar barriergrow 78
	 	
	    getactor[THISACTOR].owner temp
	    ifvare temp -1 break
	    getactorvar[temp].holoweap tempb
	    ifvare tempb 15 break
	       
		getactor[THISACTOR].htg_t 6 hitwall
		ifvarn hitwall -1
		{
			getwall[hitwall].picnum FLOORTEX
			state CHECKSTEPS
			state BULLETHITSOUNDS
			ifvare FLOORTEX 638 
			{
				sound GLASS_HEAVYBREAK 
				lotsofglass 15 
				setwall[hitwall].picnum 358 
			}
			
		}
		else
		state getfloordist
		ifvarl z 0
		{
			getsector[THISACTOR].floorpicnum FLOORTEX
			state CHECKSTEPS
			state BULLETHITSOUNDS
			ifvare FLOORTEX W_TECHWALL1 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].floorpicnum 363 }
			ifvare FLOORTEX W_TECHWALL2 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].floorpicnum 362 }
			ifvare FLOORTEX W_TECHWALL3 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].floorpicnum 360 }
			ifvare FLOORTEX W_TECHWALL4 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].floorpicnum 361 }
			ifvare FLOORTEX 5645 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].floorpicnum 5638 }
		}
		else
		ifceilingdistl 3
		{
			getsector[THISACTOR].ceilingpicnum FLOORTEX
			state CHECKSTEPS
			state BULLETHITSOUNDS
			ifvare FLOORTEX W_TECHWALL1 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].ceilingpicnum 363 }
			ifvare FLOORTEX W_TECHWALL2 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].ceilingpicnum 362 }
			ifvare FLOORTEX W_TECHWALL3 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].ceilingpicnum 360 }
			ifvare FLOORTEX W_TECHWALL4 { sound VENT_BUST debris SCRAP1 8 setsector[THISACTOR].ceilingpicnum 361 }
		}
		
	  
	  getactor[THISACTOR].htg_t 8 temp // temp = hitsprite
	  ifvarn temp -1
	  {
	       getactor[temp].picnum tilenum
	       switch tilenum
	       case PIGCOP
	       case PIGCOPDIVE
	       case LIZTROOP
	       case LIZTROOPDUCKING
	       case LIZMAN
	       case COMMANDER
	       case OCTABRAIN
	       case NEWBEAST
	       case APLAYER
	       case BOSS1
	       case BOSS2
	       case BOSS3
	       case BOSS4
	       case MINIBOSS2
	       case MINIBOSS4
	       case EVILDUKE
	       sound HITFLESH
	       break
	       endswitch
	   }
       
	}
 }
 
enda


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

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

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

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

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

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

action PSKICKING 40 2 5 1 20

move PSTOPED
move PSHRINKING // used as a var only

state check_pstandard

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



move PGROWINGPOP        // Used only as a variable
move JETBOOST 512 0


state throwholoproj

	setvar eventholodukeon 0
	getplayer[THISACTOR].holoduke_amount temp
     ifvarn currholo -1
	{
		ifvarg temp 24
		{
			mulvar temp 2
			divvarvar temp holomult // 100% holoduke_amount adds 240 hp at holomult = 20
			getactor[currholo].extra tempb
			addvarvar tempb temp
			setactor[currholo].extra tempb
			setplayer[THISACTOR].holoduke_amount 0
			sound INTRUDER_ALERT
			palfrom 24 63 63 63
		}
	}

     else
	{
	
		ifvarg temp 599
		{
			setplayer[THISACTOR].holoduke_amount 0
			sound BONUS_SPEECH1
			mulvar temp 2
			divvarvar temp holomult // 100% holoduke_amount = 2400 = 240 hp at holomult 20
			setvarvar holostrength temp
			shoot HOLOPROJ		
		}
		else quote 49
	}
ends

state monstmakebarrier
ifvarn barrierup -1 break
	espawn BARRIER
	setactorvar[RETURN].myspawner THISACTOR
	setvarvar barrierup RETURN
	sound TELEPORTER

ends

state makebarrier
	
ifvare barrierup -1 ifvarg barrierlevel 0 ifvare menutoggle 0 ifvare ONCAR 0
{
	setvar temp 1
	addvarvar temp barrierlevel
	ifvarvarg nukepart temp
	{
		espawn BARRIER
		setactorvar[RETURN].myspawner THISACTOR
		setvarvar barrierup RETURN
		sound TELEPORTER
		setvar temp 2
		addvarvar temp barrierlevel
		subvarvar nukepart temp
		setvar btap 0
	}
}

ends

state recoil

getplayer[THISACTOR].horiz temp
ifvarg hammo3 0
{
	addvar temp 2
	subvar hammo3 2
	setplayer[THISACTOR].horiz temp
}
else ifvarg hammo4 0
{
	ifvarvarg temp hammo2 // if current horiz higher than goal horiz
	{
		subvar temp 1
		subvar hammo4 1
		setplayer[THISACTOR].horiz temp
	}
	else
	{ 
		setvar hammo4 0
		setvar hammo5 -1
	}
}
else 
	setvar hammo5 -1 


ends

state soulsearch

	setvar soultime 0
	findnearsprite SKILLCOIN 2048 spriteid
	ifvare spriteid -1
	findnearsprite SKILLCOIN 4096 spriteid
	ifvare spriteid -1
	findnearsprite SKILLCOIN 8192 spriteid
	ifvare spriteid -1
	findnearsprite SKILLCOIN 12288 spriteid
	ifvare spriteid -1
	findnearsprite SKILLCOIN 16384 spriteid
	ifvare spriteid -1
	findnearsprite SKILLCOIN 32768 spriteid
	ifvare spriteid -1 
	findnearsprite SKILLCOIN 65536 spriteid
	
ends

state raincode

ifvarl framerate 10 break

setvar lotag 0
setvarvar hitag raining
ifvarl hitag 0 mulvar hitag -1
ifvarvarg hitag framerate setvarvar hitag framerate

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

ends


actor APLAYER MAXPLAYERHEALTH PSTAND 0 0


ifvarn ONCAR 0
{
	cstator 32768
	getactor[THISACTOR].htextra temp
	ifvarg temp 0
	{
		shiftvarr temp 1
		ifvare temp 0 setvar temp 1
		setactor[THISACTOR].htextra temp
	}
	getuserdef[THISACTOR].god temp
	ifvare temp 1 quote 18
	setuserdef[THISACTOR].god 0
	ifvarn ONCAR 0 

	getplayer[THISACTOR].over_shoulder_on temp
	ifvare temp 0 setvar lastcameradist 0 else
	{
		ifvarl lastcameradist 65536 addvar lastcameradist 3072
		ifvarg lastcameradist 65536 setvar lastcameradist 65536
	}
}
else setvar lastcameradist 0

ifvare startflag 1
{
	setvar clearlocators 1
	setvar temp GAMETIPS
	ifvare temp NO setvar tipfield 131071
	setvar barrierup -1
	setvar dodgeagain 0
	setvar hammo2 -1
	setvar hammo3 -1
	setvar hammo4 -1
	setvar hammo5 -1
	setvar hammo7 0
	setvar hammo8 0
	setvar nukehold 0
	setvar nukecount 0
	getuserdef[THISACTOR].player_skill temp
	ifvare temp 4
	{
		setplayer[THISACTOR].gotweapon 2 1
		setplayer[THISACTOR].ammo_amount 2 10
		setvar weap0lev 100
		setvar weap1lev 100
		setvar weap2lev 100
		setvar weap3lev 100
		setvar weap4lev 100
		setvar weap5lev 100
		setvar weap6lev 100
		setvar weap7lev 100
		setvar weap8lev 100
		setvar weap9lev 100
	}

	ifvarn currholo -1 
	{ 
		setvar currholo -1
		mulvarvar holostore holomult
		divvar holostore 2
		getplayer[THISACTOR].holoduke_amount temp
		addvarvar temp holostore
		setplayer[THISACTOR].holoduke_amount temp
		setvar holostore 0
	}

	// just in case steroids were on at the end of the last level
	setvar WEAPON1_TOTALTIME 6
	setvar WEAPON1_RELOAD 27
	setvar WEAPON2_TOTALTIME 31
	setvar WEAPON2_SPAWNTIME 24
	setvar WEAPON3_SHOTSPERBURST 0
	setvar WEAPON4_TOTALTIME 20
	ifvare VOLUME 6 setplayer[THISACTOR].jetpack_amount 0
	setvar startflag 2
	setplayer[THISACTOR].auto_aim 0
	ifvarn ONCAR 0 setplayer[THISACTOR].knuckle_incs 0
}

ifvarn raining 0 ifvare menutoggle 0 state raincode

// end level check


// player invincible at beginning of level until menu turned off

ifvare startflag 2
{
	ifvare menutoggle 0 setvar startflag 3
	getplayer[THISACTOR].last_extra temp
	getactor[THISACTOR].extra tempb
	ifvarvarl tempb temp setactor[THISACTOR].extra temp
	
}

ifvarand tipfield 1 nullop else ifvare tipdisplay 0 ifvare ONCAR 0 ifp palive
{
	setvar menutoggle 4
	setvar tipdisplay 1
	orvar tipfield 1
	setvar messagetime 26
}
	
getplayer[THISACTOR].curr_weapon tempb
ifvare tempb 9
{
	ifvarg special9 0
	{
		getplayer[THISACTOR].kickback_pic temp
		ifvare temp 3 
		{
			subvar special9 1
			ifvare special9 0 state normalfreezer
		}
	}
}
state weaplevel

state checkweight
ifvarg gunally 0 subvar gunally 1
ifvarg fireinmap 0 subvar fireinmap 1
ifvarg messagetime 0
{
	subvar messagetime 1
	ifvarand tipfield 512 nullop else 
	ifvare message 215 ifvare messagetime 0
	ifvare tipdisplay 0 ifvare ONCAR 0 ifp palive
	{
		setvar menutoggle 4
		setvar tipdisplay 512
		orvar tipfield 512
		setvar messagetime 26
	}
}
//setuserdef[THISACTOR].angleinterpolation 0

ifp prunning nullop else ifvarl stamina MAXSTAMINA
{
	ifrnd 60 addvar stamina 1
	ifvarg limits 0 ifrnd 72 addvar stamina 1
}

ifvarg limits 0
{
	getplayer[THISACTOR].airleft temp
	ifvarl temp 390 ifrnd 128 { addvar temp 1 setplayer[THISACTOR].airleft temp }
}

getplayer[THISACTOR].boot_amount temp
ifvarvarn temp lastbootamount 
{
	ifvarvarl temp lastbootamount setvar boot_on 26
	setvarvar lastbootamount temp  
}
ifvare leglevel 4 setplayer[THISACTOR].boot_amount 200
ifvarg boot_on 0 subvar boot_on 1

ifvarg superkicking 0
{
	ifvare superkicking 1 { getplayer[THISACTOR].posz initz addvar initz 1536 }
	getplayer[THISACTOR].posz z
	ifvarvarl z initz
	setplayer[THISACTOR].posz initz
	
	ifvare spinkick 1 ifvare superkickdone 0
	{
		getplayer[THISACTOR].oang angvar
		addvar angvar 194
		setplayer[THISACTOR].ang angvar
	}
	
	ifvare superkickdone 1 ifvarl superkicking 4 nullop else
	{
		getplayer[THISACTOR].rotscrnang temp
		subvar temp 36
		setplayer[THISACTOR].rotscrnang temp
	}
	ifvare superkickdone 0 
	{
		addvar superkicking 1
		ifvare superkicking 10 
		{
			ifvarn barrierup -1 setactor[barrierup].cstat 2
				shoot SUPERKICK // for breaking objects
		}
		ifvarg superkicking 7 ifvare spinkick 1
		{
			ifvarn barrierup -1 setactor[barrierup].cstat 2
				shoot SUPERKICK // for breaking objects
		}
		ifvare superkicking 7 ifvare kickimpact 0 sound KICKOUT
	}
	else 
	{ 
		subvar superkicking 1
		ifvare superkicking 0 setvar kickimpact 0
	}
	ifvare superkicking 0 { setvar superkickdone 0 setvar spinkick 0 }
	ifvarg superkicking 11 setvar superkickdone 1
}

ifvarvarg score lastscoredisp addvar lastscoredisp 1
getplayer[THISACTOR].heat_on goggles

ifvarg pipefire 0 subvar pipefire 1

// nuke combo key press counting code (see also code in moving events)
ifvarg bhold 7 { setvar btap 0 setvar bhold 0 }
ifvarg fhold 7 { setvar ftap 0 setvar fhold 0 }
ifvarg lhold 7 { setvar ltap 0 setvar lhold 0 }
ifvarg rhold 7 { setvar rtap 0 setvar rhold 0 }

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

getplayer[THISACTOR].player_par timer

ifvare timer 2
{
	setvar mapstarted 0
	setvar camerasprite -1
}


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

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

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

setvarvar tempb timer
subvarvar tempb rpresstime
ifvarg tempb 6 setvar rtap 0
// end of key press code

addvar menubackang 1
ifvarg menubackang 2047 setvar menubackang 0


ifvarg menutoggle 0
{
	setactor[THISACTOR].htextra -1
	setvarvar tempb timer
	subvarvar tempb holotime
	ifvare tempb 5 
	{ 
		addvar holoframe 1 
		ifvare holoframe 1352 setvar holoframe 1348 
		setvarvar holotime timer 
	}	
	
	setplayer[THISACTOR].movement_lock 31
		
	getplayer[THISACTOR].ang temp
	getplayer[THISACTOR].oang tempb
	ifvarvarn temp tempb ifvarvarn temp mouseox
	{
	  setvarvar angvar temp
	  subvarvar angvar mouseox
	  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 tempb angvar

	  mulvar angvar 100
	  divvar angvar 420
	  ifvare angvar 0 { ifvarg tempb 0 setvar angvar 1 ifvarl tempb 0 setvar angvar -1 }
	  setvarvar mousex angvar
	}
	 else setvar mousex 0
	
	getplayer[THISACTOR].horiz temp // mousey
	getplayer[THISACTOR].ohoriz tempb
	ifvarvarn temp tempb ifvarvarn temp mouseoy
	{
	  setvarvar tempc temp
	  subvarvar tempc mouseoy
	  setvarvar tempd tempc
	  //divvar tempc 2
	  ifvare tempc 0 { ifvarg tempd 0 setvar tempc 1 ifvarl tempd 0 setvar tempc -1 }
	  getuserdef[THISACTOR].mouseflip tempd
	  ifvare tempd 0 setvar tempd 1 else setvar tempd -1
	  mulvarvar tempc tempd
	  setvarvar mousey tempc
	}
	 else setvar mousey 0
	
	ifvarn menutoggle 4
	{
		setplayer[THISACTOR].ang mouseox
		setplayer[THISACTOR].horiz mouseoy
	}
	
	  ifvare menutoggle 1
	  {
		 ifvarg mcoordx 145 ifvarl mcoordx 175 ifvarg mcoordy 5 ifvarl mcoordy 25
		  setvar menuitem 1 // first menu choice: increase max health
		 else
		 ifvarg mcoordx 225 ifvarl mcoordx 255 ifvarg mcoordy 25 ifvarl mcoordy 45
		  setvar menuitem 2 // second menu choice:  increase holobot health multiplier
		 else
		 ifvarg mcoordx 250 ifvarl mcoordx 280 ifvarg mcoordy 75 ifvarl mcoordy 95
		  setvar menuitem 3 // third menu choice: incrase maximum ammo
		 else
		 ifvarg mcoordx 240 ifvarl mcoordx 270 ifvarg mcoordy 120 ifvarl mcoordy 140
		  setvar menuitem 4 // fourth menu choice: leg upgrades
		 else
		 ifvarg mcoordx 195 ifvarl mcoordx 225 ifvarg mcoordy 155 ifvarl mcoordy 175
		  setvar menuitem 5 // fifth menu choice: reduce damage
		 else
		 ifvarg mcoordx 95 ifvarl mcoordx 125 ifvarg mcoordy 155 ifvarl mcoordy 175
		  setvar menuitem 6 // sixth menu choice:  upgrade limits
		 else
		 ifvarg mcoordx 50 ifvarl mcoordx 80 ifvarg mcoordy 120 ifvarl mcoordy 140
		  setvar menuitem 7 // seventh menu choice:  upgrade force barrier
		 else
		 ifvarg mcoordx 40 ifvarl mcoordx 70 ifvarg mcoordy 75 ifvarl mcoordy 95
		  setvar menuitem 8 // eighth menu choice:  toggle gore effects
		 else
		 ifvarg mcoordx 65 ifvarl mcoordx 95 ifvarg mcoordy 25 ifvarl mcoordy 45
		  setvar menuitem 9 // ninth menu choice:  upgrade goggles
		 else
		 ifvarg mcoordx 275 ifvarl mcoordx 305 ifvarg mcoordy 165 ifvarl mcoordy 185
		  setvar menuitem 10 // high scores
		 else
		 ifvarg mcoordx 5 ifvarl mcoordx 40 ifvarg mcoordy 20 ifvarl mcoordy 60
		  setvar menuitem 11 // help screen
		 else setvar menuitem 0 // no item selected
	  }
	 
	  ifvarvarn menuitem omenuitem sound EXITMENUSOUND
	  setvarvar omenuitem menuitem
	  
	ifvarg mousex 0 
	{
	  ifvarg mousey 0
	  {
		  ifvarl cursorang 768 addvar cursorang 32 else
		  ifvarg cursorang 1792 addvar cursorang 32 else
		  ifvarn cursorang 768 subvar cursorang 32
	  }
	  else ifvare mousey 0
	  {
		   ifvarl cursorang 512 addvar cursorang 32 else
		   ifvarg cursorang 1536 addvar cursorang 32 else
		   ifvarn cursorang 512 subvar cursorang 32
	  }
	  else ifvarl mousey 0
	  {
		   ifvarl cursorang 256 addvar cursorang 32 else
		   ifvarg cursorang 1280 addvar cursorang 32 else
		   ifvarn cursorang 256 subvar cursorang 32
	  }
	}
	else ifvarl mousex 0
	{
	  ifvarl mousey 0
	  {
		   ifvarg cursorang 1792 subvar cursorang 32 else
		   ifvarl cursorang 768 subvar cursorang 32 else
		   ifvarn cursorang 1792 addvar cursorang 32
	  }
	  else ifvare mousey 0
	  {
		   ifvarg cursorang 1536 subvar cursorang 32 else
		   ifvarl cursorang 512 subvar cursorang 32 else
		   ifvarn cursorang 1536 addvar cursorang 32
	  }
	  else ifvarg mousey 0
	  {
		    ifvarg cursorang 1280 subvar cursorang 32 else
		    ifvarl cursorang 256 subvar cursorang 32 else
		    ifvarn cursorang 1280 addvar cursorang 32
	  }
	}
	else ifvare mousex 0
	{
		ifvarl mousey 0 ifvarn cursorang 0
		{
			  ifvarl cursorang 1024 subvar cursorang 32 else
			  addvar cursorang 32
		}
		else ifvarg mousey 0 ifvarn cursorang 1024
		{
			 ifvarl cursorang 1024 addvar cursorang 32 else
			 subvar cursorang 32
		}
	}
	 
	ifvarg cursorang 2047 subvar cursorang 2048
	ifvarl cursorang 0 addvar cursorang 2048

  	 addvarvar mcoordx mousex
	 addvarvar mcoordy mousey
	 ifvarl mcoordx 0 setvar mcoordx 0
	 ifvarg mcoordx 320 setvar mcoordx 320
	 ifvarl mcoordy 0 setvar mcoordy 0
	 ifvarg mcoordy 200 setvar mcoordy 200
	  
}
	
else 
{
 ifvare noreccam 0
 setplayer[THISACTOR].movement_lock 0
 else setplayer[THISACTOR].movement_lock 31
 
 setvarvar holotime timer
 
 ifvare dodge 0 ifvarg leglevel 0 ifvarg stamina 65
   ifp palive
     ifvarvarg timer dodgeagain
   {
	   setvar temp 0
	   ifp ponground setvar temp 1
	   
	   ifvare ltap 2
	   {
		  getplayer[THISACTOR].ang dodgeang
		  subvar dodgeang 512
		  ifvare temp 0
		  {
			   setvarvar angvar dodgeang
			   addvar angvar 1024
			   state checkwall
			   ifvare temp 1 setvar walljump 1
		  }
		  ifvare temp 1
		  {  
			 subvar stamina 52
		     setvar dodge 10
		     sound DUKE_GRUNT
	      }
	   }
	   ifvare rtap 2
	   {
		  getplayer[THISACTOR].ang dodgeang
		  addvar dodgeang 512
		  ifvare temp 0
		  {
			   setvarvar angvar dodgeang
			   addvar angvar 1024
			   state checkwall
			   ifvare temp 1 setvar walljump 1
		  }
		  ifvare temp 1
		  {
			 subvar stamina 52
		     setvar dodge 10
		     sound DUKE_GRUNT
	      }
	   }
	   ifvare ftap 2
	   {
		  getplayer[THISACTOR].ang dodgeang
		  ifvare temp 0
		  {
			    setvarvar angvar dodgeang
			    addvar angvar 1024
			    state checkwall
			    ifvare temp 1 setvar walljump 1
		  }
		  ifvare temp 1
		  {
			 subvar stamina 52
		     setvar dodge 10
		     sound DUKE_GRUNT 
	      }
	   }
	   ifvare btap 2
	   {
		  getplayer[THISACTOR].ang dodgeang
		  addvar dodgeang 1024
		  ifvare temp 0
		  {
			    setvarvar angvar dodgeang
			    addvar angvar 1024
			    state checkwall
			    ifvare temp 1 setvar walljump 1
		  }
		  ifvare temp 1
		  {
			 subvar stamina 52
		     setvar dodge 10
		     sound DUKE_GRUNT
	      }
	   }
   }
 
}
 
ifvarg dodge 0
{
	 cos xvel dodgeang
     sin yvel dodgeang
     ifvarg leglevel 2 ifvare spinkick 0
     {
           mulvar xvel 352 //384
           mulvar yvel 352 //384
     }
     else
     {
	     ifvare spinkick 1
	     {
		     shiftvarl xvel 7
		     shiftvarl yvel 7
	     }
	     else
	     {
		     shiftvarl xvel 8
		     shiftvarl yvel 8
	     }
     }
	 ifvare walljump 1
	 setplayer[THISACTOR].poszv -1536
	 setplayer[THISACTOR].posxv xvel
	 setplayer[THISACTOR].posyv yvel
	 subvar dodge 1
	 ifvare dodge 0 
     { 
	       setvarvar dodgeagain timer
	       ifp ponground addvar dodgeagain 18
	       setvar walljump 0
	 }
}

setvarvar scanned hitsprite // set the player's scanned value to the previous value of hitsprite; for the player, scanned holds the last sprite he scanned
state checkhitscan
ifvarn hitsprite -1
{
    getactor[hitsprite].picnum temp
    //ifvare temp INVISEGG ifvare goggles 0 setvar hitsprite -1 else
     setactorvar[hitsprite].scanned 1 // scanned is boolean set when scanned by player
}
ifvarn scanned -1 ifvarvarn scanned hitsprite setactorvar[scanned].scanned -1 
// if the last scan hit a sprite and the current scan hit something else, then tell the old sprite it is no longer being scanned


ifvare holosphere 0 ifvarg ftap 1 ifvare btap 2 ifvarg nukepart 2 ifvarg combolevel 3 ifp ponground
{
		state holosphereon
		subvar nukepart 3
		setvar ftap 0
		setvar btap 0
}

ifvarg holosphere 0
{
	 soundonce BUZZ
	 palfrom 5 50 50 63
	 subvar holosphere 1
	 ifvare holosphere 0 sound NITEVISION_ONOFF  
}


ifvarn target -1 ifvare spinkick 0
{
  getactor[target].statnum temp
  getactor[target].extra hp
  ifp pshrunk setvar target -1
  ifvarn temp 1 setvar target -1
  ifvarl hp 1 setvar target -1
  ifvarn target -1
  {
      getactor[target].z mz
      // ad hoc adjustments depending on target
      getactor[target].picnum tilenum
      ifvare tilenum SPIDERX addvar mz 4096
      ifvare tilenum ROTATEGUN addvar mz 5120
      getactor[target].yrepeat temp
      mulvar temp 192
      //subvar mz 8192
      subvarvar mz temp
      getplayer[THISACTOR].posz z
      subvarvar mz z
      ldist xydist THISACTOR target
      divvar xydist -8
      ifvare xydist 0 { setvar target -1 break }
      divvarvar mz xydist
      addvar mz 100
      getplayer[THISACTOR].horiz temp
      ifvarvarl temp mz
      {
          addvar temp 1
          ifvarvarl temp mz addvar temp 1
          ifvarvarl temp mz addvar temp 1
          setplayer[THISACTOR].horiz temp
      }
      else ifvarvarg temp mz
      {
          subvar temp 1
          ifvarvarg temp mz subvar temp 1
          ifvarvarg temp mz subvar temp 1
          setplayer[THISACTOR].horiz temp
      }
      getactor[target].x mx
      getactor[target].y my
      getplayer[THISACTOR].posx x
      getplayer[THISACTOR].posy y
      subvarvar mx x
      subvarvar my y
      getangle angvar mx my
      setplayer[THISACTOR].ang angvar
  }
}

addvar countvarc 1
ifhitspace ifvarg countvarc 9 ifvarg gogglelevel 1
{
 setvar countvarc 0
 ifvarn target -1 setvar target -1
  else
  {
    ifvarn hitsprite -1 
    {
     getactor[hitsprite].extra tempb
     ifvarg tempb 0
     {
        getactorvar[hitsprite].mval temp
   		ifvarg temp 0 { setvarvar target hitsprite soundonce LOCK }     
     }
    }
 }
}

// auto goggle regeneration at the expense of health
getplayer[THISACTOR].heat_amount temp
getactor[THISACTOR].extra hp
ifvarl temp 24
{
		subvar hp 1
		palfrom 21 63
		ifvarg hp 100 addvar temp 6 else
		ifvarg hp 75 addvar temp 12 else
		ifvarg hp 50 addvar temp 18 else
		ifvarg hp 25 addvar temp 24 else
		addvar temp 36
		setactor[THISACTOR].extra hp
		setplayer[THISACTOR].heat_amount temp
}

ifvare goggles 1
{
	ifvare hweapcount 0
	{
		ifvarand tipfield 128 nullop else ifvare tipdisplay 0 ifvare ONCAR 0 ifp palive
		{
			// GOGGLES TIP
			setvar menutoggle 4
			setvar tipdisplay 128
			orvar tipfield 128
			setvar messagetime 26
			globalsound EXITMENUSOUND
		}
	}
	getplayer[THISACTOR].heat_amount temp
	ifvare temp 1
	{
		soundonce DIMENSION_SHIFT
		setvar hweapcount 26 // transition dimension x to off
	}
	ifvare tipdisplay 128
	{
		addvar temp 1
		setplayer[THISACTOR].heat_amount temp
	} else
	ifvarg gogglelevel 2
	{
		addvar hshoot 1
		ifvarg hshoot 1
		{
			addvar temp 1
			setplayer[THISACTOR].heat_amount temp
			setvar hshoot 0
	    }	    
	}
	
}

// soul coin search and angle determination
addvar soultime 1
ifvarg soultime 6
{
	state soulsearch
	ifvare spriteid -1 setvar soulang -1
	else
	{
		ifvarand tipfield 2 nullop else ifvare tipdisplay 0 ifvare ONCAR 0 ifp palive
		{
			// FIRST SOUL COIN TIP
			setvar menutoggle 4
			setvar tipdisplay 2
			orvar tipfield 2
			setvar messagetime 26
			globalsound EXITMENUSOUND
		}
		getactor[spriteid].x mx
        getactor[spriteid].y my
        getplayer[THISACTOR].posx x
        getplayer[THISACTOR].posy y
        subvarvar mx x
     	subvarvar my y
        getangle soulang mx my
		getplayer[THISACTOR].ang tempb
		subvarvar soulang tempb // diff between angle to target and actual angle
		//ifvarg soulang 1024 subvar soulang 2048
		//else
		//ifvarl soulang -1024 addvar soulang 2048
		addvar soulang 1024
		ldist souldist THISACTOR spriteid
		setvar temp 32768
		subvarvar temp souldist
		ifvarl temp 6144 setvar temp 6144
		setvarvar souldist temp // the size of the arrow
		canseespr spriteid THISACTOR soulsee
	}
}

// soul coin collector nuke combo
ifvarg nukepart 0
  ifvare goggles 1 
    ifvarg combolevel 4 
      ifvarg ltap 2 ifvarg rtap 2
        ifvarn soulang -1
{
	state soulsearch
	ifvarn spriteid -1
	{
		subvar nukepart 2
		setvar ltap 0
		setvar rtap 0
		getplayer[THISACTOR].posx x
		getplayer[THISACTOR].posy y
		getplayer[THISACTOR].posz z
		setsprite spriteid x y z
		sound TELEPORTER
		palfrom 48 0 64 64
		quote 209
	}
}
	
		

ifvare railflag 1 
{
	setvar railflag 0
	ifvarn hitsprite -1
	{
		getactor[hitsprite].extra temp
		ifvarg temp 0
		{
			getactor[hitsprite].z mz
			setvarvar tempb hitz // so as not to overwrite hitz
			subvarvar tempb mz // tempb now stores how far up the sprite the hit occurred
				
			getactor[hitsprite].picnum temp
			getactorvar[hitsprite].mtype tempc
			switch temp
	
			case: PIGCOP
			ifvare tempc 1 { ifvarl tempb -12280 setactorvar[hitsprite].headshot 1 }
			else
			ifvare tempc 2 { ifvarl tempb -12280 setactorvar[hitsprite].headshot 1 }
			else
			ifvarl tempb -9216 setactorvar[hitsprite].headshot 1	
			break
	
			case: LIZTROOP
			case: ROBOMAN
			ifvarl tempb -9216 setactorvar[hitsprite].headshot 1
			break
	
			case: OCTABRAIN
			ifvarl tempb -6144 setactorvar[hitsprite].headshot 1
			break
	
			case: LIZMAN
			ifvare tempc 2 { ifvarl tempb -12280 setactorvar[hitsprite].headshot 1 }
			else
			ifvarl tempb -9216 setactorvar[hitsprite].headshot 1
			break
	
			case: NEWBEAST
			ifvare tempc 2 { ifvarl tempb -12280 setactorvar[hitsprite].headshot 1 }
			else
			ifvarl tempb -8192 setactorvar[hitsprite].headshot 1
			break
	
			case: COMMANDER
			ifvarl tempb -10500 setactorvar[hitsprite].headshot 1
			break
	
			case: MINIBOSS2
			ifvarl tempb -15360 setactorvar[hitsprite].headshot 1 // 14336
			break
		
			case: MINIBOSS4
			ifvarl tempb -14336 setactorvar[hitsprite].headshot 1
			break
	
			case BOSS1
			ifvare tempc 1 { ifvarl tempb -12000 setactorvar[hitsprite].headshot 1 }
			else ifvarl tempb -26624 setactorvar[hitsprite].headshot 1
			break
				
			case BOSS2
			case BOSS4
			ifvarl tempb -26624 setactorvar[hitsprite].headshot 1
			break
		
			case: BOSS3
			getactor[hitsprite].pal tempc
			ifvare tempc 17 { ifvarl tempb -9216 setactorvar[hitsprite].headshot 1 }
			else ifvarl tempb -26624 setactorvar[hitsprite].headshot 1
			break
					
			endswitch
		}
	}
}

ifvarn currholo -1 getactor[currholo].extra holostore  // stores holobot health for new level start

ifvare eventholodukeon 1 state throwholoproj
ifvarg btap 2 ifp ponground state makebarrier


ifvare hammo5 1
   state recoil // do weapon recoil stuff when recoil flag is set

ifvarg dtripflag 0 subvar dtripflag 1

getactor[THISACTOR].extra temp

getplayer[THISACTOR].dead_flag tempb
ifvare tempb 0
//ifp palive // note that "ifp palive" is true when the player is merely shrunk
{
	ifvarg pheal 0
	{
	   subvar pheal 1
	   ifvarvarl temp maxhealth
	   {
		   addvar temp 1
		   setactor[THISACTOR].extra temp
	   }
	}
	
	
	getplayer[THISACTOR].steroids_amount temp
	
	ifp ponsteroids 
	{
		ifvarl stamina MAXSTAMINA addvar stamina 4
		ifvarg stamina MAXSTAMINA setvar stamina MAXSTAMINA
		ifphealthl 100
		addvar pheal 1
	}  // steroids heal if below 50 health
	else 
		ifvarg ftap 3 ifvarg nukepart 1 ifvarg combolevel 1 ifp ponground // roid rage code
		{
			ifvarg temp 0 setvar mtype 1 // mtype used as flag indicating player had steroids in inventory
			setvar ftap 0
			getactor[THISACTOR].extra temp
			ifvarl temp 100 ifvarvarl temp maxhealth
			{
				setvarvar tempb 100
				subvarvar tempb temp
				ifvarg tempb 80 subvar nukepart 5 else
				ifvarg tempb 50 subvar nukepart 4 else
				ifvarg tempb 20 subvar nukepart 3 else
				subvar nukepart 2
				ifvarl nukepart 0 setvar nukepart 0
			}
			else subvar nukepart 2
			ifphealthl 5 addphealth 5
			setplayer[THISACTOR].steroids_amount 200
		}
	
	ifvare temp 1 // temp still holds the steroids_amount at this point
	{
		ifvarand tipfield 64 nullop else ifvare tipdisplay 0 ifvare ONCAR 0 ifp palive
		{
			// STEROIDS TIP
			setvar menutoggle 4
			setvar tipdisplay 64
			orvar tipfield 64
			setvar messagetime 26
			globalsound EXITMENUSOUND
		}
				
		ifvare mtype 1
		{
			setvar mtype 0 // restore steroids if player had them before boost
			setplayer[THISACTOR].steroids_amount 400
		}
	}
}



// The following code reduces the maxcount of a player jump from 1441 to 721; 901 when steroids are used or if dodge jumping


getplayer[THISACTOR].jumping_counter temp
ifp ponsteroids setvar tempb 901  else ifvarg dodge 0 setvar tempb 901 else setvar tempb 721
ifonwater nullop else ifvarvare temp tempb setplayer[THISACTOR].jumping_counter 0
getplayer[THISACTOR].falling_counter temp
ifvarg temp 9 ifvare doublejumpflag 0 setvar doublejumpflag 1


// reset doublejumpflag if player is on the ground, so that player can double jump again

ifvarn doublejumpflag 0
	ifp ponground
{
	ifvare doublejumpflag 2 sound DUKE_JETPACK_OFF
	setvar doublejumpflag 0
}
	

getactor[THISACTOR].htextra temp
ifvarg temp 0
{
	getactor[THISACTOR].htpicnum tempb
	
	switch tempb
	
	case CHILLBLAST
	case CHILLBLAST2
	case FREEZENOAIM
	setvar tempb FREEZEBLAST
	setactor[THISACTOR].htpicnum FREEZEBLAST
	break
	
	case FIRELASER2
	wackplayer
	wackplayer
	setvar tempb 9
	lockplayer tempb
	setactor[THISACTOR].htpicnum SHOTSPARK1
	break
	
	endswitch
	
	ifvare spinkick 1
	{
		divvar temp 2
		setactor[THISACTOR].htextra temp
	}

	// Anti- Friendly Fire code
	getactor[THISACTOR].htowner tempb
	ifvarn tempb -1
	{
		ifvarvare tempb currholo 
		{
			setactor[THISACTOR].htextra -1
			setactor[THISACTOR].htpicnum -1
		}
	
		// EVIL DUKE damage reduction code
		getactor[tempb].picnum tempc
		ifvare tempc EVILDUKE
		{
			getactorvar[tempb].mtype tempc
			ifvare tempc 1
			{
				divvar temp 5
				setactor[THISACTOR].htextra temp
			}
			else
			{
				ifvarl score 1000 divvar temp 4
				else ifvarl score 2000 divvar temp 3
				else ifvarl score 3000 divvar temp 2
				else ifvarl score 4000 { mulvar temp 2 divvar temp 3 }
				else ifvarl score 5000 { mulvar temp 3 divvar temp 4 }
				setactor[THISACTOR].htextra temp
			}
		}
	}
	ifvarn dreduction 100
	{
		mulvarvar temp dreduction
		divvar temp 100
		ifvare temp 0 setvar temp 1
		setactor[THISACTOR].htextra temp
	}
}

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

getplayer[THISACTOR].last_pissed_time temp
ifvare temp 5720 addvar pheal 10
			
  ifaction 0
    action PSTAND

  ifaction PFROZEN
  {
    cstat 257

    fall

    palfrom 16 0 0 24

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

        sound GLASS_BREAKING
        spawn ATOMICHEALTH

        getlastpal

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

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

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

    break
  }

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

          state standard_pjibs

          guts JIBS4 20
          guts JIBS6 20
          move PGROWINGPOP
          cstat 32768
          tossweapon

          hitradius 2048 60 70 80 90

        }
        else
          sizeto MAXXSTRETCH MAXYSTRETCH
      }
      break
    }

    ifsquished
      palfrom 32 63 63 63
    else
      fall

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

    ifaction PLYINGDEAD
    {
      ifactioncount 3
        move PSTOPED
      state updatescores
      quote 13
      ifhitspace
      {
        action PSTAND
        spawn DUKELYINGDEAD
	  
        // reset the upgradeable vars; of course, any sane player will restore from save...
         state resetupgradevars
         resetplayer
         action PSTAND
      }
      break
    }

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

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

    ifp pshrunk
    {
      state standard_pjibs
      spawn BLOODPOOL

      sound SQUISHED
      sound DUKE_DEAD

      cstat 32768         // Hide the sprite

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

    tossweapon

    break
  }

  ifsquished
  {
    strength -1
    sound SQUISHED
    state random_ooz
    break
  }

  ifp ponsteroids
  {
    ifp pstanding nullop
    else
      spawn FRAMEEFFECT1
  }

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

    ifdead
    {
      ifmultiplayer
        sound DUKE_KILLED4

	

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


    ifwasweapon RPG
    {
      ifrnd 32
        spawn BLOOD
      ifdead
        state standard_pjibs
      palfrom 48 52
      break
    }
    ifwasweapon RADIUSEXPLOSION
    {
      ifrnd 32
        spawn BLOOD
      ifdead
        state standard_pjibs
      palfrom 48 52
      break
    }
    ifwasweapon FIREEXT
    {
      ifrnd 32
        spawn BLOOD
      ifdead
        state standard_pjibs
      palfrom 48 52
      break
    }
    ifwasweapon GROWSPARK
    {
      palfrom 48 52
      sound EXPANDERHIT
      break
    }
    ifwasweapon SHRINKSPARK
    {
      palfrom 48 0 48
      move PSHRINKING // used as a var only.
      sound ACTOR_SHRINKING
      cstat 0
      break
    }
    ifwasweapon SHOTSPARK1
      palfrom 24 48
    
    ifwasweapon SLOWBULLET
      palfrom 24 48

    ifwasweapon FLAK
      palfrom 24 48

    ifwasweapon FREEZEBLAST
    {
      palfrom 48 0 0 48
      ifdead
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action PFROZEN
        break
      }
    }
    ifwasweapon COOLEXPLOSION1
      palfrom 48 48 0 48
    ifwasweapon KNEE
      palfrom 16 32
    ifwasweapon FIRELASER
      palfrom 32 32

    ifdead
    {
      action PTHROWNBACK
      tossweapon
    }

    state random_wall_jibs

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

  ifaction PFLINTCHING
  {
    ifactioncount 2
      action PSTAND
    break
  }

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

    ifrnd 4
      spawn WATERBUBBLE // For effect

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

  ifaction PFALLING
  {
    ifp ponground
    {
      action PSTAND
      ifvarand tipfield 256 nullop else ifvare tipdisplay 0 ifvare ONCAR 0 ifp palive
	  {
			// DOUBLE JUMP TIP
			setvar menutoggle 4
			setvar tipdisplay 256
			orvar tipfield 256
			setvar messagetime 26
			globalsound EXITMENUSOUND
	  }
    }
    else
    {
      ifp pfalling
        break
      else
        state check_pstandard
    }
  }

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

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

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

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

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

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

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

ifvare doublejumpflag 2
	{
	ifaction PJPHOUVER nullop else action PJPHOUVER
	}


enda

action TICOPEN 1 2 1 1 8
action TICCLOSE 1 2 1 1 8
action TICCLOSED 0 1 1 1 8
action TICAIM 3 1 8

move TICMOVE

actor ORGANTIC TURRETSTRENGTH
ifmove 0
{
	action TICCLOSED
	move TICMOVE faceplayerslow
	cstat 8 //
	// ifoutside cstat 8 else { move to ceiling code }
}

ifaction TICCLOSED 
	ifcount 52 
		ifp palive 
			ifcansee 
				ifpdistl 8192 
					ifrnd 8
{ 
	action TICOPEN 
	sound SLIM_HATCH
	resetcount 
}
	
ifaction TICOPEN
{
	sizeto 48 48
	ifactioncount 2
	{
		resetcount
		action TICAIM
	}
}

ifaction TICCLOSE
{
	sizeto 32 32
	ifactioncount 2
	{
		action TICCLOSED
		resetcount
	}
}

ifaction TICAIM
{
	ifcount 26
	{
		ifpdistl 6144
			ifcanshoottarget
		{
			sound LIZARD_SPIT
			shoot SPIT 
			shoot SPIT
			resetcount
		}
		else ifrnd 16
		{
			sound SLIM_HATCH
			action TICCLOSE
		}
	}
}
	

  ifhitweapon
  {
    state checkdart
    ifdead
    {
      addkills 1
      sound SLIM_DYING
      guts JIBS5 10
      state clearlists
      killit
    }
    //sound TURR_PAIN
    break
  }
  ifrnd 1
    soundonce SLIM_ROAM
enda

state rf
  ifrnd 128
    cstat 4
  else
    cstat 0
ends


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

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

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

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

state checktroophit

state checkdart

  ifaction ATROOPSUFFERING
  {
    stopsound LIZARD_BEG
    sound PRED_DYING
    cstat 0
    strength 0
    action ATROOPSUFFERDEAD
    break
  }
  ifdead
  {
    ifwasweapon FREEZEBLAST
    {
      sound SOMETHINGFROZE
      spritepal 1
      move 0
      action ATROOPFROZEN
      strength 0
      break
    }

    state drop_ammo
    state random_wall_jibs

    ifwasweapon GROWSPARK
    {
      cstat 0
      sound ACTOR_GROWING
      ai AITROOPGROW
      break
    }

    addkills 1
    ifvarg mval 0 { state dropcoins state addscore }

    ifvare revives 0
     {
      sound SQUISHED
      // state troop_body_jibs
      state standard_jibs
      state clearlists
      killit
    }
    
    setvar temp 0
    ifwasweapon RPG setvar temp 1
    ifwasweapon RPGNOAIM setvar temp 1
    ifwasweapon HLROCKET setvar temp 1
    ifwasweapon CPUDEV setvar temp 1
    
    ifvare temp 1
	{
      sound SQUISHED
      // state troop_body_jibs
      state standard_jibs
      state clearlists
      killit
    }
    
    else
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      // state troop_body_jibs
      state standard_jibs
      state clearlists
      killit
    }
    else
    {
      sound PRED_DYING
      ifrnd 32
        iffloordistl 32
      {
        sound LIZARD_BEG
        spawn BLOODPOOL
        strength 0
        move 0
        action ATROOPSUFFERING
        break
      }
      action ATROOPDYING
      break
    }
  }
  else
  {
    state random_wall_jibs
    sound PRED_PAIN

        ifwasweapon SHRINKSPARK ifvarl hp 301
    {
      sound ACTOR_SHRINKING
      ai AITROOPSHRUNK
    }
    else
      ifwasweapon GROWSPARK
        sound EXPANDERHIT
    else
      iffloordistl 32
        ifrnd 96
          action ATROOPFLINTCH
  }
ends

state troophidestate

ifhitweapon { ai AITROOPSEEKENEMY state checktroophit break }

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

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


state troopgunnashoot
  ifp palive
  {
    ifpdistl 1024
      ai AITROOPSHOOTING
    else
      ifactornotstayput
    {
      ifactioncount 12
        ifrnd 16
          ifcanshoottarget
      {
        ifspritepal 21
          ifrnd 4
            ifpdistg 4096
              ai AITROOPHIDE
        else
        {
          ifpdistl 2200
            ai AITROOPFLEEING
          else
          {
            ifpdistl 4096
              ifcansee
                ifcanshoottarget
                  ai AITROOPSHOOTING
            else
            {
              move TROOPRUNVELS seekplayer
              action ATROOPRUNNING
            }
          }
        }
      }
    }
    else
      ifcount 26
        ifrnd 32
          ai AITROOPSHOOTING
  }
ends

state troopseekstate
  state troopgunnashoot
  ifinwater
  {
    ai AITROOPJETPACK
    break
  }
  ifcansee
  {
    ifmove TROOPRUNVELS
      ifpdistl 1596
        ai AITROOPDUCKING
    ifp phigher
    {
      ifceilingdistl 128 nullop
      else
        ifactornotstayput
          ai AITROOPJETPACK
      break
    }
    else
      ifrnd 2
    {
      ifspritepal 21
        ifpdistg 1596
      {
        ai AITROOPHIDE
        break
      }
      ifbulletnear
      {
        ifrnd 128
          ai AITROOPDODGE
        else
          ai AITROOPDUCKING
        break
      }
    }
  }
  ifnotmoving
  {
    ifrnd 32
      operate
    else
      ifcount 32
        ifp palive
          ifcansee
            ifcanshoottarget
              ai AITROOPSHOOTING
  }
  ifrnd 1
  {
    ifrnd 128
      soundonce PRED_ROAM
    else
      soundonce PRED_ROAM2
  }
ends

state troopshooting

state aimatholobot
ifvare target -1 getplayer[THISACTOR].i target
state holozdist
ldist xydist THISACTOR target
ifvare xydist 0 setvar xydist 1
getactor[target].picnum tilenum

ifvare mtype 2
{
	sound RAIL_FIRE
	resetactioncount
	shiftvarl zdist 8
	divvarvar zdist xydist
	zshoot zdist RAILSLUG_WEAK
}
else

ifspritepal 21
{
	sound PRED_ATTACK
	resetactioncount
	shiftvarl zdist 9
	divvarvar zdist xydist
	zshoot zdist FIRELASER2
}
else
{
	sound PRED_ATTACK 
	ifvare tilenum APLAYER
	shoot FIRELASER
	else
	{
		mulvar zdist 768
		divvarvar zdist xydist
		zshoot zdist FIRELASER
	}
	resetactioncount
}
ends


state troopduckstate
  ifaction ATROOPDUCK
  {
    ifactioncount 8
    {
      ifp palive
      {
        ifrnd 128
          action ATROOPDUCKSHOOT
      }
      else
        ifmove DONTGETUP
          break
        else
          ai AITROOPSEEKPLAYER
    }
  }
  else
    ifaction ATROOPDUCKSHOOT
  {
    ifcount 64
    {
      ifmove DONTGETUP
        resetcount
      else
      {
        ifpdistl 2200
          ai AITROOPFLEEING
        else
          ai AITROOPSEEKPLAYER
      }
    }
    else
      ifactioncount 2
      {
	        cstat 257
	        ifvarl mtype 4 sizeat 41 40 // desperation safety measure to prevent invis from shooting
			state aimatholobot
			ifvarn target -1
			{
				state troopshooting
				break
			}
         	ifcanshoottarget
	        {
			    state troopshooting
		   	}
        	else ai AITROOPSEEKPLAYER
      }
  }
ends

state troopshootstate
  ifactioncount 2
  {
	cstat 257
	ifvarl mtype 4 sizeat 41 40 // desperation safety measure to prevent invis from shooting
    state aimatholobot
    ifvarn target -1
	{
		state troopshooting
		ifrnd 128
	        ai AITROOPSEEKPLAYER
		break
	}
    
    ifcanshoottarget
	{
		state troopshooting
	
	    ifrnd 128
	        ai AITROOPSEEKPLAYER
	      ifcount 24
	      {
	        ifrnd 96
	          ifpdistg 2048
	            ai AITROOPSEEKPLAYER
	          else
	          {
	            ifpdistg 1596
	              ai AITROOPFLEEING
	            else
	              ai AITROOPFLEEINGBACK
	          }
	      }
	}
	
    else
      ai AITROOPSEEKPLAYER
  }
ends

state troopfleestate
  ifactioncount 7
  {
    ifpdistg 3084
    {
      ai AITROOPSEEKPLAYER
      break
    }
    else
      ifrnd 32
        ifp palive
          ifcansee
            ifcanshoottarget
      {
        ifrnd 128
          ai AITROOPDUCKING
        else
          ai AITROOPSHOOTING
          break
      }
  }
  ifnotmoving
  {
    ifrnd 32
      operate
    else
      ifcount 32
        ifp palive
          ifcansee
            ifcanshoottarget
      {
        ifrnd 128
          ai AITROOPSHOOTING
        else
          ai AITROOPDUCKING
      }
  }
ends

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



state troopjetpackstate
  ifaction ATROOPJETPACKILL
  {
    ifcansee
      ifactioncount 2
    {
      setvar temp 0
      ifpdistl 3072 setvar temp 1
      ifrnd 36 ifvare temp 0
	  {
		resetactioncount
      	sound BOS1_ATTACK2
      	shoot MORTER
	  }
      else
	  {
        state aimatholobot
      	state troopshooting
	  }
    }

    ifp phigher
      ai AITROOPJETPACK
    else
      ifinwater
        ai AITROOPJETPACK
    else
      ifcount 26
        iffloordistl 32
          ai AITROOPSEEKPLAYER
  }
  else
    ifcount 48
      ifcansee
  {
    action ATROOPJETPACKILL
    move TROOPJETPACKILLVELS seekplayer
  }
ends

state checksquished
  ifsquished
  {
    addkills 1
    sound SQUISHED
    state standard_jibs
    state random_ooz
    ifvarg mval 0 { state dropcoins state addscore }
    state clearlists
    killit
  }
ends

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

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


state troopcode

  state monsterai
  ifvarg menutoggle 0 break
  fall
  
//  ifvare headshot 1 state headshot
 getactor[THISACTOR].extra hp
 
ifp pfacing ifpdistg 1536 ifrnd 8 ifvarg hp 0 ifvare mtype 2
	state teleport_behind
	

ifaction TROOPRISE ifactioncount 4 ai AITROOPSEEKENEMY
state setholotarg

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

      ifrnd 84
        spawn BLOODPOOL
      lotsofglass 30
      spritepal 22
      state standard_jibs
      sound GLASS_BREAKING
     ifvarg mval 0 { state dropcoins state addscore }
      state clearlists
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
       ifvare superkicking 0
        pkick
    break
  }
  else ifaction ATROOPPLAYDEAD
  {
    ifhitweapon
    {
      ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        // state troop_body_jibs
        state standard_jibs
        state clearlists
        killit
      }
      break
    }
    else
      state checksquished

    ifcount PLAYDEADTIME
    {
      addkills -1
      setvar monstatus 1
      soundonce PRED_ROAM
      cstat 257
      strength 1
      ai AITROOPSHOOTING
    }
    else
      ifp pfacing
        resetcount

    break
  }
  else
    ifaction ATROOPDEAD
  {
    strength 0
    setvar monstatus 2 // for safety -- it should already be set elsewhere, but there a bug...
    cstat 0
    state deadlist
    findnearsprite HEALBOLT 1024 temp
      ifvarn temp -1
	{
		subvar revives 1
		strength 10
		setactor[temp].xrepeat 0
		action TROOPRISE
		setvar monstatus 1
		spritepal 12
		cstat 257
		break
	}
 

    ifhitweapon
    {
      ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        // state troop_body_jibs
        state standard_jibs
        state clearlists
        killit
      }
      break
    }
    else
      state checksquished
    break
  }
  else
    ifaction ATROOPSUFFERDEAD
  {
    ifactioncount 2
    {
      ifrnd 64
      {
        resetcount
        action ATROOPPLAYDEAD
      }
      else
      {
        soundonce PRED_DYING
        action ATROOPDEAD
      }
    }
  }
  else
    ifaction ATROOPDYING
  {
    state troopdying
    break
  }
  else
    ifaction ATROOPSUFFERING
  {
    state troopsufferingstate
    ifhitweapon
     {
      state checktroophit
     }
    break
  }
  else
    ifaction ATROOPFLINTCH
  {
    ifactioncount 4
      ai AITROOPSEEKENEMY
  }
  else
  {
    ifai AITROOPSEEKPLAYER
      state troopseekstate
    else
      ifai AITROOPJETPACK
    {
      state troopjetpackstate
      ifinwater nullop
      else
        soundonce DUKE_JETPACK_IDLE
    }
    else
      ifai AITROOPSEEKENEMY
        state troopseekstate
    else
      ifai AITROOPSHOOTING
        state troopshootstate
    else
      ifai AITROOPFLEEING
        state troopfleestate
    else
      ifai AITROOPFLEEINGBACK
        state troopfleestate
    else
      ifai AITROOPDODGE
        state troopseekstate
    else
      ifai AITROOPDUCKING
        state troopduckstate
    else
      ifai AITROOPSHRUNK
        state troopshrunkstate
    else
      ifai AITROOPGROW
        state genericgrowcode
    else
      ifai AITROOPHIDE
    {
      state troophidestate
      break
    }
  }

  ifhitweapon
    {
    state checktroophit
    }
  else
    state checksquished

ends


state checktrooppalette
  ifai 0
  {
	randvar temp 60000
	ifvarg score 6000 ifvarvarl temp score
	{
		strength 200
		state difficulty
		spritepal 17
		setvar mtype 2
		setvar mval MINIBOSSVAL
	}
    state clone
    
    ifspritepal 21
    {
    	addstrength TROOPSTRENGTH
    	addvar mval 6
    }
	randvar temp 15000
	subvar temp 1000
	ifvarvarl temp score ifrnd 84
	{
    	state monstmakebarrier
    	addvar mval 8
	}
  }
ends


actor LIZTROOPJETPACK TROOPSTRENGTH
  setvar mval TROOPVAL
  state checktrooppalette
  ai AITROOPJETPACK
  cactor LIZTROOP
enda

actor LIZTROOPDUCKING TROOPSTRENGTH
  setvar mval TROOPVAL
  state checktrooppalette
  state monstersubstitution
  ai AITROOPDUCKING
  cactor LIZTROOP
  ifgapzl 48
    move DONTGETUP
enda

actor LIZTROOPSHOOT TROOPSTRENGTH ATROOPSTAND
  setvar mval TROOPVAL
  state checktrooppalette
  state monstersubstitution
  ai AITROOPSHOOTING
  cactor LIZTROOP
enda
actor LIZTROOPSTAYPUT TROOPSTRENGTH ATROOPSTAYSTAND
  setvar mval TROOPVAL
  state checktrooppalette
  state monstersubstitution
  ai AITROOPSEEKPLAYER
  cactor LIZTROOP
enda
actor LIZTROOPRUNNING TROOPSTRENGTH ATROOPSTAND
  setvar mval TROOPVAL
  state checktrooppalette
  state monstersubstitution
  ai AITROOPSEEKPLAYER
  cactor LIZTROOP
enda
actor LIZTROOPONTOILET TROOPSTRENGTH
  setvar mval TROOPVAL
  ifcount 24
  {
    sound FLUSH_TOILET
    operate
    ai AITROOPSEEKPLAYER
    cactor LIZTROOP
  }
  else
    ifcount 2
      nullop
  else
    state checktrooppalette
enda

actor LIZTROOPJUSTSIT TROOPSTRENGTH
  ifcount 30
  {
    operate
    ai AITROOPSEEKPLAYER
    cactor LIZTROOP
  }
  else
    ifcount 2
      nullop
  else
    state checktrooppalette
enda


actor LIZTROOP TROOPSTRENGTH ATROOPSTAND

  ifai 0
  {
  	setvar mval TROOPVAL
  	state checktrooppalette
  	state monstersubstitution
  }
   ifvarn barrierup -1
  {
	  setactor[barrierup].xrepeat 1
	  setactor[barrierup].yrepeat 1
	  getactorvar[barrierup].countvarb temp
	  getactorvar[barrierup].countvar tempb
	  getactor[barrierup].cstat tempc
	  ifvare temp 0 ifvare tempb 0 ifvarn tempc 2
	    setactor[barrierup].cstat 258 //33024
	  
  }
  state troopcode
  ifai AITROOPHIDE nullop else
  ifvarn barrierup -1 { setactor[barrierup].xrepeat 128 setactor[barrierup].yrepeat 96 }
enda

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

move LIZWALKVEL 72
move LIZRUNVEL 192
move LIZDODGEVEL 192
move LIZJUMPVEL 184
move LIZSTOP

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

state liztype // this state changes enforcers

ifai 0
{
	randvar temp 15000
	subvar temp 1000
	ifvarvarl temp score ifrnd 96
	{
		  state monstmakebarrier
		  addvar mval 8
	}
	  
    ifrnd 64 
	{
		ifvarg score 4000 ifrnd 96 { cactor FIRELIZMAN setvar mtype 2 break }
	  	ifvarg score 150 { spritepal 20 setvar mtype 1 addstrength 25 addvar mval 5 }
	}
    //state clone
 }
ends

state lizseekstate

  ifactornotstayput
  {
	
    ifcansee
      ifp palive
        ifpdistl 2048
          ifcount 16
            ifcanshoottarget
    {
      ai AILIZSHOOTENEMY
      break
    }
    ifai AILIZCHARGEENEMY
    {
      ifcount 52 //72
      {
	      
	      ifcanshoottarget
	      {
	        ai AILIZSHOOTENEMY
	        break
	      }
  	  }
      ifp phigher
        ifpdistg 2048
          ifrnd 6
      {
        ai AILIZJUMPENEMY
        break
      }
    }
    else
      ifpdistg 4096
    {
      ifrnd 92
      {
        ifcount 48
        {
	      
	      ifcanshoottarget
	         ai AILIZSHOOTENEMY
	      
	    }

      }
      else
        ifcount 24
      {
        ai AILIZCHARGEENEMY
        break
      }
    }

    iffloordistl 16
    {
      ifcount 48
        ifnotmoving
          ifcansee
      {
        ai AILIZJUMPENEMY
        break
      }
    }
    else
    {
      ifpdistg 1280
        ai AILIZJUMPENEMY
      break
    }

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

ends

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

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

state lizthinkstate
  ifrnd 8
    soundonce CAPT_ROAM
  ifactioncount 3
  {
    ifrnd 32
      ifp palive
        ifcansee
          ai AILIZSPIT
        else
          ifrnd 96
            ai AILIZGETENEMY
  }
  else
    ifactioncount 2
      ifrnd 1
        spawn FECES
  ifrnd 8	// was 1
    ifbulletnear
  {
    ifgapzl 96
      ai AILIZDODGE
    else
    {
      ifrnd 128
        ai AILIZJUMPENEMY
      else
        ai AILIZDODGE
    }
  }
ends

state lizshootstate

  ifcount 20
    ifrnd 6 //8
  {
    ifcansee
      ifpdistl 2048
    {
      ifrnd 128
        ai AILIZFLEENEMY
      break
    }
    ifrnd 80
      ai AILIZTHINK
    else
      ai AILIZGETENEMY
  }


  ifactioncount 2
  {
    state aimatholobot
    ifvarn target -1 canseespr THISACTOR target tempb
		
    ifvarn target -1 ifvarn tempb 0 
	{ 
		ifvare mtype 2 
		{
			sound RPG_SHOOT
			shoot FIREBULLET
		}
		else
	    {
			sound CAPT_ATTACK
			ifvare mtype 1 shoot FIRELASER
			else shoot SLOWBULLET
			state shelleject
	    } 
		resetactioncount
	}
    else
    {
	    ifcansee
	    {
	      ifcanshoottarget
	      {
	        ifvare mtype 1
	        {
		        sound CAPT_ATTACK
		        ifrnd 160 shoot FREEZEBLAST
		        else shoot FIRELASER
		        state shelleject
		        resetactioncount
	        }
		  else ifvare mtype 2
			{
				
				sound RPG_SHOOT
				shoot FIREBULLET
				resetactioncount
			}
	        else 
	        { 
		        sound CAPT_ATTACK 
		        //shoot CHAINGUN 
		        shoot SLOWBULLET
		        state shelleject
		        resetactioncount 
		    }
	      }
	      else
	        ai AILIZTHINK
	    }
    }
    else
      ai AILIZGETENEMY
  }
ends

state checklizhit
  spawn BLOOD
  state checkdart
 
  ifai AILIZSHRUNK
  {
    addkills 1
    sound SQUISHED
    state standard_jibs
    ifvarg mval 0 { state dropcoins state addscore }
    state clearlists
    killit
  }
  ifdead
  {
    ifvare mtype 1
	{
		lotsofglass 30
		spritepal 22
	    state standard_jibs
	    sound GLASS_BREAKING
	    state drop_chaingun
		ifvarg mval 0 { state dropcoins state addscore }
		addkills 1
	    state clearlists
	    killit
	}
    ifwasweapon FREEZEBLAST
    {
      sound SOMETHINGFROZE
      spritepal 1
      move 0
      action ALIZFROZEN
      strength 0
      break
    }

    state drop_chaingun
    ifvarg mval 0 { state dropcoins state addscore }

    ifvare revives 0
     {
      sound SQUISHED
      state standard_jibs
      state clearlists
      killit
    }

    ifwasweapon GROWSPARK
    {
      cstat 0
      sound ACTOR_GROWING
      ai AILIZGROW
      break
    }

    addkills 1
    
    setvar temp 0
    ifwasweapon RPG setvar temp 1
    ifwasweapon RPGNOAIM setvar temp 1
    ifwasweapon HLROCKET setvar temp 1
    ifwasweapon CPUDEV setvar temp 1
    
    ifvare temp 1
    {
      sound SQUISHED
      // state liz_body_jibs
      state standard_jibs
      state clearlists
      killit
    }

    else
      ifwasweapon RADIUSEXPLOSION
    {
      	sound SQUISHED
      	// state liz_body_jibs
      	state standard_jibs
                  state clearlists
      	killit
     }

    else
    {
      state rf
      ai AILIZDYING
      ifrnd 64
        spawn BLOODPOOL
    }
    sound CAPT_DYING
  }
  else
  {
    sound CAPT_PAIN
    ifwasweapon SHRINKSPARK
    {
     ifvarn mtype 2 ifvarl hp 301
	 {
       sound ACTOR_SHRINKING
       ai AILIZSHRUNK
       break
	 }
    }
    ifwasweapon GROWSPARK
      sound EXPANDERHIT
      
    state random_wall_jibs
    ifai AILIZHIT nullop else
    ifwasweapon SHOTSPARK1 { ifrnd 16 ai AILIZHIT } else
    ifrnd 32 ai AILIZHIT else
    ifwasweapon KNEE ifvarn superkicking 0
    ai AILIZHIT
    ifai AILIZHIT nullop else
    ifp palive
      ifcansee
        ifcanshoottarget
    {
      ai AILIZSHOOTENEMY
      break
    }
  }
ends

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

state lizdyingstate
  ifaction ALIZLYINGDEAD
  {
    strength 0
    state deadlist
    findnearsprite HEALBOLT 1024 temp
      ifvarn temp -1
	{
		subvar revives 1
		strength 10
		setactor[temp].xrepeat 0
		action LIZRISE
		setvar monstatus 1
		spritepal 12
		cstat 257
		break
	}
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      state clearlists
      killit
    }

  }
  else
    ifai AILIZDYING
      ifactioncount 6
  {
    iffloordistl 8
      sound THUD
    move LIZSTOP
    action ALIZLYINGDEAD
  }
ends

state lizdodgestate
  ifcount 13
    ai AILIZGETENEMY
ends

actor LIZMANSTAYPUT LIZSTRENGTH setvar mval LIZVAL state liztype state monstersubstitution ai AILIZGETENEMY ifactor LIZMANSTAYPUT cactor LIZMAN enda
actor LIZMANSPITTING LIZSTRENGTH setvar mval LIZVAL state liztype state monstersubstitution ai AILIZSPIT ifactor LIZMANSPITTING cactor LIZMAN enda
actor LIZMANJUMP LIZSTRENGTH setvar mval LIZVAL state liztype state monstersubstitution ai AILIZJUMPENEMY ifactor LIZMANJUMP cactor LIZMAN enda

useractor enemy FIRELIZMAN 500

strength 500
state difficulty 
setvar mval SUPERBEASTVAL 
ifai 0 ai AILIZGETENEMY 
spritepal 19 
setvar mtype 2 
sizeat 50 50 
cstator 257 
cactor LIZMAN 
enda

state flameon

	espawn STICKYFIRE
	randvar tempb 10240
	getactor[RETURN].z mz
	subvarvar mz tempb
	setactor[RETURN].z mz
	getactor[RETURN].x mx
	getactor[RETURN].y my
	randvar temp 256
	ifrnd 128 addvarvar mx temp else subvarvar mx temp
	randvar temp 256
	ifrnd 128 addvarvar my temp else subvarvar my temp
	setactor[RETURN].x mx
	setactor[RETURN].y my


ends

state lizcode
  state monsterai
  ifvare mtype 2 ifvare monstatus 1 state flameon
  ifvarg menutoggle 0 break
  state checksquished
  
  
//  ifvare headshot 1 state headshot
getactor[THISACTOR].extra hp
ifvare scanned 1 ifpdistg 2048 ifrnd 12 ifvarg hp 0
{
	setvar temp 0
	ifaction ALIZFROZEN setvar temp 1
	ifai AILIZSHOOTENEMY setvar temp 1
	ifai AILIZJUMPENEMY setvar temp 1
	ifai AILIZDYING setvar temp 1
	ifai AILIZDODGE setvar temp 1 
	ifai AILIZSHRUNK setvar temp 1
	ifvare temp 0
	{
	    ifrnd 64 
		   ai AILIZJUMPENEMY
		     else ai AILIZDODGE
    }
}

state setholotarg

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

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

      ifrnd 84
        spawn BLOODPOOL
      lotsofglass 30
      sound GLASS_BREAKING
      spritepal 22
      state standard_jibs
      ifvarg mval 0 { state dropcoins state addscore }
      state clearlists
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
       ifvare superkicking 0
        pkick
    break
  }
  else
    ifai AILIZJUMPENEMY
      state lizjumpstate
  else
  {
    fall
    ifai AILIZGETENEMY
      state lizseekstate
    else
      ifai AILIZCHARGEENEMY
        state lizseekstate
    else
      ifai AILIZDODGE
        state lizdodgestate
    else
      ifai AILIZSHOOTENEMY
        state lizshootstate
    else
      ifai AILIZFLEENEMY
        state lizfleestate
    else
      ifai AILIZTHINK
        state lizthinkstate
    else
      ifai AILIZSHRUNK
        state lizshrunkstate
    else
      ifai AILIZGROW
        state genericgrowcode
    else
      ifai AILIZDYING
        state lizdyingstate
    else
      ifai AILIZHIT
    {
	  ifcount 6 ai AILIZTHINK
    }
    else
      ifai AILIZSPIT
    {
      ifcount 26
        ai AILIZGETENEMY
      else
	  ifvare mtype 2
		{
			ifcount 6 
			{ 
				eshoot FLAMETHROWER
				getactor[RETURN].z mz
				addvar mz 1024
				setactor[RETURN].z mz
			}
			
		}
	  else
        ifcount 18
          ifrnd 96
      {
	  shoot SPIT
        sound LIZARD_SPIT
      }
    }
  }

  ifai AILIZSHRUNK
    break
  ifvare mtype 1
  {
	  getactor[THISACTOR].htextra temp
	  ifvarg temp 0
	  {
		  getactor[THISACTOR].htpicnum tempb
		  switch tempb
		  case FREEZEBLAST
		  case CHILLBLAST
		  case CHILLBLAST2
		  case FREEZENOAIM
		  setactor[THISACTOR].htextra -1
		  setactor[THISACTOR].htpicnum -1
		  break
		  endswitch
	  }
  }
  ifhitweapon
    {
    state checklizhit
    }
ends

actor LIZMAN LIZSTRENGTH
  ifai 0 setvar mval LIZVAL
  state liztype
  state monstersubstitution
  
  ifvarn barrierup -1 
  { 
	  setactor[barrierup].xrepeat 0
	  setactor[barrierup].yrepeat 0
	  getactorvar[barrierup].countvarb temp
	  getactorvar[barrierup].countvar tempb
	  getactor[barrierup].cstat tempc
	  ifvare temp 0 ifvare tempb 0 ifvarn tempc 2
	    setactor[barrierup].cstat 258 //33024
	  
  }
  state lizcode
  ifvarn barrierup -1 
  { 
	  setactor[barrierup].xrepeat 128 
	  setactor[barrierup].yrepeat 96
  }
  fall	
enda


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

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


state dronedead
  addkills 1
  debris SCRAP1 8
  debris SCRAP2 4
  debris SCRAP3 7
  ifvare mtype 1
  {
      espawn ICEPIPE
      setactor[RETURN].cstat 32768
      setactorvar[RETURN].countvar 50
      setactorvar[RETURN].myspawner THISACTOR
      sound BOOM
  }
  else ifvare mtype 2
  {
      spawn BIGEXPLOSION
      sound LASERTRIP_EXPLODE
      hitradius 3072 30 40 50 60
      setvar tempd 0
      whilevarn tempd 64
      {
	      randvar zdist 2048
	      ifrnd 128 mulvar zdist -1
	      zshoot zdist FLAMETHROWER
	      getactor[THISACTOR].ang angvar
	      addvar angvar 32
	      setactor[THISACTOR].ang angvar
	      addvar tempd 1
      }
  }
  else
  {
      spawn EXPLOSION2
      sound RPG_EXPLODE
      hitradius 2048 25 35 50 60
  }
  ifvarg mval 0 { state dropcoins state addscore }
  state clearlists
  killit
ends

state checkdronehitstate

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

state droneshrunkstate
  ifcount 24
    { state clearlists killit }
  else
    sizeto 1 1
ends

state checkdronenearplayer

  ifp palive
    ifpdistl 1596
  {
    ifcount 8
    {
      addkills 1
      sound DRON_ATTACK2
      debris SCRAP1 8
      debris SCRAP2 4
      debris SCRAP3 7
      
      ifvare mtype 1
      {
	      espawn ICEPIPE
	      setactor[RETURN].cstat 32768
	      setactorvar[RETURN].countvar 50
	      setactorvar[RETURN].myspawner THISACTOR
	      sound BOOM
      }
      else ifvare mtype 2
      {
	      spawn BIGEXPLOSION
	      sound LASERTRIP_EXPLODE
	      hitradius 3072 35 45 55 70
	      setvar tempd 0
	      whilevarn tempd 64
	      {
		      randvar zdist 2048
		      ifrnd 128 mulvar zdist -1
		      zshoot zdist FLAMETHROWER
		      getactor[THISACTOR].ang angvar
		      addvar angvar 32
		      setactor[THISACTOR].ang angvar
		      addvar tempd 1
	      }
      }
      else
      {
	      spawn EXPLOSION2
	      sound RPG_EXPLODE
	      hitradius 2048 25 35 50 60
      }
      
      ifvarg mval 0 { state dropcoins state addscore }
      state clearlists
      killit
    }
    else
      ifcount 3 nullop
      else
        sound LASERTRIP_ARMING
  }

ends

state dronegetstate

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

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

actor DRONE DRONESTRENGTH

  ifai 0
  {
     setvar mval DRONEVAL
     state clone
     ifvarg score 2500 ifrnd 32
     {
	    spawn DRONEDEV
	    getplayer[THISACTOR].max_actors_killed temp
		subvar temp 1
		setplayer[THISACTOR].max_actors_killed temp
		state clearlists
		killit 
	}
	else
	ifrnd 64
	{
		ifvarg score 8000 ifrnd 96
		{
			setvar mtype 2
			spritepal 2
			setvar mval LIZVAL
			strength 200
		}
		else
		{
			setvar mtype 1
			spritepal 1
		}
	}
	
	ai AIDRONEGETE
  }
  
  state setholotarg
  state monsterai
  ifvarg menutoggle 0 break
  
  state checkdronenearplayer

  ifrnd 2
    fall
  else
    soundonce DRON_JETSND


  ifaction 0
    ai AIDRONEGETE
  else
    ifai AIDRONEWAIT
  {
    ifactioncount 4
      ifrnd 16
        ifcansee
    {
      sound DRON_ATTACK1
      ifp phigher
        ai AIDRONEGETUP
      else ai AIDRONEGETE
    }
  }
  else
    ifai AIDRONEGETE
      state dronegetstate
  else
    ifai AIDRONEGETUP
      state dronegetstate
  else
    ifai AIDRONEPULLBACK
  {
    ifcount 32
    ai AIDRONEWAIT
  }
  else
    ifai AIDRONEHIT
  {
    ifcount 8
      ai AIDRONEWAIT
  }
  else
    ifai AIDRONESHRUNK
      state droneshrunkstate
  else
    ifai AIDRONEDODGE
      state dronedodgestate
  else
    ifai AIDRONEDODGEUP
      state dronedodgestate

  ifhitweapon
    {
    state checkdronehitstate
    }

  ifrnd 1
    soundonce DRON_ROAM

enda



action AOCTAWALK    0   3   5   1   15
action AOCTASTAND     0   1   5   1   15
action AOCTASCRATCH   0   4   5   1   15
action AOCTAHIT    30   1   1   1   10
action AOCTASHOOT    20   1   5   1   35 // length normally 10, not 35
action AOCTADYING    30   8   1   1   17
action AOCTADEAD     38   1   1   1  1
action AOCTAFROZEN    0   1   5
action OCTARISE 38 8 1 -1 51


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

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

state octagetenemystate
ifvarn currholo -1
{
    getactorvar[currholo].target temp
    ifvarvare temp THISACTOR setactorvar[currholo].target -1 // remove from target list if can't be hit
}
  ifcansee
  {
    ifactioncount 32
    {
      // ifrnd 96
        ifcanshoottarget
      {
        sound OCTA_ATTACK1
        ai AIOCTASHOOTENEMY
        break
      }
    }
    else
      ifpdistl 1280
        ai AIOCTASCRATCHENEMY
  }

ends

state octascratchenemystate
  cstat 257

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

state octashootenemystate

state setholotarg
  ifcount 25
  {
    ifcount 27
      ai AIOCTAGETENEMY
  }
  else
    ifcount 24
      {
      ifvare mtype 1 shoot COOLEXPLOSION1
      shoot COOLEXPLOSION1
      }
  else
   ifactioncount 6
   resetactioncount
ends

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

      addkills 1
      ifvarg mval 0 { state dropcoins state addscore }

      ifvare revives 0
     {
      sound SQUISHED
      state standard_jibs
      state clearlists
      killit
    }

    setvar temp 0
    ifwasweapon RPG setvar temp 1
    ifwasweapon RPGNOAIM setvar temp 1
    ifwasweapon HLROCKET setvar temp 1
    ifwasweapon CPUDEV setvar temp 1
    
    ifvare temp 1
      {
        sound SQUISHED
        state standard_jibs
        state clearlists
        killit
      }
      else
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        state clearlists
        killit
      }
      else
        ifwasweapon GROWSPARK
      {
        cstat 0
        sound ACTOR_GROWING
        ai AIOCTAGROW
        break
      }
      else
      {
        state rf
        ai AIOCTADYING
      }
      sound OCTA_DYING
    }
    else
    {
      sound OCTA_PAIN
      spawn BLOOD
      ifrnd 64
        ai AIOCTAHIT
    }
  }
  state random_wall_jibs
ends

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


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

state healfriend

canseespr THISACTOR target temp
ifvare temp 0 break
getactor[THISACTOR].z z
getactor[target].z mz
setvarvar zdist mz
subvarvar zdist z
addvar zdist 4096
ldist tempb THISACTOR target
mulvar zdist 768 // multiplies zdist by 768, the speed of the projectile
ifvare tempb 0 setvar tempb 1
divvarvar zdist tempb // zdist now holds the desired z velocity
sound LASER3FIRE
state aimattarget
zshoot zdist HEALBOLT
ends

state octahelpfriends

addvar countvar 1
ifvarg countvar 25
{
	espawn NEWSMOKE
	setactor[RETURN].pal 4
	ifvarn D1 -1  { setvarvar target D1 state healfriend }
	ifvarn D2 -1  { setvarvar target D2 state healfriend }
	ifvarn D3 -1  { setvarvar target D3 state healfriend }

	ifvarn M1 -1 ifvarvarn M1 THISACTOR { setvarvar target M1 state healfriend }
	ifvarn M2 -1 ifvarvarn M2 THISACTOR { setvarvar target M2 state healfriend }
	ifvarn M3 -1 ifvarvarn M3 THISACTOR { setvarvar target M3 state healfriend }
	setvar countvar 0
}

ifpdistl 8192 ifcansee ifvare goggles 0 ifp palive
{
	getplayer[THISACTOR].i spriteid
	ldist xydist THISACTOR spriteid
	mulvar xydist -1
	addvar xydist 8192
	divvar xydist 112
	ifvarg xydist 64 setvar xydist 64
	setplayer[THISACTOR].pals 0 0
	setplayer[THISACTOR].pals 1 0
	setplayer[THISACTOR].pals 2 0
	setplayer[THISACTOR].pals_time xydist
}
ends

actor OCTABRAINSTAYPUT OCTASTRENGTH
  cstat 2 	// make transparent and unhittable
  
  setvar mval OCTAVAL
  ai AIOCTAGETENEMY
  cactor OCTABRAIN
enda

useractor enemy SUPERBRAIN 250
 strength 200
 setvar mval TANKVAL
ai AIOCTAGETENEMY 
spritepal 17 setvar mtype 1 sizeat 60 60 cstat 2 state difficulty 
cactor OCTABRAIN enda

actor OCTABRAIN OCTASTRENGTH
 ifai AIOCTASHRUNK cstat 0
 else
 ifaction AOCTASHOOT cstat 257
 else 
 ifaction AOCTAFROZEN cstat 257
 else
 ifaction AOCTADEAD cstat 0
 else ifvare goggles 1 cstat 257
 else { cstat 2 setvar headshot 0 }
 
state monsterai
ifvarg menutoggle 0 break
 
fall
getactor[THISACTOR].extra hp
ifvarg hp 0 ifvare mtype 1 state octahelpfriends

  ifai 0 ifvarg score 2000 ifrnd 48 cactor SUPERBRAIN
 else
  ifai 0
  {
	setvar mval OCTAVAL
	//state clone
  }
  state checksquished
  
  ifaction OCTARISE ifactioncount 8 ai AIOCTAGETENEMY
  ifai 0
    ai AIOCTAGETENEMY
  else
    ifaction AOCTADEAD
  {
    strength 0
    state deadlist
     findnearsprite HEALBOLT 1024 temp
      ifvarn temp -1
	{
	subvar revives 1
	strength 10
	setactor[temp].xrepeat 0
	setvar monstatus 1
	action OCTARISE
	cstat 257
	break
	}

    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      state standard_jibs
      state clearlists
      killit
    }
    state checkdart
    break
  }
  else ifaction AOCTAFROZEN
  {
    ifcount THAWTIME
    {
      ai AIOCTAGETENEMY
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
      {
        ifactioncount 26
        {
          spawn WATERDRIP
          resetactioncount
        }
      }

    ifhitweapon
    {
      addkills 1
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }

      lotsofglass 30
      ifrnd 84
        spawn BLOODPOOL
      sound GLASS_BREAKING
      spritepal 22
      state standard_jibs
      ifvarg mval 0 { state dropcoins state addscore }
      state clearlists
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
       ifvare superkicking 0
        pkick
    break
  }
  else
  {
    ifrnd 1
      soundonce OCTA_ROAM

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

    ifmove OCTAUPVELS nullop
    else
      ifp phigher
        move OCTAUPVELS seekplayer
    else
      ifmove OCTAINWATER nullop
      else
        ifinwater
          move OCTAINWATER seekplayer

    ifhitweapon
      {
      state checkoctahitstate
      }
  }
enda

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


move PIGWALKVELS 72
move PIGRUNVELS 108
move PIGDODGEVELS 120
move PIGSTOPPED

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

state pigtype // this state changes 25% of actors into big red actors with extra health

//ifspawnedby POKEBALL break

ifai 0
{

	ifvarg score 100 ifrnd 128
	{
		ifactor TANK
		{
			ifvarg score 2000 ifrnd 128
			{
				spritepal 2 sizeat 72 72
				setvar mtype 1
				setvar mval EVILDUKEVAL
				addstrength 200
			}
		}
		else
		{
			randvar temp 15000
			subvar temp 1000
			ifvarvarl temp score ifrnd 84
			{
		    	state monstmakebarrier
		    	addvar mval 8
			}
			
			randvar temp 40000
			ifvarg score 4000 ifvarvarl temp score
			{
				cactor SUPERPIG 
				setvar mtype 2
				break
			}
			ifrnd 128
			{
				spritepal 19 sizeat 46 46
				setvar mtype 1
				addstrength 50
				setvar mval REDPIGVAL
			}
		}
	}

}
ends

state pigfiring
	
ifvare mtype 1 
{
	
    ifvare target -1 ifpdistg 2048 ifcanseetarget
	{ 
		shoot RPG 
		sound RPG_SHOOT
	} 
	else ifvarn target -1 
	{ 
		state holozdist
		state rpgatholo 
	}
	else
	{
		ifvare holosphere 0 setvar tilenum SHOTGUN else setvar tilenum SLOWBULLET
		sound PIG_ATTACK	
		shootvar tilenum
		shootvar tilenum
		shootvar tilenum
		shootvar tilenum
		shootvar tilenum
	}
	
}
else 
	ifvare mtype 2
	{
		findnearsprite SMOKER 16384 temp
	 	ifvare temp -1 ifrnd 64 
		{
			sound RPG_SHOOT
			zshoot -512 SMOKEBOMB
		}
		else
		{
			sound BLASTERSND
			shoot BLASTER3
			shoot BLASTER3
			shoot BLASTER3
		}
	 }
	 else ifvare mtype 3
	 {
		 sound PIG_ATTACK
		 shoot ACIDBULLET
		 shoot ACIDBULLET
		 shoot ACIDBULLET
		 shoot ACIDBULLET
		 shoot ACIDBULLET
		 shoot ACIDBULLET
		 shoot ACIDBULLET
		 ifpdistg 4096 shoot MORTER
	 }

	else
	{
		ifvare holosphere 0 setvar tilenum SHOTGUN else setvar tilenum SLOWBULLET
		sound PIG_ATTACK	
		shootvar tilenum
		shootvar tilenum
		shootvar tilenum
		shootvar tilenum
	}			
ends

state pigshootenemystate

    ifcount 12 nullop
    else
      ifcount 11
      {
      	state aimatholobot
      	ifvarn target -1 state pigfiring
      	else
      	ifcanshoottarget
      	state pigfiring

      	else
        	ai AIPIGSEEKENEMY
      }
    ifcount 25 nullop
    else
      ifcount 24
      {
        action APIGCOCK
        ifvarn mtype 2 sound SHOTGUN_COCK
        state shelleject2
      }
    ifcount 48 nullop
    else
      ifcount 47
    {
      state aimatholobot
      ifvarn target -1 state pigfiring
      else
      ifcanshoottarget
      state pigfiring
      
      else
        ai AIPIGSEEKENEMY
    }
    ifcount 60 nullop
    else
      ifcount 59
      {
        action APIGCOCK
        sound SHOTGUN_COCK
        state shelleject2
      }
    ifcount 72
    {
      ifrnd 64
        resetcount
      else
      {
        ifpdistl 768
          ai AIPIGFLEEENEMY
        else
          ai AIPIGSEEKENEMY
      }
    }
    ifaction APIGCOCK
      ifactioncount 2
        action APIGSHOOT
        
ends

state pigseekenemystate

  ifai AIPIGCHARGE
  {
    ifcansee
      ifpdistl 3084
    {
      ifnotmoving
        ai AIPIGSEEKENEMY
      else
        {
	        cactor PIGCOPDIVE
            ai AIPIGDIVING
        }
    }
    break
  }
  else iffloordistl 32
  {
    ifpdistg 4096
    {
	    ifactornotstayput
		{
			ifcansee 
			  ifrnd 128 
			    ifvarg mtype 0 
			ai AIPIGSHOOTENEMY
		    else ai AIPIGCHARGE
		}
    }
    ifrnd 8
    {
      ifbulletnear
        ai AIPIGDODGE
    }
  }

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

state pigfleeenemystate
  ifactioncount 8
    ai AIPIGSEEKENEMY
  else
    ifnotmoving
      ai AIPIGSEEKENEMY
ends

state pigdivestate
  ifactor PIGCOPDIVE nullop else cactor PIGCOPDIVE
  ifaction APIGDIVESHOOT
  {
    ifcansee
    {
      ifcount 12 nullop
      else
        ifcount 11
      {
	      state aimatholobot
	      ifvarn target -1 state pigfiring
	      else
	      ifcanshoottarget
	        state pigfiring
	        
	         else
	         {
	          cactor PIGCOP
	          ai AIPIGSEEKENEMY
	         }
      }
      ifcount 25 nullop
      else
        ifcount 24
          sound SHOTGUN_COCK
      ifcount 48 nullop
      else
        ifcount 47
      {
	      state aimatholobot
	      ifvarn target -1 state pigfiring
	      else
	      ifcanshoottarget
	      state pigfiring
	        
	        else
	        {
	          cactor PIGCOP
	          ai AIPIGSEEKENEMY
	        }
      }
      ifcount 60 nullop
      else
        ifcount 59
      {
        sound SHOTGUN_COCK
        ifgapzl 32
          {
	          cactor PIGCOPDIVE
	          ai AIPIGDIVING
          }
         else
        {
          cactor PIGCOP
          ifpdistl 4096
            ai AIPIGFLEEENEMY
          else
            ai AIPIGSEEKENEMY
        }
      }
    }
    else
      ifgapzl 32
        {
	        cactor PIGCOPDIVE
	        ai AIPIGDIVING
        }
       else
        {
        cactor PIGCOP
        ai AIPIGSEEKENEMY
        }
  }
  else
    ifactioncount 2
    ifp palive
    {
      resetcount
      action APIGDIVESHOOT
    }
ends

state checkpighitstate
  spawn BLOOD
  state checkdart
  ifdead
  {
     ifvare mtype 1
	{
           sound PIPEBOMB_EXPLODE spawn EXPLOSION2
           hitradius PIPEBOMBRADIUS WEAK MEDIUMSTRENGTH TOUGH ROBOTMOUSESTRENGTH
           state standard_jibs state drop_shotgun ifvarg mval 0 { state dropcoins state addscore } addkills 1 state clearlists killit
	}
    state random_wall_jibs
    
    ifrnd 16
      spawn SHIELD
    else state drop_shotgun
      

    ifwasweapon GROWSPARK
    {
	  cactor PIGCOP
      sound ACTOR_GROWING
      ai AIPIGGROW
      break
    }

    addkills 1
    ifvarg mval 0 { state dropcoins state addscore }

    ifvare revives 0
     {
      sound SQUISHED
      state standard_jibs
      state clearlists
      killit
    }

    ifwasweapon FREEZEBLAST
    {
	  cactor PIGCOP
      sound SOMETHINGFROZE
      spritepal 1
      move 0
      action APIGFROZEN
      strength 0
      break
    }
    ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      state clearlists
      killit
    }
    
    setvar temp 0
    ifwasweapon RPG setvar temp 1
    ifwasweapon RPGNOAIM setvar temp 1
    ifwasweapon HLROCKET setvar temp 1
    ifwasweapon CPUDEV setvar temp 1
    
    ifvare temp 1
    {
      sound SQUISHED
      state standard_jibs
      state clearlists
      killit
    }

    else
       {
      cactor PIGCOP
      ai AIPIGDYING
      }
        sound PIG_DYING
  }
  else
  {
    sound PIG_PAIN
    state random_wall_jibs

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

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

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

state pigcopcode

 state monsterai
 ifvarg menutoggle 0 break
  fall
  state setholotarg

  state checksquished
  
ifai 0
{
	setvar mval PIGVAL
	//state clone
}

state pigtype
ifactor SUPERPIG break
state monstersubstitution

getactor[THISACTOR].extra hp
ifvare scanned 1 ifpdistg 2024 ifrnd 16 ifvarg hp 0 ifactor PIGCOP
{
	setvar temp 0
	ifaction APIGFROZEN setvar temp 1
	ifai AIPIGSHOOTENEMY setvar temp 1
	ifai AIPIGDYING setvar temp 1
	ifai AIPIGDODGE setvar temp 1
	ifai AIPIGSHRINK setvar temp 1
    ifvare temp 0 ai AIPIGDODGE
}

ifaction PIGRISE ifactioncount 5 { setvar monstatus 1 ai AIPIGSEEKENEMY }

  ifaction APIGSTAND
    ai AIPIGSEEKENEMY
  else
    ifaction APIGDEAD
  {
      state deadlist
      findnearsprite HEALBOLT 1024 temp
      ifvarn temp -1
	{
		subvar revives 1
		strength 10
		setactor[temp].xrepeat 0
		cactor PIGCOP
		action PIGRISE
		spritepal 12
		cstator 257
		break
	}
      strength 0
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        state clearlists
        killit
      }
      state checkdart
      break
  }
  else
    ifaction APIGFROZEN
  {
    ifcount THAWTIME
    {
      ai AIPIGSEEKENEMY
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
        ifrnd 8
          spawn WATERDRIP

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

      lotsofglass 30
      ifrnd 84 spawn BLOODPOOL
      sound GLASS_BREAKING
      spritepal 22
      state standard_jibs
      ifvarg mval 0 { state dropcoins state addscore }
      state clearlists
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
       ifvare superkicking 0
        pkick
    break
  }
  else
    ifai AIPIGDYING
      state pigdyingstate
  else
    ifai AIPIGHIT
    {
      ifactioncount 3
      ai AIPIGSEEKENEMY
    }
  else
    ifai AIPIGSHRINK
      state pigshrinkstate
  else
  {
    ifai AIPIGSEEKENEMY
      state pigseekenemystate
    else
      ifai AIPIGDODGE
        state pigseekenemystate
    else
      ifai AIPIGSHOOTENEMY
        state pigshootenemystate
    else
      ifai AIPIGGROW
        state genericgrowcode
    else
      ifai AIPIGFLEEENEMY
        state pigfleeenemystate
    else
      ifai AIPIGDIVING
        state pigdivestate
    else
      ifai AIPIGCHARGE
        state pigseekenemystate
    ifhitweapon
      state checkpighitstate
    ifrnd 1
    {
      ifrnd 32
        soundonce PIG_ROAM
      else
        ifrnd 64
          soundonce PIG_ROAM2
      else
        soundonce PIG_ROAM3
    }
  }
ends

actor PIGCOPDIVE PIGCOPSTRENGTH

  state pigtype
  state monstersubstitution
ifai 0 { ai AIPIGDIVING ifvare mval 0 setvar mval PIGVAL }
ifvarn barrierup -1 
  { 
	  setactor[barrierup].xrepeat 0
	  setactor[barrierup].yrepeat 0
	  getactorvar[barrierup].countvarb temp
	  getactorvar[barrierup].countvar tempb
	  getactor[barrierup].cstat tempc
	  ifvare temp 0 ifvare tempb 0 ifvarn tempc 2
	    setactor[barrierup].cstat 258
	  
  }
state pigcopcode
ifvarn barrierup -1 { setactor[barrierup].xrepeat 128 setactor[barrierup].yrepeat 96 }
enda

actor PIGCOPSTAYPUT PIGCOPSTRENGTH
  
  state pigtype
  state monstersubstitution
  ai AIPIGSEEKENEMY
  ifvare mval 0 setvar mval PIGVAL
  ifactor PIGCOPSTAYPUT cactor PIGCOP
enda

useractor enemy SUPERPIG 250
  strength 250
  setvar mval TANKVAL
  
  state difficulty
  ifai 0 ai AIPIGSEEKENEMY
  ifrnd 128
  {
	  setvar mtype 2
	  spritepal 17
  }
  else
  {
	  setvar mtype 3
	  spritepal 14
  }
  sizeat 42 48
  cstator 257
  cactor PIGCOP
enda

actor PIGCOP PIGCOPSTRENGTH APIGSTAND
 ifvarn barrierup -1 
  {
	  setactor[barrierup].xrepeat 0
	  setactor[barrierup].yrepeat 0
	  getactorvar[barrierup].countvarb temp
	  getactorvar[barrierup].countvar tempb
	  getactor[barrierup].cstat tempc
	  ifvare temp 0 ifvare tempb 0 ifvarn tempc 2
	    setactor[barrierup].cstat 258
	  
  }
state pigcopcode
ifvarn barrierup -1 { setactor[barrierup].xrepeat 128 setactor[barrierup].yrepeat 96 }
enda


action ABOSS1WALK        0  4  5  1  12
action ABOSS1FROZEN        30 1  5
action ABOSS1RUN         0  6  5  1  5
action ABOSS1SHOOT         30 2  5  1  4
action ABOSS1LOB         40 2  5  1  35
action ABOSS1DYING        50 5  1  1  35
//action BOSS1FLINTCH       50 1  1  1  1
action ABOSS1DEAD         55
action BOSS1RISE 55 5 1 -1 45

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

ai AIBOSS1SEEKENEMY ABOSS1WALK BOSS1WALKVELS seekplayer
ai AIBOSS1RUNENEMY ABOSS1RUN BOSS1RUNVELS faceplayerslow
ai AIBOSS1SHOOTENEMY ABOSS1SHOOT BOSS1STOPPED faceplayerslow
ai AIBOSS1LOBBED ABOSS1LOB BOSS1STOPPED faceplayersmart
ai AIBOSS1DYING ABOSS1DYING BOSS1STOPPED faceplayer
ai AIBOSS1PALSHRINK ABOSS1WALK PALBOSS1SHRUNKRUNVELS furthestdir

state boss1palshrunkstate
  ifcount SHRUNKDONECOUNT
    ai AITROOPSEEKENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 40 40
  else
    state genericshrunkcode
ends

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

state boss1runenemystate
  ifpdistl 2048
  {
    ifp palive
      ai AIBOSS1SHOOTENEMY
    break
  }
  else
    ifcansee
  {
    ifactioncount 6
    {
      ifcanshoottarget
      {
        resetactioncount
        sound BOS1_WALK
      }
      else
        ai AIBOSS1SEEKENEMY
    }
  }
  else
    ai AIBOSS1SEEKENEMY
ends

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

  ifpdistl 2548
    ifp palive
  {
    ai AIBOSS1SHOOTENEMY
    break
  }

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

ends

state boss1dyingstate
  ifaction ABOSS1DEAD
  {
	move BOSS1STOPPED geth
//     ifspritepal 0
//     {
// 	    ifvarn lotag 0
// 	    {
// 		    addvar countvar 1
//       		ifvarg countvar 129
// 		    {
// 			    state standard_jibs
// 			    state standard_jibs
// 			    ifvare lotag -1 spawn BATTLEPORTAL else
// 			    espawn ACCESSCARD
// 			    ifvare lotag 1 setactor[RETURN].pal 0
// 			    else setactor[RETURN].pal lotag
// 			    killit
// 		    } else
// 		    ifrnd 64
// 		    {
// 			    randvar angvar 2047
// 			    randvar xydist 2047
// 			    getactor[THISACTOR].x x
// 			    setvarvar mx x
// 			    getactor[THISACTOR].y y
// 				addvarvar mx xydist
// 				rotatepoint x y mx y angvar mx my
// 				espawn EXPLOSION2
// 				setactor[RETURN].x mx
// 				setactor[RETURN].y my
// 				sound PIPEBOMB_EXPLODE
// 			}
// 		    
// 	    }
//         break
//     }
//       break
 
      state deadlist
      strength 0
      findnearsprite HEALBOLT 1024 temp
      ifvarn temp -1
	{
	subvar revives 1
	strength 10
	setactor[temp].xrepeat 0
	action BOSS1RISE
	setvar monstatus 1
	spritepal 12
	cstat 257
	break
	}
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        state standard_jibs
        // ifvarg mval 0 { state dropcoins state addscore }
        state clearlists
        killit
      }
      break
      state checkdart
   }
  else
  ifactioncount 5
  {
    iffloordistl 8
      sound THUD
    action ABOSS1DEAD
    cstat 0
    // endofgame 52
    
  }
ends

state boss1lobbedstate
  ifcansee
  {
    ifactioncount 2
    {
      resetactioncount
      state aimatholobot
      sound BOS1_ATTACK2
      ifspritepal 0 ifrnd 64 
      {
	      getplayer[THISACTOR].i temp
	      ldist xydist THISACTOR temp
	      divvar xydist -4
	      zshoot xydist POKEBALL
      } 
	  else
      shoot MORTER
    }
    else
      ifcount 64
        ifrnd 16
          state checkboss1seekstate
  }
  else
    state checkboss1seekstate
ends

state boss1shootenemy
  ifcount 72
    state checkboss1seekstate
  else
    ifaction ABOSS1SHOOT
      ifactioncount 2
  {
	ifvare mtype 1 setvar tilenum ACIDBULLET else
	ifvare holosphere 0 setvar tilenum CHAINGUN else setvar tilenum SLOWBULLET
    state aimatholobot
    sound BOS1_ATTACK1
    ifvare target -1
    {
  	  shootvar tilenum
  	  shootvar tilenum
  	  shootvar tilenum
 	  ifspritepal 0 { shootvar tilenum shootvar tilenum } 
    }
     else
    {
		state holozdist
		ifspritepal 0 addvar zdist 19000 else addvar zdist 12000
		ldist xydist THISACTOR target
		ifvare xydist 0 setvar xydist 1
		shiftvarl zdist 8
		divvarvar zdist xydist
		zshootvar zdist tilenum
		zshootvar zdist tilenum
		zshootvar zdist tilenum
		ifspritepal 0 { zshootvar zdist tilenum zshootvar zdist tilenum }
    }
	
    resetactioncount
  }
ends

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

    sound BOS1_DYING

    addkills 1
    ifvarg mval 0 
    {
	    ifvare lotag 42 
	    {
		    setvar mval 250
		    espawn BOSS2
		    setactorvar[RETURN].lotag 42
	    }
	    state dropcoins 
	    state addscore 
	}
    ai AIBOSS1DYING
   ifspritepal 0 nullop else ifvare revives 0
     {
      sound SQUISHED
      state standard_jibs
      state standard_jibs
      state clearlists
      killit
    }

  }
  else
  {
    ifrnd 32
    {
      action BOSS1FLINTCH
      move 0
    }

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

    soundonce BOS1_PAIN

    debris SCRAP1 1
    guts JIBS6 1
  }
ends

state boss1code

  state setholotarg
  state monsterai
  ifvarg menutoggle 0 break
  ifaction ABOSS1FROZEN
  {
    ifcount THAWTIME
    {
      ai AIBOSS1SEEKENEMY
      spritepal 21
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      state checkdart
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1
      lotsofglass 30
	  spritepal 22
      state standard_jibs
      ifrnd 84
       spawn BLOODPOOL
      sound GLASS_BREAKING
      ifvarg mval 0 { state dropcoins state addscore }
      state clearlists
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
       ifvare superkicking 0
        pkick
    break
  }
  ifai 0
  {
	 
     ifspritepal 0 
     {
	     setvar mval BOSSVAL 
	     ifvarg VOLUME 4 addstrength 10000
     }
   	  else 
   	  {
	   	  state boss1substitution
	   	  setvar mval EVILDUKEVAL
   	  }
  
    ifspritepal 0
      ai AIBOSS1RUNENEMY
    else
    {
	  ifvare mtype 0 
      	strength BOSS1PALSTRENGTH
      ai AIBOSS1SHOOTENEMY
    }
  }
  else
    ifaction BOSS1FLINTCH
  {
    ifactioncount 3
    ai AIBOSS1SHOOTENEMY
  }
  else
    ifai AIBOSS1SEEKENEMY
      state boss1seekenemystate
  else
    ifai AIBOSS1RUNENEMY
      state boss1runenemystate
  else
    ifai AIBOSS1SHOOTENEMY
      state boss1shootenemy
  else
    ifai AIBOSS1LOBBED
      state boss1lobbedstate
  else
    ifai AIBOSS1PALSHRINK
      state boss1palshrunkstate

  ifai AIBOSS1DYING
    state boss1dyingstate
  else
  {
    ifhitweapon
      {
      state checkboss1hitstate
       }
    else
      ifp palive
          ifpdistl 1280
          	ifvare superkicking 0
    {
	  ifspritepal 0
	  {
      	addphealth -1000
      	palfrom 63 63
  	  }
  	  else 
  	  {
	  	  ifai AIBOSS1PALSHRINK nullop else
	  	  {
		  	  
		  	  addphealth -2
		  	  palfrom 40 63
	  	  }
  	  }
    }
  }
ends

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

useractor enemy MINIBOSS1 400
setvar mtype 1
cstat 257
spritepal 17
sizeat 48 48
state difficulty
cactor BOSS1
enda

eventloadactor BOSS1
{
	getactor[THISACTOR].lotag lotag
	setactor[THISACTOR].lotag 0
}
enda
eventloadactor BOSS2
{
	getactor[THISACTOR].lotag lotag
	setactor[THISACTOR].lotag 0
}
enda
eventloadactor BOSS3
{
	getactor[THISACTOR].hitag hitag
	setactor[THISACTOR].hitag 0
	getactor[THISACTOR].lotag lotag
	setactor[THISACTOR].lotag 0
}
enda
eventloadactor BOSS4
{
	getactor[THISACTOR].lotag lotag
	setactor[THISACTOR].lotag 0
}
enda
eventloadactor EVILDUKE
{
	getactor[THISACTOR].lotag lotag
	setactor[THISACTOR].lotag 0
}
enda

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

move PALBOSS2SHRUNKRUNVELS 32
move PALBOSS2RUNVELS 192 -8
move BOSS2WALKVELS 224 -8
move BOSS2RUNVELS 256 -8
move BOSS2SPRINT 320 -8
move BOSS2STOPPED
move BOSS2JUMPVELS 400 -100
move BOSS2FALL 400
move BOSS2RISEVELS 0 -192

ai AIBOSS2SEEKENEMY ABOSS2WALK BOSS2WALKVELS seekplayer
ai AIBOSS2RUNENEMY ABOSS2RUN BOSS2RUNVELS faceplayerslow
ai AIBOSS2SHOOTENEMY ABOSS2SHOOT BOSS2STOPPED faceplayersmart //faceplayerslow
ai AIBOSS2LOBBED ABOSS2LOB BOSS2STOPPED faceplayerslow
ai AIBOSS2DYING ABOSS2DYING BOSS2STOPPED faceplayer
ai AIBOSS2PALSHRINK ABOSS2WALK PALBOSS2SHRUNKRUNVELS furthestdir
//ai AIBOSS2RISE BOSS2RISE BOSS2STOPPED geth
ai AIBOSS2RISE ABOSS2DEAD BOSS2RISEVELS spin
ai AIBOSS2JUMP ABOSS2JUMP BOSS2JUMPVELS jumptoplayer
ai BOSS2PAUSED ABOSS2LOB BOSS2STOPPED geth

state BOSS2jumpstate

getplayer[THISACTOR].i spriteid
ldist xydist THISACTOR spriteid

ifcount 78 nullop else
ifceilingdistl 96 count 79

ifcount 26
{
	ifmove BOSS2JUMPVELS 
	{
		ifrnd 96 
		{
			espawn EXPLOSION2
			setactor[RETURN].pal 6
		}
		ifvarl xydist 6144 
			move BOSS2FALL geth
		else
		ifcount 78
			move BOSS2FALL geth
	}
	
	
	iffloordistl 4 
	{
		ifaction ABOSS2JUMP
		{
			  action ABOSS2LOB
			  move BOSS2STOPPED
			  quake 52
			  spawn STOMPWAVE
		}
		ifaction ABOSS2LOB 
			ifactioncount 2 ai AIBOSS2SEEKENEMY
			
	}
}


ends


state BOSS2risestate
//ifactioncount 8
ifcount 78
{
  cstat 257
  spritepal 17
  setvar mtype 2
  strength 7000
  //sizeat 160 160
  setvar monstatus 1
  espawn LIFEBAR
  setactorvar[RETURN].myspawner THISACTOR
  ai AIBOSS2RUNENEMY
}
ifrnd 64
{
	espawn LIGHTNING_TRAIL2
	setactorvar[RETURN].myspawner THISACTOR
}
setactor[THISACTOR].htextra 0
setactor[THISACTOR].htpicnum -1
ends


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

state checkboss2seekstate
  ai AIBOSS2SEEKENEMY
  //ifspritepal 0 nullop
  //else
  //  move PALBOSS2RUNVELS seekplayer
ends

state boss2runenemystate
ifvare mtype 2 
	ifmove BOSS2RUNVELS
		move BOSS2SPRINT faceplayerslow
		
  ifcansee
  {
    ifactioncount 3
    {
      ifcanshoottarget
      {
        resetactioncount
        sound BOS1_WALK
      }
      else
        ai AIBOSS2SEEKENEMY
    }
    ifcount 48
      ifrnd 2
    {
      ifp palive
      {
        sound BOS2_ATTACK
        ai AIBOSS2SHOOTENEMY
      }
      break
    }
  }
  else
    ai AIBOSS2SEEKENEMY
ends

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

  ifcansee
    ifcount 32
      ifp palive
        ifrnd 48
          ifcanshoottarget
  {
    ifrnd 96
      ifpdistg 4096
    { 
      ai AIBOSS2RUNENEMY
      break
    }

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

state boss2dyingstate
  ifaction ABOSS2DEAD
  {
	move BOSS2STOPPED geth

      strength 0
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION ifvare mtype 2
      {
        sound SQUISHED
        state standard_jibs
      }
      state checkdart
      ifvare mtype 2 
      {
	    ifvarn lotag 0
	    {
		    addvar countvar 1
      		ifvarg countvar 130
		    {
			    state standard_jibs
			    state standard_jibs
				ifvarn lotag 42
				{
			    	espawn BOSSCOIN
			    	setactor[RETURN].pal 3
		    	}
			    killit
			  
		    } else
		    ifrnd 64
		    {
			    randvar angvar 2047
			    randvar xydist 2047
			    getactor[THISACTOR].x x
			    setvarvar mx x
			    getactor[THISACTOR].y y
				addvarvar mx xydist
				rotatepoint x y mx y angvar mx my
				espawn EXPLOSION2
				setactor[RETURN].x mx
				setactor[RETURN].y my
				sound PIPEBOMB_EXPLODE
			}
		    
	    }
        break
      }
      addvar countvar 1
      ifvarg countvar 129
      //ifcount 250 nullop else
      //ifcount 130
        ifrnd 64
   		{
      	 espawn LIGHTNING_TRAIL2
      	 setactorvar[RETURN].myspawner THISACTOR
   		}
      //ifcount 260 ai AIBOSS2RISE
      ifvarg countvar 259 { ai AIBOSS2RISE setvar countvar 0 }
      break
  }
  ifactioncount 8
  {
    iffloordistl 8
      sound THUD
    action ABOSS2DEAD
    cstat 0
    ifvare lotag 66 
    {
	    setvar mval 128
	    state dropcoins 
	    state addscore
	    setvar mtype 2
    }
  }
ends

state boss2lobbedstate
  ifcansee
  {
    ifactioncount 2
      resetactioncount
    else
      ifactioncount 1
      {
	    ifrnd 160
        shoot COOLEXPLOSION1
      }
    
    else
      ifcount 64
        ifrnd 16
        {
	      ifrnd 160
          state checkboss2seekstate
          else ai AIBOSS2JUMP
        }
  }
  else
    state checkboss2seekstate
ends

state boss2shootenemy
  ifcount 72
  {
	ifrnd 128
    state checkboss2seekstate
    else ai AIBOSS2JUMP
  }
  else
    ifaction ABOSS2SHOOT
      ifactioncount 2
  {
    state aimatholobot
    ifvare target -1 
    {  
	    ifvare mtype 2 
	    {
		    ifrnd 128
		    state shootnova_at_player
		}
	    else 
	    {
		    eshoot RPG
		    ifvare lotag 66 setactor[RETURN].extra 60
	    }
	} 
	else 
	{ 
		state holozdist 
		addvar zdist 19000 
		state rpgatholo 
	} 
// bosses are tall, so you must add to down angle
    resetactioncount
  }
ends

state checkboss2hitstate
  ifrnd 2
    spawn BLOODPOOL
   state checkdart
  ifdead
  {
    
    globalsound DUKE_TALKTOBOSSFALL
    sound BOS2_DYING
    addkills 1
    ifvarg mval 0 ifvare mtype 2 
    {
	    ifvare lotag 42 
	    {
		    setvar mval 250
		    espawn BOSS3
		    setactorvar[RETURN].lotag 42
	    }
	    state dropcoins 
	    state addscore 
	}
    ai AIBOSS2DYING
  }
  else 
  {
    ifai AIBOSS2JUMP nullop else
    ifrnd 144
    {
      ifrnd 32
      {
        action BOSS2FLINTCH
        move 0
      }
      else
      {
        sound BOS2_ATTACK
        ai AIBOSS2SHOOTENEMY
      }
    }

    soundonce BOS2_PAIN
    debris SCRAP1 1
    guts JIBS6 1
  }
ends

state boss2code

ifvarg menutoggle 0 
{
	setvar temp 0
	ifaction ABOSS2WALK setvar temp 1
	ifaction ABOSS2RUN setvar temp 1
	ifaction ABOSS2SHOOT setvar temp 1
	ifaction ABOSS2LOB setvar temp 1
	ifvare temp 1 { ai BOSS2PAUSED break }
}
else ifai BOSS2PAUSED ai AIBOSS2SHOOTENEMY

state setholotarg
state monsterai


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

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

      lotsofglass 30
      sound GLASS_BREAKING
      ifrnd 84 spawn BLOODPOOL
	  spritepal 22
      state standard_jibs
      ifvarg mval 0 
      {
	      ifvare lotag 42 
	      { 
		      setvar mval 250 
		      espawn BOSS3
		      setactorvar[RETURN].lotag 42
	      }
	      state dropcoins 
	      state addscore 
	  }
      state clearlists
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
       ifvare superkicking 0
        pkick
    break
  }
  ifai 0
  {
	  spritepal 3
	  setvar mval BOSSVAL
      ai AIBOSS2RUNENEMY
      ifvare lotag 66 strength 5000
  }
 
  else
    ifaction BOSS2FLINTCH
  {
    ifactioncount 3
      ai AIBOSS2SEEKENEMY
  }
  else
    ifai AIBOSS2SEEKENEMY
      state boss2seekenemystate
  else
    ifai AIBOSS2RUNENEMY
      state boss2runenemystate
  else
    ifai AIBOSS2SHOOTENEMY
      state boss2shootenemy
  else
    ifai AIBOSS2LOBBED
      state boss2lobbedstate
  else
    ifai AIBOSS2PALSHRINK
      state boss2palshrunkstate
   else
    ifai AIBOSS2RISE
       state BOSS2risestate
   else
    ifai AIBOSS2JUMP
      state BOSS2jumpstate

  ifai AIBOSS2DYING
    state boss2dyingstate
  else
  {
    ifhitweapon 
      {
       state checkboss2hitstate
       }
    else
      ifp palive
        ifpdistl 1280 
        	ifvare monstatus 1
        		ifvare superkicking 0
    {
      addphealth -1000
      palfrom 63 63
    }
  }


ends

actor BOSS2 BOSS2STRENGTH state boss2code fall enda

action AMINIBOSS2WALK        -9  4  5  1  30
action AMINIBOSS2FROZEN        -9  1  5
action AMINIBOSS2RUN         -9  4  5  1  15
action AMINIBOSS2SHOOT         11 2  5  1  15
action AMINIBOSS2LOB         21 2  5  1  105
action AMINIBOSS2DYING        31 8  1  1  35
//action MINIBOSS2FLINTCH       31 1  1  1  1
action AMINIBOSS2DEAD         39
action MINIBOSS2RISE 39 8 1 -1 45

move PALMINIBOSS2SHRUNKRUNVELS 32
move PALMINIBOSS2RUNVELS 160
move MINIBOSS2WALKVELS 192
move MINIBOSS2RUNVELS 256
move MINIBOSS2STOPPED

ai AIMINIBOSS2SEEKENEMY AMINIBOSS2WALK MINIBOSS2WALKVELS seekplayer
ai AIMINIBOSS2RUNENEMY AMINIBOSS2RUN MINIBOSS2RUNVELS faceplayerslow
ai AIMINIBOSS2SHOOTENEMY AMINIBOSS2SHOOT MINIBOSS2STOPPED faceplayersmart  // was faceplayer
ai AIMINIBOSS2LOBBED AMINIBOSS2LOB MINIBOSS2STOPPED faceplayerslow
ai AIMINIBOSS2DYING AMINIBOSS2DYING MINIBOSS2STOPPED faceplayer
ai AIMINIBOSS2PALSHRINK AMINIBOSS2WALK PALMINIBOSS2SHRUNKRUNVELS furthestdir

state MINIBOSS2palshrunkstate
  ifcount SHRUNKDONECOUNT
  {
    cstat 257
    ai AIMINIBOSS2SEEKENEMY // AITROOPSEEKENEMY
  }
  else
    ifcount SHRUNKCOUNT
      sizeto 40 40
  else
    state genericshrunkcode
ends

state checkMINIBOSS2seekstate
  ai AIMINIBOSS2SEEKENEMY
      move PALMINIBOSS2RUNVELS seekplayer
ends

state MINIBOSS2runenemystate
  ifcansee
  {
    ifactioncount 3
    {
      ifcanshoottarget
      {
        resetactioncount
        sound BOS1_WALK
      }
      else
        ai AIMINIBOSS2SEEKENEMY
    }
    ifcount 48
      ifrnd 2
    {
      ifp palive
      {
        sound BOS2_ATTACK
        ai AIMINIBOSS2SHOOTENEMY
      }
      break
    }
  }
  else
    ai AIMINIBOSS2SEEKENEMY
ends

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

  ifcansee
    ifcount 32
      ifp palive
        ifrnd 48
          ifcanshoottarget
  {
    ifrnd 64
      ifpdistg 4096
    {
      ai AIMINIBOSS2RUNENEMY
          move PALMINIBOSS2RUNVELS seekplayer
      break
    }

    ifpdistl 6144
    {
      ifrnd 128
      {
        sound BOS2_ATTACK
        ai AIMINIBOSS2LOBBED
      }
    }
    else
    {
      sound BOS2_ATTACK
      ai AIMINIBOSS2SHOOTENEMY
    }
  }
ends

state MINIBOSS2dyingstate
  ifaction AMINIBOSS2DEAD
  {    

	  move MINIBOSS2STOPPED geth
      strength 0
      state deadlist
      findnearsprite HEALBOLT 1024 temp
      ifvarn temp -1
	{
	subvar revives 1
	strength 10
	setactor[temp].xrepeat 0
	action MINIBOSS2RISE
	setvar monstatus 1
	spritepal 12
	cstat 257
	break
	}
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        state clearlists
        killit
      }
      state checkdart
      break
  }
  ifactioncount 8
  {
    iffloordistl 8
      sound THUD
    action AMINIBOSS2DEAD
    cstat 0
    

  }
ends

state MINIBOSS2lobbedstate
  ifcansee
  {
    ifactioncount 2
      resetactioncount
    else
      ifactioncount 1
    {
     shoot FLAMETHROWER
    }
    else
      ifcount 64
        ifrnd 16
          state checkMINIBOSS2seekstate
  }
  else
    state checkMINIBOSS2seekstate
ends

state MINIBOSS2shootenemy
  ifcount 72
    state checkMINIBOSS2seekstate
  else
    ifaction AMINIBOSS2SHOOT
      ifactioncount 2
  {
    state aimatholobot
    state devastator_at_player
    ifvarg score 15000 state devastator_at_player
    ifvarvarn target currholo
    {
	    ifcanshoottarget nullop else state checkMINIBOSS2seekstate
    }
    resetactioncount
  }
ends

state checkMINIBOSS2hitstate
  ifrnd 2
    spawn BLOODPOOL
   state checkdart
  ifdead
  {
    
    {
      ifrnd 64
        globalsound DUKE_TALKTOBOSSFALL
      ifwasweapon FREEZEBLAST
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action AMINIBOSS2FROZEN
        strength 0
        break
      }
    }

    sound BOS2_DYING

    addkills 1
    ifvarg mval 0 { state dropcoins state addscore }
    ifspritepal 0 nullop else ifvare revives 0
     {
      sound SQUISHED
      state standard_jibs
      state standard_jibs
      state clearlists
      killit
    }

    ai AIMINIBOSS2DYING
  }
  else
  {
    ifrnd 144
    {
      ifrnd 32
      {
        action MINIBOSS2FLINTCH
        move 0
      }
      else
      {
        sound BOS2_ATTACK
        ai AIMINIBOSS2SHOOTENEMY
      }
    }

        ifwasweapon SHRINKSPARK ifvarl hp 301
    {
      sound ACTOR_SHRINKING
      ai AIMINIBOSS2PALSHRINK
      break
    }

    soundonce BOS2_PAIN

    debris SCRAP1 1
    guts JIBS6 1
  }
ends

state MINIBOSS2code

state setholotarg
  state monsterai
  ifvarg menutoggle 0 break
  
  ifaction MINIBOSS2RISE ifactioncount 8 ai AIMINIBOSS2SEEKENEMY

  ifaction AMINIBOSS2FROZEN
  {
    ifcount THAWTIME
    {
      ai AIMINIBOSS2SEEKENEMY
        spritepal 17
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      state checkdart
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }

      addkills 1

      lotsofglass 30
      sound GLASS_BREAKING
      ifrnd 84 spawn BLOODPOOL
      spritepal 22
      state standard_jibs
      ifvarg mval 0 { state dropcoins state addscore }
      state clearlists
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
       ifvare superkicking 0
        pkick
    break
  }
  ifai 0
  {
    spritepal 17
    cstat 257
    sizeat 48 40
    setvar mval MINIBOSSVAL
    state difficulty
    ai AIMINIBOSS2RUNENEMY
  }
  else
    ifaction MINIBOSS2FLINTCH
  {
    ifactioncount 3
      ai AIMINIBOSS2SEEKENEMY
  }
  else
    ifai AIMINIBOSS2SEEKENEMY
      state MINIBOSS2seekenemystate
  else
    ifai AIMINIBOSS2RUNENEMY
      state MINIBOSS2runenemystate
  else
    ifai AIMINIBOSS2SHOOTENEMY
      state MINIBOSS2shootenemy
  else
    ifai AIMINIBOSS2LOBBED
      state MINIBOSS2lobbedstate
  else
    ifai AIMINIBOSS2PALSHRINK
      state MINIBOSS2palshrunkstate

  ifai AIMINIBOSS2DYING
    state MINIBOSS2dyingstate
  else
  {
    ifhitweapon 
      {
       state checkMINIBOSS2hitstate
      }
  }


ends

useractor enemy MINIBOSS2 250 state MINIBOSS2code fall enda


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

move PALBOSS3SHRUNKRUNVELS 32
move PALBOSS3RUNVELS 270 // full speed even for palette shifted version 84
move PALBOSS3JUMPVELS 200 -200
move PALBOSS3DOWNVELS 200 100
move BOSS3WALKVELS 208
move BOSS3RUNVELS 270
move BOSS3STOPPED

ai AIBOSS3SEEKENEMY ABOSS3WALK BOSS3WALKVELS seekplayer
ai AIBOSS3RUNENEMY ABOSS3RUN BOSS3RUNVELS faceplayerslow
ai AIBOSS3LOBENEMY ABOSS3LOB BOSS3STOPPED faceplayersmart // was faceplayer
ai AIBOSS3DYING ABOSS3DYING BOSS3STOPPED geth
ai AIBOSS3PALSHRINK ABOSS3WALK PALBOSS3SHRUNKRUNVELS faceplayer
ai AIBOSS3PALJUMP ABOSS3RUN PALBOSS3JUMPVELS jumptoplayer

state boss3jumpstate  // new for MINIBOSS3
  ifcount 9 { ai AIBOSS3SEEKENEMY resetcount }
ends

state boss3palshrunkstate
  ifcount SHRUNKDONECOUNT
   ai AIBOSS3SEEKENEMY // ai AITROOPSEEKENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 32 32
  else
    state genericshrunkcode
ends

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

state boss3runenemystate

ifspritepal 0 ifvare hitag 1 
{
	ifvare goggles 0 cstat 32768 else cstat 2
}

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

state boss3seekenemystate

ifspritepal 0 ifvare hitag 1 
{
	ifvare goggles 0 cstat 514 else cstat 2
}

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

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

    ifp palive
	{
	ifvare mtype 1 
	  { ifrnd 128 ai AIBOSS3LOBENEMY } 
	else ifvare mtype 3 ai AIBOSS3RUNENEMY
	else
   	 ai AIBOSS3LOBENEMY
	}
  }
  
 ifvare mtype 2
 {
	 ifcansee
	   ifcanshoottarget
	     ifcount 16
	       ifrnd 48
	         ifp palive
	           ai AIBOSS3LOBENEMY
 }
	     

 ifvarg mtype 0 ifp phigher ifrnd 16 ifcount 32  // new for MINIBOSS3
       ai AIBOSS3PALJUMP

ends

state boss3dyingstate
  ifaction ABOSS3DEAD
  {
    ifspritepal 0
    {
	    ifvarn lotag 0
	    {
		    addvar countvar 1
		    ifvarg countvar 130
		    {
			    state standard_jibs
			    state standard_jibs
			    ifvarn lotag 42
			    {
			    	espawn BOSSCOIN
			    	setactor[RETURN].pal 3
		    	}
			    killit
		    } else
		    ifrnd 64
		    {
			    randvar angvar 2047
			    randvar xydist 2047
			    getactor[THISACTOR].x x
			    setvarvar mx x
			    getactor[THISACTOR].y y
				addvarvar mx xydist
				rotatepoint x y mx y angvar mx my
				espawn EXPLOSION2
				setactor[RETURN].x mx
				setactor[RETURN].y my
				sound PIPEBOMB_EXPLODE
			}
		    break
	    }
	    else
        break
    }
      strength 0
      state deadlist
      findnearsprite HEALBOLT 1024 temp
      ifvarn temp -1
	{
		subvar revives 1
		strength 10
		setactor[temp].xrepeat 0
		action BOSS3RISE
		setvar monstatus 1
		spritepal 12
		cstat 257
		break
	}
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        state clearlists
        killit
      }
      state checkdart
      break
  }
  ifactioncount 8
  {
    iffloordistl 8
      sound THUD
    action ABOSS3DEAD
    cstat 0
    /* ifspritepal 0
    	 endofgame 52 */
         
  }
ends

state boss3lobbedstate

  ifspritepal 0 ifvare hitag 1 cstat 257
  
  ifcansee
  {
    ifaction ABOSS3LOBBING
      ifactioncount 2
    {
	     state aimatholobot
	     
	     ifvare mtype 0
	     {
		     ifvare hitag 1
		     {
			     randvar tempd 8
			     
			     switch tempd
			     
			     case 0
		          sound BOS1_ATTACK2
				  getplayer[THISACTOR].i temp
				  ldist xydist THISACTOR temp
				  divvar xydist -4
				  ezshoot xydist POKEBALL
				  setactorvar[RETURN].hitag 1
				 break
				 
				 case 1
				 case 2
				  
			      	ifrnd 192 ifvarn currholo -1 setvarvar target currholo else
					getplayer[THISACTOR].i target
					state calczdist
					mulvar zdist 644
					ldist xydist THISACTOR target
					ifvare xydist 0 setvar xydist 1
					divvarvar zdist xydist
					sound MISSILE2
					ezshoot zdist HLROCKET
				    setthisprojectile[RETURN].extra 100
				    setthisprojectile[RETURN].trail SMALLEXPLOSION
					flash
					setactorvar[RETURN].target target
					setactorvar[RETURN].mtype 1
					break
				 
				 case 3
				 case 4
				 case 5
				 case 6
				 case 7
				 case 8
					sound RPG_SHOOT
					shoot FIREBULLET
					shoot FIREBULLET
					shoot FIREBULLET
					break

				endswitch
				
				ifvare goggles 0 ifrnd 64 { ai AIBOSS3RUNENEMY break }
		     }
		     else
		     {
			     ifvarn target -1
			     {
				      state holozdist 
					  addvar zdist 19000 
					  state rpgatholo
				 }
				 else
				 {
				     shoot RPG
				     ifvare lotag 66
				     ifrnd 16
				     {
					     eshoot POKEBALL
					     setactorvar[RETURN].hitag 1
				     } 
		     	 }
	     	 } 
	     }
	     else
	     ifvare mtype 2
	     {
		     sound PRED_ATTACK
		     shoot FIRELASER
		     shoot FIRELASER
		     shoot FIRELASER
		     shoot FIRELASER
	     }
	     else
	     {
		 	state devastator_at_player
	 	 }
		  

	      resetactioncount
	      ifrnd 8
	        ai AIBOSS3SEEKENEMY
    }

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

state checkboss3hitstate
  ifrnd 2
    spawn BLOODPOOL

   state checkdart

  ifdead
  {
    ifspritepal 0
    {
        globalsound DUKE_TALKTOBOSSFALL
        addkills 1
        ifvarg mval 0 
        {
	        ifvare lotag 66 setvar mval 128
	        ifvare lotag 42 
		    {
			    setvar mval 250 
			    espawn BOSS4
			    setactorvar[RETURN].lotag 42
		    }
	        state dropcoins 
	        state addscore 
	    }
    }
    else
    {
	    ifrnd 48 globalsound DUKE_TALKTOBOSSFALL
	    addkills 1
	    ifvarg mval 0 { state dropcoins state addscore }
	
	    ifvare revives 0
	    {
	      sound SQUISHED
	      state standard_jibs
	      state clearlists
	      killit
	    }
	
	    ifwasweapon FREEZEBLAST
	    {
	        sound SOMETHINGFROZE
	        spritepal 1
	        move 0
	        action ABOSS3FROZEN
	        strength 0
	        break
	    }
	      
	    setvar temp 0
	    ifwasweapon RPG setvar temp 1
	    ifwasweapon RPGNOAIM setvar temp 1
	    ifwasweapon HLROCKET setvar temp 1
	    ifwasweapon CPUDEV setvar temp 1
	    
	    ifvare temp 1
	    {
		     sound SQUISHED
		     state standard_jibs
		     state standard_jibs
		     spawn BLOOD
		     state clearlists
		     killit
	    }
	
	    ifwasweapon RADIUSEXPLOSION
	    {
		     sound SQUISHED
		     state standard_jibs
		     state standard_jibs
		     spawn BLOOD
		     state clearlists
		     killit
	    }
    }
    ai AIBOSS3DYING
    sound BOS3_DYING
    sound JIBBED_ACTOR9

  }
  else
  {
    ifrnd 32
    {
      action BOSS3FLINTCH
      move 0
    }
    else ifvare mtype 1 ifrnd 32 { action BOSS3FLINTCH move 0 }

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

    soundonce BOS3_PAIN

    debris SCRAP1 1
    guts JIBS6 1
  }
ends

state boss3code

ifvare mtype 3 
{
	getactor[THISACTOR].cstat tempd
	cstat 514
	ifvare monstatus 1 spawn FRAMEEFFECT1
	setactor[THISACTOR].cstat tempd
	ifai AIBOSS3DYING nullop else ifpdistl 2048 ifcansee 
	{
		ifmove BOSS3RUNVELS nullop else
		move BOSS3RUNVELS faceplayer geth
	}
}
 
 ifspritepal 0 
 { 
	 ifvare mval -1 nullop 
	 else 
		 setvar mval BOSSVAL
 }

state setholotarg
  state monsterai
  ifvarg menutoggle 0 break

  
  ifaction BOSS3RISE ifactioncount 8 ai AIBOSS3RUNENEMY
  ifaction ABOSS3FROZEN
  {
    state checkdart
    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }

      addkills 1
      lotsofglass 30

      ifrnd 84
      spawn BLOODPOOL
      sound GLASS_BREAKING
      spritepal 22
      state standard_jibs
      ifspritepal 0 { state standard_jibs state standard_jibs }
      ifvarg mval 0 { state dropcoins state addscore }
      state clearlists
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
       ifvare superkicking 0
        pkick
    break
  }

 
  ifai 0
  {
	ifvare lotag 42 setvar hitag 1
	ifvare mtype 1 setvar mval MINIBOSSVAL
	ifvare mtype 2 setvar mval TANKVAL
	ifvare mtype 3 setvar mval TANKVAL
	ifvare mtype 0 ifspritepal 0
	ifvare hitag 1
		addstrength 1000	 
    ai AIBOSS3RUNENEMY
  } 

  else


   ifai AIBOSS3PALJUMP
      state boss3jumpstate 
      
   else

    ifaction BOSS3FLINTCH
    {
      ifactioncount 3
      ai AIBOSS3SEEKENEMY
    }
  else

    ifai AIBOSS3SEEKENEMY
      state boss3seekenemystate
  else
    ifai AIBOSS3RUNENEMY
      state boss3runenemystate
  else
    ifai AIBOSS3LOBENEMY
      state boss3lobbedstate
  else
    ifai AIBOSS3PALSHRINK
      state boss3palshrunkstate

  ifai AIBOSS3DYING
    state boss3dyingstate
  else
  {
    ifhitweapon
    {
      state checkboss3hitstate
    }
    else
      ifp palive
       // ifspritepal 0
          ifpdistl 1280
             ifvare superkicking 0
      {
		ifvare mtype 1                    
		{
			ifai AIBOSS3PALSHRINK nullop else
			{
				ifrnd 128 ifcanseetarget 
				{ 
					addphealth -1
					palfrom 32 63 
				}
			}
		}
		else ifvarg mtype 1 ifvarl mtype 4
		{
			ifai AIBOSS3PALSHRINK nullop else
			{
				ifcanseetarget 
				{ 
					addphealth -1
					palfrom 48 63 
				}
			}
		}
		else
		{
        	addphealth -1000
       		palfrom 63 63
		}
	           
      }
  }
ends

actor BOSS3 BOSS3STRENGTH state boss3code fall enda

useractor enemy MINIBOSS3 125

ifvarg score 5000 ifrnd 96
{
	ifrnd 128
	{
		sizeat 36 36 
		spritepal 19 
		setvar mtype 2
		addstrength 125
	}
	else
	{
		sizeat 36 36
		spritepal 4
		cstator 2
		setvar mtype 3
		addstrength 200
	}
}
else
{
	sizeat 32 32 
	spritepal 17 
	setvar mtype 1
}

cstator 257
state difficulty cactor BOSS3
enda


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


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

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

state checkcommhitstate

  ifhitweapon
  {
    guts JIBS6 2
    state checkdart
    ifdead
    {
      ifwasweapon FREEZEBLAST
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action ACOMMFROZEN
        strength 0
        break
      }
      else
        ifwasweapon GROWSPARK
      {
        sound ACTOR_GROWING
        ai AICOMMGROW
        break
      }

      addkills 1
     ifvarg mval 0 { state dropcoins state addscore }

      ifvare revives 0
     {
      sound SQUISHED
      state standard_jibs
      state clearlists
      killit
    }

      ifwasweapon RADIUSEXPLOSION
      {
        spawn BLOODPOOL
        sound SQUISHED
        state standard_jibs
        state clearlists
        killit
      }
    setvar temp 0
    ifwasweapon RPG setvar temp 1
    ifwasweapon RPGNOAIM setvar temp 1
    ifwasweapon HLROCKET setvar temp 1
    ifwasweapon CPUDEV setvar temp 1
    
    ifvare temp 1
      {
        sound SQUISHED
        spawn BLOODPOOL
        state standard_jibs
        state clearlists
        killit
      }

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

actor COMMANDERSTAYPUT COMMANDERSTRENGTH
  setvar mval COMMVAL
  cactor COMMANDER
  ai AICOMMABOUTTOSHOOT
enda

actor COMMANDER COMMANDERSTRENGTH

  state checksquished
  state monsterai
  ifvarg menutoggle 0 break

  ifai 0 
	{
		setvar mval COMMVAL
		ifvarg score 1999 ifrnd 64 
		{ 
			setvar mtype 1 setvar mval TANKVAL
			addstrength 200
			spritepal 17
		}
		//state clone
    }

state setholotarg

  ifaction COMMRISE ifactioncount 8 ai AICOMMWAIT
  ifaction ACOMMFROZEN
  {
    fall

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

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

      ifrnd 84
        spawn BLOODPOOL
      lotsofglass 30
      sound GLASS_BREAKING
      spritepal 22
      state standard_jibs
      ifvarg mval 0 { state dropcoins state addscore }
      state clearlists
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
       ifvare superkicking 0
        pkick
    break
  }
  ifai 0
    ai AICOMMSHOOT
  else
    ifai AICOMMWAIT
  {
    ifcount 20
    {
      ifcansee
      {
        ifcanshoottarget
        {
          ifrnd 64  // was 96
            ai AICOMMGET
          else
            ai AICOMMABOUTTOSHOOT
        }
      }
      else
        ai AICOMMGET
    }
  }
  else
    ifai AICOMMABOUTTOSHOOT
  {
    ifactioncount 2
    {
      ifcansee
        ai AICOMMSHOOT
      else
      {
        ai AICOMMGET
        break
      }
    }
    ifrnd 32 soundonce COMM_ATTACK
  }
  else
    ifai AICOMMSHOOT
  {
    ifcanshoottarget
    {
      ifcount 24
        ifrnd 16
          ai AICOMMWAIT
      ifactioncount 2
      {
	   ifpdistl 1536 ai AICOMMSPIN else
		{
		 ifvare mtype 1 state shootnova_at_player
		 else
		 {
    	    ifrnd 128 shoot RPG
   		    else spawn SEEKER
		 }
      		
		  resetactioncount
		}
      }
    }
    else
      ai AICOMMGET
  }
  else
    ifai AICOMMSHRUNK
  {
    ifcount SHRUNKDONECOUNT
      ai AICOMMGET
    else
      ifcount SHRUNKCOUNT
       sizeto 48 40
    else
      state genericshrunkcode
  }
  else
    ifai AICOMMGROW
      state genericgrowcode
  else
    ifai AICOMMGET
  {
    ifnotmoving
      ifrnd 4
        operate
    ifpdistl 1024
      ifp palive
    {
      sound COMM_SPIN
      ai AICOMMSPIN
      break
    }

    ifcansee
    {
      ifp phigher
        move COMMGETUPVELS getv geth faceplayerslow
      else
        move COMMGETVELS getv geth faceplayerslow
    }
    ifactioncount 8
      ifrnd 2
        ai AICOMMABOUTTOSHOOT
  }
  else
    ifai AICOMMSPIN
  {

    // code to make him move towards player while spinning
    ifcansee
     {
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		getactor[THISACTOR].z z
		getplayer[THISACTOR].posx mx
		getplayer[THISACTOR].posy my
		ifvarvarg x mx subvar x 64 else addvar x 64
		ifvarvarg y my subvar y 64 else addvar y 64
		updatesectorz x y z mysector
		ifvarn mysector -1
		{
			setactor[THISACTOR].x x
			setactor[THISACTOR].y y
		}
     }
    ifpdistg 6144 ai AICOMMWAIT
    soundonce COMM_SPIN
    ifcount 16
    {
      ifpdistl 1280 ifcansee
      {
        addphealth CAPTSPINNINGPLAYER
        sound DUKE_GRUNT
        palfrom 32 16 
	    resetcount
      }

    }
    
    ifactioncount 52
      ai AICOMMWAIT
    
    ifnotmoving
      ifrnd 32
        operate
  }

  ifai AICOMMDYING
  {
    fall
    strength 0
    
    ifaction ACOMMDEAD
      {
	  move COMMSTOPPED geth
      state deadlist
      findnearsprite HEALBOLT 1024 temp
      ifvarn temp -1
	{
	subvar revives 1
	strength 10
	setactor[temp].xrepeat 0
	action COMMRISE
	setvar monstatus 1
	spritepal 12
	cstat 257
	break
	}
       }


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

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

enda


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

useractor notenemy CANNONBALL CANNONBALLSTRENGTH

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

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

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

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

enda


define CANNONBALLS 1818
define CANNONBALLSSTRENGTH 10
move CANNONBALLSVEL

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


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

useractor enemy CANNON CANNONSTRENGTH // fall

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

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

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

useractor notenemy HOTMEAT TOUGH
  ifaction 0
  {
    action ANULLACTION
    cstat 257
  }
  ifhitweapon
  {
    ifdead
    {
      sound SQUISHED
      guts JIBS5 8
      guts JIBS6 9
      killit
    }
    else
      guts JIBS6 1
  }
  ifrnd 1
    spawn WATERDRIP

enda

action ASPEAKERBROKE 1
useractor notenemy SPEAKER
  ifaction 0
  {
    ifhitweapon
    {
      stopsound STORE_MUSIC
      soundonce STORE_MUSIC_BROKE
      action ASPEAKERBROKE
    }
    else
    {
      ifpdistl 10240
          soundonce STORE_MUSIC
      cstat 289
    }
  }
enda

action ALAVABUBBLE
action ALAVABUBBLEANIM 0 5 1 1 16

useractor notenemy LAVABUBBLE
  ifaction 0
  {
    cstat 32768
    action ALAVABUBBLE
  }
  else
    ifaction ALAVABUBBLE
  {
    ifcount 72
      ifrnd 2
    {
      cstat 0
      action ALAVABUBBLEANIM
    }
  }
  else
  {
    ifactioncount 5
    {
      cstat 32768
      action ALAVABUBBLE
    }
  }
enda

// RIOT TANK with Pigcop inside

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

useractor enemy TANK TANKSTRENGTH

state monsterai
ifvarg menutoggle 0 break
fall

state setholotarg
  
  ifaction 0
  {
    setvar mval TANKVAL
    sizeat 60 60
    cstat 257
    clipdist 100
    state pigtype
    state difficulty
    //state clone
    action ATANKWAIT
  }
  else

    ifaction ATANKSPIN
  {
    soundonce TANK_ROAM

    ifactioncount 20
    {
      ifrnd 16
        ifcansee
          ifcanshoottarget
      {
        move TANKSTOP geth
        action ATANKSHOOTING
        stopsound TANK_ROAM
      }
    }

    ifrnd 16
      move TANKFORWARD seekplayer
  }
  else
    ifaction ATANKSHOOTING
  {
    ifactioncount 22
    {
      ifpdistg 8192
      {
        state aimatholobot
        sound BOS1_ATTACK2
        ifvare target -1 shoot MORTER else { state holozdist state rpgatholo }
      }
      resetcount
      move 0 action ATANKWAIT
    }
    else
      ifactioncount 2
    {
      ifcansee
      {
	  ifpdistl 6144 shoot FLAMETHROWER else

        ifpdistl 16384
        {
          ifrnd 128
          {
            state aimatholobot
            sound FLAK_FIRE
            ifvare target -1 
		    {
				ifvare mtype 1 shoot FLAK
				else
				shoot SLOWBULLET 
		    }
			
				else { state holozdist state chainfireatholo }
          }
        }
        else
          ifrnd 128
        {
          state aimatholobot
          sound PRED_ATTACK
          ifvare mtype 1 shoot FIRELASER2 else shoot FIRELASER
        }
      }
      else
      {
        move TANKFORWARD seekplayer
        action ATANKSPIN
      }
    }

    ifrnd 16
    {
      stopsound TANK_ROAM
      move TANKSTOP faceplayerslow
    }
  }
  else
    ifaction ATANKWAIT
  {
    ifactioncount 32
    {
      move TANKFORWARD seekplayer
      action ATANKSPIN
    }
  }
  else
    ifaction ATANKDESTRUCT
  {
    ifactioncount 64
      action ATANKDEAD
    else
      ifactioncount 56
       sound LASERTRIP_ARMING
     else
       ifactioncount 48
         sound LASERTRIP_ARMING
     else
       ifactioncount 32
         sound LASERTRIP_ARMING
     else
       ifactioncount 16
         sound LASERTRIP_ARMING
     break
  }
  else
    ifaction ATANKDEAD
  {
    addkills 1
    hitradius 6144 TOUGH TOUGH TOUGH TOUGH
    sound LASERTRIP_EXPLODE
    debris SCRAP1 15
    spawn BIGEXPLOSION
    palfrom 33 63 63 63
    wackplayer
    // spawn EXPLOSION2
    ifvare mtype 1 nullop else ifrnd 128 spawn PIGCOP
    ifvarg mval 0 { state dropcoins state addscore }
    state clearlists
    killit
  }

  ifhitweapon
  {
    state checkdart
    ifdead
      action ATANKDEAD
    else
    {
      debris SCRAP1 1
      ifaction ATANKSHOOTING break

      ifrnd 192
      {
        move TANKSTOP geth
        action ATANKSHOOTING
        stopsound TANK_ROAM
      }
    }
  }

  ifpdistl 1280
    ifhitspace
      ifp pfacing
        ifangdiffl 512
          action ATANKDESTRUCT
enda







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

move BOSS4WALKVELS 128
move BOSS4STOPPED

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

state boss4shootstate
  ifaction ABOSS4ABOUTTOSHOOT
    ifactioncount 3
      action ABOSS4SHOOT

  ifaction ABOSS4SHOOT
  {
    ifcount 48
    {
      ifrnd 4
        ai AIBOSS4LAYEGGS
    }
    ifcount 26
      ifrnd 32
    {
      ifrnd 128
      {
        sound SHORT_CIRCUIT
        addphealth -2
      }
      else
      {
        sound DUKE_GRUNT
        addphealth -1
      }
      palfrom 32 32 0 0
    }
  }

ends

state boss4layeggs


  ifrnd 2
    sound BOS4_ROAM

  ifaction ABOSS4LAYIT
  {
	ifvare lotag 42 ifvarl spiders 512 ifrnd 128
	{
		espawn SPIDERX
		setactorvar[RETURN].mtype 1
	}
	
    ifactioncount 3
      ifcount 32
    {
      ai AIBOSS4LAYEGGS
      ifrnd 32
        move BOSS4WALKVELS furthestdir geth
      spawn NEWBEASTHANG
    }
  }
  else
    ifcount 64
      ifrnd 4
  {
    move 0

    ifrnd 88
    {
      action ABOSS4LAYIT
      sound BOS4_LAY
    }
    else
      ifp palive
        ifcansee
    {
      ai AIBOSS4SHOOT
      sound BOS4_ATTACK
    }
  }

ends

state boss4dyingstate
  ifaction ABOSS4DEAD
  {
	 
	  ifvarn lotag 0
	  {
		    addvar countvar 1
		    ifvarg countvar 130
		    {
			    spritepal 6
			    state standard_jibs
			    state standard_jibs
			    killit
		    } else
		    ifrnd 64
		    {
			    randvar angvar 2047
			    randvar xydist 2047
			    getactor[THISACTOR].x x
			    setvarvar mx x
			    getactor[THISACTOR].y y
				addvarvar mx xydist
				rotatepoint x y mx y angvar mx my
				espawn EXPLOSION2
				setactor[RETURN].x mx
				setactor[RETURN].y my
				sound PIPEBOMB_EXPLODE
			}
		    break
	  }
	    else
        break
  }
  else
    ifactioncount 9
  {
    iffloordistl 8
      sound THUD
    
    ifvare lotag 42 quake 78

    // endofgame 52
    action ABOSS4DEAD
    cstat 0
  }
ends

state checkboss4hitstate
  ifrnd 2
    spawn BLOODPOOL
  state checkdart

  ifdead

  {
    globalsound DUKE_TALKTOBOSSFALL

    addkills 1
    ifvarg mval 0 
    {
	    state dropcoins
	    state addscore 
	    ifvarn lotag 0
	    {
		    espawn BOSSCOIN
			setactorvar[RETURN].myspawner THISACTOR
			setactorvar[RETURN].lotag lotag
		}
	}
    ai AIBOSS4DYING

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

    ifaction ABOSS4LAYIT
      break

    ifrnd 16
    {
      action BOSS4FLINTCH
      move 0
    }
  }
ends

state boss4code


// getactor[THISACTOR].extra tempc
// ifvarg tempc 2000
// {
// 	findnearsprite RPG 2048 tempb
// 	ifvare tempb -1 findnearsprite FLAK 2048 tempb
// 	ifvare tempb -1 findnearsprite NOVA 2048 tempb
// 	
// 	ifvarn tempb -1
// 	{
// 		  getactor[THISACTOR].ang angvar
// 		  setactor[tempb].ang angvar
// 		  getactor[tempb].zvel tempc
// 		  mulvar tempc -1
// 		  setactor[tempb].zvel tempc
// 		  sound BARRIER_HIT
// 		  getactor[tempb].x mx
// 		  getactor[tempb].y my
// 		  getactor[tempb].z mz
// 		  espawn RINGTHING
// 		  setactor[RETURN].x mx
// 		  setactor[RETURN].y my
// 		  setactor[RETURN].z mz
// 	}
// }


getactor[THISACTOR].extra temp
state setholotarg
  // ifvarg temp 2000 { ifspritepal 22 nullop else spritepal 22 } else getlastpal
  getlastpal
  state monsterai
  ifvarg menutoggle 0 break

  ifai 0
  {
    ai AIBOSS4LAYEGGS
    ifvare lotag 42
    {
	    sizeat 255 255
	    addstrength 3000
	    state difficulty
    }
  }
  else
    ifaction BOSS4FLINTCH
    {
      ifactioncount 3
        ai AIBOSS4LAYEGGS
    }
  else
    ifai AIBOSS4LAYEGGS
      state boss4layeggs
  else
    ifai AIBOSS4SHOOT
      state boss4shootstate

  ifai AIBOSS4DYING
    state boss4dyingstate
  else
  {
    ifhitweapon
      {
      state checkboss4hitstate
      }
    else
      ifp palive
        ifpdistl 1280
           ifvare superkicking 0
      {
        addphealth -1000
        palfrom 63 63
      }
  }
ends

actor BOSS4STAYPUT BOSS4STRENGTH

  cactor BOSS4
  spritepal 6
  state boss4code
  fall
  getlastpal

enda

actor BOSS4 BOSS4STRENGTH

  cactor BOSS4
  spritepal 6
  ifai 0 setvar mval BOSSVAL
  state boss4code
  fall
  getlastpal

enda

// start MINIBOSS4 code

action AMINIBOSS4WALK          -10 4  5  1  30
action AMINIBOSS4DYING        30 9  1  1  20
action AMINIBOSS4ABOUTTOSHOOT 10 1  5  1  40
action AMINIBOSS4SHOOT        15 2  5  1  10
action AMINIBOSS4LAYIT        40 3  5  1  120
//action MINIBOSS4FLINTCH       30 1  1  1  1
action AMINIBOSS4DEAD         39
action MINIBOSS4RISE 39 9 1 -1 40

move MINIBOSS4WALKVELS 128
move MINIBOSS4STOPPED

ai AIMINIBOSS4LAYEGGS AMINIBOSS4WALK MINIBOSS4WALKVELS randomangle geth
ai AIMINIBOSS4SHOOT AMINIBOSS4ABOUTTOSHOOT MINIBOSS4STOPPED faceplayer
ai AIMINIBOSS4DYING AMINIBOSS4DYING MINIBOSS4STOPPED geth

state mini4shootplayer

getplayer[THISACTOR].i temp
ldist xydist THISACTOR temp
getactor[THISACTOR].z z
getplayer[THISACTOR].posz mz
addvar mz 12000 // because posz is at player's head, whereas z is at monsters feet
setvarvar zdist mz
subvarvar zdist z
mulvar zdist 768 // multiplies zdist by the speed of the projectile
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist
// iffloordistl 32 ifvarg zdist 128 break
zshoot zdist HEALBOLT
zshoot zdist HEALBOLT
zshoot zdist HEALBOLT
ends


state MINIBOSS4shootstate
  ifaction AMINIBOSS4ABOUTTOSHOOT
    ifactioncount 3
      action AMINIBOSS4SHOOT

  ifaction AMINIBOSS4SHOOT
  {
    ifcount 48
    {
      ifrnd 4
        ai AIMINIBOSS4LAYEGGS
    }
    ifcount 26
      ifrnd 24
       ifcanseetarget
    {
      sound 351
      state mini4shootplayer
    }
  }

ends

state MINIBOSS4layeggs
  ifrnd 2
    sound BOS4_ROAM

  ifaction AMINIBOSS4LAYIT
  {
    ifactioncount 3
      ifcount 32
    {
      ai AIMINIBOSS4LAYEGGS
      ifrnd 32
      move MINIBOSS4WALKVELS furthestdir geth
      espawn NEWBEASTHANG
    	setactor[RETURN].xrepeat 20
	setactor[RETURN].yrepeat 20
	setactor[RETURN].pal 17
	setactor[RETURN].extra 75
      setactor[RETURN].cstat 257
	setactorvar[RETURN].mtype 1
	setactorvar[RETURN].mval BABYVAL
    }
  }
  else
    ifcount 64
      ifrnd 4
  {
    move 0

    ifrnd 88
    {
      action AMINIBOSS4LAYIT
      sound BOS4_LAY
    }
    else
      ifp palive
        ifcansee
    {
      ai AIMINIBOSS4SHOOT
      sound BOS4_ATTACK
    }
  }

ends

state MINIBOSS4dyingstate
  cstat 256
  strength 0
 ifaction AMINIBOSS4DEAD
  {
   state deadlist
   findnearsprite HEALBOLT 1024 temp
      ifvarn temp -1
	{
		subvar revives 1
		strength 10
		setactor[temp].xrepeat 0
		action MINIBOSS4RISE
		setvar monstatus 1
		cstat 257
		break
	}
   }
   ifhitweapon
   { 
	setvar temp 0
    ifwasweapon RPG setvar temp 1
    ifwasweapon RPGNOAIM setvar temp 1
    ifwasweapon HLROCKET setvar temp 1
    ifwasweapon CPUDEV setvar temp 1
    
    ifvare temp 1
	{
	sound SQUISHED
    spawn BLOODPOOL
	state standard_jibs
    state standard_jibs
    state clearlists
    killit
	}

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

    ifactioncount 9
   	 action AMINIBOSS4DEAD
 
ends

state checkMINIBOSS4hitstate
  ifrnd 2
    spawn BLOODPOOL
     state checkdart

  ifdead

  {
    ifrnd 128 globalsound DUKE_TALKTOBOSSFALL

    addkills 1
    ifvarg mval 0 { state dropcoins state addscore }
    ifvare revives 0
     {
      sound SQUISHED
      state standard_jibs
      state clearlists
      killit
    }
    ai AIMINIBOSS4DYING
    sound BOS4_DYING
           
  }
  else
  {
    soundonce BOS4_PAIN
    debris SCRAP1 1
    guts JIBS6 1

    ifaction AMINIBOSS4LAYIT
      break

    ifrnd 16
    {
      action MINIBOSS4FLINTCH
      move 0
    }
  }
ends

state MINIBOSS4code

state setholotarg
 
  state monsterai
  ifvarg menutoggle 0 break
  
  ifaction MINIBOSS4RISE ifactioncount 9 ai AIMINIBOSS4LAYEGGS
  ifai 0
    ai AIMINIBOSS4LAYEGGS
  else
    ifaction MINIBOSS4FLINTCH
    {
      ifactioncount 3
        ai AIMINIBOSS4LAYEGGS
    }
  else
    ifai AIMINIBOSS4LAYEGGS
      state MINIBOSS4layeggs
  else
    ifai AIMINIBOSS4SHOOT
      state MINIBOSS4shootstate

  ifai AIMINIBOSS4DYING
    state MINIBOSS4dyingstate
  else
  {
    ifhitweapon
      {
      state checkMINIBOSS4hitstate
      }
    else
      ifp palive
        ifpdistl 1280
        	ifvare superkicking 0
      {
        addphealth -1
        palfrom 32 63
      }
  }
ends

useractor enemy MINIBOSS4STAYPUT 350

  sizeat 40 40
  cstat 257
  cactor MINIBOSS4
  spritepal 21
  state MINIBOSS4code
  fall
  getlastpal

enda

useractor enemy MINIBOSS4 350

  cactor MINIBOSS4
  
  ifai 0 
  { 
	  spritepal 21
	  sizeat 40 40 
	  cstat 257 
	  setvar mval MINIBOSSVAL
	  state difficulty
  }
  state MINIBOSS4code
  fall
  // getlastpal

enda

// end MINIBOSS4 code

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

action ANEWBEASTHANG      0  1  5
useractor enemy NEWBEASTHANG NEWBEASTSTRENGTH
  ifaction 0
  {
    action ANEWBEASTHANG
    cstator 257
    ifvare mtype 1 nullop else sizeat 40 40
  }

 ifhitweapon
  {
    state checkdart
    cactor NEWBEAST
    action ANEWBEASTSTAND
    sound NEWBEAST_PAIN
     	ifdead
  	  {
   	   state standard_jibs
  	    spawn BLOODPOOL
    	    sound SQUISHED
                      state clearlists
  	    killit
   	 }
  }
  else
      ifcount 200
        ifrnd 1
  {
    cactor NEWBEAST
    action ANEWBEASTSTAND
    sound NEWBEAST_PAIN
  }
  
enda

action ANEWBEASTHANGDEAD      -1  1  5
useractor enemy NEWBEASTHANGDEAD TOUGH

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

move NEWBEASTWALKVEL 182
move NEWBEASTRUNVEL 256
move NEWBEASTDODGEVEL 264
move NEWBEASTJUMPVEL 264
move NEWBEASTSTOP

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


state newbeastseekstate

  ifactornotstayput
  {
    ifp palive
      ifcansee
        ifpdistl 1596
    {
      ai AINEWBEASTSCRATCHENEMY
      break
    }

    ifai AINEWBEASTCHARGEENEMY
    {
      ifp palive
        ifpdistl 1596
          ifcansee
      {
        ai AINEWBEASTSCRATCHENEMY
        break
      }

   ifvarn mtype 1  // minibeasts don't shoot
      ifrnd 1
        ifpdistg 4096
          ifp palive
            ifcansee
      {
        ai AINEWBEASTSHOOT
        break
      }
    }
    else
      ifpdistg 4096
    {
      ai AINEWBEASTCHARGEENEMY
      ifvare mtype 4 move NEWBEASTDODGEVEL seekplayer
      break
    }

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

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

ends

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

state newbeastfleestate
  ifcount 8
  {
  ifvarn mtype 1 // mini beasts don't shoot
     ifrnd 64
       ifpdistg 3500
         ifp palive
           ifcansee
             ai AINEWBEASTSHOOT
  }
  else
  {
    iffloordistl 16
    {
      ifnotmoving
        ai AINEWBEASTGETENEMY
    }
    else
      ai AINEWBEASTGETENEMY
    break
  }
ends

state newbeastthinkstate

  ifrnd 8
    soundonce NEWBEAST_ROAM

  ifactioncount 3
  {
    ifrnd 128
    {
     ifvarn mtype 1 // mini beasts don't shoot
      ifpdistg 3500
        ifp palive
          ifcansee
            ai AINEWBEASTSHOOT
    }
    else
      ai AINEWBEASTGETENEMY
  }

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

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

  ifactioncount 3
  {
    ifpdistg 1596
      ai AINEWBEASTTHINK
    else 
    	ifp palive 
    		ifcansee
    			ifvare superkicking 0
    {
	    palfrom 16 16
	    ifvare mtype 1 addphealth -11
	    else
		ifvare mtype 2 { addphealth -44 wackplayer wackplayer }
		else addphealth NEWBEASTSCRATCHAMOUNT
		ifvare mtype 4 { addstrength 20 subvar stamina 100 }
	    sound DUKE_GRUNT
	    resetactioncount
	    resetcount
    }
  }
  else
    ifcount 15
      nullop
  else
    ifcount 14
  {
	ifvare mtype 4 { shoot ACIDBULLET shoot ACIDBULLET shoot ACIDBULLET }
    ifpdistl 1596
      soundonce NEWBEAST_ATTACK
    else
      soundonce NEWBEAST_ATTACKMISS
  }
ends

state checknewbeasthit
  spawn BLOOD
  state checkdart
/*
  ifai AINEWBEASTSHRUNK
  {
    addkills 1
    sound SQUISHED
    state standard_jibs
    ifvarg mval 0 { state dropcoins state addscore }
    state clearlists
    killit
  }
*/
  ifdead
  {
    ifwasweapon FREEZEBLAST
    {
      sound SOMETHINGFROZE
      spritepal 1
      move 0
      action ANEWBEASTFROZEN
      strength 0
      break
    }

    ifwasweapon GROWSPARK
    {
      cstat 0
      sound ACTOR_GROWING
      ai AINEWBEASTGROW
      break
    }

    addkills 1
    ifvarg mval 0 { state dropcoins state addscore }
    ifvare revives 0
     {
      sound SQUISHED
      state standard_jibs
      state clearlists
      killit
    }

    setvar temp 0
    ifwasweapon RPG setvar temp 1
    ifwasweapon RPGNOAIM setvar temp 1
    ifwasweapon HLROCKET setvar temp 1
    ifwasweapon CPUDEV setvar temp 1
    
    ifvare temp 1
    {
      sound SQUISHED
      // state liz_body_jibs
      state standard_jibs
      state clearlists
      killit
    }
 
    else
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      // state liz_body_jibs
      state standard_jibs
      state clearlists
      killit
    }
    else
    {
      state rf
      ai AINEWBEASTDYING
      ifrnd 64
        spawn BLOODPOOL
    }
    sound NEWBEAST_DYING
  }
  else
  {
    sound NEWBEAST_PAIN
    ifwasweapon GROWSPARK
      sound EXPANDERHIT
/*
//  The alien is immune to the shrinker
       ifwasweapon SHRINKSPARK ifvarl hp 301
    {
      sound ACTOR_SHRINKING
      ai AINEWBEASTSHRUNK
      break
    }
*/
    state random_wall_jibs
    ifai AINEWBEASTDYING break
    ifrnd 32
      ai AINEWBEASTFLINTCH
    else
    ifwasweapon KNEE ifvarn superkicking 0
      ai AINEWBEASTFLINTCH
      
      switch mtype
      case 0
      case 3
       ifrnd 32
         ifpdistg 3500
           ifp palive
             ifcansee
               ai AINEWBEASTSHOOT
	break
      case 1
       break // don't shoot if baby newbeast
     case 2
       ifp palive
          ifpdistg 2048
             ifcansee
               ai AINEWBEASTSHOOT
	break
      default
         break
      endswitch
  }
ends

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

state newbeastdyingstate
  ifaction ANEWBEASTLYINGDEAD
  {
    strength 0
    setvar monstatus 2
    state deadlist
    findnearsprite HEALBOLT 1024 temp
      ifvarn temp -1
	{
		subvar revives 1
		strength 10
		setactor[temp].xrepeat 0
		action NEWBEASTRISE
		setvar monstatus 1
		cstat 257
		break
	}
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      state clearlists
      killit
    }
    state checkdart
  /*  ifcount RESPAWNACTORTIME
      ifrespawn
    {
      spawn TRANSPORTERSTAR
      cstat 257
      strength NEWBEASTSTRENGTH
      ai AINEWBEASTGETENEMY
    }
  */
  }
  else
    ifai AINEWBEASTDYING
     ifaction ANEWBEASTDYING
      ifactioncount 7
  {
    iffloordistl 8
      sound THUD
    move NEWBEASTSTOP
    action ANEWBEASTLYINGDEAD
  }
ends

state newbeastdodgestate
  ifcount 13
    ai AINEWBEASTGETENEMY
ends

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

state newbeastcode
  state checksquished
  state monsterai
  ifvare mtype 2
  {
	  ifceilingdistl 72
	  sizeto 48 40 else
	  sizeto 64 52
  }
  ifvare mtype 3
  {
	  ifvare goggles 0 ifvare monstatus 1
	  {
		  spritepal 12
		  ifrnd 32 cstat 514 else cstat 32768
		  ifrnd 8 ifvare monstatus 1 { espawn NEWSMOKE setactor[RETURN].pal 6 }
		  getactor[THISACTOR].htpicnum temp
		  setvar tempb 0
		  ifvare temp RADIUSEXPLOSION setvar tempb 1
		  ifvare temp RPG setvar tempb 1
		  ifvare tempb 1
		  {
			  setactor[THISACTOR].htextra -1 // not even explosions can hurt it when invisible
			  setactor[THISACTOR].htpicnum -1
		  }
	  }
	  else ifaction ANEWBEASTLYINGDEAD cstat 0
	  else cstat 257
  }
  ifvarg menutoggle 0 break
  

getactor[THISACTOR].extra hp

ifp pfacing ifvare monstatus 1
{
	ifvarg mtype 2 ifvarl mtype 5 ifrnd 4 ifpdistl 8192 state teleport_behind else
	ifpdistg 2024 ifrnd 16 ifvare scanned 1
	{
		setvar temp 0
		ifaction ANEWBEASTFROZEN setvar temp 1
		ifai AINEWBEASTSHOOT setvar temp 1
		ifai AINEWBEASTDYING setvar temp 1
		ifai AINEWBEASTDODGE setvar temp 1
	    ifvare temp 0 ai AINEWBEASTDODGE
    }
}

 
state setholotarg
ifaction NEWBEASTRISE ifactioncount 8 ai AINEWBEASTGETENEMY
ifai 0
  {
    cstator 257
    ai AINEWBEASTGETENEMY
    //state clone
  }
  else
    ifaction ANEWBEASTLYINGDEAD
  {
    fall
    state newbeastdyingstate
    break
  }
  else
    ifaction ANEWBEASTFROZEN
  {
    ifcount THAWTIME
    {
      ai AINEWBEASTGETENEMY
      spritepal 0
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

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

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

    else
      ifai AINEWBEASTDODGE
        state newbeastdodgestate
    else
      ifai AINEWBEASTSCRATCHENEMY
        state newbeastscratchstate
    else
      ifai AINEWBEASTFLEENEMY
        state newbeastfleestate
    else
      ifai AINEWBEASTTHINK
        state newbeastthinkstate
/*
    else
      ifai AINEWBEASTSHRUNK
        state newbeastshrunkstate
*/
    else
      ifai AINEWBEASTGROW
        state genericgrowcode
    else
      ifai AINEWBEASTDYING
        state newbeastdyingstate
    else
      ifai AINEWBEASTSHOOT
    {
      ifp pshrunk
        ai AINEWBEASTGETENEMY
      else
        ifcount 26
          ai AINEWBEASTGETENEMY
      else
        ifcount 25 
			{
				ifvare mtype 2
				{
					ifvarg framerate 20
					{
						shoot MAGMA
						shoot MAGMA
						shoot MAGMA
					}
					else
						shoot SHRINKER
		
				}
				else ifvare mtype 3
					spawn SEEKER

				else
				{
				    ifrnd 128
					shoot SHRINKER
					
					else
					{
						shoot SPIT
						shoot SPIT
						shoot SPIT
						shoot SPIT
						shoot SPIT
						shoot SPIT
						shoot SPIT
						shoot SPIT
					}
				}
			}
      else
      {
        ifcount 5
          nullop
        else
          ifcount 4
		{
		ifvare mtype 2 sound RPG_SHOOT else
            sound NEWBEAST_SPIT
		}
      }
    }
  }

  ifhitweapon
  {
    state checknewbeasthit
  }
ends

useractor enemy SUPERBEAST NEWBEASTSTRENGTH
 setvar mtype 2
 state difficulty
 spritepal 19
 sizeat 60 49
 setvar mval SUPERBEASTVAL
 cstat 257
 ifvarg score 15000 ifrnd 96
 {
	 setvar mtype 4
	 spritepal 8
	 strength 500
	 sizeat 40 40
	 state difficulty
 }
 cactor NEWBEAST
enda

useractor enemy INVISBEAST NEWBEASTSTRENGTH
 setvar mtype 3
 spritepal 6
 sizeat 48 42
 setvar mval MINIBOSSVAL
 cstat 32768
 cactor NEWBEAST
 ai AINEWBEASTDODGE
enda

useractor enemy NEWBEAST NEWBEASTSTRENGTH

 ifaction 0
  {
    ifvarg mtype 0 ifvarl mtype 3 { ifai 0 ai AINEWBEASTDODGE }
    else       
	 ifrnd 96 ifvarg score 1200
	 {
		ifrnd 76 ifvarg score 4000 cactor SUPERBEAST
		  else
		{
			spawn MINIBOSS4
			spawn TRANSPORTERSTAR
			state standard_jibs
			sound SQUISHED
			getplayer[THISACTOR].max_actors_killed temp
			subvar temp 1
			setplayer[THISACTOR].max_actors_killed temp
			state clearlists
			killit
		}
	}
	   else
		{
       		cstator 257
       		sizeat 40 40
       		setvar mval NEWBEASTVAL
       		ai AINEWBEASTDODGE
       		ifvarg score 20000 ifrnd 96
       		{
	       		setvar mval SUPERBEASTVAL
	       		setvar mtype 4
	       		spritepal 8
	       		strength 500
	       		state difficulty
       		}
		}
       

   }
  ifaction ANEWBEASTFROZEN
    state newbeastcode
  else
  {
    spritepal 6
    state newbeastcode
    ifaction ANEWBEASTFROZEN
      break
    getlastpal
  }
fall
enda



move HOLOBOTJUMP 180 -80
move HOLOBOTJUMPBACK -180 -80
move HOLOBOTRUNSPEED 256 0
move RUNBACK -180 0
move HOLOSTOP
move HURRICANE 0 -53

move ALLYWALKVEL 160 0
move ALLYSWIMUP 128 -48
move ALLYSWIMDOWN 128 48

action HOLOBOT_STAND     -26   1   5   1  1
// action ALLYPJPHOUVER  -11   1   5   1
// action ALLYPWALK    -6   4   5   1   16
action HOLOBOT_RUN     -6   4   5   1   10
// action ALLYPWALKBACK  19   4   5  -1   16
// action ALLYPRUNBACK   19   4   5  -1   10
action HOLOBOT_JUMP   24   4   5   1   26
action HOLOBOT_FALL   34   1   5
// separate actor for ducking
action HOLO_DUCKING   40   1   5
action HOLO_CRAWLING  40   3   5   1   20

action HOLOBOT_KICK  14   2   5   1   25
action HOLO_KICKOUT  19   1   5   1   20

action ALLYPSWIMMINGGO   349   1   5   1   10
action ALLYPSWIMMING   349   4   5   1   13
action ALLYPSWIMMINGWAIT 369   1   5   1   13
action ALLYPTREDWATER  369   2   5   1   17


// action ALLYPFLINTCHING  80  1   1   1   10
// action ALLYPTHROWNBACK  35  5   1   1   18
// action ALLYPFROZEN     -6  1   5
// action ALLYPLYINGDEAD   48  1   1

// action ALLYPSWIMMINGGO   349   1   5   1   10
// action ALLYPSWIMMING   349   4   5   1   13
// action ALLYPSWIMMINGWAIT 369   1   5   1   13
// action ALLYPTREDWATER  369   2   5   1   17

ai HOLOBOTGO HOLOBOT_RUN HOLOBOTRUNSPEED geth
ai HOLOBOTRUNBACK HOLOBOT_RUN RUNBACK geth
ai HOLOJUMP HOLOBOT_JUMP HOLOBOTJUMP geth getv
ai HOLOJUMPBACK HOLOBOT_JUMP HOLOBOTJUMPBACK geth getv
ai RETURNTOPLAYER HOLOBOT_RUN HOLOBOTRUNSPEED seekplayer
ai TRANSITION HOLOBOT_RUN HOLOBOTRUNSPEED geth
ai GROWHOLO HOLOBOT_STAND HOLOSTOP geth
ai HOLOSTOPPED HOLOBOT_STAND HOLOSTOP geth
ai AIHURRICANE HOLO_KICKOUT HURRICANE geth // spin is done manually cuz it's faster that way
ai AIBOTSWIM ALLYPSWIMMING ALLYWALKVEL seekplayer

state botswimstate

ifinwater nullop else
{
	ai HOLOJUMP
	break
}

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

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

ends

state pistolfire

state calczdist

shiftvarl zdist 8
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist
sound PISTOL3
ifvare holosphere 0 setvar tilenum SHOTSPARK1 else setvar tilenum SLOWBULLET
zshootvar zdist tilenum
state shelleject

subvar hammo2 1
ends

state shotgunfire

state calczdist
shiftvarl zdist 8
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist
sound SHOTGUN_FIRE 
ifvare holosphere 0 setvar tilenum SHOTSPARK1 else setvar tilenum SLOWBULLET
zshootvar zdist tilenum
zshootvar zdist tilenum
zshootvar zdist tilenum
zshootvar zdist tilenum
zshootvar zdist tilenum
zshootvar zdist tilenum
zshootvar zdist tilenum
subvar hammo3 1

ends

state chainfire

state calczdist

shiftvarl zdist 8
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist
sound CHAINGUN_FIRE
ifvare holosphere 0 setvar tilenum SHOTSPARK1 else setvar tilenum SLOWBULLET
zshootvar zdist tilenum
state shelleject

subvar hammo4 1
ends

state rpgfire

state calczdist
mulvar zdist 644 // multiplies zdist the speed of the projectile
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist // zdist now holds the desired z velocity
sound RPG_SHOOT
zshoot zdist RPGNOAIM
subvar hammo5 1

ends

state shrinkfire
	
state calczdist
mulvar zdist 768 // multiplies zdist by 768, the speed of the projectile
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist
sound SHRINKER_FIRE
zshoot zdist SHRINKER
subvar hammo7 1

ends

state devfire

state calczdist
mulvar zdist 644 // multiplies zdist the speed of the projectile
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist // zdist now holds the desired z velocity
sound RPG_SHOOT
zshoot zdist CPUDEV
zshoot zdist CPUDEV
subvar hammo8 2
ends

state blasterfire
state calczdist
mulvar zdist 644
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist
sound BLASTERSND
zshoot zdist BLASTER
subvar hammo8 1
ends


state freezerfire
state calczdist
mulvar zdist 768 // multiplies zdist the speed of the projectile
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist // zdist now holds the desired z velocity

sound CAT_FIRE
zshoot zdist FREEZENOAIM
subvar hammo10 1
ends


state lightningfire

state calczdist
shiftvarl zdist 10
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist // zdist now holds the desired z velocity
sound 351
zshoot zdist LIGHTNINGBOLT
subvar hammo10 2

ends

state railgunfire

state calczdist

shiftvarl zdist 8
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist
sound RAIL_FIRE
zshoot zdist RAILSLUG

ends

state bfgfire

state calczdist

mulvar zdist 416
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist
sound BFG_FIRE
zshoot zdist BFG
ends


state holodeath

sound PIPEBOMB_EXPLODE
spawn EXPLOSION2
hitradius 1536 30 60 100 150
debris SCRAP1 15 debris SCRAP1 4
quote 129
setvar currholo -1
whilevarn hammo2 0
{
	spawn AMMO
	subvar hammo2 PISTOLAMMOAMOUNT
	ifvarl hammo2 0 setvar hammo2 0
}
whilevarn hammo3 0
{
	spawn SHOTGUNAMMO
	subvar hammo3 SHOTGUNAMMOAMOUNT
	ifvarl hammo3 0 setvar hammo3 0
}
whilevarn hammo4 0
{
	spawn BATTERYAMMO
	subvar hammo4 CHAINGUNAMMOAMOUNT
	ifvarl hammo4 0 setvar hammo4 0
}
whilevarn hammo5 0
{
	spawn RPGAMMO
	subvar hammo5 RPGAMMOBOX
	ifvarl hammo5 0 setvar hammo5 0
}
whilevarn hammo7 0
{
	spawn CRYSTALAMMO
	subvar hammo7 CRYSTALAMMOAMOUNT
	ifvarl hammo7 0 setvar hammo7 0
}
whilevarn hammo8 0
{
	spawn DEVISTATORAMMO
	subvar hammo8 DEVISTATORAMMOAMOUNT
	ifvarl hammo8 0 setvar hammo8 0
}
whilevarn hammo10 0
{
	spawn FREEZEAMMO
	subvar hammo10 FREEZEAMMOAMOUNT
	ifvarl hammo10 0 setvar hammo10 0
}
killit

ends

state portplayer

sound TELEPORTER	
spawn TRANSPORTERSTAR
getplayer[THISACTOR].posx mx
getplayer[THISACTOR].posy my
getplayer[THISACTOR].posz tempc
setactor[THISACTOR].x mx
setactor[THISACTOR].y my
setactor[THISACTOR].z tempc
spawn TRANSPORTERSTAR
setvar target -1 // forget about old target after teleporting
setvar hammtarg -1

ends


state switchweapon

setvar hweapcount 0
getactor[target].xrepeat tempc
getactor[target].picnum mval // the holobot's mval isn't used for anything else...


ifvarg nuclear 0
{
	ifrnd 48 { ifinwater setvar holoweap 11 else setvar holoweap 9 }
	else ifrnd 192 setvar holoweap 15
	else setvar holoweap 11
	break
}
else
 ifvarl xydist 3072 ifrnd 32 { ifai HOLOBOTRUNBACK nullop else setvar holoweap 9 }
else
 ifvarg hammo10 1 ifvarg xydist 1536
 	ifrnd 128 { setvar holoweap 10 else setvar holoweap 20 break }
else
 ifvarg hammo8 1 ifvarg xydist 1536 { ifrnd 128 setvar holoweap 8 else setvar holoweap 18 break }
else
 ifvarg hammo7 0 ifvarg countvar 40 ifvarl countvar 60 ifvarg tempc 13 { setvar holoweap 7 break }
else
 ifvarg hammo5 0 ifvarg countvar 3 ifvarl countvar 15 ifvarg xydist 2048 { setvar holoweap 5 break }
else
 ifvarg hammo5 0 ifvarg xydist 2048 ifvare mval ROTATEGUN { setvar holoweap 5 break }
else
 ifvarg hammo4 0 setvar holoweap 4
else
 ifvarg hammo3 0 setvar holoweap 3
else
 ifvarg hammo2 0 setvar holoweap 2
else
 ifvarg hammo5 0 setvar holoweap 5
else
  ifvarg hammo7 0 setvar holoweap 7
else
  ifvarg hammo10 0 setvar holoweap 10
else
  ifvarl xydist 3072 { ifinwater setvar holoweap 0 else setvar holoweap 9 }
else setvar holoweap 0
 
ends

state seekammo

ifvarn hammtarg -1
{
	getactor[hammtarg].picnum tilenum
	ifvarn tilenum DUKENUKE setvar hammtarg -1
}

ifvare hammtarg -1
  ifvarl hammo3 15 findnearactorz SHOTGUNAMMO 8192 16384 hammtarg
ifvare hammtarg -1
  ifvarl hammo2 48 findnearactorz AMMO FINDRANGE 16384 hammtarg
ifvare hammtarg -1
  ifvarl hammo4 100 findnearactorz BATTERYAMMO FINDRANGE 16384 hammtarg
ifvare hammtarg -1
  ifvarl hammo5 5 findnearactorz RPGAMMO FINDRANGE 16384 hammtarg
ifvare hammtarg -1
  ifvarl hammo8 48 findnearactorz DEVISTATORAMMO FINDRANGE 16384 hammtarg
ifvare hammtarg -1
  ifvarl hammo3 15 findnearactorz SHOTGUNSPRITE FINDRANGE 16384 hammtarg
ifvare hammtarg -1
  ifvarl hammo10 30 findnearactorz FREEZEAMMO FINDRANGE 16384 hammtarg
ifvare hammtarg -1
  ifvarl hammo7 5 findnearactorz CRYSTALAMMO FINDRANGE 16384 hammtarg

ifvarn hammtarg -1
{
	// quote 155
	getactor[hammtarg].z mz
	getactor[THISACTOR].z z
	subvar mz 4096
	setactor[hammtarg].z mz
	subvar z 8192
	setactor[THISACTOR].z z
	canseespr THISACTOR hammtarg tempb
	addvar mz 4096
	setactor[hammtarg].z mz
	addvar z 8192
	setactor[THISACTOR].z z
    ifvare tempb 1
	{
			getactor[hammtarg].x mx
      		getactor[hammtarg].y my
       		getactor[THISACTOR].x x
       		getactor[THISACTOR].y y
       		subvarvar mx x
      		subvarvar my y
      		getangle angvar mx my
      		setactor[THISACTOR].ang angvar

			ldist tempc THISACTOR hammtarg // jump to close high ammo
			ifvarvarl mz z ifvarl tempc 3072 
			{
				iffloordistl 8
				{ 
					ifai HOLOJUMP nullop 
						else { ai HOLOJUMP setvar countvar 0 }
				}
			}
			else
			{
			ifai HOLOBOTGO nullop else ai HOLOBOTGO
			ifai RETURNTOPLAYER ai HOLOBOTGO
			}
	}
	else  setvar hammtarg -1
}


ends

state confirmtarget

	getactor[target].statnum temp
	ifvare temp 1024 
	{
	  setvar target -1 // don't target things that don't exist
	  break
    }
	getactor[target].cstat temp // don't target invisible monsters
	ifvarand temp 32768 
	{
		setvar target -1
		break
	}
	getactorvar[target].monstatus temp // don't target dead monsters
	ifvare temp 2 
	{
		setvar target -1
		break
	}
	
	getactor[THISACTOR].z z
	subvar z 6144
	setactor[THISACTOR].z z
	getactor[target].z mz
	subvar mz 4096
	setactor[target].z mz
	canseespr THISACTOR target holocansee // is the enemy target visible?
	addvar z 6144
	addvar mz 4096
	setactor[THISACTOR].z z
	setactor[target].z mz

	ifvare holocansee 0 ifrnd 12 
	{
		setvar target -1 // if the enemy target isn't visible, forget about it
		break
	}
	ifvarn target -1 setvar hammtarg -1 // if you have a visible enemy target, forget the ammo target

ends

state holobotfire
	
	ifvarn holoweap 9 ifvare dodge 0 // a safety check to make sure he doesn't turn back towards the target while dodging
	state aimattarget

	switch holoweap

	case 2:  // pistol
		ifvarl botclip 1
		{
		   ifvare hweapcount 3 sound EJECT_CLIP
		   ifvare hweapcount 12 sound INSERT_CLIP
		   ifvarg hweapcount 27 
		   { 
		   		ifvarg hammo2 11 setvar botclip 12
				else setvarvar botclip hammo2
				state switchweapon
		   }
		}
		else
		{
		   ifvare hweapcount 2 state pistolfire	
		   ifvarg hweapcount 5 
			{ 
				subvar botclip 1
				setvar hweapcount 0     
				ifvarl hammo2 1 state switchweapon 
				else ifvarg countvarb 130 { state switchweapon setvar countvarb 0 }
			}
		 }
		break

	case 3:  // shotgun

		ifvare hweapcount 4 state shotgunfire
		ifvare hweapcount 15 sound SHOTGUN_COCK
		ifvare hweapcount 20 state shelleject2
		 
		
		ifvarg hweapcount 30 
		{ 
		    setvar hweapcount 0
		    ifvarl hammo3 1 state switchweapon
		      else
		       ifvarg countvarb 130 { state switchweapon setvar countvarb 0 }
		}
		break

	case 4:   // chaingun
	case 14 // flak
		ifvarg hweapcount 2 
			{
			ifvare holoweap 4 state chainfire //else state flakfire
			setvar hweapcount 0
			ifvarl hammo4 1 state switchweapon
			  else ifvarg countvarb 130 { state switchweapon setvar countvarb 0 }
			}
		
		break	
		
	case 5:   // RPG
	case 15   // railgun
		
		ifvare hweapcount 4 { ifvare holoweap 5 state rpgfire else state railgunfire }
		ifvarg hweapcount 19
		 { 
		  setvar hweapcount 0 
		  ifvarl hammo5 1 state switchweapon 
		    else ifvarg countvarb 130 { state switchweapon setvar countvarb 0 }
		  }
		break

	case 7:  // shrinker

		ifvare hweapcount 3 state shrinkfire
		ifvarg hweapcount 39 { setvar hweapcount 0 state switchweapon }
		// note that actual weapon speed would be ifvarg hweapcount 12
		break

	
	case 8:  // devastator
	case 18: // blaster
	
	
		ifvare hweapcount 3 
		{
			ifvare holoweap 8 state devfire
			 else 
			   state blasterfire
		}
		ifvarg hweapcount 4 
			{
			setvar hweapcount 0 
			ifvarl hammo8 1 state switchweapon 
				else ifvarg countvarb 130 { state switchweapon setvar countvarb 0 }
			}
		break
		
	

	case 9:  // hurricane kick

		ifvarg xydist 1280 
		{ 
			ifvare dodge 0 // a safety check to make sure he doesn't turn back towards the target while dodging
				state aimattarget
			ifai HOLOBOTGO nullop else ai HOLOBOTGO 
		}
			else
			{
				ifai AIHURRICANE nullop else ai AIHURRICANE
				ifactioncount 1
				{
					sound KICK_HIT
					getactor[target].extra temp
					ifvarg temp 0 
					{
						  subvar temp 5
						  ifvarg nuclear 0          
						  {
								subvar temp 15
								espawn SMALLEXPLOSION
								getactor[target].x mx
								getactor[target].y my
								getactor[THISACTOR].z mz
								setactor[RETURN].x mx
								setactor[RETURN].y my
								setactor[RETURN].z mz
								sound PIPEBOMB_EXPLODE
						  } 
						  
						 ifvarl temp 1 setvar temp 1
					 }
					 setactor[target].extra temp
					 ifvarl temp 2 hitradius 1536 5 5 5 5
					 resetactioncount
				}
				getactor[target].x mx
				getactor[target].y my
				getactor[target].z mz
				getactor[THISACTOR].x x
				getactor[THISACTOR].y y
				ifvarvarg x mx addvar mx 128 else subvar mx 128
				ifvarvarg y my addvar my 128 else subvar my 128						
				setactor[THISACTOR].x mx
				setactor[THISACTOR].y my
				subvar mz 5120
				setactor[THISACTOR].z mz
					
				// spinning
				getactor[THISACTOR].ang angvar
				ifvarl hweapcount 8 addvar angvar 93
				else ifvarl hweapcount 16 { soundonce HURR_KICK addvar angvar 171 }
				else ifvarl hweapcount 80 addvar angvar 267
				else ifvarl hweapcount 96 addvar angvar 171
				else ifvarl hweapcount 104 addvar angvar 93
				setactor[THISACTOR].ang angvar
			}
		

		ifvarg hweapcount 104
		{ 
			setvar hweapcount 0
			state switchweapon 
			ifai AIHURRICANE ai HOLOSTOPPED
		}

		ifvare target -1
		{ 
			setvar hweapcount 0
			state switchweapon
			ifai AIHURRICANE ai HOLOSTOPPED
		}

		break


	 case 10:  // freezer
	 case 20:  // lightning gun
	 
	 	ifvare hweapcount 2
	 	 { 
		 	 ifvare holoweap 10 state freezerfire
		 	  else state lightningfire
		 }
	
		ifvarg hweapcount 4 
			{ 
				setvar hweapcount 0 
				ifvarl hammo10 1 state switchweapon 
				else ifvarg countvarb 130 { state switchweapon setvar countvarb 0 }
				else ifvare holoweap 10
				{
					  getactor[target].extra temp
					  ifvarl temp 2 state switchweapon
				}
			 }
		break


	 case 11:  // bfg
		
		ifvare hweapcount 15 state bfgfire
		ifvarg hweapcount 30 { setvar hweapcount 0 state switchweapon }
		break


	endswitch
	
addvar hweapcount 1	
ends


state holobotcode

sizeat 42 36

getactor[THISACTOR].htextra temp
ifvarg temp 0
{
	getactor[THISACTOR].htowner spriteid
	getplayer[THISACTOR].i tempb
	ifvarvare spriteid tempb 
	{
		setactor[THISACTOR].htextra -1
		setactor[THISACTOR].htowner -1
		setactor[THISACTOR].htpicnum -1
	}
}

ifhitweapon 
{ 
	state checkdart 
	debris SCRAP1 1 
}

ifdead state holodeath

ifp pfacing
	ifp palive
		ifcansee
			ifhitspace
				ifpdistl 1024
					ifvare nuclear 0
{
	getactor[THISACTOR].extra temp
	mulvarvar temp holomult
	divvar temp 2
	getplayer[THISACTOR].holoduke_amount tempc
	addvarvar tempc temp
	setplayer[THISACTOR].holoduke_amount tempc
	palfrom 24 31 31 63
	quote 206
	sound GETATOMICHEALTH
	setvar currholo -1
	killit
}

getactor[THISACTOR].extra hp
ifvare nuclear 0 
{
	ifvarg hp 300 spritepal 14
	else
	ifvarl hp 80 spritepal 21
	else spritepal 0
	
	findnearactor DUKENUKE 8192 temp
	ifvarn temp -1
	{
		setvar target -1
		setvarvar hammtarg temp
	}
}

else // nuclear powered Dukebot!!!
{
	ifvare nuclear 666 
	{
		addvar hp 666
		setvar temp 20
		subvarvar temp holomult
		mulvar temp 66
		addvarvar hp temp
		setactor[THISACTOR].extra hp
	}
		
	ifvare nuclear 1 { addstrength -200 ifdead state holodeath }
	ifvarg nuclear 0 { subvar nuclear 1 spawn FRAMEEFFECT1 }
	addvar headshot 1 // we use headshot to cycle through the pals since it otherwise isn't used
	ifvarg headshot 10 setvar headshot 0
	setactor[THISACTOR].pal headshot
}

ifvarn target -1 
  ldist xydist THISACTOR target

ifvare holoweap 0 
{
	ifvarn target -1 state switchweapon 
	ifai AIBOTSWIM nullop else state seekammo 
	ifvare holoweap 0 setvar target -1
}


ifcansee ifcanshoottarget setvar loop 0 else
{
	addvar loop 1
	ifvarg loop  195 { setvar loop 0 state portplayer }
	// ifai AIBOTSWIM nullop else
	// ifpdistg 12288 state portplayer // move to player if out of sight and far away
}

addvar countvar 1
addvar countvarb 1

ifai AIBOTSWIM nullop else ifvare dodge 0
{
	// dodge RPG code
	findnearsprite RPG 4096 spriteid		
	ifvare spriteid -1 findnearsprite RPGNOAIM 4096 spriteid
	
	// if RPG close to feet and holobot near the ground, jump
	
	ifvarn spriteid -1 iffloordistl 4
	{
		getactor[spriteid].z tempb
		getactor[THISACTOR].z z
		subvarvar tempb z
		ifvarl tempb 0 mulvar tempb -1
		ifvarl tempb 4096
		{
			// time to jump...
			ifai HOLOJUMP nullop else { ai HOLOJUMP setvar countvar 0 }
		}
				
	}
	
	ifvare spriteid -1 findnearsprite FREEZEBLAST 4096 spriteid
	ifvare spriteid -1 findnearsprite FIRELASER 4096 spriteid
	ifvare spriteid -1 findnearsprite FIRELASER2 4096 spriteid
	ifvare spriteid -1 findnearsprite COOLEXPLOSION1 3072 spriteid
	ifvare spriteid -1 findnearsprite BLASTER 3072 spriteid
	ifvare spriteid -1 findnearsprite BLASTER2 3072 spriteid
	ifvare spriteid -1 findnearsprite BLASTER4 4096 spriteid
	ifvare spriteid -1 findnearsprite NOVA 4096 spriteid
	ifvare spriteid -1 findnearsprite FLAK 8192 spriteid
	ifvare spriteid -1 findnearsprite CPUDEV 4096 spriteid
	ifvare spriteid -1 findnearsprite FIREBULLET 4096 spriteid
	ifvarn spriteid -1
	{
		state projectilehitscan
		ifvarvare hitsprite THISACTOR ifvarn holoweap 9 // don't dodge if hurricane kicking
		{
			setvarvar tempb angvar
			ifrnd 128 addvar tempb 640 else subvar tempb 640
			setactor[THISACTOR].ang tempb
			setvar dodge 9
			ifai HOLOBOTGO nullop else ai HOLOBOTGO
		}
			
	}
}
ifvarg dodge 0 subvar dodge 1
		
ifai AIBOTSWIM state botswimstate else
{
	 ifp phigher 
	      ifvare target -1
		  		ifvarg countvar 60 
	{
		ifai HOLOBOTGO { ai HOLOJUMP setvar countvar 0 }
		ifai RETURNTOPLAYER { ai HOLOJUMP setvar countvar 0 }
	}
	ifvarn target -1 ifvarg countvar 60 ifrnd 16
	{
		ifai HOLOBOTGO ai HOLOJUMP 
		ifai HOLOBOTRUNBACK ai HOLOJUMPBACK
		setvar countvar 0
	}
	
	ifnotmoving
	{
		//ifvare target -1 
		//{
		ifrnd 2 operate
		iffloordistl 4
		{
			ifai HOLOBOTGO ai HOLOJUMP
			ifai RETURNTOPLAYER ai HOLOJUMP
		}
		//}
		ifvare dodge 0 iffloordistl 2 ifrnd 16
		{
			getactor[THISACTOR].ang angvar
			ifrnd 128 addvar angvar 192 else subvar angvar 192
			setactor[THISACTOR].ang angvar
			setvar dodge 6
		}
	}
	ifaction HOLOBOT_JUMP
	{
		ifceilingdistl 48
			ai HOLOBOTGO
	} else
	iffloordistl 4
	{
		ifaction HOLOBOT_FALL
		{
			ifai HOLOSTOPPED action HOLOBOT_STAND else
			action HOLOBOT_RUN
		} 
	} else
	{
		ifai AIHURRICANE nullop else
		{
			ifaction HOLOBOT_FALL nullop else
			action HOLOBOT_FALL
		}
	}
}





ifvarg countvar 12 { ifai HOLOJUMP ai HOLOBOTGO ifai HOLOJUMPBACK ai HOLOBOTRUNBACK }
ifvare target -1 ifai HOLOBOTRUNBACK ai HOLOBOTGO
ifvarg countvar 63 setvar countvar 0


ifvarn target -1 ifvare dodge 0 // if target acquired and not dodging
{
	ifai AIBOTSWIM nullop else
	{
		ifai HOLOSTOPPED ai HOLOBOTGO
		getactor[target].xrepeat temp
		 ifvarl xydist 2560 ifai HOLOBOTGO 
		 {
			ifvarl temp 14 nullop else // don't back off if enemy small
			{
				ifvare holoweap 9 nullop
				else
				ifrnd 128 ai HOLOBOTRUNBACK else ai HOLOJUMPBACK
			}
		 }
		   ifvarg xydist 4096 { ifai HOLOBOTRUNBACK ai HOLOBOTGO ifai HOLOJUMPBACK ai HOLOBOTGO }
	}
	
	state confirmtarget

	ifvarn target -1 ifai RETURNTOPLAYER ai HOLOBOTGO
}

    ifvarn target -1
	 ifvarn holoweap 0
	  ifvare dodge 0
	    state holobotfire
	    
	    else
	      ifai AIHURRICANE ai HOLOSTOPPED
	               
ifai AIBOTSWIM nullop else
ifvare target -1 ifvare dodge 0 // return to player
{
    state seekammo
	ifvare hammtarg -1
	{
		ifpdistg 2048 // follow the player if far away
		{
	     	ifai HOLOSTOPPED ai HOLOBOTGO
			ifai RETURNTOPLAYER { ifcansee ai HOLOBOTGO } else
			{
				getplayer[THISACTOR].posx mx
				getplayer[THISACTOR].posy my
       			getactor[THISACTOR].x x
       			getactor[THISACTOR].y y
       			subvarvar mx x
      			subvarvar my y
      			getangle angvar mx my
      			setactor[THISACTOR].ang angvar
			}
			ifai HOLOBOTGO
				{
					ifcansee nullop
					 else ai TRANSITION
				}

			ifai TRANSITION ai RETURNTOPLAYER
		}
		
	    else 
		{
			// don't let him trap the player
			ifpdistl 768 ifai HOLOSTOPPED
			{
				getplayer[THISACTOR].ang angvar
				setactor[THISACTOR].ang angvar
				ai HOLOBOTGO
			}
			else
			   ifpdistl 1024 nullop else ifactioncount 4 // don't stop if super close
			{
				ifai RETURNTOPLAYER ai HOLOSTOPPED
				ifai HOLOBOTGO ai HOLOSTOPPED // stop if between 1024 and 2048
			}

		}
	}
}

ifgapzl 48
{
	ifaction HOLOBOT_STAND
	{
		ifaction HOLO_DUCKING nullop else action HOLO_DUCKING
	} else
	ifaction HOLOBOT_RUN
	{
		ifaction HOLO_CRAWLING nullop else action HOLO_CRAWLING
	}
}
else ifrnd 4
{
	ifaction HOLO_DUCKING action HOLOBOT_STAND
	ifaction HOLO_CRAWLING action HOLOBOT_RUN
}

ifvare countvar 0 setvar target -1 // to prevent him from keeping one target too long

ifinwater
{
	ifai AIBOTSWIM nullop else
	ai AIBOTSWIM
}


ends


useractor notenemy HOLOBOT 100

ifvarg menutoggle 0 break
fall


ifai 0
{
	setactor[THISACTOR].extra holostrength
	randvar hammo2 42
	randvar hammo3 10
	randvar hammo4 50
	randvar hammo5 4
	randvar hammo7 3
	randvar hammo8 20
	randvar hammo10 20
	
	setvarvar temp holostrength
	divvar temp 100
	ifvarl temp 1 setvar temp 1
	randvar tempb 2
	switch tempb
	case 0 mulvarvar hammo2 temp mulvarvar hammo3 temp mulvarvar hammo4 temp break
	case 1 mulvarvar hammo5 temp mulvarvar hammo8 temp break
	case 2 mulvarvar hammo7 temp mulvarvar hammo10 temp break
	endswitch
	
	sizeat MINXSTRETCH MINYSTRETCH
	action HOLOBOT_STAND
	
	setvarvar currholo THISACTOR
	sound ACTOR_SHRINKING
	setvar holoweap 2
	cstat 2
	ai GROWHOLO
	
	ifvarand tipfield 8 nullop else ifvare tipdisplay 0 ifvare ONCAR 0 ifp palive
	{
			// DUKEBOT TIP
			setvar menutoggle 4
			setvar tipdisplay 8
			orvar tipfield 8
			setvar messagetime 26
			globalsound EXITMENUSOUND
	}
}


ifai GROWHOLO
{
	ifcount 36 
	{ 
		cstat 259 
		ai HOLOBOTGO
	}
	else
	{
		sizeto 42 36 // 42 36
		spawn FRAMEEFFECT1
	}
}

else 
state holobotcode

enda

// ****************BEGINNING OF EVIL DUKE CODE*********************

action EVIL_RUN  -2495  4 5 1 10
action EVIL_STAND -2429 1 5 1 1 // actually crouching
action EVIL_JUMP -2465 4 5 1 15
action EVIL_DYING -2409 7 1 1 18
action EVIL_DEAD -2402 1 1
// action EVIL_RBACK -2470 4 5 -1 10
action EVIL_RBACK -2495 4 5 1 10
action EVIL_RISE -2402 1 -1 36
action EKICK_OUT -2471 1 5 1 20

move EVILJUMP 180 -80
move EVILJUMPBACK -180 -80
move EVILRUNSPEED 256 -8
move ERUNBACK -180 -8
move EVILSTOP

ai EVILGO EVIL_RUN EVILRUNSPEED geth
ai EVILRUNBACK EVIL_RBACK ERUNBACK geth // old action EVIL_RUN
ai EJUMP EVIL_JUMP EVILJUMP geth getv
ai EJUMPBACK EVIL_JUMP EVILJUMPBACK geth getv
ai EVILTOPLAYER EVIL_RUN EVILRUNSPEED seekplayer
ai ESTOPPED EVIL_STAND EVILSTOP geth
ai EDYING EVIL_DYING EVILSTOP geth
ai AIEHURRICANE EKICK_OUT HURRICANE geth
ai EVILDODGE EVIL_RUN EVILSTOP geth

state minitaunt

randvar temp 4
addvar temp 416
soundvar temp
ends


state evildeath

strength 0
ifaction EVIL_DEAD 
{
    state deadlist

	sound PIPEBOMB_EXPLODE
	spawn EXPLOSION2
	hitradius 1536 30 60 100 150
	debris SCRAP1 15 debris SCRAP1 4
	           // state exitwplist
	           state clearlists
	           killit
          break
}

ifactioncount 2 nullop else ifactioncount 1 ifvare mtype 1 soundonce MINIDEATH
ifactioncount 7
{ 
	cstat 256 
	action EVIL_DEAD 
	setactor[THISACTOR].htextra 0
	ifvare mtype 1
	{
		sound PIPEBOMB_EXPLODE
		spawn SMALLEXPLOSION
		hitradius 1024 15 30 50 75
		state clearlists
		// state exitwplist
	           	killit
	}
	              
}

ends


state evilswitchweapon

ifvarl xydist 5120 ifvarn mtype 1 ifvarn target -1
{
	ifvare mtype 0 ifvarg hammo5 0 nullop else
	{
		ifvarl xydist 2048 
		{
			ifrnd 24 
			setvar holoweap 9
		}
		else ifrnd 8 setvar holoweap 9
	}
}
else
ifvarg hammo8 0 ifvarg xydist 1536 setvar holoweap 8
else
ifvarg hammo10 0 setvar holoweap 10
else
ifvarg hammo7 0 ifvarg countvar 40 ifvarl countvar 60 setvar holoweap 7
else
ifvarg hammo5 0 ifrnd 128 setvar holoweap 5
else
ifvarg hammo4 0 setvar holoweap 4
else
ifvarg hammo3 0 setvar holoweap 3
else
ifvarg hammo2 0 setvar holoweap 2
else
 ifvarg hammo7 0 setvar holoweap 7
else
 ifvarn mtype 1 ifvarl xydist 6144 ifvare ONCAR 0 setvar holoweap 9
 
else setvar holoweap 0

ends

state evilportplayer
sound TELEPORTER	
spawn TRANSPORTERSTAR
getplayer[THISACTOR].posx mx
getplayer[THISACTOR].posy my
getplayer[THISACTOR].posz tempc
setactor[THISACTOR].x mx
setactor[THISACTOR].y my
setactor[THISACTOR].z tempc
spawn TRANSPORTERSTAR
setvar target -1 // forget about old target after teleporting
ends

state evilfireweapon

ifvare mtype 1 ifpdistg 6144 break

ifvarn holoweap 9
{
	setvarvar temp hammo2
	addvarvar temp hammo3
	addvarvar temp hammo4
	addvarvar temp hammo5
	addvarvar temp hammo7
	addvarvar temp hammo8
	addvarvar temp hammo10
	ifvarl temp 0 setvar holoweap 9
}
	
	ifvarn holoweap 9 ifvare dodge 0
		state aimattarget
	addvar hweapcount 1

	switch holoweap

	case 2:  // pistol
		ifvarl botclip 1
		{
		   ifvare hweapcount 3 sound EJECT_CLIP
		   ifvare hweapcount 12 sound INSERT_CLIP
		   ifvarg hweapcount 27 
		   { 
		   		ifvarg hammo2 11 setvar botclip 12
				else setvarvar botclip hammo2
				setvar hweapcount 0
		   }
		}
		else
		{
		   ifvare hweapcount 2 state pistolfire	
		   ifvarg hweapcount 5 
			{ 
				subvar botclip 1
				setvar hweapcount 0
			}
		 }
		break

	case 3:  // shotgun

		ifvare hweapcount 4 state shotgunfire
		ifvare hweapcount 15 sound SHOTGUN_COCK
		ifvare hweapcount 20 state shelleject2
		
		ifvarg hweapcount 30 
		    setvar hweapcount 0
	
		break

	case 4:   // chaingun
		ifvarg hweapcount 2 
		{
			ifvare holoweap 4 state chainfire
			setvar hweapcount 0
		}
		
		break	
		
	case 5:   // RPG
	case 15   // railgun
		
		ifvare hweapcount 4 { ifvare holoweap 5 state rpgfire else state railgunfire }
		ifvarg hweapcount 19
		  setvar hweapcount 0 
		  
		break

	case 7:  // shrinker

		ifvare hweapcount 3 state shrinkfire
		ifvarg hweapcount 39 setvar hweapcount 0
		// note that actual weapon speed would be ifvarg hweapcount 12
		break

	
	case 8:  // devastator
	case 18: // blaster
	
		ifvare hweapcount 3 
		{
			ifvare holoweap 8 state devfire
			 else 
			   state blasterfire
		}
		ifvarg hweapcount 4 
			setvar hweapcount 0 
			
		break
		
	

	case 9:  // hurricane kick

		ifvarg xydist 8192 ifvarg hweapcount 79
		{
			ai ESTOPPED
			setvar hweapcount 0
		}
		else
		{
			ifai AIEHURRICANE nullop else ai AIEHURRICANE
			ifactioncount 1 ifvarl xydist 1536
			{
					sound KICK_HIT
					  
					ifvare mtype 2          
					{
						setactor[target].htextra 15
						espawn SMALLEXPLOSION
						getactor[target].x mx
						getactor[target].y my
						getactor[THISACTOR].z mz
						setactor[RETURN].x mx
						setactor[RETURN].y my
						setactor[RETURN].z mz
						sound PIPEBOMB_EXPLODE
					} 
					else 
					 setactor[target].htextra 7
					 setactor[target].htpicnum KNEE
					 resetactioncount
			}
				getactor[target].x mx
				getactor[target].y my
				getactor[target].z mz
				getactor[THISACTOR].x x
				getactor[THISACTOR].y y
				ifvarvarg x mx 
				{
					subvar x 96
					ifvarvarl x mx addvar x 128
				}
				else
				{
					addvar x 96
					ifvarvarg x mx subvar x 128
				}
				ifvarvarg y my
				{
					subvar y 96
					ifvarvarl y my addvar y 128
				}
				else
				{
					addvar y 96
					ifvarvarg y my subvar y 128
				}
				subvar mz 5120
				updatesectorz x y mz mysector
				ifvarn mysector -1		
				{			
					setactor[THISACTOR].x x
					setactor[THISACTOR].y y
					setactor[THISACTOR].z mz
				}
				// spinning
				getactor[THISACTOR].ang angvar
				ifvarl hweapcount 8 addvar angvar 93
				else ifvarl hweapcount 16 { soundonce HURR_KICK addvar angvar 171 }
				else ifvarl hweapcount 80 addvar angvar 267
				else ifvarl hweapcount 96 addvar angvar 171
				else ifvarl hweapcount 104 addvar angvar 93
				setactor[THISACTOR].ang angvar
		}
		

		ifvarg hweapcount 104
		{
			setvar hweapcount 0
			ifai AIEHURRICANE ai ESTOPPED
		}


		break


	 case 10:  // freezer
	 case 20:  // lightning gun
	 
	 	ifvare hweapcount 2
	 	 {
		 	 ifvare holoweap 10 state freezerfire
		 	  else state lightningfire
		 }
	
		ifvarg hweapcount 4 
				setvar hweapcount 0  
		break

	default: setvar hweapcount 0 state evilswitchweapon break

	endswitch
	
ends

state evilcheckwall

cos mycos countvarc
sin mysin countvarc
setvar zdist 0
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z
subvar z 4096
getactor[THISACTOR].sectnum mysector
hitscan x y z mysector mycos mysin zdist hitsector hitwall hitsprite hitx hity hitz clipmask

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

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

ends


state evildodgeprojectile

ifvarg dodge 0 ifai EVILDODGE
{
	cos xvel countvarc
	sin yvel countvarc
	  
	divvar xvel 70
	divvar yvel 70
	     
	setvar zvel 0
	movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN 
}
ifvare hammtarg -1 
break
ifvare holoweap 9 break
getactor[hammtarg].picnum tilenum
switch tilenum
case RPG
case RPGNOAIM
case HLROCKET
case CPUDEV
iffloordistl 8
{
	getactor[hammtarg].z tempb
	getactor[THISACTOR].z z
	subvarvar tempb z
	ifvarl tempb 0 mulvar tempb -1
	ifvarl tempb 4096
	{
		// time to jump...
		ifai EJUMP nullop else { ai EJUMP setvar countvar 0 }
	}
			
}
break
endswitch


ifai EJUMP nullop else ifai EJUMPBACK nullop else ifvare dodge 0
{
	getactor[THISACTOR].ang countvarc
	ifrnd 128 
	{
		addvar countvarc 480
		state evilcheckwall
		ifvarl xydist 1560 subvar countvarc 960
	} 
	else 
	{
		subvar countvarc 480
		state evilcheckwall
		ifvarl xydist 1560 addvar countvarc 960
	}
	setvar dodge 20
	ai EVILDODGE
}


ends

state evilcode

addvar countvar 1
ifaction EVIL_RISE ifactioncount 7 ai EVILGO
state setholotarg
state monsterai
ifvarg menutoggle 0 break

ifvarn holoweap 0
{
	getactor[THISACTOR].z z
	subvar z 8192
	setactor[THISACTOR].z z
	setvar target -1
    ifvarn currholo -1 
    {
	    setvarvar target currholo
		canseespr THISACTOR target holocansee // is the enemy target visible?
		ifvare holocansee 0 setvar target -1
	}
	ifvare target -1
	{
		getplayer[THISACTOR].i target
		canseespr THISACTOR target holocansee
		ifvare holocansee 0 setvar target -1
	}
	addvar z 8192
	setactor[THISACTOR].z z

}

ifvare mtype 1
{
	getplayer[THISACTOR].heat_on temp
	ifvare temp 0 { cstat 32768 changespritestat THISACTOR 0 }
}


ifhitweapon 
{ 
	state checkdart 
	debris SCRAP1 1 
	ifwasweapon SHOTSPARK1 ifvare dodge 0 //ifrnd 96
	{
		getactor[THISACTOR].ang countvarc
		ifrnd 128
		{
			addvar countvarc 480
			state evilcheckwall
			ifvarl xydist 1560 subvar countvarc 960
		}
		else
		{
			subvar countvarc 480
			state evilcheckwall
			ifvarl xydist 1560 addvar countvarc 960
		}
		setvar dodge 13
		ai EVILDODGE
	}
}

ifdead 
{ 
	ai EDYING state dropcoins state addscore cstat 128  
	break
}
ifsquished { ai EDYING state dropcoins state addscore cstat 128 break }


ifvare holoweap 0 state evilswitchweapon

// dodge code
state evildodgeprojectile


// random dodge on hitscan
ifvare scanned 1 ifrnd 12 ifvare dodge 0 iffloordistl 8
{
	ifai EJUMP nullop else ifai EJUMPBACK nullop else
	{
		getactor[THISACTOR].ang countvarc
		ifrnd 128 
		{
			addvar countvarc 384
			state evilcheckwall
		    ifvarl xydist 1560 subvar countvarc 768
	    }
		else 
		{
			subvar countvarc 384
			state evilcheckwall
			ifvarl xydist 1560 addvar countvarc 768
		}
		setvar dodge 13
		ai EVILDODGE
	}
}

ifvarg dodge 0 
{
	subvar dodge 1
	ifvare dodge 0 ifai EVILDODGE ai EVILGO
}


ifp phigher
 	ifvarg countvar 60 
{
		ifai EVILGO { ai EJUMP setvar countvar 0 }
		ifai EVILTOPLAYER { ai EJUMP setvar countvar 0 }
}


ifvarg countvar 58 ifrnd 32
{
		ifai EVILTOPLAYER ai EJUMP
		ifai EVILGO ai EJUMP 
		ifai EVILRUNBACK ai EJUMPBACK
		setvar countvar 0
}


ifvare mtype 1 ifvarg countvar 50 
{ 
	ifai EJUMP nullop else ifai EJUMPBACK nullop else ai EJUMP
	ifrnd 64 state minitaunt
	setvar countvar 0
}

ifnotmoving
		ifrnd 2 operate		
		
ifvarg countvar 13 { ifai EJUMP ai EVILGO ifai EJUMPBACK ai EVILRUNBACK }
ifvare target -1 ifai EVILRUNBACK ai EVILGO

ifvarg countvar 63 setvar countvar 0

ifvarn target -1 ifvare dodge 0 // if target acquired and not dodging
{
	
	ldist xydist THISACTOR target
      	ifvare xydist 0 setvar xydist 1 // to avoid dividing by zero when enemy at zero distance

	getactor[target].xrepeat temp
	ifvarl temp 14 { ifai EVILGO nullop else ai EVILGO } // if enemy small, go towards it to squish
        else
	{
		ifawayfromwall ifvarl xydist 2560 ifai EVILGO { ifrnd 128 ai EVILRUNBACK else ai EJUMPBACK }
		ifvarg xydist 6144 { ifai EVILRUNBACK ai EVILGO ifai EJUMPBACK ai EVILGO }
	}
	
	ifai EVILTOPLAYER ai EVILGO	
}


ifvare hweapcount 0 state evilswitchweapon

    ifvarn target -1
	 ifvarn holoweap 0
	   state evilfireweapon
	  
else
	ifai AIEHURRICANE { ai ESTOPPED setvar hweapcount 0 }
	      
ifai ESTOPPED ifcount 13 ai EVILGO


ifvare target -1 ifvare dodge 0 // return to player or follow waypoints
{
	ifai EVILGO ai EVILTOPLAYER
}
	  
ends


useractor enemy EVILDUKE 150


ifai 0
{
	cstat 257
	spritepal 10
	randvar temp 6
	switch temp
	case 0 setvar hammo2 240 setvar holoweap 2 break
	case 1 setvar hammo3 68 setvar holoweap 3 break
	case 2 setvar hammo4 444 setvar holoweap 4 break
	case 3 setvar hammo5 68 setvar holoweap 5 break
	case 4 setvar hammo7 50 setvar holoweap 7 break
	case 5 setvar hammo8 180 setvar holoweap 8 break
	case 6 setvar hammo10 148 setvar holoweap 10 break
	endswitch
	
	ifvare mtype 1
	{
		ai EJUMP
		setvar hammo5 0 setvar hammo8 0 setvar hammo7 0  setvar holoweap 4 setvar hammo4 444 
		sizeat 16 14 setvar mval PIGVAL strength 30
		state minitaunt
	}
	else ifvarg score 15000 ifrnd 84
	{
		ai EVILGO
		sizeat 42 36
		setvar mval SUPERBEASTVAL
		state monstmakebarrier
		strength 300
		setvar hammo3 30
		setvar hammo4 0 //200
		setvar hammo5 26
		setvar hammo7 0
		setvar hammo8 0
		setvar hammo10 0
		setvar mtype 2
		spritepal 14
	}
		 
	else
	{
		 ai EVILGO 
		 sizeat 42 36 
		 setvar mval EVILDUKEVAL 
	}
	
	state difficulty
}

ifvarn barrierup -1 
{
	  setactor[barrierup].xrepeat 0
	  setactor[barrierup].yrepeat 0
	  getactorvar[barrierup].countvarb temp
	  getactorvar[barrierup].countvar tempb
	  getactor[barrierup].cstat tempc
	  ifvare temp 0 ifvare tempb 0 ifvarn tempc 2
	    setactor[barrierup].cstat 258
	  
}

ifai EDYING state evildeath
else
state evilcode
fall
setvar hammtarg -1

ifvarn barrierup -1 { setactor[barrierup].xrepeat 128 setactor[barrierup].yrepeat 96 }

enda

// END OF EVIL DUKE CODE


action SEEK  -8 15 1 1 4

move FLY 320 0

ai SEEKERGO SEEK FLY faceplayerslow

state seekerboom
hitradius 1536 15 22 35 45
spawn EXPLOSION2
sound PIPEBOMB_EXPLODE
killit
ends

useractor notenemy SEEKER 5 

ifai 0 
{ 
	sizeat 20 20 
	cstat 256 
	spritepal 7 
	ai SEEKERGO 
	ifspawnedby NEWBEAST spritepal 6
}
		
	getplayer[THISACTOR].posz mz
	getactor[THISACTOR].z z

	ifvarvarg z mz			
	{ 
		subvar z 256
		setactor[THISACTOR].z z
	}
	else ifvarvarl z mz
	{
		addvar z 256
		setactor[THISACTOR].z z
	}
		
ifhitweapon ifdead state seekerboom
findnearactorz BARRIER 768 8192 temp
ifvarn temp -1 state seekerboom
ifpdistl 896 state seekerboom
ifcount 520 state seekerboom
// iffloordistl 2 state seekerboom
// ifceilingdistl 2 state seekerboom
// ifawayfromwall nullop else state seekerboom

// spawn NEWSMOKE
enda


//  start of Forcebarrier code


state barrierdestroyed
lotsofglass 30
sound GLASS_BREAKING
//setactorvar[myspawner].forcefield 0
setactorvar[myspawner].barrierup -1
killit
ends

move BARRIERGROW

useractor notenemy BARRIER 200

sleeptime 0

ifmove 0
{
	sizeat 1 1
	move BARRIERGROW
	spritepal 12
	cstat 771
	ifvare barrierlevel 4 ifspawnedby APLAYER addstrength 200
	getactor[myspawner].picnum mtype
	ifvarn mtype APLAYER // strength of monster shields depends on score
	{
		sizeto 128 96
		setvarvar temp score
		ifvarg temp 1000
		{
			divvar temp 1000
			mulvar temp 25
			getactor[THISACTOR].extra hp
			addvarvar hp temp
			setactor[THISACTOR].extra hp
		}
	}
}
// cstat  771 =  blocks, shootable, and transparency level 2

ifvare mtype APLAYER 
{
	ifvarn ONCAR 0 state barrierdestroyed
	ifvarg barriergrow 0 subvar barriergrow 1
	//findnearspritez NUKEBUTTON 844 10240 spriteid
	//ifvarn spriteid -1 setvar barriergrow 0
	ifvarg barriergrow 0
	{
		sizeto 128 96
		sizeto 128 96
		sizeto 128 96
		sizeto 128 96
		sizeto 128 96
	}
	else
	{
		sizeto 1 1
		sizeto 1 1
		sizeto 1 1
	}
}


ifvarg barrierlevel 2 ifvare mtype APLAYER
{
	getactor[myspawner].extra temp
	ifvarvarl temp maxhealth ifvarl temp 100
	{
		soundonce INTRUDER_ALERT
		palfrom 15 0 0 31
		getactor[THISACTOR].extra tempb
		subvar tempb 1
		addvar pheal 1
		setactor[THISACTOR].extra tempb
		ifvarl tempb 1 state barrierdestroyed
	}
}

/*
ifcount 3 ifvarg barrierlevel 1 ifvare mtype APLAYER
{
	  resetcount
	  findnearactorz PIGCOP 768 6144 temp ifvare temp -1
	  findnearactorz LIZMAN 768 6144 temp ifvare temp -1
	  findnearactorz EGG 768 6144 temp ifvare temp -1
	  findnearactorz GREENSLIME 768 6144 temp ifvare temp -1
	  findnearactorz OCTABRAIN 768 6144 temp ifvare temp -1
	  findnearactorz COMMANDER 768 6144 temp ifvare temp -1
	  findnearactorz NEWBEAST 768 6144 temp ifvare temp -1
	  findnearactorz TANK 768 6144 temp ifvare temp -1
	  findnearactorz RECON 768 6144 temp ifvare temp -1
	  findnearactorz BOSS1 768 6144 temp ifvare temp -1
	  findnearactorz MINIBOSS2 768 6144 temp ifvare temp -1
	  findnearactorz BOSS3 768 6144 temp ifvare temp -1
	  findnearactorz BOSS4 768 6144 temp ifvare temp -1
	  findnearactorz MINIBOSS4 768 6144 temp ifvare temp -1
	  findnearactorz DRONE 768 6144 temp ifvare temp -1
	  findnearactorz ROBOMAN 768 6144 temp ifvare temp -1
	  findnearactorz DRONEDEV 768 6144 temp ifvare temp -1
	  findnearactorz LIZTROOP 768 6144 temp

  	  ifvarn temp -1
	  { 
		getactorvar[temp].monstatus tempc
		ifvare tempc 1
		{
			sound SHORT_CIRCUIT 
			getactor[temp].htextra tempb
			ifvarl tempb 1
			{
				  setactor[temp].htextra 2
				  setactor[temp].htpicnum RADIUSEXPLOSION
				  setactor[temp].htowner THISACTOR
				  palfrom 15 0 30 30
				  addstrength -1
		    }
    	}
		
	  }
}
*/	



// Barrier positioning
getactor[myspawner].yrepeat temp
ifvarl temp 24 state barrierdestroyed
	 
getactor[myspawner].z z
getactor[myspawner].x x
getactor[myspawner].y y
getactor[myspawner].ang angvar
setactor[THISACTOR].ang angvar
addvar z 2048
setactor[THISACTOR].z z

setvarvar mx x
addvar mx 640

rotatepoint x y mx y angvar temp my
setactor[THISACTOR].x temp
setactor[THISACTOR].y my

ifvarg holosphere 0
{
	ifvarg holosphere 1 cstat 32768
	else cstat 771
	break
}

ifvare mtype APLAYER
{	
	
	ifvare target -1 findnearspritez SHRINKER 1024 10240 target
	ifvare target -1 findnearspritez FLAK 1024 10240 target
	ifvare target -1 findnearspritez HLROCKET 1024 10240 target
	ifvare target -1 findnearspritez NOVA 1024 10240 target
	ifvare target -1 findnearspritez BLASTER 1024 10240 target
	
	
	ifvarn target -1
	{
		getactor[target].owner tempb
		ifvarvare tempb myspawner setvar target -1
	}
	ifvare target -1 findnearspritez SLOWBULLET 1024 10240 target
	ifvare target -1 findnearspritez FLAMETHROWER 1024 10240 target
	ifvare target -1 findnearspritez FIRELASER 1024 10240 target
	ifvare target -1 findnearspritez RPGNOAIM 1024 10240 target
	ifvare target -1 findnearspritez FREEZENOAIM 1024 10240 target
	ifvare target -1 findnearspritez CPUDEV 1024 10240 target
	ifvare target -1 findnearspritez FIRELASER3 1024 10240 target
	ifvare target -1 findnearspritez MAGMA 1024 10240 target
	ifvare target -1 findnearspritez BLASTER3 1024 10240 target
	ifvare target -1 findnearspritez BLASTER4 1024 10240 target
	
	
	ifvarn target -1
	{
		cstat 771
		sound BARRIER_HIT
		getactor[target].x mx
		getactor[target].y my
		getactor[target].z mz
		getactor[THISACTOR].extra hp
		getactor[target].owner tempb
		ifvarvarn tempb THISACTOR subvar hp 5
		setactor[THISACTOR].extra hp
		ifdead state barrierdestroyed
	
		ifvarg barrierlevel 1
		{
		 	getactor[THISACTOR].ang angvar
		 	setactor[target].ang angvar
		  	getactor[target].zvel tempc
		 	mulvar tempc -1
		 	setactor[target].zvel tempc
	        setactor[target].owner THISACTOR
		}
		//else setactor[target].xrepeat 0
		
		espawn LASER3IMPACT
		setactor[RETURN].x mx
		setactor[RETURN].y my
		setactor[RETURN].z mz
		setvar target -1
	}
}
else
{
	ifvarg superkicking 0 ifvare kickimpact 0
	{
		ifp pfacing
			ifpdistl 1792
				ifcansee
					ifcanshoottarget
		{
			setvar dodge 0
			ifvarg superkicking 7
			{
				ifvare spinkick 0 setvar kickimpact 1
				sound BARRIER_HIT
				setvarvar tempb weap0lev
				setactor[THISACTOR].htpicnum KNEE
				setactor[THISACTOR].htextra tempb
			}
		}
	}
}

getactor[THISACTOR].cstat temp
ifvare temp 2
{
	getactorvar[myspawner].holoweap holoweap
	switch holoweap
	case 2
	case 3
	case 4
	case 15
		ifvarg countvar -1
		cstat 771
		break
	case 5
	case 8
	case 18
	case 10
	case 13
		ifvarg countvar 1 
		cstat 771
		break
	case 6
	case 16
		ifvarg countvar 5
		 cstat 771
		  break
	
	case 14
	case 20
		ifvarg countvar 0
		 cstat 771
		  break
	
	case 11
	case 7	
		ifvarg countvar 3
		 cstat 771
		  break
		
	default
	 ifvarg countvar 1
	 cstat 771
	  break
	endswitch
	
	addvar countvar 1
}
else setvar countvar 0

getactorvar[myspawner].barrierup barrierup
ifvare barrierup -1 killit

getactor[myspawner].extra temp
ifvarl temp 1 state barrierdestroyed

ifvarg countvarb 0 subvar countvarb 1

getactor[THISACTOR].htextra temp
ifvarg temp 0
{
	getactor[THISACTOR].htpicnum tempb
	ifvare tempb KNEE setactor[THISACTOR].htextra 0
}

ifhitweapon
{
	ifvarn mtype APLAYER { cstat 771 setvar countvarb 3 }
	
	ifwasweapon KNEE nullop
	else
	{
		ifvare mtype APLAYER palfrom 25 0 0 50
		sound BARRIER_HIT
	}
	ifdead state barrierdestroyed
}

enda

state allyfire

ldist xydist THISACTOR target
state calczdist
subvar zdist 4096

ifvare mtype 2 shiftvarl zdist 8 else
mulvar zdist 644
ifvare xydist 0 setvar xydist 1
divvarvar zdist xydist // zdist now holds the desired z velocity
spawn MUZZLEFLASHLOW
ifvare mtype 0
{
  sound RPG_SHOOT
  ezshoot zdist CPUDEV
  setactor[RETURN].owner myspawner
}
ifvare mtype 1
{
  sound BLASTERSND
  ezshoot zdist BLASTER
  setactor[RETURN].owner myspawner
}
ifvare mtype 2
{
  sound M16FIRE
  ezshoot zdist APROUND
}  

addvar weap5xp 2
setvarvar tempd pdamage
setvar tempb 5
state weaplevel
setvarvar pdamage tempd
addstrength -2

ends

state turntowardsenemy

        state gradualturn
        ifvarl tempd 0 mulvar tempd -1
        mulvar tempd 2     
ends


action ASATNSPINALLY     0 5 1 1 4
action ASATSHOOTINGALLY   -10 3 5 1 40
action ASATWAITALLY      0 1 5 1 1

useractor notenemy ROTATEGUNALLY 50

setvar gunally 8

ifvarn target -1
{
    ifaction ASATWAITALLY action ASATSHOOTINGALLY
    state turntowardsenemy
}
else
{
  findnearactor ROTATEGUNALLY 16384 temp
  ifvarn temp -1
     getactorvar[temp].target target
}

  ifaction 0
  {
    action ASATWAITALLY
    cstat 257
    sizeat 42 42
    
    getactor[THISACTOR].z z
    subvar z 5120
    setactor[THISACTOR].z z
    espawn 3861
    setactor[RETURN].xrepeat 16
    setactor[RETURN].yrepeat 12
    setactor[RETURN].cstat 130
    getactor[RETURN].z mz
    addvar mz 2048
    setactor[RETURN].z mz
    setvarvar hammo2 RETURN
   
   randvar mtype 2
   getplayer[THISACTOR].i myspawner
   setactor[THISACTOR].owner myspawner
  }
  else
    ifaction ASATNSPINALLY
  {
    ifactioncount 32
    {
      action ASATWAITALLY
    }
  }
  else
    ifaction ASATSHOOTINGALLY
  {
 
    ifactioncount 12
      ifrnd 32
    {
      action ASATWAITALLY
      move 0
    }
    ifcount 32
      resetcount
    else
      ifcount 16
    {
      ifcount 17 nullop
      else
      ifvarn target -1
	  {
		  canseespr THISACTOR target temp
		  ifvare temp 1 ifvarl tempd 64
	       {
	      	  	state allyfire
				getactor[target].extra hp
	  			ifvarl hp 1 setvar target -1
			}
		   else setvar target -1
	   }
    }
    else
      ifcount 4
    {
      ifcount 5 nullop
      else
      {	
        	ifvarn target -1
	  {
	  canseespr THISACTOR target temp
	  ifvare temp 1 ifvarl tempd 64
		{
      	  	state allyfire
		getactor[target].extra hp
  		ifvarl hp 1 setvar target -1
		}
	  else setvar target -1
	  }
		
      }
    }
 
  }

  

  ifdead
    {
      sound LASERTRIP_EXPLODE
      debris SCRAP1 15
      spawn EXPLOSION2
      setactor[hammo2].xrepeat 0
      setactor[hammo2].yrepeat 0
      setactor[hammo2].cstat 32768
      killit
    }

  ifhitweapon
  {
    ifdead
    {
      sound LASERTRIP_EXPLODE
      debris SCRAP1 15
      spawn EXPLOSION2
      setactor[hammo2].xrepeat 0
      setactor[hammo2].yrepeat 0
      setactor[hammo2].cstat 32768
      killit
    }
    else
    {
      action ASATNSPINALLY
      debris SCRAP1 4
    }
    move 0
  }

enda



// ********************
// ****    MECH    ****
// ********************


action AMECHWALK      0  4  5  1  30
action AMECHPREPFIRE  20 3  5  1  40
action AMECHFIRE      30 2  5  1  7
action AMECHFIRE2     30 2  5  1  30
action AMECHDYING     40 8  1  1  18
//action AMECHDEAD      -5 1  5  1
action AMECHDEAD	47 1 5 1

move MECHWALKVELS 150
move MECHSTOPVELS 0

ai AIMECHDYING AMECHDYING MECHSTOPVELS
ai AIMECHWALK AMECHWALK MECHWALKVELS randomangle
ai AIMECHPREPFIRE AMECHPREPFIRE MECHSTOPVELS faceplayerslow
ai AIMECHFIRE AMECHFIRE MECHSTOPVELS faceplayerslow
ai AIMECHFIRE2 AMECHFIRE2 MECHSTOPVELS faceplayerslow
ai AIMECHSEARCH AMECHWALK MECHWALKVELS seekplayer
ai AIMECHDWALK AMECHWALK MECHWALKVELS randomangle
ai AIMECHDPREPFIRE AMECHPREPFIRE MECHSTOPVELS faceplayerslow
ai AIMECHDFIRE AMECHFIRE MECHSTOPVELS faceplayerslow
ai AIMECHDFIRE2 AMECHFIRE2 MECHSTOPVELS faceplayerslow
ai AIMECHDSEARCH AMECHWALK MECHWALKVELS seekplayer


state mechdeadstate

strength 0
ifhitweapon
{
	ifwasweapon RADIUSEXPLOSION
	{
		debris SCRAP1 20
  		debris SCRAP2 16
  		debris SCRAP3 16
  		debris SCRAP4 16
  		debris SCRAP5 16
  		spawn BIGEXPLOSION
  		spawn BURNING
  		hitradius 2048 7 14 21 28
  		killit
	}
	else state ricochetsound
}

ends

state mechhitstate

state checkdart

ifdead ifvarn monstatus 2
{
	addkills 1
	spawn BIGEXPLOSION
	spawn BURNING
	debris SCRAP2 4
	debris SCRAP1 4
	debris SCRAP3 4
	sound RPG_EXPLODE
	hitradius 1548 10 20 30 40 
	ai AIMECHDYING
	state dropcoins
	state clearlists
	state addscore
}
else
{
	debris SCRAP2 1
	ifwasweapon RPG setactor[THISACTOR].xvel 0
	ifwasweapon RADIUSEXPLOSION setactor[THISACTOR].xvel 0
}
ends

useractor enemy MECH1 600

ifvarg menutoggle 0 break
fall
state monsterai
 
ifceilingdistl 72 sizeto 42 36
else sizeto 48 48

ifaction 0
{ 
	clipdist 80
	setvar mval SUPERBEASTVAL
	cstat 257
	state difficulty
	sizeat 48 48
	//soundonce BOS3_RECOG 
	ai AIMECHWALK 
}

ifaction AMECHDEAD { state mechdeadstate break }
else 
{ 
	state setholotarg
	ifai AIMECHDYING 
	{ 
		ifactioncount 8 
		{ 
			action AMECHDEAD
			spawn NEWSMOKE
			cstat 0
		} 
	} 
}

ifai AIMECHWALK
{

	ifactioncount 1 { soundonce MECHWALK }
	ifactioncount 2 { soundonce MECHSTOMP }
	ifactioncount 3 { soundonce MECHWALK }
	ifactioncount 4 { soundonce MECHSTOMP resetactioncount }
	ifcansee { ifrnd 3 { ai AIMECHPREPFIRE resetactioncount } }
	else { ifrnd 6  ai AIMECHSEARCH }
}

ifai AIMECHSEARCH
{
	ifactioncount 1 { soundonce MECHWALK }
	ifactioncount 2 { soundonce MECHSTOMP }
	ifactioncount 3 { soundonce MECHWALK }
	ifactioncount 4 { soundonce MECHSTOMP resetactioncount }

	ifcansee 
	{ 
		ifrnd 3 
		{ 
			ai AIMECHPREPFIRE 
			resetactioncount 
		} 
	}
}

ifai AIMECHPREPFIRE
{
	ifactioncount 3 ifcanshoottarget
	{
		ifrnd 160 ai AIMECHFIRE
		else
		{
			ifpdistl 4096 ai AIMECHFIRE
			else ai AIMECHFIRE2
		}
	}
}

ifaction AMECHDEAD nullop
else 
{ 
	ifpdistl 1024 ifvare superkicking 0
	{ 
		addphealth -2
		palfrom 40 63
	} 
}

ifai AIMECHFIRE2
{
	ifactioncount 2	
	{
		ifrnd 192 ifvarn currholo -1 setvarvar target currholo else
		getplayer[THISACTOR].i target
		state calczdist
		mulvar zdist 644
		ldist xydist THISACTOR target
		ifvare xydist 0 setvar xydist 1
		divvarvar zdist xydist
		sound MISSILE2
		ezshoot zdist HLROCKET
	    setthisprojectile[RETURN].extra 100
	    setthisprojectile[RETURN].trail SMALLEXPLOSION
		flash
		setactorvar[RETURN].target target
		setactorvar[RETURN].mtype 1
		resetactioncount
	}
	ifrnd 3 ai AIMECHWALK
} 

ifai AIMECHFIRE
{
	ifactioncount 2	
	{
		sound FLAK_FIRE shoot FLAK shoot FLAK
		flash
		resetactioncount
	}
	ifrnd 3 ai AIMECHWALK
	ifcanshoottarget nullop else ifrnd 12 ai AIMECHWALK
} 

ifai AIMECHDWALK
{
	ifrnd 6 
	{ 
		ifcansee 
		{ 
			ai AIMECHDPREPFIRE 
			resetactioncount 
		} 
	}
	else { ifrnd 6 ai AIMECHDSEARCH  }
}

ifai AIMECHDSEARCH
{
	ifrnd 3 
	{ 
		ifcansee 
		{ 
			ai AIMECHDPREPFIRE 
			resetactioncount 
		} 
	}
}

ifai AIMECHDPREPFIRE
{
	ifactioncount 3
	{
		ifrnd 128 ai AIMECHDFIRE
		else
		{
			ifrnd 100 ai AIMECHDFIRE
			else ai AIMECHDFIRE2
		}
		
	}
}

ifhitweapon state mechhitstate


enda

action AROBOWALKING       0     4    5    1    16
action AROBORUNNING       0     4    5    1    8
action AROBOTHINK         20    2    5    1    40
action AROBOSCREAM        30    1    5    1    2
action AROBOJUMP          45    3    5    1    20
action AROBOFALL          55
action AROBOSHOOTING      70    2    5    1    7
action AROBODYING         60    6    1    1    15
action AROBOLYINGDEAD     65    1
action AROBOFROZEN         0    1    5

move ROBOWALKVEL 72
move ROBORUNVEL 192
move ROBODODGEVEL 256
move ROBOHOVERVEL 192 -16
move ROBOFALLVEL 192 16
move ROBOJUMPVEL 184 -128
move ROBOSTOP

ai AIROBOGETENEMY AROBOWALKING ROBOWALKVEL seekplayer
ai AIROBODODGE AROBORUNNING ROBODODGEVEL dodgebullet
ai AIROBOCHARGEENEMY AROBORUNNING ROBORUNVEL seekplayer
ai AIROBOFLEENEMY AROBOWALKING ROBOWALKVEL fleeenemy
ai AIROBOSHOOTENEMY AROBOSHOOTING ROBOSTOP faceplayer
ai AIROBOJUMPENEMY AROBOJUMP ROBOJUMPVEL jumptoplayer
ai AIROBOTHINK AROBOTHINK ROBOSTOP faceplayerslow
ai AIROBOSHRUNK AROBOWALKING SHRUNKVELS fleeenemy
ai AIROBOHEAL AROBOSCREAM ROBOSTOP faceplayerslow
ai AIROBODYING AROBODYING ROBOSTOP faceplayer

state dodgecode

ifbulletnear
{
    ifspritepal 10 ifrnd 160
    {
        state teleport_behind
        ifvare tempd 1
	        break
        
    }
    ifgapzl 128 { setvar countvar 0 ai AIROBODODGE }
    else
    { 
        ifrnd 32
        {
            sound ROBOBOOST 
        	ai AIROBOJUMPENEMY 
    	}
        else { setvar countvar 0 ai AIROBODODGE }
    }
}

ends

state roboseekstate

    ifactornotstayput
    {
	    ifvarl hp 200 ifrnd 2 { ai AIROBOHEAL break }
        ifcansee ifp palive ifpdistl 2048 ifcount 16 ifcanshoottarget { ai AIROBOSHOOTENEMY break }
        ifai AIROBOCHARGEENEMY
        {
            ifcount 72 ifcanshoottarget { ai AIROBOSHOOTENEMY break }
            ifp phigher ifpdistg 2048 ifrnd 6 { sound ROBOBOOST ai AIROBOJUMPENEMY break }
        }
        else ifpdistg 4096 { ifrnd 92 { ifcount 48 ifcanshoottarget ai AIROBOSHOOTENEMY } else ifcount 24 { setvar countvar 0 ai AIROBOCHARGEENEMY break } }

        iffloordistl 16 { ifcount 24 ifnotmoving ifcansee { sound ROBOBOOST ai AIROBOJUMPENEMY break } }
        else { ifpdistg 1280 sound ROBOBOOST ai AIROBOJUMPENEMY break }

        ifrnd 4 ifnotmoving operate
        else state dodgecode
    }
    else
    {
        ifactioncount 16 { ifp palive ifrnd 32 ifcansee ifcanshoottarget ai AIROBOSHOOTENEMY }
        ifcount 16 ifrnd 32 move ROBOWALKVEL randomangle geth
    }

ends

state roboshrunkstate
    ifcount SHRUNKDONECOUNT { setvar countvar 0 ai AIROBOGETENEMY }
    else ifcount SHRUNKCOUNT sizeto 32 28
    else state genericshrunkcode
ends

state robofleestate
    ifcount 16 { ifrnd 48 ifp palive ai AIROBOHEAL }
    else 
    { 
	    iffloordistl 16 nullop else 
	    { 
		    setvar countvar 0 
		    ai AIROBOGETENEMY 
		} 
		break 
	}
ends

state robothinkstate
	state dodgecode
    //ifrnd 8 soundonce CAPT_ROAM
    ifactioncount 3
    {
        ifrnd 32 ifp palive ai AIROBOHEAL
        else ifrnd 96 { setvar countvar 0 ai AIROBOGETENEMY }
    }
    
ends

state roboshootstate
    ifcount 20 ifrnd 16
    {
        ifcansee ifpdistl 2048 
        { 
	        ifrnd 128
	        { 
		        setvar countvar 0
	        	ai AIROBOFLEENEMY 
        	}
	        break 
	    }
        ifrnd 128 ai AIROBOTHINK else { setvar countvar 0 ai AIROBOGETENEMY }
    }
    ifactioncount 2
    {
        ifcansee
        {
            ifcanshoottarget 
            { 
	            sound LASER3FIRE
	            ifspritepal 10 ifrnd 64 shoot BLASTER3 else
	            shoot FIRELASER3 
	            resetactioncount 
	        }
            else ai AIROBOTHINK
        }
        else { setvar countvar 0 ai AIROBOGETENEMY }
    }
    state dodgecode
ends

state checkrobohit
	ifvare goggles 0 ifspritepal 6 getlastpal
    debris SCRAP1 1
    ifai AIROBOSHRUNK
    { 
	        addkills 1
	        spawn EXPLOSION2 
	        sound PIPEBOMB_EXPLODE 
	        ifvarg mval 0 { state dropcoins state addscore }
			state clearlists
			debris SCRAP1 10
  			debris SCRAP2 8
  			debris SCRAP3 8
  			debris SCRAP4 8
  			debris SCRAP5 8	
  			spawn BURNING
  			hitradius 1536 7 12 16 21
  			killit
	}
    ifdead
    {
        ifwasweapon FREEZEBLAST { sound SOMETHINGFROZE spritepal 1 move 0 action AROBOFROZEN strength 0 break }

        state drop_chaingun
        addkills 1
        ifvarg mval 0 { state dropcoins state addscore }
		state clearlists

        ifwasweapon RPG 
        { 
	        spawn EXPLOSION2 
	        sound PIPEBOMB_EXPLODE 
			debris SCRAP1 10
  			debris SCRAP2 8
  			debris SCRAP3 8
  			debris SCRAP4 8
  			debris SCRAP5 8	
  			spawn BURNING
  			hitradius 1536 7 12 16 21
	        killit 
	    }
        else ifwasweapon RADIUSEXPLOSION 
        {  
	        spawn EXPLOSION2 
	        sound PIPEBOMB_EXPLODE
			debris SCRAP1 10
  			debris SCRAP2 8
  			debris SCRAP3 8
  			debris SCRAP4 8
  			debris SCRAP5 8	
  			spawn BURNING
  			hitradius 1536 7 12 16 21
	        killit 
	    }
        else { state rf ai AIROBODYING }
        // death sound here
    }
    else
    {
        state ricochetsound
        ifwasweapon SHRINKSPARK { sound ACTOR_SHRINKING ai AIROBOSHRUNK break }
        // spawn sparks or something
        ifp palive ifcansee ifcanshoottarget 
        {
	        ifaction AROBOJUMP nullop else ifai AIROBOSHOOTENEMY nullop else
	        ifai AIROBODODGE nullop else
	        {
		        ifrnd 192
		        ai AIROBOSHOOTENEMY
		        else 
		        {
			        ifgapzl 96 { ai AIROBODODGE setvar countvar 0 }
			        else
			        ifrnd 192 { ai AIROBODODGE setvar countvar 0 }
			        else { sound ROBOBOOST ai AIROBOJUMPENEMY }
		        }
	        }
	        break 
	    }
    }
ends

state robojumpstate
    ifaction AROBOFALL 
    {
	    ifcanshoottarget ifrnd 9 
	    { 
		    sound LASER3FIRE
		    ifspritepal 10 ifrnd 64 shoot BLASTER3 else 
		    shoot FIRELASER3 
		}
	    iffloordistl 16 { setvar countvar 0 ai AIROBOGETENEMY }
	    ifrnd 192 spawn NEWSMOKE
	    ifactioncount 52 ifrnd 8 move ROBOFALLVEL geth getv
	}
    else
    {
	    ifp phigher 
	    { 
		    ifactioncount 9 { action AROBOFALL move ROBOHOVERVEL geth getv }
		    ifactioncount 3 soundonce DUKE_JETPACK_IDLE
		}
	    else ifactioncount 4 { action AROBOFALL move ROBOHOVERVEL geth getv }
	    ifactioncount 2
	    {
		    ifrnd 128 { espawn SMALLEXPLOSION setactor[RETURN].cstat 2 }
		    else spawn NEWSMOKE
	    }
    }
ends

state robodyingstate

iffloordistl 8 nullop else
{
	ifrnd 64 spawn NEWSMOKE
	ifrnd 64 spawn SMALLEXPLOSION
}

    ifaction AROBOLYINGDEAD
{
     strength 0
     ifhitweapon ifwasweapon RADIUSEXPLOSION 
     { 
	    spawn EXPLOSION2
	    sound PIPEBOMB_EXPLODE 
	    debris SCRAP1 10
  		debris SCRAP2 8
  		debris SCRAP3 8
  		debris SCRAP4 8
  		debris SCRAP5 8	
  		spawn BURNING
  		hitradius 1536 7 12 16 21
	    killit 
	 }
}

else ifai AIROBODYING ifactioncount 6
{ 
	iffloordistl 8 sound THUD 
	move ROBOSTOP 
	action AROBOLYINGDEAD 
}

ends

state robododgestate
	soundonce ROBODODGE
    ifcount 13 { setvar countvar 0 ai AIROBOGETENEMY }
ends


useractor enemy ROBOMAN 200

    ifvarg menutoggle 0 break
	fall
	getactor[THISACTOR].zvel zvel
	ifvarg zvel 768 setactor[THISACTOR].zvel 768
	
	ifvarn barrierup -1
    {
	  setactor[barrierup].xrepeat 0
	  setactor[barrierup].yrepeat 0
	  getactorvar[barrierup].countvarb temp
	  getactorvar[barrierup].countvar tempb
	  getactor[barrierup].cstat tempc
	  ifvare temp 0 ifvare tempb 0 ifvarn tempc 2
	    setactor[barrierup].cstat 258 //33024
	  
    }
	state monsterai
	state setholotarg
    state checksquished
    ifvarn myspawner -1
    {
	    ifai AIROBOHEAL nullop else
	    {
		    setactor[myspawner].xrepeat 0
		    setactor[myspawner].yrepeat 0
		    setvar myspawner -1
	    }
    }
    ifai 0
    {
	    sizeat 32 28 
	    cstat 257
	    state difficulty
	    setvar mval COMMVAL
	    state monstmakebarrier
	    ifvarg score 6000 ifrnd 128 spritepal 10
	    ifspritepal 10 { setvar mtype 1 addvar mval 10 }
	    ai AIROBOGETENEMY
	}
    else ifaction AROBOLYINGDEAD { fall state robodyingstate break }
    else ifaction AROBOFROZEN
    {
        ifcount THAWTIME { setvar countvar 0 ai AIROBOGETENEMY getlastpal }
        else ifcount FROZENDRIPTIME { ifactioncount 26 { spawn WATERDRIP resetactioncount } }

        ifhitweapon
        {
            ifwasweapon FREEZEBLAST { strength 0 break }
            addkills 1

            lotsofglass 30
            sound GLASS_BREAKING
            ifvarg mval 0 { state dropcoins state addscore }
			state clearlists
            killit
        }
        ifp pfacing ifpdistl FROZENQUICKKICKDIST  ifvare superkicking 0 pkick
        break
    }
    else ifai AIROBOJUMPENEMY state robojumpstate
    else
    {
        fall
        ifai AIROBOGETENEMY state roboseekstate
        else ifai AIROBOCHARGEENEMY state roboseekstate
        else ifai AIROBODODGE state robododgestate
        else ifai AIROBOSHOOTENEMY state roboshootstate
        else ifai AIROBOFLEENEMY state robofleestate
        else ifai AIROBOTHINK state robothinkstate
        else ifai AIROBOSHRUNK state roboshrunkstate
        else ifai AIROBODYING state robodyingstate
        else ifai AIROBOHEAL
        {
	        	ifvare myspawner -1
	        	{
		        	espawn FIRESPHERE
		        	setvarvar myspawner RETURN
	        	}
	            ifcount 52 
	            {
		            ifvare mtype 1 spritepal 10 else spritepal 0 
		            setvar countvar 0
		            ai AIROBOGETENEMY
		            ifvare barrierup -1 ifrnd 128 state monstmakebarrier 
		        }
	            else ifcount 18 
	            {
		            ifvare mtype 1
		            {
			            ifspritepal 10 spritepal 6 else spritepal 10
		            }
		            else
		            {
			            ifspritepal 0 spritepal 6 else spritepal 0
		            }
		            ifvarl hp 400 addstrength 1
		            ifvarl hp 100 addstrength 1
		            soundonce INTRUDER_ALERT
		        }
	    }
    }

    ifai AIROBOSHRUNK break
    ifhitweapon state checkrobohit
    ifvarn barrierup -1 
    { 
	    setactor[barrierup].xrepeat 128 
	    setactor[barrierup].yrepeat 96 
	}


enda


action DRONEDEVFRAMES   0   1   7   1   1
action DRONEDEVSCREAM   0   1   7   1   1
move DRONEDEVRUNVELS 128 16
move DRONEDEVRUNUPVELS 128 -64
move DRONEDEVBULLVELS 256 -32
move DRONEDEVBACKWARDS -96 -32
move DRONEDEVRISE 32 -64
move DRONEDEVSTOPPED -16
move DRONESEEKVELS 96 -16

ai AIDRONEDEVSEEK DRONEDEVFRAMES DRONESEEKVELS seekplayer getv
ai AIDRONEDEVGETE DRONEDEVSCREAM DRONEDEVRUNVELS faceplayerslow getv
ai AIDRONEDEVWAIT DRONEDEVFRAMES DRONEDEVSTOPPED faceplayerslow getv // added
ai AIDRONEDEVGETUP DRONEDEVSCREAM DRONEDEVRUNUPVELS faceplayerslow getv
ai AIDRONEDEVPULLBACK DRONEDEVFRAMES DRONEDEVBACKWARDS faceplayerslow getv // added
ai AIDRONEDEVHIT DRONEDEVSCREAM DRONEDEVBACKWARDS faceplayerslow getv // added
ai AIDRONEDEVDODGE DRONEDEVFRAMES DRONEDEVSTOPPED geth getv
ai AIDRONEDEVDODGEUP DRONEDEVFRAMES DRONEDEVRISE getv geth


state DRONEDEVdead
  addkills 1
  debris SCRAP1 16
  debris SCRAP2 8
  debris SCRAP3 14
  spawn EXPLOSION2
  sound RPG_EXPLODE
  hitradius 2048 30 40 50 60
  ifvarg mval 0 { state dropcoins state addscore }
  state clearlists
  killit
ends

state checkDRONEDEVhitstate

  state checkdart
  ifdead state DRONEDEVdead
  else ifsquished state DRONEDEVdead
  else
  {
    sound DRON_PAIN
    ai AIDRONEDEVGETE
  }
ends

state dronedev_shoot

	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 BLASTER4
	ifactor MECH2 
	{
		setthisprojectile[RETURN].drop -100
		setthisprojectile[RETURN].workslike 36870
		//setthisprojectile[RETURN].bounces 2
		setactor[RETURN].yvel 2
		setthisprojectile[RETURN].bsound NULLSOUND
	}
	sound RPG_SHOOT
	ifvare countvarb 0 setvar countvarb 1 else setvar countvarb 0
	setvar countvar 0
	
ends

state DRONEDEVgetstate

state setholotarg
state monsterai
ifvarg menutoggle 0 break
  
ifp palive
	ifcansee
		ifcanshoottarget
			ifvarg countvar 12
				state dronedev_shoot
	  
  ifrnd 208
  {
    ifcansee
    {
      ifvarn hammtarg -1
      {
        ai AIDRONEDEVDODGE
        getactor[THISACTOR].ang dodge
        ifrnd 128 addvar dodge 480 else subvar dodge 480
        break
      }
      ifmove DRONEDEVBULLVELS
      {
        ifcount 42
          ai AIDRONEDEVPULLBACK
        else
          ifnotmoving
            ifcount 16
              ai AIDRONEDEVPULLBACK
      }
      else
        ifcount 32
      {
        ifp phigher
          move DRONEDEVBULLVELS geth getv
        else
          move DRONEDEVBULLVELS geth
      }
    }
    else
      ifrnd 2
        operate
  }
else
{
  ifcansee
  {
    ifpdistl 3072
      ai AIDRONEDEVPULLBACK
  }
  else
    ifcount 40 ai AIDRONEDEVSEEK
}
  
 
ends

state DRONEDEVdodgestate
  ifai AIDRONEDEVDODGEUP
  {
     ifcount 8
       ai AIDRONEDEVGETE
     else
       ifnotmoving
         ai AIDRONEDEVGETE
  }
  else
  {
	 cos xvel dodge
     sin yvel dodge
  
     divvar xvel 80
     divvar yvel 80
     
     setvar zvel 0
     movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN 
	  
    ifcount 12
      ai AIDRONEDEVGETE
    else
      ifnotmoving
        ai AIDRONEDEVGETE
  }
ends

state DRONEDEVseekstate

ifcansee 
 ai AIDRONEDEVWAIT

ends

useractor enemy DRONEDEV 250

setactor[THISACTOR].htcgg 0
addvar countvar 1
ifceilingdistl 32 nullop else
{
	iffloordistl 64
	{
		getactor[THISACTOR].zvel zvel
		subvar zvel 128
		setactor[THISACTOR].zvel zvel
	}
}
getactor[THISACTOR].zvel temp
ifvarg temp 128 setactor[THISACTOR].zvel 128


  ifai 0
  {
	 state difficulty
	 clipdist 128
     sizeat 40 40
     cstat 257
     setvar mval MINIBOSSVAL
     setactor[THISACTOR].pitch 1024
     espawn ROTATEGUN
     setactorvar[RETURN].myspawner THISACTOR
     espawn ROTATEGUN
     setactorvar[RETURN].myspawner THISACTOR
     setactorvar[RETURN].countvarb 1
  }
  
  state monsterai

  //ifrnd 8
    fall
  else
    soundonce DRON_JETSND


  ifaction 0
    ai AIDRONEDEVGETE
  else
    ifai AIDRONEDEVWAIT
  {
    ifactioncount 4
      ifrnd 16
      {
	    ifcansee
	    {
	      sound DRON_ATTACK1
	      ifp phigher
	        ai AIDRONEDEVGETUP
	      else ai AIDRONEDEVGETE
	    }
    	else ai AIDRONEDEVSEEK
	  }
  }
  else
    ifai AIDRONEDEVGETE
      state DRONEDEVgetstate
  else
    ifai AIDRONEDEVGETUP
      state DRONEDEVgetstate
  else
    ifai AIDRONEDEVSEEK
      state DRONEDEVseekstate
  else
    ifai AIDRONEDEVPULLBACK
  {
    ifcount 32
    ai AIDRONEDEVWAIT
  }
  else
    ifai AIDRONEDEVHIT
  {
    ifcount 8
      ai AIDRONEDEVWAIT
  }
  else
    ifai AIDRONEDEVDODGE
      state DRONEDEVdodgestate
  else
    ifai AIDRONEDEVDODGEUP
      state DRONEDEVdodgestate

  ifhitweapon
    state checkDRONEDEVhitstate
    

  ifrnd 1
    soundonce DRON_ROAM
    
setvar hammtarg -1

enda


useractor notenemy FAKEBULSHOOTER 0
shoot FAKEBULLET
killit
enda

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

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

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

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


state mech2deadstate

strength 0
ifhitweapon
{
	ifwasweapon RADIUSEXPLOSION
	{
		debris SCRAP1 20
  		debris SCRAP2 16
  		debris SCRAP3 16
  		debris SCRAP4 16
  		debris SCRAP5 16
  		spawn BIGEXPLOSION
  		spawn BURNING
  		hitradius 2048 7 14 21 28
  		killit
	}
	else state ricochetsound
}

ends

state mech2hitstate

state checkdart

ifdead ifvarn monstatus 2
{
	addkills 1
	spawn BIGEXPLOSION
	spawn BURNING
	spawn STICKYFIRE
	debris SCRAP2 4
	debris SCRAP1 4
	debris SCRAP3 4
	sound RPG_EXPLODE
	hitradius 1548 10 20 30 40 
	ai AIMECH2DYING
	state dropcoins
	state clearlists
	state addscore
}
else
{
	debris SCRAP2 1
	ifwasweapon RPG setactor[THISACTOR].xvel 0
	ifwasweapon RADIUSEXPLOSION setactor[THISACTOR].xvel 0
}
ends

useractor enemy MECH2 1000

ifvarg menutoggle 0 break
fall
state monsterai
 
ifaction 0
{ 
	clipdist 80
	setvar mval SUPERBEASTVAL
	cstat 257
	state difficulty
	sizeat 40 40
	ai AIMECH2GETENEMY 
}

ifaction AMECH2LYINGDEAD { state mech2deadstate break }
else
{ 
	state setholotarg
	ifai AIMECH2DYING 
	{ 
		state randexplosions
		ifactioncount 19
		{
			action AMECH2LYINGDEAD
			spawn NEWSMOKE
			spawn BURNING2
			cstat 0
			ifvare lotag 66 
			{
				espawn BOSSCOIN
			    setactor[RETURN].pal 3
		    }
		}
		
	} 
}

ifai AIMECH2JUMPENEMY
{
	ifcount 27 nullop else
	  ifcount 26 
	  	{
		  	move MECH2FALLVEL geth getv faceplayerslow
		  	action AMECH2FALL
		  	sound DUKE_JETPACK_OFF
	  	}
	ifmove MECH2FALLVEL
	{
	  iffloordistl 4 ai AIMECH2GETENEMY
    }
	  
	ifrnd 64 spawn NEWSMOKE
}

ifai AIMECH2GETENEMY
{
	ifactioncount 2 soundonce MECHSTOMP
	ifactioncount 4 { soundonce MECHSTOMP resetactioncount }
	
	ifcansee
	{
		ifrnd 6 ai AIMECH2THINK
	}
	else ifrnd 2 ai AIMECH2THINK
	
}

ifai AIMECH2FLYUP
{
	soundonce DUKE_JETPACK_IDLE
	ifp phigher
	{
		 ifmove MECH2LANDVEL
		   ifcount 26 move MECH2UPVEL seekplayer
		   
		 ifcount 52 resetcount
	}
	else
	ifcount 130 ifmove MECH2UPVEL
	{
		sound ROBOBOOST
		move MECH2LANDVEL seekplayer
	}
	
	iffloordistl 16 ifmove MECH2LANDVEL ai AIMECH2GETENEMY
	
	ifactioncount 8 ifcansee ifcanshoottarget
	{
		ifrnd 192 ifvarn currholo -1 setvarvar target currholo else
		getplayer[THISACTOR].i target
		state calczdist
		mulvar zdist 644
		ldist xydist THISACTOR target
		ifvare xydist 0 setvar xydist 1
		divvarvar zdist xydist
		sound MISSILE2
		ezshoot zdist HLROCKET
	    setthisprojectile[RETURN].extra 100
	    setthisprojectile[RETURN].trail SMALLEXPLOSION
		flash
		setactorvar[RETURN].target target
		setactorvar[RETURN].mtype 1
		resetactioncount
	}
	
}

ifai AIMECH2THINK
{
	ifactioncount 2 ifcanshoottarget
	{
		ifrnd 64 ai AIMECH2SHOOT1
		else
		{
			ifpdistl 3072 
			   ai AIMECH2SHOOT1
			else ifrnd 128
			  ai AIMECH2SHOOT2
			else
			{
			  ai AIMECH2JUMPENEMY
			  sound ROBOBOOST
		    }
		}
	}
	ifcount 130 ai AIMECH2GETENEMY
	
	ifp phigher ifrnd 8
	{
		ifceilingdistl 128 nullop
		else 
		{ 
			ai AIMECH2FLYUP 
			break
		}
	}
}

ifaction AMECH2LYINGDEAD nullop
else
{ 
	ifpdistl 1024
	  ifcansee
	    ifp palive
	      ifvare superkicking 0
	{ 
		addphealth -2
		palfrom 40 63
	} 
}

ifai AIMECH2SHOOT2
{
	ifactioncount 2	
	{
		state dronedev_shoot
		resetactioncount
	}
	ifvarvarn target currholo
	{
		ifcansee nullop else ifcount 26 ai AIMECH2GETENEMY
	}
	ifcount 130 ai AIMECH2GETENEMY
} 

ifai AIMECH2SHOOT1
{
	ifactioncount 2	
	{
		state aimatholobot
		ifvare target -1
		{
			getplayer[THISACTOR].i target
			ldist xydist THISACTOR target
		}
		
		state calczdist
		addvar zdist 3072
		shiftvarl zdist 8
		ifvare xydist 0 setvar xydist 1
		divvarvar zdist xydist
		sound SHOTGUN_FIRE 
		ifvare holosphere 0 setvar tilenum SHOTSPARK1 else setvar tilenum SLOWBULLET
		zshootvar zdist tilenum
		zshootvar zdist tilenum
		zshootvar zdist tilenum
		zshootvar zdist tilenum
		zshootvar zdist tilenum
		zshootvar zdist tilenum
		zshootvar zdist tilenum
		sound SHOTGUN2 
		flash
		resetactioncount
	}
	ifcansee nullop else ifrnd 6 ai AIMECH2GETENEMY
	ifcount 130 ai AIMECH2GETENEMY
} 


ifhitweapon state mech2hitstate


enda

action SPIDERSTAND 0 1 5 1 10
action SPIDERWALK -5 3 5 1 6
action SPIDERSHOOT 10 1 5 1 20
action SPIDERFLIP -11 6 1 1 5
action SPIDERDIE 15 6 1 1 20

move SPIDERVELS 96
move SPIDERCHARGEVELS 160
move SPIDERSHRUNKVELS 24
move SPIDERUP 0 -160
move SPIDERSTOPPED


ai AISPIDERWAIT SPIDERSTAND SPIDERSTOPPED geth
ai AISPIDERSEEK SPIDERWALK SPIDERVELS seekplayer
ai AISPIDERSHOOT SPIDERSHOOT SPIDERSTOPPED faceplayerslow
ai AISPIDERCHARGE SPIDERWALK SPIDERCHARGEVELS faceplayer
ai AISPIDERSUFFER SPIDERFLIP SPIDERSTOPPED geth
ai AISPIDERDYING SPIDERDIE SPIDERSTOPPED geth
ai AISPIDERFLIPUP SPIDERFLIP SPIDERUP getv
ai AISPIDERFLIPDOWN SPIDERFLIP SPIDERSTOPPED geth
ai AISPIDERFROZEN SPIDERSTAND SPIDERSTOPPED geth
ai AISPIDERSHRUNK SPIDERWALK SPIDERSHRUNKVELS fleeenemy
ai AISPIDERJUMP SPIDERSTAND SPIDERCHARGEVELS jumptoplayer

state spidshootstate

ifcount 20
{
	ifspritepal 2
	{
		sound PRED_ATTACK
		shoot FIRELASER
		resetcount
	}
	else ifspritepal 8 
	{
		shoot ACIDBULLET
		sound DART_FIRE
		resetcount
	}
	else ifspritepal 1
	{
		ifphealthl 2
		{
			sound PRED_ATTACK
			shoot FIRELASER
		} else
		{
			shoot FREEZEBLAST
			sound CAT_FIRE
		}
		resetcount
	}
	else ifspritepal 4
	{
		shoot HEALBOLT
		sound RECO_ATTACK
		resetcount
	}
}

ends

spritenoshade SPIDERX
spriteshadow SPIDERX

useractor notenemy SPIDERX 25

ifvarg menutoggle 0 break
ifvare hammo2 0 fall // don't fall if on the ceiling
state monsterai
ifvarn mtype 0 setvar immunity 0

ifvare goggles 0 ifvare mtype 0 cstat 32768 else
ifai AISPIDERSHRUNK cstat 0 else
ifai AISPIDERSUFFER cstat 265 else
{
	cstat 257
	ifvare hammo2 2 cstator 8
}

getactor[THISACTOR].htextra temp
ifvarg temp 0
{
	getactor[THISACTOR].htpicnum tilenum
	ifspritepal 2 ifvare tilenum FLAMETHROWER setactor[THISACTOR].htextra -1
	ifspritepal 1 ifvare tilenum FREEZEBLAST setactor[THISACTOR].htextra -1
	ifvare goggles 0 ifvare mtype 0 setactor[THISACTOR].htextra -1
}

ifai 0
{
	ai AISPIDERJUMP
	sizeat 36 36
	// cstat 257
	setvar mval EGGVAL
	state difficulty
}

ifai AISPIDERSHRUNK
{
  ifcount SHRUNKDONECOUNT
  {
    ai AISPIDERSEEK
    // cstat 257
  }
  else
    ifcount SHRUNKCOUNT
      sizeto 36 36 
  else
    state genericshrunkcode
  break
}

ifai AISPIDERFROZEN

{
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
       ifvare superkicking 0
        pkick

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

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
        break

      state checkdart
      lotsofglass 30
      sound GLASS_BREAKING
      addkills 1
      state dropcoins
      state addscore
      state clearlists
      killit
    }
    break
}

ifvare hammo2 2
{
	// ifvare goggles 1 cstat 265 // just in case
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].sectnum mysector
	getceilzofslope mysector x y z // z is the return var
	addvar z 4096
	setactor[THISACTOR].z z
	setvar temp 0
	ifvare goggles 1 setvar temp 1
	ifvarn mtype 0 setvar temp 1
	ifvare temp 1
	{
		ifpdistg 4096
		{
			getplayer[THISACTOR].i spriteid
			ldist xydist THISACTOR spriteid
			ifvarl xydist 1560
			{
				setvar hammo2 0
				ai AISPIDERFLIPDOWN
			}
		}
		ifbulletnear
		{
			setvar hammo2 0
			ai AISPIDERFLIPDOWN
		}
	}
	
}

ifai AISPIDERDYING
{
	ifactioncount 6 killit
	break
}

ifai AISPIDERSUFFER
{
	strength 0
	ifvare holoweap 1
	{
		action SPIDERWALK
		// cstat 265
		count 13
		setactor[THISACTOR].htextra 10
		setactor[THISACTOR].htpicnum RADIUSEXPLOSION
		sound SQUISHED
	}
	
	ifaction SPIDERFLIP
	{
		
		ifactioncount 6
		{
			// cstat 265
			action SPIDERWALK
			resetcount
		}
		break
	}
	
	ifcount 12
	  ifhitweapon
	{
		state checkdart
		addkills 1
		state dropcoins
		state clearlists
		state addscore
	    ai AISPIDERDYING
		guts JIBS3 2
		guts JIBS4 3
		guts JIBS5 2
		guts JIBS6 3
    }
	ifcount 208
	{
	  ai AISPIDERSEEK
	  // cstat 257
    }
	break
}
ifvare goggles 1 state setholotarg else
ifvarn mtype 0 state setholotarg

ifhitweapon
{
	sound SPIDERPAIN
	state checkdart
	ifwasweapon SHRINKSPARK
    {
    	sound ACTOR_SHRINKING
    	ai AISPIDERSHRUNK
    	cstat 0
    	setvar hammo2 0
    	break
    }
	ifvarg hammo2 0
	{
		setvar hammo2 0
		ai AISPIDERFLIPDOWN
	}
	ifai AISPIDERWAIT ai AISPIDERSEEK
	ifdead
	{
		ifwasweapon FREEZEBLAST
		{
			ifspritepal 1 nullop else
			{
				spritepal 1
				// cstat 257
				setvar hammo2 0
				ai AISPIDERFROZEN
				sound SOMETHINGFROZE
				break
			}
		}
		// cstat 257
		ai AISPIDERSUFFER
		ifwasweapon RPG setvar holoweap 1
		ifwasweapon RADIUSEXPLOSION setvar holoweap 1
		break
	}
}

ifai AISPIDERSHOOT
{
	state spidshootstate

	ifcanshoottarget nullop else ai AISPIDERSEEK
	ifpdistg 4096 ai AISPIDERSEEK
	ifvare goggles 0 ai AISPIDERSEEK else
	ifvarn mtype 0 ai AISPIDERSEEK
}

ifai AISPIDERCHARGE
{
	ifvarn hammo2 0
	{
		setvar hammo2 0
		ai AISPIDERFLIPDOWN
		break
	}
	ifpdistl 1024
	{
		addkills 1
		state dropcoins
		state clearlists
		state addscore
	    ai AISPIDERDYING
		guts JIBS3 2
		guts JIBS4 3
		guts JIBS5 2
		guts JIBS6 3
		hitradius 2048 15 25 40 60
		spawn EXPLOSION2
		sound PIPEBOMB_EXPLODE
		break
	}
	ifnotmoving ifcount 12 iffloordistl 8 ai AISPIDERJUMP else
	ifcount 52 ai AISPIDERWAIT
}

ifai AISPIDERJUMP
	ifcount 8 ai AISPIDERSEEK


ifai AISPIDERWAIT
{
	 ifoutside 
	 {
		 ifvarn hammo2 0
		 {
			 setvar hammo2 0
			 ai AISPIDERFLIPDOWN
			 break
		 }
	 }
	    
     // hammo2 is 1 if the spider is on the ceiling, 0 otherwise
	 else ifvare hammo2 0
	    iffloordistl 8
	       	 ifrnd 6
     {
	     ifgapzl 320
	     {
		     ifgapzl 48 nullop else
		     {
			     setvar hammo2 1
			     ai AISPIDERFLIPUP
	     		 break
     		 }
 		 }
	 }    
    
	setvar temp 0
	ifcount 26 
	{
		ifvare goggles 1 setvar temp 1
		ifvarn mtype 0 setvar temp 1
	}
	ifvare temp 1
	{
		ifcansee
		    move SPIDERVELS faceplayer
		ai AISPIDERSEEK
		
	}
}


ifai AISPIDERFLIPUP
{
	ifaction SPIDERFLIP
	{
		ifactioncount 6
		{
			action SPIDERSTAND
			// cstat 265
			setvar hammo2 2
		}
	}
	
	ifceilingdistl 48
	{
		setvar hammo2 2
		ai AISPIDERWAIT
	}
    
}

ifai AISPIDERFLIPDOWN
{
	
	ifactioncount 6
	{
		// cstat 257
		ai AISPIDERSEEK
	}
	
}

ifai AISPIDERSEEK
{
	ifvare hammo2 0 ifnotmoving ifcount 12 iffloordistl 8
	{
		ai AISPIDERJUMP
		break
	}
	
	setvar temp 0
	ifvare goggles 1 setvar temp 1
	ifvarn mtype 0 setvar temp 1
    ifp palive
      	ifcanshoottarget
        	ifcount 26
        		ifvare temp 1
        		{
	        			ifspritepal 0 
	        			{
		        			ifpdistl 6144 ai AISPIDERCHARGE
	        			}
	        			else
	        			ifpdistl 3072
        				  ai AISPIDERSHOOT
    			}
        				 		
     else
  
     ifcount 52
     	ifrnd 32
     		ai AISPIDERWAIT		
}


enda

state decalcode

ifmove 0
{
	move INIT
	insertspriteq
}

ends


state fitsector

ifvare mysector -1 break

getsector[mysector].wallptr wallpoint // get the firstwall of the sector
getsector[mysector].wallnum numwalls // get the number of walls in the sector
setvar currwall 0
ifvarl numwalls 1 break
   		
whilevarvarn currwall numwalls
{
	getwall[wallpoint].x hitx
	getwall[wallpoint].y hity
	state pythagoras
	ifvare currwall 0 setvarvar xydist2 xydist else
	ifvarvarl xydist xydist2 setvarvar xydist2 xydist
	addvar wallpoint 1 // next wall in sector
	addvar currwall 1
}
// xydist is now the shortest distance between decal and any wall point in the sector

ifvarl xydist2 768
{
	divvar xydist2 9
	getactor[THISACTOR].xrepeat digx
	ifvarvarl xydist2 digx
	setactor[THISACTOR].xrepeat xydist2
	setactor[THISACTOR].yrepeat xydist2
	ifvarl xydist2 12 killit
}

setvar botclip 0
setvarvar mx x
addvar mx 128
getactor[THISACTOR].ang angvar
getactor[THISACTOR].z z
setvar mtype 0
whilevarn botclip 8
{
	rotatepoint x y mx y angvar hitx hity
	state pythagoras
	updatesectorz hitx hity z temp
	ifvarvarn temp mysector 
	{ 
		getflorzofslope temp hitx hity mz
		subvarvar mz z
		ifvarg mz 256
		{
			setvar botclip 7 
			setvar mtype 1
		}	
	}
	
	addvar mx 256 // checking further out
	rotatepoint x y mx y angvar hitx hity
	subvar mx 256
	state pythagoras
	updatesectorz hitx hity z temp
	ifvarvarn temp mysector 
	{
		getflorzofslope temp hitx hity mz
		subvarvar mz z
		ifvarg mz 256
		{
			setvar botclip 7 
			setvar mtype 2
		}
	}
		
	addvar angvar 256
	addvar botclip 1
}

ifvare mtype 1 killit
ifvare mtype 2
{
	getactor[THISACTOR].xrepeat x
	ifvarg x 16 { divvar x 2 ifvarl x 12 setvar x 12 setactor[THISACTOR].xrepeat x }
	getactor[THISACTOR].yrepeat y
	ifvarg y 16 { divvar y 2 ifvarl y 12 setvar y 12 setactor[THISACTOR].yrepeat y }
}



ends

useractor notenemy SCORCH 0

ifspritepal 3 break

ifmove 0
{
	move INIT
	ifvarn initx 0 sizeat 16 16 else
	sizeat 64 64
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].sectnum mysector
	ifvare lotag 1 
	{
		ifonwater killit else
		state fitsector 
		break 
	}
	ifvare hitag 1 { state fitsector break }
	getwall[target].nextsector hammo2
	
	ifvarn hammo2 -1
	{
    	getsector[hammo2].lotag temp
    	switch temp
    	case 16    // ELEVATOR PLATFORM DOWN
		case 17    // ELEVATOR PLATFORM UP
		case 18    // ELEVATOR DOWN
		case 19    // ELEVATOR UP
    	case 20    // CEILING DOOR
	    case 21    // FLOOR DOOR
	    case 22    // SPLIT DOOR
	    case 23    // SWING DOOR
	    case 26    // SPLIT STAR TREK DOOR
	    case 28    // DROP FLOOR
	    case 29    // TEETH DOOR
	    case  9    // STAR TREK DOORS
	    case 25    // SLIDE DOOR
	    case 27    // BRIDGE
	    case 30    // ROTATE RISE BRIDGE
	    case 31    // 2 WAY TRAIN
	    killit
	    break
	    endswitch
	}
	
	getsector[hammo2].floorz initz
	getsector[hammo2].ceilingz inity
	// calculate distance to wallpoint
	// calculate distance to wallpoint2
	// if either ditance is short, shrink accordingly
	setvar xydist2 8192
	getwall[target].x hitx
	getwall[target].y hity
	state pythagoras	
	setvarvar xydist2 xydist
	getwall[target].point2 currwall
	getwall[currwall].x hitx
	getwall[currwall].y hity
	state pythagoras
	
	// we need to check angle to the next wallpoint before we decide that this is a distance to worry about
	getwall[currwall].point2 wallpoint
	getwall[wallpoint].x digx
	getwall[wallpoint].y digy
	subvarvar hitx digx
	subvarvar hity digy
	getangle tempb digx digy
    getactor[THISACTOR].ang angvar
    getincangle tempd angvar tempb
    ifvarl tempd 0 mulvar tempd -1
    ifvarg tempd 128
	ifvarvarl xydist2 xydist setvarvar xydist xydist2
	
	ifvarl xydist 768
	{
		divvar xydist 7
		getactor[THISACTOR].xrepeat digx
		ifvarvarl xydist digx
		setactor[THISACTOR].xrepeat xydist
		ifvarl xydist 12 killit
	}
	
	ifvarn hammo2 -1
	{
		getsector[hammo2].floorz mz
		getactor[THISACTOR].z z
		ifvarvarl mz z
		{
			subvarvar z mz
			ifvarl z 6144
			{
				shiftvarr z 7
				getactor[THISACTOR].yrepeat y
				ifvarvarl z y
				setactor[THISACTOR].yrepeat z
				ifvarl z 12 killit
			}
		}
		getsector[hammo2].ceilingz mz
		ifvarvarg mz z
		{
			subvarvar mz z
			shiftvarr mz 7
			getactor[THISACTOR].yrepeat y
			ifvarvarl mz y
			setactor[THISACTOR].yrepeat mz
		}
				
	}

}

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

ifvarn target -1
{
	getwall[target].shade shade
	ifvarl shade 0 setvar shade 0
	addvar shade 5
	setactor[THISACTOR].shade shade


 getwall[target].nextsector hammo2
 ifvarn hammo2 -1
 {
	 getsector[hammo2].floorz temp
	 ifvarvarn temp initz
	 {
		 subvarvar temp initz
		 ifvarl temp 0 mulvar temp -1
		 ifvarg temp 2048
		 killit
	 }
	 getsector[hammo2].ceilingz temp
	 ifvarvarn temp inity 
	 {
		 subvarvar temp inity
		 ifvarl temp 0 mulvar temp -1
		 ifvarg temp 2048
		 killit
	 }
 }
}
enda

useractor notenemy CONCRETEHOLE2 0
state decalcode
enda

useractor notenemy ELECTRONICHOLE 0
state decalcode
enda

useractor notenemy METALHOLE 0
state decalcode
enda

useractor notenemy ORGANICHOLE 0
state decalcode
enda

useractor notenemy WOODHOLE 0
state decalcode
enda

useractor notenemy ROCKETHALO 0

ifvare countvar 0
{
	
	ifvare myspawner -1 sizeat 32 32
	else
	{
		getactor[myspawner].xrepeat x
		mulvar x 2
		setactor[THISACTOR].xrepeat x
		getactor[myspawner].yrepeat y
		mulvar y 2
		setactor[THISACTOR].yrepeat y
	}
}
cstat 642

ifcount 1 
	killit 
	
enda

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

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

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

state recondead
  addkills 1
  debris SCRAP1 16
  debris SCRAP2 8
  debris SCRAP3 14
  spawn EXPLOSION2
  spawn BURNING
  sound RPG_EXPLODE
  espawn PIGCOP
  hitradius 1560 5 10 15 20
  ifvarg mval 0 { state dropcoins state addscore }
  killit
  break
ends

state recondying

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

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

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

ends

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

state reconshrunkstate
  ifcount 24
    killit
  else
    sizeto 1 1
ends

state checkreconnearplayer

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

ends

state recongetstate

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

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

  }

ends

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

useractor enemy RECONDP 130

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

ifvare target -1 ifrnd 4 ifpdistl 16384
{
	ifcanshoottarget 
	{
	    getplayer[THISACTOR].i target
    }
}
ifvare target -1 ifvarn currholo -1 ifrnd 8 setvarvar target currholo
ifvarn target -1
{
	ifrnd 8 state checksight
	ifvarn target -1
	{
		state gradualturn
		dist xydist THISACTOR target
		ifvare xydist 0 setvar xydist 1
		
		setvar myspawner -1 // no locator set
		getactor[THISACTOR].z z
		getactor[target].z mz
		setvarvar zdist mz
		subvarvar zdist z
		ifvarl zdist 0 mulvar zdist -1
	}
	
}
else
{
	ifvarg locators 0
	{
		ifmove RECONRUNVELS move RECONPATROLVELS geth
		getactorvar[lotag].locatorids myspawner
		canseespr THISACTOR myspawner temp
		ifvare temp 1
		{
			ldist xydist THISACTOR myspawner
			setvarvar temp lotag
			addvar temp 1
			ifvarvarg temp locators setvar temp 0
			ifvarl xydist 512 setvarvar lotag temp else
			{
				getactorvar[temp].locatorids spriteid
				ldist xydist2 THISACTOR spriteid
				ifvarvarl xydist2 xydist setvarvar lotag temp
			}
			ifvarvarn lotag temp
			{
				setvarvar target myspawner
				state gradualturn
				setvar target -1
				getactor[myspawner].z mz
				getactor[THISACTOR].z z
				subvarvar mz z
				shiftvarr mz 3
				movesprite THISACTOR 0 0 mz CLIPMASK0 RETURN
			}
		}
		else
		{
			addvar lotag 1
			ifvarvarg lotag locators setvar lotag 0
			
		}
	}
	
}


 state monsterai
 state setholotarg

state checkreconnearplayer
addvar hammo4 1 // used as a counter

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

    soundonce RECO_ROAM

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

  else
    ifai AIRECONWAIT
  {
    ifcount 14
      ifvarn target -1
    {
      addvar holoweap 1
      ifvarg holoweap 52
       {
	    ifrnd 128 setvar target -1
        setvar holoweap 0
        setvar hweapcount 0
        ifvarvarg z mz
          { ai AIRECONGETUP ifvarg hammo4 51 setvar botclip 1 }
        else { ai AIRECONGETE ifvarg hammo4 51 setvar botclip 1 }
        }
      else
       {
        ifvare holoweap 2
        {
	        sound RPG_SHOOT
			shoot MORTER	
        }
        else ifvarg holoweap 19
        {
	         ldist xydist THISACTOR target
	         ifvare xydist 0 setvar xydist 1
	         state calczdist
	         subvar zdist 8192
             addvar hweapcount 1
             ifvarg hweapcount 2
             {
	             flash
	             setvar hweapcount 0
                 // shoot bullets
				 sound PISTOL2
                 state calczdist
                 shiftvarl zdist 8
                 ifvare xydist 0 setvar xydist 1 
                 divvarvar zdist xydist
                 zshoot zdist SHOTSPARK1
                 zshoot zdist SHOTSPARK1
             }
         }
        }
    }
    else ifcount 52 ai AIRECONGETE
  }
  else
    ifai AIRECONGETE
      state recongetstate
  else
    ifai AIRECONGETUP
      state recongetstate
  else
    ifai AIRECONPULLBACK
  {
    ifcount 32
    ai AIRECONWAIT
  }
  else
    ifai AIRECONHIT
  {
    ifcount 8
      ai AIRECONWAIT
  }
  else
    ifai AIRECONSHRUNK
      state reconshrunkstate
  else
    ifai AIRECONDODGE
      state recondodgestate
  else
    ifai AIRECONDODGEUP
      state recondodgestate

  ifhitweapon
    state checkreconhitstate

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

enda

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

useractor notenemy RAINSPRITE 0

ifvarg raining 0 fall 
ifinwater killit
ifaction 0
{
	ifoutside nullop else killit
	ifinspace killit
	setactor[THISACTOR].mdflags 2
	ifvarg raining 0
	{
		action RAINFRAME
		sizeat 10 15
	}
	else
	{
		getactor[THISACTOR].z z
		action SNOWFRAME
		// move SNOWFALL getv
		ifrnd 128 cstator 4
		ifrnd 128 cstator 8
		randvar x 3 addvar x 3
		randvar y 3 addvar y 3
		setactor[THISACTOR].xrepeat x
		setactor[THISACTOR].yrepeat y
		addvarvar x y // between 6 and 12
		setvar mtype 1040
		mulvar x 32
		subvarvar mtype x
	}

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


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

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

enda

move BOULDER

useractor notenemy ROLLBOULDER 300


ifmove 0
{
	ifcansee nullop else break
	setvar holoweap NEWSCRAP3
	move BOULDER
	sizeat 40 40
	cstat 257
	clipdist 100
	setactor[THISACTOR].mdzoff -10240
	setvar initx 64 // speed
}
fall
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getplayer[THISACTOR].posx hitx
getplayer[THISACTOR].posy hity
subvarvar hitx x
subvarvar hity y
getangle angvar hitx hity
getactor[THISACTOR].ang tempb

getincangle tempd angvar tempb
ifvarg tempd -448 ifvarl tempd 448
ifpdistl 1408
  ifcansee
   ifcanshoottarget
     ifp palive
       ifmove BOULDER
        ifvarl initx 256
{
	addphealth -1000
	sound SQUISHED
}

ifmove BOULDER
{
	soundonce EARTHQUAKE
	ifpdistl 4096 quake 26
	getactor[THISACTOR].pitch temp
	switch initx
	case 64 addvar temp 64 break
	case 128 addvar temp 32 break
	case 256 addvar temp 16 break
	endswitch
	setactor[THISACTOR].pitch temp
	getactor[THISACTOR].ang angvar
	cos xvel angvar
	sin yvel angvar  
	divvarvar xvel initx
	divvarvar yvel initx
	setvar zvel 0
	movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN
	ifvarn RETURN 0 
	{
        addvar RETURN 16384
        ifvarl RETURN 16384
        ifvarg RETURN -1
        {
	        setactor[RETURN].htextra 1000
	        setactor[RETURN].htpicnum RADIUSEXPLOSION
	        setactor[RETURN].htowner THISACTOR
        }
         else
        {
	        addvar hammo3 768
	        randvar temp 512
	        addvarvar hammo3 temp
	        setactor[THISACTOR].ang hammo3
			mulvar initx 2
			ifvarg initx 256 move INIT
		}
	}
}



getactor[THISACTOR].ang hammo3
ifhitweapon
{
	state shootscrap
	setactor[THISACTOR].ang hammo3
	ifdead
	{
		state breakboulder
		// temporary
		sound PIPEBOMB_EXPLODE
		spawn EXPLOSION2
		killit
	}
}

enda

eventloadactor SKYCAR_CRASHED 
{
	getactor[THISACTOR].lotag lotag 
	setactor[THISACTOR].lotag 0 
	setvar ONCAR 1
}
enda

action SKYCARIDLE 0 1 1 1 1
action SKYCARTHRUST 1 1 1 1

move CARMOVE 384 0

useractor notenemy SKYCAR_CRASHED 0

ifmove 0
{
	action SKYCARTHRUST
	setvar ONCAR 1
	move CARMOVE geth
	sizeat 64 64
	cstat 0
	clipdist 64
	setactor[THISACTOR].pitch 64
}

ifmove CARMOVE
{
	//cstat 2
	quake 26
	getactorvar[lotag].locatorids myspawner
	
	ldist xydist THISACTOR myspawner
	ifvare lotag 0
	{
		ifvarl xydist 512
		{
			action SKYCARIDLE
			getplayer[THISACTOR].i spriteid
			setactor[spriteid].cstat 257
			getactor[myspawner].x x
			getactor[myspawner].y y
			setactor[THISACTOR].x x
			setactor[THISACTOR].y y
			getactor[myspawner].z z
			setactor[THISACTOR].z z
			getactor[myspawner].sectnum mysector
			changespritesect THISACTOR mysector
			setplayer[THISACTOR].posx x
			setplayer[THISACTOR].posy y
			setplayer[THISACTOR].ammo_amount 7 0
			setplayer[THISACTOR].gotweapon 7 0
			setplayer[THISACTOR].curr_weapon 0
			subvar z 8192
			setplayer[THISACTOR].posz z
			setplayer[THISACTOR].cursectnum mysector
			setvar ONCAR 0
			globalsound GENERIC_AMBIENCE23
			wackplayer
			wackplayer
			wackplayer
			sound DUKE_LAND_HURT
			move INIT
			cstat 1
			spawn BIGEXPLOSION
			setvar countvar 0
			getactor[THISACTOR].ang holoweap
			whilevarn countvar 32
			{
				addvar countvar 1
				randvar zdist 8192 subvar zdist 10240 
				ifrnd 128 ezshoot zdist NEWSCRAP1 else ezshoot zdist NEWSCRAP6
				setthisprojectile[RETURN].trail SMALLSMOKE
				randvar temp 128
				addvar temp 160
				setthisprojectile[RETURN].vel temp
				addvar holoweap 64
				setactor[THISACTOR].ang holoweap
			}
			ifrnd 128 espawn BURNING else espawn BURNING2
			setactorvar[RETURN].mtype 2
			espawn CAR_BLOCKER
			setactorvar[RETURN].myspawner THISACTOR
			getactor[THISACTOR].roll temp
			ifvarl temp -64 setactor[THISACTOR].roll -64 else
			ifvarg temp 64 setactor[THISACTOR].roll 64
			break
		}
		setvarvar target myspawner
		state gradualturn
		// state aimattarget
		setvar target -1
		getactor[myspawner].z mz
		getactor[THISACTOR].z z
		subvarvar mz z
		shiftvarr mz 3
		movesprite THISACTOR 0 0 mz CLIPMASK0 RETURN
		ifvarg mz 0
		{
			getactor[THISACTOR].z digz
			ifvarvare z digz // failure to move down
			fall
		}
	} else
	{
		setvarvar temp lotag
		subvar temp 1
		
		ifvarl xydist 512 setvarvar lotag temp
		else
		{
			getactorvar[temp].locatorids spriteid
			ldist xydist2 THISACTOR spriteid
			ifvarvarl xydist2 xydist setvarvar lotag temp
		}
		ifvarvarn lotag temp
		{
			setvarvar target myspawner
			state gradualturn
			// state aimattarget
			setvar target -1
			getactor[myspawner].z mz
			getactor[THISACTOR].z z
			subvarvar mz z
			shiftvarr mz 3
			movesprite THISACTOR 0 0 mz CLIPMASK0 RETURN
			ifvarg mz 0
			{
				getactor[THISACTOR].z digz
				ifvarvare z digz // failure to move down
				fall
			}
		}
	}
	setplayer[THISACTOR].over_shoulder_on 0
	setplayer[THISACTOR].curr_weapon 7
	setplayer[THISACTOR].ammo_amount 7 99
	setplayer[THISACTOR].gotweapon 7 1
	setplayer[THISACTOR].poszv 0
	getactor[THISACTOR].ang angvar
	setplayer[THISACTOR].ang angvar
	getplayer[THISACTOR].i spriteid
	setactor[spriteid].htextra -1
	setactor[spriteid].htpicnum -1
	getactor[spriteid].extra temp
	ifvarl temp MAXPLAYERHEALTH setactor[spriteid].extra MAXPLAYERHEALTH
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	
	addvar angvar 1024
	setvarvar mx x
	addvar mx 1024
	rotatepoint x y mx y angvar x y

	setplayer[THISACTOR].posx x
	setplayer[THISACTOR].posy y
	getactor[THISACTOR].z z
	subvar z 12288
	setplayer[THISACTOR].posz z
	updatesectorz x y z mysector
	setplayer[THISACTOR].cursectnum mysector
	setactor[spriteid].sectnum mysector

	state randexplosions
	state recontilt
	
	break
}

fall

ifcount 52
{
	// spawn smoke etc.
	ifrnd 128 
	{
		getactor[THISACTOR].z initz
		subvar initz 6144
		getactor[THISACTOR].ang angvar
		addvar angvar 1024
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		setvarvar mx x
		addvar mx 844
		rotatepoint x y mx y angvar x y
		espawn NEWSMOKE
		setactor[RETURN].z initz
		setactor[RETURN].x x
		setactor[RETURN].y y
	}
		
	resetcount
}



enda

eventloadactor SKYCAR_FLY
{
	getactor[THISACTOR].lotag lotag 
	setactor[THISACTOR].lotag 0 
} 
enda

move CARFLY1 256 0
move CARFLY2 384 0
move CARFLY3 512 0
move CARFLY4 640 0
move CARFLY5 768 0
move CARFLY6 896 0
move CARFLY7 1024 0

useractor notenemy CAR_BLOCKER 0

ifmove 0
{
	cstator 32768
	sizeat 64 32
	cstator 257
	clipdist 172
}
ifvarn ONCAR 0 cstat 32768
else
{
	cstator 257
}
getactor[myspawner].x x
getactor[myspawner].y y
getactor[myspawner].z z
getactor[myspawner].sectnum mysector
getactor[myspawner].ang angvar
setactor[THISACTOR].ang angvar

setactor[THISACTOR].x x
setactor[THISACTOR].y y
setactor[THISACTOR].z z

updatesectorz x y z mysector
changespritesect THISACTOR mysector

getactorvar[myspawner].hammtarg hammtarg
ifvare hammtarg 1 // owner is available for boarding
{
	getactorvar[myspawner].monstatus monstatus
	ifvare monstatus 1
		ifp palive
			ifp pfacing
	  			ifpdistl 1792
	  				ifhitspace
	  				{
		  				setplayer[THISACTOR].ang angvar
		  				setplayer[THISACTOR].horiz 100
	  					setactorvar[myspawner].countvarc 1
	  					globalsound BONUS_SPEECH4
  					}
}

enda

state movespriteoverride
	
getactor[THISACTOR].z digz

updatesectorz x y digz temp

ifvarn mysector -1 ifvare temp -1 { setactor[THISACTOR].z z changespritesect THISACTOR mysector }
else
{
	ifvarg mz 0
	{	
		ifvarvare z digz // failure to move down
		fall
	}
	ifvarl mz 0
	{
		ifvarvare z digz // failure to move up
		{
			getceilzofslope mysector x y temp
			ifonwater { setvarvar temp z subvar temp 8192 subvar z 6144 }
			subvar z 1024
			ifvarvarl temp z setactor[THISACTOR].z z else
			addvar z 1024
		}
	}
}
ends

state collision

ifrnd 128
sound SKYCAR_COLLIDE else
sound SKYCAR_COLLIDE2

setvar barrierup 1

ifmove CARFLY1 { addphealth -5 } else
ifmove CARFLY2 { addphealth -10 move CARFLY1 geth } else
ifmove CARFLY3 { addphealth -15 move CARFLY2 geth } else
ifmove CARFLY4 { addphealth -20 move CARFLY3 geth } else
ifmove CARFLY5 { addphealth -25 move CARFLY4 geth } else
ifmove CARFLY6 { addphealth -30 move CARFLY5 geth } else
ifmove CARFLY7 { addphealth -40 move CARFLY6 geth }

ends

useractor notenemy SKYCAR_FLY 0

ifmove 0
{
	action SKYCARIDLE
	sizeat 64 64
	cstat 0
	clipdist 64
	setvar monstatus 1
	move INIT
	espawn CAR_BLOCKER
	setactorvar[RETURN].myspawner THISACTOR
}

ifvare countvarc 1 // player just got in, using the blocking actor
{
	setvar barrierup 1
	setvar countvarc 0
	getplayer[THISACTOR].ammo_amount 7 hammo7
	getplayer[THISACTOR].gotweapon 7 mtype
	setplayer[THISACTOR].over_shoulder_on 1
	setvar ONCAR 2
	move CARFLY1 geth
	action SKYCARTHRUST
	cstat 0
	resetcount
}

ifmove INIT
{
	setvar hammtarg 1
	ifpdistl 6144
	  ifcansee
	    ifvare holoweap 0
	      ifcount 26
	{
		globalsound GENERIC_AMBIENCE15
		setvar holoweap 1
	}
	fall
		
	break
}
else setvar hammtarg 0

ifvarn ONCAR 0
{
	soundonce TFORCEGOAT
	addvar countvar 1
	ifvarg countvar 52 ifvarand bits 8192
	{
		espawn BIGBOMB
		sound RPG_SHOOT
		setvar temp 0
		ifmove CARFLY2 setvar temp 1
		ifmove CARFLY3 setvar temp 2
		ifmove CARFLY4 setvar temp 3
		ifmove CARFLY5 setvar temp 4
		ifmove CARFLY6 setvar temp 5
		ifmove CARFLY7 setvar temp 6
		setactorvar[RETURN].mtype temp
		setvar countvar 0
	}
	
	ifcount 12
	{
		ifvarand extbits 1
		{
			ifmove CARFLY1 { stopsound SKYCAR_JET1 move CARFLY2 geth } else
			ifmove CARFLY2 { stopsound SKYCAR_JET2 move CARFLY3 geth } else
			ifmove CARFLY3 { stopsound SKYCAR_JET3 move CARFLY4 geth } else
			ifmove CARFLY4 { stopsound SKYCAR_JET4 move CARFLY5 geth } else
			ifmove CARFLY5 { stopsound SKYCAR_JET5 move CARFLY6 geth } else
			ifmove CARFLY6 { stopsound SKYCAR_JET6 move CARFLY7 geth } 
			resetcount
		}
		ifvarand extbits 2
		{
			ifmove CARFLY7 { stopsound SKYCAR_JET7 move CARFLY6 geth } else
			ifmove CARFLY6 { stopsound SKYCAR_JET6 move CARFLY5 geth } else
			ifmove CARFLY5 { stopsound SKYCAR_JET5 move CARFLY4 geth } else
			ifmove CARFLY4 { stopsound SKYCAR_JET4 move CARFLY3 geth } else
			ifmove CARFLY3 { stopsound SKYCAR_JET3 move CARFLY2 geth } else
			ifmove CARFLY2 { stopsound SKYCAR_JET2 move CARFLY1 geth }
			resetcount
		}
	}
	ifmove CARFLY1 soundonce SKYCAR_JET1 else
	ifmove CARFLY2 soundonce SKYCAR_JET2 else
	ifmove CARFLY3 soundonce SKYCAR_JET3 else
	ifmove CARFLY4 soundonce SKYCAR_JET4 else
	ifmove CARFLY5 soundonce SKYCAR_JET5 else
	ifmove CARFLY6 soundonce SKYCAR_JET6 else
	ifmove CARFLY7 soundonce SKYCAR_JET7
	
	stopsound CAT_FIRE
	ifvarand bits 4
	{
		setvar countvarb 6
		setplayer[THISACTOR].over_shoulder_on 0
		setvar hammo10 1
		cstator 514
	} else ifvare countvarb 0
	{
		ifvare hammo10 1
		{
			setplayer[THISACTOR].over_shoulder_on 1
			setvar hammo10 0
			cstat 0
		}
	}
	ifvarg countvarb 0 subvar countvarb 1
	
	getactor[THISACTOR].ang angvar
	getplayer[THISACTOR].ang temp
	
	getincangle tempd angvar temp
	
	ifvarg tempd -16 ifvarl tempd 16 nullop else
	{
		setvarvar tempb tempd
		shiftvarr tempb 2
		addvarvar angvar tempb
		setactor[THISACTOR].ang angvar
	}
	
	ifvarl tempd -128
	{
		setvarvar temp angvar
		subvar temp 128
		setplayer[THISACTOR].ang temp
	} else
	ifvarg tempd 128
	{
		setvarvar temp angvar
		addvar temp 128
		setplayer[THISACTOR].ang temp
	}
	
	ifvare dodge 0
	{
		ifvarand extbits 4 
		{ 
			setvar dodge 1
			 
		} else
		ifvarand extbits 8 
		{
			setvar dodge -1 
		}
	}
	ifvarn dodge 0
	{
		setvarvar temp dodge
		shiftvarl temp 6
		setactor[THISACTOR].roll temp
		ifvarg dodge 0 
		{
			addvar dodge 1
			ifvare dodge 32 
			{
				setvar dodge 0
				setactor[THISACTOR].roll 0
			}
		}
		ifvarl dodge 0
		{
			subvar dodge 1
			ifvare dodge -32
			{
				setvar dodge 0
				setactor[THISACTOR].roll 0
			}
		}
	}
	
	cos xvel angvar
    sin yvel angvar
  
    shiftvarr xvel 11
    shiftvarr yvel 11
     
    setvar zvel 0
    movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN
    
    ifvare RETURN 0 setvar barrierup -1
    else ifvare barrierup -1 state collision
    
    
	
	setvar mz 0
	
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].z z
	updatesectorz x y z mysector
	ifvare mysector -1 fall
	
	setvar mz 0
	getplayer[THISACTOR].horiz tempb
	subvar tempb 100
	mulvar tempb -4 // -1
	addvarvar mz tempb
	ifvarl mz -480 setvar mz -480
	ifvarg mz 480 setvar mz 480
	setvarvar digz mz
	ifvarn dodge 0 
	{
		getactor[THISACTOR].ang angvar
		ifvarl dodge 0 addvar angvar 512 else subvar angvar 512
		cos xvel angvar
		sin yvel angvar
		ifmove CARFLY7 setvar temp 29 else
		ifmove CARFLY6 setvar temp 30 else
	  	ifmove CARFLY5 setvar temp 32 else
	  	ifmove CARFLY4 setvar temp 40 else
	  	ifmove CARFLY3 setvar temp 48 else
	  	ifmove CARFLY2 setvar temp 56
	  	else setvar temp 64
		divvarvar xvel temp
		divvarvar yvel temp
	     
		setvar zvel 0
		movesprite THISACTOR xvel yvel zvel CLIPMASK0 RETURN
		
	}
	setactor[THISACTOR].pitch digz
	ifvarl mz 16 ifvarg mz -16 nullop else
	{
		ifvarg mz 16 subvar mz 16 else
		ifvarl mz -16 addvar mz 16
		
		ifvarn countvarb 0 shiftvarl mz 3 else
		ifmove CARFLY7 shiftvarl mz 5  else
		ifmove CARFLY6 mulvar mz 28  else
	  	ifmove CARFLY5 mulvar mz 24   else
	  	ifmove CARFLY4 mulvar mz 20  else
	  	shiftvarl mz 4
	  	
		// shiftvarl mz 5
		movesprite THISACTOR 0 0 mz CLIPMASK0 RETURN
		state movespriteoverride
	}

// ground collision code is buggy
// 	getflorzofslope mysector x y temp
// 	subvar temp 256
// 	ifvarvarg z temp ifvarg digz 16 ifvare barrierup -1 
// 	{ 
// 		state collision 
// 		setactor[THISACTOR].pitch -32 
// 		setplayer[THISACTOR].horiz 124 
// 	}
	
	ifvarand bits 1 setvar mz -6144
	ifvarand bits 2 setvar mz 6144
	ifvarn mz 0
	{
		movesprite THISACTOR 0 0 mz CLIPMASK0 RETURN
		state movespriteoverride
	}
	
	setplayer[THISACTOR].curr_weapon 7
	setplayer[THISACTOR].ammo_amount 7 99
	setplayer[THISACTOR].gotweapon 7 1
	setplayer[THISACTOR].poszv 0
	
	getactor[THISACTOR].ang angvar
	addvar angvar 1024
	setvarvar mx x
	addvar mx 768
	rotatepoint x y mx y angvar x y
	
	getplayer[THISACTOR].i spriteid
	setplayer[THISACTOR].posx x
	setplayer[THISACTOR].posy y
	
	
	getactor[THISACTOR].z z
	updatesectorz x y z mysector
	ifvarn mysector -1
	{
		getceilzofslope mysector x y temp
		ifonwater { setvarvar temp z subvar temp 1024 }
		ifvarvarg z temp
		{
			setvarvar digz z
			subvarvar digz temp
			// ifvarg digz 12288 subvar z 12288 else subvarvar z digz
			ifvarg digz 8192 subvar z 8192 else subvarvar z digz
			setplayer[THISACTOR].posz z
			setplayer[THISACTOR].cursectnum mysector
			setactor[spriteid].sectnum mysector
		}
	}
	
	ifp palive nullop else
	{
		fall
		iffloordistl 4 
		{
			stopsound TFORCEGOAT
			setvar ONCAR 0
			resetcount
			move INIT
		} else
		state randexplosions
		setvar monstatus 2
	}
	
	ifvare dodge 0
	state recontilt
	
	ifhitspace ifcount 6
	{
		stopsound TFORCEGOAT
		action SKYCARIDLE
		setactor[spriteid].cstat 257
		setplayer[THISACTOR].ammo_amount 7 hammo7
		setplayer[THISACTOR].gotweapon 7 mtype
		setplayer[THISACTOR].curr_weapon 0
		setplayer[THISACTOR].over_shoulder_on 0
		setvar ONCAR 0
		setvar countvar 0
		resetcount
		getactor[THISACTOR].ang holoweap
		setactor[THISACTOR].pitch 0
		break
	}
}

ifvare ONCAR 0 ifcount 78 move INIT

enda

useractor notenemy BIGBOMB 0

ifvare camerasprite -1 setvarvar camerasprite THISACTOR

ifmove 0
{
	setactor[THISACTOR].pitch 512
	sizeat 64 16
	ifvare mtype 1 move CARFLY1 geth
	ifvare mtype 2 move CARFLY2 geth
	ifvare mtype 3 move CARFLY3 geth
	ifvare mtype 4 move CARFLY4 geth
	ifvare mtype 5 move CARFLY5 geth
	ifvare mtype 6 move CARFLY6 geth
}

ifcount 14
{
	resetcount
	ifmove CARFLY6 move CARFLY5 geth else
	ifmove CARFLY5 move CARFLY4 geth else
	ifmove CARFLY4 move CARFLY3 geth else
	ifmove CARFLY3 move CARFLY2 geth else
	ifmove CARFLY2 move CARFLY1 geth else
	ifmove CARFLY1 move INIT
}

fall
spawn SMALLSMOKE
iffloordistl 8 ifpdistg 3072
{
	addvar countvar 1
	
	ifvare countvar 1
	{
		move INIT
		cstat 32768
		spawn BIGEXPLOSION
		sound PIPEBOMB_EXPLODE
		hitradius 5120 120 200 280 360
		setvar countvarb 0
		getactor[THISACTOR].ang holoweap
		whilevarn countvarb 36
		{
			addvar countvarb 1
			randvar zdist 8192 subvar zdist 6144 
			ifrnd 128 ezshoot zdist NEWSCRAP1 else ezshoot zdist NEWSCRAP6
			setthisprojectile[RETURN].trail SMALLSMOKE
			randvar temp 128
			addvar temp 256
			setthisprojectile[RETURN].vel temp
			addvar holoweap 170
			setactor[THISACTOR].ang holoweap
		}
		ifrnd 128 spawn BURNING else spawn BURNING2
	}
	else
	{
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		getactor[THISACTOR].z z
		randvar temp 4096
		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 EXPLOSION2
			ifrnd 160 sound BOOM
			else sound PIPEBOMB_EXPLODE	
			setactor[RETURN].x x
			setactor[RETURN].y y
			setactor[RETURN].z z
			espawn NEWSMOKE
			setactor[RETURN].x x
			setactor[RETURN].y y
			setactor[RETURN].z z
			
		}
		ifrnd 64 hitradius 5120 30 30 30 30
		ifvarg countvar 26 
		{
			setvar camerasprite -1
			killit
		}
	}
}

enda


useractor notenemy ICEBLOCK 100

ifmove 0
{
	clipdist 64
	ifspawnedby APLAYER sizeat 64 64
	cstator 257
	move INIT
}

ifhitweapon
{
	ifdead
	{
		lotsofglass 30
		killit
	}
}
		

enda

eventloadactor CAMERA1
getactor[THISACTOR].extra mtype
setactor[THISACTOR].extra -1
enda