defineprojectile GARGHEAD PROJ_WORKSLIKE 6278
defineprojectile GARGHEAD PROJ_EXTRA 0
defineprojectile GARGHEAD PROJ_BOUNCES 1
defineprojectile GARGHEAD PROJ_HITRADIUS 0
defineprojectile GARGHEAD PROJ_VEL 64
defineprojectile GARGHEAD PROJ_SPAWNS GARGHEAD
defineprojectile GARGHEAD PROJ_DROP -128
defineprojectile GARGHEAD PROJ_BSOUND -1
defineprojectile GARGHEAD PROJ_CLIPDIST 16
defineprojectile GARGHEAD PROJ_XREPEAT 30
defineprojectile GARGHEAD PROJ_YREPEAT 30

defineprojectile GARGWING PROJ_WORKSLIKE 6278
defineprojectile GARGWING PROJ_EXTRA 0
defineprojectile GARGWING PROJ_BOUNCES 1
defineprojectile GARGWING PROJ_HITRADIUS 0
defineprojectile GARGWING PROJ_VEL 64
defineprojectile GARGWING PROJ_SPAWNS GARGWINGFLOOR
defineprojectile GARGWING PROJ_DROP -128
defineprojectile GARGWING PROJ_BSOUND -1
defineprojectile GARGWING PROJ_CLIPDIST 16
defineprojectile GARGWING PROJ_XREPEAT 30
defineprojectile GARGWING PROJ_YREPEAT 30


defineprojectile GARGHIT PROJ_WORKSLIKE 4097
defineprojectile GARGHIT PROJ_SPAWNS SHOTSPARK1
defineprojectile GARGHIT PROJ_XREPEAT 3
defineprojectile GARGHIT PROJ_YREPEAT 3
defineprojectile GARGHIT PROJ_DECAL -1
defineprojectile GARGHIT PROJ_RANGE 1524

defineprojectile SGARGHIT PROJ_WORKSLIKE 4097
defineprojectile SGARGHIT PROJ_SPAWNS SHOTSPARK1
defineprojectile SGARGHIT PROJ_XREPEAT 3
defineprojectile SGARGHIT PROJ_YREPEAT 3
defineprojectile SGARGHIT PROJ_DECAL -1
defineprojectile SGARGHIT PROJ_RANGE 1524

//------------------------------GARGOYLE

action AGARGDECOR -5 1 -5 1 1

actor GARG_DECOR 0 AGARGDECOR
fall sizeat 36 36
cstat 0
enda

spriteshadow GABGBONE
defineprojectile GABGBONE PROJ_WORKSLIKE 32770
defineprojectile GABGBONE PROJ_HITRADIUS 0
defineprojectile GABGBONE PROJ_VEL 700
defineprojectile GABGBONE PROJ_DROP -60
defineprojectile GABGBONE PROJ_XREPEAT 32
defineprojectile GABGBONE PROJ_YREPEAT 32
defineprojectile GABGBONE PROJ_OFFSET -2048
defineprojectile GABGBONE PROJ_ISOUND -1
defineprojectile GABGBONE PROJ_EXTRA 20
defineprojectile GABGBONE PROJ_SPAWNS GARGBONEHIT

action ABONE 0 4 1 1 6
actor GARGBONEHIT 0 ABONE
sizeat 40 40 ifactioncount 4 killit enda

useractor notenemy STATSTUB
fall sizeat 30 30 cstat 257
getactor[THISACTOR].htextra htextra
getactor[THISACTOR].htang htang
cos x htang
sin y htang
ifvarn htextra -1 { setvarvar k_damage htextra addvar peractor3 8 } // damage				     
iffloordistl 10	// deaccelerate on ground

subvarvar k_damage peractor3
ifvarl k_damage 0 { setvar k_damage 0 setactor[THISACTOR].htextra -1 setvar peractor3 0 }     // clamping multiplier

mulvarvar x k_damage                // roll force = damage - deacceleration
mulvarvar y k_damage
shiftvarr x 15
shiftvarr y 15
setvar z 0
movesprite THISACTOR x y z CLIPMASK0 RETURN
enda

action ASTATWAKEUP 5 3 1 1 25

eventloadactor GARBSTATUE 
getactor[THISACTOR].xvel rx_can
ifvare rx_can 0 {

	getactor[THISACTOR].lotag LOTAGSAVED
	getuserdef[THISACTOR].m_player_skill skillit //враги на разных уровнях сложности
	ifmultiplayer addvar skillit 1
	ifvare skillit 3 setvar skillit 4 else 
	ifvare skillit 4 setvar skillit 8 else 
	ifvare skillit 5 setvar skillit 16
	setactor[THISACTOR].lotag 0			
} else {

}
setactor[THISACTOR].xrepeat 30
setactor[THISACTOR].yrepeat 30
enda

state gargaction 
ifaction NO { ifcansee ifpdistl 4096 ifvarn peractor 1 { sizeat 30 30 action ASTATWAKEUP } }
ends

useractor notenemy GARBSTATUE fall 
cstat 257 
sizeat 30 30	
getactorvar[PLAYERID].invisible peractor
getactor[THISACTOR].htextra htextra
ifvarn htextra -1 getactor[THISACTOR].htang htang

ifvare rx_can 0 {  // Not protection Gargoyle
	ifvarg LOTAGSAVED 0 {
		ifvarvarand skillit LOTAGSAVED {
			state gargaction
		} 
	} else state gargaction

} else ifvare active 1 {
	sizeat 30 30 action ASTATWAKEUP setvar active 0
}
	
ifaction ASTATWAKEUP { 
	ifactioncount 3 { 
		espawn GARGOYLE 
		getactor[THISACTOR].z z 
		addvar z -8192 
		setactor[RETURN].z z 
		setactor[RETURN].pal sprite[THISACTOR].pal
		spawn STATSTUB 
		killit 	
	} 
}

ifpdistl 1400 {
	ifhitspace { 
		ifvare buttonhit 0 {
			setvar htextra 100
			setvarvar htang player[THISACTOR].ang
			setvar buttonhit 1
		}
	} else setvar buttonhit 0
} 

cos x htang
sin y htang
ifvarn htextra -1 { setvarvar k_damage htextra addvar peractor3 8 } // damage				     
iffloordistl 10	// deaccelerate on ground

subvarvar k_damage peractor3
ifvarl k_damage 0 { setvar k_damage 0 setactor[THISACTOR].htextra -1 setvar peractor3 0 }     // clamping multiplier

mulvarvar x k_damage                // roll force = damage - deacceleration
mulvarvar y k_damage
shiftvarr x 15
shiftvarr y 15
setvar z 0
movesprite THISACTOR x y z CLIPMASK0 RETURN

enda

action AGARGWALK 0 4 -5 1 15
action AGARGSHOOT 20 6 -5 1 15
action AGARGBONESHOOT 20 6 -5 1 15
action ASTGARGBONESHOOT 1125 0 -5 1 15
action AGARGHURT 55 1 -5 1 1
action AGARGDYING 69 5 1 1 15
action AGARGDEAD1 74 1 1 1 1
action AGARGTESLA 2249 1 -5 1 1

move GARGWALK 0
move GARGUP 0 0
move GARGDOWN 0
move GARGSTOP

ai AIGARGWALK AGARGWALK GARGUP 
ai AIGARGHURT AGARGHURT GARGSTOP 
ai AIGARGRANDOM AGARGWALK GARGWALK randomangle
ai AIGARGTESLA AGARGTESLA GARGSTOP
ai AIGARGSTOP AGARGWALK GARGSTOP
ai AIGARGSHOOT AGARGSHOOT GARGSTOP 
ai AIGARGBONESHOOT AGARGBONESHOOT GARGSTOP 
ai AISTGARGBONESHOOT ASTGARGBONESHOOT GARGSTOP 
ai AIGARGDYING AGARGDYING GARGSTOP 
ai AIGARGDEAD1 AGARGDEAD1 GARGSTOP

state stonegargshoot
	sound GARGBLST
	eshoot STAFFALTPROJ
	getactor[THISACTOR].x x
	getactor[THISACTOR].y y
	getactor[THISACTOR].ang ang
	setvarvar y2 y
	addvarvar y2 128
	rotatepoint x y x y2 ang x3 y3
	setactor[RETURN].x x3
	setactor[RETURN].y y3
	getactor[THISACTOR].z z
	subvar z 9216
	setactor[RETURN].z z

	eshoot STAFFALTPROJ
	setvarvar y2 y
	subvarvar y2 128
	rotatepoint x y x y2 ang x3 y3
	setactor[RETURN].x x3
	setactor[RETURN].y y3
	getactor[THISACTOR].z z
	subvar z 9216
	setactor[RETURN].z z
ends


eventloadactor GARGOYLE 
getactor[THISACTOR].pal pal
ifvare pal 0 {
	setactor[THISACTOR].xrepeat 24
	setactor[THISACTOR].yrepeat 24
	setactor[THISACTOR].extra GARGSTRENGTH
} else ifvare pal 5 {
	setactor[THISACTOR].xrepeat 36
	setactor[THISACTOR].yrepeat 36
	setactor[THISACTOR].extra 2760
}
enda

spritenoshade GARGOYLE

useractor notenemy GARGOYLE 

	getactor[THISACTOR].pal pal
	clipdist 48
	setvar maxSpeed 230
	setvar weight 2
	setvar addition_weight 3
	ifvare pal 0 setvar width 256 else
	ifvare pal 5 setvar width 512
	setvar height 4096
	ifvarg sprite[THISACTOR].extra 0
		setvar fly_enemy 1
	setvar enemy_nohitscan_z 0
	setvar cantseetarget 0

	ifai NO { 
		ifvare pal 0 { sizeat 24 24 strength GARGSTRENGTH } else
		ifvare pal 5 { sizeat 36 36 strength 2760 }
		addvar TOTALKILLS 1 
		cstat 257 
		setvarvar enemy_type STAYPUT 
		setvarvar change_ai enemy_type 
	}
	
	ifvare enemy_type STAYPUT  { 
		ifvare change_ai STAYPUT {
			ai AIGARGSTOP
			setvar change_ai -1 
		}
		
		ifvare change_ai -1 {
			ifp palive ifcansee {
				state facingstate 
				ifvare set 1 {
					setvarvar target_id PLAYERID 
					ifvare pal 5 {
						ifvarl enemyroam 2 soundonce SARGSPOT
						ifvare enemyroam 3 soundonce SARGROAM 
					} else ifvarl enemyroam 2 soundonce GARGSPOT
					setvar enemy_type WALK
					setvar change_ai WALK
				}
			}
		}
	}
	
	state mainAI
	
	ifvarg sprite[THISACTOR].extra 0 {
		ifcansee { //sector update
			getactor[THISACTOR].x x
			getactor[THISACTOR].y y
			getactor[THISACTOR].z z
			updatesectorz x y z sectnum
			ifvare sectnum -1 {
				subvar z 11264
				updatesectorz x y z sectnum
				ifvare sectnum -1 {
					updatesector x y sectnum
				}
			}	
		}
		
		getactor[THISACTOR].z z
		getflorzofslope sectnum x y enemy_floordist
		ifvarand sector[sectnum].floorstat 1024 nullop
		else
		ifvarvarg z enemy_floordist {
			setactor[THISACTOR].z enemy_floordist
		}
		
		subvar z 11264
		ifvarand sector[sectnum].ceilingstat 1024 nullop else
		ifvarvarl z sector[sectnum].ceilingz {
			setvarvar z sector[sectnum].ceilingz
			addvar z 11264
			setactor[THISACTOR].z z
		}
	}
	
	
	ifvare enemy_type WALK {	
	
		ifvarn target_id -1	
		ifcansee ifvarg sprite[target_id].extra 0
		ifvarn enemy_invis 1 {
			getactor[THISACTOR].x x
			getactor[THISACTOR].y y
			getactor[THISACTOR].z z
			updatesectorz x y z sectnum
			
			ifvarn sectnum -1
				getceilzofslope sectnum x y mz
			else getactor[THISACTOR].z mz
			subvarvar mz z
			ifvarg targetdist 5192 {
				addvar maxSpeed 70
				ifvarn enemy_type ATTACK {
					ifvarl enemy_zdist 135000 {
						ifvarl mz -16384 { 
							getactor[THISACTOR].z z
							subvar z 1000
							setactor[THISACTOR].z z
						}
					} else {
						getactor[THISACTOR].z z
						addvar z 800
						setactor[THISACTOR].z z
					}
				}
			} else {
				ifvarg enemy_zdist 0 { 
					ifvarn sectnum -1
					getflorzofslope sectnum x y mz
					else getactor[THISACTOR].z mz

					subvarvar mz z

					ifvarg mz 5192 ifvarn enemy_type ATTACK {
						getactor[THISACTOR].z z
						addvar z 800
						setactor[THISACTOR].z z
					}
				}
				else ifvarl mz -16384 {
					getactor[THISACTOR].z z
					subvar z 500
					setactor[THISACTOR].z z
				}
			}
		}
		
		ifvarn target_id -1 ifvarg sprite[THISACTOR].extra 0
		ifcansee ifvarg sprite[target_id].extra 0 { 
			ifvare pal 5 {
				ifvarl enemyroam 2 soundonce SARGSPOT
				ifvare enemyroam 3 soundonce SARGROAM 
			} else ifvarl enemyroam 2 soundonce GARGSPOT
		}
	
		ifvare change_ai WALK {
			ai AIGARGWALK
			setvar change_ai -1 
		}

		ifvarl targetdist 650
			ifvarg anglefield -384 ifvarl anglefield 384
				ifvarn enemy_invis 1
					setvarvar enemy_ang enemy_hita
		
		ifvarvare target_id PLAYERID
		ifrnd 32 ifvarvare enemy_hittid target_id {
			ifvarg anglefield -128 ifvarl anglefield 128 {
				ifvarn enemy_movtype EVASION  
				ifvarn enemy_movtype BLOCK {
					ifvarg sprite[target_id].extra 0
					ifvarn actorvar[target_id].invisible 1 {
						ifvarg targetdist 2048 ifvarl targetdist 8192 {
							setvar enemy_type ATTACK
							ifvare pal 0 ai AIGARGBONESHOOT else ifvare pal 5 ai AISTGARGBONESHOOT
							setvar change_ai USERAI
						} 
					}
				}
			}			
		}	
	}
	
	ifvare enemy_type ATTACK {
		ifvare change_ai ATTACK {
			ai AIGARGSHOOT 
			setvar change_ai USERAI
		}
		
		ifai AISTGARGBONESHOOT { //Stone garg
			addvar enemycount 1
			ifvare enemycount 10 state stonegargshoot else
			ifvare enemycount 20 state stonegargshoot else
			ifvare enemycount 30 state stonegargshoot
			ifcount 35 { 
				setvar enemycount 0 
				setvar enemy_type WALK
				setvar change_ai WALK
				setvar shoot_var 0  
			} 
		}
		
		ifai AIGARGBONESHOOT { 
			setactor[THISACTOR].ang enemy_hita
			ifactioncount 3 
			ifvare shoot_var 0 {
				soundonce GARGCLAW 
				shoot GABGBONE
				setvar shoot_var 1
			}
			
			ifactioncount 6 { 
				setvar enemy_type WALK
				setvar change_ai WALK
				setvar shoot_var 0 
				resetactioncount 
			}
		}
	
		ifai AIGARGSHOOT { 
			ifvare shoot_var 0 {
				ifactioncount 3 {
					ifvarl targetdist 800 {
						ifvarg anglefield -128 ifvarl anglefield 128 {
							ifvarn enemy_refl 1
								{ 
								ifvare pal 5 { 
								getactor[THISACTOR].z z
								addvarvar z height
								setactor[THISACTOR].z z
								zshoot 2048 SGARGHIT 
								subvarvar z height
								setactor[THISACTOR].z z
								} else zshoot 2048 GARGHIT }
							else 
								setvar hitself 1
						}
						else
							{ ifvare pal 5 zshoot 8192 SGARGHIT else zshoot 8192 GARGHIT }
					} else { ifvare pal 5 zshoot 8192 SGARGHIT else zshoot 8192 GARGHIT }
					setvar shoot_var 1
				}
			}
			ifactioncount 5 { 
				ifvare hitself 1 {
					state bloodspraystate 
					getactor[THISACTOR].extra extra
					ifvare pal 5 getprojectile[SGARGHIT].extra tmp else
						getprojectile[GARGHIT].extra tmp
					subvarvar extra tmp
					setactor[THISACTOR].extra extra
					ifvarg extra 0 { ifvare pal 0 soundonce GARGPAIN setvar enemy_type GETDAMAGE setvar change_ai GETDAMAGE } else {
					setvar enemy_type DYING setvar change_ai DYING }
					
				}
			
				getactor[target_id].extra extra
				ifvarg targetdist 550 { 
					setvar enemy_type WALK
					setvarvar change_ai enemy_type
				} else {
					ifvarl extra 1 { setvar enemy_type WALK setvarvar change_ai enemy_type } else
					ifvarg anglefield -128 ifvarl anglefield 128 ifvarn enemy_invis 1 nullop else {
					setvar enemy_type WALK setvarvar change_ai enemy_type
					}
				}
				
				setvar hitself 0
				setvar shoot_var 0 
				resetactioncount 
			}
			ifvarl targetdist 600
				ifvarg anglefield -128 ifvarl anglefield 128 
					ifvarn enemy_invis 1 {
					setactor[THISACTOR].ang enemy_hita
					setvarvar enemy_ang enemy_hita
				}
		}
	}

	ifvare enemy_type GETDAMAGE {
		ifvare change_ai GETDAMAGE {
			setvar enemy_tesla 0 
			ifvare pal 0 {
				soundonce GARGPAIN
				ifvarn teslahitenable 1 {
					ai AIGARGHURT
				} else
					ai AIGARGTESLA
				setvar change_ai USERAI
			} else { //Stone Garg
				setvar enemycount 5
				ifai AIGARGBONESHOOT {
					setvar enemy_type ATTACK
					setvarvar change_ai USERAI
				} else {				
					setvar enemy_type WALK
					setvarvar change_ai enemy_type
				}
			}
		}
		
		ifvare change_ai USERAI {
			ifai AIGARGHURT
			ifcount 9 {
				setvar enemy_type WALK
				setvarvar change_ai enemy_type
			}	
			ifai AIGARGTESLA { 
				setvar enemy_tesla 1 
				setvar teslahitenable 0 
				ifcount 30 { 
					setvar enemy_tesla 0 
					setvar enemy_type WALK
					setvarvar change_ai enemy_type
				}  
			}
		}	
	}
	
	ifvare enemy_type GETHEAVYDAMAGE {
		ifvare pal 0 {
		espawn GARGSQUISH 
		setactorvar[RETURN].htang htang
		setactorvar[RETURN].htextra htextra
		addkills 1 
		killit 
		} else {
			setvar enemy_type DYING 
			setvar change_ai DYING
		}
	}
	
	ifvare enemy_type VOODOO {
		setvar enemy_type DYING 
		setvar change_ai DYING
	}

	ifvare enemy_type BURNING {
		ifvarn pal 5
		{
			espawn GARGBURNING 
			setactor[THISACTOR].extra 0
			setactor[RETURN].xrepeat 30
			setactor[RETURN].yrepeat 30
			state enemykill_trigger
			setactorvar[RETURN].se_xvel se_xvel
			addkills 1 
			killit
		} else {
			setvar enemy_type DYING 
			setvar change_ai DYING
		}
	}
	
	
	ifvare enemy_type DYING {
		ifvare change_ai DYING {
			setactor[THISACTOR].extra 0
			state bloodsprayshit 
			ifvare pal 5 { ifrnd 96 soundonce SARGDIE1 else ifrnd 96 soundonce SARGDIE2 else soundonce SARGDIE3 } else
			ifrnd 96 soundonce GARGDIE1 else ifrnd 96 soundonce GARGDIE2 else soundonce GARGDIE3
			ai AIGARGDYING
			ifrnd 128 cstat 4 else cstat 0
			setvar change_ai USERAI
		}
		
		ifvare change_ai USERAI {
			ifai AIGARGDYING ifactioncount 5 { ai AIGARGDEAD1 setvar change_ai -1 }
		}
	}

	ifvarl sprite[THISACTOR].extra 1 {
		setvar fly_enemy 0
		fall
	}
enda


action AGARGBURNING 0 3 1 1 15
action AGARGBURN 4 5 1 1 15
action AGARGBURNED 10 1 1 1 1

ai AIGARGBURNING AGARGBURNING GARGSTOP faceplayer
ai AIGARGBURN AGARGBURN GARGSTOP faceplayer
ai AIGARGBURNED AGARGBURNED GARGSTOP

spriteshadow GARGBURNING
spritenoshade GARGBURNING
useractor notenemy GARGBURNING
ifai NO { sizeat 30 30 cstat 1 ai AIGARGBURNING }
ifai AIGARGBURNING { setactorvar[THISACTOR].lights_on 1 ifcount 100 { fall ai AIGARGBURN } }
ifai AIGARGBURN { fall ifactioncount 5 ai AIGARGBURNED }
ifai AIGARGBURNED { setactorvar[THISACTOR].lights_on 0 cstat 0 fall }
enda

action AGARGSQUISH 0 5 1 1 15
action AGARGSQUISHED 5 1 1 1 1

ai AIGARGSQUISH AGARGSQUISH GARGSTOP faceplayer
ai AIGARGSQUISHED AGARGSQUISHED GARGSTOP

useractor notenemy GARGHEAD fall sizeat 30 30 
cstat 256 ifhitweapon {  qspawn BLOODPOOL2 killit } 
enda

useractor notenemy GARGWINGFLOOR fall sizeat 30 30 
cstat 0
enda

useractor notenemy GARGSQUISH
fall
ifai NO 
{ 
	sizeat 30 30 cstat 1 ai AIGARGSQUISH 
	randvar zdist 1024
	ifrnd 128 mulvar zdist -1
	subvar zdist 512
	ezshootvar zdist JIBS7
	randvar zdist 1024
	ifrnd 128 mulvar zdist -1
	subvar zdist 512
	ezshootvar zdist GARGHEAD
	getprojectile[GARGHEAD].vel tmp
	randvar tmp2 32
	addvarvar tmp tmp2
	setprojectile[GARGHEAD].vel tmp
	getactor[RETURN].ang ang
	randvar tmp 2048
	ifrnd 128 mulvar tmp -1
	addvarvar ang tmp
	setactor[RETURN].ang ang
	
	randvar zdist 1024
	ifrnd 128 mulvar zdist -1
	subvar zdist 512
	ezshootvar zdist GARGWING
	getprojectile[GARGWING].vel tmp
	randvar tmp2 32
	addvarvar tmp tmp2
	setprojectile[GARGWING].vel tmp
	getactor[RETURN].ang ang
	randvar tmp 2048
	ifrnd 128 mulvar tmp -1
	addvarvar ang tmp
	setactor[RETURN].ang ang
}
ifai AIGARGSQUISH ifactioncount 5 { cstat 0 ai AIGARGSQUISHED }

ifvarg htextra 0 {
	cos x htang
	sin y htang
						
	iffloordistl 10
		subvar htextra 8

	mulvarvar x htextra
	mulvarvar y htextra
	shiftvarr x 12
	shiftvarr y 12
	setvar z 0
	movesprite THISACTOR x y z CLIPMASK0 RETURN
} else 
	setvar htextra -1
enda
