
action AFISHWALK  0  3  5  1  20
action AFISHBITE 5 3 5 1 20
action AFISHDYING -413 4 1 1 10
action AFISHDEAD -411 1 1 1 10
action AFISHTESLA 1859 1 -5 1 1

move FISHWALK 0
move FISHSTOP 

ai AIFISHWALK AFISHWALK FISHWALK faceplayer
ai AIFISHBITE AFISHBITE FISHSTOP faceplayer 
ai AIFISHSTAY AFISHWALK FISHSTOP 
ai AIFISHTESLA AFISHTESLA FISHSTOP
ai AIFISHDYING AFISHDYING FISHSTOP
ai AIFISHDEAD AFISHDEAD FISHSTOP

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

eventloadactor FISH 
setactor[THISACTOR].xrepeat 24
setactor[THISACTOR].yrepeat 24
getactor[THISACTOR].ang ang
setvarvar enemy_ang ang
enda

spritenoshade FISH

useractor notenemy FISH FISHSTRENGTH sizeat 24 24
	setvar maxSpeed 130
	setvar weight 2
	setvar width 64
	setvar height 768
	setvar enemy_nohitscan_z 1
	setvar cantseetarget 0
	setvar fly_enemy 0
	setactor[THISACTOR].clipdist 16
	
	ifai NO { addvar TOTALKILLS 1 cstat 257 setvarvar enemy_type STAYPUT setvarvar change_ai enemy_type }
	
	ifvare target_inwater 0
		setvar cantseetarget 1 
	else setvar cantseetarget 0
		
	ifvare enemy_type STAYPUT  { 
		ifvare change_ai STAYPUT {
			ai AIFISHSTAY 
			setvar change_ai -1 
		}
		
		ifvare change_ai -1 {
			ifp palive ifcansee {
				state facingstate 
				ifvare set 1 {
					setvarvar target_id PLAYERID 
					soundonce EELROAM 
					setvar enemy_movtype WALK
					setvar change_ai WALK
				}
			}
		}
	}
	
	state mainAI
	
	ifvare enemy_type WALK {
		ifvare change_ai WALK {
			ai AIFISHWALK
			setvar change_ai -1 
		}
		ifcansee ifvarg sprite[target_id].extra 0 { ifvarl enemyroam 4 soundonce EELROAM }
	}
	
	ifvare enemy_type ATTACK {
		ifvare change_ai ATTACK {
			ai AIFISHBITE 
			setvar change_ai USERAI
		}
		
		ifai AIFISHBITE {
			ifvare shoot_var 0 {
				ifactioncount 1 {
					ifvarl targetdist 600 {
						ifvarg anglefield -128 ifvarl anglefield 128 {
							ifvarn enemy_refl 1
								shoot ELLHIT 
							else {
								state bloodspraystate 
								getactor[THISACTOR].extra extra
								getprojectile[ELLHIT].extra htextra
								subvarvar extra htextra
								setactor[THISACTOR].extra extra
								ifvarg extra 0 { soundonce EELPAIN setvar enemy_type GETDAMAGE setvar change_ai GETDAMAGE } else {
								setvar enemy_type DYING setvar change_ai DYING }
							}
						}
						else
							zshoot 8192 ELLHIT
					} else zshoot 8192 ELLHIT
					setvar shoot_var 1
				}
			}
			ifactioncount 3 { 
				getactor[target_id].extra extra
				ifvarg targetdist 550 { 
					ai AIFISHWALK setvar change_ai -1 
				} else {
					ifvarl extra 1 { ai AIFISHWALK setvar change_ai -1 } else
					ifvarg anglefield -128 ifvarl anglefield 128 ifvarn enemy_invis 1 nullop else {
					ai AIFISHWALK setvar change_ai -1
					}
				}
				
				setvar shoot_var 0 
				resetactioncount 
			}
			ifvarl targetdist 600
				ifvarg anglefield -128 ifvarl anglefield 128 
					ifvarn enemy_invis 1
				setvarvar enemy_ang enemy_hita
		}
	}
	
	ifvare enemy_type GETDAMAGE {

		ifvare change_ai GETDAMAGE {
			soundonce EELPAIN 
			ifvare teslahitenable 1 {
				ai AIFISHTESLA
			}
			setvar change_ai USERAI
		}
		
		ifvare change_ai USERAI {
			ifai AIFISHTESLA { setvar enemy_tesla 1 ifcount 30 { ai AIFISHWALK setvar enemy_tesla 0 setvar teslahitenable 0 setvar change_ai -1 }  } else {
				ifcount 5 { 
					setvar enemy_type WALK
					setvar change_ai -1
				}
			}			
		}	
		
	}

	ifvare enemy_type GETHEAVYDAMAGE {
		setvar enemy_type DYING 
		setvar change_ai DYING
	}
	
	ifvare enemy_type VOODOO {
		setvar enemy_type DYING 
		setvar change_ai DYING
	}
	
	ifvare enemy_type DYING {
		ifvare teslahitenable 1 { 
			ifvare change_ai DYING {
				ai AIFISHTESLA
				setvar change_ai USERAI
			}
			ifvare change_ai USERAI {
				ifai AIFISHTESLA { setvar enemy_tesla 1 ifcount 30 { setvar teslahitenable 0 setvar enemy_tesla 0 setvar change_ai DYING } }			
			}	
		} else {
			ifvare change_ai DYING {
				setactor[THISACTOR].extra 0 //чтобы при раздавливании код не повторялся несколько раз
				state bloodsprayshit 
				ifrnd 128 cstat 4 else cstat 0
				ifrnd 96 soundonce EELDIE1 else ifrnd 96 soundonce EELDIE2 else soundonce EELDIE3
				ai AIFISHDYING
				setvar change_ai USERAI
			}
		}
		
		ifvare change_ai USERAI {
			ifai AIFISHDYING ifactioncount 7 { ai AIFISHDEAD setvar change_ai -1 }
		}
	}
	
	ifinwater nullop else ifvarn enemy_type DYING 
	ifvarn enemy_type DEAD {
		setvar enemy_type DYING 
		setvar change_ai DYING
	}
	ifvarl sprite[THISACTOR].extra 1 fall
	
enda