HoS_PRC8/_mod/_module/nss/rtsa_headerl.nss
Jaysyn904 e2f4ba74d5 Merged redundant hak files
Merged redundant hak files.  Moved hak scripts into module.  Updated gitignore.  Full Compile.  Added release folder & archive.
2024-12-12 15:02:17 -05:00

315 lines
11 KiB
Plaintext

///////////////////////////////////////////////////////////////////////////////////
// REAL TIME STRATEGY ADVENTURE - Kit
// FILE: rtsa_headerl
// NAME: Active List header file
// SCRIPTED BY: Deva Bryson Winblood
// DATE: 7/17/2003
///////////////////////////////////////////////////////////////////////////////////
#include "rtsa_headere" // error and debug
int fnInitializeList(string sPrefix, object oOn)
{ // setup a list on object with this prefix
// error messages 0 = okay -1 = already exists -2 = oOn not found
int nRet=0;
object oOb;
int nN;
string sVar;
if (oOn!=OBJECT_INVALID)
{ // valid object
sVar="oRTSA"+sPrefix+GetTag(oOn);
oOb=GetLocalObject(oOn,sVar);
if (oOb==OBJECT_INVALID)
{ // okay to create
SetLocalObject(oOn,sVar,oOn);
sVar="nRTSA"+sPrefix;
SetLocalInt(oOn,sVar+"F",0);
SetLocalInt(oOn,sVar+"L",0);
SetLocalInt(oOn,sVar+"C",0);
} // okay to create
else
nRet=-1;
} // valid object
else
nRet=-2;
return nRet;
} // fnInitializeList()
void fnAddListEntry(string sPrefix,object oOn,object oItem,int nWeight)
{ // add an item into the list
string sVar="oRTSA"+sPrefix+"O";
int nL=GetLocalInt(oOn,"nRTSA"+sPrefix+"L");
string sNum;
int nP;
int nN;
fnDebug("fnAddListEntry("+sPrefix+","+GetTag(oOn)+","+GetName(oItem)+","+IntToString(nWeight)+")");
//fnDebug(" Initial Values: sVar='"+sVar+"' nL="+IntToString(nL));
//fnDebug(" Add Item");
sVar="nRTSA"+sPrefix;
nN=nL+1;
if (nL!=0) SetLocalInt(oOn,sVar+"N"+IntToString(nL),nN);
if (nL==0) SetLocalInt(oOn,sVar+"F",nN);
SetLocalInt(oOn,"nRTSA"+sPrefix+"P"+IntToString(nN),nL);
SetLocalInt(oOn,"nRTSA"+sPrefix+"L",nN);
SetLocalObject(oOn,"oRTSA"+sPrefix+"O"+IntToString(nN),oItem);
SetLocalInt(oOn,"nRTSA"+sPrefix+"W"+IntToString(nN),nWeight);
fnDebug(" [ADDED TO LIST]");
fnDebug(" nN:"+IntToString(nN));
fnDebug(" N[nN]:"+IntToString(GetLocalInt(oOn,sVar+"N"+IntToString(nN))));
fnDebug(" P[nN]:"+IntToString(GetLocalInt(oOn,sVar+"P"+IntToString(nN))));
fnDebug(" O[nN]:"+GetName(GetLocalObject(oOn,"oRTSA"+sPrefix+"O"+IntToString(nN))));
fnDebug(" Last List Entry="+IntToString(nN)+" Name:'"+GetName(GetLocalObject(oOn,"oRTSA"+sPrefix+"O"+IntToString(nN)))+"'");
} // fnAddListEntry()
int fnFindListEntry(string sPre,object oOn,object oItem)
{ // find list entry
int nRet=0;
int nC=GetLocalInt(oOn,"nRTSA"+sPre+"F");
string sVar="oRTSA"+sPre+"O";
int bFound=FALSE;
while(nC!=0&&bFound!=TRUE)
{ // traverse
if (GetLocalObject(oOn,sVar+IntToString(nC))==oItem)
{ // found
nRet=nC;
bFound=TRUE;
} // found
nC=GetLocalInt(oOn,"nRTSA"+sPre+"N"+IntToString(nC));
} // traverse
return nRet;
} // fnFindListEntry()
void fnAdjustListEntry(string sPre,object oOn,object oItem,int nWeight,int nActive=TRUE)
{ // change the entry
int nEntry=fnFindListEntry(sPre,oOn,oItem);
string sVar="nRTSA"+sPre;
fnDebug("fnAdjustListEntry("+sPre+","+GetTag(oOn)+","+GetName(oItem)+","+IntToString(nWeight)+",ACTIVE:"+IntToString(nActive)+")");
if (nEntry!=0)
{ // item is in list
//fnDebug(" Found to adust as entry #"+IntToString(nEntry));
SetLocalInt(oOn,sVar+"W"+IntToString(nEntry),nWeight);
SetLocalInt(oOn,sVar+"A"+IntToString(nEntry),nActive);
} // item is in list
else
{
//fnDebug(" Entry not found.");
}
} // fnAdjustListEntry()
int fnGetListEntryWeight(string sPre,object oOn,object oItem)
{ // find out what the list weight is for the item
int nRet=0;
int nEntry=fnFindListEntry(sPre,oOn,oItem);
if (nEntry!=0)
{ // valid item
nRet=GetLocalInt(oOn,"nRTSA"+sPre+"W"+IntToString(nEntry));
} // valid item
return nRet;
} // fnGetListEntryWeight()
object fnGetFirstListEntry(string sPre,object oOn)
{ // get first list entry
object oRet=OBJECT_INVALID;
int nR=GetLocalInt(oOn,"nRTSA"+sPre+"F");
if (nR!=0)
{ // there are entries
//fnDebug(" [DUMP LIST INFORMATION]");
//fnDebug(" Prefix:"+sPre);
//fnDebug(" F:"+IntToString(GetLocalInt(oOn,"nRTSA"+sPre+"F")));
//fnDebug(" L:"+IntToString(GetLocalInt(oOn,"nRTSA"+sPre+"L")));
//fnDebug(" C:"+IntToString(GetLocalInt(oOn,"nRTSA"+sPre+"C")));
//fnDebug(" O[1]:"+GetName(GetLocalObject(oOn,"oRTSA"+sPre+"O"+IntToString(nR))));
SetLocalInt(oOn,"nRTSA"+sPre+"C",nR);
oRet=GetLocalObject(oOn,"oRTSA"+sPre+"O"+IntToString(nR));
//fnDebug("fnGetFirstListEntry("+sPre+IntToString(nR)+","+GetTag(oOn)+")="+GetName(oRet));
} // there are entries
return oRet;
} // fnGetFirstListEntry()
object fnGetNextListEntry(string sPre,object oOn)
{ // get next list entry
object oRet=OBJECT_INVALID;
int nR=GetLocalInt(oOn,"nRTSA"+sPre+"C");
nR=GetLocalInt(oOn,"nRTSA"+sPre+"N"+IntToString(nR));
if (nR!=0)
{ // valid
SetLocalInt(oOn,"nRTSA"+sPre+"C",nR);
oRet=GetLocalObject(oOn,"oRTSA"+sPre+"O"+IntToString(nR));
//fnDebug("fnGetNextListEntry("+sPre+","+GetTag(oOn)+")="+GetName(oRet));
} // valid
return oRet;
} // fnGetNextListEntry()
int fnGetListEntryActive(string sPre,object oOn,object oItem)
{ // find out what the list weight is for the item
int nRet=0;
int nEntry=fnFindListEntry(sPre,oOn,oItem);
if (nEntry!=0)
{ // valid item
nRet=GetLocalInt(oOn,"nRTSA"+sPre+"A"+IntToString(nEntry));
} // valid item
return nRet;
} // fnGetListEntryWeight()
object fnFindHeaviestActiveListEntry(string sPre,object oOn)
{ // find heaviest list item
object oRet=OBJECT_INVALID;
int nHeavy=-1;
int nCur;
int nNum;
object oTest=fnGetFirstListEntry(sPre,oOn);
//fnDebug("fnFindHeaviestActiveListEntry("+sPre+","+GetTag(oOn)+")");
while(oTest!=OBJECT_INVALID)
{ // traverse list
nNum=GetLocalInt(oOn,"nRTSA"+sPre+"C");
nCur=GetLocalInt(oOn,"nRTSA"+sPre+"W"+IntToString(nNum));
if (nCur>nHeavy||nHeavy==0)
{ // heavier
oRet=oTest;
nHeavy=nCur;
} // heavier
oTest=fnGetNextListEntry(sPre,oOn);
} // traverse list
return oRet;
} // fnFindHeaviestActiveListEntry()
object fnGetListEntry(string sPre,object oOn,int nNum)
{ // get list entry by number
object oRet=GetLocalObject(oOn,"oRTSA"+sPre+"O"+IntToString(nNum));
return oRet;
} // fnGetListEntry()
void fnDeleteListEntry(string sPre,object oOn,object oItem)
{ // delete list entry
int nEntry=fnFindListEntry(sPre,oOn,oItem);
int nP;
int nN;
fnDebug("fnDeleteListEntry("+sPre+","+GetTag(oOn)+","+GetName(oItem)+")");
if (nEntry!=0)
{ // valid entry
nP=GetLocalInt(oOn,"nRTSA"+sPre+"P"+IntToString(nEntry));
nN=GetLocalInt(oOn,"nRTSA"+sPre+"N"+IntToString(nEntry));
if (nP!=0)
{ // valid previous
SetLocalInt(oOn,"nRTSA"+sPre+"N"+IntToString(nP),nN);
} // valid previous
if (nN!=0)
{ // valid next
SetLocalInt(oOn,"nRTSA"+sPre+"P"+IntToString(nN),nP);
} // valid next
if (nEntry==GetLocalInt(oOn,"nRTSA"+sPre+"L"))
{ // new last
SetLocalInt(oOn,"nRTSA"+sPre+"L",nP);
} // new last
if (nEntry==GetLocalInt(oOn,"nRTSA"+sPre+"F"))
{ // new first
SetLocalInt(oOn,"nRTSA"+sPre+"F",nN);
} // new first
if (nEntry==GetLocalInt(oOn,"nRTSA"+sPre+"C"))
{ // new current
SetLocalInt(oOn,"nRTSA"+sPre+"C",0);
} // new current
/// delete variables
DeleteLocalObject(oOn,"oRTSA"+sPre+"O"+IntToString(nEntry));
DeleteLocalInt(oOn,"nRTSA"+sPre+"P"+IntToString(nEntry));
DeleteLocalInt(oOn,"nRTSA"+sPre+"N"+IntToString(nEntry));
DeleteLocalInt(oOn,"nRTSA"+sPre+"W"+IntToString(nEntry));
DeleteLocalInt(oOn,"nRTSA"+sPre+"A"+IntToString(nEntry));
} // valid entry
} // fnDeleteListEntry()
void fnSetCampaignList(string sCamp,string sPre,object oOn,object oPC=OBJECT_INVALID)
{ // store list in database
object oOb;
int nN;
int nE;
string sSPre=sPre+GetTag(oOn);
if (oOn!=OBJECT_INVALID)
{ // is valid
nN=GetLocalInt(oOn,"nRTSA"+sPre+"F");
SetCampaignInt(sCamp,"nRTSA"+sSPre+"F",nN,oPC);
nN=GetLocalInt(oOn,"nRTSA"+sPre+"L");
SetCampaignInt(sCamp,"nRTSA"+sSPre+"L",nN,oPC);
oOb=fnGetFirstListEntry(sPre,oOn);
while(oOb!=OBJECT_INVALID)
{ // traverse list
nE=fnFindListEntry(sPre,oOn,oOb);
SetCampaignString(sCamp,"sRTSA"+sSPre+"O"+IntToString(nE),GetResRef(oOb),oPC);
SetCampaignString(sCamp,"sRTSA"+sSPre+"T"+IntToString(nE),GetTag(oOb),oPC);
SetCampaignLocation(sCamp,"lRTSA"+sSPre+"L"+IntToString(nE),GetLocation(oOb),oPC);
nN=GetLocalInt(oOn,"nRTSA"+sPre+"W"+IntToString(nE));
SetCampaignInt(sCamp,"nRTSA"+sSPre+"W"+IntToString(nE),nN,oPC);
nN=GetLocalInt(oOn,"nRTSA"+sPre+"A"+IntToString(nE));
SetCampaignInt(sCamp,"nRTSA"+sSPre+"A"+IntToString(nE),nN,oPC);
nN=GetLocalInt(oOn,"nRTSA"+sPre+"P"+IntToString(nE));
SetCampaignInt(sCamp,"nRTSA"+sSPre+"P"+IntToString(nE),nN,oPC);
nN=GetLocalInt(oOn,"nRTSA"+sPre+"N"+IntToString(nE));
SetCampaignInt(sCamp,"nRTSA"+sSPre+"N"+IntToString(nE),nN,oPC);
oOb=fnGetNextListEntry(sPre,oOn);
} // traverse list
} // is valid
} // fnSetCampaignList()
void fnGetCampaignList(string sCamp,string sPre,object oOn,object oPC=OBJECT_INVALID)
{ // load a list from a database
} // fnGetCampaignList()
void fnDeleteListEntryN(string sPre,object oOn,int nEntry)
{ // delete list entry
int nP;
int nN;
fnDebug("fnDeleteListEntryN("+sPre+","+GetTag(oOn)+","+IntToString(nEntry)+")");
if (nEntry!=0)
{ // valid entry
nP=GetLocalInt(oOn,"nRTSA"+sPre+"P"+IntToString(nEntry));
nN=GetLocalInt(oOn,"nRTSA"+sPre+"N"+IntToString(nEntry));
if (nP!=0)
{ // valid previous
SetLocalInt(oOn,"nRTSA"+sPre+"N"+IntToString(nP),nN);
} // valid previous
if (nN!=0)
{ // valid next
SetLocalInt(oOn,"nRTSA"+sPre+"P"+IntToString(nN),nP);
} // valid next
if (nEntry==GetLocalInt(oOn,"nRTSA"+sPre+"L"))
{ // new last
SetLocalInt(oOn,"nRTSA"+sPre+"L",nP);
} // new last
if (nEntry==GetLocalInt(oOn,"nRTSA"+sPre+"F"))
{ // new first
SetLocalInt(oOn,"nRTSA"+sPre+"F",nN);
} // new first
if (nEntry==GetLocalInt(oOn,"nRTSA"+sPre+"C"))
{ // new current
SetLocalInt(oOn,"nRTSA"+sPre+"C",0);
} // new current
/// delete variables
DeleteLocalObject(oOn,"oRTSA"+sPre+"O"+IntToString(nEntry));
DeleteLocalInt(oOn,"nRTSA"+sPre+"P"+IntToString(nEntry));
DeleteLocalInt(oOn,"nRTSA"+sPre+"N"+IntToString(nEntry));
DeleteLocalInt(oOn,"nRTSA"+sPre+"W"+IntToString(nEntry));
DeleteLocalInt(oOn,"nRTSA"+sPre+"A"+IntToString(nEntry));
} // valid entry
} // fnDeleteListEntryN()
void fnCleanList(string sPre,object oOn)
{ // clean out OBJECT_INVALIDs
object oList;
string sVar="RTSA"+sPre;
int nF=GetLocalInt(oOn,"n"+sVar+"F");
int nC=nF;
int nN;
//fnDebug(" fnCleanList()");
while(nC!=0)
{ // traverse
oList=fnGetListEntry(sPre,oOn,nC);
nN=GetLocalInt(oOn,"n"+sVar+"N"+IntToString(nC));
if (oList==OBJECT_INVALID)
{ // delete this entry
fnDeleteListEntryN(sPre,oOn,nC); // delete entry
} // delete this entry
nC=nN;
} // traverse
} // fnCleanList()