//****************************************************************************************// // // GROUP 0B // // MISSION: GENCON // 2nd Group Main Reinforcement (South Path) // Units: 3 // // //****************************************************************************************// fsm mc2_gencon_group0b; var static real[3] startPosition; static PatrolState basePatrolState,group2PatrolState, playerPatrolState; static PatrolPath basePatrolPath,group2PatrolPath, playerPatrolPath; static boolean willRequestHelp; static real lastHelpRequestTime; static real helpRequestFrequency; static real attackerHelpRadius; static real defenderHelpRadius; static integer AttackStateHandle; static integer GoToBaseStateHandle; static integer Group1AttacksStateHandle; static integer Group0AttacksStateHandle; static boolean GoToBaseSet; static boolean Group1AttacksSet; static boolean Group0AttacksSet; static integer numFunctionalWeapons; static integer[20] weaponList; //**************************************************************************************** function init; code //setDebugWindow(-1, -1); //--------------------------- // Grab his start position... getObjectPosition(-1, startPosition); //------------------- // Look for movers... setTargetPriority(0, TARGET_PRIORITY_CURTARGET, -1, 400, 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); AttackStateHandle = getStateHandle("attack"); GoToBaseStateHandle = getStateHandle("goToBase"); Group1AttacksStateHandle = getStateHandle("group1Attacks"); Group0AttacksStateHandle = getStateHandle("group0Attacks"); GoToBaseSet = false; Group1AttacksSet = false; Group0AttacksSet = false; basePatrolState[0] = PATROL_TYPE_LINEAR; basePatrolState[1] = 2; //?num points basePatrolState[2] = 1; //?num cycles basePatrolState[3] = PATROL_DIRECTION_FORWARD; basePatrolState[4] = -1; //reset cur point basePatrolState[5] = -1; //reset cur cycle basePatrolState[6] = CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED; basePatrolPath[0, 0] = 64.0; basePatrolPath[0, 1] = 2752.0; basePatrolPath[1, 0] = -362.667; basePatrolPath[1, 1] = 2709.333; playerPatrolState[0] = PATROL_TYPE_LINEAR; playerPatrolState[1] = 1; //?num points playerPatrolState[2] = 1; //?num cycles playerPatrolState[3] = PATROL_DIRECTION_FORWARD; playerPatrolState[4] = -1; //reset cur point playerPatrolState[5] = -1; //reset cur cycle playerPatrolState[6] = CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED; playerPatrolPath[0, 0] = 3989.33; playerPatrolPath[0, 1] = -2666.667; group2PatrolState[0] = PATROL_TYPE_LINEAR; group2PatrolState[1] = 1; //?num points group2PatrolState[2] = 1; //?num cycles group2PatrolState[3] = PATROL_DIRECTION_FORWARD; group2PatrolState[4] = -1; //reset cur point group2PatrolState[5] = -1; //reset cur cycle group2PatrolState[6] = CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED; group2PatrolPath[0, 0] = 4047.667; group2PatrolPath[0, 1] = 106.667; willRequestHelp = true; //?true or false helpRequestFrequency = 20.0; //?in secs attackerHelpRadius = 225; //?in meters defenderHelpRadius = 225; //?in meters lastHelpRequestTime = -100.0; 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; //------------------------------------- // Is it time to move to set this flag? if ((not Group0AttacksFlag) and (Group0AttacksTime > 0.0)) then if (curTime > Group0AttacksTime) then mcprint("set Group0Attacks = true"); Group0AttacksFlag = true; endif; endif; //----------------------------------- // Is it time to move to a new state? curStateHandle = getCurrentStateHandle; if (GoToBaseFlag) then if (not GoToBaseSet) then GoToBaseSet = true; if (curStateHandle <> GoToBaseStateHandle) then mcprint("trans GoToBase"); trans GoToBase; endif; endif; else if (Group1AttacksFlag) then if (not Group1AttacksSet) then Group1AttacksSet = true; if (curStateHandle <> Group1AttacksStateHandle) then mcprint("trans Group1Attacks"); trans Group1Attacks; endif; endif; else if (Group0AttacksFlag) then if (not Group0AttacksSet) then Group0AttacksSet = true; if (curStateHandle <> Group0AttacksStateHandle) then mcprint("trans Group0Attacks"); trans Group0Attacks; endif; endif; endif; endif; endif; //-------------------------------------------------- // 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: if (Group0AttacksTime <= 0.0) then mcprint("Group0Attacks + 3.0"); Group0AttacksTime = getTime + 3.0; endif; 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; code update; setDebugString(-1, 3, " ATTACK "); coreAttack(0, TACORDER_PARAM_PURSUE); resetOrders(1); transBack; endstate; //---------------------------------------------------------------------------------------- state goToBase; var WorldPosition guardLocation; code update; setDebugString(-1, 3, " gotToBase "); guardLocation[0] = -362.667; guardLocation[1] = 2709.333; guardLocation[2] = 0.0; if (numFunctionalWeapons > 0) then corePatrol(basePatrolState, basePatrolPath, AttackStateHandle); setMoveArea(guardLocation, 50.0); coreGuard(guardLocation, -1, AttackStateHandle); else setDebugString(-1, 3, " gotToBase(NO WP) "); setMoveArea(startPosition, -1.0); corePatrol(basePatrolState, basePatrolPath, -1); trans noWeapons; endif; endstate; //---------------------------------------------------------------------------------------- state group1Attacks; var real[3] group2Loc; code update; setMoveArea(startPosition, -1.0); setDebugString(-1, 3, "group1Attacks"); group2Loc[0] = 4047.667; group2Loc[1] = 106.667; group2Loc[2] = 0.0; coreMoveTo(group2Loc, TACORDER_PARAM_RUN/* + TACORDER_PARAM_HOLDFIRE*/); if (numFunctionalWeapons > 0) then corePatrol(group2PatrolState, group2PatrolPath, AttackStateHandle); else trans noWeapons; endif; endstate; //---------------------------------------------------------------------------------------- state group0Attacks; var WorldPosition group1Loc; code update; setMoveArea(startPosition, -1.0); setDebugString(-1, 3, "group0Attacks"); group1Loc[0] = 3178.667; group1Loc[1] = 1130.667; group1Loc[2] = 0.0; coreMoveTo(group1Loc, TACORDER_PARAM_RUN/* + TACORDER_PARAM_HOLDFIRE*/); setMoveArea(group1Loc, 50.0); coreGuard(group1Loc, -1, AttackStateHandle); endstate; //---------------------------------------------------------------------------------------- state start; code update; setMoveArea(startPosition, -1.0); setDebugString(-1, 3, " PATROL "); numFunctionalWeapons = getWeapons(weaponList, 1); if (numFunctionalWeapons > 0) then corePatrol(playerPatrolState, playerPatrolPath, AttackStateHandle); else corePatrol(playerPatrolState, playerPatrolPath, 0); if (Group0AttacksTime <= 0.0) then mcprint("Group0Attacks + 3.0"); Group0AttacksTime = getTime + 3.0; endif; resetOrders(1); endif; endstate; //---------------------------------------------------------------------------------------- endfsm. //****************************************************************************************