define BLOODP2         5231
define BLOODP3         5232
define BLOODP4         5233
define BLOODP1         5235
define BSPAWNER        5234
define GBSPAWNER       5238
define NEWBLOOD54        5241
define GNEWBLOOD       5406
define NEWBLOODSPLAT1  5410
define NEWBLOODSPLAT2  5411
define NEWBLOODSPLAT3  5412
define NEWBLOODSPLAT4  5413

move faster  5 300
move stop 0

state rf
  ifrnd 128
    cstat 4
  else
    cstat 0
ends

state attachfloor
  getactor[THISACTOR].x x
  getactor[THISACTOR].y y
  updatesector x y SECT
  getflorzofslope SECT x y z
  setactor[THISACTOR].z z
ends

spritenoshade SPOTLITE

state CHECKSTEPS

setvar STEPSOUNDFX 0

switch FLOORTEX

case 0 setvar STEPSOUNDFX 0 break

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

setvar STEPSOUNDFX 1 break

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

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

setvar STEPSOUNDFX 2 break

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

setvar STEPSOUNDFX 3 break

case 803 setvar STEPSOUNDFX 4 break

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

setvar STEPSOUNDFX 5 break

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

setvar STEPSOUNDFX 6 break

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

setvar STEPSOUNDFX 7 break

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

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

setvar STEPSOUNDFX 9 break

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

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

break

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

break

endswitch

ends

state spark
randvar z 256
mulvar z -1
ezshoot z 3742
ends

state getceilz
  getactor[THISACTOR].x x
  getactor[THISACTOR].y y
  updatesector x y mysector
  ifvare mysector -1 getsector[THISACTOR].ceilingz z
  else
  getceilzofslope mysector x y z
ends

state stepsounds
randvar FOOTSTEPCOUNT 3
switch STEPSOUNDFX	
		case 0
		case 7
		ifvare FOOTSTEPCOUNT 0 sound STEP1 else
		ifvare FOOTSTEPCOUNT 1 sound STEP2 else
		ifvare FOOTSTEPCOUNT 2 sound STEP3 else
		ifvare FOOTSTEPCOUNT 3 sound STEP4
		break
		
		case 1
		ifvare FOOTSTEPCOUNT 0 sound WOOD1 else
		ifvare FOOTSTEPCOUNT 1 sound WOOD2 else
		ifvare FOOTSTEPCOUNT 2 sound WOOD3 else
		ifvare FOOTSTEPCOUNT 3 sound WOOD4
		break
		
		case 2
		ifvare FOOTSTEPCOUNT 0 sound TIN1 else
		ifvare FOOTSTEPCOUNT 1 sound TIN2 else
		ifvare FOOTSTEPCOUNT 2 sound TIN3 else
		ifvare FOOTSTEPCOUNT 3 sound TIN4
		break
		
		case 3
		ifvare FOOTSTEPCOUNT 0 sound GRATES1 else
		ifvare FOOTSTEPCOUNT 1 sound GRATE2 else
		ifvare FOOTSTEPCOUNT 2 sound GRATE3 else
		ifvare FOOTSTEPCOUNT 3 sound GRATE4
		break
		
		case 4
		ifvare FOOTSTEPCOUNT 0 sound GRASS1 else
		ifvare FOOTSTEPCOUNT 1 sound GRASS2 else
		ifvare FOOTSTEPCOUNT 2 sound GRASS3 else
		ifvare FOOTSTEPCOUNT 3 sound GRASS4
		break
		
		case 5
		ifvare FOOTSTEPCOUNT 0 sound TILE1 else
		ifvare FOOTSTEPCOUNT 1 sound TILE2 else
		ifvare FOOTSTEPCOUNT 2 sound TILE3 else
		ifvare FOOTSTEPCOUNT 3 sound TILE4
		break
		
		case 6
		ifvare FOOTSTEPCOUNT 0 sound CARPET1 else
		ifvare FOOTSTEPCOUNT 1 sound CARPET2 else
		ifvare FOOTSTEPCOUNT 2 sound CARPET3 else
		ifvare FOOTSTEPCOUNT 3 sound CARPET4
		break
		
		case 8
		ifvare FOOTSTEPCOUNT 0 sound SNOW1 else
		ifvare FOOTSTEPCOUNT 1 sound SNOW2 else
		ifvare FOOTSTEPCOUNT 2 sound SNOW3 else
		ifvare FOOTSTEPCOUNT 3 sound SNOW4
		ifactor APLAYER
		{
			  setplayer[THISACTOR].footprintcount 2
			  setplayer[THISACTOR].footprintpal 13
			  setplayer[THISACTOR].footprintshade 0
		}
		break
		
		case 9 
		// soundonce DUKE_ONWATER
		break // STEPSOUNDFX 9 IS FOR WATER
		
		default 
		ifvare FOOTSTEPCOUNT 0 sound STEP1 else
		ifvare FOOTSTEPCOUNT 1 sound STEP2 else
		ifvare FOOTSTEPCOUNT 2 sound STEP3 else
		ifvare FOOTSTEPCOUNT 3 sound STEP4
		break	
		endswitch	
	resetactioncount
ends

state stepsoundstuff

getsector[THISACTOR].floorpicnum FLOORTEX

ifinwater break
ifonwater break
ifp pfalling break

ifp pjetpack break
ifactioncount 2 nullop else break

setvar temp 0
ifp prunning setvar temp 1
ifp pwalking setvar temp 1
ifp pducking setvar temp 0

ifvare temp 1
{
	getplayer[THISACTOR].spritebridge temp // IF THE PLAYER IS ON A FLAT SPRITE
	ifvare temp 1 
	{ 
		getplayer[THISACTOR].sbs tempb // GET THE FLATSPRITE'S ID TAG
		getactor[tempb].picnum temp // CHECK IT'S TEXTURE
		setvarvar FLOORTEX temp // SET THE VARIABLE FLOORTEX TO IT'S TEXTURE
		
	}
	
	state CHECKSTEPS // CHECKS THE STEP DEFINES
	state stepsounds
}

ends

state HITMETALSOUND

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

endswitch


ends

state HITSTONESOUND

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

ends

state WOODHITSOUND

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

endswitch


ends

state HITDIRTSOUND

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

endswitch


ends

state HITWATERSOUND

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

endswitch


ends


state landsounds
ifvare STEPSOUNDFX 1 { soundonce LANDWOOD  } else
ifvare STEPSOUNDFX 2 { soundonce LANDMETAL  } else
ifvare STEPSOUNDFX 3 { soundonce LANDMETAL  } else
ifvare STEPSOUNDFX 4 { soundonce LANDDIRT } else
ifvare STEPSOUNDFX 7 { soundonce LANDNORMAL  } else
ifvare STEPSOUNDFX 8 { soundonce LANDSNOW  } else
ifvare STEPSOUNDFX 9 { soundonce LANDWATER  } else
ifvare STEPSOUNDFX 11 { soundonce JIBLAND  } else
{  soundonce LANDNORMAL  }
ends

state STOPSTEPSOUNDS
stopsound DUKE_LAND
stopsound STEP1
stopsound STEP2
stopsound STEP3
stopsound STEP4
stopsound WOOD1
stopsound WOOD2
stopsound WOOD3
stopsound WOOD4
stopsound TIN1
stopsound TIN2
stopsound TIN3
stopsound TIN4
stopsound GRATES1
stopsound GRATE2
stopsound GRATE3
stopsound GRATE4
stopsound GRASS1
stopsound GRASS2
stopsound GRASS3
stopsound GRASS4
stopsound TILE1
stopsound TILE2
stopsound TILE3
stopsound TILE4
stopsound CARPET1
stopsound CARPET2
stopsound CARPET3
stopsound CARPET4
stopsound SNOW1
stopsound SNOW2
stopsound SNOW3
stopsound SNOW4
ends

state BULLETHITSOUNDS

switch STEPSOUNDFX
case 0
break

case 1
case 5
	state WOODHITSOUND break

case 2
case 3
	state HITMETALSOUND state spark state spark break

	
case 4
case 8
	state HITDIRTSOUND break

case 7
	state HITSTONESOUND debris SCRAP3 1
break
	
case 9
	state HITWATERSOUND break
case 10
	state HITSTONESOUND debris SCRAP3 1 break
	
case 11
    sound HITFLESH 
    spritepal 6
    espawn JIBS6
	setactor[RETURN].xrepeat 32
	setactor[RETURN].yrepeat 32
	setactor[RETURN].zvel 0
	//guts JIBS6 1
    break

endswitch

ends

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

define TRAIL 4056

eventloadactor TRAIL
{
getactor[THISACTOR].hitag hitagsaved
getactor[THISACTOR].lotag code
setactor[THISACTOR].lotag 0
setactor[THISACTOR].hitag 0
}
enda

useractor notenemy TRAIL
cstator 32768
sizeat 8 8
enda

action doorn 0 1 1 1 1
action doorfall 1 2 1 1 12
action doorfalled 4 1 1 1  1

useractor notenemy 8138 0

ifvare destroy 555
{
ifaction 0
{
action doorfall
}
}

ifaction doorfall
{
quake 80
ifactioncount 2
{
action doorfalled
cstat 0
setvar destroy 0
break
}
}

enda

state mp5k

setvar x 160
  addvarvar x weapon_xoffset
  subvarvar x looking_angSR1
      
  setvar y 120
  addvarvar y looking_arc
  subvarvar y gun_pos
setvar tilenum 3716

switch weaponcount
case 0
rotatesprite x y 65536 1024 tilenum 0 0 4 0 0 xdim ydim
break

case 1
randvar temp 2048
randvar temp2 2048
randvar temp3 2048
rotatesprite 203 127 65536 temp 3826 0 0 33 0 0 xdim ydim
rotatesprite 203 127 65536 temp2 3826 0 0 33 0 0 xdim ydim
rotatesprite 203 127 65536 temp3 3826 0 0 33 0 0 xdim ydim
rotatesprite x y 65536 1024 tilenum 0 0 4 0 0 xdim ydim
break

case 2
rotatesprite x y 65536 1024 tilenum 0 0 4 0 0 xdim ydim
break

case 3 
rotatesprite x y 65536 1024 tilenum 0 0 4 0 0 xdim ydim
break

case 4
case 5
case 6
case 7
case 8
case 9
case 10
setvar tilenum 3717
rotatesprite x y 65536 1024 tilenum 0 0 4 0 0 xdim ydim
break
case 11
case 12
case 13
case 14
case 15
case 16
case 17
case 18
case 19
case 20
case 21
setvar tilenum 3718
addvar y 90
rotatesprite x y 65536 1024 tilenum 0 0 4 0 0 xdim ydim
break 
case 22
case 23
case 24
case 25
case 26
case 27
case 28
case 29
case 30
case 31
case 32
case 33
case 34
setvar tilenum 3719
addvar y 90
rotatesprite x y 65536 1024 tilenum 0 0 4 0 0 xdim ydim
break 
case 35
case 36
case 37
case 38
case 39
case 40
case 41
case 42
case 43
case 44
case 45
case 46
case 47
case 48
case 49
case 50
case 51
case 52
case 53
setvar tilenum 3720
addvar y 30
rotatesprite x y 65536 1024 tilenum 0 0 4 0 0 xdim ydim
break 
case 54
case 55
case 56
case 57
case 58
case 59
case 60
case 61
case 62
case 63
case 64
case 65
case 66
case 67
case 68
case 69
case 70
setvar tilenum 3721
addvar y 30
rotatesprite x y 65536 1024 tilenum 0 0 4 0 0 xdim ydim
break 

endswitch
ends

state deagle

setvar x 183
setvar y 120
addvarvar x weapon_xoffset
subvarvar x looking_angSR1
addvarvar y looking_arc
subvarvar y gun_pos
setvar picnum FIRSTGUN

switch weaponcount
case 0 
rotatesprite x y 65536 1024 picnum 0 0 4 0 0 xdim ydim
break
case 1
addvar picnum 1
rotatesprite x y 65536 1024 picnum 0 0 4 0 0 xdim ydim
break
case 2
case 3
addvar picnum 2
rotatesprite x y 65536 1024 picnum 0 0 4 0 0 xdim ydim
break
case 4
case 5
addvar picnum 3
rotatesprite x y 65536 1024 picnum 0 0 4 0 0 xdim ydim
break
case 6
case 7
case 8
case 9
case 10
addvar picnum 4
rotatesprite x y 65536 1024 picnum 0 0 4 0 0 xdim ydim
break
case 11
case 12
case 13
case 14
case 15
case 16
case 17
case 18
case 19
case 20
case 21
addvar picnum 5
rotatesprite x y 65536 1024 picnum 0 0 4 0 0 xdim ydim
break 
case 22
case 23
case 24
case 25
case 26
case 27
case 28
case 29
case 30
case 31
case 32
case 33
case 34
addvar picnum 6
rotatesprite x y 65536 1024 picnum 0 0 4 0 0 xdim ydim
break 
case 35
case 36
case 37
case 38
case 39
case 40
case 41
case 42
case 43
case 44
case 45
case 46
case 47
case 48
case 49
case 50
case 51
case 52
case 53
addvar picnum 7
rotatesprite x y 65536 1024 picnum 0 0 4 0 0 xdim ydim
break 
case 54
case 55
case 56
case 57
case 58
case 59
case 60
case 61
case 62
case 63
case 64
case 65
case 66
case 67
case 68
case 69
case 70
addvar picnum 8
rotatesprite x y 65536 1024 picnum 0 0 4 0 0 xdim ydim
break 

endswitch
ends

action NOTHING 0 1 1 1 1
move MNONE       0

state killit1
  setvarvar MODSEED randomseed
  setvarvar randomseed SAVEDRND
  killit
ends

state saverandom
  setvarvar SAVEDRND randomseed
  setvarvar randomseed MODSEED
ends

state loadrandom
  setvarvar MODSEED randomseed
  setvarvar randomseed SAVEDRND
ends

state random_wall_jibs1
  ifrnd 96 shoot NEWBLOODSPLAT1
  ifrnd 96 shoot NEWBLOODSPLAT2
  ifrnd 96 shoot NEWBLOODSPLAT3
  ifrnd 96 shoot NEWBLOODSPLAT4
  ifrnd 96 shoot NEWBLOODSPLAT1
ends

state wallbloodcode
  ifaction 0
  {
    ifspawnedby NEWBEAST { spritepal 6 }
    sizeat 10 10
    cstat 16
    cstator 128

    getactor[THISACTOR].ang ANGVAR
    addvar ANGVAR 1024
    setactor[THISACTOR].ang ANGVAR
    action NOTHING
  }
ends

useractor notenemy NEWBLOODSPLAT1 state wallbloodcode enda
useractor notenemy NEWBLOODSPLAT2 state wallbloodcode enda
useractor notenemy NEWBLOODSPLAT3 state wallbloodcode enda
useractor notenemy NEWBLOODSPLAT4 state wallbloodcode enda


useractor notenemy GBSPAWNER // simulate "BSPAWNER spawned by NEWBEAST"
  setactor[THISACTOR].htpicnum NEWBEAST
  cactor BSPAWNER
enda

move BLOODMOV  140 -60

useractor notenemy BSPAWNER
  state saverandom
  ifspawnedby NEWBEAST { cactor NEWBEAST spritepal 6 }
  ifaction 0
  {
    move BLOODMOV randomangle
    sizeat 6 6
    state random_wall_jibs1
    action NOTHING
  }
  move BLOODMOV geth getv

  ifrnd 196
  {
    ifinwater spawn NEWBLOOD54 else
    {
      spawn BLOODP2
      ifrnd 128 { ifrnd 128 spawn BLOODP1 else spawn BLOODP2 }
           else { ifrnd 128 spawn BLOODP3 else spawn BLOODP4 }
    }
  }
  ifrnd 64 state killit1
  cactor BSPAWNER
  state loadrandom
enda


action NEWBLOODA1 0 10 1 1 4
action NEWBLOODA2 0 10 1 1 12

move NBMOVE 10 -10

useractor notenemy GNEWBLOOD // simulate "GNEWBLOOD spawned by NEWBEAST"
  setactor[THISACTOR].htpicnum NEWBEAST
  cactor NEWBLOOD54
enda

useractor notenemy NEWBLOOD54
  state saverandom
  ifvarl framerate 20 { killit } ifcount 2048 { killit }
  cstat 514
  ifspawnedby BLOODP1 { getactor[THISACTOR].sectnum TMP getsector[TMP].floorz Z setactor[THISACTOR].z Z cstator 32 }
  ifspawnedby BLOODP2 { getactor[THISACTOR].sectnum TMP getsector[TMP].floorz Z setactor[THISACTOR].z Z cstator 32 }
  ifspawnedby BLOODP3 { getactor[THISACTOR].sectnum TMP getsector[TMP].floorz Z setactor[THISACTOR].z Z cstator 32 }
  ifspawnedby BLOODP4 { getactor[THISACTOR].sectnum TMP getsector[TMP].floorz Z setactor[THISACTOR].z Z cstator 32 }
  ifspawnedby NEWBEAST { spritepal 6 } else spritepal 2
  ifaction 0 { state rf { ifinwater action NEWBLOODA2 else ifonwater action NEWBLOODA2 else action NEWBLOODA1 } ifrnd 128 { ifrnd 128 sizeat 100 50 else sizeat 80 30 } else { ifrnd 128 sizeat 110 60 else sizeat 70 40 } }
  ifaction NEWBLOODA1 { { ifspawnedby NEWBEAST { } else cstator 128 } { ifactioncount 10 state killit1 }  }
  ifaction NEWBLOODA2 { { ifspawnedby NEWBEAST { } else cstator 128 } { ifactioncount 10 state killit1 }  }
  state loadrandom
enda

move BLOODMOV2  50

state bloodpcode
  state saverandom
  ifvarl framerate 20 { killit } ifcount 2048 { killit }
  ifspawnedby NEWBEAST { spritepal 6 }
  state getfloordist
  ifvarl z 1
  {
    cstat 32
    sizeat 16 16
    move MNONE geth
    ifinwater
    {
      ifspawnedby NEWBEAST { spawn GNEWBLOOD } else { spawn NEWBLOOD54 }
      state killit1
    }

    ifvare FLAG 0
    {
        getactor[THISACTOR].picnum PICNUM
        cactor BLOODPOOL
        setvar FLAG 1
        findnearspritez BLOODP1 64 1024 TMP
        ifvare TMP -1 findnearspritez BLOODP2 64 1024 TMP
        ifvare TMP -1 findnearspritez BLOODP3 64 1024 TMP
        ifvare TMP -1 findnearspritez BLOODP4 64 1024 TMP
        ifvarn TMP -1
        {
            getactor[TMP].xrepeat mx
            addvar mx 10 ifvarg mx 52 setvar mx 52
            setactor[TMP].xrepeat mx
            setactor[TMP].yrepeat mx
            state killit1
        }
        setactor[THISACTOR].picnum PICNUM
    }
  }
  else
  {
    sizeat 7 7
    move BLOODMOV2 randomangle
  }
  fall
  state getfloordist
  ifvarl z 2     state attachfloor
  iffloordistl 2 state attachfloor
  ifonwater
  {
    ifspawnedby NEWBEAST { spawn GNEWBLOOD } else { spawn NEWBLOOD54 }
    state killit1
  }
  ifcansee { } else { ifrnd 1 state killit1 }
  state loadrandom
ends

useractor notenemy BLOODP1 state bloodpcode enda
useractor notenemy BLOODP2 state bloodpcode enda
useractor notenemy BLOODP3 state bloodpcode enda
useractor notenemy BLOODP4 state bloodpcode enda