
//DudeInfo 203
define ZOMBAHEALTH 80
define ZOMBAMASS 120
define ZOMBAEYEHEIGHT 30 //46
define ZOMBAHEARDIST 6826 //10240
define ZOMBASEEDIST 34133 //51200
define ZOMBAPERIPHERY 512
define ZOMBASPEED 44000 //58254   k=1.3
define ZOMBAANGSPEED 384
define ZOMBAALERT 32768

defineprojectile ZOMBIEHEAD PROJ_WORKSLIKE 6150
defineprojectile ZOMBIEHEAD PROJ_HITRADIUS 0
defineprojectile ZOMBIEHEAD PROJ_BOUNCES 5
defineprojectile ZOMBIEHEAD PROJ_VEL 1700
defineprojectile ZOMBIEHEAD PROJ_DROP -120
defineprojectile ZOMBIEHEAD PROJ_CSTAT 0
defineprojectile ZOMBIEHEAD PROJ_BSOUND BODYHIT1
defineprojectile ZOMBIEHEAD PROJ_XREPEAT 32
defineprojectile ZOMBIEHEAD PROJ_YREPEAT 32
defineprojectile ZOMBIEHEAD PROJ_EXTRA 0
defineprojectile ZOMBIEHEAD PROJ_SPAWNS -1

spritenoshade ZOMBIEHEAD
useractor notenemy ZOMBIEHEAD 0 NO enda

spritenoshade ZOMBIE
spriteshadow ZOMBIE
defineprojectile ZOMBIEAXE PROJ_WORKSLIKE 4097
defineprojectile ZOMBIEAXE PROJ_SPAWNS SHOTSPARK1
defineprojectile ZOMBIEAXE PROJ_XREPEAT 3
defineprojectile ZOMBIEAXE PROJ_YREPEAT 3
defineprojectile ZOMBIEAXE PROJ_DECAL -1
defineprojectile ZOMBIEAXE PROJ_RANGE 1024

action AZOMBIEWALK1  0 6 -5 1 13
//action AZOMBIEWALK2  20 4 -5 -1 10

action AZOMBIESTAYPUT  0 1 -5 1 1
action AZOMBIESHOOT 54 7 -5 1 12
action AZOMBIEGOTHIT 30 1 -5 1 10
action AZOMBIEJIB 46 6 1 1 13
action AZOMBIEGUTS 158 6 1 1 10
action AZOMBIEFALLING 35 4 1 1 12
action AZOMBIEGETUP 40 6 1 1 12
action AZOMBIEVOODOO1 2484 7 1 1 12
action AZOMBIEVOODOO2 2492 1 1 1 1
action AZOMBIETESLA 2493 1 -5 1 1
action AZOMBIEDEAD 53 1 1 1 1
action AZOMBIEDEAD2 39 1 1 1 1
action AZOMBIEGUTS2 165 1 1 1 1
action AZOMBIEEARTH 1885 1 1 1 1
action AZOMBIERISE 1876 9 1 1 15

define RISER 7
define RISERACTIVE 8
define UPPER 9

eventloadactor EZOMBIEFALL
	
	//aiInit
	
	getactor[THISACTOR].mdflags  tmp
	orvar  tmp 16
	setactor[THISACTOR].mdflags  tmp
	
	setvar ai_animation_old -1
	setvar ai_aistate UPPER
	setvar zombie_lay 1
	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 ZOMBASPEED
	setvar ai_angspeed ZOMBAANGSPEED
	setvar ai_periphery ZOMBAPERIPHERY
	setvar ai_eyeheight ZOMBAEYEHEIGHT
	setvar ai_heardist ZOMBAHEARDIST
	setvar ai_seedist ZOMBASEEDIST
	setvar ai_alertchance ZOMBAALERT
	setvar ai_mass ZOMBAMASS
	
	setactor[THISACTOR].extra ZOMBAHEALTH

	orvar sprFlags kAttrMove
	orvar sprFlags kAttrGravity
	orvar sprFlags kAttrFalling
	
	setactor[THISACTOR].xrepeat 28
	setactor[THISACTOR].yrepeat 28
	
	setvar width 128
	setvar height 8192
	
	cstat 128
	addvar TOTALKILLS 1	
	cactor ZOMBIE
	
enda

eventloadactor ZOMBIERISE

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

	setvar zombie_lay 1
	setvarvar ai_target -1
	setvarvar ai_targetx 0
	setvarvar ai_targety 0
	setvarvar ai_targetz 0
	setvar ai_statetimer 0
	
	setvar ai_speed ZOMBASPEED
	setvar ai_angspeed ZOMBAANGSPEED
	setvar ai_periphery ZOMBAPERIPHERY
	setvar ai_eyeheight ZOMBAEYEHEIGHT
	setvar ai_heardist ZOMBAHEARDIST
	setvar ai_seedist ZOMBASEEDIST
	setvar ai_alertchance ZOMBAALERT
	setvar ai_mass ZOMBAMASS
	
	setactor[THISACTOR].extra ZOMBAHEALTH

	orvar sprFlags kAttrMove
	orvar sprFlags kAttrGravity
	orvar sprFlags kAttrFalling
	
	setactor[THISACTOR].xrepeat 28
	setactor[THISACTOR].yrepeat 28
	
	setvar width 128
	setvar height 8192
	
	cstat 128
	addvar TOTALKILLS 1
	
	cactor ZOMBIE

enda

state zombie_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 ZOMBASPEED
	setvar ai_angspeed ZOMBAANGSPEED
	setvar ai_periphery ZOMBAPERIPHERY
	setvar ai_eyeheight ZOMBAEYEHEIGHT
	setvar ai_heardist ZOMBAHEARDIST
	setvar ai_seedist ZOMBASEEDIST
	setvar ai_alertchance ZOMBAALERT
	setvar ai_mass ZOMBAMASS
	
	setactor[THISACTOR].extra ZOMBAHEALTH
	
	orvar sprFlags kAttrMove
	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 8192
	addvar TOTALKILLS 1
ends

eventloadactor ZOMBIE  
	state zombie_init
enda

state zombie_findInnocent	
	ifvare ai_state 1 {
		setvar sectorid 0
		whilevarvarn sectorid NUMSECTORS  {
			headspritesect spriteid sectorid
			whilevarn spriteid -1 {
				ifvare sprite[spriteid].picnum CIVILIAN 
				ifvarg sprite[spriteid].extra 0 {
					ldist DIST THISACTOR spriteid
					ifvarl DIST 2000 {
						setvarvar ai_target spriteid
						setvarvar ai_targetx sprite[ai_target].x
						setvarvar ai_targety sprite[ai_target].y
						setvarvar ai_targetz sprite[ai_target].z
						state aiActivateDude
					}
				}
				nextspritesect spriteid spriteid
			}
			addvar sectorid 1
		}
	}
ends

state azombieswitchaction

	ifvare ai_aistate IDLE ifvarn ai_animation_old IDLE { 
		action AZOMBIESTAYPUT
		setvar ai_animation_old IDLE
	}
	ifvare ai_aistate SEARCH ifvarn ai_animation_old GOTO {
		action AZOMBIEWALK1
		setvar ai_animation_old GOTO
	}
	ifvare ai_aistate CHASE ifvarn ai_animation_old GOTO {	
		action AZOMBIEWALK1
		setvar ai_animation_old GOTO
	}
	ifvare ai_aistate GOTO ifvarn ai_animation_old GOTO {
		action AZOMBIEWALK1
		setvar ai_animation_old GOTO
	}
	ifvare ai_aistate HACK ifvarn ai_animation_old HACK {	
		action AZOMBIESHOOT
		setvar ai_animation_old HACK
	}
	
	ifvare ai_aistate RECOIL ifvarn ai_animation_old RECOIL {
		action AZOMBIEGOTHIT
		setvar ai_animation_old RECOIL
	}
	ifvare ai_aistate PONDER ifvarn ai_animation_old GOTO {
		action AZOMBIEWALK1
		setvar ai_animation_old GOTO
	}
	ifvare ai_aistate RISER ifvarn ai_animation_old RISER {
		action AZOMBIEEARTH
		setvar ai_animation_old RISER
	}
			
ends

state thinkGoto
	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_switchaction 1
		}
	}
	state aiThinkTarget
ends

state thinkSearch
	setvarvar ain1 ai_goalang
	state aiChooseDirection
	state aiThinkTarget
	state zombie_findInnocent
ends

state thinkChase
	ifvare ai_target -1 {
		setvar ai_aistate SEARCH
		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_switchaction 1
		}
		else ifvarvare ai_target PLAYERID ifvare actorvar[PLAYERID].invisible 1 {
			setvar ai_aistate GOTO
			setvar ai_statetimer 1000
			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 targetdist 682 {
							ifvarl ai_losang 85 {
								setvar ai_aistate HACK
								setvar ai_switchaction 1
								setvar ai_statetimer 90
								setvar ai_next PONDER
							}
						} 
					} else {
						//Axe zombie lost sight of target
						setvar ai_aistate GOTO
						setvar ai_statetimer 1000
						setvar ai_next IDLE
						setvar ai_switchaction 1
					}
				} else {
					//Axe zombie lost sight of target
					setvar ai_aistate GOTO
					setvar ai_statetimer 1000
					setvar ai_next IDLE
					setvar ai_switchaction 1
				}
			} else {
				//Axe zombie lost sight of target
				setvar ai_aistate GOTO
				setvar ai_statetimer 1000
				setvar ai_next IDLE
				setvar ai_switchaction 1
			}		
		}
	}
	
ends

state thinkPonder

	ifvare ai_target -1 {
		setvar ai_aistate SEARCH
		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_switchaction 1
		}
		else ifvarvare ai_target PLAYERID ifvare actorvar[PLAYERID].invisible 1 {
			setvar ai_aistate GOTO
			setvar ai_statetimer 1000
			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 //pxsprite.target xxx
						setvarvar ai_targetx sprite[ai_target].x
						setvarvar ai_targety sprite[ai_target].y
						setvarvar ai_targetz sprite[ai_target].z
						
						setvarvar se_x ai_targetx
						subvarvar se_x sprite[THISACTOR].x
						setvarvar se_y ai_targety
						subvarvar se_y sprite[THISACTOR].y
						mulvarvar se_x se_x
						mulvarvar se_y se_y
						addvarvar se_x se_y
						sqrt se_x targetdist

						ifvarl targetdist 682 {
							ifvarl ai_losang 85 {
								setvar ai_aistate HACK
								setvar ai_switchaction 1
								setvar ai_statetimer 90
								setvar ai_next PONDER
							}
						}  else {
							setvar ai_aistate CHASE
							setvar ai_statetimer 1000
			setvar ai_next IDLE
							setvar ai_switchaction 1
						}
					} else {
						setvar ai_aistate CHASE
						setvar ai_statetimer 1000
			setvar ai_next IDLE
						setvar ai_switchaction 1
					}
				} else {
					setvar ai_aistate CHASE
					setvar ai_statetimer 1000
			setvar ai_next IDLE
					setvar ai_switchaction 1
				}
			} else {
				setvar ai_aistate CHASE
				setvar ai_statetimer 1000
			setvar ai_next IDLE
				setvar ai_switchaction 1
			}		
		}
	}
	
ends

gamevar zmspawn 0 2

useractor notenemy ZOMBIE ZOMBAHEALTH

	ifspawnedby BL_RESPAWN ifvare zmspawn 0 {
		state zombie_init
		setvar zmspawn 1
	}

	ifvare active 1 ifvarg sprite[THISACTOR].extra 0 {
		setvarvar ai_state 1

		ifvare ai_aistate UPPER {
			setvar ai_aistate RECOIL
			getactor[THISACTOR].cstat tmp
			orvar tmp 257
			setactor[THISACTOR].cstat tmp
			action AZOMBIEGETUP
			setvar zombie_lay 0
			setvar ai_animation_old -1
		} else {
			setvarvar ai_aistate SEARCH
			setvar ai_statetimer 1800
			setvar ai_next IDLE
		}

		setvar ai_switchaction 1
		setvar active 0
	}

	//ifaction AZOMBIEWALK1 ifactioncount 3 action AZOMBIEWALK2
	//ifaction AZOMBIEWALK2 ifactioncount 4 action AZOMBIEWALK1
	
	ifvare VISION 1 ifvarg sprite[THISACTOR].extra 0 { setactor[THISACTOR].shade -127 }
	
	ifvarg flamedamage 0 { addvar COUNTER 1 state newfirestate } 
	ifinwater setvar COUNTER 0
	ifvarvare COUNTER flamedamage { setvar flamedamage 0 setvar COUNTER 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 {

		setvarvar ain1 sprite[ai_naffected].x
		setvarvar ain2 sprite[ai_naffected].y
		setvarvar ain3 sprite[ai_naffected].z
		setvarvar ain4 4000

		state ConcussSprite
		setactor[THISACTOR].htpicnum RADIUSEXPLOSION
		
		ifvarg sprite[THISACTOR].extra 0 {
			ifvare ai_aistate RISER {
				setactor[THISACTOR].htextra 1000 
				state enemyjibs_state 
				addkills 1	
				state rx_cansetactive
				state enemykill_trigger
				setactor[THISACTOR].extra 0
			}
			ifvare ai_aistate UPPER {
				setactor[THISACTOR].htextra 1000 
				state enemyjibs_state 
				addkills 1	
				state rx_cansetactive
				state enemykill_trigger
				setactor[THISACTOR].extra 0
			}
			ifvare ai_aistate RISERACTIVE {
				setactor[THISACTOR].htextra 1000 
				state enemyjibs_state 
				addkills 1	
				state rx_cansetactive
				state enemykill_trigger
				setactor[THISACTOR].extra 0
			}
			ifaction AZOMBIEDEAD2
			{
				setactor[THISACTOR].htextra 1000 
				state enemyjibs_state 
				addkills 1	
				state rx_cansetactive
				state enemykill_trigger
				setactor[THISACTOR].extra 0
			}
			ifaction AZOMBIEGETUP
			{
				setactor[THISACTOR].htextra 1000 
				state enemyjibs_state 
				addkills 1	
				state rx_cansetactive
				state enemykill_trigger
				setactor[THISACTOR].extra 0
			}
		}
	} else {
		// process vectorscan
		ifvarg sprite[THISACTOR].htextra 0 ifvare sprite[THISACTOR].htpicnum 2595 {
			ifvarn CURRWEAP 3 {
				state WeaponHitProcess //aim
				state ApplyWeaponForce //add vel
			}
		}
	}
	
	ifvare ai_switchaction 1 {
		state azombieswitchaction
		setvar ai_switchaction 0
	}

	state AirDrag
	state MoveDude

	ifvare burningguyactive 1 { 
		espawn BURNINGGUY 
		getactor[THISACTOR].z z
		addvar z 10144
		setactor[RETURN].z z
		setactor[THISACTOR].extra 0 //чтобы привязанный ключ смог переопределить спрайт горящего чувака
		setactor[RETURN].xrepeat 26
		setactor[RETURN].yrepeat 26
		setactorvar[RETURN].bguy_id 1 
		state enemykill_trigger
		setactorvar[RETURN].se_xvel se_xvel
		addkills 1 
		killit 
	}

	//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 RISER {
			ifcansee ifvare actorvar[PLAYERID].invisible 0 ifpdistl 4096 {
				setvar ai_aistate RISERACTIVE
				action AZOMBIERISE
				getactor[THISACTOR].cstat tmp
				orvar tmp 257
				setactor[THISACTOR].cstat tmp
				setvar ai_animation_old -1
			}
		}
		
		ifvare ai_aistate RISERACTIVE {
			ifaction AZOMBIERISE {
				ifactioncount 8 {
					setvar zombie_lay 0
					setvar ai_aistate IDLE
					setvar ai_switchaction 1
					resetcount
				}
			}
		}

		ifvare ai_aistate UPPER {
			action AZOMBIEDEAD2
			setvar ai_animation_old -1
			
			ifcansee ifvare actorvar[PLAYERID].invisible 0 ifpdistl 4096 {
				setvar ai_aistate RECOIL
				getactor[THISACTOR].cstat tmp
				orvar tmp 257
				setactor[THISACTOR].cstat tmp
				action AZOMBIEGETUP
				setvar zombie_lay 0
				setvar ai_animation_old -1
			}
		}
		
		ifvare ai_aistate IDLE {
			state aiThinkTarget
			state zombie_findInnocent
		}
			
		ifvare ai_aistate SEARCH {
			state aiMoveForward
			ifvare ai_thinktick 0 { 
				state thinkSearch	
			}
		}
		ifvare ai_aistate CHASE {	
			state aiMoveForward
			ifvare ai_thinktick 0 state thinkChase
		}
		ifvare ai_aistate GOTO {
			state aiMoveForward
			ifvare ai_thinktick 0 state thinkGoto
		}
		ifvare ai_aistate PONDER {
			state aiMoveTurn
			ifvare ai_thinktick 0 state thinkPonder
		}
		
		ifvare ai_aistate HACK {
			ifaction AZOMBIESHOOT
			ifactioncount 4 {
				soundonce AZOMSWIP 
				ifvarn actorvar[ai_target].reflective 1 {
					getactor[THISACTOR].z z
					addvar z 8192
					setactor[THISACTOR].z z
					shoot ZOMBIEAXE 
					subvar z 8192
					setactor[THISACTOR].z z
				}
				else {
					state bloodspraystate 
					getactor[THISACTOR].extra extra
					getprojectile[ZOMBIEAXE].extra tmp
					subvarvar extra tmp
					setactor[THISACTOR].extra extra

					setactor[THISACTOR].htextra tmp
				}			
				resetactioncount
			}
		}

		ifvare ai_aistate RECOIL {
		
			ifaction AZOMBIETESLA {
				setvar enemy_tesla 1
				ifactioncount 30 {
					setvar ai_aistate PONDER
					setvar ai_statetimer 1000
					setvar ai_next IDLE
					setvar ai_switchaction 1
					getactor[THISACTOR].cstat tmp
					orvar tmp 257
					setactor[THISACTOR].cstat tmp
					setvar ai_animation_old -1
					setvar teslahitenable 0
					setvar enemy_tesla 0
				}
			}
			
			ifaction AZOMBIEGOTHIT {
				ifactioncount 2 {
					setvar ai_aistate PONDER
					setvar ai_statetimer 1000
					setvar ai_next IDLE
					setvar ai_switchaction 1
					getactor[THISACTOR].cstat tmp
					orvar tmp 257
					setactor[THISACTOR].cstat tmp
				}
			}
			ifaction AZOMBIEFALLING {
				ifactioncount 4 {
					action AZOMBIEDEAD2
					
					setvar r_enemyhitag 1
					setvar ai_animation_old -1
				}
			}
			ifaction AZOMBIEDEAD2 {
				ifcount 90 {
					action AZOMBIEGETUP
					setvar zombie_lay 0
					getactor[THISACTOR].cstat tmp
					orvar tmp 257
					setactor[THISACTOR].cstat tmp
					setvar ai_animation_old -1
					resetcount
				}
			}
			ifaction AZOMBIEGETUP {
				ifactioncount 5 {
				
					setvar ai_aistate PONDER
					setvar ai_statetimer 1000
					setvar ai_next IDLE
					setvar ai_switchaction 1
				}
			}
		} else { setvar enemy_tesla 0 setvar teslahitenable 0 }

		ifvare flarehit 1 {
			getuserdef[THISACTOR].player_skill pskill
			ifvarl pskill 3
			{
				setvar ai_aistate RECOIL
				action AZOMBIEFALLING
				setvar zombie_lay 1
				setvar ai_animation_old -1
				
				setvar ai_next -1
				getactor[THISACTOR].cstat tmp
				ifvarand tmp 257 xorvar tmp 257
				setactor[THISACTOR].cstat tmp
				resetcount
			}
			setvar flarehit 0
		}
		
		/*
		ifpdistl 1224 ifvare CURRWEAP 1 //пистолет
		{
			getuserdef[THISACTOR].player_skill pskill
			ifvare player[THISACTOR].kickback_pic 5 
			ifvarl pskill 3 ifvarvare HITSPRITE THISACTOR //state checkhitscan from BloodCM.con
			{
				setvar ai_aistate RECOIL
				action AZOMBIEFALLING
				setvar ai_animation_old -1
				
				setvar ai_next -1
				getactor[THISACTOR].cstat tmp
				ifvarand tmp 257 xorvar tmp 257
				setactor[THISACTOR].cstat tmp
				resetcount
			}
		}
		*/

		ifvare ai_statetimer 0 ifvarn ai_next -1 {
			setvarvar ai_aistate ai_next
			setvar ai_switchaction 1
			setvar ai_next -1
		}	
		
		// process dudes for voodoo recoil
		ifvare voodootouchenemy 1 
		{
			soundonce AZOMPAIN
			setvar ai_aistate RECOIL
			action AZOMBIEGOTHIT
			setvar ai_animation_old -1
			
			state bloodspraystate
			ifrnd 64 state bloodspraystate
				
			setvar ai_next -1
			getactor[THISACTOR].cstat tmp
			ifvarand tmp 257 xorvar tmp 257
			setactor[THISACTOR].cstat tmp
			setvar voodootouchenemy 0
			resetcount
		}
			
		
		// process dudes for recoil
		
		ifvarg sprite[THISACTOR].htextra 0 { 
			//stopsound AZOMROAM
			//soundonce AZOMPAIN
			
			getactor[THISACTOR].htextra tmp
			ifvarg tmp 10 {
				getuserdef[THISACTOR].player_skill pskill
				ifvare pskill 2 {
					mulvarvar tmp 4
					divvarvar tmp 5
				}
				ifvare pskill 3 {
					mulvarvar tmp 3
					divvarvar tmp 4
				}
				ifvare pskill 4 {
					mulvarvar tmp 2
					divvarvar tmp 3
				}
				ifvare pskill 5 {
					divvarvar tmp 2
				}
				setactor[THISACTOR].htextra tmp
			}
			
			getactor[THISACTOR].htowner spriteid
			ifvarg spriteid 0 { 
				getactor[THISACTOR].picnum picnum
				getactor[spriteid].picnum tmp
				ifvarvarn tmp picnum { 
				switch tmp
				case ZOMBIE
				case HERETIC
				case FISH
				case SPIDER
				case PHANTASM
				case HELLDOG
				case GILLBEAST
				case GARGOYLE
				case BUTCHER
				case FATRAT
				case BOSSSPIDER
				case APLAYER
					setvarvar ai_target spriteid 
				break 
				endswitch
				}
			}
			
			ifvarvarg sprite[THISACTOR].htextra sprite[THISACTOR].extra {
				ifwasweapon RADIUSEXPLOSION {
					state enemyjibs_state 
					action AZOMBIEGUTS
					setvar burningguyactive 0
					setvar COUNTER 0
					setactor[THISACTOR].extra -100
				} else {
					ifrnd 64 {
						setprojectile[ZOMBIEHEAD].vel 60 
						ezshoot 256 ZOMBIEHEAD
						action AZOMBIEJIB
					}
					else action AZOMBIEGOTHIT
				}
				setvar ai_switchaction 0
			} else
			ifvarg sprite[THISACTOR].htextra 15 { //cumulDamage[nXSprite] >= pDudeInfo.hinderDamage << 4
		
				setvar ai_aistate RECOIL
				getuserdef[THISACTOR].player_skill pskill
				ifvarl pskill 3 {
					action AZOMBIEFALLING
					soundonce AZOMPAIN
					setvar zombie_lay 1
					getactor[THISACTOR].cstat tmp
					ifvarand tmp 257 xorvar tmp 257
					setactor[THISACTOR].cstat tmp
				}
				else {
					setvar ai_aistate PONDER
					setvar ai_statetimer 1000
					setvar ai_next IDLE
				}

				ifvare teslahitenable 1 {
					action AZOMBIETESLA
				}
				setvar ai_animation_old -1

				state shootblood 
				state shootblood 
				state shootblood 
				
				state bloodspraystate
				ifrnd 64 state bloodspraystate
			
				setvar ai_next -1
				
				resetcount
			}
		
		
			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 {
			ifvare sprite[THISACTOR].htextra 1000 {
				setvar in1 10
				setvar in2 JIBS9
				setvarvar utl_tmp1 in1
				whilevarn utl_tmp1 0
				{
					espawnvar in2
					getactor[RETURN].z z
					subvar z 8192
					setactor[RETURN].z z
					subvar utl_tmp1 1
				}
				killit
			}
			setactor[THISACTOR].htextra -1
		}
		
		ifvare ai_dead 0 {
		
			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
				}
			}
			
			setactor[THISACTOR].cstat 128
			addkills 1	
			state rx_cansetactive
			setvar enemy_tesla 0
			state enemykill_trigger
			//stopsound AZOMPAIN
			ifrnd 85 soundonce AZOMDIE1 else ifrnd 85 soundonce AZOMDIE2 else soundonce AZOMDIE3
			
			ifaction AZOMBIEGUTS nullop else ifaction AZOMBIEJIB nullop else
				action AZOMBIEFALLING

			setvar ai_dead 1
		}
		ifaction AZOMBIEGUTS 
			ifactioncount 6 action AZOMBIEGUTS2

		ifvare voodoohitenemy 1 {	
			action AZOMBIEVOODOO1
			setvar voodoohitenemy 0
		}
		ifaction AZOMBIEVOODOO1 {
			ifactioncount 7 {
				action AZOMBIEVOODOO2 
				setvar voodoohitenemy 0
			}
		}
		ifaction AZOMBIEFALLING {
			ifactioncount 4 {
				action AZOMBIEDEAD2
			}
		}
		
		ifaction AZOMBIEJIB
			ifactioncount 6 action AZOMBIEDEAD
			
	}

enda
