Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CaptureAndHoldManager.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/GameMode/CaptureAndHold", description: "Manager component allowing access and API over CaptureAndHold areas.")]
5
9class SCR_CaptureAndHoldManager : SCR_BaseGameModeComponent
10{
12 [Attribute(defvalue: "0", desc: "If enabled, custom weather Id will be used. Authority only.", category: "CaptureAndHold: Environment")]
13 bool m_bUseCustomWeather;
14
16 [Attribute(defvalue: "", desc: "Weather IDs are the same as used in the TimeAndWeatherManager. Weather set on game start. Authority only.", category: "CaptureAndHold: Environment")]
18
20 [Attribute(defvalue: "0", desc: "If enabled, custom time of the day will be used. Authority only.", category: "CaptureAndHold: Environment")]
22
24 [Attribute(defvalue: "12", desc: "Time of the day set on game start. Authority only.", category: "CaptureAndHold: Environment", params: "0 24 0.01")]
26
28 [Attribute(defvalue: "0", desc: "Should actions be persistent (sticky) in the sense that they are not cleared when players leave the area?")]
30
32 protected static SCR_CaptureAndHoldManager s_Instance;
33
35 protected ref array<SCR_CaptureAndHoldArea> m_aAreas = {};
36
38 protected ref array<SCR_CaptureAndHoldSpawnArea> m_aSpawnAreas = {};
39
40 //------------------------------------------------------------------------------------------------
43 {
44 m_aAreas.Insert(area);
45 }
46
47 //------------------------------------------------------------------------------------------------
50 {
51 int indexOf = m_aAreas.Find(area);
52 if (indexOf != -1)
53 m_aAreas.Remove(indexOf);
54 }
55
56 //------------------------------------------------------------------------------------------------
58 void RegisterSpawnArea(SCR_CaptureAndHoldSpawnArea spawnArea)
59 {
60 m_aSpawnAreas.Insert(spawnArea);
61 }
62
63 //------------------------------------------------------------------------------------------------
65 void UnregisterSpawnArea(SCR_CaptureAndHoldSpawnArea spawnArea)
66 {
67 int indexOf = m_aSpawnAreas.Find(spawnArea);
68 if (indexOf != -1)
69 m_aSpawnAreas.Remove(indexOf);
70 }
71
72 //------------------------------------------------------------------------------------------------
75 {
76 return m_aAreas.Count();
77 }
78
79 //------------------------------------------------------------------------------------------------
82 {
83 return m_aSpawnAreas.Count();
84 }
85
86 //------------------------------------------------------------------------------------------------
92
93 //------------------------------------------------------------------------------------------------
95 SCR_CaptureAndHoldSpawnArea GetSpawnArea(int index)
96 {
97 return m_aSpawnAreas[index];
98 }
99
100 //------------------------------------------------------------------------------------------------
102 int GetAreas(notnull array<SCR_CaptureAndHoldArea> outAreas)
103 {
104 int count = 0;
105 foreach (SCR_CaptureAndHoldArea area : m_aAreas)
106 {
107 outAreas.Insert(area);
108 ++count;
109 }
110 return count;
111 }
112
113 //------------------------------------------------------------------------------------------------
115 int GetAreas(notnull array<SCR_CaptureAndHoldSpawnArea> outAreas)
116 {
117 int count = 0;
118 foreach (SCR_CaptureAndHoldSpawnArea area : m_aSpawnAreas)
119 {
120 outAreas.Insert(area);
121 ++count;
122 }
123 return count;
124 }
125
126 //------------------------------------------------------------------------------------------------
133
134 //------------------------------------------------------------------------------------------------
136 protected override void OnPostInit(IEntity owner)
137 {
138 super.OnPostInit(owner);
139 SetEventMask(owner, EntityEvent.INIT);
140
141 // This is not the best way of solving this problem,
142 // but for a small game mode like this it's completely fine.
144 }
145
146 //------------------------------------------------------------------------------------------------
148 protected override void OnDelete(IEntity owner)
149 {
150 super.OnDelete(owner);
151
153 }
154
155 //------------------------------------------------------------------------------------------------
157 protected void DoPanZoomMap(float x, float z, float zoom)
158 {
160 if (!mapEntity)
161 return;
162
163 // Zoom and pan to objectives almost immediately
164 mapEntity.ZoomPanSmooth(zoom, x, z, 0.001);
165 }
166
167 //------------------------------------------------------------------------------------------------
169 protected void OnMapOpen(MapConfiguration config)
170 {
171 // Get average of all positions
172 float x;
173 float z;
174 int count;
175 foreach (SCR_CaptureAndHoldArea area : m_aAreas)
176 {
177 vector worldPos = area.GetWorldObjectiveCenter();
178 x += worldPos[0];
179 z += worldPos[2];
180 ++count;
181 }
182
183 // No can do!
184 if (count == 0)
185 return;
186
187 x /= (float)count;
188 z /= (float)count;
189
191 if (!mapEntity)
192 return;
193
194 CanvasWidget mapWidget = mapEntity.GetMapWidget();
195 vector usize = mapWidget.GetSizeInUnits();
196 float zoomVal = usize[0] / (usize[0] * mapWidget.PixelPerUnit());
197
198 // Unfortunately we need to "override" the default respawn menu focus,
199 // currently not aware of a nicer way - perhaps it will begone in some future update :)
200 GetGame().GetCallqueue().CallLater(DoPanZoomMap, 100, false, x, z, zoomVal);
201 }
202
203 //------------------------------------------------------------------------------------------------
205 protected override void OnPlayerKilled(notnull SCR_InstigatorContextData instigatorContextData)
206 {
207 super.OnPlayerKilled(instigatorContextData);
208
209 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(instigatorContextData.GetVictimEntity());
210 if (!character)
211 return;
212
213 Faction faction = character.GetFaction();
214 if (!faction)
215 return;
216
217 foreach (SCR_SpawnArea area : m_aSpawnAreas)
218 {
219 Faction areaFaction = area.GetAffiliatedFaction();
220 if (!areaFaction)
221 continue;
222
223 if (!areaFaction.IsFactionFriendly(faction))
224 continue;
225
226 // We have to query ourselves, the character is dead and filtered out
227 if (!area.QueryEntityInside(character))
228 continue;
229
230 // Character died in a friendly spawn zone, therefore
231 // let's clear their respawn timer to reduce frustration
232 // of spawn / team kills
233 SCR_BaseGameMode gameMode = GetGameMode();
234 if (!gameMode)
235 return;
236
237 // Unless SCR_RespawnTimerComponent handles individual times on top of faction times,
238 // this will have no impact unfortunately
239 SCR_RespawnTimerComponent respawnTimer = SCR_RespawnTimerComponent.Cast(gameMode.FindComponent(SCR_RespawnTimerComponent));
240 if (!respawnTimer)
241 return;
242
243 // Reset to 0
244 respawnTimer.SetRespawnTime(instigatorContextData.GetVictimPlayerID(), 0.0);
245 }
246 }
247
248 //------------------------------------------------------------------------------------------------
250 static SCR_CaptureAndHoldManager GetAreaManager()
251 {
252 BaseGameMode gameMode = GetGame().GetGameMode();
253 if (!gameMode)
254 return null;
255
256 if (!s_Instance)
257 s_Instance = SCR_CaptureAndHoldManager.Cast(gameMode.FindComponent(SCR_CaptureAndHoldManager));
258
259 return s_Instance;
260 }
261
262
263 //------------------------------------------------------------------------------------------------
265 protected void SetWeather(string weatherId)
266 {
267 if (!m_pGameMode.IsMaster())
268 return;
269
270 if (weatherId.IsEmpty())
271 return;
272
273 ChimeraWorld world = GetOwner().GetWorld();
274 if (!world)
275 return;
276
277 TimeAndWeatherManagerEntity weatherManager = world.GetTimeAndWeatherManager();
278 if (!weatherManager)
279 {
280 Print("Cannot initialize weather: TimeAndWeatherManagerEntity not found!", LogLevel.WARNING);
281 return;
282 }
283
284 weatherManager.ForceWeatherTo(true, weatherId, 0.0);
285 }
286
287 //------------------------------------------------------------------------------------------------
289 protected void SetTimeOfTheDay(float timeOfTheDay)
290 {
291 if (!m_pGameMode.IsMaster())
292 return;
293
294 ChimeraWorld world = GetOwner().GetWorld();
295 if (!world)
296 return;
297
298 TimeAndWeatherManagerEntity weatherManager = world.GetTimeAndWeatherManager();
299 if (!weatherManager)
300 {
301 Print("Cannot initialize TimeOfTheDay: TimeAndWeatherManagerEntity not found!", LogLevel.WARNING);
302 return;
303 }
304
305 weatherManager.SetTimeOfTheDay(timeOfTheDay, true);
306 }
307
308 //------------------------------------------------------------------------------------------------
310 protected override void EOnInit(IEntity owner)
311 {
312 super.EOnInit(owner);
313
316
317 if (m_bUseCustomWeather)
319 }
320}
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_BaseGameModeComponentClass m_pGameMode
The game mode entity this component is attached to.
SCR_BaseGameMode GetGameMode()
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void OnMapOpen(MapConfiguration config)
void OnPlayerKilled(notnull SCR_InstigatorContextData instigatorContextData)
string m_sCustomWeatherId
Weather IDs are the same as used in the TimeAndWeatherManager. Weather set on game start....
SCR_CaptureAndHoldSpawnArea GetSpawnArea(int index)
Returns a spawn area at given index.
bool GetIsAreaFactionPersistent()
int GetAreas(notnull array< SCR_CaptureAndHoldArea > outAreas)
Fills the provided array with all registered zones and returns the count.
void SetTimeOfTheDay(float timeOfTheDay)
Forcefully sets time of the day to provided value. Authority only.
float m_fCustomTimeOfTheDay
Time of the day set on game start. Authority only.
SCR_CaptureAndHoldArea GetArea(int index)
Returns an area at given index.
void RegisterSpawnArea(SCR_CaptureAndHoldSpawnArea spawnArea)
Register a spawn area to this manager. Area must be unique.
bool m_bUseCustomTime
If enabled custom time of the day will be used on session start. Authority only.
void UnregisterArea(SCR_CaptureAndHoldArea area)
Unregisters a capture area from this manager.
int GetAreaCount()
Returns the number of registered capture areas.
bool m_bPersistentAreaFactions
If enabled then capture status is persistent.
void DoPanZoomMap(float x, float z, float zoom)
Pans the map to provided world coordinates.
void UnregisterSpawnArea(SCR_CaptureAndHoldSpawnArea spawnArea)
Unregisters a capture area from this manager.
ref array< SCR_CaptureAndHoldArea > m_aAreas
Array of all areas registered within this manager.
void SetWeather(string weatherId)
Forcefully sets weather to provided weatherId. Authority only.
ref array< SCR_CaptureAndHoldSpawnArea > m_aSpawnAreas
Array of all spawn areas registered within this manager.
void RegisterArea(SCR_CaptureAndHoldArea area)
Register a capture area to this manager. Area must be unique.
int GetSpawnAreaCount()
Returns the number of registered spawn areas.
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SCR_RespawnTimerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_SpawnerSlotManagerClass s_Instance
Class used for managing changes and removals of slots present in world.
proto external BaseWorld GetWorld()
CanvasWidget GetMapWidget()
Get map widget.
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapOpen()
Get on map open invoker.
void ZoomPanSmooth(float targetPixPerUnit, float worldX, float worldY, float zoomTime=0.25)
static SCR_MapEntity GetMapInstance()
Get map entity instance.
void ForceWeatherTo(bool setLooping, string weatherID=string.Empty, float transitionDuration=0, float stateDuration=0.001, int playerThatChangedWeather=0)
Definition float.c:13
IEntity GetOwner()
Owner entity of the fuel tank.
override void EOnInit(IEntity owner)
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
EntityEvent
Various entity events.
Definition EntityEvent.c:14