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

action AFATRATWALK  0  4  -5  1  6
action AFATRATWSTAYPUT  0  1  -5  1 
action AFATRATBITE 5 1 -5 1 7
action AFATRATDYING 20 5 1 1 14
action AFATRATDEAD 25 1 1 1 10
action AFATRATBURNING -9 4 1 1 10
action AFATRATBURN -4 4 1 1 40
action AFATRATBURNED -1 1 1 1 10

move FATRATWALK 0
move FATRATSTOP 

ai AIFATRATWALK AFATRATWALK FATRATWALK
ai AIFATRATRANDOM AFATRATWALK FATRATWALK
ai AIFATRATWSTAYPUT AFATRATWSTAYPUT FATRATSTOP
ai AIFATRATSEEK AFATRATWALK FATRATWALK
ai AIFATRATBITE AFATRATBITE FATRATSTOP
ai AIFATRATBURNING AFATRATBURNING FATRATSTOP
ai AIFATRATBURNED AFATRATBURNED FATRATSTOP
ai AIFATRATBURN AFATRATBURN FATRATSTOP
ai AIFATRATDYING AFATRATDYING FATRATSTOP
ai AIFATRATDEAD AFATRATDEAD FATRATSTOP

eventloadactor FATRAT 
setactor[THISACTOR].xrepeat 20
setactor[THISACTOR].yrepeat 20
getactor[THISACTOR].ang ang
setvarvar enemy_ang ang
enda

spritenoshade FATRAT
spriteshadow FATRAT


useractor notenemy FATRAT FATRATSTREGTH sizeat 20 20 
	fall
	setvar maxSpeed 120
	setvar weight 3
	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 }
	ifp phigher ifpdistl 600 ifvarg sprite[THISACTOR].extra 0 { setvar enemy_type DYING setvar change_ai DYING } 
	
	ifvare enemy_type STAYPUT  { 
		ifvare change_ai STAYPUT {
			ai AIFATRATWSTAYPUT 
			setvar change_ai -1 
		}
		
		ifvare change_ai -1 {
			ifp palive ifcansee {
				state facingstate 
				ifvare set 1 {
					setvarvar target_id PLAYERID 
					soundonce RATSPOT 
					setvar enemy_movtype WALK
					setvar change_ai WALK
				}
			}
		}
	}
	
	state mainAI
	
	ifvare enemy_type WALK {
	
		ifvarn target_id -1 ifvarg sprite[THISACTOR].extra 0
		ifcansee ifvarg sprite[target_id].extra 0 { 
			ifvare enemyroam 1 soundonce RATSPOT
		}
	
		ifvare change_ai WALK {
			ai AIFATRATWALK
			setvar change_ai -1 
		}
		
		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 {
			ai AIFATRATBITE 
			setvar change_ai USERAI
		}
		
		ifai AIFATRATBITE {
			setactor[THISACTOR].ang enemy_hita
			ifvare shoot_var 0 {
				ifactioncount 2 {
					ifvarl targetdist 600 {
						ifvarg anglefield -128 ifvarl anglefield 128 {
							ifvarn enemy_refl 1
								shoot RATHIT 
							else {
								state bloodspraystate 
								getactor[THISACTOR].extra extra
								getprojectile[RATHIT].extra tmp
								subvarvar extra tmp
								setactor[THISACTOR].extra extra
								ifvarg extra 0 { soundonce RATPAIN setvar enemy_type GETDAMAGE setvar change_ai GETDAMAGE } else {
								setvar enemy_type DYING setvar change_ai DYING }
							}
						}
						else
							zshoot 8192 RATHIT
					} else zshoot 8192 RATHIT
					setvar shoot_var 1
				}
			}
			ifvarg targetdist 600 {
				ai AIFATRATWALK setvar change_ai -1
			} else {
				ifcount 30 { 
					getactor[target_id].extra extra
					ifvarg targetdist 550 { 
						ai AIFATRATWALK setvar change_ai -1 
					} else {
						ifvarl extra 1 { ai AIFATRATWALK setvar change_ai -1 } else
						ifvarg anglefield -128 ifvarl anglefield 128 ifvarn enemy_invis 1 nullop else {
						ai AIFATRATWALK setvar change_ai -1
						}
					}
					
					setvar shoot_var 0 
					resetcount 
				}
				
				ifvarg anglefield -128 ifvarl anglefield 128 
					ifvarn enemy_invis 1
				setvarvar enemy_ang enemy_hita
			}
		}
	}
	
	ifvare enemy_type GETDAMAGE {

		ifvare change_ai GETDAMAGE {
			soundonce RATPAIN 
			setvar change_ai USERAI
		}
		
		ifvare change_ai USERAI {
			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 BURNING {
		ifvare change_ai BURNING {
			ai AIFATRATBURNING 
			setvar flamedamage 0
			setvar change_ai USERAI 
		}
		
		ifvare change_ai USERAI {
			ifai AIFATRATBURNING { 
				ifactioncount 4 cstat 4
				ifactioncount 8 cstat 0
				ifactioncount 12 cstat 4
				ifactioncount 16 cstat 0
				ifactioncount 20 { ifrnd 128 cstat 4 else cstat 0 ai AIFATRATBURN } 
			}
			ifai AIFATRATBURN { ifactioncount 4 { ai AIFATRATBURNED setvar enemy_type DEAD setvar change_ai DEAD } }
		}
	}
	
	ifvare enemy_type DYING {
		ifvare change_ai DYING {
			setactor[THISACTOR].extra 0 //чтобы при раздавливании код не повторялся несколько раз
			state bloodsprayshit 
			ifrnd 96 soundonce RATDIE1 else ifrnd 96 soundonce RATDIE2 else soundonce RATDIE3
			ai AIFATRATDYING
			ifrnd 128 cstat 4 else cstat 0
			setvar change_ai USERAI
		}
		
		ifvare change_ai USERAI {
			ifai AIFATRATDYING ifactioncount 5 { ai AIFATRATDEAD setvar change_ai -1 }
		}
	}
	
enda