//DudeInfo 221

define PODHEALTH 50
define POD2HEALTH 100
define PODMASS 65535
define PODHEIGHT 40
define PODHEARDIST 1365 //2048
define PODSEEDIST 7509 //11264
define PODSEEDIST2 10240 //15360
define PODPERIPHERY 1024
define PODSPEED 0
define PODANGSPEED 384
define PODALERT 32768

define PODSLEEP 5

action APODIDLE 0 1 1 1 1
action APODSTAND 4 1 1 1 1
action APODOPEN 1 4 1 1 10
action APODCLOSE 4 4 1 -1 10
action APODATTACK 3 4 1 -1 10
action APODDYING1 -7 5 1 1 10
action APODDYING3 -20 6 1 1 10
action APODDEAD3 -14 1 1 1 1

action APODDEAD1 -1 1 1 1 1
action APODDYING2 23 5 1 1 10
action APODDEAD2 28 1 1 1 1

define GREENBALL 6980
define GREENPOOL 6981
define GREENSPRAY 9145
define GREENSPRAY2 9143

define FIREBALL2 7140
define FIRESPRAY 9150
define FIRESPRAY2 9148

spriteshadow POD
spriteshadow GREENBALL
spriteshadow FIREBALL2
spritenoshade POD
spritenoshade GREENBALL
spritenoshade FIREBALL2

gamevar ballxvel 0 2
gamevar ballyvel 0 2
gamevar ballzvel 0 2

actor FIRESPRAY2
	setvar width 48

	ifcount 5 { state newfirestate resetcount }
	sizeat 32 32 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 { killit }
enda

actor FIRESPRAY
	sizeat 32 32
	spawn FIRESPRAY2
	
	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 { killit }
	ifceilingdistl 10 { killit } 
enda

actor GREENSPRAY2
	sizeat 32 32 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 { killit }
enda

actor GREENSPRAY
	sizeat 32 32
	spawn GREENSPRAY2
	
	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 { killit }
	ifceilingdistl 10 { killit } 
enda

actor GREENPOOL
	cstat 35
	sizeat 32 32
	
	ifcount 300
		killit
enda

actor GREENBALL
	sizeat 32 32
	cstat 128
	
	getactor[THISACTOR].mdflags  tmp
	orvar  tmp 16
	setactor[THISACTOR].mdflags  tmp
	
	state AirDrag
	
	state GetSpriteExtents
	
	setvarvar floordist zbot
	subvarvar floordist sprite[THISACTOR].z
	divvarvar floordist 5
	setvarvar ceildist sprite[THISACTOR].z
	subvarvar ceildist ztop
	divvarvar ceildist 5
	setvarvar cm_clipdist sprite[THISACTOR].clipdist
	shiftvarl cm_clipdist 2
	
	setvarvar xvel sprXVel
	shiftvarr xvel 12
	shiftvarl xvel 14
	setvarvar yvel sprYVel
	shiftvarr yvel 12
	shiftvarl yvel 14

	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].z z
	getactor[THISACTOR].sectnum nsector

	clipmove movehit x y z nsector xvel yvel cm_clipdist floordist ceildist CLIPMASK0 
	
	ifvare nsector -1 {
		setvarvar nsector sprite[THISACTOR].sectnum
	} else {
		setactor[THISACTOR].x x
		setactor[THISACTOR].y y
		setactor[THISACTOR].z z
	}
	
	ifvarn sprZVel 0 {
		setvarvar tmp sprZVel
		shiftvarr tmp 8
		getactor[THISACTOR].z z
		addvarvar z tmp
		setactor[THISACTOR].z z
	}
	
	getzrange sprite[THISACTOR].x sprite[THISACTOR].y sprite[THISACTOR].z nsector ceilz ceilhit floorz floorhit cm_clipdist CLIPMASK0
	
	state GetSpriteExtents
	
	ifvarvarl zbot floorz {
		addvarvar sprZVel 58254
		getactor[THISACTOR].z z
		addvarvar z 455
		setactor[THISACTOR].z z
	} else {
		setvarvar tmp movehit
		andvar tmp 0xE000
		ifvare tmp 0xC000 {
			setvarvar spriteid movehit
			andvar spriteid 0x1FFF
			ifvarvarn spriteid spawnedby {
				setactor[spriteid].htextra 2
				setactor[spriteid].htowner spawnedby
				ifvarvare spriteid PLAYERID {
					setvar paextra 2
					state checkb_armor
				}
				killit
			}
		} else {
			setvarvar tmp floorhit
			andvar tmp 0xE000
			ifvare tmp 0xC000 {
				setvarvar spriteid floorhit
				andvar spriteid 0x1FFF
				ifvarvarn spriteid spawnedby {
					setactor[spriteid].htextra 2
					setactor[spriteid].htowner spawnedby
					ifvarvare spriteid PLAYERID {
						setvar paextra 2
						state checkb_armor
					}
					killit
				}
			} else { 
				eqspawn GREENPOOL
				getflorzofslope sprite[RETURN].sectnum sprite[RETURN].x sprite[RETURN].y floorz
				randvar tmp 1000
				subvar tmp 500
				getactor[RETURN].x x
				addvarvar x tmp
				setactor[RETURN].x x
				randvar tmp 1000
				subvar tmp 500
				getactor[RETURN].y y
				addvarvar y tmp
				setactor[RETURN].y y
				setactor[RETURN].z floorz

				//distancedamage
				setvar DIST 133
				mulvar DIST 16
				
				getactor[THISACTOR].x x
				getactor[THISACTOR].y y
				getactor[THISACTOR].z z
				getactor[PLAYERID].x x2
				getactor[PLAYERID].y y2
				getactor[PLAYERID].z z2

				subvarvar x2 x
				subvarvar y2 y
				subvarvar z2 z
				shiftvarr z2 4
				mulvarvar x2 x2
				mulvarvar y2 y2
				mulvarvar z2 z2
				addvarvar x2 y2
				addvarvar x2 z2
				sqrt x2 len

				ifvarvarl len DIST {
					setvarvar damagez DIST
					subvarvar damagez len
					mulvarvar damagez 20 //damageHit
					divvarvar damagez DIST
					
					setactor[PLAYERID].htextra damagez
					setactor[PLAYERID].htowner spawnedby
					
					setvarvar paextra damagez
					state checkb_armor
				}
				killit
			}
		}
	}
enda

state fireballexplode
	espawn EXPLOSION6
	setactor[RETURN].xrepeat 48
	setactor[RETURN].yrepeat 48
	setactor[RETURN].cstat 0
	soundonce EXPLODCL
	
	ldist len THISACTOR PLAYERID
	ifvarl len 2048 {
		getactorvar[PLAYERID].flamedamage tmp 
		addvar tmp 50 
		setactorvar[PLAYERID].flamedamage tmp 
	}	

	setvar in1 2
	setvar in2 FIRESPRAY
	state spawn_multiply
ends

actor FIREBALL2
	sizeat 32 32
	cstat 128
	
	getactor[THISACTOR].mdflags  tmp
	orvar  tmp 16
	setactor[THISACTOR].mdflags  tmp
	
	state AirDrag
	
	state GetSpriteExtents
	
	setvarvar floordist zbot
	subvarvar floordist sprite[THISACTOR].z
	divvarvar floordist 5
	setvarvar ceildist sprite[THISACTOR].z
	subvarvar ceildist ztop
	divvarvar ceildist 5
	setvarvar cm_clipdist sprite[THISACTOR].clipdist
	shiftvarl cm_clipdist 2
	
	setvarvar xvel sprXVel
	shiftvarr xvel 12
	shiftvarl xvel 14
	setvarvar yvel sprYVel
	shiftvarr yvel 12
	shiftvarl yvel 14

	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].z z
	getactor[THISACTOR].sectnum nsector

	clipmove movehit x y z nsector xvel yvel cm_clipdist floordist ceildist CLIPMASK0 
	
	ifvare nsector -1 {
		setvarvar nsector sprite[THISACTOR].sectnum
	} else {
		setactor[THISACTOR].x x
		setactor[THISACTOR].y y
		setactor[THISACTOR].z z
	}
	
	ifvarn sprZVel 0 {
		setvarvar tmp sprZVel
		shiftvarr tmp 8
		getactor[THISACTOR].z z
		addvarvar z tmp
		setactor[THISACTOR].z z
	}
	
	getzrange sprite[THISACTOR].x sprite[THISACTOR].y sprite[THISACTOR].z nsector ceilz ceilhit floorz floorhit cm_clipdist CLIPMASK0
	
	state GetSpriteExtents
	
	ifvarvarl zbot floorz {
		addvarvar sprZVel 58254
		getactor[THISACTOR].z z
		addvarvar z 455
		setactor[THISACTOR].z z
	} else {
		setvarvar tmp movehit
		andvar tmp 0xE000
		ifvare tmp 0xC000 {
			setvarvar spriteid movehit
			andvar spriteid 0x1FFF
			ifvarvarn spriteid spawnedby {
				
				state fireballexplode
				
				killit
			}
		} else {
			setvarvar tmp floorhit
			andvar tmp 0xE000
			ifvare tmp 0xC000 {
				setvarvar spriteid floorhit
				andvar spriteid 0x1FFF
				ifvarvarn spriteid spawnedby {
					
					state fireballexplode
					
					killit
				}
			} else { 
				
				state fireballexplode

				killit
			}
		}
	}
enda

state pod_init
	//aiInit
	
	getactor[THISACTOR].mdflags  tmp
	orvar  tmp 16
	setactor[THISACTOR].mdflags  tmp
	
	setvar ai_animation_old -1
	setvar ai_aistate IDLE
	setvar ai_switchaction 1

	setvarvar ai_target -1
	setvarvar ai_targetx 0
	setvarvar ai_targety 0
	setvarvar ai_targetz 0
	setvar ai_statetimer 0
	
	setvar ai_speed PODSPEED
	setvar ai_angspeed PODANGSPEED
	setvar ai_periphery PODPERIPHERY
	setvar ai_eyeheight PODHEIGHT
	setvar ai_heardist PODHEARDIST
	setvar ai_alertchance PODALERT
	setvar ai_mass PODMASS
	
	ifvare sprite[THISACTOR].pal 0 {
		setactor[THISACTOR].extra PODHEALTH
		setvar ai_seedist PODSEEDIST
	}
	else ifvare sprite[THISACTOR].pal 2 {
		setactor[THISACTOR].extra POD2HEALTH
		setvar ai_seedist PODSEEDIST2
	}
	
	orvar sprFlags kAttrGravity
	orvar sprFlags kAttrFalling
	
	setactor[THISACTOR].xrepeat 28
	setactor[THISACTOR].yrepeat 28
	
	getactor[THISACTOR].cstat acstat
	ifvarand acstat 256 nullop else
	orvar acstat 256
	ifvarand acstat 128 nullop else
	orvar acstat 128
	ifvarand acstat 1 nullop else
	orvar acstat 1
	setactor[THISACTOR].cstat acstat
	
	setvar width 128
	setvar height 2048
ends

eventloadactor POD
	state pod_init
enda

state apodswitchaction

	ifvare ai_aistate IDLE ifvarn ai_animation_old IDLE { 
		action APODIDLE
		setvar ai_animation_old IDLE
	}
	ifvare ai_aistate SEARCH ifvarn ai_animation_old GOTO {
		action APODSTAND
		setvar ai_animation_old GOTO
	}
	ifvare ai_aistate CHASE ifvarn ai_animation_old GOTO {	
		ifaction APODIDLE action APODOPEN else
		action APODSTAND
		setvar ai_animation_old GOTO
	}
	ifvare ai_aistate GOTO ifvarn ai_animation_old GOTO {
		action APODSTAND
		setvar ai_animation_old GOTO
	}
	ifvare ai_aistate HACK ifvarn ai_animation_old HACK {
		action APODATTACK
		setvar ai_animation_old HACK
	}
	ifvare ai_aistate PODSLEEP ifvarn ai_animation_old PODSLEEP {
		action APODCLOSE
		setvar ai_animation_old PODSLEEP
	}
			
ends

state podSearch
	setvarvar ain1 ai_goalang
	state aiChooseDirection
	state aiThinkTarget
ends

state podGoto
	setvarvar se_x ai_targetx
	subvarvar se_x sprite[THISACTOR].x
	setvarvar se_y ai_targety
	subvarvar se_y sprite[THISACTOR].y
	
	getangle ain1 se_x se_y
	setvarvar ai_tmp1 ain1
	state aiChooseDirection

	mulvarvar se_x se_x
	mulvarvar se_y se_y
	addvarvar se_x se_y
	sqrt se_x targetdist

	ifvarl targetdist 512 {
		setvarvar ang sprite[THISACTOR].ang
		subvarvar ang ai_tmp1
		ifvarl ang 0
			mulvar ang -1
			
		ifvarvarl ang ai_periphery {
			setvar ai_aistate SEARCH
			setvar ai_statetimer 1800
			setvar ai_next IDLE
			setvar ai_switchaction 1
		}
	}
	state aiThinkTarget
ends

state podChase
	ifvare ai_target -1 {
		setvar ai_aistate PODSLEEP //Sleep
		setvar ai_switchaction 1
	}
	else {
		setvarvar se_x ai_targetx
		subvarvar se_x sprite[THISACTOR].x
		setvarvar se_y ai_targety
		subvarvar se_y sprite[THISACTOR].y

		// check target
		getangle ain1 se_x se_y
		setvarvar ai_tmp1 ain1
		
		state aiChooseDirection

		// target is dead
		ifvarl sprite[ai_target].extra 1 {
			setvar ai_aistate SEARCH
			setvar ai_statetimer 1800
			setvar ai_next IDLE
			setvar ai_switchaction 1
		}
		else {
			mulvarvar se_x se_x
			mulvarvar se_y se_y
			addvarvar se_x se_y
			sqrt se_x targetdist

			ifvarvarl targetdist ai_seedist {
			
				setvarvar ai_nangle ai_tmp1

				setvarvar z ai_eyeheight
				setvarvar tmp sprite[THISACTOR].yrepeat
				shiftvarl tmp 2
				mulvarvar z tmp
				
				setvarvar tmp sprite[THISACTOR].z
				subvarvar tmp z
				
				// is there a line of sight to the target?
				ifvarg sprite[ai_target].sectnum -1 
					cansee sprite[ai_target].x sprite[ai_target].y sprite[ai_target].z sprite[ai_target].sectnum sprite[THISACTOR].x sprite[THISACTOR].y tmp sprite[THISACTOR].sectnum see
				else setvar see 0
				
				ifvare see 1 {
					setvarvar ai_losang 1024
					addvarvar ai_losang ai_nangle
					subvarvar ai_losang sprite[THISACTOR].ang
					andvar ai_losang 2047
					subvarvar ai_losang 1024
					
					ifvarl ai_losang 0
						mulvar ai_losang -1
				
					// is the target visible?

					ifvarvarl ai_losang ai_periphery {
						setvarvar ai_target PLAYERID
						setvarvar ai_targetx sprite[ai_target].x
						setvarvar ai_targety sprite[ai_target].y
						setvarvar ai_targetz sprite[ai_target].z

						ifvarl ai_losang 85 {
							setvar ai_aistate HACK
							setvar ai_statetimer 600
							setvar ai_next CHASE
							setvar ai_switchaction 1
						}
						
					} else {
						setvar ai_aistate PODSLEEP
						setvar ai_switchaction 1
						setvarvar ai_target -1
					}
				} else {
					setvar ai_aistate PODSLEEP
					setvar ai_switchaction 1
					setvarvar ai_target -1
				}
			} else {
				setvar ai_aistate PODSLEEP
				setvar ai_switchaction 1
				setvarvar ai_target -1
			}		
		}
	}
ends

state aiTentacle_pHackCallback

	setvarvar se_x ai_targetx
	subvarvar se_x sprite[THISACTOR].x
	setvarvar se_y ai_targety
	subvarvar se_y sprite[THISACTOR].y
	setvarvar se_z ai_targetz
	subvarvar se_z sprite[THISACTOR].z
	
	randvar tmp 2000
	subvarvar tmp 1000
	
	addvarvar se_x tmp
	addvarvar se_y tmp
	addvarvar se_z 5333

	mulvarvar se_x se_x
	mulvarvar se_y se_y
	addvarvar se_x se_y
	sqrt se_x targetdist
	
	setvarvar tmp ai_seedist
	divvarvar tmp 10
	
	ifvarvarg targetdist tmp {
		divvarvar targetdist 540

		shiftvarl targetdist 23
		divvarvar targetdist 120 ///velocity
		
		shiftvarr se_z 7
		subvarvar se_z 14500 //nSlope

		cos mycos sprite[THISACTOR].ang
		sin mysin sprite[THISACTOR].ang
		
		mulscale RETURN 128 mycos 16
		getactor[THISACTOR].x se_x
		addvarvar se_x RETURN
		mulscale RETURN 128 mysin 16
		getactor[THISACTOR].y se_y
		addvarvar se_y RETURN
		
		ifvare sprite[THISACTOR].pal 0
			espawn GREENBALL
		else ifvare sprite[THISACTOR].pal 2
			espawn FIREBALL2

		soundonce PODSPIT2
		setactorvar[RETURN].spawnedby THISACTOR
		setactor[RETURN].x se_x
		setactor[RETURN].y se_y
		getactor[THISACTOR].z z
		subvarvar z 5333
		setactor[RETURN].z z

		mulscale ballxvel targetdist mycos 14
		mulscale ballyvel targetdist mysin 14
		mulscale ballzvel targetdist se_z 14
		
		setactorvar[RETURN].sprXVel ballxvel
		setactorvar[RETURN].sprYVel ballyvel
		setactorvar[RETURN].sprZVel ballzvel
		
		ifvare sprite[THISACTOR].pal 0 {
			setvar in1 4
			setvar in2 GREENSPRAY
			state spawn_multiply
		}
		else ifvare sprite[THISACTOR].pal 2 {
			setvar in1 4
			setvar in2 FIRESPRAY
			state spawn_multiply
		}
	}
ends 

useractor notenemy POD

	ifaction NO {
		ifvare sprite[THISACTOR].pal 0
			setactor[THISACTOR].extra PODHEALTH
		else ifvare sprite[THISACTOR].pal 2
			setactor[THISACTOR].extra POD2HEALTH
		action 1
	}
	
	ifvare active 1 {
		setvarvar ai_state 1
		setvarvar ai_aistate SEARCH
		setvar ai_statetimer 1800
		setvar ai_next IDLE
		setvar ai_switchaction 1
		setvar active 0
	}
	
	ifvare VISION 1 ifvarg sprite[THISACTOR].extra 0 { setactor[THISACTOR].shade -127 }
	
	ifvarg flamedamage 0 { subvar flamedamage 1 state newfirestate } 
	ifinwater setvar flamedamage 0

	// process explosions
	findnearspritevar EXPLOSION2 1536 ai_naffected
	ifvare ai_naffected -1 findnearspritevar EXPLOSION3 1536 ai_naffected
	ifvare ai_naffected -1 findnearspritevar EXPLOSION4 1536 ai_naffected
	ifvare ai_naffected -1 findnearspritevar EXPLOSION6 1536 ai_naffected
	ifvarg ai_naffected 0 {
		setactor[THISACTOR].htpicnum RADIUSEXPLOSION
	}
	
	ifvare ai_switchaction 1 {
		state apodswitchaction
		setvar ai_switchaction 0
	}
	
	state AirDrag
	state MoveDude
	
	//aiProcessDudes
	// don't manipulate dead guys
	ifvarg sprite[THISACTOR].extra 0 ifvare ai_dead 0 {
	
		ifvarg ai_statetimer 0 {
			subvar ai_statetimer 4
		} else setvar ai_statetimer 0

		ifvarl ai_thinktick 3 {
			addvar ai_thinktick 1
		} else setvar ai_thinktick 0

		ifvare ai_aistate IDLE {
			setvar ai_statetimer 0
			setvar ai_next -1
			state aiThinkTarget
		}
		
		ifvare ai_aistate SEARCH {
			state aiMoveTurn
			ifvare ai_thinktick 0 { 
				state podSearch	
			}
		}
		
		ifaction APODOPEN {
			soundonce PODOPEN
			ifactioncount 4 
				action APODSTAND
		}
		ifaction APODCLOSE {
			ifactioncount 4 {
				action APODIDLE
				setvar ai_animation_old -1
				setvar ai_aistate IDLE
				setvar ai_statetimer 0
				setvar ai_next -1
			}
		}
		
		ifvare ai_aistate HACK {
			ifaction APODATTACK {
				ifactioncount 2 {
					state aiTentacle_pHackCallback
					action APODSTAND
				}
			} 
		}

		ifvare ai_aistate CHASE {	
			state aiMoveTurn
			ifvare ai_thinktick 0 state podChase
		}
		ifvare ai_aistate GOTO {
			state aiMoveTurn
			ifvare ai_thinktick 0 state podGoto
		} 

		ifvare ai_statetimer 0 ifvarn ai_next -1 {
			setvarvar ai_aistate ai_next
			setvar ai_switchaction 1
			setvar ai_next -1
		}	

	ifvare burningguyactive 1 ifvare sprite[THISACTOR].pal 0 { 
		addkills 1
		killit
	}		

		// process dudes for recoil
		ifvarg sprite[THISACTOR].htextra 0 { //cumulDamage[nXSprite] >= pDudeInfo.hinderDamage << 4
			getactor[THISACTOR].extra tmp
			subvarvar tmp sprite[THISACTOR].htextra
			setactor[THISACTOR].extra tmp
			setvar ai_animation_old -1
			getactor[THISACTOR].htpicnum enemy_htpic 
			setactor[THISACTOR].htextra -1
		}		
	} else { 
		ifvarg sprite[THISACTOR].htextra 0 
			setactor[THISACTOR].htextra -1
		
		ifvare ai_dead 0 {
			ifrnd 64 soundonce PODDIE1 else ifrnd 64 soundonce PODDIE2 else soundonce PODDIE3
			ifvarg enemy_htpic 0 { //projectile trigger
				ifvare triggerlink 6 {
					ifvarn enemy_htpic 2595  
						setvarvar hitspritesaved THISACTOR
				}
				ifvare triggerlink 3 
					setvarvar hitspritesaved THISACTOR				
			} else {
				ifvare triggerlink 6 {
					ifvare burninactivenow 1 setvarvar hitspritesaved THISACTOR //если загорелся
					ifvarg flamedamage 0 setvarvar hitspritesaved THISACTOR
					ifvare voodoohitenemy 1 setvarvar hitspritesaved THISACTOR
				}
			}
			ifvare enemy_htpic RADIUSEXPLOSION {
				action APODDYING1
			} else
				action APODDYING2
			setactor[THISACTOR].cstat 128
			state rx_cansetactive
			setvar ai_dead 1
		}
		ifaction APODDYING1 { 
			ifactioncount 5 { action APODDEAD1 }
		}
		ifaction APODDYING2 { 
			ifactioncount 5 { action APODDEAD2 }
		}
		ifaction APODDEAD2 {
			ifcount 200
				action APODDYING3
		}
		
		ifaction APODDYING3 { 
			ifactioncount 6 { action APODDEAD3 }
		}
	}
	
enda