action FRAME1 0 1 5 1 1
action FRAME2 5 1 5 1 1
action FRAME3 10 1 5 1 1
action FRAME4 15 1 5 1 1
action FRAME5 20 1 5 1 1

action FRAMEMINUS1 -1
action FRAMEMINUS2 -2
action FRAMEMINUS3 -3
action FRAMEMINUS4 -4
action FRAMEMINUS5 -5
action FRAMEMINUS6 -6
action FRAMEMINUS7 -7

action FRAME_FRAME1 0 1 1 1 1
action FRAME_FRAME2 1 1 1 1 1
action FRAME_FRAME3 2 1 1 1 1
action FRAME_FRAME4 3 1 1 1 1
action FRAME_FRAME5 4 1 1 1 1
action FRAME_FRAME6 5 1 1 1 1
action FRAME_FRAME7 6 1 1 1 1
action FRAME_FRAME8 7 1 1 1 1

action FLAME2_FRAME1 1 1 1 1 1
action FLAME2_FRAME2 2 1 1 1 1
action FLAME2_FRAME3 -15 1 1 1 1
action FLAME2_FRAME4 -13 1 1 1 1
action FLAME2_FRAME5 -14 1 1 1 1
action FLAME2_FRAME6 -15 1 1 1 1
action FLAME2_FRAME7 2 1 1 1 1
action FLAME2_FRAME8 1 1 1 1 1
action FLAME2_FRAME9 0 1 1 1 1
action FLAME2_FRAME10 1362 1 1 1 1
action FLAME2_FRAME11 1364 1 1 1 1

action NULL 0
action ONE 1
action TWO 2
action THREE 3
action FOUR 4
action FIVE 5

action ACTIVE 1

action DELAY1 0
action DELAY2 0

//polymer light spawn
state spawnlight
	setactorvar[RETURN].light_spawner THISACTOR
	setactor[RETURN].lotag 49 
	setactor[RETURN].hitag light_radius 
	setactor[RETURN].xvel red 
	setactor[RETURN].yvel green
	setactor[RETURN].zvel blue
	setactor[RETURN].picnum SECTOREFFECTOR
	changespritestat RETURN 3
ends

state other_item
ifvare DOCTORSBAGAM 0 
ifvare DIVINGSUITAM 0 
ifvare CRYSTALLBALLAM 0 
ifvare BEASTVISIONAM 0 
ifvare BOOTSOFJUMPINGAM 0 
	setplayer[THISACTOR].inven_icon 0 else {
	setvar tmp 8
	whilevarn tmp 13
	{
		ifvare tmp 8 ifvarg DOCTORSBAGAM 0 setplayer[THISACTOR].inven_icon 8 else
		ifvare tmp 9 ifvarg DIVINGSUITAM 0 setplayer[THISACTOR].inven_icon 9 else
		ifvare tmp 10 ifvarg CRYSTALLBALLAM 0 setplayer[THISACTOR].inven_icon 10 else
		ifvare tmp 11 ifvarg BEASTVISIONAM 0 setplayer[THISACTOR].inven_icon 11 else
		ifvare tmp 12 ifvarg BOOTSOFJUMPINGAM 0 setplayer[THISACTOR].inven_icon 12
		addvar tmp 1
	}
}
ends

state newfirestate
ifinwater { setvar burningguyactive 0 setvar flamedamage 0 }
else {
	eshoot NEWFIRE
	setactorvar[RETURN].newfire_size sprite[THISACTOR].xrepeat
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	setvarvar yrepeat height
	setvarvar x2 x
	addvarvar x2 width
	randvar ang 2048
	ifrnd 128 mulvar ang -1
	rotatepoint x y x2 y ang x3 y3
	setactor[RETURN].x x3
	setactor[RETURN].y y3
	
	getactor[THISACTOR].z z
	randvar tmp 16
	ifvarn tmp 0 divvarvar yrepeat tmp
	subvarvar z yrepeat
	ifvare sprite[THISACTOR].picnum TCHERNOBOG
		addvar z 8192
	ifvare sprite[THISACTOR].picnum ZOMBIE
		addvar z 8192	
	ifvare sprite[THISACTOR].picnum CIVILIAN
		addvar z 8192
	setactor[RETURN].z z

	getactor[THISACTOR].extra extra
	getactor[THISACTOR].picnum picnum
	ifvare picnum APLAYER
	ifvarn godmode 1
	ifvarn DEATHMASK_ON 1
	ifvarg extra 0
	{
		ifvare fireshield 0 { ifcount 2 { subvar extra 1 resetcount } } else
		{ ifcount 3 { subvar extra 1 subvar fireshield 1 resetcount } }
		ifvarl extra 1 { setvar extra 1 setvar burningguyactive 1 }
		setactor[THISACTOR].extra extra
	} else
	ifvarn picnum TCHERNOBOG
	ifvarn picnum APLAYER
	ifvarn picnum GARGOYLE
	ifvarn picnum HELLDOG
	ifvarn picnum PHANTASM
	ifvarn picnum BEAST
	ifvarg extra 0 {
		ifcount 2 {
			subvar extra 1
			ifvarl extra 1 { setvar extra 1 setvar burningguyactive 1 }
			ifvare picnum POD { ifvarn sprite[THISACTOR].pal 2
				setactor[THISACTOR].extra extra
			}
			else ifvare picnum TENTACLE { ifvarn sprite[THISACTOR].pal 2
				setactor[THISACTOR].extra extra
			} else setactor[THISACTOR].extra extra
			resetcount
		}
	} else 
	ifvare picnum GARGOYLE
	ifvarg extra 0 {
		getactor[THISACTOR].pal pal
		ifvare pal 0
		{
			ifcount 2 {
			subvar extra 1
			ifvarl extra 1 { setvar extra 1 setvar burningguyactive 1 }
			setactor[THISACTOR].extra extra
			resetcount
			}
		}
	}
}
ends

state spawn_sparks
	
	setvarvar tmp in1
	whilevarn tmp 0
	{
		espawnvar in2
		getwall[broken_spw].x x
		getwall[broken_spw].y y
		getwall[broken_spw].pal broken_pal
		
		getwall[broken_spw].nextsector sectorid
		ifvarn sectorid -1
		{
			getsector[sectorid].floorz z
			getsector[sectorid].ceilingz z2
			subvarvar z2 z
			randvarvar broken_randz z2
			addvarvar z broken_randz
			setactor[RETURN].z z
		}
				
		getwall[broken_spw].point2 broken_spw2
		getwall[broken_spw2].x x2
		getwall[broken_spw2].y y2
		subvarvar x2 x
		subvarvar y2 y
		setvarvar d_x x2
		setvarvar d_y y2
		mulvarvar d_x d_x
		mulvarvar d_y d_y
		addvarvar d_x d_y
		sqrt d_x wall_len

		randvarvar broken_randx x2
		randvarvar broken_randy y2
		addvarvar x broken_randx
		addvarvar y broken_randy
		setactor[RETURN].x x
		setactor[RETURN].y y
		divvarvar wall_len 64
		ifvarvarl wall_len 24 setvar wall_len 24
		setactor[RETURN].xrepeat wall_len
		setactor[RETURN].yrepeat wall_len
		setactor[RETURN].pal broken_pal
		subvar tmp 1
	}
ends

state brokenwalls
	ifvare wall[broken_id].lotag 511
	ifvarand wall[broken_id].cstat 80
	{
		setvarvar broken_spw broken_id
		switch wall[broken_id].overpicnum 
		default //case 5386
		setwall[broken_id].cstat 32768
		getwall[broken_id].nextwall broken_id
		setwall[broken_id].cstat 32768
		setvar in1 30
		setvar in2 GLASS_PART 
		state spawn_sparks 
		setvar in2 SCRAP_PART 
		state spawn_sparks
		soundonce 19
		break
		endswitch
		
		ifvarn wall[broken_id].hitag 0 {
			setvar sectorid 0
			whilevarvarn sectorid NUMSECTORS {
				headspritesect spriteid sectorid
				whilevarn spriteid -1 {
					ifvarvare wall[broken_id].hitag actorvar[spriteid].se_xvel { setactorvar[spriteid].active 1  }
					nextspritesect spriteid spriteid
				}
				addvar sectorid 1
			}
		}	
	}
ends

state broken_proj
		setvar wallid2 0
		setvarvar wallnum NUMWALLS
		subvar wallnum 1
		whilevarvarn wallid2 wallnum
		{
			ifvarn wall[wallid2].hitag 0 ifvarn wall[wallid].hitag 0
			ifvarvare wall[wallid].hitag wall[wallid2].hitag
			{
			   setvarvar broken_id wallid2
			   state brokenwalls
			}
			addvar wallid2 1
		}
		setvarvar broken_id wallid 
		state brokenwalls 	
ends