182 lines
8.5 KiB
Plaintext
182 lines
8.5 KiB
Plaintext
////////////////////////////////////////////////////////////////////////////////
|
|
// pop_control - Population control
|
|
// By Deva B. Winblood. November 13th, 2008
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "x3_inc_string"
|
|
|
|
///////////////////////////////
|
|
// FUNCTION
|
|
///////////////////////////////
|
|
|
|
|
|
int fnValidToCount(object oNPC,object oLead,object oChamp,object oProxy)
|
|
{ // PURPOSE: Return whether valid to count
|
|
if (GetIsPC(oNPC)) return FALSE;
|
|
else if (oNPC==oLead) return FALSE;
|
|
else if (oNPC==oChamp) return FALSE;
|
|
else if (oNPC==oProxy) return FALSE;
|
|
else if (GetLocalInt(oNPC,"bGarrison")) return FALSE;
|
|
else if (GetLocalInt(oNPC,"bNoClean")) return FALSE;
|
|
else if (GetPlotFlag(oNPC)) return FALSE;
|
|
|
|
return TRUE;
|
|
} // fnValidToCount()
|
|
|
|
|
|
void fnReducePop(object oProxy,object oLead,object oChamp, int nReduce,string sTeamID)
|
|
{ // PURPOSE: Remove nReduce units from team
|
|
int nToRemove=nReduce;
|
|
object oPC;
|
|
object oItem;
|
|
int nRemoved;
|
|
float fCR;
|
|
string sReport;
|
|
int nImportants;
|
|
object oMember=GetFirstFactionMember(oProxy,FALSE);
|
|
while(GetIsObjectValid(oMember)&&nToRemove>0)
|
|
{ // remove excess
|
|
if (fnValidToCount(oMember,oLead,oChamp,oProxy))
|
|
{ // not PC, Proxy, Leader, Champion, or Garrison NPC
|
|
if (!GetIsInCombat(oMember)&&!IsInConversation(oMember)&&!GetIsDMPossessed(oMember))
|
|
{ // not in combat, conversation, or possessed by DM
|
|
oPC=GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC,oMember,1);
|
|
if (!GetIsObjectValid(oPC))
|
|
{ // No PCs in area
|
|
oItem=GetItemPossessedBy(oMember,"MANA_CRYSTAL_5");
|
|
if (!GetIsObjectValid(oItem))
|
|
{ // not carrying large mana crystal
|
|
oItem=GetItemPossessedBy(oMember,"MANA_CRYSTAL_2");
|
|
if (!GetIsObjectValid(oItem))
|
|
{ // not carrying mana crystal
|
|
oItem=GetItemPossessedBy(oMember,"MANA_CRYSTAL_1");
|
|
if (!GetIsObjectValid(oItem))
|
|
{ // not carrying minor mana crystal
|
|
oItem=GetItemPossessedBy(oMember,"rts_powerres");
|
|
if (!GetIsObjectValid(oItem))
|
|
{ // not carrying power reservoir
|
|
if (!GetLocalInt(oMember,"bImportant"))
|
|
{ // not important
|
|
nToRemove=nToRemove-1;
|
|
nRemoved++;
|
|
fCR=fCR+GetChallengeRating(oMember);
|
|
DelayCommand(2.0,DestroyObject(oMember));
|
|
if (GetIsPC(oLead))
|
|
{ // leader report
|
|
sReport=StringToRGBString(" Despawned '"+GetName(oMember)+"' for population control.","375");
|
|
SendMessageToPC(oLead,sReport);
|
|
} // leader report
|
|
} // not important
|
|
else
|
|
{ // important - skip
|
|
nImportants++;
|
|
} // important - skip
|
|
} // not carrying power reservoir
|
|
} // not carrying minor mana crystal
|
|
} // not carrying mana crystal
|
|
} // not carrying large mana crystal
|
|
} // No PCs in area
|
|
} // not in combat, conversation, or possessed by DM
|
|
} // not PC, Proxy, Leader, Champion, or Garrison NPC
|
|
oMember=GetNextFactionMember(oProxy,FALSE);
|
|
} // remove excess
|
|
if (nToRemove>0&&nImportants>0)
|
|
{ // remove importants
|
|
oMember=GetFirstFactionMember(oProxy,FALSE);
|
|
while(GetIsObjectValid(oMember)&&nToRemove>0)
|
|
{ // remove excess
|
|
if (fnValidToCount(oMember,oLead,oChamp,oProxy))
|
|
{ // not PC, Proxy, Leader, Champion, or Garrison NPC
|
|
if (!GetIsInCombat(oMember)&&!IsInConversation(oMember)&&!GetIsDMPossessed(oMember))
|
|
{ // not in combat, conversation, or possessed by DM
|
|
oPC=GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC,oMember,1);
|
|
if (!GetIsObjectValid(oPC))
|
|
{ // No PCs in area
|
|
oItem=GetItemPossessedBy(oMember,"MANA_CRYSTAL_5");
|
|
if (!GetIsObjectValid(oItem))
|
|
{ // not carrying large mana crystal
|
|
oItem=GetItemPossessedBy(oMember,"MANA_CRYSTAL_2");
|
|
if (!GetIsObjectValid(oItem))
|
|
{ // not carrying mana crystal
|
|
oItem=GetItemPossessedBy(oMember,"MANA_CRYSTAL_1");
|
|
if (!GetIsObjectValid(oItem))
|
|
{ // not carrying minor mana crystal
|
|
oItem=GetItemPossessedBy(oMember,"rts_powerres");
|
|
if (!GetIsObjectValid(oItem))
|
|
{ // not carrying power reservoir
|
|
nToRemove=nToRemove-1;
|
|
nRemoved++;
|
|
fCR=fCR+GetChallengeRating(oMember);
|
|
DelayCommand(2.0,DestroyObject(oMember));
|
|
if (GetIsPC(oLead))
|
|
{ // leader report
|
|
sReport=StringToRGBString(" Despawned '"+GetName(oMember)+"' for population control.","375");
|
|
SendMessageToPC(oLead,sReport);
|
|
} // leader report
|
|
} // not carrying power reservoir
|
|
} // not carrying minor mana crystal
|
|
} // not carrying mana crystal
|
|
} // not carrying large mana crystal
|
|
} // No PCs in area
|
|
} // not in combat, conversation, or possessed by DM
|
|
} // not PC, Proxy, Leader, Champion, or Garrison NPC
|
|
oMember=GetNextFactionMember(oProxy,FALSE);
|
|
} // remove excess
|
|
} // remove importants
|
|
if (GetIsPC(oLead))
|
|
{ // report
|
|
sReport=StringToRGBString(IntToString(nRemoved)+" units were despawned to keep population where it is supposed to be. [CR Lost: "+IntToString(FloatToInt(fCR))+"]","373");
|
|
SendMessageToPC(oLead,sReport);
|
|
} // report
|
|
} // fnReducePop()
|
|
|
|
|
|
void fnControlPop(string sTeamID)
|
|
{ // PURPOSE: Population control
|
|
object oProxy=GetObjectByTag(sTeamID+"_PROXY");
|
|
object oMod=GetModule();
|
|
object oLead=GetLocalObject(oMod,"oTeamLead"+sTeamID);
|
|
object oMember;
|
|
object oChamp=GetObjectByTag(GetStringLowerCase(sTeamID+"_champ"));
|
|
int nCount;
|
|
int nMaxPop=GetLocalInt(oMod,"nMaxUnits");
|
|
oMember=GetFirstFactionMember(oProxy,FALSE);
|
|
while(GetIsObjectValid(oMember))
|
|
{ // count
|
|
if (fnValidToCount(oMember,oLead,oChamp,oProxy))
|
|
{ // valid
|
|
nCount++;
|
|
//if (GetIsPC(oLead)) SendMessageToPC(oLead,"["+IntToString(nCount)+"] "+GetName(oMember)+" in '"+GetName(GetArea(oMember))+"'");
|
|
} // valid
|
|
oMember=GetNextFactionMember(oProxy,FALSE);
|
|
} // count
|
|
if (nCount>nMaxPop)
|
|
{ // population needs to be adjusted
|
|
DelayCommand(2.0,fnReducePop(oProxy,oLead,oChamp,nCount-nMaxPop,sTeamID));
|
|
} // population needs to be adjusted
|
|
else
|
|
{ // count
|
|
SetLocalInt(oMod,"nUnitCount_"+sTeamID,nCount);
|
|
} // count
|
|
if (GetIsPC(oLead)) SendMessageToPC(oLead,"System... checking population. ["+IntToString(nCount)+"/"+IntToString(nMaxPop)+"]");
|
|
} // fnControlPop()
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////[ MAIN ]/////////
|
|
void main()
|
|
{
|
|
object oMod=GetModule();
|
|
int nPopControl=GetLocalInt(oMod,"nPopControlCount");
|
|
string sTeamID;
|
|
nPopControl++;
|
|
if (nPopControl>4) nPopControl=1;
|
|
SetLocalInt(oMod,"nPopControlCount",nPopControl);
|
|
if (nPopControl==1) sTeamID="UNC";
|
|
else if (nPopControl==2) sTeamID="UND";
|
|
else if (nPopControl==3) sTeamID="DWF";
|
|
else if (nPopControl==4) sTeamID="SPID";
|
|
fnControlPop(sTeamID);
|
|
}
|
|
///////////////////////////////////////////////////////////////[ MAIN ]/////////
|