//****************************************************************************************// // // Ecounter 4 Mech that patrol Production Fac and Reinforce the Turret Control Base // // MISSION: MC2_15 // BushWacker // This unit will scan for the player. And attack the player if detected // //****************************************************************************************// fsm mc2_15_E4_ref_TCBASE_Mech2; var static WorldPosition startPosition; static PatrolState startPatrolState, TCBase_AttackState, TCBase_PatrolState; static PatrolPath startPatrolPath, TCBase_AttackPatrol, TCBase_PatrolPath; static boolean willRequestHelp; static real lastHelpRequestTime; static real helpRequestFrequency; static real attackerHelpRadius; static real defenderHelpRadius; static integer AttackStateHandle; static integer numFunctionalWeapons; static integer[20] weaponList; static boolean TCBasePatrolTrigger; //**************************************************************************************** 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, 400, CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED); setTargetPriority(2, TARGET_PRIORITY_NONE, 0, 0, 0); AttackStateHandle = getStateHandle("attack"); TCBasePatrolTrigger = false; TCBase_PatrolState[0] = PATROL_TYPE_LINEAR; TCBase_PatrolState[1] = 2; //?num points TCBase_PatrolState[2] = -1; //?num cycles TCBase_PatrolState[3] = PATROL_DIRECTION_FORWARD; TCBase_PatrolState[4] = -1; //reset cur point TCBase_PatrolState[5] = -1; //reset cur cycle TCBase_PatrolState[6] = CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED; TCBase_PatrolPath[0, 0] = 960.000; TCBase_PatrolPath[0, 1] = -4800.000; TCBase_PatrolPath[1, 0] = 490.667; TCBase_PatrolPath[1, 1] = -5525.333; TCBase_AttackState[0] = PATROL_TYPE_LINEAR; TCBase_AttackState[1] = 2; //?num points TCBase_AttackState[2] = -1; //?num cycles TCBase_AttackState[3] = PATROL_DIRECTION_FORWARD; TCBase_AttackState[4] = -1; //reset cur point TCBase_AttackState[5] = -1; //reset cur cycle TCBase_AttackState[6] = CONTACT_CRITERIA_ENEMY + CONTACT_CRITERIA_VISUAL_OR_SENSOR + CONTACT_CRITERIA_NOT_DISABLED; TCBase_AttackPatrol[0, 0] = 960.000; TCBase_AttackPatrol[0, 1] = -4800.000; TCBase_AttackPatrol[1, 0] = 490.667; TCBase_AttackPatrol[1, 1] = -5525.333; //------------------------------------------- // Setup the Patrol here... //XL startpatrolstate Start startpatrolstate[0] = PATROL_TYPE_LOOPING; startpatrolstate[1] = 8; //?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] = 1301.000; startpatrolPath[0, 1] = 5141.000 + 44; startpatrolPath[1, 0] = 405.000; startpatrolPath[1, 1] = 5909.000 + 44; startpatrolPath[2, 0] = -789.000; startpatrolPath[2, 1] = 5866.667 + 44; startpatrolPath[3, 0] = -1045.000; startpatrolPath[3, 1] = 4373.000 + 44; startpatrolPath[4, 0] = -1258.667; startpatrolPath[4, 1] = 3178.667 + 44; startpatrolPath[5, 0] = -533.000; startpatrolPath[5, 1] = 2794.000 + 44; startpatrolPath[6, 0] = 1045.000; startpatrolPath[6, 1] = 2538.000 + 44; startpatrolPath[7, 0] = 1514.000; startpatrolPath[7, 1] = 3861.000 + 44; //XLs startpatrolPath end willRequestHelp = true; //?true or false helpRequestFrequency = 20.0; //?in secs attackerHelpRadius = 200; //?in meters defenderHelpRadius = 225; //?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 //-------------------------------------------------- // Check Time and Check Current State Handle curTime = getTime; curStateHandle = getCurrentStateHandle; //-------------------------------------------------- //-------------------------------------------------- // Trigger for when Supply base gets attacked. if (TurretBase_Attacked) and (Not TCBasePatrolTrigger) then TCBasePatrolTrigger= True; trans TCBaseAttacked; 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: 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_RIGHT_FLANK, tacticState); // coreAttack(0, TACORDER_PARAM_PURSUE); resetOrders(1); transBack; endstate; //---------------------------------------------------------------------------------------- state TCBaseAttacked; code update; setDebugString(-1, 3, " ReinForce "); corePatrol(TCBase_AttackState, TCBase_AttackPatrol, AttackStateHandle); trans TCBasePatrol; endstate; //---------------------------------------------------------------------------------------- state TCBasePatrol; code update; setDebugString(-1, 3, " ReinForce "); corePatrol(TCBase_PatrolState, TCBase_PatrolPath, AttackStateHandle); resetOrders(1); endstate; //---------------------------------------------------------------------------------------- state start; code update; setDebugString(-1, 3, "StartPatrol1 "); //coreGuard(startPosition, -1 , AttackStateHandle); corePatrol(startPatrolState, startPatrolPath, AttackStateHandle); resetOrders(1); endstate; //---------------------------------------------------------------------------------------- endfsm. //****************************************************************************************