actor IceCircleWep_NormalBar : NormalBar {args 4, 205}
actor IceCircleWep_ScriptBar : ScriptBar {}

actor IceCircleWep : BaseMM8BDMWep
{
	//$Category RNC-Weapons
	//$Title Ice Circle
	//$Sprite RNCWB0
	Weapon.AmmoGive 28
	weapon.ammouse 7
	Weapon.SlotNumber 7
	Tag "$TAG_ICECIRCLE"
	Obituary "$OB_ICECIRCLE"
	Inventory.Pickupmessage "$PU_ICECIRCLE"
	weapon.ammotype "IceCircleAmmo"
	inventory.icon "RNCWP2"
	States
	{
		SpawnLoop:
			RNCW B -1
			loop

		Ready:
			NCH1 G 0 ACS_NamedExecuteWithResult("core_weaponcolor",CLR_ICECIRCLE)
			NCH1 G 0 A_ClearRefire
			NCH1 G 1 A_WeaponReady
			goto Ready+2

		Deselect:
			NCH1 G 0 A_TakeInventory("ShieldCheck",1)
			NCH1 G 0 A_TakeInventory("IceCircleCharge",99)
			goto DeselectSwap
		Select:
			NCH1 G 0
			goto SelectSwap
			
		Fire:
			NCH1 G 0 A_JumpIfInventory("ShieldCheck",1,"ShieldThrow")
			NCH1 G 0 A_JumpIfNoAmmo("NoAmmo")
			NCH1 G 0 A_PlaySoundEx("weapons/mm6/blizzardattackfire","Weapon")
			NCH1 G 0 A_TakeInventory("IceCircleAmmo",7)
			NCH1 GHIJKL 1
			NCH1 L 0 A_GiveInventory("ShieldCheck",1)
			NCH1 L 0 A_GiveInventory("IceCircleCharge",24)
			NCH1 L 0 A_SpawnItemEx("IceCircleWarper")
			TNT1 A 0 A_SpawnItemEx("IceCircleMover")
			goto ShieldActive
		Hold:
			NCH1 G 1
			goto Ready+1
		ShieldActive:
			NCH1 MN 2
			NCH1 N 0 A_SpawnItemEx("IceRadius",0,0,0)
			goto Shield
		Shield:
			NCH1 G 4 A_WeaponReady
			NCH1 G 0 A_SpawnItemEx("IceRadius",0,0,0)
			NCH1 G 0 A_TakeInventory("IceCircleCharge",1)
			NCH1 G 0 A_JumpIfInventory("IceCircleCharge",1,"Shield")
		ShieldThrow:
			NCH1 G 0 A_TakeInventory("IceCircleCharge",99)
			NCH1 OP 2
			NCH1 G 0 A_TakeInventory("ShieldCheck",1)
			NCH1 P 0 A_FireCustomMissile("IceCircleShot",0,0,0,0)
			NCH1 Q 15
			NCH1 PO 3
			goto Ready+1

		NoAmmo:
			NCH1 G 1 ACS_NamedExecute("core_noammo",0)
			goto Ready+1
	}
}

actor IceCircleAmmo : Ammo {inventory.amount 1 inventory.maxamount 28}

actor IceCircleCharge : WeaponCharge
{
	inventory.maxamount 24
}

actor IceCircleWarper : BaseShieldWarper
{
	States
	{
		Shield:
			RNCP CCDDEE 1 A_Warp(AAPTR_TARGET, 0, 0, 0, 0, WARPF_INTERPOLATE|WARPF_NOCHECKPOSITION)
		ShieldLoop:
			RNCP FFGGHHII 1 A_Warp(AAPTR_TARGET, 0, 0, 0, 0, WARPF_INTERPOLATE|WARPF_NOCHECKPOSITION)
			loop
	}
}

actor IceRadius : BasicExplosion
{
	Damagetype "IceCircle"
	Obituary "$OB_ICECIRCLE"
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_SpawnItemEx("IcePitFreeze")
			TNT1 A 0 A_Explode(CallACS("rnc_cbm_damage",13),130,0)
			stop
	}
}

actor IceCircleBounce : BasicProjectile
{
	BounceSound "weapon/freezecrackerhit"
	Bouncetype Doom
	-BOUNCEONFLOORS
	+MOVEWITHSECTOR
	+CANBOUNCEWATER
	+DONTSPLASH
	+NOEXPLODEFLOOR
	+STEPMISSILE
	//Maxstepheight 7
	Maxstepheight 24
	+BOUNCEONACTORS
	+SKYEXPLODE
	Bouncefactor 1.0
	Wallbouncefactor 1.0
}

const int ICECIRCLE_GROUND_NUM = 11;
const int ICECIRCLE_GROUND_DIV = 5;
const int ICECIRCLE_AIR_NUM = 3;
const int ICECIRCLE_AIR_DIV = 5;

actor IceCircleSpeed : PowerSpeed
{
	+POWERSPEED.NOTRAIL
	Speed 0.75
	Powerup.Duration 5
}

actor IceCircleMover : IceCircleBounce
{
	+SERVERSIDEONLY

	+NOBOUNCESOUND
	+USEBOUNCESTATE

	+DONTBLAST
	+DONTREFLECT
	+THRUGHOST

	Radius 15
	Height 54
	damage (0)

	var int user_owner;
	var int user_ground;
	var int user_air;
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_owner", ACS_NamedExecuteWithResult("core_gettarget",0))
			TNT1 A 0 A_TakeFromTarget("IceCircleStoppedFlag",999)
		Spawn2:
			TNT1 A 0 A_JumpIfInTargetInventory("ShieldCheck",1,"Spawn3")
			goto TheEnd
		Spawn3:
			TNT1 A 0 A_Warp(AAPTR_TARGET, 0, 0, 0, 0, WARPF_INTERPOLATE|WARPF_NOCHECKPOSITION|WARPF_USECALLERANGLE)
			TNT1 A 0 A_ChangeVelocity(30,0,0,CVF_RELATIVE|CVF_REPLACE)
			//TNT1 A 0 A_LogInt(angle)
			TNT1 A 0 A_SpawnItemEx("IceCircleMoveCheck")
			TNT1 A 0 A_JumpIfInTargetInventory("IceCircleStoppedFlag",6,"TurnAround")
			goto Spawn4
		TurnAround:
			//TNT1 A 0 A_Log("turn around")
			TNT1 A 0 A_PlaySound("weapon/freezecrackerhit")
			TNT1 A 0 A_TakeFromTarget("IceCircleStoppedFlag",999)
			TNT1 A 0 A_SetAngle(angle+180)
			goto Spawn4
		Spawn4:
			TNT1 A 0 A_GiveToTarget("IceCircleSpeed",1)
			TNT1 A 0 A_CheckFloor("Spawn4B")
			//TNT1 A 0 A_Log(air)
			//TNT1 A 0 A_LogInt((user_air+ICECIRCLE_AIR_NUM)/ICECIRCLE_AIR_DIV)
			TNT1 A 0 ThrustThing(angle*256/360,(user_air+ICECIRCLE_AIR_NUM)/ICECIRCLE_AIR_DIV,1,user_owner)
			TNT1 A 0 A_SetUserVar("user_air",(user_air+ICECIRCLE_AIR_NUM)%ICECIRCLE_AIR_DIV)
			goto SpawnEnd
		Spawn4B:
			//TNT1 A 0 A_Log(ground)
			//TNT1 A 0 A_LogInt(user_ground+ICECIRCLE_GROUND_NUM)/ICECIRCLE_GROUND_DIV)
			TNT1 A 0 ThrustThing(angle*256/360,(user_ground+ICECIRCLE_GROUND_NUM)/ICECIRCLE_GROUND_DIV,1,user_owner)
			TNT1 A 0 A_SetUserVar("user_ground",(user_ground+ICECIRCLE_GROUND_NUM)%ICECIRCLE_GROUND_DIV)
			goto SpawnEnd
		SpawnEnd:
			TNT1 A 1
			//PLAY A 1
			TNT1 A 0 A_ChangeFlag("USEBOUNCESTATE",1)
			goto Spawn2
		Bounce:
			TNT1 A 0 A_ChangeFlag("USEBOUNCESTATE",0)
			TNT1 A 0 A_PlaySound("weapon/freezecrackerhit")
			goto Spawn2
		Death:
		TheEnd:
			TNT1 A 0
			stop
	}
}

actor IceCircleStoppedFlag : Inventory
{
	inventory.amount 1
	inventory.maxamount 6
}

actor IceCircleMoveCheck
{
	PROJECTILE
	+SERVERSIDEONLY
	+NOINTERACTION
	+NOCLIP
	+DONTBLAST
	damage (0)
	radius 1
	height 1
	speed 0
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 1
			TNT1 A 0 A_JumpIfCloser(2,"Stopped")
			//TNT1 A 0 A_JumpIfCloser(3,"Stopped")
			//TNT1 A 0 A_JumpIfCloser(5,"Stopped")
			//TNT1 A 0 A_Log("Going")
			TNT1 A 0 A_TakeFromTarget("IceCircleStoppedFlag",1)
			stop
		Stopped:
			//TNT1 A 0 A_Log("Stopped")
			TNT1 A 1 A_GiveToTarget("IceCircleStoppedFlag",1)
			stop
	}
}

actor IceCircleShot : IceCircleBounce
{
	+RIPPER
	-NOGRAVITY
	Damagetype "IceCircle"
	Obituary "$OB_ICECIRCLE"
	damage (0)
	Gravity 0.8
	Radius 12
	Height 12
	Speed 20
	reactiontime 24
	States
	{
		Spawn:
			RNCP F 0
			TNT1 A 0 A_CountDown
			TNT1 A 0 A_SpawnItemEx("IcePitFreeze")
			TNT1 A 0 A_Explode(CallACS("rnc_cbm_damage",9),90,0)
			RNCP FG 2
			TNT1 A 0 A_CountDown
			TNT1 A 0 A_SpawnItemEx("IcePitFreeze")
			TNT1 A 0 A_Explode(CallACS("rnc_cbm_damage",9),90,0)
			RNCP HI 2
			loop
	}
}