class CratePosition : SquareActor
{
	Default
	{
		+SOLID;
		+NOGRAVITY;
		+DONTSPLASH;
		RenderStyle 'None';
		Radius 10;
		Height 42;
	}
	States
	{
	Spawn:
		TNT1 A 0;
		Stop;
	}
}

class Crate : SwitchableDecoration
{
	// [XA] the user_ prefix is no longer required in zscript, but this variable's
	// referenced in ACS (it's the only one) so it'll need to stay until refactoring.
	int user_itemspawnid;

	Default
	{
		PushFactor 0.75;
		Health 20;
		Radius 10;
		Height 42;
		+SOLID;
		+SHOOTABLE;
		+NOBLOOD;
		+NOBLOCKMONST;
		+PUSHABLE;
		+DONTGIB;
		+NOICEDEATH;
		+USESPECIAL;
		+NOTAUTOAIMED;
		Activation THINGSPEC_Switch | THINGSPEC_ThingTargets | THINGSPEC_NoDeathSpecial;
		DeathSound "world/crate/death";
		Obituary "$OB_BARREL";
	}
	States
	{
	Spawn:
		BAR0 A 0;
		BAR0 A 0 A_JumpIf(user_itemspawnid > 0, "Idle");
		BAR0 A 0 { self.user_itemspawnid = args[0]; } // [XA] TODO: refactor this at some point
		BAR0 A 0 A_Jump(256, "Idle");
	Idle:
		BAR0 A 1;
		Wait;
	Active:
	Inactive:
		TNT1 A 0 A_JumpIf(CallACS("Crate_PickupCheck") > 0, "PickupSuccess");
		TNT1 A 0 A_Jump(256, "Idle");
		Goto Idle;
	PickupSuccess:
		TNT1 A 0 A_PlaySound("player/square/exert");
		TNT1 A 0 ACS_NamedExecuteWithResult("Crate_Pickup");
		TNT1 A 0 A_Jump(256, "Pickup");
	Pickup:
		TNT1 A 0 A_GiveToTarget("CrateWeaponGiver", 1);
		Stop;
	Death:
		BAR0 B -1 SQ_CrateBreak();
		Wait;
	}

	void SQ_CrateBreak()
	{
		self.bUseSpecial = false;
		A_Scream();
		A_Fall();
		A_SpawnItem("CribSpawnerPlain");
		ACS_NamedExecuteWithResult("Crate_Break");
	}
	
	// used by subclasses:

	void SQ_CrateQuake()
	{
		self.bUseSpecial = false;
		A_Quake(3, 35, 0, 500, "");
	}
}

class TNTCrate : Crate
{
	Default
	{
		DeathSound "world/tntcrate/death";
	}
	States
	{
	Idle:
		BAR1 A 1;
		Wait;
	Pickup:
		TNT1 A 0 A_GiveToTarget("TNTCrateWeaponGiver", 1);
		Stop;
	Death:
		BAR1 A 5 Bright SQ_CrateQuake();
		TNT1 A 15 Bright SQ_TNTCrateBoom();
		TNT1 A 10 Bright;
		TNT1 A 1050 Bright A_BarrelDestroy();
		TNT1 A 5 A_Respawn();
		Wait;
	}

	void SQ_TNTCrateBoom()
	{
		A_Scream();
		A_SpawnItem("CribSpawnerTNT");
		A_Explode(100, 128, XF_HURTSOURCE);
		A_SpawnItemEx("ExplosionSilent",0,0,16);
	}
}

class NukageCrate : Crate
{
	const BLOB_AMOUNT = 20;

	Default
	{
		DeathSound "world/tntcrate/death";
	}
	States
	{
	Idle:
		BAR2 A 1;
		Wait;
	Pickup:
		TNT1 A 0 A_GiveToTarget("NukageCrateWeaponGiver", 1);
		Stop;
	Death:
		BAR2 A 5 Bright SQ_CrateQuake();
		TNT1 A 15 Bright SQ_NukageCrateBoom();
		TNT1 A 10 Bright;
		TNT1 A 1050 Bright A_BarrelDestroy();
		TNT1 A 5 A_Respawn();
		Wait;
	}

	void SQ_NukageCrateBoom()
	{
		A_Scream();
		A_SpawnItem("GooSpawner");
		for(int i = 0; i < BLOB_AMOUNT; i++) {
			A_SpawnItemEx("GoonadeProjectileOozeBlob", 0, 0, 0, random(-6, 6), random(-6, 6), random(4, 6));
		}
		A_Explode(75, 96, XF_HURTSOURCE);
		A_SpawnItemEx("ExplosionGreen",0,0,16);
	}
}

class FizzoPopCrate : Crate
{
	Default
	{
		DeathSound "world/fizzocrate/death";
	}
	States
	{
	Idle:
		BAR3 A 1;
		Wait;
	Pickup:
		TNT1 A 0 A_GiveToTarget("FizzoPopCrateWeaponGiver", 1);
		Stop;
	Death:
		BAR3 A 5 SQ_CrateQuake();
		TNT1 A 15 Bright SQ_FizzoCrateBoom();
		TNT1 A 10 Bright;
		TNT1 A 1050 Bright A_BarrelDestroy();
		TNT1 A 5 A_Respawn();
		Wait;
	}

	void SQ_FizzoCrateBoom()
	{
		A_Scream();
		A_SpawnItem("GibSpawnerFizzoCrate");
		A_Explode(32, 100, XF_HURTSOURCE);
		A_Blast(0, 128, 128, 32.0, "StunPuff", "blank");
		A_SpawnItemEx("ExplosionFizzo",0,0,16);
	}
}

class Crack : SquareActor
{
	Default
	{
		+SHOOTABLE;
		+NOBLOOD;
		+NOGRAVITY;
		+INVISIBLE;
		+DONTBLAST;
		+NOTAUTOAIMED;
		Radius 0;
		Height 0;
		Health 10;
		Mass 0x7fffffff;
		DamageFactor "Bullet", 0.0;
		DamageFactor "Magic", 0.0;
		DamageFactor "Enemy", 0.0;
		DamageFactor "OvoltExp", 0.0;
		DamageFactor "Goo", 0.0;
		DamageFactor "Fire", 0.0;
	}
	States
	{
	Spawn:
		TNT1 A 1;
		Loop;
	}
}

class TrashCan : SquareActor
{
	Default
	{
		+SOLID;
		+DONTBLAST;
		Height 48;
		Radius 16;
		Scale 0.9;
	}
	States
	{
	Spawn:
		TCAN A -1;
		Stop;
	}
}

class FizzoProp : SwitchableDecoration
{
	Default
	{
		+DONTBLAST;
		Height 16;
		Radius 8;
	}
	States
	{
	Spawn:
	Active:
		FIZZ ABC 5;
		Loop;
	Inactive:
		FIZZ D -1;
		Stop;
	}
}

class FizzoDrop : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		+DONTBLAST;
		Height 16;
		Radius 8;
	}
	States
	{
	Spawn:
		FIZZ E -1;
		Stop;
	}
}

class FizzoPoop : SwitchableDecoration
{
	Default
	{
		+DONTBLAST;
		Height 16;
		Radius 8;
	}
	States
	{
	Spawn:
	Active:
		FIZG ABC 5;
		Loop;
	Inactive:
		FIZZ D -1;
		Stop;
	}
}

class TrafficCone : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		+DONTBLAST;
		Height 32;
		Radius 12;
	}
	States
	{
	Spawn:
		CONE A -1;
		Stop;
	}
}

class Jackhammer : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		+DONTBLAST;
	}
	States
	{
	Spawn:
		JCKH A -1;
		Stop;
	}
}

class Pickaxe : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		+DONTBLAST;
	}
	States
	{
	Spawn:
		PCKA A -1;
		Stop;
	}
}

class Spade1 : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		+DONTBLAST;
	}
	States
	{
	Spawn:
		SPAD A -1;
		Stop;
	}
}

class Spade2 : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		+DONTBLAST;
	}
	States
	{
	Spawn:
		SPAD B -1;
		Stop;
	}
}

class CigarTable : SquareActor
{
	Default
	{
		+SOLID;
		Height 32;
		Radius 14;
	}
	States
	{
	Spawn:
		CTBL A -1;
		Stop;
	}
}

class HardHat1 : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
	}
	States
	{
	Spawn:
		HHAT A -1;
		Stop;
	}
}

class HardHat2 : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
	}
	States
	{
	Spawn:
		HHAT B -1;
		Stop;
	}
}

class HardHatStack1 : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
	}
	States
	{
	Spawn:
		HHAT C -1;
		Stop;
	}
}

class HardHatStack2 : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
	}
	States
	{
	Spawn:
		HHAT D -1;
		Stop;
	}
}

class HardHatStack3 : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
	}
	States
	{
	Spawn:
		HHAT E -1;
		Stop;
	}
}

class IndyFedora : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
	}
	States
	{
	Spawn:
		HAT2 A -1;
		Stop;
	}
}

class IndyWhip : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
	}
	States
	{
	Spawn:
		WHIP A -1;
		Stop;
	}
}

class CowIdol : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
	}
	States
	{
	Spawn:
		IDOL A -1;
		Stop;
	}
}

class CowHologram : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		RenderStyle 'Add';
		Scale 3.0;
	}
	States
	{
	Spawn:
		COWH AB 1 Bright;
		Loop;
	}
}

class OctatechHologram : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		RenderStyle 'Add';
		Scale 2.0;
	}
	States
	{
	Spawn:
		HOCT AB 1 Bright;
		Loop;
	}
}

class TankFreak1 : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		+FLOATBOB;
	}
	States
	{
	Spawn:
		FREK A -1;
		Stop;
	}
}

class TankFreak2 : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		+FLOATBOB;
	}
	States
	{
	Spawn:
		FREK B -1;
		Stop;
	}
}

class TankFreak3 : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		+FLOATBOB;
	}
	States
	{
	Spawn:
		FREK C -1;
		Stop;
	}
}

class GrandDayOutRocket : SquareActor
{
	Default
	{
		+SOLID;
		Scale 2.0;
		radius 96;
		height 256;
	}
	States
	{
	Spawn:
		WGRK A -1 Bright;
		Stop;
	}
}

class CowSphinx : SquareActor
{
	Default
	{
		+SOLID;
		Scale 2.0;
		Radius 100;
		Height 216;
	}
	States
	{
	Spawn:
		ECOW A -1;
		Stop;
	}
}

class CowPedestalSmall : SquareActor
{
	Default
	{
		+SOLID;
		Radius 16;
		Height 80;
	}
	States
	{
	Spawn:
		ECOW B -1;
		Stop;
	}
}

class CowPedestalMedium : CowPedestalSmall
{
	Default
	{
		+SOLID;
		Height 104;
	}
	States
	{
	Spawn:
		ECOW Q -1;
		Stop;
	}
}

class CowPedestalLarge : CowPedestalSmall
{
	Default
	{
		+SOLID;
		Height 128;
	}
	States
	{
	Spawn:
		ECOW P -1;
		Stop;
	}
}

class CowUdderPedestal : SquareActor
{
	Default
	{
		+SOLID;
		Radius 16;
		Height 60;
	}
	States
	{
	Spawn:
		ECOW C -1;
		Stop;
	}
}

class CowChandelier : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		+SPAWNCEILING;
		+NOGRAVITY;
		Height 46;
	}
	States
	{
	Spawn:
		ECOW D -1;
		Stop;
	}
}

class CowChandelierLit : CowChandelier
{
	States
	{
	Spawn:
		ECOW E -1 Bright;
		Stop;
	}
}

class CheeseCabinet : SquareActor
{
	Default
	{
		+SOLID;
		Radius 20;
		Height 48;
	}
	States
	{
	Spawn:
		ECOW F -1;
		Stop;
	}
}

class CowTorch : SquareActor
{
	Default
	{
		+SOLID;
		Radius 12;
		Height 72;
	}
	States
	{
	Spawn:
		ECOW H -1;
		Stop;
	}
}

class CowTorchLit : CowTorch
{
	States
	{
	Spawn:
		ECOW G -1 Bright;
		Stop;
	}
}

class CowArmor : SquareActor
{
	Default
	{
		+SOLID;
		Radius 31;
		Height 48;
	}
	States
	{
	Spawn:
		ECOW I -1;
		Stop;
	}
}

class CowArmorBits : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		Radius 16;
		Height 26;
	}
	States
	{
	Spawn:
		ECOW J -1;
		Stop;
	}
}

class Sarcowphagus : SquareActor
{
	Default
	{
		+SOLID;
		Radius 20;
		Height 68;
	}
	States
	{
	Spawn:
		ECOW K -1;
		Stop;
	}
}

class SarcowphagusOpen : Sarcowphagus
{
	States
	{
	Spawn:
		ECOW L -1;
		Stop;
	}
}

class CowJug : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		Radius 15;
		Height 40;
	}
	States
	{
	Spawn:
		ECOW M -1;
		Stop;
	}
}

class CowJugBroken : CowJug
{
	Default
	{
		+CLIENTSIDEONLY;
		Height 30;
	}
	States
	{
	Spawn:
		ECOW N -1;
		Stop;
	}
}

class RejectTritankle : SquareActor
{
	Default
	{
		+SOLID;
		Radius 24;
		Height 40;
	}
	States
	{
	Spawn:
		REJA A -1;
		Stop;
	}
}

class RejectRocketRon : SquareActor
{
	Default
	{
		+SOLID;
		Radius 24;
		Height 80;
	}
	States
	{
	Spawn:
		REJB A -1;
		Stop;
	}
}

class RejectDestructinator : SquareActor
{
	Default
	{
		+SOLID;
		Radius 32;
		Height 80;
	}
	States
	{
	Spawn:
		REJC A 6;
		REJC B 3 A_Jump(224, "Spawn");
		Goto Spawn;
	}
}

class ShadiusEye : SwitchableDecoration
{
	int lifetime;
	const POOF_PARTICLE_COUNT = 20;

	Default
	{
		+SOLID;
		Radius 16;
		Height 64;
	}
	States
	{
	Spawn:
	Active:
		VEYE ABCDEFGHIDKL 3 Bright;
		VEYE A 0 SQ_ShadiusEyeCountdown();
		Loop;
	Explode:
		VEYE A 3 Bright;
		VECD A 0 SQ_ShadiusEyePoof();
	ExplodedLoop:
		VECD AB 3;
		Loop;
	Inactive:
		VEYE A 3;
		VEYC BCDEFGHIDKL 3;
		Loop;
	}

	state SQ_ShadiusEyeCountdown()
	{
		self.lifetime += 1;
		if(self.lifetime >= args[0]) {
			return ResolveState('Explode');
		}
		return null;
	}

	void SQ_ShadiusEyePoof()
	{
		self.bSolid = false;
		A_PlaySound("effects/shadiuseye/poof");
		for(int i = 0; i < POOF_PARTICLE_COUNT; i++) {
			A_SpawnItemEx("ShadiusPuff", frandom[SquareEffectRandom](-6.0,6.0), frandom[SquareEffectRandom](-6.0,6.0), frandom[SquareEffectRandom](32,48), frandom[SquareEffectRandom](-1.0,1.0), frandom[SquareEffectRandom](-1.0,1.0), frandom[SquareEffectRandom](-1.0,1.0), 2);
		}
	}
}

class StoveRobot : SquareActor
{
	Default
	{
		+SOLID;
		Radius 26;
		Height 80;
	}
	States
	{
	Spawn:
		WGRK B -1;
		Stop;
	}
}

class PicnicBasket : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		Radius 15;
		Height 16;
	}
	States
	{
	Spawn:
		WGRK C -1;
		Stop;
	}
}

class ThermosAndTea : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		Radius 16;
		Height 24;
	}
	States
	{
	Spawn:
		WGRK D -1;
		Stop;
	}
}

class PlateOfCheese : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		Radius 11;
		Height 8;
	}
	States
	{
	Spawn:
		WGRK E -1;
		Stop;
	}
}

class CutCheeseMound : SquareActor
{
	Default
	{
		+CLIENTSIDEONLY;
		Radius 12;
		Height 12;
	}
	States
	{
	Spawn:
		WGRK F -1;
		Stop;
	}
}
