Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FactionBaseResourceComponent.c
Go to the documentation of this file.
4
5class SCR_FactionBaseResourceComponent : SCR_MilitaryBaseLogicComponent
6{
7 protected FactionAffiliationComponent m_FactionAffiliationComp;
8
9 //------------------------------------------------------------------------------------------------
11 {
13 return null;
14
15 Faction faction = m_FactionAffiliationComp.GetAffiliatedFaction();
16 if (faction)
17 return faction;
18
19 return m_FactionAffiliationComp.GetDefaultAffiliatedFaction();
20 }
21
22 //------------------------------------------------------------------------------------------------
23 override protected void OnBaseFactionChanged(Faction faction)
24 {
25 if (!m_FactionAffiliationComp || !faction)
26 return;
27
28 if (m_FactionAffiliationComp.GetAffiliatedFaction() == faction)
29 return;
30
31 m_FactionAffiliationComp.SetAffiliatedFaction(faction);
32 }
33
34 //------------------------------------------------------------------------------------------------
35 protected void RegisterBaseLogic()
36 {
38 return;
39
41 if (!baseManager)
42 return;
43
44 baseManager.RegisterLogicComponent(this);
45 }
46
47 //------------------------------------------------------------------------------------------------
48 protected void FetchFactionAffiliation()
49 {
50 IEntity owner = GetOwner();
51 IEntity parent = owner.GetParent();
52 while (parent && !m_FactionAffiliationComp)
53 {
54 m_FactionAffiliationComp = FactionAffiliationComponent.Cast(parent.FindComponent(FactionAffiliationComponent));
56 owner = parent;
57
58 parent = parent.GetParent();
59 }
60
62 {
63 m_FactionAffiliationComp = FactionAffiliationComponent.Cast(owner.FindComponent(FactionAffiliationComponent));
65 return;
66 }
67
68 // In conflict we have to discard bases which come from the command post composition, as they are not used
69 bool isCampaign = SCR_GameModeCampaign.Cast(GetGame().GetGameMode()) != null;
70
71 vector ownerPos = owner.GetOrigin();
72 float closestDistance = float.MAX;
73 SCR_MilitaryBaseComponent closestBase;
75 foreach (SCR_MilitaryBaseComponent base : m_aBases)
76 {
77 if (base.GetOwner() == owner)
78 return;
79
80 campaignBase = SCR_CampaignMilitaryBaseComponent.Cast(base);
81 if (isCampaign && !campaignBase)
82 continue;
83
84 if (campaignBase && campaignBase.GetType() != SCR_ECampaignBaseType.BASE)
85 continue;
86
87 float distance = vector.DistanceSqXZ(base.GetOwner().GetOrigin(), ownerPos);
88 if (distance < closestDistance)
89 {
90 closestDistance = distance;
91 closestBase = base;
92 }
93 }
94
95 if (closestBase)
96 OnBaseFactionChanged(closestBase.GetFaction());
97 }
98
99 //------------------------------------------------------------------------------------------------
100 override protected void EOnInit(IEntity owner)
101 {
102 super.EOnInit(owner);
103
104 SCR_EditorLinkComponent linkComponent = SCR_EditorLinkComponent.Cast(SCR_EntityHelper.GetMainParent(GetOwner(), true).FindComponent(SCR_EditorLinkComponent));
105 if (linkComponent)
106 {
107 linkComponent.GetOnLinkedEntitiesSpawned().Insert(FetchFactionAffiliation);
108 linkComponent.GetOnLinkedEntitiesSpawned().Insert(RegisterBaseLogic);
109 return;
110 }
111
113 }
114}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_BaseGameMode GetGameMode()
void OnBaseFactionChanged(notnull SCR_MilitaryBaseComponent base, Faction faction)
SCR_CampaignFaction GetFaction()
float distance
SCR_FactionBaseResourceComponentClass m_FactionAffiliationComp
void FetchFactionAffiliation()
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
SCR_MilitaryBaseLogicComponentClass m_aBases
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external IEntity GetParent()
SCR_ECampaignBaseType GetType()
Returns type of this base.
static IEntity GetMainParent(IEntity entity, bool self=false)
static SCR_MilitaryBaseSystem GetInstance()
void RegisterLogicComponent(notnull SCR_MilitaryBaseLogicComponent component)
IEntity GetOwner()
Owner entity of the fuel tank.
override void EOnInit(IEntity owner)