Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SuppliesTransferWaypoint.c
Go to the documentation of this file.
4
5//~ Supplies transfer invoker
6void ScriptInvokerAITransferSuppliesMethod(EResourcePlayerInteractionType interactionType, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue, SCR_AIGroupUtilityComponent utility);
8typedef ScriptInvokerBase<ScriptInvokerAITransferSuppliesMethod> ScriptInvokerAITransferSupplies;
9
10// Base class for supply transfer waypoints (shared logic)
12{
13 [Attribute("2000", desc: "How much supplies can transfer per operation", params: "0 inf")]
14 protected float m_fTransferAmount;
15
16 [Attribute("2", desc: "Delay between operations [s]", params: "0 inf")]
17 protected float m_fTransferDelay;
18
20
21 //------------------------------------------------------------------------------------------------
27
28 //------------------------------------------------------------------------------------------------
34
35 //------------------------------------------------------------------------------------------------
38 {
39 return m_fTransferAmount;
40 }
41
42 //------------------------------------------------------------------------------------------------
45 {
46 return m_fTransferDelay;
47 }
48}
49
50// Base class for state functionality (shared logic)
51class SCR_SuppliesTransferWaypointState : SCR_AIWaypointState
52{
53 protected const EResourceType RESOURCE_TYPE = EResourceType.SUPPLIES;
54
55 protected SCR_ResourceComponent m_ResourceComponent;
57 protected SCR_ResourceConsumer m_ResourceConsumer;
58
59 protected float m_fMaxStoredResource;
60 protected float m_fCurrentResource;
61 protected float m_fCurrentTransferValue;
62 protected float m_fTransferAmount;
63
65
66 protected static ref ScriptInvokerAITransferSupplies s_OnAITransferedSupplies;
67
68 //------------------------------------------------------------------------------------------------
69 protected void InitSupplyTransfer(notnull SCR_AIGroupUtilityComponent utility, SCR_SuppliesTransferWaypoint wp, EResourceGeneratorID generatorId, EResourceGeneratorID consumerId, bool isLoad)
70 {
71 m_Base = wp.GetBase();
72 if (!m_Base)
73 m_Base = FindBase(wp.GetOrigin());
74
75 if (!m_Base)
76 return;
77
78 SCR_ResourceComponent baseResourceComponent = m_Base.GetResourceComponent();
79 if (!baseResourceComponent)
80 return;
81
82 // For load operation: DEFAULT is consumer, VEHICLE_LOAD is generator
83 // For unload operation: VEHICLE_UNLOAD is consumer, DEFAULT is generator
84 if (isLoad)
85 m_ResourceConsumer = baseResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, RESOURCE_TYPE);
86 else
87 m_ResourceGenerator = baseResourceComponent.GetGenerator(EResourceGeneratorID.DEFAULT, RESOURCE_TYPE);
88
90
91 IEntity vehicleEntity = GetVehicleFromGroupLeader(utility);
92 if (!vehicleEntity)
93 {
94 Print("The group leader is not in a vehicle.", LogLevel.WARNING);
95 if (m_Utility && m_Utility.m_Owner)
96 m_Utility.m_Owner.CompleteWaypoint(m_Waypoint);
97
98 return;
99 }
100
101 m_ResourceComponent = SCR_ResourceComponent.FindResourceComponent(vehicleEntity);
103 return;
104
105 if (isLoad)
107 else
109
110 }
111
112 //------------------------------------------------------------------------------------------------
114 {
116 if (!militaryBaseSystem)
117 return null;
118
119 array<SCR_MilitaryBaseComponent> bases = {};
120 militaryBaseSystem.GetBases(bases);
121
123 foreach (SCR_MilitaryBaseComponent base : bases)
124 {
125 campaignBase = SCR_CampaignMilitaryBaseComponent.Cast(base);
126 if (!campaignBase)
127 continue;
128
129 int radius = campaignBase.GetRadius();
130 if (vector.DistanceSqXZ(campaignBase.GetOwner().GetOrigin(), position) <= (radius * radius))
131 {
132 return campaignBase;
133 }
134 }
135
136 return null;
137 }
138
139 //------------------------------------------------------------------------------------------------
141 {
142 AIAgent aiAgent = utility.GetAIAgent();
143 AIGroup group = AIGroup.Cast(aiAgent);
144 if (!group)
145 return null;
146
147 AIAgent leaderAgent = group.GetLeaderAgent();
148 if (!leaderAgent)
149 return null;
150
151 ChimeraCharacter character = ChimeraCharacter.Cast(leaderAgent.GetControlledEntity());
152 if (!character)
153 return null;
154
155 CompartmentAccessComponent compartment = character.GetCompartmentAccessComponent();
156 if (!compartment)
157 return null;
158
159 return compartment.GetVehicleIn(character);
160 }
161
162 //------------------------------------------------------------------------------------------------
163 protected void GetResourceValues(out float currentResource, out float maxResource, out float transferAmount)
164 {
166 return;
167
168 currentResource = m_ResourceConsumer.GetAggregatedResourceValue();
169 maxResource = Math.Min(m_ResourceGenerator.GetAggregatedMaxResourceValue() - m_ResourceGenerator.GetAggregatedResourceValue(), currentResource);
170
172 transferAmount = maxResource;
173 else
174 transferAmount = m_fTransferAmount;
175 }
176
177 //------------------------------------------------------------------------------------------------
178 static ScriptInvokerAITransferSupplies GetOnAITransferedSupplies()
179 {
180 if (!s_OnAITransferedSupplies)
181 s_OnAITransferedSupplies = new ScriptInvokerAITransferSupplies();
182
183 return s_OnAITransferedSupplies;
184 }
185}
enum SCR_EAIActivityCause m_Utility
vector position
EResourceGeneratorID
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_ResourceComponent m_ResourceComponent
IEntity GetVehicleFromGroupLeader(notnull SCR_AIGroupUtilityComponent utility)
float m_fCurrentResource
SCR_SuppliesTransferWaypoint RESOURCE_TYPE
float m_fTransferAmount
SCR_CampaignMilitaryBaseComponent m_Base
float m_fCurrentTransferValue
float m_fMaxStoredResource
SCR_ResourceConsumer m_ResourceConsumer
SCR_ResourceGenerator m_ResourceGenerator
void InitSupplyTransfer(notnull SCR_AIGroupUtilityComponent utility, SCR_SuppliesTransferWaypoint wp, EResourceGeneratorID generatorId, EResourceGeneratorID consumerId, bool isLoad)
SCR_CampaignMilitaryBaseComponent FindBase(vector position)
void GetResourceValues(out float currentResource, out float maxResource, out float transferAmount)
func ScriptInvokerAITransferSuppliesMethod
ScriptInvokerBase< ScriptInvokerAITransferSuppliesMethod > ScriptInvokerAITransferSupplies
Definition Math.c:13
void SCR_AIWaypoint(IEntitySource src, IEntity parent)
int GetBases(notnull out array< SCR_MilitaryBaseComponent > bases)
static SCR_MilitaryBaseSystem GetInstance()
SCR_CampaignMilitaryBaseComponent GetBase()
SCR_CampaignMilitaryBaseComponent m_Base
void SetBase(SCR_CampaignMilitaryBaseComponent base)
Set the base for supply operation, if not set will auto-discover.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute