
//---------------------------SPIDER CODE  ///7045

action ASPIDERWALK  0  3  5  1  6
action ASPIDERJUMP  -5 1  5  1  6
action ASPIDERWSTAYPUT  0  1  5  1  1
action ASPIDERBITE 23 1 5 1 1
action ASPIDERDYING -153 4 1 1 20
action ASPIDERDEAD -150 1 1 1 1
action ASPIDERBURNING -23 4 1 1 15
action ASPIDERBURN -30 5 1 1 5
action ASPIDERBURNED -27 1 1 1 1

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

move SPIDERWALK 0
move SPIDERSTOP 

ai AISPIDERWALK ASPIDERWALK SPIDERWALK 
ai AISPIDERJUMP ASPIDERJUMP SPIDERWALK 
ai AISPIDERRANDOM ASPIDERWALK SPIDERWALK
ai AISPIDERWSTAYPUT ASPIDERWSTAYPUT SPIDERSTOP
ai AISPIDERSEEK ASPIDERWALK SPIDERWALK 
ai AISPIDERBITE ASPIDERBITE SPIDERSTOP 
ai AISPIDERBURNING ASPIDERBURNING SPIDERSTOP
ai AISPIDERBURNED ASPIDERBURNED SPIDERSTOP
ai AISPIDERBURN ASPIDERBURN SPIDERSTOP
ai AISPIDERDYING ASPIDERDYING SPIDERSTOP
ai AISPIDERDEAD ASPIDERDEAD SPIDERSTOP

gamevar spider_up 0 2

eventloadactor SPIDER 
setactor[THISACTOR].xrepeat 20
setactor[THISACTOR].yrepeat 20
setvarvar enemy_ang sprite[THISACTOR].ang
enda

actor SPIDER2
espawn SPIDER 
ifvarand sprite[THISACTOR].cstat 8 
	setactorvar[RETURN].spider_up 1
setactor[RETURN].extra GREENSPIDERSTRENGTH
setactor[RETURN].yvel sprite[THISACTOR].yvel 
setactor[RETURN].xvel sprite[THISACTOR].xvel  
setactorvar[RETURN].se_xvel sprite[THISACTOR].xvel  
setactorvar[RETURN].enemy_ang sprite[THISACTOR].ang
setactor[RETURN].pal 4 
killit
enda

spritenoshade SPIDER
spriteshadow SPIDER

useractor notenemy SPIDER REDSPIDERSTRENGTH sizeat 20 20
	ifvare spider_up 0
		fall
	setvar maxSpeed 150
	setvar weight 2
	setvar width 96
	setvar height 1536
	setvar enemy_nohitscan_z 1
	setvar cantseetarget 0
	setvar fly_enemy 0
	setactor[THISACTOR].clipdist 32
	
	ifai NO { addvar TOTALKILLS 1 ifvare spider_up 1 cstat 265 else 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 AISPIDERWSTAYPUT
			setvar change_ai -1 
		}
		
		ifvare change_ai -1 {
			ifp palive ifcansee {
				state facingstate 
				ifvare set 1 {
					ifvare spider_up 1 { 
						cstat 257 setvar spider_up 0 }
					setvarvar target_id PLAYERID 
					soundonce SPIDSPOT
					setvar enemy_movtype WALK
					setvar change_ai WALK
				}
			}
		}
	}
	
	state mainAI
	
	ifinwater ifvarn enemy_type DYING 
	ifvarn enemy_type DEAD {
		setvar enemy_type DYING 
		setvar change_ai DYING
	}
	
	ifvare enemy_type WALK {
		ifvare change_ai WALK {
			ai AIHANDWALK
			setvar change_ai -1 
		}
		
		ifai AISPIDERJUMP { ifcount 12 ai AISPIDERWALK } else ifvare enemy_movtype MOVETOTARGET ifvarl targetdist 2048 ifcount 6 ai AISPIDERJUMP
		ifcansee ifvarg sprite[target_id].extra 0 { ifvare enemyroam 1 soundonce SPIDSPOT }
	}
	
	ifvare enemy_type ATTACK {
		ifvare change_ai ATTACK {
			ai AISPIDERBITE 
			setvar change_ai USERAI
		}
		
		ifai AISPIDERBITE {
			ifvare shoot_var 0 {
				ifactioncount 2 {
					ifvarl targetdist 600 {
						ifvarg anglefield -128 ifvarl anglefield 128 {
							ifvarn enemy_refl 1 {
								ifvare sprite[THISACTOR].pal 4
									shoot SPIDERHIT 
								shoot SPIDERHIT 
								ifvare sprite[THISACTOR].pal 4 {
									ifvarg sprite[target_id].htextra 0 ifrnd 64 { soundonce POWERUP randvar peractor 150 addvar peractor 50 setactorvar[target_id].playerdrunk peractor }
								}
							}
							else {
								state bloodspraystate 
								getactor[THISACTOR].extra extra
								getprojectile[SPIDERHIT].extra tmp
								ifvare sprite[THISACTOR].pal 4 
									mulvar tmp 2
								subvarvar extra tmp
								setactor[THISACTOR].extra extra
								ifvarg extra 0 { soundonce SPIDPAIN  setvar enemy_type GETDAMAGE setvar change_ai GETDAMAGE } else {
								setvar enemy_type DYING setvar change_ai DYING }
							}
						} else zshoot 8192 SPIDERHIT
					} else zshoot 8192 SPIDERHIT
					setvar shoot_var 1
				}
			}
			ifactioncount 26 { 
				getactor[target_id].extra extra
				ifvarg targetdist 550 { 
					ai AIHANDWALK setvar change_ai -1 
				} else {
					ifvarl extra 1 { ai AIHANDWALK setvar change_ai -1 } else
					ifvarg anglefield -128 ifvarl anglefield 128 ifvarn enemy_invis 1 nullop else {
					ai AIHANDWALK 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 SPIDPAIN
			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 AISPIDERBURNING
			setvar spider_up 0
			setvar flamedamage 0
			setvar change_ai USERAI 
		}
		
		ifvare change_ai USERAI {
			ifai AISPIDERBURNING { 
				addvar fire_count 1
				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 AISPIDERBURN } 
			}
			ifai AISPIDERBURN { ifactioncount 4 ai AISPIDERBURNED }
			ifai AISPIDERBURNED { setvar enemy_type DEAD setvar change_ai DEAD }
		}
	}
	
	ifvare enemy_type DYING {
		ifvare change_ai DYING {
			setvar spider_up 0
			setactor[THISACTOR].extra 0 //чтобы при раздавливании код не повторялся несколько раз
			state bloodsprayshit 
			ifrnd 96 soundonce SPIDDIE1 else ifrnd 96 soundonce SPIDDIE2 else soundonce SPIDDIE3
			ifrnd 128 cstat 4 else cstat 0
			ai AISPIDERDYING
			setvar change_ai USERAI
		}
		
		ifvare change_ai USERAI {
			ifai AISPIDERDYING ifactioncount 4 { ai AISPIDERDEAD setvar change_ai -1 }
		}
	}

enda


action ASPBOSSSTAYPUT  0 1 5 1 1
action ASPBOSSSPRINT  -20 2 5 1 40
action ASPBOSSSPRINTFALL  -10 1 5 1 1
action ASPBOSSWALK  -10 3 5 1 20
action ASPBOSSDYING -151 5 1 1 10
action ASPBOSSDEAD -146 1 1 1 1


move SPBOSSWALK 0 512
move SPBOSSSPRINT 256 50
move SPBOSSSPRINTFALL 384 512
move SPBOSSFALL 0 512
move SPBOSSSTOP

ai AISPBOSSSTAYPUT ASPBOSSSTAYPUT SPBOSSFALL
ai AISPBOSSSPRINT ASPBOSSSPRINT SPBOSSSPRINT jumptoplayer
ai AISPBOSSSPRINTFALL ASPBOSSSPRINTFALL SPBOSSSPRINTFALL faceplayer
ai AISPBOSSWALK ASPBOSSWALK SPBOSSWALK
ai AISPBOSSDYING ASPBOSSDYING SPBOSSSTOP
ai AISPBOSSDEAD ASPBOSSDEAD SPBOSSSTOP

eventloadactor BOSSSPIDER
setactor[THISACTOR].xrepeat 46
setactor[THISACTOR].yrepeat 46
setactor[THISACTOR].extra BOSSSPIDERSTRENGTH
enda


spritenoshade BOSSSPIDER
spriteshadow BOSSSPIDER
useractor notenemy BOSSSPIDER BOSSSPIDERSTRENGTH fall sizeat 46 46
	
	state enemyeffects
	ifvarg flamedamage 0 { addvar COUNTER 1 state newfirestate } 
	ifinwater setvar COUNTER 0
	ifvarvare COUNTER flamedamage { setvar flamedamage 0 setvar COUNTER 0 }
	
	getplayer[THISACTOR].i PLAYERID
	setactorvar[THISACTOR].width 128
	setactorvar[THISACTOR].height 8192
	setactor[THISACTOR].clipdist 48
	setvar maxSpeed 70
	setvar weight 4
	state start_coord
	getactor[THISACTOR].extra extra
	getactorvar[PLAYERID].invisible enemy_invis
	ifp pdead setvar enemy_invis 1
	
ifai AISPBOSSDYING { spritepal 0 cstat 0 setactor[THISACTOR].extra 0 soundonce MSPIDIE ifactioncount 4 { cstat 0 state enemykill_trigger ai AISPBOSSDEAD } }
else ifvarg extra 0 { ifhitweapon { ifwasweapon ALTTESLA { ifrnd 128 soundonce MSPIPAN1 else soundonce MSPIPAN2 } state bloodsprayshit } } else ifai AISPBOSSDEAD nullop else ai AISPBOSSDYING

ifai NO { cstat 257 ai AISPBOSSSTAYPUT }
ifai AISPBOSSSTAYPUT { ifp palive ifcansee { state facingstate ifvare set 1 { setvarvar target_id PLAYERID ai AISPBOSSWALK } } }

ifai AISPBOSSWALK
{
	randvar enemyroam 128
	{
		ifvare enemyroam 1 soundonce MSPISPT1 else ifvare enemyroam 2 soundonce MSPISPT2	
		state vectors_calc
		state seeker_calc
		state move_to_vector
		ifcansee ifvarn enemy_invis 1 {
		ifpdistl 3192 nullop else ifrnd 16 ai AISPBOSSSPRINT
		ifrnd 128 { ifrnd 8 { espawn SPIDER setactor[RETURN].pal 7 } } else { ifrnd 8 { espawn SPIDER setactor[RETURN].pal 4 } } } else ifcount 390 { ai AISPBOSSSTAYPUT resetcount }
	}
}
ifai AISPBOSSSPRINT ifactioncount 2 ai AISPBOSSSPRINTFALL
ifai AISPBOSSSPRINTFALL ifactioncount 9 ai AISPBOSSWALK

ifvare burningguyactive 1 { 
	ai AISPBOSSDYING
	setvar flamedamage 100
	setvar burningguyactive 0
}

enda




























