//------------------------------GILL BEAST CODE

action AGBEASTWALK1 0 4  -5  1  15
action AGBEASTWALK2 15 4  -5  -1  15
action AGBEASTSTAY 0 1  -5  1  1
action AGBEASTWATERSTAY 25 1  -5  1  1
action AGBEASTSWIM 25 4  -5  1  15
action AGBEASTATTACK 50 3  -5  1  20
action AGBEASTSWIMATTACK 65 3  -5  1  20
action AGBEASTHIT 80 1  1  1  20
//action AGBEASTHIT2 85 1  1  1  20
//action AGBEASTDYING 90 5  1  1  20
action AGBEASTDYING -6 5  1  1  15
action AGBEASTDEAD -1
action AGBEASTDEAD2 -7
action AGBEASTGUTS -12 -5  1  1 15
action AGBEASTTESLA 2164 1 -5 1 1

move GBEASTSTOP 

ai AIGBEASTWALK AGBEASTWALK1 
ai AIGBEASTSWIM AGBEASTSWIM 
ai AIGBEASTHIT AGBEASTHIT GBEASTSTOP 
ai AIGBEASTATTACK AGBEASTATTACK GBEASTSTOP 
ai AIGBEASTSWIMATTACK AGBEASTSWIMATTACK GBEASTSTOP 
ai AIGBEASTSTAY AGBEASTSTAY GBEASTSTOP
ai AIGBEASTWATERSTAY AGBEASTWATERSTAY GBEASTSTOP
ai AIGBEASTDYING AGBEASTDYING GBEASTSTOP 
ai AIGBEASTGUTS AGBEASTGUTS GBEASTSTOP 
ai AIGBEASTDEAD AGBEASTDEAD GBEASTSTOP
ai AIGBEASTDEAD2 AGBEASTDEAD2 GBEASTSTOP
ai AIGBEASTTESLA AGBEASTTESLA

defineprojectile GBEASTHIT PROJ_WORKSLIKE 4097
defineprojectile GBEASTHIT PROJ_SPAWNS SHOTSPARK1
defineprojectile GBEASTHIT PROJ_XREPEAT 3
defineprojectile GBEASTHIT PROJ_YREPEAT 3
defineprojectile GBEASTHIT PROJ_DECAL -1
defineprojectile GBEASTHIT PROJ_RANGE 1024

eventloadactor GILLBEAST 
setactor[THISACTOR].xrepeat 30
setactor[THISACTOR].yrepeat 30
setactor[THISACTOR].extra GILLBEASTSTRENGTH
enda

spritenoshade GILLBEAST
spriteshadow GILLBEAST

useractor notenemy GILLBEAST GILLBEASTSTRENGTH sizeat 30 30 
	ifinwater { setvar enemy_nohitscan_z 1 setvar maxSpeed 200 setvar weight 1 setvar height 4096 } else { setvar enemy_nohitscan_z 0 fall setvar maxSpeed 100 setvar weight 2 setvar height 8192 }
	setvar width 128
	setvar cantseetarget 0
	setvar fly_enemy 0
	
	ifai NO { addvar TOTALKILLS 1 cstat 257 setvarvar enemy_type STAYPUT setvarvar change_ai enemy_type }
	
	ifvare enemy_type STAYPUT  { 
		ifvare change_ai STAYPUT {
			ifinwater ai AIGBEASTWATERSTAY else 
				ai AIGBEASTSTAY
			setvar change_ai -1 
		}
		
		ifvare change_ai -1 {
			ifp palive ifcansee {
				state facingstate 
				ifvare set 1 {
					setvarvar target_id PLAYERID 
					soundonce GILLSPOT 
					setvar enemy_movtype WALK
					setvar change_ai WALK
				}
			}
		}
	}
	
	state mainAI
	
	ifinwater ifvarg sprite[THISACTOR].extra 0 {
		ifcanseetarget ifvarn target_id -1 {
			getactor[THISACTOR].z enemy_z
			getactor[target_id].z target_z
			setvarvar tmp target_z
			addvarvar tmp 512
			ifvarvarl tmp enemy_z {
				subvarvar enemy_z 400
			} else {
			
				setvarvar tmp target_z
				subvarvar tmp 512
				ifvarvarg tmp enemy_z 
					addvarvar enemy_z 400
			}
			setactor[THISACTOR].z enemy_z
		}
		
		getactor[THISACTOR].sectnum sectnum
		getactor[THISACTOR].z z
		ifvarvarg z sector[sectnum].floorz 
			setactor[THISACTOR].z sector[sectnum].floorz
		
		subvar z 8192
		ifvarvarl z sector[sectnum].ceilingz {
			setvarvar z sector[sectnum].ceilingz
			addvar z 8192
			setactor[THISACTOR].z z
		}
	}
	
	
	ifvare enemy_type WALK {
		ifinwater nullop else {
		ifaction AGBEASTWALK1 ifactioncount 4 action AGBEASTWALK2
		ifaction AGBEASTWALK2 ifactioncount 4 action AGBEASTWALK1 }
			
		ifvare change_ai WALK {
			ifinwater ai AIGBEASTSWIM else ai AIGBEASTWALK
			setvar change_ai -1 
		}
		
		ifinwater { ifvarn target_id -1 ifcansee ifvarg sprite[target_id].extra 0 soundonce GILLSPOT ifai AIGBEASTWALK ai AIGBEASTSWIM }
		else { 	
			ifvarn target_id -1		
			ifcansee ifvarg sprite[target_id].extra 0 
				ifvarl enemyroam 2 soundonce GILLROAM
			ifai AIGBEASTSWIM ai AIGBEASTWALK 
		}
		
		ifvarl targetdist 650
			ifvarg anglefield -384 ifvarl anglefield 384
				ifvarn enemy_invis 1
					setvarvar enemy_ang enemy_hita
	}
	
	ifvare enemy_type ATTACK {
		ifvare change_ai ATTACK {
			ifinwater ai AIGBEASTSWIMATTACK else ai AIGBEASTATTACK 
			setvar change_ai USERAI
		}
		
		ifvare change_ai USERAI { 
			ifvare shoot_var 0 {
				ifactioncount 1 {
					ifvarl targetdist 600 {
						ifvarg anglefield -128 ifvarl anglefield 128 {
							ifvarn enemy_refl 1
								shoot GBEASTHIT 
							else 
								setvar hitself 1
							
						}
						else
							zshoot 8192 GBEASTHIT 
					} else zshoot 8192 GBEASTHIT 
					setvar shoot_var 1
				}
			}
			ifactioncount 3 { 
				ifvare hitself 1 {
					state bloodspraystate 
					getactor[THISACTOR].extra extra
					getprojectile[GBEASTHIT].extra tmp
					subvarvar extra tmp
					setactor[THISACTOR].extra extra
					ifvarg extra 0 { soundonce GILLPAIN 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 {
			soundonce GILLPAIN
				
			ifvarn teslahitenable 1 {
				ai AIGBEASTHIT
			} else
				ai AIGBEASTTESLA
			setvar change_ai USERAI
		}
		
		ifvare change_ai USERAI {
			ifai AIGBEASTHIT
			ifcount 5 { 
				setvar enemy_type WALK
				setvarvar change_ai enemy_type
			}	
			ifai AIGBEASTTESLA { 
				setvar enemy_tesla 1 
				ifcount 30 { 
					setvar enemy_tesla 0 
					setvar teslahitenable 0 
					setvar enemy_type WALK
					setvarvar change_ai enemy_type
				}  
			}
		}	
	}
	
	ifvare enemy_type GETHEAVYDAMAGE {
		ifvare change_ai GETHEAVYDAMAGE {
			state enemyjibs_state 
			ai AIGBEASTGUTS
			setvar burningguyactive 0
			setactor[THISACTOR].extra -100
			setvar change_ai USERAI
		}
		
		ifvare change_ai USERAI {
			ifai AIGBEASTGUTS { iffloordistl 10 ifactioncount 5 { cstat 0 ai AIGBEASTDEAD2 setvar enemy_type DEAD setvar change_ai DEAD } }
		}
	}
	
	ifvare enemy_type VOODOO {
		setvar enemy_type DYING 
		setvar change_ai DYING
	}

	ifvare enemy_type BURNING {
		setvar enemy_type DYING 
		setvar change_ai DYING
	}
	
	ifvare enemy_type DYING {
		ifvare change_ai DYING {
			state bloodsprayshit 
			ifrnd 85 soundonce GILLDIE1 else ifrnd 85 soundonce GILLDIE2 else soundonce GILLDIE3
			ai AIGBEASTDYING
			ifrnd 128 cstat 4 else cstat 0
			setvar change_ai USERAI
		}
		
		ifvare change_ai USERAI {
			ifai AIGBEASTDYING ifactioncount 5 { ai AIGBEASTDEAD setvar change_ai -1 }
		}
	}
	
	ifvarl sprite[THISACTOR].extra 1 
		fall
	
enda
