//****************************************************************************************// // // Brains used for Renard in his most Awesome Atlas // // MISSION: Mc2_17 // // //****************************************************************************************// fsm mc2_17_a1_Copter_2; var static WorldPosition startPosition; static PatrolState startPatrolState, BasePatrolState, spawnState; static PatrolPath startPatrolPath, BasePatrolPath, spawnPath; 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 attackBase; static real TurnOffSensor; //**************************************************************************************** function init; code //setDebugWindow(-1, -1); //--------------------------- // Grab his start position... getObjectPosition(-1, startPosition); //------------------- // Look for movers... setTargetPriority(0, TARGET_PRIORITY_CURTARGET, -1, 100, CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED); setTargetPriority(1, TARGET_PRIORITY_MOVER, 0,500, CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED); setTargetPriority(2, TARGET_PRIORITY_NONE, 0, 0, 0); AttackStateHandle = getStateHandle("attack"); attackBase = False; startPatrolState[0] = PATROL_TYPE_LINEAR; startPatrolState[1] = 5; //?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] = CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED; startPatrolPath[0 ,0] = startPosition[0] + 1664.667; startPatrolPath[0,1] = startPosition[1] - 981.333; startPatrolPath[1 ,0] = startPosition[0] + 2426.667; startPatrolPath[1 ,1] = startPosition[1] - 1279.333; startPatrolPath[2 ,0] = startPosition[0] + 3925.667; startPatrolPath[2 ,1] = startPosition[1] - 4266.333; startPatrolPath[3 ,0] = startPosition[0] + 6528.667; startPatrolPath[3 ,1] = startPosition[1] - 3925.333; startPatrolPath[4 ,0] = startPosition[0] + 8703.667; startPatrolPath[4 ,1] = startPosition[1] - 2474.333; spawnState[0] = PATROL_TYPE_LINEAR; spawnState[1] = 4; //?num points spawnState[2] = 1; //?num cycles spawnState[3] = PATROL_DIRECTION_FORWARD; spawnState[4] = -1; //reset cur point spawnState[5] = -1; //reset cur cycle spawnState[6] = CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED; spawnPath[0 ,0] = startPosition[0] ; spawnPath[0 ,1] = startPosition[1] ; spawnPath[1 ,0] = startPosition[0] + 256; spawnPath[1 ,1] = startPosition[1] + 42.667; spawnPath[2 ,0] = startPosition[0] + 682.667; spawnPath[2 ,1] = startPosition[1] - 170.666; spawnPath[3 ,0] = startPosition[0] + 1237.334; spawnPath[3 ,1] = startPosition[1] - 384; 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] = 2837; BasePatrolPath[0, 1] = -3050; BasePatrolPath[1, 0] = -4970; BasePatrolPath[1, 1] = -234; willRequestHelp = true; //?true or false helpRequestFrequency = 20.0; //?in secs attackerHelpRadius = 100; //?in meters defenderHelpRadius = 125; //?in meters lastHelpRequestTime = -100.0; setWillHelp(False); 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; //-------------------------------------------------- // Check to see if time to attack the player if (LiaoSonAttack) and (Not attackBase) then attackBase = True; TurnOffSensor = getTime + 20; trans SpawnIN; 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_JOUST, tacticState); coreAttack(0, TACORDER_PARAM_PURSUE); resetOrders(1); transBack; endstate; //---------------------------------------------------------------------------------------- state attackingBase; code update; setDebugString(-1, 3, "attackingBase "); corePatrol(startPatrolState, startPatrolPath, attackStateHandle); resetOrders(1); trans PatrolBase; endstate; //---------------------------------------------------------------------------------------- state SpawnIN; code update; setDebugString(-1, 3, "Spawin "); corePatrol(spawnState, spawnPath, -1); resetOrders(1); trans attackingBase; endstate; //---------------------------------------------------------------------------------------- state PatrolBase; code update; setDebugString(-1, 3, "PatrolBase "); corePatrol(basePatrolState, basePatrolPath, attackStateHandle); resetOrders(1); endstate; //---------------------------------------------------------------------------------------- state WaitForObj1; var worldPosition WaitGuard; code WaitGuard[0] = -7274; WaitGuard[1] = -362; waitGuard[2] = 0; update; setDebugString(-1, 3, " WaitObj1 "); coreGuard(waitGuard, -1, attackStateHandle); resetOrders(1); endstate; //---------------------------------------------------------------------------------------- state start; code update; endstate; //---------------------------------------------------------------------------------------- endfsm. //****************************************************************************************