238 lines
9.6 KiB
Plaintext
238 lines
9.6 KiB
Plaintext
////////////////////////////////////////////////////////////////////////////////
|
|
// consolidate_h - This is the header file for Version 2.0 of Unit Consolidation
|
|
// By Deva Bryson Winblood. 03/05/2005
|
|
//------------------------------------------------------------------------------
|
|
// Purpose: To enable a single unit to act as proxy in behalf of many other units
|
|
// until needed and then the other units will be brought into play. This is
|
|
// designed to reduce CPU utilization since only 1 unit has to do the pathing
|
|
// while units are consolidated.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
///////////////////////////////
|
|
// PROTOTYPES
|
|
///////////////////////////////
|
|
|
|
// FILE: consolidate_h FUNCTION: ConsolidatePush()
|
|
// This function will push an object pointer onto a data structure stack on
|
|
// the oStack object. It will not move oCreature or oStack. It simply adds
|
|
// the creature pointer to the stack.
|
|
void ConsolidatePush(object oStack,object oCreature);
|
|
|
|
// FILE: consolidate_h FUNCTION: ConsolidatePop()
|
|
// This function will pop an object pointer off of the data structure stack
|
|
// stored on the oStack object.
|
|
object ConsolidatePop(object oStack);
|
|
|
|
// FILE: consolidate_h FUNCTION: ConsolidatePutAway()
|
|
// This function will put the creature in question away into a holding area
|
|
// reduce their CPU utilization to as low as possible. The waypoint name for
|
|
// where they should be sent is specified.
|
|
void ConsolidatePutAway(object oCreature,string sWhereTag);
|
|
|
|
// FILE: consolidate_h FUNCTION: ConsolidateBringBack()
|
|
// This will bring the specified creature out of the holding area and to the
|
|
// specific location and will set their AI_LEVEL to the level specified.
|
|
void ConsolidateBringBack(object oCreature,location lLocation,int nAI_Level);
|
|
|
|
// FILE: consolidate_h FUNCTION: ConsolidateMakeLeader()
|
|
// This function will check near the object in question and if one has not been
|
|
// made a consolidation leader it will set the current leader to one. Otherwise,
|
|
// it will return an object pointer to the consolidation leader. A range can
|
|
// be set. The sSpecialVariable is a variable name for a string variable that
|
|
// the comparisons to other NPCs must be made to in order to determine if they
|
|
// are part of the consolidation. EXAMPLE: "sTeamToRaid"
|
|
object ConsolidateMakeLeader(object oCreature,string sSpecialVariable,float fRange=100.0);
|
|
|
|
// FILE: consolidate_h FUNCTION: ConsolidateFreeLeader()
|
|
// This function will make the specified creature no longer the leader and
|
|
// if any units are still consolidated on the stack it will pop them off at
|
|
// the leaders current location.
|
|
void ConsolidateFreeLeader(object oCreature);
|
|
|
|
// FILE: consolidate_h FUNCTION: GetIsConsolidationLeader()
|
|
// This will return TRUE if the creature in question is a consolidation leader.
|
|
int GetIsConsolidationLeader(object oCreature);
|
|
|
|
// FILE: consolidate_h FUNCTION: GetShouldConsolidate()
|
|
// This will return TRUE if the creature in question should consolidate
|
|
int GetShouldConsolidate(object oCreature);
|
|
|
|
// FILE: consolidate_h FUNCTION: Consolidate()
|
|
// This function will fire off consolidation. It will check to see who the
|
|
// leader is add this unit to that leaders stack, and if this unit is not the
|
|
// leader it will call ConsolidatePutAway() for the units.
|
|
void Consolidate(object oCreature,string sWhereTag,string sSpecialVariable,float fRange=100.0);
|
|
|
|
|
|
//////////////////////////////
|
|
// FUNCTIONS
|
|
//////////////////////////////
|
|
|
|
void ConsolidatePush(object oStack,object oCreature)
|
|
{ // ConsolidatePush()
|
|
int nTop=GetLocalInt(oStack,"nCONStackTop");
|
|
if (oCreature!=OBJECT_INVALID&&oStack!=OBJECT_INVALID)
|
|
{ // valid
|
|
nTop++;
|
|
SetLocalObject(oStack,"oCONStack"+IntToString(nTop),oCreature);
|
|
SetLocalInt(oStack,"nCONStackTop",nTop);
|
|
} // valid
|
|
} // ConsolidatePush()
|
|
|
|
object ConsolidatePop(object oStack)
|
|
{ // ConsolidatePop()
|
|
object oRet=OBJECT_INVALID;
|
|
int nTop;
|
|
if (oStack!=OBJECT_INVALID)
|
|
{ // valid
|
|
nTop=GetLocalInt(oStack,"nCONStackTop");
|
|
if (nTop>0)
|
|
{ // there are stack items
|
|
oRet=GetLocalObject(oStack,"oCONStack"+IntToString(nTop));
|
|
nTop=nTop-1;
|
|
SetLocalInt(oStack,"nCONStackTop",nTop);
|
|
} // there are stack items
|
|
} // valid
|
|
return oRet;
|
|
} // ConsolidatePop()
|
|
|
|
void ConsolidatePutAway(object oCreature,string sWhereTag)
|
|
{ // ConsolidatePutAway()
|
|
object oWP=GetWaypointByTag(sWhereTag);
|
|
if (oWP!=OBJECT_INVALID)
|
|
{ // valid
|
|
if (oCreature!=OBJECT_INVALID)
|
|
{ // valid creature
|
|
if (GetArea(oCreature)!=GetArea(oWP)||GetDistanceBetween(oCreature,oWP)>20.0)
|
|
{ // jump
|
|
AssignCommand(oCreature,JumpToObject(oWP));
|
|
DelayCommand(1.0,ConsolidatePutAway(oCreature,sWhereTag));
|
|
} // jump
|
|
else
|
|
{ // lower ai
|
|
SetAILevel(oCreature,AI_LEVEL_VERY_LOW);
|
|
AssignCommand(oCreature,ClearAllActions(TRUE));
|
|
SetCommandable(FALSE,oCreature);
|
|
SetLocalInt(oCreature,"bConsolidated",TRUE);
|
|
} // lower ai
|
|
} // valid creature
|
|
} // valid
|
|
else
|
|
{ // error
|
|
SendMessageToPC(GetFirstPC(),"ERROR: consolidation: could not find location specified as "+sWhereTag+" for unit "+GetName(oCreature)+".");
|
|
} // error
|
|
} // ConsolidatePutAway()
|
|
|
|
|
|
void ConsolidateBringBack(object oCreature,location lLocation,int nAI_Level)
|
|
{ // ConsolidateBringBack()
|
|
object oArea=GetAreaFromLocation(lLocation);
|
|
if (oCreature!=OBJECT_INVALID&&oArea!=OBJECT_INVALID)
|
|
{ // valid
|
|
SetCommandable(TRUE,oCreature);
|
|
SetAILevel(oCreature,AI_LEVEL_NORMAL);
|
|
if (GetArea(oCreature)!=oArea||GetDistanceBetweenLocations(lLocation,GetLocation(oCreature))>15.0)
|
|
{ // jump
|
|
AssignCommand(oCreature,JumpToLocation(lLocation));
|
|
DelayCommand(1.0,ConsolidateBringBack(oCreature,lLocation,nAI_Level));
|
|
} // jump
|
|
else
|
|
{ // reset settings
|
|
SetAILevel(oCreature,nAI_Level);
|
|
DeleteLocalInt(oCreature,"bConsolidated");
|
|
} // reset settings
|
|
} // calid
|
|
} // ConsolidateBringBack()
|
|
|
|
|
|
object ConsolidateMakeLeader(object oCreature,string sSpecialVariable,float fRange=100.0)
|
|
{ // PURPOSE: Return consolidation leader
|
|
object oRet=OBJECT_INVALID;
|
|
object oOb;
|
|
int nN;
|
|
if (oCreature!=OBJECT_INVALID)
|
|
{ // valid
|
|
if (GetIsConsolidationLeader(oCreature)==FALSE)
|
|
{ // not currently leader
|
|
nN=1;
|
|
oOb=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oCreature,nN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_FRIEND,CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_NOT_PC);
|
|
while(oOb!=OBJECT_INVALID&&oRet==OBJECT_INVALID&&GetDistanceBetween(oOb,oCreature)<=fRange)
|
|
{ // look for leader
|
|
if (GetLocalString(oCreature,"sTeamID")==GetLocalString(oOb,"sTeamID"))
|
|
{ // they are on the same team
|
|
if (GetLocalInt(oCreature,"nMState")==GetLocalInt(oOb,"nMState"))
|
|
{ // they are in the same state
|
|
if (GetLocalInt(oCreature,"nParm")==GetLocalInt(oOb,"nParm"))
|
|
{ // parameters are the same
|
|
if (GetLocalString(oCreature,sSpecialVariable)==GetLocalString(oOb,sSpecialVariable))
|
|
{ // they are the same value
|
|
if (GetLocalInt(oOb,"bConsolidationLeader")==TRUE) oRet=oOb;
|
|
} // they are the same value
|
|
} // parameters are the same
|
|
} // they are in the same state
|
|
} // they are on the same team
|
|
nN++;
|
|
oOb=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oCreature,nN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_FRIEND,CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_NOT_PC);
|
|
} // look for leader
|
|
if (oRet==OBJECT_INVALID)
|
|
{ // make this creature consolidation leader
|
|
SetLocalInt(oCreature,"bConsolidationLeader",TRUE);
|
|
oRet=oCreature;
|
|
} // make this creature consolidation leader
|
|
} // not currently leader
|
|
else
|
|
{ // is leader
|
|
oRet=oCreature;
|
|
} // is leader
|
|
} // valid
|
|
return oRet;
|
|
} // ConsolidateMakeLeader()
|
|
|
|
void ConsolidateFreeLeader(object oCreature)
|
|
{ // ConsolidateFreeLeader()
|
|
object oOb;
|
|
location lLoc=GetLocation(oCreature);
|
|
if (oCreature!=OBJECT_INVALID&&GetLocalInt(oCreature,"bConsolidationLeader"))
|
|
{ // valid
|
|
oOb=ConsolidatePop(oCreature);
|
|
while(oOb!=OBJECT_INVALID)
|
|
{ // free up consolidated units
|
|
ConsolidateBringBack(oOb,lLoc,AI_LEVEL_NORMAL);
|
|
oOb=ConsolidatePop(oCreature);
|
|
} // free up consolidated units
|
|
DeleteLocalInt(oCreature,"bConsolidationLeader");
|
|
} // valid
|
|
} // ConsolidateFreeLeader()
|
|
|
|
int GetIsConsolidationLeader(object oCreature)
|
|
{ // GetIsConsolidationLeader()
|
|
return GetLocalInt(oCreature,"bConsolidationLeader");
|
|
} // GetIsConsolidationLeader()
|
|
|
|
void Consolidate(object oCreature,string sWhereTag,string sSpecialVariable,float fRange=100.0)
|
|
{ // Consolidate()
|
|
object oLeader=ConsolidateMakeLeader(oCreature,sSpecialVariable,fRange);
|
|
if (oLeader!=OBJECT_INVALID&&oLeader!=oCreature)
|
|
{ // put away
|
|
ConsolidatePush(oLeader,oCreature);
|
|
ConsolidatePutAway(oCreature,sWhereTag);
|
|
} // put away
|
|
} // Consolidate()
|
|
|
|
int GetShouldConsolidate(object oCreature)
|
|
{ // GetShouldConsolidate()
|
|
int bRet=TRUE;
|
|
object oEnemy=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oCreature,1,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_ENEMY);
|
|
object oPC=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oCreature,1,CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC);
|
|
if (oEnemy!=OBJECT_INVALID&&GetObjectSeen(oCreature,oEnemy)) bRet=FALSE;
|
|
if (oPC!=OBJECT_INVALID)
|
|
{ // PC exist
|
|
if (GetIsDM(oPC)==TRUE) oPC=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oCreature,2,CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC);
|
|
if (GetIsDM(oPC)==FALSE&&oPC!=OBJECT_INVALID) bRet=FALSE;
|
|
} // PC exist
|
|
return bRet;
|
|
} // GetShouldConsolidate()
|
|
|
|
//void main(){}
|