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

180 lines
6.9 KiB
Plaintext

////////////////////////////////////////////////////////////////////////////////
// pl_hb_citydonate - Gold placed within this will defend the city more
// By Deva B. Winblood. November 11th, 2008
////////////////////////////////////////////////////////////////////////////////
#include "lib_hos2_shpath"
#include "nw_i0_generic"
////////////////////////////
// FUNCTIONS
////////////////////////////
void fnPossessCaptain()
{ // PURPOSE: Possessive function for captain
object oMe=OBJECT_SELF;
float fDelay=12.0;
object oEnemy=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oMe,1,CREATURE_TYPE_PERCEPTION,PERCEPTION_SEEN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_ENEMY);
if (!GetIsInCombat(oMe)&&!IsInConversation(oMe)&&!GetIsDMPossessed(oMe)&&!GetIsObjectValid(oEnemy))
{ // okay to control
int nMode=GetLocalInt(oMe,"nMode");
int nMax=GetMaxHitPoints(oMe);
int nCurr=GetCurrentHitPoints(oMe);
object oWP;
if (nCurr<nMax)
{ // go to municipal building 0 to heal
oWP=GetWaypointByTag("MUNICIPAL_GUARD_0");
if (GetArea(oWP)!=GetArea(oMe)||GetDistanceBetween(oWP,oMe)>5.0)
{ // run
int nRet=MoveToObject(oMe,oWP,TRUE,4.0);
fDelay=4.0;
} // run
else
{ // sit and heal
AssignCommand(oMe,ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS,1.0,8.1));
effect eHeal=EffectHeal(1);
ApplyEffectToObject(DURATION_TYPE_INSTANT,eHeal,oMe);
fDelay=8.0;
} // sit and heal
} // go to municipal building 0 to heal
else
{ // path to guard point
oWP=GetWaypointByTag("MUNICIPAL_GUARD_"+IntToString(nMode));
if (GetIsObjectValid(oWP))
{ // path
if (GetArea(oWP)!=GetArea(oMe)||GetDistanceBetween(oWP,oMe)>5.0)
{ // move
int nRet=MoveToObject(oMe,oWP,FALSE,4.0);
fDelay=4.0;
} // move
else
{ // arrived
AssignCommand(oMe,ClearAllActions());
AssignCommand(oMe,SetFacing(GetFacing(oWP)));
nMode=nMode+1;
} // arrived
} // path
else { nMode=0; fDelay=6.0; }
SetLocalInt(oMe,"nMode",nMode);
} // path to guard point
} // okay to control
else if (!GetIsInCombat(oMe)&&GetIsObjectValid(oEnemy))
{ // declare combat
AssignCommand(oMe,ClearAllActions(TRUE));
DetermineCombatRound(oEnemy);
} // declare combat
DelayCommand(fDelay,fnPossessCaptain());
} // fnPossessCaptain()
void fnPossessGuard()
{ // PURPOSE: Possessive function for guard
object oMe=OBJECT_SELF;
float fDelay=24.0;
object oWP=GetLocalObject(oMe,"oPost");
object oEnemy=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oMe,1,CREATURE_TYPE_PERCEPTION,PERCEPTION_SEEN,CREATURE_TYPE_REPUTATION,REPUTATION_TYPE_ENEMY);
if (!GetIsInCombat(oMe)&&!IsInConversation(oMe)&&!GetIsDMPossessed(oMe)&&!GetIsObjectValid(oEnemy))
{ // okay to control
if (GetArea(oWP)!=GetArea(oMe)||GetDistanceBetween(oMe,oWP)>5.0)
{ // path
SetAILevel(oMe,AI_LEVEL_NORMAL);
int nRet=MoveToObject(oMe,oWP,FALSE,4.0);
fDelay=6.0;
} // path
else
{ // reduce AI level
SetAILevel(oMe,AI_LEVEL_DEFAULT);
} // reduce AI Level
} // okay to control
else
{ // check after combat
if (!GetIsInCombat(oMe)&&GetIsObjectValid(oEnemy))
{ // attack
AssignCommand(oMe,ClearAllActions());
DetermineCombatRound(oEnemy);
} // attack
fDelay=10.0;
} // check after combat
DelayCommand(fDelay,fnPossessGuard());
} // fnPossessGuard()
///////////////////////////////////////////////////////////////////[ MAIN]//////
void main()
{
object oMe=OBJECT_SELF;
object oMod=GetModule();
int nFunds=GetLocalInt(oMod,"nGuardFund");
if (nFunds>0)
{ // guard fund exists
object oCaptain=GetLocalObject(oMe,"oCaptain");
if (GetIsObjectValid(oCaptain))
{ // captain exists - check for troop spawn
int nType=GetLocalInt(oMe,"nType");
string sRes;
int nCost=0;
if (nType==1) { sRes="cityguard2"; nCost=2; }
else if (nType==2) { sRes="cityguard1"; nCost=5; }
else if (nType==3) { sRes="cityguard5"; nCost=20; }
else if (nType==4) { sRes="cityguard7"; nCost=100; }
if (nFunds>nCost)
{ // create if need be
int nN=1;
int nSlot=0;
object oGuard=GetLocalObject(oMe,"oGuard"+IntToString(nN));
while(nSlot==0&&nN<9)
{ // check for slot
if (!GetIsObjectValid(oGuard)) nSlot=nN;
nN++;
oGuard=GetLocalObject(oMe,"oGuard"+IntToString(nN));
} // check for slot
if (nSlot>0)
{ // slot found
object oWP=GetWaypointByTag("MUNICIPAL_GUARD_"+IntToString(nSlot));
nFunds=nFunds-nCost;
oGuard=CreateObject(OBJECT_TYPE_CREATURE,sRes,GetLocation(oMe));
SetAILevel(oGuard,AI_LEVEL_NORMAL);
SetLocalObject(oGuard,"oPost",oWP);
AssignCommand(oGuard,fnPossessGuard());
SetLocalObject(oMe,"oGuard"+IntToString(nSlot),oGuard);
} // slot found
} // create if need be
} // captain exists - check for troop spawn
else
{ // captain needs to be created
int nType=0;
if (nFunds>799) nType=4;
else if (nFunds>119) nType=3;
else if (nFunds>51) nType=2;
else { nType=1; }
SetLocalInt(oMe,"nType",nType);
string sRes="";
int nCost=0;
if (nType==1) { sRes="cityguard3"; nCost=10; }
else if (nType==2) { sRes="cityguard4"; nCost=50; }
else if (nType==3) { sRes="cityguard6"; nCost=100; }
else if (nType==4) { sRes="cityguard8"; nCost=500; }
if (nFunds>nCost)
{ // create
nFunds=nFunds-nCost;
oCaptain=CreateObject(OBJECT_TYPE_CREATURE,sRes,GetLocation(oMe));
SetAILevel(oCaptain,AI_LEVEL_NORMAL);
AssignCommand(oCaptain,fnPossessCaptain());
SetLocalObject(oMe,"oCaptain",oCaptain);
} // create
} // captain needs to be created
int nTime=GetLocalInt(oMe,"nTime");
if (nTime!=GetTimeHour())
{ // double funds
SetLocalInt(oMe,"nTime",GetTimeHour());
nFunds=nFunds*2;
if (nFunds>3000) nFunds=3000;
} // double funds
SetLocalInt(oMod,"nGuardFund",nFunds);
} // guard fund exists
}
///////////////////////////////////////////////////////////////////[ MAIN]//////