//****************************************************************************************// // // This brain is used to guard the Base // // MISSION: Mc2_2 Tutorial Brain // // //****************************************************************************************// fsm mc2_19_MOG_guard2; var static WorldPosition startPosition; static PatrolState startPatrolState, BaseAssaultState; static PatrolPath startPatrolPath, BaseAssaultPath; static boolean willRequestHelp; static real lastHelpRequestTime; static real helpRequestFrequency; static real attackerHelpRadius; static real defenderHelpRadius; static integer AttackStateHandle; static boolean poweredDown; static integer numFunctionalWeapons; static integer[20] weaponList; static boolean HeadingTowardBase; //**************************************************************************************** function init; code //setDebugWindow(-1, -1); //--------------------------- // Grab his start position... getObjectPosition(-1, startPosition); //------------------- // Look for movers... 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, 200, CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED); AttackStateHandle = getStateHandle("attack"); HeadingTowardBase = False; //------------------------------------------- // Setup the Patrol here... //XL startPatrolState Start startPatrolState[0] = PATROL_TYPE_LINEAR; startPatrolState[1] = 3; //?num points startPatrolState[2] = 1; //?num cycles startPatrolState[3] = PATROL_DIRECTION_FORWARD; startPatrolState[4] = -1; //reset cur point startPatrolState[5] = -1; //reset cur cycle startPatrolState[6] = 0 + CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL + CONTACT_CRITERIA_NOT_DISABLED; startPatrolPath[0, 0] = startPosition[0]; startPatrolPath[0, 1] = 7402; startPatrolPath[1, 0] = startPosition[0]; startPatrolPath[1, 1] = startPatrolPath[0, 1] - 5034; startPatrolPath[2, 0] = startPosition[0] + 2036; startPatrolPath[2, 1] = startPatrolPath[1, 1] - 1280; //XLs startPatrolPath end willRequestHelp = true; //?true or false helpRequestFrequency = 20.0; //?in secs attackerHelpRadius = 100; //?in meters defenderHelpRadius = 125; //?in meters lastHelpRequestTime = -100.0; endfunction; //---------------------------------------------------------------------------------------- function setWillRequestHelp (boolean setting); code if (setting and (not willRequestHelp)) then lastHelpRequestTime = 0.0; endif; willRequestHelp = setting; 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; 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, attackerHelpRadius, attackerPos, defenderHelpRadius, 1); endif; endif; numFunctionalWeapons = getWeapons(weaponList, 0); if (curStateHandle <> AttackStateHandle) then if ((numFunctionalWeapons > 0) and (curTarget == 0)) then coreAttack(pilotEventParams[0], TACORDER_PARAM_PURSUE); setState(AttackStateHandle); endif; endif; endcase; case PILOT_EVENT_ATTACK_ORDER: curTarget = getTarget(-1); if (curStateHandle <> AttackStateHandle) then if ((numFunctionalWeapons > 0) and (curTarget == 0))then coreAttack(pilotEventParams[0], TACORDER_PARAM_PURSUE); setState(AttackStateHandle); endif; endif; endcase; case PILOT_EVENT_FIRED_WEAPON: endcase; endswitch; endif; endwhile; return(0); endfunction; //---------------------------------------------------------------------------------------- state noWeapons; code setDebugString(-1, 3, " NO WEAPONS "); if (objectClass(-1) == 2) then coreEject; else corePower(false); endif; endstate; //---------------------------------------------------------------------------------------- state attack; var integer tacticState; code update; setDebugString(-1, 3, " ATTACK "); coreAttackTactic(0, TACORDER_PARAM_NONE, TACTIC_REAR, tacticState); //coreAttack(0, TACORDER_PARAM_PURSUE); resetOrders(1); transBack; endstate; //---------------------------------------------------------------------------------------- state start; code update; setDebugString(-1, 3, "Guarding "); coreGuard(startPosition, -1, attackstateHandle); resetOrders(1); endstate; //---------------------------------------------------------------------------------------- endfsm. //****************************************************************************************