// Donated by JPalomo!
// Feel free to modify/use this code for whatever you want.

#include "zcommon.acs"
#library "Forkgod" // It's morphing time!

// Change this if you change the armor.maxsaveamount of the shield actor.
#define ShieldMaxSaveAmount 1000000
// Increase this number if more shields are added
#define NumShieldTypes 5
// Then add the actor name to this list
str ShieldTypes[NumShieldTypes] =
{
	"ShieldCharge",
	"MaintenanceShield",
	"SupportShield",
	"AssaultShield",
	"ConquerorShield"
};

int Player_ShieldAmount[8];
str Player_ShieldType[8];
int Player_HealthAmount[8];


// Gets the player's shield values.
Function void GetShieldAmount (void)
{
	if (CheckInventory ("Armor"))
	{
		for (int i = 0; i < NumShieldTypes; i++)
		{
			if (GetArmorType(ShieldTypes[i], PlayerNumber())>0)
			{
				Player_ShieldAmount[PlayerNumber()] = GetArmorType(ShieldTypes[i], PlayerNumber()); // Get the player's armor value
				Player_ShieldType[PlayerNumber()] = ShieldTypes[i]; // As well as the armor type
				i = 0;
				break;
			}
		}
	}
}

// Gets the player's health value. This one is rather easy.
Function void GetHealthAmount (void)
{
	Player_HealthAmount[PlayerNumber()] = (GetActorProperty (0, APROP_Health));
}

Script 701 (void)
{
	// Store these values for later...
	GetShieldAmount();
	GetHealthAmount();
	// Then morph the player
	GiveInventory ("Forkanator", 1);
}

Script 700 (void)
{
	// Unmorph the player...
	UnMorphActor (0, True);
	// then restore the old values,
	SetActorProperty (0, APROP_Health, Player_HealthAmount[PlayerNumber()]);
	GiveInventory(Player_ShieldType[PlayerNumber()], ShieldMaxSaveAmount);
	TakeInventory("Armor", (ShieldMaxSaveAmount - Player_ShieldAmount[PlayerNumber()]));
	// Then reset the values (for checking if next script should be executed or not).
}

/* 									KNOWN BUGS

-If the player manages to kill himself while morphed, health will be reset back to 100, and you lose your armor.
-If the player exits the map while morphed, health will reset back 100, and you lose your armor.

*/