Jaysyn904 04165202c0 Initial upload
Initial upload
2024-11-25 19:36:07 -05:00

796 lines
24 KiB
Plaintext

// uc_h - Unit Creation Version 2 - Header File
// By Deva Bryson Winblood. 04/10/2005
#include "rtsh_multiplay"
#include "color_header"
#include "x3_inc_string"
/////////////////////////////////////////
// PROTOTYPES
/////////////////////////////////////////
// FILE: uc_h FUNCTION: GetUnitDescription()
// This function will return a string which can be used in
// a token that describes the unit. It will be in the format of
// Name M: # G: # S: # Tax In:# Tax Out: # [Abilities]
string GetUnitDescription(string sID,int nNumber,int nQuantity=1,int nUpgradeFrom=-1,object oPC=OBJECT_INVALID);
// FILE: uc_h FUNCTION: HasSufficientResources()
// This function will return TRUE if the PC has sufficient resources
// to produce nQuantity number of the specified unit.
// If bUpgrade is set to TRUE then this is an upgrade
int HasSufficientResources(object oPC,int nNumber,int nQuantity,int nUpgradeFrom=-1);
// FILE: uc_h FUNCTION: TakeResourceCost()
// This function will take the resources required to produce
// nQuantity of unit number nNumber from oPC.
void TakeResourceCost(object oPC,int nNumber,int nQuantity,int nUpgradeFrom=-1);
// FILE: uc_h FUNCTION: GetManaCost()
// This function will return the mana cost of the unit
int GetManaCost(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetGoldCost()
// This function will return the gold cost of the unit
int GetGoldCost(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetSoulCost()
// This function will return the soul cost of the unit
int GetSoulCost(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetTaxIn()
// This function will return the amount of tax in
int GetTaxIn(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetTaxOut()
// This function will return the amount of tax out
int GetTaxOut(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetRequiredUnit()
// This function will return the tag of a unit that must
// exist on this team before this unit can be built.
string GetRequiredUnit(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetCanScout()
// This function will return TRUE if the unit can scout
int GetCanScout(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetCanHarvest()
// This function will return TRUE if the unit can harvest
int GetCanHarvest(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetCanUpgrade()
// This function will return TRUE if the unit can be upgraded
int GetCanUpgrade(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetMinimumLevelReq()
// This function will return the minimum level the team leader
// must be before this unit can be constructed.
int GetMinimumLevelReq(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetCanGrow()
// This function will return TRUE if the unit in question
// is on a timed upgrade.
int GetCanGrow(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetCanBeCreated()
// This function will return TRUE if the unit can be created
int GetCanBeCreated(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetRequiredItem()
// This function will return the TAG of an item required to
// create this unit.
string GetRequiredItem(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetHasSoul()
// This function will return TRUE if the unit has a soul
int GetHasSoul(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetLightSensitivity()
// This function will return the light sensitivity level of the unit
// 0 = none, 1 = light sensitive, 2 = sun fatal
int GetLightSensitivity(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetUnitName()
// This function will return the name of the specified unit
string GetUnitName(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetUnitHitDice()
// This function will return the hit dice of the specified unit
int GetUnitHitDice(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetUnitTag()
string GetUnitTag(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetUnitURequiredName()
string GetUnitURequiredName(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetUnitIRequiredName()
string GetUnitIRequiredName(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetUnitSubRaceOverride()
string GetUnitSubRaceOverride(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetUnitUpgradeNumber()
int GetUnitUpgradeNumber(string sID,int nNumber,int nUpgradeSlot);
// FILE: uc_h FUNCTION: GetUnitLevel()
int GetUnitLevel(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetUnitResRef()
string GetUnitResRef(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetUnitConsumeItem()
int GetUnitConsumeItem(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetUnitTimedUpgradeTime()
int GetUnitTimedUpgradeTime(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetUnitTimedUpgradeResRef()
string GetUnitTimedUpgradeResRef(string sID,int nNumber);
// FILE: uc_h FUNCTION: GetUnitTimedUpgradeUnitNum()
int GetUnitTimedUpgradeUnitNum(string sID,int nNumber);
/////////////////////////////////////////
// FUNCTIONS
/////////////////////////////////////////
string GetUnitTag(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
string sReq=GetLocalString(oMod,sVar+"_tag");
return sReq;
} // GetUnitTag()
string GetUnitResRef(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
string sReq=GetLocalString(oMod,sVar+"_res");
return sReq;
} // GetUnitResRef()
int GetUnitTimedUpgradeTime(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
return GetLocalInt(oMod,sVar+"_timeup");
} // GetUnitTimedUpgradeTime()
string GetUnitTimedUpgradeResRef(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
return GetLocalString(oMod,sVar+"_timers");
} // GetUnitTimedUpgradeResRef()
int GetUnitTimedUpgradeUnitNum(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
return GetLocalInt(oMod,sVar+"_untimers");
} // GetUnitTimedUpgradeUnitNum()
int GetUnitConsumeItem(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
return GetLocalInt(oMod,sVar+"_cons");
} // GetUnitConsumeItem()
string GetUnitURequiredName(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
string sReq=GetLocalString(oMod,sVar+"_unitn");
return sReq;
} // GetUnitURequiredName()
string GetUnitIRequiredName(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
string sReq=GetLocalString(oMod,sVar+"_itemn");
return sReq;
} // GetUnitIRequiredName()
int GetUnitUpgradeNumber(string sID,int nNumber,int nUpgradeSlot)
{
return GetLocalInt(GetModule(),sID+IntToString(nNumber)+"_up"+IntToString(nUpgradeSlot));
} // GetUnitUpgradeNumber()
int GetUnitLevel(string sID,int nNumber)
{
object oMod=GetModule();
int nRet=-1;
string sVar=sID+IntToString(nNumber);
nRet=GetLocalInt(oMod,sVar+"_hd");
return nRet;
} // GetUnitLevel()
string GetUnitSubRaceOverride(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
string sReq=GetLocalString(oMod,sVar+"_srovr");
return sReq;
} // GetUnitSubRaceOverride()
int GetManaCost(string sID,int nNumber)
{
object oMod=GetModule();
int nRet=-1;
int nMin=0;
string sVar=sID+IntToString(nNumber);
float fMult=GetLocalFloat(oMod,"fUCMultpile");
if (fMult<0.01)
{ // find
nRet=GetLocalInt(oMod,"nGSUnitCostMult");
fMult=1.0;
if (nRet==1) fMult=0.25;
else if (nRet==2) fMult=0.5;
else if (nRet==3) fMult=0.75;
else if (nRet==4) fMult=1.25;
else if (nRet==5) fMult=1.5;
else if (nRet==6) fMult=1.75;
else if (nRet==7) fMult=2.0;
else if (nRet==8) fMult=3.0;
else if (nRet==9) fMult=4.0;
SetLocalFloat(oMod,"fUCMultiple",fMult);
} // find
nRet=GetLocalInt(oMod,sVar+"_ccmana");
if (nRet>0) nMin=1;
nRet=FloatToInt(IntToFloat(nRet)*fMult);
if (nRet<nMin) nRet=nMin;
return nRet;
} // GetManaCost()
int GetGoldCost(string sID,int nNumber)
{
object oMod=GetModule();
int nRet=-1;
int nMin=0;
string sVar=sID+IntToString(nNumber);
float fMult=GetLocalFloat(oMod,"fUCMultpile");
if (fMult<0.01)
{ // find
nRet=GetLocalInt(oMod,"nGSUnitCostMult");
fMult=1.0;
if (nRet==1) fMult=0.25;
else if (nRet==2) fMult=0.5;
else if (nRet==3) fMult=0.75;
else if (nRet==4) fMult=1.25;
else if (nRet==5) fMult=1.5;
else if (nRet==6) fMult=1.75;
else if (nRet==7) fMult=2.0;
else if (nRet==8) fMult=3.0;
else if (nRet==9) fMult=4.0;
SetLocalFloat(oMod,"fUCMultiple",fMult);
} // find
nRet=GetLocalInt(oMod,sVar+"_ccgold");
if (nRet>0) nMin=1;
nRet=FloatToInt(IntToFloat(nRet)*fMult);
if (nRet<nMin) nRet=nMin;
return nRet;
} // GetGoldCost()
int GetSoulCost(string sID,int nNumber)
{
object oMod=GetModule();
int nRet=-1;
string sVar=sID+IntToString(nNumber);
nRet=GetLocalInt(oMod,sVar+"_ccsoul");
return nRet;
} // GetSoulCost()
int GetTaxIn(string sID,int nNumber)
{
object oMod=GetModule();
int nRet=-1;
string sVar=sID+IntToString(nNumber);
nRet=GetLocalInt(oMod,sVar+"_taxin");
return nRet;
} // GetTaxIn()
int GetTaxOut(string sID,int nNumber)
{
object oMod=GetModule();
int nRet=-1;
string sVar=sID+IntToString(nNumber);
nRet=GetLocalInt(oMod,sVar+"_taxout");
return nRet;
} // GetTaxOut()
int GetCanUpgrade(string sID,int nNumber)
{
object oMod=GetModule();
int nVal;
string sVar=sID+IntToString(nNumber);
nVal=GetLocalInt(oMod,sVar+"_up1");
if (nVal>-1) return TRUE;
return FALSE;
} // GetCanUpgrade()
int GetCanGrow(string sID,int nNumber)
{
object oMod=GetModule();
string sTag;
string sVar=sID+IntToString(nNumber);
sTag=GetLocalString(oMod,sVar+"_timers");
if (sTag!="NA"||GetStringLength(sTag)<2) return TRUE;
return FALSE;
} // GetCanGrow()
int GetCanHarvest(string sID,int nNumber)
{
object oMod=GetModule();
int nVal;
string sVar=sID+IntToString(nNumber);
nVal=GetLocalInt(oMod,sVar+"_harvest");
if (nVal==1) return TRUE;
return FALSE;
} // GetCanHarvest()
int GetCanScout(string sID,int nNumber)
{
object oMod=GetModule();
int nVal;
string sVar=sID+IntToString(nNumber);
nVal=GetLocalInt(oMod,sVar+"_scout");
if (nVal==1) return TRUE;
return FALSE;
} // GetCanScout()
string GetRequiredUnit(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
string sReq=GetLocalString(oMod,sVar+"_requnit");
return sReq;
} // GetRequiredUnit()
string GetRequiredItem(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
string sReq=GetLocalString(oMod,sVar+"_item");
return sReq;
} // GetRequiredItem()
int GetMinimumLevelReq(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
int nRet=GetLocalInt(oMod,sVar+"_minlev");
return nRet;
} // GetMinimumLevelReq()
int GetCanBeCreated(string sID,int nNumber)
{
object oMod=GetModule();
int nVal;
string sVar=sID+IntToString(nNumber);
nVal=GetLocalInt(oMod,sVar+"_create");
if (nVal==1) return TRUE;
return FALSE;
} // GetCanBeCreated()
int GetHasSoul(string sID,int nNumber)
{
object oMod=GetModule();
int nVal;
string sVar=sID+IntToString(nNumber);
nVal=GetLocalInt(oMod,sVar+"_soul");
if (nVal==1) return TRUE;
return FALSE;
} // GetHasSoul()
int GetLightSensitivity(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
return GetLocalInt(oMod,sVar+"_light");
} // GetLightSensitivity()
string GetUnitName(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
return GetLocalString(oMod,sVar+"_name");
} // GetUnitName()
int GetUnitHitDice(string sID,int nNumber)
{
object oMod=GetModule();
string sVar=sID+IntToString(nNumber);
return GetLocalInt(oMod,sVar+"_hitdice");
} // GetUnitHitDice()
int fnGetHasQtyOfItem(object oPC,string sTag,int nQty)
{
int nC;
object oItem;
oItem=GetItemPossessedBy(oPC,sTag);
if (!GetIsObjectValid(oItem)) return FALSE;
oItem=GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem)&&nC<nQty)
{ // count items
if (GetTag(oItem)==sTag) nC=nC+GetItemStackSize(oItem);
oItem=GetNextItemInInventory(oPC);
} // count items
if (nC>=nQty) return TRUE;
return FALSE;
} // fnGetHasQtyOfItem()
string GetUnitDescription(string sID,int nNumber,int nQuantity=1,int nUpgradeFrom=-1,object oPC=OBJECT_INVALID)
{
string sDesc;
int nV;
int nUC;
string sS;
string sName=GetUnitName(sID,nNumber);
int bCanBuild=TRUE;
int nMana=100000;
int nGold=100000;
int nSouls=10000;
int nLevel=60;
int bConsumeItem=GetUnitConsumeItem(sID,nNumber);
object oOb;
int bOverride=FALSE;
sName=GetStringUpperCase(sName);
nV=GetUnitLevel(sID,nNumber);
sDesc="[Lvl:"+IntToString(nV)+"]";
if (GetIsObjectValid(oPC))
{ // PC in play
nMana=fnGetTeamMana(oPC);
nGold=GetGold(oPC);
nSouls=fnGetTeamSouls(oPC);
nLevel=GetLevelByPosition(1,oPC)+GetLevelByPosition(2,oPC)+GetLevelByPosition(3,oPC);
} // PC in play
sDesc=sDesc+"(Cost: M:";
nV=GetManaCost(sID,nNumber);
nV=nV*nQuantity;
if (nUpgradeFrom>-1)
{ // upgrade from
nUC=GetManaCost(sID,nUpgradeFrom);
nUC=nUC*nQuantity;
nV=nV-nUC;
} // upgrade from
if (nV>nMana) { sDesc=sDesc+StringToRGBString(IntToString(nV),"733"); bCanBuild=FALSE; }
else { sDesc=sDesc+StringToRGBString(IntToString(nV),"555"); }
sDesc=sDesc+",G:";
nV=GetGoldCost(sID,nNumber);
nV=nV*nQuantity;
if (nUpgradeFrom>-1)
{ // upgrade from
nUC=GetGoldCost(sID,nUpgradeFrom);
nUC=nUC*nQuantity;
nV=nV-nUC;
} // upgrade from
if (nV>nGold) { sDesc=sDesc+StringToRGBString(IntToString(nV),"733"); bCanBuild=FALSE; }
else { sDesc=sDesc+StringToRGBString(IntToString(nV),"555"); }
sDesc=sDesc+",S:";
nV=GetSoulCost(sID,nNumber);
nV=nV*nQuantity;
if (nUpgradeFrom>-1)
{ // upgrade from
nUC=GetSoulCost(sID,nUpgradeFrom);
nUC=nUC*nQuantity;
nV=nV-nUC;
} // upgrade from
if (nV>nSouls) { sDesc=sDesc+StringToRGBString(IntToString(nV),"733"); bCanBuild=FALSE; }
else { sDesc=sDesc+StringToRGBString(IntToString(nV),"555"); }
sDesc=sDesc+")";
nV=GetMinimumLevelReq(sID,nNumber);
if (nV>0)
{ // minimum level required
sDesc=sDesc+"(Lvl Req:";
if (nV>nLevel) { sDesc=sDesc+StringToRGBString(IntToString(nV),"733"); bCanBuild=FALSE; }
else { sDesc=sDesc+StringToRGBString(IntToString(nV),"555"); }
sDesc=sDesc+")";
} // minimum level required
nV=GetTaxIn(sID,nNumber);
if (nV>0)
{ // tax in
nUC=GetLocalInt(GetModule(),"nManaGoldMultiplier");
if (nUC<1) nUC=1;
nV=nV*nUC;
sDesc=sDesc+"[Income:"+StringToRGBString(IntToString(nV),"777")+"]";
} // tax in
nV=GetTaxOut(sID,nNumber);
if (nV>0)
{ // tax out
sDesc=sDesc+"[Hourly Cost:"+StringToRGBString(IntToString(nV),"474")+"]";
} // tax out
sS=GetUnitSubRaceOverride(sID,nNumber);
if (GetStringLength(sS)>0&&GetStringUpperCase(GetSubRace(oPC))==GetStringUpperCase(sS)) bOverride=TRUE;
sS=GetRequiredItem(sID,nNumber);
if (bConsumeItem&&GetStringLength(sS)>0&&sS!="NA")
{ // consumeable item required
sDesc=sDesc+"(Consumeable Item:'";
if (GetIsObjectValid(oPC))
{ // PC exists
if (fnGetHasQtyOfItem(oPC,sS,nQuantity))
{ // has the item
sDesc=sDesc+StringToRGBString(GetUnitIRequiredName(sID,nNumber),"555");
} // has the item
else
{ // does not have sufficient quantity of the item
sDesc=sDesc+StringToRGBString(GetUnitIRequiredName(sID,nNumber),"733");
bCanBuild=FALSE;
} // does not have sufficient quantity of the item
} // PC exists
else
{ // list item
sDesc=sDesc+StringToRGBString(GetUnitIRequiredName(sID,nNumber),"555");
} // list item
sDesc=sDesc+"')";
} // consumeable item required
else if (GetStringLength(sS)>0&&sS!="NA")
{ // required item
sDesc=sDesc+"(Item:'";
if (GetIsObjectValid(oPC))
{ // PC exists
oOb=GetItemPossessedBy(oPC,sS);
if (GetIsObjectValid(oOb))
{ // has item
sDesc=sDesc+StringToRGBString(GetUnitIRequiredName(sID,nNumber),"555");
} // has item
else
{ // does not have item
sDesc=sDesc+StringToRGBString(GetUnitIRequiredName(sID,nNumber),"733");
if (!bOverride) bCanBuild=FALSE;
} // does not have item
} // PC exists
else
{ // list item
sDesc=sDesc+StringToRGBString(GetUnitIRequiredName(sID,nNumber),"555");
} // list item
sDesc=sDesc+"')";
} // required item
sS=GetRequiredUnit(sID,nNumber);
if (GetStringLength(sS)>0&&sS!="NA")
{ // required unit
oOb=GetObjectByTag(sS);
sDesc=sDesc+"(Unit:'";
if (GetIsObjectValid(oOb))
{ // unit exists
sDesc=sDesc+StringToRGBString(GetUnitURequiredName(sID,nNumber),"555");
} // unit exists
else
{ // unit does not exist
sDesc=sDesc+StringToRGBString(GetUnitURequiredName(sID,nNumber),"733");
if (!bOverride) bCanBuild=FALSE;
} // unit does not exist
sDesc=sDesc+"')";
} // required unit
sS=GetUnitSubRaceOverride(sID,nNumber);
if (GetStringLength(sS)>0)
{ // sub-race override
sDesc=sDesc+"(Override:'"+StringToRGBString(sS,"555")+"')";
} // sub-race override
if (GetCanUpgrade(sID,nNumber))
{ // can upgrade
sDesc=sDesc+"["+StringToRGBString("Upgradeable","474")+"]";
} // can upgrade
if (GetCanGrow(sID,nNumber))
{ // timed upgrade
sDesc=sDesc+"["+StringToRGBString("Grows","474")+"]";
} // timed upgrade
if (GetCanHarvest(sID,nNumber))
{ // can harvest
sDesc=sDesc+"["+StringToRGBString("Harvests","474")+"]";
} // can harvest
if (GetCanScout(sID,nNumber))
{ // can scout
sDesc=sDesc+"["+StringToRGBString("Scouts","474")+"]";
} // can scout
nV=GetLightSensitivity(sID,nNumber);
if (nV>0)
{ // light sensitivity
if (nV==1)
{ // light sensitive
sDesc=sDesc+"["+StringToRGBString("Light Sensitive","744")+"]";
} // light sensitive
else if (nV==2)
{ // sun fatal
sDesc=sDesc+"["+StringToRGBString("Sun Fatal","744")+"]";
} // sun fatal
} // light sensitivity
if (bCanBuild) sDesc=StringToRGBString(sName,"477")+": "+sDesc;
else { sDesc=StringToRGBString(sName,"755")+": "+sDesc; }
return sDesc;
} // GetUnitDescription()
int HasSufficientResources(object oPC,int nNumber,int nQuantity,int nUpgradeFrom=-1)
{
object oMod=GetModule();
int bRet=TRUE;
string sID=GetLocalString(oPC,"sTeamID");
int nMana=fnGetTeamMana(oPC);
int nGold=GetGold(oPC);
int nSouls=fnGetTeamSouls(oPC);
int nV;
int nUC;
string sS,sU;
object oIt;
int bOverride=FALSE;
object oLeader=GetLocalObject(oMod,"oTeamLead"+sID);
int nLevel=GetLevelByPosition(1,oLeader)+GetLevelByPosition(2,oLeader)+GetLevelByPosition(3,oLeader);
string sSROverride=GetUnitSubRaceOverride(sID,nNumber);
int bConsumeItem=GetUnitConsumeItem(sID,nNumber);
nV=GetCanBeCreated(sID,nNumber);
if (nV!=TRUE&&nUpgradeFrom<0) return FALSE;
if (bConsumeItem)
{ // consumeable item required
sS=GetRequiredItem(sID,nNumber);
if (nUpgradeFrom>-1)
{ // upgrade check
sU=GetRequiredItem(sID,nUpgradeFrom);
if (!GetUnitConsumeItem(sID,nUpgradeFrom)||sU!=sS)
{ // new items to be consumed
if (!fnGetHasQtyOfItem(oPC,sS,nQuantity)) return FALSE;
} // new items to be consumed
} // upgrade check
else
{ // consume item
if (!fnGetHasQtyOfItem(oPC,sS,nQuantity)) return FALSE;
} // consume item
} // consumeable item required
if (GetStringLength(sSROverride)>0&&sSROverride!=GetSubRace(oPC))
{ // not sub-race overridden
sS=GetRequiredItem(sID,nNumber);
if (sS!="NA"&&GetStringLength(sS)>2)
{ // item required
bOverride=TRUE;
oIt=GetItemPossessedBy(oPC,sS);
if (oIt==OBJECT_INVALID) return FALSE;
} // item required
sS=GetRequiredUnit(sID,nNumber);
if (sS!="NA"&&GetStringLength(sS)>2)
{ // unit is required
bOverride=TRUE;
bRet=FALSE;
nV=0;
oIt=GetObjectByTag(sS,nV);
while(oIt!=OBJECT_INVALID&&bRet==FALSE)
{ // check units with tag
if (GetLocalString(oIt,"sTeamID")==sID) bRet=TRUE;
nV++;
oIt=GetObjectByTag(sS,nV);
} // check units with tag
if (!bRet) return FALSE;
} // unit is required
if(!bOverride) return FALSE;
} // not sub-race overridden
nV=GetMinimumLevelReq(sID,nNumber);
if (nLevel<nV) return FALSE;
nV=GetManaCost(sID,nNumber);
nV=nV*nQuantity;
if (nUpgradeFrom>-1)
{ // upgrade
nUC=GetManaCost(sID,nUpgradeFrom);
nV=nV-(nUC*nQuantity);
} // upgrade
if (nMana<nV) return FALSE;
nV=GetGoldCost(sID,nNumber);
nV=nV*nQuantity;
if (nUpgradeFrom>-1)
{ // upgrade
nUC=GetGoldCost(sID,nUpgradeFrom);
nV=nV-(nUC*nQuantity);
} // upgrade
if (nGold<nV) return FALSE;
nV=GetSoulCost(sID,nNumber);
nV=nV*nQuantity;
if (nUpgradeFrom>-1)
{ // upgrade
nUC=GetSoulCost(sID,nUpgradeFrom);
nV=nV-(nUC*nQuantity);
} // upgrade
if (nSouls<nV) return FALSE;
return TRUE;
} // HasSufficientResources()
void fnConsumeItems(object oPC,string sItemTag,int nQuantity)
{ // PURPOSE: Consume the consumeable items
int nRem=nQuantity;
object oItem;
int nStack;
oItem=GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem)&&nRem>0)
{ // consume items
if (GetTag(oItem)==sItemTag)
{ // this is the item
nStack=GetItemStackSize(oItem);
if (nStack==1)
{ // one item
nRem=nRem-1;
DelayCommand(0.1,DestroyObject(oItem));
} // one item
else
{ // multiple item stack
if (nStack<=nRem)
{ // consume stack
nRem=nRem-nStack;
DelayCommand(0.1,DestroyObject(oItem));
} // consume stack
else
{ // decrease stack
SetItemStackSize(oItem,nStack-nRem);
nRem=0;
} // decrease stack
} // multiple item stack
} // this is the item
oItem=GetNextItemInInventory(oPC);
} // consume items
} // fnConsumeItems()
void TakeResourceCost(object oPC,int nNumber,int nQuantity,int nUpgradeFrom=-1)
{
object oMod=GetModule();
int bRet=TRUE;
string sID=GetLocalString(oPC,"sTeamID");
int nMana=fnGetTeamMana(oPC);
int nGold=GetGold(oPC);
int nSouls=fnGetTeamSouls(oPC);
int nV;
int nUC;
string sS;
if (GetUnitConsumeItem(sID,nNumber))
{ // consumeable items
sS=GetRequiredItem(sID,nNumber);
if (sS!="NA"&&GetStringLength(sS)>0) fnConsumeItems(oPC,sS,nQuantity);
} // consumeable items
nV=GetManaCost(sID,nNumber);
nV=nV*nQuantity;
if (nUpgradeFrom>-1)
{ // upgrade
nUC=GetManaCost(sID,nUpgradeFrom);
nV=nV-(nUC*nQuantity);
} // upgrade
nMana=nMana-nV;
if (nV>0) fnSetTeamMana(oPC,nMana);
nV=GetGoldCost(sID,nNumber);
nV=nV*nQuantity;
if (nUpgradeFrom>-1)
{ // upgrade
nUC=GetGoldCost(sID,nUpgradeFrom);
nV=nV-(nUC*nQuantity);
} // upgrade
if (nV>0) TakeGoldFromCreature(nV,oPC,TRUE);
nV=GetSoulCost(sID,nNumber);
nV=nV*nQuantity;
if (nUpgradeFrom>-1)
{ // upgrade
nUC=GetSoulCost(sID,nUpgradeFrom);
nV=nV-(nUC*nQuantity);
} // upgrade
nSouls=nSouls-nV;
if (nV>0) fnSetTeamSouls(oPC,nSouls);
} // TakeResourceCost()
//void main(){}