
//------------------------------PHANTASM CODE

actor PHANTOMSKULL 0 FRAME1 sizeat 32 32 enda

defineprojectile PHANTOMSKULL PROJ_WORKSLIKE 32770
defineprojectile PHANTOMSKULL PROJ_HITRADIUS 0
defineprojectile PHANTOMSKULL PROJ_EXTRA 14
defineprojectile PHANTOMSKULL PROJ_EXTRA_RAND 2
defineprojectile PHANTOMSKULL PROJ_SPAWNS BUCHERAXESPAWN
defineprojectile PHANTOMSKULL PROJ_VEL 300 
defineprojectile PHANTOMSKULL PROJ_XREPEAT 32
defineprojectile PHANTOMSKULL PROJ_YREPEAT 32
defineprojectile PHANTOMSKULL PROJ_CSTAT 642

defineprojectile PHANHIT PROJ_WORKSLIKE 4097
defineprojectile PHANHIT PROJ_SPAWNS SHOTSPARK1
defineprojectile PHANHIT PROJ_XREPEAT 3
defineprojectile PHANHIT PROJ_YREPEAT 3
defineprojectile PHANHIT PROJ_DECAL -1
defineprojectile PHANHIT PROJ_RANGE 1526

action APANTWALK 0 5  -5  1  15
action APANTSTAY 0 1  -5  1  1
action APANTATTACK 25 5  -5  1  20
action APANTPAIN 50 1  -5  1  1

action APANTDYING 61 7 1 1  15
action APANTDEAD 67 1 1 1 1
action APANTTESLA 679 1 -5 1 1

move PANTSTOP 

ai AIPANTWALK APANTWALK
ai AIPANTRANDOM APANTWALK
ai AIPANTPAIN APANTPAIN PANTSTOP
ai AIPANTATTACK APANTATTACK PANTSTOP
ai AIPANTATTACK2 APANTATTACK PANTSTOP
ai AIPANTSTAY APANTSTAY PANTSTOP
ai AIPANTDYING APANTDYING PANTSTOP
ai AIPANTDEAD APANTDEAD PANTSTOP
ai AIPANTTESLA APANTTESLA PANTSTOP

eventloadactor PHANTASM 
setactor[THISACTOR].xrepeat 30
setactor[THISACTOR].yrepeat 30
setactor[THISACTOR].extra PHANTASMSTRENGTH
enda

spriteshadow PHANTASM
spritenoshade PHANTASM

useractor notenemy PHANTASM PHANTASMSTRENGTH sizeat 30 30 

	setvar maxSpeed 250
	setvar weight 2
	setvar width 256
	setvar height 4096
	setvar fly_enemy 1
	setvar enemy_nohitscan_z 0
	setvar cantseetarget 0
	
	ifai NO { addvar TOTALKILLS 1 cstat 514 setvarvar enemy_type STAYPUT setvarvar change_ai enemy_type }
	
	ifvare enemy_type STAYPUT  { 
		ifvare change_ai STAYPUT {
			ai AIPANTSTAY
			setvar change_ai -1 
		}
		
		ifvare change_ai -1 {
			ifp palive ifcansee {
				state facingstate 
				ifvare set 1 {
					setvarvar target_id PLAYERID 
					soundonce PHANSPOT 
					setvar enemy_type WALK
					setvar change_ai WALK
				}
			}
		}
	}

	ifvarg sprite[THISACTOR].htextra 0 {
		ifvare teslahitenable 1 {
			setvar enemy_type GETDAMAGE 
			setvar change_ai GETDAMAGE
		} else
		ifvarg sprite[THISACTOR].htextra 30
		ifvare enemy_type ATTACK {
			setvar enemy_type GETDAMAGE 
			setvar change_ai GETDAMAGE
		}
	}
	
	ifvarn target_id -1	
	ifcansee ifvarg sprite[target_id].extra 0
	ifvarn enemy_invis 1 ifvarn enemy_type ATTACK {
		ifvarl targetdist 5192 {
			getactor[THISACTOR].z enemy_z
			getactor[target_id].z target_z
			setvarvar zvel actorvar[target_id].height
			subvarvar target_z zvel
			subvarvar target_z enemy_z
			divvar zvel -2
			subvar zvel 250
			ifvarvarl target_z zvel movesprite THISACTOR 0 0 -500 CLIPMASK0 RETURN else {
				addvar zvel 250
				getactor[THISACTOR].x x
				getactor[THISACTOR].y y
				getactor[THISACTOR].z z
				getactor[THISACTOR].sectnum sectnum
				getflorzofslope sectnum x y mz
				subvarvar mz z
				ifvarvarg target_z zvel ifvarg mz 5192 
					movesprite THISACTOR 0 0 1500 CLIPMASK0 RETURN   
					
			}
		}
	}
	
	state mainAI

	ifvare enemy_type WALK {	
		ifvare change_ai WALK {
			ai AIPANTWALK
			cstat 514
			setvar change_ai -1 
		}
		
		ifvarn target_id -1		
		ifcansee ifvarg sprite[target_id].extra 0 { 
			ifvarl enemyroam 2 soundonce PHANSPOT
		}
		
		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 3092 ifvarl targetdist 6144 {
							setvar enemy_type ATTACK
							ai AIPANTATTACK2
							setvar change_ai USERAI
						} 
					}
				}
			}			
		}
		
		//ifvarvarn enemy_hittid target_id
		ifvarl anglefield -512 ifvarg anglefield 512
			ifvarn enemy_movtype EVASION  
				ifvarn enemy_movtype BLOCK 
					setvar change_ai USERAI 

		ifvare change_ai USERAI	{
			addvar enemy_ang 128
			setactor[THISACTOR].ang enemy_ang
			state move_to_vector
			
			getactor[THISACTOR].x x
			getactor[THISACTOR].y y
			getactor[THISACTOR].z z
			getactor[THISACTOR].sectnum sectnum
			getceilzofslope sectnum x y mz
			subvarvar mz z
			ifvarl mz -16384
				movesprite THISACTOR 0 0 -1500 CLIPMASK0 RETURN
			
			ifcount 100 {
				setvar change_ai WALK
			}
		}
	}
	
	ifvare enemy_type ATTACK {
		cstat 257
		ifp phigher nullop else movesprite THISACTOR 0 0 200 CLIPMASK0 RETURN
			
		ifvare change_ai ATTACK {
			ai AIPANTATTACK 
			setvar change_ai USERAI
		}
		
		ifai AIPANTATTACK2 { //skull
			setactor[THISACTOR].ang enemy_hita
			ifactioncount 3 
			ifvare shoot_var 0 {
				soundonce SKULAIR4
				shoot PHANTOMSKULL
				setvar shoot_var 1
			}
			
			ifactioncount 5 { 
				setvar enemy_type WALK
				setvar change_ai WALK
				setvar shoot_var 0 
				resetactioncount 
			}
		}
	
		ifai AIPANTATTACK { 
			ifvare shoot_var 0 {
				ifactioncount 3 {
					ifvarl targetdist 800 {
						ifvarg anglefield -128 ifvarl anglefield 128 {
							ifvarn enemy_refl 1
								shoot PHANHIT 
							else 
								setvar hitself 1
						}
						else
							zshoot 8192 PHANHIT 
					} else zshoot 8192 PHANHIT 
					soundonce BDYPRTIM
					setvar shoot_var 1
				}
			}
			ifactioncount 5 { 
				ifvare hitself 1 {
					state bloodspraystate 
					getactor[THISACTOR].extra extra
					getprojectile[PHANHIT].extra tmp
					subvarvar extra tmp
					setactor[THISACTOR].extra extra
					ifvarg extra 0 { soundonce PHANPAIN 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 PHANPAIN
			cstat 514
			ifvarn teslahitenable 1 {
				ai AIPANTPAIN
			} else
				ai AIPANTTESLA
			setvar change_ai USERAI
		}
		
		ifvare change_ai USERAI {
			ifai AIPANTPAIN
			ifcount 9 {
				setvar enemy_type WALK
				setvarvar change_ai enemy_type
			}	
			ifai AIPANTTESLA { 
				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 {
		setvar enemy_type DYING 
		setvar change_ai DYING
	}
	
	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 
			soundonce PHANDIE1
			ai AIPANTDYING
			ifrnd 128 cstat 4 else cstat 0
			setvar change_ai USERAI
		}
		
		ifvare change_ai USERAI {
			ifai AIPANTDYING ifactioncount 7 { addkills 1 killit }
		}
	}

	ifvarl sprite[THISACTOR].extra 1 
		fall
enda