Author Topic: Patrol/Movement brain not responding to fire, any elegant solution?  (Read 6 times)

0 Members and 2 Guests are viewing this topic.

Patrol/Movement brain not responding to fire, any elegant solution?
Hello potentially dead forum,

I am having an issue with a mission I am working on. I have a mission brain set up to change the warrior brain of a bunch of mechs and vehicles to a patrol brain to move toward a base when you either (a) capture the base HQ or (b) approach the starting point of the relevant vehicles (will probably also add (c) when the base defenders are all destroyed). The movement part is working for both conditions currently implemented, however, when you attack this force en route to the base it does not respond to fire and does not return fire.

Unless I figure out a more elegant solution, I will probably just set them to have an escort brain targeting a Mobile HQ or similar, non-combat vehicle, have a wide scan range to ensure they are ahead of it if the player mechs approach, and just set the movement brain to the Mobile HQ (or whatever).

I have tried the original approach with both a basic patrol brain derived from the original MC2 warrior brains, and one using the universal warrior brain and both have the same problem. Not really a strong coder so if anyone knows of a more elegant solution in .abl I am all ears, otherwise just gonna move ahead with this.

FWIW here is the patrol brain from my most recent attempt:
Code: [Select]
//****************************************************************************************//
//
// Universal Warrior Brain for Mech Commander Omnitech
//****************************************************************************************//

//[EDIT]
fsm rs_1_7_Reinforcements; //EACH BRAIN MUST HAVE AN UNIQUE FSM ID..
//[EDIT END]


var

static WorldPosition startPosition;
static PatrolState PState;
static PatrolPath PPath;
static boolean willRequestHelp;
static real lastHelpRequestTime;
static real helpRequestFrequency;
static integer AttackStateHandle;
static boolean poweredDown;
static boolean powerUp;
//static boolean been_hit;  //use this if powered down and you want to power up when hit.
//static boolean All_power; //use this if powered down and you want to power up all mates on this unit power-up.
static integer scanRange;
static WorldPosition MovePoint;
static integer escortSquadID;
static integer[20] moverList;
static real escortRange;
static boolean IsEscortUnitDead;
static worldPosition guardSpot;

static integer Orders1; //declare here for control in this file or declare in main mission.abl as eternal boolean for control from there.
//****************************************************************************************

function init;

    code


//[EDIT]
//********************************************************************
// Scan Ranges for Unit
scanRange = 500;

//********************************************************************
// Patrol brain part
// Patrol STATE
PState[0] = 0;    // This is the Type of Patrol. 0 = Linear. 1 = Looping
//(Linear = Unit will move from 1 to 2 to 3, then 3 to 2 to 1) Assuming there are only 3 points to the Patrol
//(Looping = Unit will move from 1 to 2 to 3, then 1 to 2 to 3) Assuming there are only 3 points to the Patrol
PState[1] = 9;    //This is the Amount of Move Points there are listed below. Make sure you Count Patrol Point '0'
PState[2] = 1;    //This is How many Times the unit will perform the Patrol.. (-1 = Forever).

// Patrol Points below

//Enter the Coordinates of where you want the Unit to Patrol. It will do them in Order Start from 0 and ending at the Last Point
//Make sure you change the Index number (numbers in Brackets [0, 0] to match the correct Patrol Point.
//Also, the number of Mover Points MUST match the number you have entered in the Patrol State.

PPath[0, 0] = 2624; //X coordinate found in the editor
PPath[0, 1] = -4160; //Y coordinate found in the editor
PPath[1, 0] = 448;
PPath[1, 1] = -4160;
PPath[2, 0] = 192;
PPath[2, 1] = -832;
PPath[3, 0] = -2624;
PPath[3, 1] = 2752;
PPath[4, 0] = -3136;
PPath[4, 1] = 2752;
PPath[5, 0] = -3136;
PPath[5, 1] = 3392;
PPath[6, 0] = -3392;
PPath[6, 1] = 3392;
PPath[7, 0] = -3392;
PPath[7, 1] = -1088;
PPath[8, 0] = -2624;
PPath[8, 1] = -2624;

PState[3] = PATROL_DIRECTION_FORWARD;   
PState[4] = -1;    //reset cur point
PState[5] = -1;    //reset cur cycle
PState[6] = CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED;
//********************************************************************
// Escort brain part
// Unit ID to escort
escortSquadID = 2; //This is the Squad ID (Found in editor) for the unit you want to escort
escortRange = 250.0; //How far the escorting unit will drift


// Guard Location if escortee is dead
guardSpot[0] = -704; //The X Coordinate (Found in the editor) is the area this Unit will Guard if the Unit it is suppose to Escort is destroyed
guardSpot[1] = 4842; //The Y Coordinate (Found in the editor) is the area this Unit will Guard if the Unit it is suppose to Escort is destroyed
guardSpot[2] = 0;

IsEscortUnitDead = False;
getUnitMates(escortSquadID, moverList);
//********************************************************************

// Grab his start position...
getObjectPosition(-1, startPosition);
setTargetPriority(0, TARGET_PRIORITY_CURTARGET, -1, 150, CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED);
setTargetPriority(1, TARGET_PRIORITY_MOVER, 0, scanRange, CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED);
setTargetPriority(2, TARGET_PRIORITY_NONE, 0, 0, 0);
AttackStateHandle = getStateHandle("attack");
willRequestHelp = true; //?true or false
helpRequestFrequency = 20.0; //?in secs
lastHelpRequestTime = -100.0;

setWillHelp(True);
//********************************************************************
//use this if unit is powered down

poweredDown = False;
powerUp = True;
//been_hit = True;
//All_power = True;
//********************************************************************
//Use this if unit powered down and out of map

MovePoint[0] = -448;
MovePoint[1] = -7146;
MovePoint[2] = 0;
//********************************************************************
//Control variable use to set brain type

Orders1 = 2; //0 - guard
//1 - attack object - guard
//2 - moveto position - guard
//3 - patrol
//4 - dredattack
//5 - sentry
//6 - escort

endfunction;

//----------------------------------------------------------------------------------------

function update : integer;

var

boolean processingPilotEvents;
// boolean thinking;
integer pilotEventID;
integer pilotState;
integer[20] pilotEventParams;
integer curTarget;
real curTime;
real[3] myPos;
real[3] attackerPos;
// real distanceToAttacker;
integer curStateHandle;
static integer numFunctionalWeapons;
static integer[20] weaponList;

code

curTime = getTime;
curStateHandle = getCurrentStateHandle;


//--------------------------------------------------
// Process the pilot events since the last update...
numFunctionalWeapons = getWeapons(weaponList, 1);
if (numFunctionalWeapons == 0) then
trans noWeapons;
endif;

//--------------------------------------------------
// Check to see escorting Unit is dead
if (((objectStatus(moverList[0]) == 1) or (objectStatus(moverList[0]) == 2)) and (Not IsEscortUnitDead)) then
IsEscortUnitDead = True;
//trans guardLocation;
endif;

processingPilotEvents = TRUE;
while (processingPilotEvents) do
pilotEventID = getNextPilotEvent(pilotEventParams);
if (pilotEventID == PILOT_EVENT_NONE) then
processingPilotEvents = FALSE;
else
switch (pilotEventID)
case PILOT_EVENT_TARGETED:
curTarget = getTarget(-1);
if (lastHelpRequestTime < (curTime - helpRequestFrequency)) then
lastHelpRequestTime = curTime;
if (willRequestHelp) then
//distanceToAttacker = distanceToObject(-1, pilotEventParams[0]);
getObjectPosition(pilotEventParams[0], attackerPos);
getObjectPosition(-1, myPos);
requestHelp(pilotEventParams[0], myPos, 300.0, attackerPos, 300.0, 1);
endif;
endif;
numFunctionalWeapons = getWeapons(weaponList, 0);
if (curStateHandle <> AttackStateHandle) then
if ((numFunctionalWeapons > 0) and (curTarget == 0)) then
corerun = True;
magicAttack(pilotEventParams[0]);
setState(AttackStateHandle);
endif;
endif;
endcase;
case PILOT_EVENT_ATTACK_ORDER:
curTarget = getTarget(-1);
if (curStateHandle <> AttackStateHandle) then
if ((numFunctionalWeapons > 0) and (curTarget == 0)) then
corerun = True;
magicAttack(pilotEventParams[0]);
setState(AttackStateHandle);
endif;
endif;
endcase;
case PILOT_EVENT_FIRED_WEAPON:
endcase;
case PILOT_EVENT_HIT:
if ((poweredDown) AND (powerUp)) then
corePower(True);
powerUp = False;
endif;
endcase;
endswitch;
endif;
endwhile;

return(0);

endfunction;

//----------------------------------------------------------------------------------------

state noWeapons;

code

if (objectClass(-1) == 2) then
coreEject;
else
corePower(false);
endif;

endstate;

//----------------------------------------------------------------------------------------

state attack;

code

update;
corerun = True;
magicAttack(0);
resetOrders(1);
transBack;

endstate;

//----------------------------------------------------------------------------------------

state start;

var

worldposition escortPos;

code

//Activate this if unit is powered down
// if (not poweredDown) then
// corePower(false);
// poweredDown = true;
// endif;

// if ((been_hit) AND (beenhit)) then //beenhit is a system variable that is set to True when hit by weapon fire
// corePower(True);
// been_hit = False; //close this loop forewer unit is active
// All_powerup = True; //global variable defined in main mission.ABL used for global power-up other from beenhit - here used to send power-up signal for all mates
// All_power = False; //close the following loop forewer unit is active
// endif;

// if ((All_power) AND (All_powerup)) then //this loop is used if you recive power-up signal from mates or global power-up (All_powerup=True)
// corePower(True);
// All_power = False; //close this loop forewer unit is active
// been_hit = False; //close the previous loop forewer unit is active
// endif;


switch (Orders1)
case 0:
corerun = True;
magicGuard(startposition, -1);
endcase;
case 1:
if ((getenemycount(-1) == 0)) then
if isalive(73402) then
magicAttack(73402);
endif;
else
corerun = True;
getObjectPosition(-1, startPosition);
magicGuard(startposition, -1);
endif;
endcase;
case 2:
if (distancetoposition(-1, MovePoint) > 150) then
corerun = True;
coreMoveTo(MovePoint, TACORDER_PARAM_RUN);
else
corerun = True;
getObjectPosition(-1, startPosition);
magicGuard(startposition, -1);
endif;
endcase;
case 3:
corerun = True;
magicPatrol(PState, PPath);
endcase;
case 4:
corerun = True;
getObjectPosition(-1, startPosition);
magicGuard(startposition, -1);
endcase;
case 5:
coreRun = True;
coreSentry(startposition, 300, -1);
endcase;
case 6:
if not IsEscortUnitDead then
getObjectPosition(moverList[0], escortPos);
corerun = True;
setMoveArea(escortPos, escortRange);
magicEscort(moverList[0]);
else
coreRun = True;
magicGuard(guardSpot, -1);
endif;
endcase;
endswitch;

update;
resetOrders(1);
endstate;

//----------------------------------------------------------------------------------------

endfsm.

//****************************************************************************************

and here is the solution from the original attempt:
Code: [Select]
//****************************************************************************************//
//
// This Brain will patrol a defined patrol path
//****************************************************************************************//

//[EDIT]
fsm rs_1_7_Reinforcements; //EACH BRAIN MUST HAVE AN UNIQUE FSM ID..
//assigned via mission brain
//[EDIT END]


var

static WorldPosition startPosition;
static PatrolState PState;
static PatrolPath PPath;
static boolean willRequestHelp;
static real lastHelpRequestTime;
static real helpRequestFrequency;
static integer AttackStateHandle;
// static boolean poweredDown;
static integer scanRange;

//****************************************************************************************

function init;

    code


//[EDIT]
//********************************************************************
// Scan Ranges for Unit
scanRange = 500;


//********************************************************************
// Patrol STATE
PState[0] = 1;    // This is the Type of Patrol. 0 = Linear. 1 = Looping
//(Linear = Unit will move from 1 to 2 to 3, then 3 to 2 to 1) Assuming there are only 3 points to the Patrol
//(Looping = Unit will move from 1 to 2 to 3, then 1 to 2 to 3) Assuming there are only 3 points to the Patrol
PState[1] = 9;    //This is the Amount of Move Points there are listed below. Make sure you Count Patrol Point '0'
PState[2] = 1;    //This is How many Times the unit will perform the Patrol.. (-1 = Forever).

//********************************************************************
// Patrol Points below

//Enter the Coordinates of where you want the Unit to Patrol. It will do them in Order Start from 0 and ending at the Last Point
//Make sure you change the Index number (numbers in Brackets [0, 0] to match the correct Patrol Point.
//Also, the number of Mover Points MUST match the number you have entered in the Patrol State.

PPath[0, 0] = 2624; //X coordinate found in the editor
PPath[0, 1] = -4160; //Y coordinate found in the editor
PPath[1, 0] = 448;
PPath[1, 1] = -4160;
PPath[2, 0] = 192;
PPath[2, 1] = -832;
PPath[3, 0] = -2624;
PPath[3, 1] = 2752;
PPath[4, 0] = -3136;
PPath[4, 1] = 2752;
PPath[5, 0] = -3136;
PPath[5, 1] = 3392;
PPath[6, 0] = -3392;
PPath[6, 1] = 3392;
PPath[7, 0] = -3392;
PPath[7, 1] = -1088;
PPath[8, 0] = -2624;
PPath[8, 1] = -2624;

//[EDIT END]





//********************************************************************
// DO NOT EDIT BELOW THESE LINES
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

PState[3] = PATROL_DIRECTION_FORWARD;   
PState[4] = -1;    //reset cur point
PState[5] = -1;    //reset cur cycle
PState[6] = CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED;

//setDebugWindow(-1, -1);
//---------------------------
// Grab his start position...
getObjectPosition(-1, startPosition);
setTargetPriority(0, TARGET_PRIORITY_CURTARGET, -1, 0, CONTACT_CRITERIA_NONE);
setTargetPriority(1, TARGET_PRIORITY_MOVER, 0, 0, CONTACT_CRITERIA_NONE);
setTargetPriority(2, TARGET_PRIORITY_NONE, 0, 0, 0);
AttackStateHandle = getStateHandle("attack");
willRequestHelp = true; //?true or false
helpRequestFrequency = 20.0; //?in secs
lastHelpRequestTime = -100.0;

setWillHelp(True);

endfunction;

//----------------------------------------------------------------------------------------

function update : integer;

var

boolean processingPilotEvents;
// boolean thinking;
integer pilotEventID;
integer pilotState;
integer[20] pilotEventParams;
integer curTarget;
real curTime;
real[3] myPos;
real[3] attackerPos;
// real distanceToAttacker;
integer curStateHandle;
static integer numFunctionalWeapons;
static integer[20] weaponList;

code

curTime = getTime;
curStateHandle = getCurrentStateHandle;


//--------------------------------------------------
// Process the pilot events since the last update...
numFunctionalWeapons = getWeapons(weaponList, 1);
// if (numFunctionalWeapons == 0) then
// trans noWeapons;
// endif;

processingPilotEvents = TRUE;
while (processingPilotEvents) do
pilotEventID = getNextPilotEvent(pilotEventParams);
if (pilotEventID == PILOT_EVENT_NONE) then
processingPilotEvents = FALSE;
else
switch (pilotEventID)
case PILOT_EVENT_TARGETED:
curTarget = getTarget(-1);
if (lastHelpRequestTime < (curTime - helpRequestFrequency)) then
lastHelpRequestTime = curTime;
if (willRequestHelp) then
//distanceToAttacker = distanceToObject(-1, pilotEventParams[0]);
getObjectPosition(pilotEventParams[0], attackerPos);
getObjectPosition(-1, myPos);
requestHelp(pilotEventParams[0], myPos, 300.0, attackerPos, 300.0, 1);
endif;
endif;
endcase;
endswitch;
endif;
endwhile;

return(0);

endfunction;


//----------------------------------------------------------------------------------------

state start;

code

update;
// if (order1) then
magicPatrol(PState, PPath);
// else
// if (order2) then
// coreRun = True;
//                magicPatrol(PState1, PPath1);
// else
// coreRun = True;
//                magicPatrol(PState2, PPath2);
// endif;
// endif;
resetOrders(1);
endstate;

//----------------------------------------------------------------------------------------

endfsm.

//****************************************************************************************