// ATTRAND.CON

state setbeastpal
setvar pal 15
ifvarand monstflags 8192 { setvar pal 49 addvar mval 100 } else
ifvarand monstflags 256 setvar pal 10 else
ifvarand monstflags 64 setvar pal 17 else
ifvarand monstflags 32 setvar pal 12 else
ifvarand monstflags 16 setvar pal 21 else
ifvarand monstflags 8 setvar pal 23 else
ifvarand monstflags 4 setvar pal 16 else
ifvarand monstflags 2 setvar pal 14

ifspritepal 6 setactor[THISACTOR].httempang pal
else
{
	setactor[THISACTOR].httempang 6
	setactor[THISACTOR].pal pal
}
ends

state randomizestate

ifactor RESPAWN break


setvarvar temp randomize
subvar temp 2000
ifvarg temp 32000 setvar temp 32000
// 1% per level chance of double fire power
randvar tempb 100000
ifvarvarl tempb temp orvar monstflags 8

setvarvar temp randomize
subvar temp 3000
ifvarg temp 32000 setvar temp 32000
// 1% per level chance of attack variation 3
randvar tempb 100000
ifvarvarl tempb temp orvar monstflags 64
else
{
	setvarvar temp randomize
	subvar temp 1000
	ifvarg temp 32000 setvar temp 32000
	// 1% per level chance of attack variation 2
	randvar tempb 100000
	ifvarvarl tempb temp orvar monstflags 32
	else
	{
		setvarvar temp randomize
		ifvarg temp 36000 setvar temp 36000
		shiftvarl temp 1 // 2% per level chance of attack variation 1
		randvar tempb 100000
		ifvarvarl tempb temp orvar monstflags 16
	}
}

setvarvar temp randomize
addvar temp 4000
// 4% +1% per level
ifvarg temp 40000 setvar temp 40000
randvar tempb 100000
ifvarvarl tempb temp orvar monstflags 512

setvarvar temp randomize
addvar temp 5000
ifvarg temp 20000 addvar temp 20000 else
shiftvarl temp 1
ifvarg temp 70000 setvar temp 70000
randvar tempb 100000
ifvarvarl tempb temp orvar monstflags 2048
else ifvare VOLUME 6 orvar monstflags 2048

setvarvar temp randomize
ifvarg temp 5000 addvar temp 5000 else
shiftvarl temp 1
ifvarg temp 32000 setvar temp 32000
randvar tempb 100000
ifvarvarl tempb temp orvar monstflags 8192 // hyper speed

setvarvar temp randomize
subvar temp 2000
ifvarg temp 5000 addvar temp 5000 else
shiftvarl temp 1
ifvarg temp 30000 ifvarn sprite[THISACTOR].picnum ROTATEGUN setvar temp 30000
randvar tempb 100000
ifvarvarl tempb temp
{
	orvar monstflags 256
	orvar monstflags 2048
}

setvarvar temp randomize
subvar temp 4000
shiftvarl temp 1
ifvarg temp 50000 setvar temp 50000
randvar tempb 100000
ifvarvarl tempb temp
orvar monstflags 2

ifrnd 4 orvar monstflags 128

ifvarand monstflags 8192 nullop else
ifrnd 20 orvar monstflags 4096

getactor[THISACTOR].picnum picnum
switch picnum
case BOSS1
	ifspawnedby MSPAWNER spritepal 3
	getactor[THISACTOR].pal pal
	ifvarn pal 0
	ifrnd 80
	ifvarn VOLUME 6
	{
		cactor BOSS2PALRESPAWN 
		spritepal 3 setvar pal 3 
		setactor[THISACTOR].httempang 3 
	}
	ifvare pal 0
	{
		ifvarand monstflags 4096 xorvar monstflags 4096
		ifvarand monstflags 2 xorvar monstflags 2
	    ifvarg truelevel 2 ifvare monstflags 0 orvar monstflags 2
		ifvare LEVEL 31 { setvar monstflags 18800 setvar mtype 1 }
	}
break

case BOSS1STAYPUT
ifspawnedby MSPAWNER spritepal 3
getactor[THISACTOR].pal pal
	ifvarn pal 0
	ifrnd 80
	ifvarn VOLUME 6
	{
		cactor BOSS2PALRESPAWN spritepal 3 setvar pal 3
		orvar monstflags 1 // stayput flag
		setactor[THISACTOR].httempang 3
	}
	ifvare pal 0
	{
		ifvarand monstflags 2 xorvar monstflags 2
	    ifvarg truelevel 2 ifvare monstflags 0 orvar monstflags 2
		 ifvare LEVEL 31 { setvar monstflags 18800 setvar mtype 1 }
	}
break

case BOSS2
case BOSS3
case BOSS4
case BOSS4STAYPUT
ifactor BOSS4 ifspawnedby MSPAWNER { spritepal 3 setvar pal 3 }
ifvare sprite[THISACTOR].pal 0
{
	ifvarand monstflags 2 xorvar monstflags 2
	ifvarg truelevel 2 ifvare monstflags 0 orvar monstflags 2
	ifvarand monstflags 4096 xorvar monstflags 4096
	orvar monstflags 256
	ifvare LEVEL 31
	ifvarg truelevel 11
	{
		setvar monstflags 18800
		setvar mtype 1
	}

}
break

case PIGCOP
ifvarg randomize 10000
{
	setvarvar temp randomize
	subvar temp 6000
	randvar tempb 100000
	ifvarvarl tempb temp
	{
		ifvarand monstflags 256 xorvar monstflags 256
		ifvarand monstflags 16 xorvar monstflags 16
		ifvarand monstflags 32 xorvar monstflags 32
		ifvarand monstflags 64 xorvar monstflags 64
		orvar monstflags 3086 // fast shooting 1024, double firepower 8, smart 2048, extra tough 2, 4
	}
}

ifvarand monstflags 256 
ifvarn VOLUME 6
{
	ifvarand monstflags 16 xorvar monstflags 16
	ifvarand monstflags 64 xorvar monstflags 64
	orvar monstflags 32
	cactor BOSS3PALRESPAWN
}
break

case LIZMAN
case LIZMANJUMP
case LIZMANSTAYPUT
ifvarg randomize 10000
{
	setvarvar temp randomize
	subvar temp 6000
	randvar tempb 100000
	ifvarvarl tempb temp
	{
		orvar monstflags 11406 // fast shooting 1024, fast moving 8192, double firepower 8, smart 2048, teleport 128, extra tough 2, 4
		spritepal 48
	}
	
}

ifceilingdistl 256 nullop else
ifvarn sprite[THISACTOR].pal 57
ifvarg truelevel 1
ifawayfromwall
ifvarn VOLUME 6
{
	ifrnd 1 { cactor BOSS2PALRESPAWN spritepal 3 setvar pal 3 setactor[THISACTOR].httempang 3 } else
	ifrnd 1 { cactor BOSS3PALRESPAWN spritepal 3 setvar pal 3 setactor[THISACTOR].httempang 3 } 
	else
	ifrnd 1 { spritepal 3 setvar pal 3 setactor[THISACTOR].httempang 3 cactor BOSS4 state setbeastpal }
}

break

case NEWBEAST
case NEWBEASTJUMP

setvarvar temp randomize
shiftvarl temp 1
ifvarg temp 50000 setvar temp 50000
randvar tempb 100000
ifvarvarl tempb temp
orvar monstflags 1024

ifvarg randomize 10000
{
	setvarvar temp randomize
	subvar temp 6000
	randvar tempb 100000
	ifvarvarl tempb temp
	{
		{
			orvar monstflags 11310 // stealth 1024, fast moving 8192, double firepower 8, smart 2048, expander 32, extra tough 2, 4
			spritepal 49
		}
	}
}


ifceilingdistl 256 nullop else
ifvarand monstflags 11310 nullop else
ifvarg truelevel 1
ifawayfromwall
ifvarn VOLUME 6
{
	ifrnd 1 { cactor BOSS2PALRESPAWN spritepal 3 setvar pal 3 setactor[THISACTOR].httempang 3 } else
	ifrnd 1 { cactor BOSS3PALRESPAWN spritepal 3 setvar pal 3 setactor[THISACTOR].httempang 3 } 
	else
	ifrnd 1 { spritepal 3 setvar pal 3 setactor[THISACTOR].httempang 3 cactor BOSS4 state setbeastpal }
}

break

case RECON
cactor RECONDP
break

case DRONE
ifvarg randomize 10000
{
	setvarvar temp randomize
	subvar temp 6000
	randvar tempb 100000
	ifvarvarl tempb temp
		orvar monstflags 1024
}

break

case LIZTROOP
case LIZTROOPSTAYPUT
case LIZTROOPSHOOT
case LIZTROOPJETPACK
case LIZTROOPRUNNING
case LIZTROOPDUCKING

ifspawnedby MSPAWNER { ifrnd 64 { spritepal 21 orvar monstflags 16384 } }
ifvarg randomize 10000
{
	setvarvar temp randomize
	subvar temp 6000
	randvar tempb 100000
	ifvarvarl tempb temp
		setvar monstflags 11398 // biglaser 1024, fast moving 8192, smart 2048, teleport 128, extra tough 2, 4
}

ifvarand monstflags 256 
{
	ifvarand monstflags 64 xorvar monstflags 64
	ifvarand monstflags 32 xorvar monstflags 32
	ifvarand monstflags 16 xorvar monstflags 16
	ifvarand monstflags 8 xorvar monstflags 8
} else
ifvarg randomize 2000
{
	
	ifgapzl 160 nullop else
	ifvarg randomize 9000
	ifvarn VOLUME 6
	{
		setvarvar temp randomize
		subvar temp 7000
		randvar tempb 100000
		ifvarvarl tempb temp
		{
			cactor MECH2
			ai AIMECH2WAIT
			strength 2500
			divvar temp 2
			ifvarg randomize 14000
			ifvarvarl tempb temp
			{
				setvar monstflags 2056
				spritepal 57
			}
			else
			{
				setvar monstflags 2048
				spritepal 0
			}
			sizeat 38 36
		}
	}
	ifactor MECH2 nullop else
	ifvarn VOLUME 6
	{
		setvar A 0
		findnearspritez BOTALLY 8192 16384 spriteid
		ifvarn spriteid -1
		{
			getactorvar[spriteid].playerally temp
			ifvare temp 0 setvar A 1
		}
		ifvare A 0
		{
			setvarvar temp randomize
			subvar temp 2000
			shiftvarl temp 1
			ifvarg temp 33000 setvar temp 33000
			randvar tempb 100000
			ifvarvarl tempb temp
			{
				ifvarg temp 1000 shiftvarr temp 1
				divvar temp 1000
				ifvarg temp 10 setvar temp 10
				ifvare sprite[THISACTOR].picnum LIZTROOPSTAYPUT setvar command 1
				cactor BOTALLY
				ifvarand monstflags 2 { spritepal 17 setvar monstflags 2 } else
				{
					spritepal 19
					setvar monstflags 0
				}
				setvar lotag 1
				whilevarn temp 0
				{
					randvarvar tempb temp
					ifvare tempb 0 nullop else
					ifvare tempb 1 orvar monstflags 16 else
					ifvare tempb 2 orvar monstflags 128 else
					ifvare tempb 3 orvar monstflags 32 else
					ifvare tempb 4 orvar monstflags 512 else
					ifvare tempb 5 orvar monstflags 64 else
					ifvare tempb 6 orvar monstflags 256 else
					{
						randvar tempd 2
						ifvare tempd 0 orvar monstflags 512 else
						ifvare tempd 1 orvar monstflags 64 else
						orvar monstflags 256
					}
					subvar temp 1
		 		}
		 		
			}
		}
	}
}
break

case BOTALLY

ifvarand monstflags 2 { spritepal 17 setvar monstflags 2 } else
{
	spritepal 19
	setvar monstflags 0
}
setvar lotag 1
setvarvar temp randomize
subvar temp 2000
shiftvarl temp 1
ifvarg temp 33000 setvar temp 33000
ifvarg temp 1000 shiftvarr temp 1
divvar temp 1000
ifvarg temp 10 setvar temp 10
ifvarl temp 1 setvar temp 1
whilevarn temp 0
{
	randvarvar tempb temp
	ifvare tempb 0 nullop else
	ifvare tempb 1 orvar monstflags 16 else
	ifvare tempb 2 orvar monstflags 128 else
	ifvare tempb 3 orvar monstflags 32 else
	ifvare tempb 4 orvar monstflags 512 else
	ifvare tempb 5 orvar monstflags 64 else
	ifvare tempb 6 orvar monstflags 256 else
	{
		randvar tempd 2
		ifvare tempd 0 orvar monstflags 512 else
		ifvare tempd 1 orvar monstflags 64 else
		orvar monstflags 256
	}
	subvar temp 1
}
break

case TANK
ifgapzl 160 nullop else
ifvarg randomize 7000
ifvarn VOLUME 6
{
	setvarvar temp randomize
	subvar temp 6000
	randvar tempb 100000
	ifvarvarl tempb temp
	{
		cactor MECH2
		ai AIMECH2WAIT
		strength 2500
		divvar temp 3
		ifvarvarl tempb temp
		{
			setvar monstflags 2056
			spritepal 57
		}
		else
		{
			setvar monstflags 2048
			spritepal 0
		}
		sizeat 38 36
	}
}
ifactor TANK ifvarg randomize 10000
{
	setvarvar temp randomize
	subvar temp 6000
	randvar tempb 100000
	ifvarvarl tempb temp
	{
		orvar monstflags 3078 // fuckall 1024, smart 2048, extra tough 2, 4
		ifvarand monstflags 16 xorvar monstflags 16
		ifvarand monstflags 32 xorvar monstflags 32
		ifvarand monstflags 64 xorvar monstflags 64
	}
}
break

case COMMANDER
ifgapzl 160 nullop else
ifvarg randomize 8000
ifvarn VOLUME 6
{
	setvarvar temp randomize
	subvar temp 6000
	randvar tempb 100000
	ifvarvarl tempb temp
	{
		cactor MECH2
		ai AIMECH2WAIT
		strength 2500
		divvar temp 3
		ifvarvarl tempb temp
		{
			setvar monstflags 2056
			spritepal 57
		}
		else
		{
			setvar monstflags 2048
			spritepal 0
		}
		sizeat 38 36
	}
}
break

case MECH2
setvarvar temp randomize
subvar temp 7000
randvar tempb 100000
ai AIMECH2WAIT
strength 2500
divvar temp 2
ifvarg randomize 14000
ifvarvarl tempb temp
{
	setvar monstflags 2056
	spritepal 57
}
else
{
	setvar monstflags 2048
	spritepal 0
}
sizeat 38 36
break

case BOSS2PALRESPAWN
case BOSS3PALRESPAWN
spritepal 3
break

default 
break
endswitch

ends

state wakemon
	getactor[spriteid].picnum picnum
	switch picnum
	case LIZTROOP  
	case LIZTROOPDUCKING
	case LIZTROOPJETPACK
	case LIZTROOPSHOOT
	case LIZTROOPONTOILET
	case LIZTROOPJUSTSIT
	case LIZTROOPRUNNING
	case OCTABRAIN  
	case OCTABRAINSTAYPUT
	case DRONE  
	case COMMANDER  
	case COMMANDERSTAYPUT
	case TANK  
	case MECH2
	case PIGCOP  
	case PIGCOPDIVE  
	case PIGCOPSTAYPUT
	case LIZMAN  
	case LIZMANSTAYPUT
	case LIZMANSPITTING
	case LIZMANJUMP
	case ROTATEGUN   
	case BOSS1 
	case BOSS1STAYPUT 
	case BOSS2  
	case BOSS3  
	case NEWBEAST
	case BOSS4
	case BOSS4STAYPUT
	case BOTALLY
	case BOTALLYCROUCH
	case MSPAWNER
	canseespr THISACTOR spriteid temp
	ifvare temp 1
	{
		changespritestat spriteid 1
		setactor[spriteid].httimetosleep 780	
	}
	break
	default break
	endswitch
ends

state setmonval

ifvare playerally -1 { setvar mval 0 break }

getactor[THISACTOR].picnum picnum
switch picnum

case EGG
setvar mval EGGVAL
ifvarand monstflags 512 xorvar monstflags 512
break

case LIZTROOP
case LIZTROOPSTAYPUT
case LIZTROOPSHOOT
case LIZTROOPJETPACK
case LIZTROOPRUNNING
case LIZTROOPDUCKING
setvar mval TROOPVAL


ifvarand monstflags 16384 addvar mval TROOPVAL // was ifspritepal 21
ifvarand monstflags 1024 { spritepal 50 addvar mval TROOPVAL } else
ifvarand monstflags 64 spritepal 49 else
ifvarand monstflags 32 spritepal 71 else
ifvarand monstflags 16 spritepal 10 else
ifvarand monstflags 8 spritepal 23 else
ifvarand monstflags 4 spritepal 16 else
ifvarand monstflags 2 spritepal 46

ifvarand monstflags 256 
{
	spritepal 17
	shiftvarl mval 1
	orvar monstflags 2048
	orvar monstflags 16384
}
break

case BOTALLY
case BOTALLYCROUCH
setvar mval BOTVAL
break

case LIZTROOPONTOILET
case LIZTROOPJUSTSIT
ifvarand monstflags 512 xorvar monstflags 512
setvar mval TROOPVAL
ifvarand monstflags 16384 addvar mval TROOPVAL else
ifvarand monstflags 64 spritepal 49 else
ifvarand monstflags 32 spritepal 71 else
ifvarand monstflags 16 spritepal 10 else
ifvarand monstflags 8 spritepal 23 else
ifvarand monstflags 4 spritepal 16 else
ifvarand monstflags 2 spritepal 46
break

case OCTABRAIN
case OCTABRAINSTAYPUT
ifvarand monstflags 512 xorvar monstflags 512
ifvarand monstflags 64 spritepal 17 else
ifvarand monstflags 32 spritepal 71 else
ifvarand monstflags 16 spritepal 19 else
ifvarand monstflags 8 spritepal 102 else
ifvarand monstflags 4 spritepal 90 else
ifvarand monstflags 2 spritepal 64
setvar mval OCTAVAL
break

case DRONE
ifvarand monstflags 512 xorvar monstflags 512
ifvarand monstflags 64 spritepal 17 else
ifvarand monstflags 32 spritepal 48 else
ifvarand monstflags 16 spritepal 19 else
ifvarand monstflags 8 spritepal 102 else
ifvarand monstflags 4 spritepal 90 else
ifvarand monstflags 2 spritepal 64
setvar mval DRONEVAL
break

case PIGCOP
case PIGCOPSTAYPUT
case PIGCOPDIVE
setvar mval PIGVAL
ifvarand monstflags 1024 { spritepal 21 addvar mval 200 } else
ifvarand monstflags 64 spritepal 17 else
ifvarand monstflags 32 spritepal 10 else
ifvarand monstflags 16 spritepal 16 else
ifvarand monstflags 8 spritepal 23 else
ifvarand monstflags 4 spritepal 90 else
ifvarand monstflags 2 spritepal 46

break

case SHARK
setvar monstflags 0
setvar mval 50
break

case RECON
case RECONDP
cactor RECONDP
setvar picnum RECONDP
ifvarand monstflags 512 xorvar monstflags 512
ifvarand monstflags 64 spritepal 17 else
ifvarand monstflags 32 spritepal 10 else
ifvarand monstflags 16 spritepal 16 else
ifvarand monstflags 8 spritepal 23 else
ifvarand monstflags 4 spritepal 90 else
ifvarand monstflags 2 spritepal 46
setvar mval RECONVAL
break

case COMMANDER
case COMMANDERSTAYPUT
ifvarand monstflags 256 spritepal 90
ifvarand monstflags 64 spritepal 17 else
ifvarand monstflags 32 spritepal 56 else
ifvarand monstflags 16 spritepal 19 else
ifvarand monstflags 8 spritepal 102 else
ifvarand monstflags 4 spritepal 40 else
ifvarand monstflags 2 spritepal 64
setvar mval COMMVAL
break

case TANK
setvar mval TANKVAL
ifvarand monstflags 1024 { spritepal 24 addvar mval 500 } else
ifvarand monstflags 64 spritepal 17 else
ifvarand monstflags 32 spritepal 48 else
ifvarand monstflags 16 spritepal 19 else
ifvarand monstflags 8 spritepal 102 else
ifvarand monstflags 4 spritepal 7 else
ifvarand monstflags 2 spritepal 64
ifvarand monstflags 512 xorvar monstflags 512
break

case MECH2
setvar mval BOSSPALVAL
addvar mval BOSSPALVAL
break

case LIZMAN
case LIZMANSTAYPUT
case LIZMANJUMP
case LIZMANSPITTING
setvar mval LIZVAL
ifvarand monstflags 1024
{
	ifvarand monstflags 256 xorvar monstflags 256
	ifvarand monstflags 32 xorvar monstflags 32
	ifvarand monstflags 16 xorvar monstflags 16
}
ifspritepal 48 addvar mval 100 else
ifvarand monstflags 64 spritepal 17 else
ifvarand monstflags 32 spritepal 50 else
ifvarand monstflags 16 spritepal 57 else
ifvarand monstflags 8 spritepal 102 else
ifvarand monstflags 4 spritepal 27 else
ifvarand monstflags 2 spritepal 27

ifvarand monstflags 1024 addvar mval 100 
break

case ROTATEGUN
ifvarand monstflags 512 xorvar monstflags 512
ifvarand monstflags 64 
{
	spritepal 17
	ifvarand monstflags 256 xorvar monstflags 256 
}
else
ifvarand monstflags 32 spritepal 48 else
ifvarand monstflags 16 spritepal 19 else
ifvarand monstflags 8 spritepal 102 else
ifvarand monstflags 4 spritepal 90 else
ifvarand monstflags 2 spritepal 64
setvar mval TURRVAL
break

case BOSS1
case BOSS1STAYPUT
case BOSS2
case BOSS2PALRESPAWN
ifvarn sprite[THISACTOR].pal 0
{
	ifvarand monstflags 64 spritepal 17 else
	ifvarand monstflags 32 spritepal 48 else
	ifvarand monstflags 16 spritepal 19 else
	ifvarand monstflags 8 spritepal 102 else
	ifvarand monstflags 4 spritepal 90 else
	ifvarand monstflags 2 spritepal 64
}

ifvarand monstflags 512 xorvar monstflags 512
ifspritepal 0 setvar mval BOSSVAL else setvar mval BOSSPALVAL
break

case BOSS3
case BOSS3PALRESPAWN
ifvarn sprite[THISACTOR].pal 0
{
	ifvarand monstflags 64 spritepal 17 else
	ifvarand monstflags 32 spritepal 71 else
	ifvarand monstflags 16 spritepal 19 else
	ifvarand monstflags 8 spritepal 102 else
	ifvarand monstflags 4 spritepal 90 else
	ifvarand monstflags 2 spritepal 64
}

ifvarand monstflags 512 xorvar monstflags 512
ifspritepal 0 setvar mval BOSSVAL else setvar mval BOSSPALVAL

case BOSS4
case BOSS4STAYPUT

ifvarn pal 0
{
	ifvarand monstflags 64 spritepal 17 else
	ifvarand monstflags 32 spritepal 10 else
	ifvarand monstflags 16 spritepal 16 else
	ifvarand monstflags 8 spritepal 23 else
	ifvarand monstflags 4 spritepal 14 else
	ifvarand monstflags 2 spritepal 13
}
ifvarand monstflags 512 xorvar monstflags 512
ifvare pal 0 setvar mval BOSSVAL else setvar mval BOSSPALVAL
break

case NEWBEAST
case NEWBEASTSTAYPUT
case NEWBEASTHANG
case NEWBEASTJUMP

setvar mval BEASTVAL
ifvarand monstflags 512 xorvar monstflags 512
ifvarand monstflags 4096 xorvar monstflags 4096

ifspawnedby BOSS4
{
	getactorvar[sprite[THISACTOR].owner].pal pal
	ifvarn pal 0 setvar mval 100
}
ifspawnedby EGG setvar mval 50
ifvarn mval 50
ifvarn pal 49
{
	setvarvar temp randomize
	subvar temp 2000
	shiftvarl temp 2
	ifvarg temp 50000 setvar temp 50000
	randvar tempb 100000
	ifvarvarl tempb temp
	{
		orvar monstflags 256
		orvar monstflags 2048
	}
}

state setbeastpal
	
break

case GREENSLIME
setvar mval 10
break

default
setvar mval 777777 // this will make errors obvious
break
endswitch

// now make adjustments depending on generic monstflags

ifvarand monstflags 2
{
	mulvar mval 3
	shiftvarr mval 1
}

ifactor BOTALLY break
ifactor BOTALLYCROUCH break

ifvarand monstflags 8 // double fire power
{
	mulvar mval 3
	shiftvarr mval 1
}
ifvarand monstflags 16 // attack variation 1
{
	mulvar mval 3
	shiftvarr mval 1
} else
ifvarand monstflags 32 // attack variation 2
{
	mulvar mval 5
	divvar mval 3
} else
ifvarand monstflags 64 // attack variation 3
{
	shiftvarl mval 1
}

ifvarn VOLUME 6 // ALL monsters have the flag in VOLUME 6, so it isn't credited
ifvarand monstflags 2048 // smart tactics
{
	ifvarn picnum EGG
	ifvarn picnum ROTATEGUN
	ifvarn picnum RECONDP
	{
		mulvar mval 5
		shiftvarr mval 2
	}
}

ifvarand monstflags 8192 // hyper speed
{
	ifvare picnum RECONDP xorvar monstflags 8192
	ifvare picnum EGG xorvar monstflags 8192
	ifvare picnum ROTATEGUN xorvar monstflags 8192
	ifvarand monstflags 8192 addvar mval 50
}

ifvarand monstflags 128 // teleports
{
	mulvar mval 7
	divvar mval 6
}

ends


state rollfordrop

// about 5% chance of drop per roll
randvar tempb 100
ifvarl tempb 5
{
	addvar botclip 200
	addvarvar botclip M
	randvar temp 100
	ifvarl temp 7 ifvarl nukes 3 setvar picnum ATOMICHEALTH else // nuke energy
	ifvarl temp 41 setvar picnum COLA else // +1 max health
	ifvarl temp 43 ifvarl player[THISACTOR].boot_amount 150 setvar picnum BOOTS else // just ordinary boots, for flame protection
	ifvarl temp 52 setvar picnum FIRSTAID else // + medical skill
    ifvarl temp 62 setvar picnum AMMOPACK else // + max ammo or random ammo
	ifvarl temp 72 setvar picnum HOLODUKE else // + duke bot level
	ifvarl temp 82 setvar picnum STEROIDS else // + steroids level
	ifvarl temp 88 setvar picnum HEATSENSOR else // + stealth level
	setvar picnum SHIELD // + 5 max armor
	espawnvar picnum
	setactorvar[RETURN].peractor4 13
	setactorvar[RETURN].mtype 1
	getactor[RETURN].htflags temp
	orvar temp 64
	setactor[RETURN].htflags temp
	randvar angvar 2047
	setactor[RETURN].ang angvar
}
else addvar botclip 50


ends

state rollfordrop2

setvarvar I mval
shiftvarr I 7
ifvarg mval 100 addvar I 1
ifvarl I 0 setvar I 0
whilevarn I 0
{
	ifrnd 18
	{
		// drop regular item
		randvar temp 100
		ifvarl temp 20 setvar picnum COLA else
		ifvarl temp 28 setvar picnum SIXPAK else
		ifvarl temp 29 setvar picnum JETPACK else
		ifvarl temp 30 setvar picnum HOLODUKE else
		ifvarl temp 31 setvar picnum STEROIDS else
		ifvarl temp 32 setvar picnum HEATSENSOR else
		ifvarl temp 37 setvar picnum FIRSTGUNSPRITE else
	    ifvarl temp 45 { ifvare player[THISACTOR].gotweapon 2 0 setvar picnum SHOTGUNSPRITE else setvar picnum SHOTGUNAMMO } else
	    ifvarl temp 55 { ifvare player[THISACTOR].gotweapon 3 0 setvar picnum CHAINGUNSPRITE else setvar picnum BATTERYAMMO } else
	    ifvarl temp 60 { ifvare player[THISACTOR].gotweapon 4 0 setvar picnum RPGSPRITE else setvar picnum RPGAMMO } else
	    ifvarl temp 64 setvar picnum HBOMBAMMO else
	    ifvarl temp 68 { ifvare player[THISACTOR].gotweapon 6 0 setvar picnum SHRINKERSPRITE else setvar picnum CRYSTALAMMO } else
	    ifvarl temp 72 { ifvare player[THISACTOR].gotweapon 7 0 setvar picnum DEVISTATORSPRITE else setvar picnum DEVISTATORAMMO } else
	    ifvarl temp 75 { ifvare player[THISACTOR].gotweapon 9 0 setvar picnum FREEZESPRITE else setvar picnum FREEZEAMMO } else
	    ifvarl temp 78 setvar picnum TRIPBOMBSPRITE else
	    ifvarl temp 82 { ifvare player[THISACTOR].gotweapon 7 0 setvar picnum GROWSPRITEICON else setvar picnum GROWAMMO } else
	    ifvarl temp 84 { ifvare rage FULLRAGE setvar picnum ESHIELDSPRITE else setvar picnum RAGESPRITE } else
	    ifvarl temp 86 setvar picnum ROFSPRITE else
	    ifvarl temp 87 setvar picnum XPSPRITE else
		setvar picnum SHIELD
		espawnvar picnum
		setactorvar[RETURN].peractor4 13
		setactorvar[RETURN].mtype 2 // will disappear
		randvar angvar 2047
		setactor[RETURN].ang angvar
		subvar I 2 ifvarl I 1 setvar I 1
	}
	subvar I 1
}

ends

state randomdrop

setvarvar M mval
divvar M 7 // max of 7 upgrades can drop
setvar botclip 0
whilevarvarn botclip mval
{
	state rollfordrop
	ifvarvarg botclip mval setvarvar botclip mval
}

setvar botclip 0
ifvare VOLUME 6 state rollfordrop2

ends