
//------------------------------CERBERUS BOSS

gamevar half_dead 0 2
gamevar attack_type 0 2
gamevar end_attack 0 2
gamevar hlf_health 0 2

eventloadactor CERBERUS 
setactor[THISACTOR].xrepeat 48
setactor[THISACTOR].yrepeat 48
setactor[THISACTOR].extra CERBERUSSTRENGTH
enda

move CERBERWALK
move CERBERSTOP 

action CERB1A1 25 4 -5 1 15
action CERB1D1 45 4 -8 1 24
action CERB1E1 1069 1 -5 1
action CERB1I1 -5 1 -5 1
action CERB1M1 0  5  -5  1  18
action CERB1R1 53 1 -8 1
action CERB2A1 -21 2 -8 1 22
action CERB2I1 69 1 -8 1
action CERB2D1 117 4 1 1 21
action CERB2D2 120 1 1 1 
action CERB2D3 121 5 1 1 21
action CERB2D4 126 1 1 1 1
action CERB2M1 77 5 -8 1 24
action CERB2R1 -21 1 -8 1

ai AICERBIDLE1 CERB1I1 CERBERSTOP
ai AICERBIDLE2 CERB2I1 CERBERSTOP
ai AICERBATTACK CERB1A1 CERBERSTOP
ai AICERBDYING1 CERB1I1 CERBERSTOP
ai AICERBELECTR CERB1E1 CERBERSTOP
ai AICERBMOVING CERB1M1 CERBERWALK
ai AICERBR1 CERB1I1 CERBERSTOP
ai AICERBATTACK2 CERB2A1 CERBERSTOP
ai AICERBDYING2 CERB2D1 CERBERSTOP
ai AICERBMOVING2 CERB2M1 CERBERWALK
ai AICERBR2 CERB2I1 CERBERSTOP
ai AICERBDEAD CERB2D4 CERBERSTOP

state pain
ifrnd 128 soundonce CERPAIN1 else soundonce CERPAIN2 
ends

state spot
soundonce CERSPOT2 
ends

state die 
soundonce CERDIE1
ends 

state cerb_attack1
	setactor[THISACTOR].ang enemy_hita
	setvarvar enemy_ang enemy_hita
	eshoot HELLFLAME
	getactor[THISACTOR].z z
	subvarvar z height
	subvarvar z 2060
	setactor[RETURN].z z
	
	setvarvar y enemy_y
	addvar y 160
	rotatepoint enemy_x enemy_y enemy_x y enemy_hita x2 y2
	setactor[RETURN].x x2
	setactor[RETURN].y y2

	ifvare half_dead 0 {
		setvarvar ang enemy_hita
		addvar ang 16
		setactor[RETURN].ang ang

		eshoot HELLFLAME
		setactor[RETURN].z z
		setvarvar y enemy_y
		subvar y 160
		rotatepoint enemy_x enemy_y enemy_x y enemy_hita x2 y2
		setactor[RETURN].x x2
		setactor[RETURN].y y2

		setvarvar ang enemy_hita
		subvar ang 16
		setactor[RETURN].ang ang
	}
ends

state cerb_attack2
	setactor[THISACTOR].ang enemy_hita
	setvarvar enemy_ang enemy_hita
	eshoot PR_NAPALM
	getactor[THISACTOR].z z
	subvarvar z height
	subvarvar z 2560
	setactor[RETURN].z z

	setvarvar y enemy_y
	addvar y 160
	rotatepoint enemy_x enemy_y enemy_x y enemy_hita x2 y2
	setactor[RETURN].x x2
	setactor[RETURN].y y2

	ifvare half_dead 0 {
		setvarvar ang enemy_hita
		addvar ang 16
		setactor[RETURN].ang ang
		
		
		eshoot PR_NAPALM
		setactor[RETURN].z z
		setvarvar y enemy_y
		subvar y 160
		rotatepoint enemy_x enemy_y enemy_x y enemy_hita x2 y2
		setactor[RETURN].x x2
		setactor[RETURN].y y2

		setvarvar ang enemy_hita
		subvar ang 16
		setactor[RETURN].ang ang
	}
ends

state animation_controller
	ifai AICERBATTACK {
		ifaction CERB1A1 ifactioncount 4 action CERB1I1
		ifaction CERB1I1 ifactioncount 2 { action CERB1A1 setvar end_attack 1 }
	}
	ifai AICERBDYING1 {
		ifaction CERB1I1 ifactioncount 6 action CERB1D1
		ifaction CERB1D1 ifactioncount 4 { 
			getactor[THISACTOR].cstat tmp
			orvar tmp 256
			setactor[THISACTOR].cstat tmp
			setvar half_dead 1 
		}
	}
	ifai AICERBR1 {
		ifaction CERB1I1 ifactioncount 5 action CERB1R1
		ifaction CERB1R1 ifactioncount 12 action CERB1I1 
	}
	ifai AICERBATTACK2 {
		ifaction CERB2A1 ifactioncount 2 action CERB2I1
		ifaction CERB2I1 ifactioncount 2 { action CERB2A1 setvar end_attack 1 }
	}
	ifai AICERBDYING2 {
		ifaction CERB2D1 ifactioncount 4 action CERB2D2 
		ifaction CERB2D2 ifactioncount 30 action CERB2D3
		ifaction CERB2D3 ifactioncount 5 action CERB2D4
	}
	ifai AICERBR2 {
		ifaction CERB2I1 ifactioncount 5 action CERB2R1
		ifaction CERB2R1 ifactioncount 12 action CERB2I1 
	}
ends

spriteshadow CERBERUS
spritenoshade CERBERUS

useractor notenemy CERBERUS CERBERUSSTRENGTH 
	sizeat 48 48
	fall
	setvar maxSpeed 120
	setvar addition_weight 10
	setvar weight 2
	setvar width 256
	setvar height 8192
	setvar enemy_nohitscan_z 0
	setvar cantseetarget 0
	setvar fly_enemy 0
	
	ifai NO { addvar TOTALKILLS 1 cstat 257 setvarvar enemy_type STAYPUT setvarvar change_ai enemy_type }
	
	state animation_controller
	ifvare enemy_type STAYPUT  { 
		ifvare change_ai STAYPUT {
			ifvare half_dead 0 
				ai AICERBIDLE1
			else 
				ai AICERBIDLE2
			setvar change_ai -1 
		}
		
		ifvare change_ai -1 {
			ifp palive ifcanseetarget {
				state facingstate 
				ifvare set 1 {
					setvarvar target_id PLAYERID 
					state spot
					setvar enemy_movtype WALK
					setvar change_ai WALK
				}
			}
		}
	}
	
	ifvarg sprite[THISACTOR].htextra 0 {
		ifvare sprite[THISACTOR].htpicnum PR_NAPALM ifvarvare sprite[THISACTOR].htowner THISACTOR {
			setvar change_ai -1
			setvar teslahitenable 0
			setactor[THISACTOR].htextra -1
		}
	}
			
	
	state mainAI

	setvar hlf_health CERBERUSSTRENGTH
	divvar hlf_health 2	
	ifvarn enemy_type GETDAMAGE
	ifvarvarl extra hlf_health 
	ifvare half_dead 0 {
		ai AICERBDYING1
		
		getactor[THISACTOR].cstat tmp
		ifvarand tmp 256 xorvar tmp 256
		setactor[THISACTOR].cstat tmp
	
		setvar enemy_type GETDAMAGE
		setvar change_ai USERAI
	}
	
	ifvarvarl extra hlf_health 
	ifvare teslahitenable 1 {
		setvar teslahitenable 0
	}
	
	ifvarn enemy_type DYING
	ifvarn enemy_type GETDAMAGE
	ifvarg htextra 150 ifvarg extra 0 {
		setvar enemy_type GETDAMAGE
		setvar change_ai GETDAMAGE
	}
	
	ifvare enemy_type WALK {
	
		ifvare change_ai WALK {
			ifvare half_dead 0 
				ai AICERBMOVING
			else 
				ai AICERBMOVING2
			setvar change_ai -1 
		}
		
		ifvarn target_id -1		
		ifcansee ifvarg sprite[target_id].extra 0 { 
			ifvarl enemyroam 2 state spot
		}
		
		ifvarvare target_id PLAYERID
		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 1024 ifvarl targetdist 3092 {
							setvar enemy_type ATTACK
							setvar attack_type 1
							setvar shoot_var 0 
							setvar change_ai ATTACK
						} else
						ifvarg targetdist 3092 ifvarl targetdist 4096 {
							setvar enemy_type ATTACK
							setvar attack_type 2
							setvar shoot_var 0 
							setvar change_ai ATTACK
						}
					}
				}
			}			
		}
	}

	ifvare enemy_type ATTACK {
		ifvare change_ai ATTACK {
			ifvare half_dead 0 
				ai AICERBATTACK 
			else
				ai AICERBATTACK2
			setvar change_ai USERAI
		}

		ifvare attack_type 1 { 
			ifactioncount 1 
			ifvare shoot_var 0 {
				state cerb_attack1
				setvar shoot_var 1
			}
			
			ifvare end_attack 1 { 
				setvar enemy_type WALK
				setvar change_ai WALK
				setvar attack_type 0
				setvar shoot_var 0 
				setvar end_attack 0
				resetactioncount 
			}
		}
		
		ifvare attack_type 2 { 
			ifactioncount 1
			ifvare shoot_var 0 {
				state cerb_attack2
				setvar shoot_var 1
			}
			
			ifvare end_attack 1 { 
				setvar enemy_type WALK
				setvar change_ai WALK
				setvar shoot_var 0 
				setvar attack_type 0
				setvar end_attack 0
				resetactioncount 
			}
		}

		ifvare attack_type 0 { 
			ifvare shoot_var 0 {
				ifactioncount 1 {
					ifvarl targetdist 900 {
						ifvarg anglefield -128 ifvarl anglefield 128 {
							ifvarn enemy_refl 1
								shoot BUCHERAXE 
							else 
								setvar hitself 1
						}
						else
							zshoot 8192 BUCHERAXE
					} else zshoot 8192 BUCHERAXE
					setvar shoot_var 1
				}
			}
			
			ifvare end_attack 1 { //ближняя аттака
				ifvare hitself 1 {
					state bloodspraystate 
					getactor[THISACTOR].extra extra
					getprojectile[BUCHERAXE].extra tmp
					subvarvar extra tmp
					setactor[THISACTOR].extra extra
					ifvarg extra 0 { state pain setvar enemy_type GETDAMAGE setvar change_ai GETDAMAGE } else {
					setvar enemy_type DYING setvar change_ai DYING }
				}
			
				getactor[target_id].extra extra
				ifvarg targetdist 984 { 
					setvar change_ai -1
				} else {
					ifvarl extra 1 { setvar change_ai -1 } else
					ifvarg anglefield -128 ifvarl anglefield 128 ifvarn enemy_invis 1 nullop else {
						setvar change_ai -1
					}
				}
				
				setvar hitself 0
				setvar shoot_var 0 
				setvar end_attack 0
				resetactioncount 
			}
			
			ifvarl targetdist 984
			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 {
			ifvare teslahitenable 1 ifvare enemy_htpic ALTTESLA {
				ai AICERBELECTR
				setvar change_ai USERAI
			} else ifvarn change_ai USERAI {
		
				ifvarg htextra 150 {
					state pain
						
					ifvarvarg extra hlf_health {
						ai AICERBR1
					}
					else {
						ifvare half_dead 0 { 
							ai AICERBDYING1
						} else {
							ai AICERBR2
						}
					}
					setvar change_ai USERAI
				} else {
					setvar change_ai -1
				}
			}
		}
		
		ifvare change_ai USERAI {
			ifvare teslahitenable 1 {
				ifai AICERBELECTR { setvar enemy_tesla 1 ifcount 30 { setvar teslahitenable 0 setvar enemy_tesla 0 setvar change_ai -1 }  }			
				ifai AICERBDYING1 setvar teslahitenable 0 
				ifai AICERBR2 setvar teslahitenable 0 
			} else {
				ifai AICERBDYING1 {
					ifvare half_dead 1 { 
						setvar enemy_type WALK 
						setvar change_ai WALK
					}
				} else
				ifactioncount 8 { 
					setvar enemy_type WALK 
					setvar change_ai WALK
				}
			}	
			setvar shoot_var 0 
			setvar attack_type 0
			setvar end_attack 0			
		}	
	}
	
	ifvare enemy_type GETHEAVYDAMAGE {
		setvar enemy_type DYING 
		setvar change_ai DYING
	}

	ifvare enemy_type DYING {
		ifvare change_ai DYING {
			setactor[THISACTOR].extra 0
			state bloodsprayshit 
			state die
			ai AICERBDYING2
			ifrnd 128 cstat 4 else cstat 0
			setvar change_ai USERAI
		}
		
		ifvare change_ai USERAI {
			ifai AICERBDYING2 ifaction CERB2D4 { ai AICERBDEAD setvar change_ai -1 }
		}
	}
enda
