9 static const float DEFEND_TASK_DEFAULT_MIN_ALLY_DISTANCE = 300;
10 static const float DEFEND_TASK_DEFAULT_MAX_ALLY_DISTANCE = 400;
11 static const float DEFEND_TASK_DEFAULT_MIN_ENEMY_DISTANCE = 300;
12 static const float DEFEND_TASK_DEFAULT_MAX_ENEMY_DISTANCE = 400;
24 static float GetMinAllyDistance()
27 return DEFEND_TASK_DEFAULT_MIN_ALLY_DISTANCE;
31 return supportEntity.GetMinAllyDistance();
33 return DEFEND_TASK_DEFAULT_MIN_ALLY_DISTANCE;
37 static float GetMaxAllyDistance()
40 return DEFEND_TASK_DEFAULT_MAX_ALLY_DISTANCE;
44 return supportEntity.GetMaxAllyDistance();
46 return DEFEND_TASK_DEFAULT_MAX_ALLY_DISTANCE;
50 static float GetMinEnemyDistance()
53 return DEFEND_TASK_DEFAULT_MIN_ENEMY_DISTANCE;
57 return supportEntity.GetMinEnemyDistance();
59 return DEFEND_TASK_DEFAULT_MIN_ENEMY_DISTANCE;
63 static float GetMaxEnemyDistance()
66 return DEFEND_TASK_DEFAULT_MAX_ENEMY_DISTANCE;
70 return supportEntity.GetMaxEnemyDistance();
72 return DEFEND_TASK_DEFAULT_MAX_ENEMY_DISTANCE;
78 array<SCR_BaseTask> tasks =
new array<SCR_BaseTask>();
84 for (
int i = tasks.Count() - 1; i >= 0; i--)
90 if (defendTask.GetTargetBase() == targetBase && defendTask.GetTargetFaction() == targetFaction)
101 array<SCR_MilitaryBaseComponent> bases = {};
107 int closestBaseIndex = -1;
108 float closestBaseDistance =
float.MAX;
109 float minAllyDistanceSq = Math.Pow(GetMinAllyDistance(), 2);
110 vector controlledEntityOrigin = controlledEntity.GetOrigin();
112 for (
int i = bases.Count() - 1; i >= 0; i--)
119 if (!campaignBase.IsInitialized())
122 if (campaignBase.GetFaction() != faction)
125 float distance = vector.DistanceSq(campaignBase.GetOwner().GetOrigin(), controlledEntityOrigin);
130 closestBaseIndex = i;
134 if (closestBaseIndex != -1)
142 IEntity locallyControlledEntity = playerController.GetMainEntity();
144 if (!locallyControlledEntity)
147 FactionAffiliationComponent factionAffiliationComponent = FactionAffiliationComponent.Cast(locallyControlledEntity.FindComponent(FactionAffiliationComponent));
148 if (!factionAffiliationComponent)
155 closestBase = FindClosestFriendlyBase(locallyControlledEntity, faction);
161 if (FindDefendTask(closestBase, faction))
164 if (!FindEnemyPresence(closestBase, faction))
175 SCR_CampaignFaction enemyFaction = SCR_CampaignFactionManager.Cast(
GetGame().GetFactionManager()).GetEnemyFaction(alliedFaction);
185 distanceSq = supportEntity.GetMinEnemyDistance();
187 distanceSq = supportEntity.GetMaxEnemyDistance();
189 distanceSq *= distanceSq;
191 array<SCR_ChimeraCharacter> enemyCharacters = supportEntity.GetCharactersByFaction(enemyFaction);
192 if (!enemyCharacters)
195 vector baseOrigin = base.GetOwner().GetOrigin();
196 for (
int i = enemyCharacters.Count() - 1; i >= 0; i--)
198 if (vector.DistanceSq(baseOrigin, enemyCharacters[i].GetOrigin()) < distanceSq)
206 static bool IsCharacterInAnyDefendTaskRange(SCR_ChimeraCharacter character)
208 array<SCR_BaseTask> tasks =
new array<SCR_BaseTask>();
218 for (
int i = tasks.Count() - 1; i >= 0; i--)
224 if (defendTask.IsCharacterInDefendTaskRange(character, supportEntity))
236 protected override void UpdateMapInfo()
244 protected override void ShowAvailableTask(
bool afterAssigneeRemoved =
false)
247 if (CanBeAssigned(reason))
252 string text = TASK_AVAILABLE_TEXT +
" " + GetTitle();
256 baseName = m_TargetBase.GetBaseNameUpperCase();
264 override protected void ShowTaskProgress(
bool showMsg =
true)
267 if (campaign && showMsg)
272 baseName = m_TargetBase.GetBaseNameUpperCase();
283 override void SetDescriptionWidgetText(notnull TextWidget textWidget,
string taskText)
288 baseName = m_TargetBase.GetBaseName();
290 textWidget.SetTextFormat(taskText, baseName);
294 override void Finish(
bool showMsg =
true)
297 super.Finish(showMsg);
311 SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(
GetGame().
GetGameMode().FindComponent(SCR_XPHandlerComponent));
323 array<SCR_ChimeraCharacter> characters = supportClass.GetCharactersByFaction(
SCR_CampaignFaction.Cast(GetTargetFaction()));
327 for (
int i = characters.Count() - 1; i >= 0; i--)
329 if (IsCharacterInDefendTaskRange(characters[i]))
330 comp.AwardXP(
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(characters[i]),
SCR_EXPRewards.TASK_DEFEND, 1.0);
337 override void Fail(
bool showMsg =
true)
346 if (campaign && showMsg)
368 if (character.GetFaction() == GetTargetFaction())
369 maxDistanceSq = supportClass.GetMaxAllyDistance();
371 maxDistanceSq = supportClass.GetMaxEnemyDistance();
373 maxDistanceSq *= maxDistanceSq;
375 float distanceSq = vector.DistanceSq(character.GetOrigin(), GetTargetBase().
GetOwner().
GetOrigin());
377 return (distanceSq < maxDistanceSq);
385 void PeriodicalCheck()
388 if (!m_TargetBase || !campaignFaction)
399 if (!FindEnemyPresence(m_TargetBase, campaignFaction,
false))
400 supportEntity.FinishTask(
this);
407 if (character.GetFaction() != GetTargetFaction() && IsCharacterInDefendTaskRange(character))
413 void OnBaseCaptured(SCR_MilitaryBaseComponent base,
Faction faction)
425 supportEntity.FailTask(
this);
429 override string GetMapDescriptorText()
431 return GetTaskListTaskText();
468 baseManager.GetOnBaseFactionChanged().Remove(OnBaseCaptured);