const int SNAKE_SPEED = 18; //18 Snake speed
const int SNAKE_CSPEED = 25; //25 Commanded snake speed

actor Snakeman_W : BaseMM8BDMWep_CBM
{
tag "$TAGC_3F"
dropitem "SearchSnakeWep"
Weapon.AmmoUse 2
Weapon.AmmoGive 28
Weapon.AmmoUse2 28
Weapon.AmmoGive2 15
Obituary "$OB_SEARCHSNAKE"
weapon.ammotype "TastySnakeAmmo"
weapon.ammotype2 "SnakeCommandAmmo"
States
{
Spawn:
C_03 F 1
loop

Deselect:
SNAB A 0
goto DeselectSwap
Select:
SNAB A 0
goto SelectSwap

Ready:
SNAB A 0 ACS_NamedExecuteWithResult("core_weaponcolor",DYE_SNAKEMAN)
SNAB A 0
SNAB A 0 A_GunFlash("Flash",1)
goto Ready1
Ready1:
SNAB A 0 A_JumpIfInventory("TastySnakeAmmo",2,"Ready2")
SNAB A 0 A_JumpIfInventory("SnakeCommandAmmo",28,"Ready3")
SNAB A 5 A_WeaponReady(12)
SNAB A 0 A_GiveInventory("TastySnakeAmmo",2)
SNAB A 0 A_GiveInventory("SnakeCommandAmmo",1)
loop
Ready2:
SNAB A 0 A_JumpIfInventory("SnakeCommandAmmo",28,"Ready4")
SNAB A 5 A_WeaponReady(8)
SNAB A 0 A_GiveInventory("TastySnakeAmmo",2)
SNAB A 0 A_GiveInventory("SnakeCommandAmmo",1)
loop
Ready3:
SNAB A 0 A_JumpIfInventory("TastySnakeAmmo",2,"Ready4")
SNAB A 5 A_WeaponReady(4)
SNAB A 0 A_GiveInventory("TastySnakeAmmo",2)
SNAB A 0 A_GiveInventory("SnakeCommandAmmo",1)
loop
Ready4:
SNAB A 5 A_WeaponReady
SNAB A 0 A_GiveInventory("TastySnakeAmmo",2)
SNAB A 0 A_GiveInventory("SnakeCommandAmmo",1)
loop

Fire:
SNAB A 0 A_PlaySoundEx("weapon/mbuster","Weapon")
SNAB A 0 A_FireCustomMissile("SnakePlugBall_H",0,1,-8,0)//SnakeM_SnakeStart
SNAB B 3
SNAB C 2
SNAB C 1 A_GiveInventory("SnakeCommandAmmo",1)
SNAB A 4
SNAB A 0 A_GiveInventory("SnakeCommandAmmo",1)
Goto Ready1
AltFire:
SNAB D 1 A_GiveInventory("CBM_TargetMarker")
SNAB E 1 A_GiveInventory("SearchSnakeCommand",1)
SNAB FG 1
SNAB G 0 A_PlaySoundEx("weapon/Snakecommand","Body")
SNAB G 6 A_FireCustomMissile("SnakemanMeleePoke",0,1,0,0)
SNAB FED 3
SNAB A 2 A_TakeInventory("SearchSnakeCommand",1)
Goto Ready1

Flash:
TNT1 A 1 A_GiveInventory("SnakemanFlashClimb_P",1)
loop
}
}

actor SnakeCommandAmmo : Ammo
{
inventory.amount 1
inventory.maxamount 28
+INVENTORY.IGNORESKILL
}

actor TastySnakeAmmo : Ammo
{
inventory.amount 1
inventory.maxamount 28
+INVENTORY.IGNORESKILL
}

actor SnakeClamberAmmo : Ammo
{
inventory.amount 1
inventory.maxamount 500
+INVENTORY.IGNORESKILL
}

actor SearchSnakeCommand : Powerup
{
Powerup.Duration 18
}
actor SnakeClimbing : OnceC {}

actor SnakeOnWall : PowerUp
{
Powerup.Duration 4
}

actor PowerSnakeSlowSpeed : PowerSpeed
{
powerup.duration 4
Speed 0.8
+POWERSPEED.NOTRAIL
}

actor SnakemanClimbingItem : BasicClassItem
{
inventory.icon "SnakIcon"
inventory.pickupmessage "Metal Gear Sssssolid?!"
Tag "Snake Climb Toggle"
states
{
Spawn:
SNAB Z 1
loop
UseCBM:
TNT1 A 0 A_PlaySoundEx("item/ItemUseMM9","SoundSlot7")
TNT1 A 0 A_JumpIfInventory("SnakeClimbing",1,"Use2")
TNT1 A 0 A_GiveInventory("SnakeClimbing",1)
fail
Use2:
TNT1 A 0 A_TakeInventory("SnakeClimbing",1)
TNT1 A 0 A_TakeInventory("SnakeClamberAmmo",1)
fail
}
}

actor SnakemanFlashClimb_P : CustomInventory
{
states
{
Pickup:
TNT1 A 0 A_JumpIfInventory("SnakeClimbing",1,"Pickup2")
goto PickupAmmo
Pickup2:
TNT1 A 0 A_GiveInventory("SnakeClimbCheckPickup",1)
goto PickupAmmo

PickupAmmo:
TNT1 A 0 A_JumpIf(z-floorz<1,"PickupAmmoYes")
goto PickupClimb
PickupAmmoYes:
TNT1 A 0 A_JumpIfInventory("SnakeClamberAmmo",500,"PickupClimb")
TNT1 A 0 A_GiveInventory("SnakeClamberAmmo",3)
goto PickupClimb

PickupClimb:
TNT1 A 0 A_JumpIfInventory("SnakeOnWall",1,"PickupClimbYes")
TNT1 A 0 A_GiveInventory("CBM_AviationOff_P")
TNT1 A 0 A_TakeInventory("PowerSnakeSlowSpeed",1)
stop
PickupClimbYes:
TNT1 A 0 A_GiveInventory("CBM_AviationOn_P")
TNT1 A 0 A_GiveInventory("PowerSnakeSlowSpeed",1)
stop
}
}

actor SnakeClimbCheckPickup : CustomInventory
{
states
{
Pickup:
TNT1 A 0 A_JumpIfInventory("SnakeClamberAmmo",1,"Success")
stop
Success:
TNT1 A 0 A_SpawnItemEx("SnakeClimbCheck",0,0,16,0,0,34)
TNT1 A 0 //A_FireCustomMissile("SnakeClimbCheck",0,0,0,-12)
stop
}
}

actor SnakeClimbCheck
{
PROJECTILE
+DONTBLAST
+DONTSPLASH
+SKYEXPLODE
+EXPLODEONWATER
+THRUACTORS
+DONTREFLECT
+SERVERSIDEONLY
Damage (0)
//radius 16
//height 56
radius 48//44
height 16
//height 88//112
speed 0
States
{
Spawn:
TNT1 A 0
TNT1 A 0 //A_CheckFloor("Death")
TNT1 A 1
stop
Death:
//TNT1 A 0 A_CheckFloor("Death2")
TNT1 A 0 //A_JumpIf(floorz==z,"Death2")
TNT1 A 0 A_TakeFromTarget("SnakeClamberAmmo",1)
TNT1 A 0 A_GiveToTarget("SnakeOnWall",1)
TNT1 A 1
stop
Death2:
TNT1 A 0
stop
}
}


actor SnakemanMeleePoke
{
PROJECTILE
Damagetype "SnakeM_Poke"//Snake
Obituary "$OB_SNAKEPOKE"
reactiontime 3
damage (80)
Radius 7
Height 7
speed 40
scale 2.5
States
{
Spawn:
TNT1 A 0
TNT1 A 1 A_CountDown
wait
Death:
TNT1 A 0 A_Explode(90,52,0)
goto XDeath
XDeath:
TNT1 A 0 A_Stop
TNT1 A 2
stop
}
}


actor SnakePlugBall_H : BasicHelper
{
Speed 1
Args 18,18
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_SetArg(4,angle*100000)
TNT1 A 0 A_SpawnItemEx("SnakePlugBall",0,0,0,momx,momy,momz,0,8+32+SXF_MULTIPLYSPEED+SXF_TRANSFERSPECIAL)//8192+32768
stop
}
}


actor SnakePlugBall : ProjSpawnFuncActor
{
PROJECTILE
damagetype "SnakeM_Snake"
Obituary "$OB_SEARCHSNAKE"

+SKYEXPLODE

-NOGRAVITY
-BOUNCEONFLOORS
+BOUNCEONWALLS
+BOUNCEONCEILINGS
+USEBOUNCESTATE
+CANBOUNCEWATER

//+ALLOWBOUNCEONACTORS
//+BOUNCEONACTORS

+DONTBLAST
+DONTREFLECT
//+HITTRACER

+NOEXPLODEFLOOR
+STEPMISSILE
maxstepheight 17

bouncefactor 0.50
wallbouncefactor 1.0
gravity 1.00002//65537
reactiontime 1//2
Damage (180)
Radius 6
Height 5
Speed 24
Scale 2.5
Args 18,18
States
{
Spawn:
TNT1 A 0
Q_3F A 0 A_SetArg(4,angle*100000)
Spawned:
Q_3F A 0 ThrustThingZ(0,0,0,1)//Resync
Q_3F A 0 ThrustThing(angle*256/360,0,1,0)
InAir:
Q_3F A 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F A 1 A_JumpIf(z-floorz==0,"HitGround")
Q_3F A 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F A 1 A_JumpIf(z-floorz==0,"HitGround")
Q_3F B 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F B 1 A_JumpIf(z-floorz==0,"HitGround")
Q_3F B 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F B 1 A_JumpIf(z-floorz==0,"HitGround")
loop

Command:
"----" # 0 ACS_NamedExecuteWithResult("core_aimattargetcursor",CallACS("core_gettarget")+PLN_TARGETPOINT_OFFSET)
"----" # 0 A_SpawnItemEx("SnakePlugBall_Fiat",0,0,0,25,0,8,0,1)
stop

OnFloor:
Q_3F A 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F A 1 A_JumpIf(z-floorz>18,"Fell")
Q_3F B 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F B 1 A_JumpIf(z-floorz>18,"Fell")
Q_3F B 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F B 1 A_JumpIf(z-floorz>18,"Fell")
Q_3F B 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F B 1 A_JumpIf(z-floorz>18,"Fell")
Q_3F B 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F B 1 A_JumpIf(z-floorz>18,"Fell")
Q_3F A 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F A 1 A_JumpIf(z-floorz>18,"Fell")
Q_3F A 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F A 1 A_JumpIf(z-floorz>18,"Fell")
Q_3F A 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F A 1 A_JumpIf(z-floorz>18,"Fell")
Q_3F A 0 A_JumpIf(sqrt(momx*momx+momy*momy)<4,1)
loop
Q_3F A 0 A_JumpIf(Args[2]>6,"Death")
Q_3F A 0 A_SetArg(2,Args[2]+1)
loop

Fell:
Q_3F E 0 //A_Log("Fell")
Q_3F E 0 A_SetGravity(0.0)
Q_3F E 0 A_ChangeVelocity(0,0,-Args[1],3)
Q_3F E 0 //ThrustThingZ(0,0,0,1)
Q_3F E 0 ThrustThing(angle*256/360,0,1,0)
Falling:
Q_3F E 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F E 1 A_JumpIf(z-floorz==0,"HitGround")
Q_3F E 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F E 1 A_JumpIf(z-floorz==0,"HitGround")
Q_3F F 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F F 1 A_JumpIf(z-floorz==0,"HitGround")
Q_3F F 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F F 1 A_JumpIf(z-floorz==0,"HitGround")
Q_3F F 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F F 1 A_JumpIf(z-floorz==0,"HitGround")
Q_3F F 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F F 1 A_JumpIf(z-floorz==0,"HitGround")
Q_3F E 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F E 1 A_JumpIf(z-floorz==0,"HitGround")
Q_3F E 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F E 1 A_JumpIf(z-floorz==0,"HitGround")
loop
HitGround:
Q_3F A 0 //A_Log("HitGround")
Q_3F A 0 A_SetGravity(1.0)
Q_3F A 0 A_ChangeVelocity(Args[0],0,momz,3)
Q_3F A 0 //ThrustThingZ(0,0,0,1)
Q_3F A 1 //ThrustThing(angle*256/360,0,1,0)
goto OnFloor

/*
Bounce.Actor:
Q_3F # 0 ////A_Log("Bounce.Actor")
Q_3F # 0 //A_JumpIf(CallACS("uh_IsTracerAllyOrEnemy")==-1,"BouncedOnFoe")
goto Bounce.Wall+1
BouncedOnFoe:
Q_3F # 0 //////A_SetArg(2,118)
goto Bounce.Wall+1
*/
Bounce.Wall:
Q_3F C 0 //A_Log("Bounce.Wall")
Q_3F C 0 A_SetAngle(Args[4]/100000)
Q_3F C 0 A_SetGravity(0.0)
Q_3F C 0 A_ChangeVelocity(0,0,Args[1],3)
Q_3F C 0 ThrustThingZ(0,0,0,1)
Q_3F C 0 ThrustThing(angle*256/360,0,1,0)
Q_3F C 0 A_SetArg(3,Args[3]+1)

Q_3F C 2 A_JumpIf(Args[3]>2,1)
goto RiseThrust
Q_3F D 2 A_JumpIf(Args[3]>4,1)
goto RiseThrust
Q_3F C 2 A_SetArg(3,0)
goto RiseThrust

RiseThrust:
Q_3F # 0 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
Q_3F # 0 A_SetGravity(1.0)
Q_3F # 0 A_ChangeVelocity(5,0,Args[1]/3.0,3)
Q_3F # 0 //ThrustThingZ(0,0,0,1)
Q_3F # 2 //ThrustThing(angle*256/360,0,1,0)
Q_3F # 0 //////A_SetArg(2,0)
goto Spawned//InAir

Rising:
Q_3F CCDDDDCC 1 A_JumpIfInTargetInventory("SearchSnakeCommand",1,"Command")
//A_Warp(0,16,0,0,0,WARPF_TESTONLY,"HitGround")//Sadness
loop

Bounce.Ceiling:
//Hitting the ceiling on initial spawn
Q_3F E 0 A_JumpIf(CallACS("core_getactorproperty",0,APROP_Gravity,0)==65537,"Fell")
Q_3F E 0 //A_Log("Bounce.Ceiling")
Q_3F E 0 A_CountDown
Q_3F E 0 //////A_SetArg(2,0)
Q_3F E 0 A_JumpIf(1,3)//Sync client?! so snake doesn't fall from the ceiling with gravity
Q_3F E 0 A_SetArg(4,Args[4]-180*100000)
Q_3F E 0 A_SetAngle(Args[4]/100000)
goto Fell
Q_3F E 0 A_SetArg(4,Args[4]-180*100000)
Q_3F E 0 A_SetAngle(Args[4]/100000)
goto Fell

Death:
TNT1 A 0
stop
}
}

actor SnakePlugBall_Fiat : SnakePlugBall
{
damagetype "SnakeM_Snake2"
Args 25,25
States
{
Spawn:
R_3F A 0
R_3F A 0 A_SetArg(4,angle*100000)
Spawned:
R_3F A 0 ThrustThingZ(0,0,0,1)
R_3F A 0 ThrustThing(angle*256/360,0,1,0)
InAir:
R_3F AABB 1 A_JumpIf(z-floorz==0,"HitGround")
loop

OnFloor:
R_3F ABBBBAAA 1 A_JumpIf(z-floorz>18,"Fell")
R_3F A 0 A_JumpIf(sqrt(momx*momx+momy*momy)<4,1)
loop
R_3F A 0 A_JumpIf(Args[2]>6,"Death")
R_3F A 0 A_SetArg(2,Args[2]+1)
loop
Fell:
R_3F E 0 A_SetGravity(0.0)
R_3F E 0 A_ChangeVelocity(0,0,-Args[1],3)
R_3F E 0 ThrustThing(angle*256/360,0,1,0)
Falling:
R_3F EEFFFFEE 1 A_JumpIf(z-floorz==0,"HitGround")
loop
HitGround:
R_3F A 0 A_SetGravity(1.0)
R_3F A 1 A_ChangeVelocity(Args[0],0,momz,3)
goto OnFloor


//Bounce.Actor:
Bounce.Wall:
R_3F C 0 A_SetAngle(Args[4]/100000)
R_3F C 0 A_SetGravity(0.0)
R_3F C 0 A_ChangeVelocity(0,0,Args[1],3)
R_3F C 0 ThrustThingZ(0,0,0,1)
R_3F C 0 ThrustThing(angle*256/360,0,1,0)
R_3F C 0 A_SetArg(3,Args[3]+1)

R_3F C 2 A_JumpIf(Args[3]>2,1)
goto RiseThrust
R_3F D 2 A_JumpIf(Args[3]>4,1)
goto RiseThrust
R_3F C 2 A_SetArg(3,0)
goto RiseThrust

RiseThrust:
R_3F # 0 A_SetGravity(1.0)
R_3F # 2 A_ChangeVelocity(5,0,Args[1]/3.0,3)
goto Spawned

Rising:
R_3F CCDDDDCC 1
loop

Bounce.Ceiling:
R_3F E 0 A_JumpIf(CallACS("core_getactorproperty",0,APROP_Gravity,0)==65537,"Fell")
R_3F E 0 A_CountDown
R_3F E 0 A_JumpIf(1,3)
R_3F E 0 A_SetArg(4,Args[4]-180*100000)
R_3F E 0 A_SetAngle(Args[4]/100000)
goto Fell
R_3F E 0 A_SetArg(4,Args[4]-180*100000)
R_3F E 0 A_SetAngle(Args[4]/100000)
goto Fell
}
}


actor Snakeman_W_NormalBar : NormalBar {Args 4,110}
actor Snakeman_W_SecondBar : SecondBar {Args 4,94}
actor Snakeman_W_ScriptBar : ScriptBar {}