
class ZShrunkEnemy : Actor
{

	class<actor> Aactor;
	string Asactor;
	StateLabel Aunshrinkbeginstate;
	double Ahealth;
	SpriteID Asprite;
	uint8 Aframe1;
	uint8 Aframe2;
	uint8 Aframe3;
	uint8 Aframe4;
	double Aheight;
	vector2 Ascale;
	bool Afloat;
	bool Aboss;

	Default
	{
		+SLIDESONWALLS
	}

	action state A_CheckFloorPlus(StateLabel label)
	{
		if (abs(pos.z - GetZAt()) <= 1)
		{
			double aradius = self.radius;
			if (GetZAt(aradius,0) == floorz && GetZAt(-aradius,0) == floorz && GetZAt(0,aradius) == floorz && GetZAt(0,-aradius) == floorz) {
				return ResolveState(label);
			}
		}

		return null;
	}

	private void updateTargets(Actor oldactor, Actor newactor)
	{
		ThinkerIterator actors = ThinkerIterator.Create("Actor",STAT_DEFAULT);
		Actor monster;
		while (monster = Actor(actors.Next()))
		{
			if (monster.bISMONSTER && monster!=oldactor && monster!=newactor && monster.target && monster.target==oldactor)
			{
				monster.target = newactor;
			}
		}
	}

	void A_SetSizeHeight()
	{
		self.A_SetSize(-1, Aheight);
	}

	void A_JumpIfCondition(int condition, StateLabel label)
	{
		if(condition==1) {
			if ((self.Scale.X < Ascale.Y) && (self.Scale.Y < Ascale.Y)) {self.SetStateLabel(label); return;}
		}
		else if(condition==2) {
			if (Afloat) {self.SetStateLabel(label); return;}
		}
		else if(condition==3) {
			if (Aboss) {self.SetStateLabel(label); return;}
		}
	}

	void A_ReplaceWithSourceEnemy(int frame, int ticks)
	{
		Actor a = self;
     		a.sprite = Asprite;
		
		if(frame==0) {a.frame = Aframe1;}
		else if(frame==1) {a.frame = Aframe2;}
		else if(frame==2) {a.frame = Aframe3;}
		else if(frame==3) {a.frame = Aframe4;}
		else {a.frame = Aframe1;}

     		a.A_SetTics(ticks);
	}

	void A_Unshrink(bool deathceiling=false, StateLabel customunshrinkbeginstate="Dummy")
	{
		Actor a = self;
		Actor aunshrink;

		if(Asactor=="") {
			aunshrink = Spawn(Aactor, a.pos);
		} else {
			aunshrink = Spawn(Asactor, a.pos);
		}

		if(deathceiling) Aunshrinkbeginstate = "Deathceiling";
		if(customunshrinkbeginstate!="Dummy") Aunshrinkbeginstate = customunshrinkbeginstate;

		aunshrink.health = Ahealth;
		aunshrink.target = a.target;
		aunshrink.master = a.master;
		aunshrink.A_SetInventory("MasterShieldState", 2);
		aunshrink.SetStateLabel(Aunshrinkbeginstate);

		updateTargets(a, aunshrink);
	}

}