define PRIMARY_BLOOD 5856
define SECONDARY_BLOOD 5854



spriteshadow JIBS7
spriteshadow JIBS8
spriteshadow JIBS9
spriteshadow JIBS10
spriteshadow JIBS11
spriteshadow JIBS12

gamevar htangsaved 0 2
gamevar htextrasaved 0 2
gamevar explosionvar 0 2
gamevar utl_tmp1 0 0
gamevar sfx_tmp1 0 0

// IN: in1 = count of actors, in2 = actor to spawn
state spawn_multiply
	
	setvarvar utl_tmp1 in1
	whilevarn utl_tmp1 0
	{
		espawnvar in2
		setactorvar[RETURN].newscrap_pal newscrap_pal
		setactorvar[RETURN].setspark_phis setspark_phis
		setactorvar[RETURN].setglass_phis setglass_phis
		subvar utl_tmp1 1
	}
ends

state bloodspraystate
	getactor[THISACTOR].z z
	setvarvar z2 z
	subvarvar z 2048
	setactor[THISACTOR].z z
	randvar in1 1
	addvar in1 1
	setvar in2 PRIMARY_BLOOD
	state spawn_multiply
	setactor[THISACTOR].z z2
ends

state bloodsprayshit
	getactor[THISACTOR].z z
	setvarvar z2 z
	subvarvar z 2048
	setactor[THISACTOR].z z
	randvar in1 3
	addvar in1 1
	setvar in2 PRIMARY_BLOOD
	state spawn_multiply
	setactor[THISACTOR].z z2
ends

actor BLOODPOOL2
sizeat 32 32 cstat 34
getactor[THISACTOR].sectnum tmp
headspritesect spriteid tmp
whilevarn spriteid -1 
{
	getactor[spriteid].picnum picnum
	ifvare picnum SECTOREFFECTOR
	{
		getactor[spriteid].lotag lotag
		ifvare lotag 24 setvar skillit 1
	}
	nextspritesect spriteid spriteid
}
ifvare skillit 1 killit
getsector[tmp].lotag lotag
ifvare lotag 1 killit
getsector[tmp].floorstat tmp
ifvarand tmp 1024 killit
getactor[THISACTOR].x x
getactor[THISACTOR].y y
getactor[THISACTOR].z z
updatesectorz x y z sectorid
ifvare sectorid -1 killit
enda

action BLOOD_FLAMES 0 4 1 1 10

actor BLOODDROP
fall sizeat 32 32
ifspritepal 0
{ 
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		randvar tmp 512
		addvar tmp -256
		addvarvar x tmp
		randvar tmp 512
		addvar tmp -256
		addvarvar y tmp
		setactor[THISACTOR].x x
		setactor[THISACTOR].y y
		spritepal 30
}
ifaction 0 
iffloordistl 1
{ 
	getactor[THISACTOR].sectnum sectorid
	getsector[sectorid].floorstat tmp
	ifvarand tmp 1024 { ifvare sector[sectorid].lotag 1 killit } else
	{
		getactor[THISACTOR].x x
		getactor[THISACTOR].y y
		getactor[THISACTOR].z z
		updatesectorz x y z sectnum1
		ifvarn sectnum1 -1
		{
		getflorzofslope sectnum1 x y mz

		action BLOOD_FLAMES ifsound BLOODDROPSND 
		{ ifrnd 32 sound BLOODDROPSND } else sound BLOODDROPSND 
		eqspawn BLOODPOOL2 
		setactor[RETURN].z mz 
		setactor[RETURN].sectnum sectnum1
		} else killit
	}
}
ifactioncount 4 killit
enda

actor SECONDARY_BLOOD
	sizeat 24 24 fall
	randvar tmp 3
	switch tmp
		case 0 action FRAME_FRAME1 break
		case 1 action FRAME_FRAME2 break
		case 2 action FRAME_FRAME3 break
		case 3 action FRAME_FRAME4 break
	endswitch
	iffloordistl 1 { ifrnd 10 { qspawn BLOODDROP } killit }
enda

actor PRIMARY_BLOOD
	sizeat 24 24
	spawn SECONDARY_BLOOD
	
	ifstrength 0
	{
		randvar in1 300  //xvel
		subvar in1 150
		randvar in2 300  //yvel
		subvar in2 150
		randvar in3 -9000 //zvel
		subvar in3 5000
		
		state physics_start
		state phys_add_vel
		state physics_end		
		
		randvar sfx_tmp1 100
		addvar sfx_tmp1 1100
		
		setactorvar[THISACTOR].phys_air_damping_x 1050
		setactorvar[THISACTOR].phys_air_damping_y 1050
		setactorvar[THISACTOR].phys_air_damping_z sfx_tmp1		
	
		setactorvar[THISACTOR].phys_gravity_x 0 
		setactorvar[THISACTOR].phys_gravity_y 0
		randvar sfx_tmp1 200
		addvar sfx_tmp1 400
		setactorvar[THISACTOR].phys_gravity_z sfx_tmp1
		strength 1
	}
	
	state physics_start
	state physics_interact_air
	state physics_move
	state physics_end 
	
	iffloordistl 10 { spawn BLOODDROP killit }
	ifceilingdistl 10 { spawn BLOODDROP killit } 
enda

state jib_particle  //klimaka code

	ifstrength 0
	{
		getactorvar[THISACTOR].htangsaved ang
		getactorvar[THISACTOR].htextrasaved paextra
		getactorvar[THISACTOR].explosionvar explosionvar
		ifvare explosionvar 1
		{ randvar tmp 512 addvar tmp 256 } else
		{ randvar tmp 2048 }
		addvarvar ang tmp
		
		cos x ang
		sin y ang
		divvar x 40
		divvar y 40
		addvarvar x paextra
		addvarvar y paextra
		randvar z 64
		addvar z 18
		ifvare explosionvar 1 ifvarl z 25 setvar z 25
		mulvar paextra -3
		divvar paextra 2
		mulvarvar z paextra
		
		setactor[THISACTOR].xvel x
		setactor[THISACTOR].yvel y
		setactor[THISACTOR].zvel z
		
		getactor[THISACTOR].z z
		subvar z 100
		setactor[THISACTOR].z z
		strength 1
		
	}
	
	getactor[THISACTOR].xvel x
	getactor[THISACTOR].yvel y
	getactor[THISACTOR].zvel z

	addvar z 100
	iffloordistl 1
	{
		ifvarg z 4096
			killit
		
		// x /= 1.5
		mulvar x 10
		divvar x 15
		
		// y /= 1.5
		mulvar y 10
		divvar y 15
		
		shiftvarr z 1
		mulvar z -1 	
		setvar peractor 0
	}
	ifceilingdistl 5
	ifvare peractor 0
	{
		shiftvarr z 1
		mulvar z -1 
		setvar peractor 1
	}
	
	// j = A_MoveSprite(i,&tmpvect,CLIPMASK0);
	movesprite THISACTOR x y z CLIPMASK0 RETURN
	
	// if ((j&49152) == 32768)
	setvarvar r1 RETURN
	andvar r1 49152
	ifvare r1 32768
	{

		// calc wall reflection
		// in src is:
		// k = getangle(
        //              wall[wall[j].point2].x-wall[j].x,
        //              wall[wall[j].point2].y-wall[j].y);
        //        s->ang = ((k<<1) - s->ang)&2047;
	
		// j &= (MAXWALLS-1);
		andvar RETURN 16383
		
		// deaccelerate
		shiftvarr x 2
		shiftvarr y 2
		
		// get wall vector
		// wall[wall[j].point2].x-wall[j].x
		// wall[wall[j].point2].y-wall[j].y
		getwall[RETURN].x r2
		getwall[RETURN].y r3
		getwall[RETURN].point2 r4
		getwall[r4].x r5
		getwall[r4].y r6
		subvarvar r5 r2
		subvarvar r6 r3
		// ( r5,r6 ) - wall vector
		
		
		// calc vector length
		setvarvar r2 x
		mulvarvar r2 r2
		setvarvar r3 y
		mulvarvar r3 r3
		addvarvar r2 r3
		sqrt r2 r2
		
		// get reflect angle
		// s->ang = ((k<<1) - s->ang)&2047;
		getangle tmp r5 r6
		getangle tmp2 x y
		shiftvarl tmp 1
		subvarvar tmp tmp2
		andvar tmp 2047
		
		// calc reflect vector
		// r2 vector lendth
		cos x tmp
		mulvarvar x r2 
		divvar x 16384 
		
		sin y tmp
		mulvarvar y r2
		divvar y 16384
	}
	
	ifhitweapon 
	{
		getactor[THISACTOR].htang ang
		
		cos x2 ang
		sin y2 ang
		
		mulvar x2 4000
		divvar x2 32768
		addvarvar x x2
		
		mulvar y2 4000
		divvar y2 32768
		addvarvar y y2
		
		ifvare CURRWEAP 0 {
			setactorvar[THISACTOR].setspark_phis 2
			setvar in1 15
			setvar in2 JIBS9
			state spawn_multiply
			sound 604
			killit
		}
		
		strength 1
	}
	
	setactor[THISACTOR].xvel x
	setactor[THISACTOR].yvel y
	setactor[THISACTOR].zvel z

	
ends

actor JIBS7FLOOR
	sizeat 32 32 
	ifvare acstat 0 { cstat 256 ifrnd 128 cstator 4 setvar acstat 1 }
	fall
	ifhitweapon ifvare CURRWEAP 0 {
		setactorvar[THISACTOR].setspark_phis 2
		setvar in1 15
		setvar in2 JIBS9
		state spawn_multiply
		sound 604
		killit
	}
enda

actor JIBS7	
	sizeat 32 32 
	cstat 256 
	fall state jib_particle 
	{  
			getactor[THISACTOR].xvel x
			getactor[THISACTOR].yvel y
			getactor[THISACTOR].zvel z
			ifvare x 0 ifvare y 0 { spawn JIBS7FLOOR killit }
	}
enda //pechen

actor JIBS8FLOOR
	sizeat 32 32 
	ifvare peractor 0 { cstat 256 ifrnd 128 cstator 4 setvar peractor 1 }
	fall
	ifhitweapon ifvare CURRWEAP 0 {
		setactorvar[THISACTOR].setspark_phis 2
		setvar in1 15
		setvar in2 JIBS9
		state spawn_multiply
		sound 604
		killit
	}
enda

actor JIBS8	
	sizeat 32 32 
	cstat 256
	fall state jib_particle 
	{  
			getactor[THISACTOR].xvel x
			getactor[THISACTOR].yvel y
			getactor[THISACTOR].zvel z
			ifvare x 0 ifvare y 0 { spawn JIBS8FLOOR killit }
	}
enda //obrubok kishki

actor JIBS9
	sizeat 28 28
	spritepal 2
	ifstrength 0
	{
		getactorvar[THISACTOR].setspark_phis jibs_zv
		ifvare jibs_zv 0
		{
		randvar in1 300  //xvel
		subvar in1 150
		randvar in2 300  //yvel
		subvar in2 150
		randvar in3 -13000 //zvel
		} else ifvare jibs_zv 1
		{
			randvar in1 150  //xvel
			subvar in1 75
			randvar in2 150  //yvel
			subvar in2 75
			randvar in3 -2000 //zvel
		} else ifvare jibs_zv 2
		{
			getactor[THISACTOR].z z
			subvar z 6144
			setactor[THISACTOR].z z
			randvar in1 150  //xvel
			subvar in1 75
			randvar in2 150  //yvel
			subvar in2 75
			randvar in3 -5000 //zvel
		}
		
		state physics_start
		state phys_add_vel
		state physics_end		
		
		randvar sfx_tmp1 100
		addvar sfx_tmp1 1100
		
		setactorvar[THISACTOR].phys_air_damping_x 1050
		setactorvar[THISACTOR].phys_air_damping_y 1050
		setactorvar[THISACTOR].phys_air_damping_z sfx_tmp1		
	
		setactorvar[THISACTOR].phys_gravity_x 0 
		setactorvar[THISACTOR].phys_gravity_y 0
		randvar sfx_tmp1 200
		addvar sfx_tmp1 300
		setactorvar[THISACTOR].phys_gravity_z sfx_tmp1
		strength 1
	}
	
	state physics_start
	state physics_interact_air
	state physics_move
	state physics_end 
	
	iffloordistl 10 { ifrnd 64 spawn BLOODDROP killit }
	ifceilingdistl 10 { killit } 
enda

actor JIBS10 
	sizeat 32 32 
	ifvare acstat 0 { cstat 256 ifrnd 128 cstator 4 setvar acstat 1 }
	fall	
	state jib_particle
	iffloordistl 10
	{
		getactor[THISACTOR].xvel x
		getactor[THISACTOR].yvel y
		ifvarl x 3 ifvarl y 3 { setactor[THISACTOR].zvel 0 }
	}
enda //hand

actor JIBS11
	sizeat 32 32 
	ifvare acstat 0 { cstat 256 ifrnd 128 cstator 4 setvar acstat 1 }
	fall	
	state jib_particle
	iffloordistl 10
	{
		getactor[THISACTOR].xvel x
		getactor[THISACTOR].yvel y
		ifvarl x 3 ifvarl y 3 { setactor[THISACTOR].zvel 0 }
	}
enda //eye

actor JIBS12
	sizeat 32 32 
	ifvare acstat 0 { cstat 256 ifrnd 128 cstator 4 setvar acstat 1 }
	fall	
	state jib_particle
	iffloordistl 10
	{
		getactor[THISACTOR].xvel x
		getactor[THISACTOR].yvel y
		ifvarl x 3 ifvarl y 3 { setactor[THISACTOR].zvel 0 }
	}
enda //red triangle jib

actor MIMJIB1	
ifvare acstat 0 { cstat 256 ifrnd 128 cstator 4 setvar acstat 1 }
	sizeat 32 32
	ifstrength 0
	{
		randvar in1 400  //xvel
		subvar in1 350
		randvar in2 400  //yvel
		subvar in2 350
		randvar in3 -5000 //zvel
		subvar in3 5050
	
		state physics_start
		state phys_add_vel
		state physics_end		
		
		randvar sfx_tmp1 100
		addvar sfx_tmp1 1100
		
		setactorvar[THISACTOR].phys_air_damping_x 1045
		setactorvar[THISACTOR].phys_air_damping_y 1045
		setactorvar[THISACTOR].phys_air_damping_z sfx_tmp1	

		setactorvar[THISACTOR].phys_wall_damping_x 1045 
		setactorvar[THISACTOR].phys_wall_damping_y 1045
		setactorvar[THISACTOR].phys_wall_damping_z 1045 		
	
		setactorvar[THISACTOR].phys_gravity_x 0 
		setactorvar[THISACTOR].phys_gravity_y 0
		randvar sfx_tmp1 200
		addvar sfx_tmp1 300
		setactorvar[THISACTOR].phys_gravity_z sfx_tmp1
		strength 1
	}
	
	state physics_start
	state physics_interact_air
	state physics_move
	state physics_interact_walls
	state physics_end 
	iffloordistl 10 { ifhitweapon { setvar in1 10
	setvar in2 JIBS9
	state spawn_multiply killit } }
enda

actor MIMJIB2	
	sizeat 32 32 
	ifvare acstat 0 { cstat 256 ifrnd 128 cstator 4 setvar acstat 1 }
	fall state jib_particle 
enda

state jibs_state //deadman code

	getactor[THISACTOR].htextra paextra
	ifvarn obj_statnum 15 ifhitweapon
	{
		getactor[THISACTOR].htang htang

		setvar in1 1
		setvar in2 JIBS7
		state spawn_multiply
		setactorvar[RETURN].htangsaved htang
		setactorvar[RETURN].htextrasaved paextra
		ifwasweapon RADIUSEXPLOSION { setactorvar[RETURN].explosionvar 1 }

		setvar in1 10
		setvar in2 JIBS9
		state spawn_multiply
				
		setvar in1 1
		setvar in2 JIBS8
		state spawn_multiply
		setactorvar[RETURN].htangsaved htang
		setactorvar[RETURN].htextrasaved paextra
		ifwasweapon RADIUSEXPLOSION { setactorvar[RETURN].explosionvar 1 }
		
		setvar in1 2
		setvar in2 JIBS10
		state spawn_multiply
		setactorvar[RETURN].htangsaved htang
		setactorvar[RETURN].htextrasaved paextra
		ifwasweapon RADIUSEXPLOSION { setactorvar[RETURN].explosionvar 1 }
		
		setvar in1 2
		setvar in2 JIBS11
		state spawn_multiply
		setactorvar[RETURN].htangsaved htang
		setactorvar[RETURN].htextrasaved paextra
		ifwasweapon RADIUSEXPLOSION { setactorvar[RETURN].explosionvar 1 }
		
		setvar in1 1
		setvar in2 JIBS12
		state spawn_multiply
		setactorvar[RETURN].htangsaved htang
		setactorvar[RETURN].htextrasaved paextra
		ifwasweapon RADIUSEXPLOSION { setactorvar[RETURN].explosionvar 1 }
		
		ifrnd 64 { sound FLSHDOR1 } else ifrnd 64 { sound FLSHDOR2 }
		ifrnd 127 { sound FLSHSTP1 sound FLSHSTP2 }
		state bloodspraystate
		state bloodspraystate
		killit
	}

ends

state deadman_state //deadman code
getactorvar[THISACTOR].obj_statnum obj_statnum
ifvarn obj_statnum 15 {
	getactor[THISACTOR].htextra paextra
	ifhitweapon
	{
		getactor[THISACTOR].htang htang
		setvar in1 10
		setvar in2 JIBS9
		state spawn_multiply
		
		ifrnd 64 { sound FLSHDOR1 } else ifrnd 64 { sound FLSHDOR2 }
		ifrnd 127 { sound FLSHSTP1 sound FLSHSTP2 }
		state bloodspraystate
		killit
	}
}
ends

spritenoshade SPARK1

actor SPARK1 0
	getactorvar[THISACTOR].setspark_phis setspark_phis
	ifvare setspark_phis 1 sizeat 24 24 else ifvare setspark_phis 2 sizeat 24 24 else
	sizeat 16 16
	
	ifstrength 0
	{
		ifvare setspark_phis 1
		{
			randvar in1 1000 
			subvar in1 500
			randvar in2 1000
			subvar in2 500
			randvar in3 -12144
		} else ifvare setspark_phis 2
		{
			randvar in1 500 
			subvar in1 250
			randvar in2 500
			subvar in2 250
			randvar in3 128
		} else
		{
		randvar in1 2000 
		subvar in1 1000
		randvar in2 2000 
		subvar in2 1000
		randvar in3 -25000 
		//( -1000..1000, -1000..1000, -25000..0 )
		}
		state physics_start
		state phys_reset_vel
		state phys_add_vel
		state physics_end		
		
		randvar sfx_tmp1 200
		addvar sfx_tmp1 1100
		//1100..1300
		
		setactorvar[THISACTOR].phys_air_damping_x sfx_tmp1 
		setactorvar[THISACTOR].phys_air_damping_y sfx_tmp1
		setactorvar[THISACTOR].phys_air_damping_z sfx_tmp1		
		
		setactorvar[THISACTOR].phys_gnd_damping_x 1500
		setactorvar[THISACTOR].phys_gnd_damping_y 1500
		setactorvar[THISACTOR].phys_gnd_damping_z 1500 
		
		setactorvar[THISACTOR].phys_wall_damping_x 2000 
		setactorvar[THISACTOR].phys_wall_damping_y 2000
		setactorvar[THISACTOR].phys_wall_damping_z 2000 
		
		setactorvar[THISACTOR].phys_gravity_x 0 
		setactorvar[THISACTOR].phys_gravity_y 0
		
		randvar sfx_tmp1 200
		addvar sfx_tmp1 500  //500..700
		setactorvar[THISACTOR].phys_gravity_z sfx_tmp1
		
		setactorvar[THISACTOR].phys_max_fall_speed 0
		
		movesprite THISACTOR 0 0 -2048 CLIPMASK0 RETURN
		
		strength 1
	}
	
	state physics_start
	
	state physics_interact_air
	state physics_interact_ground
	state physics_move
	state physics_interact_walls
	
	
	andvar phys_movfalg_interanl TOUCH_FLOOR_FLAG 
	ifvare phys_movfalg_interanl TOUCH_FLOOR_FLAG
		killit
	
	state physics_end
	getactorvar[THISACTOR].newscrap_pal newscrap_pal
	setactor[THISACTOR].pal newscrap_pal
	
enda

spritenoshade SPARK2

actor SPARK2 0
	sizeat 24 24
	spawn NEWSMOKE
	
	ifstrength 0
	{
		randvar in1 2000 
		subvar in1 1000
		randvar in2 2000 
		subvar in2 1000
		randvar in3 -25000 
		//( -1000..1000, -1000..1000, -25000..0 )
		
		state physics_start
		state phys_reset_vel
		state phys_add_vel
		state physics_end		
		
		randvar sfx_tmp1 100
		addvar sfx_tmp1 1100
		//1100..1300
		
		setactorvar[THISACTOR].phys_air_damping_x 1050//sfx_tmp1 
		setactorvar[THISACTOR].phys_air_damping_y 1050//sfx_tmp1
		setactorvar[THISACTOR].phys_air_damping_z sfx_tmp1		
		
		setactorvar[THISACTOR].phys_gnd_damping_x 1500
		setactorvar[THISACTOR].phys_gnd_damping_y 1500
		setactorvar[THISACTOR].phys_gnd_damping_z 1500 
		
		setactorvar[THISACTOR].phys_wall_damping_x 2000 
		setactorvar[THISACTOR].phys_wall_damping_y 2000
		setactorvar[THISACTOR].phys_wall_damping_z 2000 
		
		setactorvar[THISACTOR].phys_gravity_x 0 
		setactorvar[THISACTOR].phys_gravity_y 0
		
		randvar sfx_tmp1 200
		addvar sfx_tmp1 500  //500..700
		setactorvar[THISACTOR].phys_gravity_z sfx_tmp1
		
		setactorvar[THISACTOR].phys_max_fall_speed 0
		
		movesprite THISACTOR 0 0 -2048 CLIPMASK0 RETURN
		
		strength 1
	}
	
	state physics_start
	
	state physics_interact_air
	state physics_interact_ground
	state physics_move
	state physics_interact_walls
	
	
	andvar phys_movfalg_interanl TOUCH_FLOOR_FLAG 
	ifvare phys_movfalg_interanl TOUCH_FLOOR_FLAG
		killit
	
	state physics_end
	
enda

actor ZHEAD_BLOOD2
	sizeat 32 32
	ifstrength 0
	{
		getactorvar[THISACTOR].enemycount in1
		randvar in2 32
		addvar in2 16
		getactorvar[THISACTOR].enemycount tmp
		modvar tmp 1024
		setvar in3 -4096
		divvar tmp 7
		ifvarl in1 1024 addvarvar in3 tmp else { subvar tmp -1024 subvarvar in3 tmp }
		
		state physics_start
		state phys_add_vel_ang
		state physics_end		
		
		randvar sfx_tmp1 100
		addvar sfx_tmp1 1100
		
		setactorvar[THISACTOR].phys_air_damping_x 1050
		setactorvar[THISACTOR].phys_air_damping_y 1050
		setactorvar[THISACTOR].phys_air_damping_z sfx_tmp1		
	
		setactorvar[THISACTOR].phys_gravity_x 0 
		setactorvar[THISACTOR].phys_gravity_y 0
		randvar sfx_tmp1 200
		addvar sfx_tmp1 500
		setactorvar[THISACTOR].phys_gravity_z sfx_tmp1
		strength 1
	}
	
	state physics_start
	state physics_interact_air
	state physics_move
	state physics_end 
	
	iffloordistl 10  killit
	ifceilingdistl 10 killit 
enda

state spark_state
getactorvar[THISACTOR].setglass_phis setglass_phis
getactor[THISACTOR].xrepeat xrepeat
ifvarl xrepeat 2 { setactor[THISACTOR].xrepeat 24 setactor[THISACTOR].yrepeat 24 }

	ifstrength 0
	{
		ifvare setglass_phis 1
		{
			randvar in1 500 
			subvar in1 250
			randvar in2 500
			subvar in2 250
			randvar in3 128
		} else
		{
		randvar in1 500 
		subvar in1  250
		randvar in2 500 
		subvar in2 250
		randvar in3 -10000 
		//( -1000..1000, -1000..1000, -25000..0 )
		}
		state physics_start
		state phys_reset_vel
		state phys_add_vel
		state physics_end		
		
		randvar sfx_tmp1 100
		addvar sfx_tmp1 1100
		//1100..1300
		
		setactorvar[THISACTOR].phys_air_damping_x 1050//sfx_tmp1 
		setactorvar[THISACTOR].phys_air_damping_y 1050//sfx_tmp1
		setactorvar[THISACTOR].phys_air_damping_z sfx_tmp1		
		
		setactorvar[THISACTOR].phys_gnd_damping_x 1500
		setactorvar[THISACTOR].phys_gnd_damping_y 1500
		setactorvar[THISACTOR].phys_gnd_damping_z 1500 
		
		setactorvar[THISACTOR].phys_wall_damping_x 2000 
		setactorvar[THISACTOR].phys_wall_damping_y 2000
		setactorvar[THISACTOR].phys_wall_damping_z 2000 
		
		setactorvar[THISACTOR].phys_gravity_x 0 
		setactorvar[THISACTOR].phys_gravity_y 0
		
		randvar sfx_tmp1 200
		addvar sfx_tmp1 500  //500..700
		setactorvar[THISACTOR].phys_gravity_z sfx_tmp1
		
		setactorvar[THISACTOR].phys_max_fall_speed 0
		
		movesprite THISACTOR 0 0 -2048 CLIPMASK0 RETURN
		
		strength 1
	}
	
	state physics_start
	
	state physics_interact_air
	state physics_interact_ground
	state physics_move
	state physics_interact_walls
	
	
	andvar phys_movfalg_interanl TOUCH_FLOOR_FLAG 
	ifvare phys_movfalg_interanl TOUCH_FLOOR_FLAG
		killit
	
	state physics_end
ends

actor GLASS_PART
	setactor[THISACTOR].cstat 2
	state spark_state
enda

spritenoshade SPARK3
spritenoshade SPARK4
spritenoshade SPARK5
spritenoshade SPARK6
spritenoshade SPARK7
actor SPARK3 state spark_state enda
actor SPARK4 state spark_state enda
actor SPARK5 state spark_state enda
actor SPARK6 state spark_state enda
actor SPARK7 state spark_state enda

actor GLASS_PART2 state spark_state enda
actor GLASS_PART3 state spark_state enda
actor GLASS_PART4 state spark_state enda
actor GLASS_PART5 state spark_state enda


actor SPIRALBLOOD
	sizeat 32 32
	
	ifstrength 0
	{
		getactorvar[THISACTOR].enemycount in1
		randvar in2 64
		addvar in2 32
		getactorvar[THISACTOR].enemycount tmp
		modvar tmp 1024
		setvar in3 -7000
		mulvar tmp 7
		ifvarl in1 1024 addvarvar in3 tmp else { subvar tmp 7168 subvarvar in3 tmp }
		
		state physics_start
		state phys_add_vel_ang
		state physics_end		
		
		randvar sfx_tmp1 100
		addvar sfx_tmp1 1100
		
		setactorvar[THISACTOR].phys_air_damping_x 1050
		setactorvar[THISACTOR].phys_air_damping_y 1050
		setactorvar[THISACTOR].phys_air_damping_z sfx_tmp1		
	
		setactorvar[THISACTOR].phys_gravity_x 0 
		setactorvar[THISACTOR].phys_gravity_y 0
		randvar sfx_tmp1 200
		addvar sfx_tmp1 500
		setactorvar[THISACTOR].phys_gravity_z sfx_tmp1
		strength 1
	}
	
	state physics_start
	state physics_interact_air
	state physics_move
	state physics_end 
	
	iffloordistl 10 { ifrnd 32 spawn BLOODDROP killit }
	ifceilingdistl 10 { ifrnd 32 spawn BLOODDROP killit } 
enda

actor SCRAP_PART
	getactor[THISACTOR].xrepeat xrepeat
    ifvarl xrepeat 2 { setactor[THISACTOR].xrepeat 24 setactor[THISACTOR].yrepeat 24 }
	ifstrength 0
	{
		randvar in1 500 
		subvar in1  250
		randvar in2 500 
		subvar in2 250
		randvar in3 -10000 
		//( -1000..1000, -1000..1000, -25000..0 )
		
		state physics_start
		state phys_reset_vel
		state phys_add_vel
		state physics_end		
		
		randvar sfx_tmp1 100
		addvar sfx_tmp1 1100
		//1100..1300
		
		setactorvar[THISACTOR].phys_air_damping_x 1050//sfx_tmp1 
		setactorvar[THISACTOR].phys_air_damping_y 1050//sfx_tmp1
		setactorvar[THISACTOR].phys_air_damping_z sfx_tmp1		
		
		setactorvar[THISACTOR].phys_gnd_damping_x 1500
		setactorvar[THISACTOR].phys_gnd_damping_y 1500
		setactorvar[THISACTOR].phys_gnd_damping_z 1500 
		
		setactorvar[THISACTOR].phys_wall_damping_x 2000 
		setactorvar[THISACTOR].phys_wall_damping_y 2000
		setactorvar[THISACTOR].phys_wall_damping_z 2000 
		
		setactorvar[THISACTOR].phys_gravity_x 0 
		setactorvar[THISACTOR].phys_gravity_y 0
		
		randvar sfx_tmp1 200
		addvar sfx_tmp1 500  //500..700
		setactorvar[THISACTOR].phys_gravity_z sfx_tmp1
		
		setactorvar[THISACTOR].phys_max_fall_speed 0
		
		movesprite THISACTOR 0 0 -2048 CLIPMASK0 RETURN
		
		strength 1
	}
	
	state physics_start
	
	state physics_interact_air
	state physics_interact_ground
	state physics_move
	state physics_interact_walls
	
	
	andvar phys_movfalg_interanl TOUCH_FLOOR_FLAG 
	ifvare phys_movfalg_interanl TOUCH_FLOOR_FLAG
		killit
	
	state physics_end
enda

actor SCRAP2_PART
	sizeat 24 24
	ifstrength 0
	{
		randvar in1 500 
		subvar in1  250
		randvar in2 500 
		subvar in2 250
		randvar in3 -10000 
		//( -1000..1000, -1000..1000, -25000..0 )
		
		state physics_start
		state phys_reset_vel
		state phys_add_vel
		state physics_end		
		
		randvar sfx_tmp1 100
		addvar sfx_tmp1 1100
		//1100..1300
		
		setactorvar[THISACTOR].phys_air_damping_x 1050//sfx_tmp1 
		setactorvar[THISACTOR].phys_air_damping_y 1050//sfx_tmp1
		setactorvar[THISACTOR].phys_air_damping_z sfx_tmp1		
		
		setactorvar[THISACTOR].phys_gnd_damping_x 1500
		setactorvar[THISACTOR].phys_gnd_damping_y 1500
		setactorvar[THISACTOR].phys_gnd_damping_z 1500 
		
		setactorvar[THISACTOR].phys_wall_damping_x 2000 
		setactorvar[THISACTOR].phys_wall_damping_y 2000
		setactorvar[THISACTOR].phys_wall_damping_z 2000 
		
		setactorvar[THISACTOR].phys_gravity_x 0 
		setactorvar[THISACTOR].phys_gravity_y 0
		
		randvar sfx_tmp1 200
		addvar sfx_tmp1 500  //500..700
		setactorvar[THISACTOR].phys_gravity_z sfx_tmp1
		
		setactorvar[THISACTOR].phys_max_fall_speed 0
		
		movesprite THISACTOR 0 0 -2048 CLIPMASK0 RETURN
		
		strength 1
	}
	
	state physics_start
	
	state physics_interact_air
	state physics_interact_ground
	state physics_move
	state physics_interact_walls
	
	
	andvar phys_movfalg_interanl TOUCH_FLOOR_FLAG 
	ifvare phys_movfalg_interanl TOUCH_FLOOR_FLAG
		killit
	
	state physics_end
enda

spritenopal YELLOWLEAFFLOOR
spritenopal GREENLEAFFLOOR
useractor notenemy YELLOWLEAFFLOOR fall sizeat 24 24 killit enda
useractor notenemy GREENLEAFFLOOR fall sizeat 24 24 killit enda 

action NEWSMOKEFRAMES 0 7 1 1 5
actor NEWSMOKE 0 NEWSMOKEFRAMES
setactor[THISACTOR].pal 0
sizeat 32 32 cstat 642
ifactioncount 7 killit
enda

action NAPALMSMOKEFRAMES 0 2 1 1 15
actor NAPALMSMOKE 0 NAPALMSMOKEFRAMES
cstat 642
ifactioncount 2 killit
enda

action NAPALMSMOKEFRAMES1 -2
action NAPALMSMOKEFRAMES2 -1
action NAPALMSMOKEFRAMES3 0
action NAPALMSMOKEFRAMES4 -17 //7280
action NAPALMSMOKEFRAMES5 -16 //7281
action NAPALMSMOKEFRAMES6 -15 //7282
action NAPALMSMOKEFRAMES7 -17
action NAPALMSMOKEFRAMES8 0

actor NAPALMSMOKE2 0 NAPALMSMOKEFRAMES2
spritepal 5
cstat 642
addvar COUNTER 1
ifvare COUNTER 2
{
		setvar COUNTER 0
		ifaction NAPALMSMOKEFRAMES1 { sizeat 12 12 action NAPALMSMOKEFRAMES2 } else
		ifaction NAPALMSMOKEFRAMES2 { sizeat 14 14 action NAPALMSMOKEFRAMES3 } else
		ifaction NAPALMSMOKEFRAMES3 { sizeat 16 16 action NAPALMSMOKEFRAMES4 } else 
		ifaction NAPALMSMOKEFRAMES4 { sizeat 18 18 action NAPALMSMOKEFRAMES5 } else
		ifaction NAPALMSMOKEFRAMES5 { sizeat 20 20 action NAPALMSMOKEFRAMES6 } else
		ifaction NAPALMSMOKEFRAMES6 { sizeat 22 22 action NAPALMSMOKEFRAMES7 } else
		ifaction NAPALMSMOKEFRAMES7 { sizeat 24 24 action NAPALMSMOKEFRAMES8 } else
		ifaction NAPALMSMOKEFRAMES8 killit
}
enda

action FLY 0 3 5 1 5

state np_fire
	iffloordistl 5 
	ifcount 4 
	{ 
		getactorvar[THISACTOR].napalmammo np_ammo
		ifvarg np_ammo 1 subvar np_ammo 2 else subvar np_ammo 1
		setactorvar[THISACTOR].napalmammo np_ammo
		subvar np_ammo 1
		getactor[THISACTOR].ang ang
		ifvarg np_ammo 0 espawn FIREBALL
		setactor[RETURN].ang ang
		setactorvar[RETURN].napalmammo np_ammo
		setactor[RETURN].xrepeat 20
		setactor[RETURN].yrepeat 20 
	}
ends

spritenoshade FIREBALL

useractor notenemy FIREBALL 0 FLY cstat 384 fall
espawn NAPALMSMOKE
setactor[RETURN].xrepeat 18
setactor[RETURN].yrepeat 18

	ifstrength 0
	{
		getactor[THISACTOR].ang ang
		randvar in1 512  //xvel
		subvar in1 256
		addvarvar in1 ang
		setactor[THISACTOR].ang in1
		randvar in2 900  //yvel
		subvar in2 450
		randvar in3 -14000 //zvel
		
		state physics_start
		state phys_add_vel_ang
		state physics_end		
		
		randvar sfx_tmp1 100
		addvar sfx_tmp1 1100
		
		setactorvar[THISACTOR].phys_air_damping_x 1050
		setactorvar[THISACTOR].phys_air_damping_y 1050
		setactorvar[THISACTOR].phys_air_damping_z sfx_tmp1	

		setactorvar[THISACTOR].phys_wall_damping_x 1000 
		setactorvar[THISACTOR].phys_wall_damping_y 1000
		setactorvar[THISACTOR].phys_wall_damping_z 1000 		
	
		setactorvar[THISACTOR].phys_gravity_x 0 
		setactorvar[THISACTOR].phys_gravity_y 0
		randvar sfx_tmp1 200
		addvar sfx_tmp1 300
		setactorvar[THISACTOR].phys_gravity_z sfx_tmp1

		strength 1
	}
	
	state physics_start
	state physics_interact_air
	state physics_move
	state physics_interact_walls
	
	// {  getactorvar[THISACTOR].napalmammo np_ammo addvar np_ammo 1 setactorvar[THISACTOR].napalmammo np_ammo killit }
	
	state physics_end 
	
getactorvar[THISACTOR].napalmammo np_ammo
ifvarand np_ammo 1
{ state np_fire	} else { state np_fire state np_fire }

iffloordistl 5 
{ 
	ifcount 4 
	{ 
		hitradius 1152 16 32 64 128 
		espawn EXPLOSION6 
		setactor[RETURN].xrepeat 32 
		setactor[RETURN].yrepeat 32 
		ifvare QUAKETIME 0 { setvar QUAKETIME 26 setvar QUAKEACTIVE 1 } else { setvar QUAKETIME 36 setvar QUAKEACTIVE 2 }
		globalsound EXPLODCM
		killit
	}
}
	
ifpdistg 16384 { killit }
ifonwater { killit }
enda

spritenopal FLOORSHSHEEL
useractor notenemy FLOORSHSHEEL

	fall sizeat 8 8
	ifspritepal 0
	{
		ifrnd 128 { cstat 4 } else cstat 0
		spritepal 30
	}
	ifcount 1560 { killit }
enda

action ATESLAANIM 0 4 1 1 7
useractor notenemy TESLADECAL 
sizeat 32 32 cstat 145
ifaction 0 action ATESLAANIM
ifactioncount 4 killit
enda

spritenopal FLOORSHEEL
useractor notenemy FLOORSHEEL 

	fall sizeat 8 8
	ifspritepal 0
	{
		getactor[THISACTOR].ang ang
		randvar ang 2048
		setactor[THISACTOR].ang ang
		ifrnd 128 { cstat 4 } else cstat 0
		spritepal 30
	}
	ifcount 1560 { killit }
enda

spritenoshade EXPLOSION3
action EXPLOSION3_FRAMES 0 12 1 1 4
useractor notenemy EXPLOSION3 0 EXPLOSION3_FRAMES
sizeat 48 48 cstat 0
ifactioncount 12 killit

ifspawnedby TNTFLOOR
ifspritepal 0 
{ 
	globalsound EXPLODCM
	hitradius 2048 60 100 160 300
	ifvare QUAKETIME 0 { setvar QUAKETIME 26 setvar QUAKEACTIVE 1 } else { setvar QUAKETIME 26 setvar QUAKEACTIVE 2 }
	setvar in1 10
	setvar in2 SPARK1
	state spawn_multiply
	randvar in1 5
	setvar in2 SPARK2
	state spawn_multiply
	spritepal 30 
}
enda

spritenoshade EXPLOSION4
action EXPLOSION4_FRAMES 0 12 1 1  4
actor EXPLOSION4 1 EXPLOSION4_FRAMES
cstat 128 sizeat 40 40
ifactioncount 12 killit

ifspritepal 0 
{ 
	setvar in1 10
	setvar in2 SPARK1
	state spawn_multiply
	randvar in1 5
	setvar in2 SPARK2
	state spawn_multiply
	spritepal 30 
}
enda

spritenoshade EXPLOSION6
action EXPLOSION6_FRAMES 0 11 1 1 8
useractor notenemy EXPLOSION6 0 EXPLOSION6_FRAMES
ifactioncount 11 killit

ifspritepal 0 
{ 
	ifspawnedby PR_NAPALM
	{
		setvar in1 14
		setvar in2 SPARK1
		state spawn_multiply
		randvar in1 5
		setvar in2 SPARK2
		state spawn_multiply
	}
	ifspawnedby ALTNAPALM
	{
		setvar in1 8
		setvar in2 SPARK1
		state spawn_multiply
		randvar in1 2
		setvar in2 SPARK2
		state spawn_multiply
	}
	ifspawnedby FLARE
	{
		sizeat 64 64
		setvar in1 25
		setvar in2 SPARK1
		state spawn_multiply
		globalsound EXPLODFS
	}
	ifspawnedby SPRAYFLOOR
	{
		setvar in1 8
		setvar in2 SPARK1
		state spawn_multiply
	}
	spritepal 30 
} else ifactioncount 2 ifspawnedby FLARE sizeat 32 32
enda

state headkick
	setvar pspeed 700
	setprojectile[ZOMBIEHEAD].vel pspeed
    ezshoot pspeed ZOMBIEHEAD
	setactorvar[RETURN].zheadkick spriteid
	sound PUNT
	getactor[spriteid].ang tmp
	setactor[RETURN].ang tmp
	getactor[THISACTOR].z z
	setactor[RETURN].z z
	setactorvar[RETURN].active tx_can
	killit 
ends

actor ZOMBIEHEAD2 fall spawn ZHEADFLOOR killit enda

eventloadactor ZHEADFLOOR
setvar COUNTER 50
enda

spritenoshade ZHEADFLOOR
useractor notenemy ZHEADFLOOR
getactor[THISACTOR].sectnum tmp
getsector[tmp].floorshade enemyshade
setactor[THISACTOR].shade enemyshade
cstator 257 sizeat 32 32 fall
	
ifvarl COUNTER 50 addvar COUNTER 1
switch COUNTER
case 5 case 6 case 7 case 8 case 9 case 10
 case 22 case 23 case 24 case 25 case 26 case 27 case 28 case 29
case 40 case 41 case 42 case 43 case 44 case 45 case 46 case 47 case 48 case 49
	setvarvar utl_tmp1 1
	whilevarn utl_tmp1 0
	{
		espawnvar ZHEAD_BLOOD2
		getactor[THISACTOR].z z
		subvar z 4096
		setactor[RETURN].z z
		subvar utl_tmp1 1
	}
	randvar peractor 2048
	setactorvar[RETURN].enemycount peractor
break
endswitch
	
getactor[THISACTOR].yvel tx_can

ifpdistl 812 
ifvarg pspeed 0
{ 
	mulvar pspeed 8
	setprojectile[ZOMBIEHEAD].vel pspeed ifvarg pspeed 256 
	{ mulvar pspeed 4 ezshoot pspeed ZOMBIEHEAD } else 
	eshoot ZOMBIEHEAD sound PUNT
	getplayer[THISACTOR].ang tmp
	setactor[RETURN].ang tmp
	getactor[THISACTOR].z z
	setactor[RETURN].z z
	addvar puntcount 1
	setactorvar[RETURN].puntcount puntcount
	setactorvar[RETURN].active tx_can
	killit 
}

findnearactor ZOMBIE 512 spriteid
ifvarn spriteid -1 { getactor[spriteid].extra extra ifvarg extra 0 state headkick }
findnearactor HERETIC 512 spriteid
ifvarn spriteid -1 { getactor[spriteid].extra extra ifvarg extra 0 state headkick }


ifhitweapon { 
	setvar in1 5
	setvar in2 JIBS9
	state spawn_multiply killit 
}
enda

state bloodsplatstate
ifvare wallblood 1
{
	cstat 82
	addvar COUNTER 1
	ifvarl COUNTER 35
	{
		getactor[THISACTOR].xrepeat blood_xsize
		getactor[THISACTOR].yrepeat blood_ysize
		ifcount 5
		{
			setvarvar tmp blood_ysize
			divvarvar tmp blood_xsize
			ifvarl tmp 2 
			{
				getactor[THISACTOR].z z
				addvar z 1024 
				setactor[THISACTOR].z z
				addvarvar blood_ysize 4
			}
			setactor[THISACTOR].yrepeat blood_ysize
			resetcount
		}
	}
}
ends

useractor 4 BLOODSPLAT5 state bloodsplatstate enda
useractor 4 BLOODSPLAT6 state bloodsplatstate enda
