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

274 lines
10 KiB
Plaintext

////////////////////////////////////////////////////////////////////////////////
// ai_powerres - Challenging AI - Power Reservoir Recovery mode
// By Deva Bryson Winblood. 02/04 - 02/05/2005
////////////////////////////////////////////////////////////////////////////////
#include "powres_h"
#include "color_header"
#include "rts_pathing"
#include "rts_header"
void fnApplyEffect(string sID,int nNum)
{ // visual effect
object oMe=OBJECT_SELF;
object oOb=GetLocalObject(GetModule(),"oHasPowerRes_"+sID);
effect eVFX;
if (oOb==oMe)
{ // carrying power res
eVFX=EffectVisualEffect(nNum);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eVFX,oMe,5.0);
DelayCommand(4.9,fnApplyEffect(sID,nNum));
} // carrying power res
} // fnApplyEffect()
////////////////////////////////////////////////////////////////////////// MAIN
void main()
{
object oMe=OBJECT_SELF;
int nState=GetLocalInt(oMe,"nSState");
location lLoc;
string sS;
int nN;
float fF;
object oOb;
object oPowerRes=GetObjectByTag("RTS_POWER_RES",0);
object oLair;
string sID=GetLocalString(oMe,"sTeamID");
string sHas;
int nMainPath;
int nTravelMethod=0;
int nNum;
effect eEff;
if (sID=="DWF") nTravelMethod=2;
else if (sID=="UND") nTravelMethod=0;
else if (sID=="SPID") nTravelMethod=0;
else if (sID=="UNC") nTravelMethod=0;
if (fnCheckForLight()>1) nTravelMethod=4;
else if (fnCheckForLight()>0) nTravelMethod=3;
//SendMessageToPC(GetFirstPC(),GetTag(oMe)+" ai_powerres in "+GetName(GetArea(oMe))+" nState:"+IntToString(nState));
////////// Check for state of PowerReservoir
// if it is in a lair other than your own... immediately go into retrieval mode
if (oPowerRes!=OBJECT_INVALID)
{ // test location
oLair=GetNearestObjectByTag("LAIR",oPowerRes);
if (oLair!=OBJECT_INVALID)
{ // it is in a lair
sHas=GetLocalString(oPowerRes,"sTeamID");
//SendMessageToPC(GetFirstPC()," Power Reservoir is in lair '"+sHas+"'.");
if (GetStringLength(sHas)>0&&sHas!=sID)
{ // in lair
//SendMessageToPC(GetFirstPC()," That is NOT my lair... must recover the reservoir.");
if (nState<3)
{ // seek power reservoir
nState=3;
SetLocalInt(oMe,"nSState",3);
} // seek power reservoir
} // in lair
else if (nState>2)
{ // nothing specific
nState=0;
SetLocalInt(oMe,"nSState",0);
} // nothing specific
} // it is in a lair
else if (oLair==OBJECT_INVALID)
{ // not in a lair
if (nState>2)
{ // set back to a state that is not seeking power res
nState=0;
SetLocalInt(oMe,"nSState",0);
} // set back to a state that is not seeking power res
} // not in a lair
} // test location
oOb=GetLocalObject(GetModule(),"oHasPowerRes_"+sID);
if (oOb!=OBJECT_INVALID&&GetArea(oOb)==GetArea(oMe))
{ // follow
//SendMessageToPC(GetFirstPC()," I am in area of team mate with reservoir... must follow!");
SetLocalInt(oMe,"nSState",6);
nState=6;
} // follow
switch(nState)
{ // behavior switch
case 0: { // move to planning location
SetLocalInt(oMe,"nRun",FALSE);
SetActionMode(oMe,ACTION_MODE_STEALTH,FALSE);
sS=sID+"_PR_PLANNING";
oOb=GetWaypointByTag(sS);
if (oOb!=OBJECT_INVALID)
{ // waypoint exists
fF=GetDistanceBetween(oMe,oOb);
if (fF>5.0||GetArea(oMe)!=GetArea(oOb))
{ // path
if (GetArea(oMe)!=GetArea(oOb))
{ // different area
oOb=fnReversePath(GetArea(oMe),oOb,sID,nTravelMethod);
if (GetCurrentAction(oMe)!=ACTION_MOVETOPOINT) AssignCommand(oMe,ActionForceMoveToObject(oOb,FALSE,1.0,120.0));
} // different area
else
{ // same area
if (GetCurrentAction(oMe)!=ACTION_MOVETOPOINT) AssignCommand(oMe,ActionForceMoveToObject(oOb,FALSE,1.0,120.0));
} // same area
} // path
else
{ // arrived
SetLocalInt(oMe,"nPRPath",0);
SetLocalInt(oMe,"nSState",1);
} // arrived
} // waypoint exists
else
{ // error
AssignCommand(oMe,SpeakString("**ERROR: ai_powerres - can't find '"+sS+"'!"));
} // error
break;
} // move to planning location
case 1: { // pick next destination
nN=GetLocalInt(oMe,"nPRPath");
AssignCommand(oMe,ActionPlayAnimation(ANIMATION_LOOPING_LOOK_FAR,1.0,3.0));
nMainPath=GetLocalInt(oMe,"nPRMainPath");
if (nN==0)
{ // first path
nMainPath=d4();
SetLocalInt(oMe,"nPRMainPath",nMainPath);
nN=1;
sS=sID+"_PR"+IntToString(nMainPath)+"_"+IntToString(nN);
} // first path
else
{ // next
nN++;
sS=sID+"_PR"+IntToString(nMainPath)+"_"+IntToString(nN);
} // next
oOb=GetWaypointByTag(sS);
if (oOb!=OBJECT_INVALID)
{ // destination exists
SetLocalInt(oMe,"nPRPath",nN);
SetLocalInt(oMe,"nSState",2);
} // destination exists
else
{ // end of line
SetLocalInt(oMe,"nSState",0);
DeleteLocalInt(oMe,"nPRPath");
DeleteLocalInt(oMe,"nPRMainPath");
} // end of line
break;
} // pick next destination
case 2: { // move to destination
SetLocalInt(oMe,"nRun",FALSE);
SetActionMode(oMe,ACTION_MODE_STEALTH,FALSE);
nN=GetLocalInt(oMe,"nPRPath");
nMainPath=GetLocalInt(oMe,"nPRMainPath");
sS=sID+"_PR"+IntToString(nMainPath)+"_"+IntToString(nN);
oOb=GetWaypointByTag(sS);
if (GetArea(oMe)!=GetArea(oOb)||GetDistanceBetween(oMe,oOb)>1.5)
{ // move
if (GetCurrentAction(oMe)!=ACTION_MOVETOPOINT) AssignCommand(oMe,ActionForceMoveToObject(oOb,FALSE,1.0,120.0));
} // move
else
{ // arrived
SetLocalInt(oMe,"nSState",1);
} // arrived
break;
} // move to destination
case 3: { // go to enemy lair
//SendMessageToPC(GetFirstPC()," Go to enemy lair!");
SetLocalInt(oMe,"nRun",TRUE);
SetActionMode(oMe,ACTION_MODE_STEALTH,FALSE);
oOb=GetWaypointByTag(sHas+"_START");
if (GetArea(oOb)!=GetArea(oMe))
{ // move
oOb=fnReversePath(GetArea(oMe),oOb,sHas,nTravelMethod);
if (GetCurrentAction(oMe)!=ACTION_MOVETOPOINT) AssignCommand(oMe,ActionForceMoveToObject(oOb,TRUE,1.0,120.0));
} // move
else
{ // same area
SetLocalInt(oMe,"nSState",4);
} // same area
break;
} // go to enemy lair
case 4: { // move to power reservoir
SetLocalInt(oMe,"nRun",FALSE);
SetActionMode(oMe,ACTION_MODE_STEALTH,TRUE);
if (GetDistanceBetween(oMe,oPowerRes)>2.0)
{ // move to power reservoir
if (GetCurrentAction(oMe)!=ACTION_MOVETOPOINT) AssignCommand(oMe,ActionForceMoveToObject(oPowerRes,TRUE,1.0,120.0));
} // move to power reservoir
else
{ // arrived
SetLocalInt(oMe,"nSState",5);
} // arrived
break;
} // move to power reservoir
case 5: { // pick up power reservoir
sS=ColorRGBString(GetName(oMe)+" has picked up the Power Reservoir!",0,5,0);
fnSoundMessage(sS,"NA","as_cv_belltower3");
CreateItemOnObject("rts_powerres",oMe);
SetLocalObject(GetModule(),"oHasPowerRes_"+sID,oMe);
nNum=VFX_DUR_FLAG_BLUE;
if (sID=="UNC") nNum=VFX_DUR_FLAG_GOLD;
else if (sID=="UND") nNum=VFX_DUR_FLAG_PURPLE;
else if (sID=="SPID") nNum=VFX_DUR_FLAG_RED;
fnApplyEffect(sID,nNum);
SetLocalInt(oMe,"nSState",7);
break;
} // pick up reservoir
case 6: { // team mate has power reservoir follow them if same area
SetLocalInt(oMe,"nRun",TRUE);
SetActionMode(oMe,ACTION_MODE_STEALTH,FALSE);
oOb=GetLocalObject(GetModule(),"oHasPowerRes_"+sID);
if (GetArea(oOb)==GetArea(oMe)&&oOb!=OBJECT_INVALID)
{ // follow
AssignCommand(oMe,ClearAllActions());
AssignCommand(oMe,ActionForceFollowObject(oOb,2.5));
} // follow
else
{ // done following
AssignCommand(oMe,ClearAllActions());
SetLocalInt(oMe,"nSState",0);
} // done following
break;
} // team mate has power reservoir follow them if same area
case 7: { // return to lair
SetLocalInt(oMe,"nRun",TRUE);
SetActionMode(oMe,ACTION_MODE_STEALTH,FALSE);
sS=sID+"_START";
oOb=GetWaypointByTag(sS);
if (GetArea(oMe)!=GetArea(oOb)&&oOb!=OBJECT_INVALID)
{ // move to area
oOb=fnReversePath(GetArea(oMe),oOb,sID,nTravelMethod);
if (GetCurrentAction(oMe)!=ACTION_MOVETOPOINT) AssignCommand(oMe,ActionForceMoveToObject(oOb,TRUE,1.0,120.0));
} // move to area
else
{ // arrived
SetLocalInt(oMe,"nSState",8);
} // arrived
break;
} // return to lair
case 8: { // move near throne
SetLocalInt(oMe,"nRun",TRUE);
SetActionMode(oMe,ACTION_MODE_STEALTH,FALSE);
oOb=GetObjectByTag(sID);
if (oOb!=OBJECT_INVALID)
{ // throne found
if (GetArea(oOb)!=GetArea(oMe)||GetDistanceBetween(oMe,oOb)>2.0)
{ // move
if (GetCurrentAction(oMe)!=ACTION_MOVETOPOINT) AssignCommand(oMe,ActionForceMoveToObject(oOb,TRUE,1.0,120.0));
} // move
else
{ // arrived
SetLocalInt(oMe,"nSState",9);
} // arrived
} // throne found
break;
} // move near throne
case 9: { // place power reservoir
DeleteLocalObject(GetModule(),"oHasPowerRes_"+sID);
oOb=CreateObject(OBJECT_TYPE_PLACEABLE,"plc_phylact001",GetLocation(oMe),FALSE);
oOb=GetItemPossessedBy(oMe,"rts_powerres");
if (oOb!=OBJECT_INVALID) DestroyObject(oOb);
SetLocalInt(oMe,"nSState",0);
AssignCommand(oMe,ActionRest());
break;
} // place power reservoir
default: { SetLocalInt(oMe,"nSState",0); break; }
} // behavior switch
}
////////////////////////////////////////////////////////////////////////// MAIN