HoS_PRC8/_mod/_module/nss/ai_h_custom.nss
Jaysyn904 04165202c0 Initial upload
Initial upload
2024-11-25 19:36:07 -05:00

168 lines
5.5 KiB
Plaintext

///////////////////////////////////////////////////////////////////////////////
// ai_h_custom - Custom AI Header
// By Deva Bryson Winblood.
//----------------------------------------------------------------------------
// PURPOSE: To provide a lot of common functions to be used when setting up your
// own AI for teams.
///////////////////////////////////////////////////////////////////////////////
///////////////////////
// CONSTANTS
///////////////////////
const int DWF_TEAM =1;
const int UND_TEAM =2;
const int UNC_TEAM =3;
const int SPID_TEAM=4;
// constants for UNIT AI STATES - see rts_unit_ai for more info
const int CMD_GUARD_LAIR = 11;
const int CMD_RAID = 17;
const int CMD_HARVEST =1;
const int CMD_GUARD = 2;
const int CMD_PROTECT = 4;
const int CMD_SEEK = 6;
const int CMD_STAND = 7;
const int CMD_ROAM = 8;
const int CMD_HEAL = 9;
const int CMD_SCOUT = 12;
const int CMD_RECON = 14;
const int CMD_CONTROL = 18; // capture control point
const int CMD_ITEM = 19; // item collector AI
const int CMD_GUARDA = 21; // guard area
///////////////////////
// PROTOTYPES
///////////////////////
// FILE: ai_h_custom FUNCTION: fnAIGetLairStart()
// returns the starting waypoint where players and leaders spawn
object fnAIGetLairStart(string sID);
// FILE: ai_h_custom FUNCTION: fnAIGetLairChest()
// returns the object that the taxes are stored in for this team
object fnAIGetLairChest(string sID);
// FILE: ai_h_custom FUNCTION: fnAIGetLargestTrespasser()
// returns the ID of the team that has the most trespass counts against this
// team sID.
string fnAIGetLargestTrespasser(string sID);
// FILE: ai_h_custom FUNCTION: fnAIGetRandomTrespasser()
// returns the ID of a team that has trespassed randomly chosen.
string fnAIGetRandomTrespasser(string sID);
// FILE: ai_h_custom FUNCTION: fnAIRaid()
// This function can be applied to a unit and used to set the raid type
// as well as who to raid.
void fnAIRaid(object oOb,string sRaid,int nParm);
// FILE: ai_h_custom FUNCTION: fnAILevel()
// This function will return the level of the NPC or PC who is passed to the function
int fnAILevel(object oOb);
// FILE: ai_h_custom FUNCTION: fnAIGetGold()
// This function returns how much gold the team has in its tax chest.
int fnAIGold(string sID);
// FILE: ai_h_custom FUNCTION: fnAISetGold()
// This function enables you to set how much gold this team has in the tax chest
void fnAISetGold(string sID,int nGold);
///////////////////////
// FUNCTIONS
///////////////////////
void fnAISetGold(string sID,int nGold)
{
object oChest=GetObjectByTag(sID+"_CHEST");
int nG=0;
object oItem=GetFirstItemInInventory(oChest);
while(oItem!=OBJECT_INVALID)
{ // count gold
if (GetResRef(oItem)=="nw_it_gold001")
{ // gold
DelayCommand(0.3,DestroyObject(oItem));
} // gold
oItem=GetNextItemInInventory(oChest);
} // count gold
CreateItemOnObject("nw_it_gold001",oChest,nGold);
} // set gold amount
int fnAIGetGold(string sID)
{
object oChest=GetObjectByTag(sID+"_CHEST");
int nG=0;
object oItem=GetFirstItemInInventory(oChest);
while(nG==0&&oItem!=OBJECT_INVALID)
{ // check chest inventory
if (GetTag(oItem)=="NW_IT_GOLD001") nG=GetItemStackSize(oItem);
oItem=GetNextItemInInventory(oChest);
} // check chest inventory
return nG;
} // fnAIGetGold()
int fnAILevel(object oOb)
{ // return level
return GetLevelByPosition(1,oOb)+GetLevelByPosition(2,oOb)+GetLevelByPosition(3,oOb);
} // fnLevel()
void fnAIRaid(object oOb,string sRaid,int nParm)
{
DeleteLocalInt(oOb,"nSState");
SetLocalString(oOb,"sTeamToRaid",sRaid);
SetLocalInt(oOb,"nParm",nParm); // attack
SetLocalInt(oOb,"nMState",17);
SetLocalInt(oOb,"nRun",TRUE);
//AssignCommand(oOb,SpeakString("*raid "+sRaid+"*"));
} // fnAIRaid()
object fnAIGetLairStart(string sID)
{
object oWP=GetWaypointByTag(sID+"_START");
return oWP;
} // fnAIGetLairStart()
object fnAIGetLairChest(string sID)
{
object oOb=GetObjectByTag(sID+"_CHEST");
return oOb;
} // fnAIGetLairChest()
string fnAIGetLargestTrespasser(string sID)
{
string sRet="NA";
object oMod=GetModule();
string sTresPrefix="nAITrespass"+sID+"_";
int nCount=0;
if (sID!="DWF"&&GetLocalInt(oMod,sTresPrefix+"DWF")>nCount) { nCount=GetLocalInt(oMod,sTresPrefix+"DWF"); sRet="DWF"; }
if (sID!="UND"&&GetLocalInt(oMod,sTresPrefix+"UND")>nCount) { nCount=GetLocalInt(oMod,sTresPrefix+"UND"); sRet="UND"; }
if (sID!="UNC"&&GetLocalInt(oMod,sTresPrefix+"UNC")>nCount) { nCount=GetLocalInt(oMod,sTresPrefix+"UNC"); sRet="UNC"; }
if (sID!="SPID"&&GetLocalInt(oMod,sTresPrefix+"SPID")>nCount) { nCount=GetLocalInt(oMod,sTresPrefix+"SPID"); sRet="SPID"; }
return sRet;
} // fnAIGetLargestTrespasser()
string fnAIGetRandomTrespasser(string sID)
{
string sRet="NA";
object oMod=GetModule();
int nCount=0;
int nR;
string sTresPrefix="nAITrespass"+sID+"_";
if (fnAIGetLargestTrespasser(sID)!="NA")
{ // there is a trespasser
while(sRet=="NA")
{ // get trespasser
nR=d4();
if (sID!="DWF"&&GetLocalInt(oMod,sTresPrefix+"DWF")>nCount&&nR==1) return "DWF";
else if (sID!="UND"&&GetLocalInt(oMod,sTresPrefix+"UND")>nCount&&nR==2) return "UND";
else if (sID!="UNC"&&GetLocalInt(oMod,sTresPrefix+"UNC")>nCount&&nR==3) return "UNC";
else if (sID!="SPID"&&GetLocalInt(oMod,sTresPrefix+"SPID")>nCount&&nR==4) return "SPID";
} // get trespasser
} // there is a trespasser
return sRet;
} // fnAIGetRandomTrespasser()
//void main(){}