//****************************************************************************************// // // FIGHTER: PATROL AND CALL IN REINFORCEMENTS // MISSION: E3_Beach // Patrol for units 124, 125, 126 // civ trucks near initial base // //****************************************************************************************// module mc2_demo_patrol1 : integer; /* DESCRIPTION: This pilot will patrol the given patrol path, until contact is made with an enemy. At that point, the pilot will engage the contact. In addition, when he is targeted, he will request help. PARAMETERS: The following brain cells must be set: 0:integer request help 1:integer number of patrol points 2:integer number of patrol cycles 3:float patrol point 1 x-world coord 4:float patrol point 1 y-world coord 5:float patrol point 2 x-world coord 6:float patrol point 2 y-world coord etc. There may be up to 20 patrol points. */ //**************************************************************************************** var static real[3] startPosition; static integer retreatBuilding; static PatrolState patrolState1; static PatrolPath patrolPath1; static boolean willRequestHelp; static real lastHelpRequestTime; static real helpRequestFrequency; static real attackerHelpRadius; static real defenderHelpRadius; //**************************************************************************************** function init; var integer i; integer numPatrolPoints; code //---------------------------------------------------- // Grab his start position, and set his start state... getObjectPosition(-1, startPosition); setPilotState(PILOT_STATE_PATROL); setDebugWindow(-1, -1); //------------------- // Look for movers... setTargetPriority(0, TARGET_PRIORITY_CURTARGET, -1, 300, CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED); setTargetPriority(1, TARGET_PRIORITY_MOVER, 0, 300, CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED); setTargetPriority(2, TARGET_PRIORITY_NONE, 0, 0, 0); retreatBuilding = 0; //------------------------- // Setup the Patrol here... patrolState1[0] = PATROL_TYPE_LINEAR; patrolState1[1] = 2; //?num points patrolState1[2] = -1; //?num cycles patrolState1[3] = PATROL_DIRECTION_FORWARD; patrolState1[4] = -1; //reset cur point patrolState1[5] = -1; //reset cur cycle patrolState1[6] = CONTACT_CRITERIA_VISUAL + CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_NOT_DISABLED; patrolPath1[0, 0] = 3500; //?x coord patrolPath1[0, 1] = 2700; //?y coord patrolPath1[1, 0] = 1650; //?x coord patrolPath1[1, 1] = 1850; //?y coord willRequestHelp = true; //?true or false helpRequestFrequency = 20.0; //?in secs attackerHelpRadius = 250; //?in meters defenderHelpRadius = 250; //?in meters lastHelpRequestTime = -100.0; endfunction; //---------------------------------------------------------------------------------------- order 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; code curTime = getTime; //--------------------------------------------------------- // First, process the pilot events since the last update... 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, attackerHelpRadius, attackerPos, defenderHelpRadius, 1); endif; endif; if (curTarget == 0) then newAttack(pilotEventParams[0], TACORDER_PARAM_PURSUE); setPilotState(PILOT_STATE_ATTACK); endif; endcase; case PILOT_EVENT_HIT: endcase; case PILOT_EVENT_DAMAGED: endcase; case PILOT_EVENT_FRIENDLY_KILLED: endcase; case PILOT_EVENT_FRIENDLY_CRIPPLED: endcase; case PILOT_EVENT_FRIENDLY_DESTROYED: endcase; case PILOT_EVENT_CRIPPLED: endcase; case PILOT_EVENT_DESTROYED: endcase; case PILOT_EVENT_WITHDRAWN: endcase; case PILOT_EVENT_ATTACK_ORDER: curTarget = getTarget(-1); if (curTarget == 0) then newAttack(pilotEventParams[0], TACORDER_PARAM_PURSUE); setPilotState(PILOT_STATE_ATTACK); endif; endcase; case PILOT_EVENT_COLLISION: endcase; case PILOT_EVENT_GUARD_RADIUS_BREACH: endcase; case PILOT_EVENT_TARGET_KILLED: endcase; case PILOT_EVENT_MATE_FIRED_WEAPON: endcase; case PILOT_EVENT_PLAYER_ORDER: endcase; case PILOT_EVENT_NO_MOVEPATH: endcase; case PILOT_EVENT_GATE_CLOSING: endcase; case PILOT_EVENT_CONTACT: endcase; endswitch; endif; endwhile; //---------------------------------- // Now, go through our state code... thinking = TRUE; while (thinking) do thinking = FALSE; pilotState = getPilotState; switch (pilotState) case PILOT_STATE_IDLE: endcase; case PILOT_STATE_PATROL: setDebugString(-1, 3, " PATROL "); patrol(patrolState1, patrolPath1); setPilotState(PILOT_STATE_ATTACK); endcase; case PILOT_STATE_ATTACK: setDebugString(-1, 3, " ATTACK "); newAttack(0, TACORDER_PARAM_PURSUE); setPilotState(PILOT_STATE_PATROL); endcase; case PILOT_STATE_RETREAT: if (retreatBuilding == 0) then retreatBuilding = requestShelter(800); endif; if (retreatBuilding <> 0) then newMoveToObject(retreatBuilding, 0); objectRemove(-1); endif; endcase; endswitch; endwhile; return(0); endorder; //---------------------------------------------------------------------------------------- // Main Code //---------------------------------------------------------------------------------------- code update; endmodule. //****************************************************************************************