690 lines
26 KiB
Plaintext
690 lines
26 KiB
Plaintext
// ai_cpc
|
|
// Control Point Capture
|
|
//-----------------------------------------------------------
|
|
//////////////////////////////////
|
|
// PROTOTYPES
|
|
//////////////////////////////////
|
|
#include "npcact_h_moving"
|
|
object fnFindNearest(object oCP);
|
|
string fnControlPointTag(string sID,int nNum);
|
|
void fnDefaultCaptureMethod(string sID);
|
|
void fnGarrisonCaptureMethod(string sID,int nCount);
|
|
void fnGarrison();
|
|
void fnUnbalancedCaptureMethod(string sID,int nClose,int nFar);
|
|
void fnPatrolCaptureMethod(string sID);
|
|
void fnPatrolGarrisonCaptureMethod(string sID,int nCount);
|
|
void fnFallBackCaptureMethod(string sID,int nCount);
|
|
|
|
////////////////////////////////////////////////////////////////////// MAIN
|
|
void main()
|
|
{
|
|
object oMe=OBJECT_SELF;
|
|
object oMod=GetModule();
|
|
string sID=GetLocalString(oMe,"sTeamID");
|
|
int nMode=GetLocalInt(oMod,"nCaptureStyle_"+sID);
|
|
if (GetLocalInt(oMe,"nGarrisonNum")>0)
|
|
{ // is garrison unit
|
|
fnGarrison();
|
|
return;
|
|
} // is garrison unit
|
|
switch(nMode)
|
|
{ // choose capture method
|
|
case 1:
|
|
{ // Light Garrison
|
|
fnGarrisonCaptureMethod(sID,2);
|
|
break;
|
|
} // Light Garrison
|
|
case 2:
|
|
{ // Medium Garrison
|
|
fnGarrisonCaptureMethod(sID,4);
|
|
break;
|
|
} // Medium Garrison
|
|
case 3:
|
|
{ // Heavy Garrison
|
|
fnGarrisonCaptureMethod(sID,5);
|
|
break;
|
|
} // Heavy Garrison
|
|
case 4:
|
|
{ // Defensive
|
|
fnUnbalancedCaptureMethod(sID,4,2);
|
|
break;
|
|
} // Defensive
|
|
case 5:
|
|
{ // Blockade
|
|
fnUnbalancedCaptureMethod(sID,2,4);
|
|
break;
|
|
} // Blockade
|
|
case 6:
|
|
{ // Patrol
|
|
fnPatrolCaptureMethod(sID);
|
|
break;
|
|
} // Patrol
|
|
case 7:
|
|
{ // Patrol - Light Garrison
|
|
fnPatrolGarrisonCaptureMethod(sID,2);
|
|
break;
|
|
} // Patrol - Light Garrison
|
|
case 8:
|
|
{ // Fall Back Defensive
|
|
fnFallBackCaptureMethod(sID,3);
|
|
break;
|
|
} // Fall Back Defensive
|
|
default:
|
|
{ // default capture method
|
|
fnDefaultCaptureMethod(sID);
|
|
} // default capture method
|
|
} // choose capture method
|
|
}
|
|
////////////////////////////////////////////////////////////////////// MAIN
|
|
|
|
/////////////////////////
|
|
// FUNCTIONS
|
|
/////////////////////////
|
|
|
|
object fnGetGarrison(object oWP,int nNum)
|
|
{ // PURPOSE: Return Garrison
|
|
string sID=GetLocalString(oWP,"sTeamID");
|
|
object oGarrison=GetLocalObject(oWP,"oGarrisonUnit"+sID+IntToString(nNum));
|
|
return oGarrison;
|
|
} // fnGetGarrison()
|
|
|
|
|
|
void fnSetGarrison(object oWP,int nNum,object oUnit)
|
|
{ // PURPOSE: Make oUnit a garrison unit
|
|
string sID=GetLocalString(oWP,"sTeamID");
|
|
SetLocalObject(oWP,"oGarrisonUnit"+sID+IntToString(nNum),oUnit);
|
|
SetLocalObject(oUnit,"oGarrisonPoint",oWP);
|
|
SetLocalInt(oUnit,"nGarrisonNum",nNum);
|
|
} // fnSetGarrison()
|
|
|
|
|
|
void fnFreeGarrison(object oWP,int nNum)
|
|
{ // PURPOSE: Free the garrison unit
|
|
string sID=GetLocalString(oWP,"sTeamID");
|
|
object oGarrison=GetLocalObject(oWP,"oGarrisonUnit"+sID+IntToString(nNum));
|
|
DeleteLocalObject(oWP,"oGarrisonUnit"+sID+IntToString(nNum));
|
|
DeleteLocalObject(oGarrison,"oGarrisonPoint");
|
|
DeleteLocalInt(oGarrison,"nGarrisonNum");
|
|
} // fnFreeGarrison()
|
|
|
|
|
|
void fnNextGarrison(object oWP,object oUnit)
|
|
{ // PURPOSE: Find next garrison slot
|
|
string sID=GetLocalString(oWP,"sTeamID");
|
|
int nNum=1;
|
|
object oGarrison=GetLocalObject(oWP,"oGarrisonUnit"+sID+IntToString(nNum));
|
|
while(GetIsObjectValid(oGarrison))
|
|
{ // look for slot
|
|
nNum++;
|
|
oGarrison=GetLocalObject(oWP,"oGarrisonUnit"+sID+IntToString(nNum));
|
|
} // look for slot
|
|
fnSetGarrison(oWP,nNum,oUnit);
|
|
} // fnNextGarrison()
|
|
|
|
|
|
void fnGarrison()
|
|
{ // PURPOSE: Handle Garrison AI
|
|
object oMe=OBJECT_SELF;
|
|
object oWP=GetLocalObject(oMe,"oGarrisonPoint");
|
|
int nMax=GetLocalInt(oWP,"nGarrisonMax"+GetLocalString(oMe,"sTeamID"));
|
|
int nNum=GetLocalInt(oMe,"nGarrisonNum");
|
|
if (nMax<nNum)
|
|
{ // no longer garrison
|
|
fnFreeGarrison(oWP,nNum);
|
|
} // no longer garrison
|
|
else if (GetArea(oWP)!=GetArea(oMe))
|
|
{ // move to garrison point at all cost
|
|
if (GetIsInCombat(oMe)) AssignCommand(oMe,ClearAllActions(TRUE));
|
|
if (!IsInConversation(oMe)&&!GetIsDMPossessed(oMe))
|
|
{ // run
|
|
object oDest=fnFindNearest(oWP);
|
|
fnMoveToDestination(oMe,oWP,2.0);
|
|
} // run
|
|
} // move to garrison point at all cost
|
|
else if (!GetIsInCombat(oMe)&&!IsInConversation(oMe)&&!GetIsDMPossessed(oMe))
|
|
{ // okay to move
|
|
if (GetDistanceBetween(oMe,oWP)>5.0)
|
|
{ // Move
|
|
fnMoveToDestination(oMe,oWP,3.0);
|
|
} // Move
|
|
} // okay to move
|
|
} // fnGarrison()
|
|
|
|
|
|
void fnUnbalancedCaptureMethod(string sID,int nClose,int nFar)
|
|
{ // PURPOSE: Handle the default capture method
|
|
object oMe=OBJECT_SELF;
|
|
object oCP;
|
|
string sCP1;
|
|
string sCP2;
|
|
string sCP3;
|
|
string sCP4;
|
|
object oCP1;
|
|
object oCP2;
|
|
object oCP3;
|
|
object oCP4;
|
|
object oDest=GetLocalObject(oMe,"oDest");
|
|
float fDist;
|
|
int nCount;
|
|
sCP1=fnControlPointTag(sID,1);
|
|
sCP2=fnControlPointTag(sID,2);
|
|
sCP3=fnControlPointTag(sID,3);
|
|
sCP4=fnControlPointTag(sID,4);
|
|
oCP1=GetWaypointByTag(sCP1);
|
|
oCP2=GetWaypointByTag(sCP2);
|
|
oCP3=GetWaypointByTag(sCP3);
|
|
oCP4=GetWaypointByTag(sCP4);
|
|
oCP=OBJECT_INVALID;
|
|
if (oCP1!=OBJECT_INVALID&&GetLocalString(oCP1,"sTeamID")!=sID) { oCP=oCP1; nCount=nClose;}
|
|
else if (oCP2!=OBJECT_INVALID&&GetLocalString(oCP2,"sTeamID")!=sID) { oCP=oCP2; nCount=nClose; }
|
|
else if (oCP3!=OBJECT_INVALID&&GetLocalString(oCP3,"sTeamID")!=sID) { oCP=oCP3; nCount=nFar; }
|
|
else if (oCP4!=OBJECT_INVALID&&GetLocalString(oCP4,"sTeamID")!=sID) { oCP=oCP4; nCount=nFar; }
|
|
if (oCP!=OBJECT_INVALID)
|
|
{ // target control point chosen
|
|
oDest=fnFindNearest(oCP);
|
|
if (GetArea(oCP)==GetArea(oMe)) oDest=oCP;
|
|
fDist=GetDistanceBetween(oMe,oDest);
|
|
if (oDest!=OBJECT_INVALID&&(GetArea(oDest)!=GetArea(oMe)||fDist>3.0))
|
|
{ // move
|
|
fnMoveToDestination(oMe,oDest,1.0);
|
|
} // move
|
|
SetLocalInt(oCP,"nGarrisonMax"+sID,nCount);
|
|
if (GetArea(oCP)==GetArea(oMe))
|
|
{ // set garrisons if need be
|
|
int nL=1;
|
|
object oGarrison=fnGetGarrison(oCP,nL);
|
|
while(nL<=nCount)
|
|
{ // check each garrison slot
|
|
if (!GetIsObjectValid(oGarrison))
|
|
{ // allocate to this slot
|
|
fnSetGarrison(oCP,nL,oMe);
|
|
nL=nCount+5;// break out of loop
|
|
} // allocate to this slot
|
|
nL++;
|
|
oGarrison=fnGetGarrison(oCP,nL);
|
|
} // check each garrison slot
|
|
} // set garrisons if need be
|
|
} // target control point chosen
|
|
else
|
|
{ // set all garrisons
|
|
SetLocalInt(oCP1,"nGarrisonMax"+sID,nClose);
|
|
SetLocalInt(oCP2,"nGarrisonMax"+sID,nClose);
|
|
SetLocalInt(oCP3,"nGarrisonMax"+sID,nFar);
|
|
SetLocalInt(oCP4,"nGarrisonMax"+sID,nFar);
|
|
if (GetLocalString(oCP1,"sTeamID")==sID&&!GetIsObjectValid(fnGetGarrison(oCP1,nClose)))
|
|
{ // room for garrison
|
|
fnNextGarrison(oCP1,oMe);
|
|
} // room for garrison
|
|
else if (GetLocalString(oCP2,"sTeamID")==sID&&!GetIsObjectValid(fnGetGarrison(oCP2,nClose)))
|
|
{ // room for garrison
|
|
fnNextGarrison(oCP2,oMe);
|
|
} // room for garrison
|
|
else if (GetLocalString(oCP3,"sTeamID")==sID&&!GetIsObjectValid(fnGetGarrison(oCP3,nFar)))
|
|
{ // room for garrison
|
|
fnNextGarrison(oCP3,oMe);
|
|
} // room for garrison
|
|
else if (GetLocalString(oCP4,"sTeamID")==sID&&!GetIsObjectValid(fnGetGarrison(oCP4,nFar)))
|
|
{ // room for garrison
|
|
fnNextGarrison(oCP4,oMe);
|
|
} // room for garrison
|
|
} // set all garrisons
|
|
} // fnUnbalancedCaptureMethod()
|
|
|
|
|
|
void fnGarrisonCaptureMethod(string sID,int nCount)
|
|
{ // PURPOSE: Handle the default capture method
|
|
object oMe=OBJECT_SELF;
|
|
object oCP;
|
|
string sCP1;
|
|
string sCP2;
|
|
string sCP3;
|
|
string sCP4;
|
|
object oCP1;
|
|
object oCP2;
|
|
object oCP3;
|
|
object oCP4;
|
|
object oDest=GetLocalObject(oMe,"oDest");
|
|
float fDist;
|
|
sCP1=fnControlPointTag(sID,1);
|
|
sCP2=fnControlPointTag(sID,2);
|
|
sCP3=fnControlPointTag(sID,3);
|
|
sCP4=fnControlPointTag(sID,4);
|
|
oCP1=GetWaypointByTag(sCP1);
|
|
oCP2=GetWaypointByTag(sCP2);
|
|
oCP3=GetWaypointByTag(sCP3);
|
|
oCP4=GetWaypointByTag(sCP4);
|
|
oCP=OBJECT_INVALID;
|
|
if (oCP1!=OBJECT_INVALID&&GetLocalString(oCP1,"sTeamID")!=sID) oCP=oCP1;
|
|
else if (oCP2!=OBJECT_INVALID&&GetLocalString(oCP2,"sTeamID")!=sID) oCP=oCP2;
|
|
else if (oCP3!=OBJECT_INVALID&&GetLocalString(oCP3,"sTeamID")!=sID) oCP=oCP3;
|
|
else if (oCP4!=OBJECT_INVALID&&GetLocalString(oCP4,"sTeamID")!=sID) oCP=oCP4;
|
|
if (oCP!=OBJECT_INVALID)
|
|
{ // target control point chosen
|
|
oDest=fnFindNearest(oCP);
|
|
if (GetArea(oCP)==GetArea(oMe)) oDest=oCP;
|
|
fDist=GetDistanceBetween(oMe,oDest);
|
|
if (oDest!=OBJECT_INVALID&&(GetArea(oDest)!=GetArea(oMe)||fDist>3.0))
|
|
{ // move
|
|
fnMoveToDestination(oMe,oDest,1.0);
|
|
} // move
|
|
SetLocalInt(oCP,"nGarrisonMax"+sID,nCount);
|
|
if (GetArea(oCP)==GetArea(oMe))
|
|
{ // set garrisons if need be
|
|
int nL=1;
|
|
object oGarrison=fnGetGarrison(oCP,nL);
|
|
while(nL<=nCount)
|
|
{ // check each garrison slot
|
|
if (!GetIsObjectValid(oGarrison))
|
|
{ // allocate to this slot
|
|
fnSetGarrison(oCP,nL,oMe);
|
|
nL=nCount+5;// break out of loop
|
|
} // allocate to this slot
|
|
nL++;
|
|
oGarrison=fnGetGarrison(oCP,nL);
|
|
} // check each garrison slot
|
|
} // set garrisons if need be
|
|
} // target control point chosen
|
|
else
|
|
{ // set all garrisons
|
|
SetLocalInt(oCP1,"nGarrisonMax"+sID,nCount);
|
|
SetLocalInt(oCP2,"nGarrisonMax"+sID,nCount);
|
|
SetLocalInt(oCP3,"nGarrisonMax"+sID,nCount);
|
|
SetLocalInt(oCP4,"nGarrisonMax"+sID,nCount);
|
|
if (GetLocalString(oCP1,"sTeamID")==sID&&!GetIsObjectValid(fnGetGarrison(oCP1,nCount)))
|
|
{ // room for garrison
|
|
fnNextGarrison(oCP1,oMe);
|
|
} // room for garrison
|
|
else if (GetLocalString(oCP2,"sTeamID")==sID&&!GetIsObjectValid(fnGetGarrison(oCP2,nCount)))
|
|
{ // room for garrison
|
|
fnNextGarrison(oCP2,oMe);
|
|
} // room for garrison
|
|
else if (GetLocalString(oCP3,"sTeamID")==sID&&!GetIsObjectValid(fnGetGarrison(oCP3,nCount)))
|
|
{ // room for garrison
|
|
fnNextGarrison(oCP3,oMe);
|
|
} // room for garrison
|
|
else if (GetLocalString(oCP4,"sTeamID")==sID&&!GetIsObjectValid(fnGetGarrison(oCP4,nCount)))
|
|
{ // room for garrison
|
|
fnNextGarrison(oCP4,oMe);
|
|
} // room for garrison
|
|
} // set all garrisons
|
|
} // fnGarrisonCaptureMethod()
|
|
|
|
|
|
void fnFallBackCaptureMethod(string sID,int nCount)
|
|
{ // PURPOSE: Handle the default capture method
|
|
object oMe=OBJECT_SELF;
|
|
object oCP;
|
|
string sCP1;
|
|
string sCP2;
|
|
string sCP3;
|
|
string sCP4;
|
|
object oCP1;
|
|
object oCP2;
|
|
object oCP3;
|
|
object oCP4;
|
|
object oDest=GetLocalObject(oMe,"oDest");
|
|
float fDist;
|
|
sCP1=fnControlPointTag(sID,1);
|
|
sCP2=fnControlPointTag(sID,2);
|
|
sCP3=fnControlPointTag(sID,3);
|
|
sCP4=fnControlPointTag(sID,4);
|
|
oCP1=GetWaypointByTag(sCP1);
|
|
oCP2=GetWaypointByTag(sCP2);
|
|
oCP3=GetWaypointByTag(sCP3);
|
|
oCP4=GetWaypointByTag(sCP4);
|
|
SetLocalInt(oCP3,"nGarrisonMax"+sID,0);
|
|
SetLocalInt(oCP4,"nGarrisonMax"+sID,0);
|
|
oCP=OBJECT_INVALID;
|
|
if (oCP1!=OBJECT_INVALID&&GetLocalString(oCP1,"sTeamID")!=sID) oCP=oCP1;
|
|
else if (oCP2!=OBJECT_INVALID&&GetLocalString(oCP2,"sTeamID")!=sID) oCP=oCP2;
|
|
if (oCP!=OBJECT_INVALID)
|
|
{ // target control point chosen
|
|
DeleteLocalInt(oMe,"nPatrol");
|
|
oDest=fnFindNearest(oCP);
|
|
if (GetArea(oCP)==GetArea(oMe)) oDest=oCP;
|
|
fDist=GetDistanceBetween(oMe,oDest);
|
|
if (oDest!=OBJECT_INVALID&&(GetArea(oDest)!=GetArea(oMe)||fDist>3.0))
|
|
{ // move
|
|
fnMoveToDestination(oMe,oDest,1.0);
|
|
} // move
|
|
SetLocalInt(oCP,"nGarrisonMax"+sID,nCount);
|
|
if (GetArea(oCP)==GetArea(oMe))
|
|
{ // set garrisons if need be
|
|
int nL=1;
|
|
object oGarrison=fnGetGarrison(oCP,nL);
|
|
while(nL<=nCount)
|
|
{ // check each garrison slot
|
|
if (!GetIsObjectValid(oGarrison))
|
|
{ // allocate to this slot
|
|
fnSetGarrison(oCP,nL,oMe);
|
|
nL=nCount+5;// break out of loop
|
|
} // allocate to this slot
|
|
nL++;
|
|
oGarrison=fnGetGarrison(oCP,nL);
|
|
} // check each garrison slot
|
|
} // set garrisons if need be
|
|
} // target control point chosen
|
|
else
|
|
{ // pick patrol target
|
|
int nPatrol=GetLocalInt(oMe,"nPatrol");
|
|
if (nPatrol==0) { SetLocalInt(oMe,"nPatrol",1); oCP=oCP1; }
|
|
if (nPatrol==1) oCP=oCP1;
|
|
else if (nPatrol==2) oCP=oCP2;
|
|
if (GetIsObjectValid(oCP))
|
|
{ // patrol point exists
|
|
oDest=fnFindNearest(oCP);
|
|
if (GetArea(oCP)==GetArea(oMe)) oDest=oCP;
|
|
if (GetIsObjectValid(oDest)&&(GetArea(oDest)!=GetArea(oMe)||GetDistanceBetween(oMe,oDest)>5.0))
|
|
{ // move
|
|
fnMoveToDestination(oMe,oDest,4.0);
|
|
} // move
|
|
else if (GetArea(oCP)==GetArea(oMe)&&GetDistanceBetween(oMe,oCP)<6.0)
|
|
{ // pick next patrol
|
|
nPatrol++;
|
|
if (nPatrol>2) nPatrol=1;
|
|
SetLocalInt(oMe,"nPatrol",nPatrol);
|
|
} // pick next patrol
|
|
} // patrol point exists
|
|
} // pcik patrol target
|
|
} // fnFallBackCaptureMethod()
|
|
|
|
|
|
void fnPatrolGarrisonCaptureMethod(string sID,int nCount)
|
|
{ // PURPOSE: Handle the default capture method
|
|
object oMe=OBJECT_SELF;
|
|
object oCP;
|
|
string sCP1;
|
|
string sCP2;
|
|
string sCP3;
|
|
string sCP4;
|
|
object oCP1;
|
|
object oCP2;
|
|
object oCP3;
|
|
object oCP4;
|
|
object oDest=GetLocalObject(oMe,"oDest");
|
|
float fDist;
|
|
sCP1=fnControlPointTag(sID,1);
|
|
sCP2=fnControlPointTag(sID,2);
|
|
sCP3=fnControlPointTag(sID,3);
|
|
sCP4=fnControlPointTag(sID,4);
|
|
oCP1=GetWaypointByTag(sCP1);
|
|
oCP2=GetWaypointByTag(sCP2);
|
|
oCP3=GetWaypointByTag(sCP3);
|
|
oCP4=GetWaypointByTag(sCP4);
|
|
oCP=OBJECT_INVALID;
|
|
if (oCP1!=OBJECT_INVALID&&GetLocalString(oCP1,"sTeamID")!=sID) oCP=oCP1;
|
|
else if (oCP2!=OBJECT_INVALID&&GetLocalString(oCP2,"sTeamID")!=sID) oCP=oCP2;
|
|
else if (oCP3!=OBJECT_INVALID&&GetLocalString(oCP3,"sTeamID")!=sID) oCP=oCP3;
|
|
else if (oCP4!=OBJECT_INVALID&&GetLocalString(oCP4,"sTeamID")!=sID) oCP=oCP4;
|
|
if (oCP!=OBJECT_INVALID)
|
|
{ // target control point chosen
|
|
DeleteLocalInt(oMe,"nPatrol");
|
|
oDest=fnFindNearest(oCP);
|
|
if (GetArea(oCP)==GetArea(oMe)) oDest=oCP;
|
|
fDist=GetDistanceBetween(oMe,oDest);
|
|
if (oDest!=OBJECT_INVALID&&(GetArea(oDest)!=GetArea(oMe)||fDist>3.0))
|
|
{ // move
|
|
fnMoveToDestination(oMe,oDest,1.0);
|
|
} // move
|
|
SetLocalInt(oCP,"nGarrisonMax"+sID,nCount);
|
|
if (GetArea(oCP)==GetArea(oMe))
|
|
{ // set garrisons if need be
|
|
int nL=1;
|
|
object oGarrison=fnGetGarrison(oCP,nL);
|
|
while(nL<=nCount)
|
|
{ // check each garrison slot
|
|
if (!GetIsObjectValid(oGarrison))
|
|
{ // allocate to this slot
|
|
fnSetGarrison(oCP,nL,oMe);
|
|
nL=nCount+5;// break out of loop
|
|
} // allocate to this slot
|
|
nL++;
|
|
oGarrison=fnGetGarrison(oCP,nL);
|
|
} // check each garrison slot
|
|
} // set garrisons if need be
|
|
} // target control point chosen
|
|
else
|
|
{ // pick patrol target
|
|
int nPatrol=GetLocalInt(oMe,"nPatrol");
|
|
if (nPatrol==0) { SetLocalInt(oMe,"nPatrol",1); oCP=oCP1; }
|
|
if (nPatrol==1) oCP=oCP1;
|
|
else if (nPatrol==2) oCP=oCP2;
|
|
else if (nPatrol==3) oCP=oCP3;
|
|
else if (nPatrol==4) oCP=oCP4;
|
|
if (GetIsObjectValid(oCP))
|
|
{ // patrol point exists
|
|
oDest=fnFindNearest(oCP);
|
|
if (GetArea(oCP)==GetArea(oMe)) oDest=oCP;
|
|
if (GetIsObjectValid(oDest)&&(GetArea(oDest)!=GetArea(oMe)||GetDistanceBetween(oMe,oDest)>5.0))
|
|
{ // move
|
|
fnMoveToDestination(oMe,oDest,4.0);
|
|
} // move
|
|
else if (GetArea(oCP)==GetArea(oMe)&&GetDistanceBetween(oMe,oCP)<6.0)
|
|
{ // pick next patrol
|
|
nPatrol++;
|
|
if (nPatrol>4) nPatrol=1;
|
|
SetLocalInt(oMe,"nPatrol",nPatrol);
|
|
} // pick next patrol
|
|
} // patrol point exists
|
|
} // pcik patrol target
|
|
} // fnPatrolGarrisonCaptureMethod()
|
|
|
|
|
|
void fnPatrolCaptureMethod(string sID)
|
|
{ // PURPOSE: Handle the patrol capture method
|
|
object oMe=OBJECT_SELF;
|
|
object oCP;
|
|
string sCP1;
|
|
string sCP2;
|
|
string sCP3;
|
|
string sCP4;
|
|
object oCP1;
|
|
object oCP2;
|
|
object oCP3;
|
|
object oCP4;
|
|
object oDest=GetLocalObject(oMe,"oDest");
|
|
float fDist;
|
|
sCP1=fnControlPointTag(sID,1);
|
|
sCP2=fnControlPointTag(sID,2);
|
|
sCP3=fnControlPointTag(sID,3);
|
|
sCP4=fnControlPointTag(sID,4);
|
|
oCP1=GetWaypointByTag(sCP1);
|
|
oCP2=GetWaypointByTag(sCP2);
|
|
oCP3=GetWaypointByTag(sCP3);
|
|
oCP4=GetWaypointByTag(sCP4);
|
|
oCP=OBJECT_INVALID;
|
|
if (oCP1!=OBJECT_INVALID&&GetLocalString(oCP1,"sTeamID")!=sID) oCP=oCP1;
|
|
else if (oCP2!=OBJECT_INVALID&&GetLocalString(oCP2,"sTeamID")!=sID) oCP=oCP2;
|
|
else if (oCP3!=OBJECT_INVALID&&GetLocalString(oCP3,"sTeamID")!=sID) oCP=oCP3;
|
|
else if (oCP4!=OBJECT_INVALID&&GetLocalString(oCP4,"sTeamID")!=sID) oCP=oCP4;
|
|
if (oCP!=OBJECT_INVALID)
|
|
{ // target control point chosen
|
|
DeleteLocalInt(oMe,"nPatrol");
|
|
oDest=fnFindNearest(oCP);
|
|
if (GetArea(oCP)==GetArea(oMe)) oDest=oCP;
|
|
fDist=GetDistanceBetween(oMe,oDest);
|
|
if (oDest!=OBJECT_INVALID&&(GetArea(oDest)!=GetArea(oMe)||fDist>3.0))
|
|
{ // move
|
|
fnMoveToDestination(oMe,oDest,1.0);
|
|
} // move
|
|
} // target control point chosen
|
|
else
|
|
{ // pick patrol target
|
|
int nPatrol=GetLocalInt(oMe,"nPatrol");
|
|
if (nPatrol==0) { SetLocalInt(oMe,"nPatrol",1); oCP=oCP1; }
|
|
if (nPatrol==1) oCP=oCP1;
|
|
else if (nPatrol==2) oCP=oCP2;
|
|
else if (nPatrol==3) oCP=oCP3;
|
|
else if (nPatrol==4) oCP=oCP4;
|
|
DeleteLocalInt(oCP,"nGarrisonMax"+sID);
|
|
if (GetIsObjectValid(oCP))
|
|
{ // patrol point exists
|
|
oDest=fnFindNearest(oCP);
|
|
if (GetArea(oCP)==GetArea(oMe)) oDest=oCP;
|
|
if (GetIsObjectValid(oDest)&&(GetArea(oDest)!=GetArea(oMe)||GetDistanceBetween(oMe,oDest)>5.0))
|
|
{ // move
|
|
fnMoveToDestination(oMe,oDest,4.0);
|
|
} // move
|
|
else if (GetArea(oCP)==GetArea(oMe)&&GetDistanceBetween(oMe,oCP)<6.0)
|
|
{ // pick next patrol
|
|
nPatrol++;
|
|
if (nPatrol>4) nPatrol=1;
|
|
SetLocalInt(oMe,"nPatrol",nPatrol);
|
|
} // pick next patrol
|
|
} // patrol point exists
|
|
} // pcik patrol target
|
|
} // fnPatrolCaptureMethod()
|
|
|
|
|
|
void fnDefaultCaptureMethod(string sID)
|
|
{ // PURPOSE: Handle the default capture method
|
|
object oMe=OBJECT_SELF;
|
|
object oCP;
|
|
string sCP1;
|
|
string sCP2;
|
|
string sCP3;
|
|
string sCP4;
|
|
object oCP1;
|
|
object oCP2;
|
|
object oCP3;
|
|
object oCP4;
|
|
object oDest=GetLocalObject(oMe,"oDest");
|
|
float fDist;
|
|
sCP1=fnControlPointTag(sID,1);
|
|
sCP2=fnControlPointTag(sID,2);
|
|
sCP3=fnControlPointTag(sID,3);
|
|
sCP4=fnControlPointTag(sID,4);
|
|
oCP1=GetWaypointByTag(sCP1);
|
|
oCP2=GetWaypointByTag(sCP2);
|
|
oCP3=GetWaypointByTag(sCP3);
|
|
oCP4=GetWaypointByTag(sCP4);
|
|
oCP=OBJECT_INVALID;
|
|
if (oCP1!=OBJECT_INVALID&&GetLocalString(oCP1,"sTeamID")!=sID) oCP=oCP1;
|
|
else if (oCP2!=OBJECT_INVALID&&GetLocalString(oCP2,"sTeamID")!=sID) oCP=oCP2;
|
|
else if (oCP3!=OBJECT_INVALID&&GetLocalString(oCP3,"sTeamID")!=sID) oCP=oCP3;
|
|
else if (oCP4!=OBJECT_INVALID&&GetLocalString(oCP4,"sTeamID")!=sID) oCP=oCP4;
|
|
if (oCP!=OBJECT_INVALID)
|
|
{ // target control point chosen
|
|
DeleteLocalInt(oCP,"nGarrisonMax"+sID);
|
|
oDest=fnFindNearest(oCP);
|
|
if (GetArea(oCP)==GetArea(oMe)) oDest=oCP;
|
|
fDist=GetDistanceBetween(oMe,oDest);
|
|
if (oDest!=OBJECT_INVALID&&(GetArea(oDest)!=GetArea(oMe)||fDist>3.0))
|
|
{ // move
|
|
fnMoveToDestination(oMe,oDest,1.0);
|
|
} // move
|
|
} // target control point chosen
|
|
} // fnDefaultCaptureMethod()
|
|
|
|
|
|
string fnControlPointTag(string sID,int nNum)
|
|
{ // PURPOSE: Return the tag for the control point nNum 1-4 for the team sID
|
|
if (sID=="SPID")
|
|
{ // spider cultists
|
|
if (nNum==1) return "CONTROL_POINT3";
|
|
else if (nNum==2) return "CONTROL_POINT1";
|
|
else if (nNum==3) return "CONTROL_POINT4";
|
|
else if (nNum==4) return "CONTROL_POINT2";
|
|
} // spider cultists
|
|
else if (sID=="DWF")
|
|
{ // dwarves
|
|
if (nNum==1) return "CONTROL_POINT2";
|
|
else if (nNum==2) return "CONTROL_POINT4";
|
|
else if (nNum==3) return "CONTROL_POINT1";
|
|
else if (nNum==4) return "CONTROL_POINT3";
|
|
} // dwarves
|
|
else if (sID=="UNC")
|
|
{ // Unclean
|
|
if (nNum==1) return "CONTROL_POINT1";
|
|
else if (nNum==2) return "CONTROL_POINT2";
|
|
else if (nNum==3) return "CONTROL_POINT4";
|
|
else if (nNum==4) return "CONTROL_POINT3";
|
|
} // Unclean
|
|
else if (sID=="UND")
|
|
{ // Undead
|
|
if (nNum==1) return "CONTROL_POINT4";
|
|
else if (nNum==2) return "CONTROL_POINT3";
|
|
else if (nNum==3) return "CONTROL_POINT2";
|
|
else if (nNum==4) return "CONTROL_POINT1";
|
|
} // Undead
|
|
return "";
|
|
} // fnControlPointTag()
|
|
|
|
|
|
|
|
string fnFindAIPathNear(object oNear)
|
|
{ // find AI path near
|
|
if (GetNearestObjectByTag("AIPATH11",oNear,1)!=OBJECT_INVALID) return "AIPATH11";
|
|
else if (GetNearestObjectByTag("AIPATH21",oNear,1)!=OBJECT_INVALID) return "AIPATH21";
|
|
else if (GetNearestObjectByTag("AIPATH31",oNear,1)!=OBJECT_INVALID) return "AIPATH31";
|
|
else if (GetNearestObjectByTag("AIPATH12",oNear,1)!=OBJECT_INVALID) return "AIPATH12";
|
|
else if (GetNearestObjectByTag("AIPATH32",oNear,1)!=OBJECT_INVALID) return "AIPATH32";
|
|
else if (GetNearestObjectByTag("AIPATH13",oNear,1)!=OBJECT_INVALID) return "AIPATH13";
|
|
else if (GetNearestObjectByTag("AIPATH23",oNear,1)!=OBJECT_INVALID) return "AIPATH23";
|
|
else if (GetNearestObjectByTag("AIPATH33",oNear,1)!=OBJECT_INVALID) return "AIPATH33";
|
|
return "NA";
|
|
} // fnFindAIPathNear()
|
|
|
|
object fnFindNearest(object oCP)
|
|
{ // return next destination
|
|
object oMe=OBJECT_SELF;
|
|
object oThisArea;
|
|
object oNext;
|
|
string sTag;
|
|
string sTagNCP;
|
|
string sTagNMe;
|
|
string sID=GetLocalString(oMe,"sTeamID");
|
|
if (GetArea(oCP)==GetArea(oMe)) return oCP;
|
|
else
|
|
{ // not in the same area
|
|
if (GetNearestObjectByTag(sID+"_START",oMe,1)!=OBJECT_INVALID)
|
|
{ // I'm in my lair
|
|
if (sID=="SPID") sTag="AIPATH32";
|
|
else if (sID=="UNC") sTag="AIPATH21";
|
|
else if (sID=="UND") sTag="AIPATH23";
|
|
else if (sID=="DWF") sTag="AIPATH12";
|
|
oNext=GetWaypointByTag(sTag);
|
|
if (oNext!=OBJECT_INVALID) return oNext;
|
|
} // I'm in my lair
|
|
else
|
|
{ // outside
|
|
sTagNCP=fnFindAIPathNear(oCP);
|
|
sTagNMe=fnFindAIPathNear(oMe);
|
|
sTag="NA";
|
|
if (sTagNCP=="AIPATH11"&&sTagNMe=="AIPATH21") sTag=GetTag(oCP);
|
|
else if (sTagNCP=="AIPATH11"&&sTagNMe=="AIPATH31") sTag="AIPATH21";
|
|
else if (sTagNCP=="AIPATH11"&&sTagNMe=="AIPATH12") sTag=GetTag(oCP);
|
|
else if (sTagNCP=="AIPATH11"&&sTagNMe=="AIPATH32") sTag="AIPATH31";
|
|
else if (sTagNCP=="AIPATH11"&&sTagNMe=="AIPATH13") sTag="AIPATH12";
|
|
else if (sTagNCP=="AIPATH11"&&sTagNMe=="AIPATH23") sTag="AIPATH13";
|
|
else if (sTagNCP=="AIPATH11"&&sTagNMe=="AIPATH33") sTag="AIPATH23";
|
|
else if (sTagNCP=="AIPATH13"&&sTagNMe=="AIPATH11") sTag="AIPATH12";
|
|
else if (sTagNCP=="AIPATH13"&&sTagNMe=="AIPATH21") sTag="AIPATH11";
|
|
else if (sTagNCP=="AIPATH13"&&sTagNMe=="AIPATH31") sTag="AIPATH21";
|
|
else if (sTagNCP=="AIPATH13"&&sTagNMe=="AIPATH12") sTag=GetTag(oCP);
|
|
else if (sTagNCP=="AIPATH13"&&sTagNMe=="AIPATH32") sTag="AIPATH33";
|
|
else if (sTagNCP=="AIPATH13"&&sTagNMe=="AIPATH23") sTag=GetTag(oCP);
|
|
else if (sTagNCP=="AIPATH13"&&sTagNMe=="AIPATH33") sTag="AIPATH23";
|
|
else if (sTagNCP=="AIPATH31"&&sTagNMe=="AIPATH11") sTag="AIPATH21";
|
|
else if (sTagNCP=="AIPATH31"&&sTagNMe=="AIPATH21") sTag=GetTag(oCP);
|
|
else if (sTagNCP=="AIPATH31"&&sTagNMe=="AIPATH12") sTag="AIPATH11";
|
|
else if (sTagNCP=="AIPATH31"&&sTagNMe=="AIPATH32") sTag=GetTag(oCP);
|
|
else if (sTagNCP=="AIPATH31"&&sTagNMe=="AIPATH13") sTag="AIPATH12";
|
|
else if (sTagNCP=="AIPATH31"&&sTagNMe=="AIPATH23") sTag="AIPATH33";
|
|
else if (sTagNCP=="AIPATH31"&&sTagNMe=="AIPATH33") sTag="AIPATH32";
|
|
else if (sTagNCP=="AIPATH33"&&sTagNMe=="AIPATH11") sTag="AIPATH21";
|
|
else if (sTagNCP=="AIPATH33"&&sTagNMe=="AIPATH21") sTag="AIPATH31";
|
|
else if (sTagNCP=="AIPATH33"&&sTagNMe=="AIPATH31") sTag="AIPATH32";
|
|
else if (sTagNCP=="AIPATH33"&&sTagNMe=="AIPATH12") sTag="AIPATH13";
|
|
else if (sTagNCP=="AIPATH33"&&sTagNMe=="AIPATH32") sTag=GetTag(oCP);
|
|
else if (sTagNCP=="AIPATH33"&&sTagNMe=="AIPATH13") sTag="AIPATH23";
|
|
else if (sTagNCP=="AIPATH33"&&sTagNMe=="AIPATH23") sTag=GetTag(oCP);
|
|
if (sTag=="NA") sTag=GetTag(oCP);
|
|
oNext=GetWaypointByTag(sTag);
|
|
//if (GetIsPC(GetLocalObject(GetModule(),"oTeamLead"+sID))) SendMessageToPC(GetFirstPC(),"TAG:"+GetTag(oNext)+" AREA:"+GetName(GetArea(oNext)));
|
|
if (oNext!=OBJECT_INVALID) return oNext;
|
|
} // outside
|
|
} // not in the same area
|
|
return OBJECT_INVALID;
|
|
} // fnFindNearest()
|