Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_GameModeLastStand.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4 };
5 
6 //------------------------------------------------------------------------------------------------
8 {
9  [Attribute("10", UIWidgets.EditBox, "How long between clearing the last wave and a new one")]
10  float m_TimeoutBetweenWaves;
11 
12  [Attribute("4", UIWidgets.EditBox, "How many groups spawned each wave")]
13  int m_InitialGroupsCount;
14 
15  [Attribute("1", UIWidgets.EditBox, "How many new groups should spawn each round")]
16  int m_AddedGroupsPerRound;
17 
18  [Attribute("", UIWidgets.ResourceNamePicker, "What group type should spawn")]
19  ResourceName m_GroupType;
20 
21  [Attribute("USSR", UIWidgets.EditBox, "Enemy faction key")]
22  protected FactionKey m_sEnemyFactionKey;
23 
24  [Attribute("US", UIWidgets.EditBox, "Friendly faction key")]
25  protected FactionKey m_sFriendlyFactionKey;
26 
27  int m_iGroupsToSpawn;
28  int m_iRoundNumber;
29 
30  Widget m_wRoot;
31  TextWidget m_wText;
32  ref array<IEntity> m_aEnemySoldiers;
33  ref array<SCR_AIGroup> m_aGroups;
34  ref array<SCR_SpawnPoint> m_aEnemySpawnPoints;
35  ref array<SCR_SpawnPoint> m_aPlayerSpawnPoints;
36  float m_fCurrentTimeout;
37  AIWaypoint m_AttackWP;
38 
39  //------------------------------------------------------------------------------------------------
40  override void EOnFrame(IEntity owner, float timeSlice)
41  {
42  //PrintString("printing");
43  super.EOnFrame(owner, timeSlice);
44 
45  if (m_fCurrentTimeout > 0)
46  {
47  m_fCurrentTimeout -= timeSlice;
48  if (m_fCurrentTimeout < 0)
49  {
50  m_fCurrentTimeout = 0;
51  m_iRoundNumber++;
52  if (m_iRoundNumber > 0)
53  {
54  SpawnEnemies(m_iRoundNumber);
55  Print("Sending next wave of enemies.");
56  ShowHint("Sending next wave of enemies.", 5);
57  }
58  }
59  }
60  else if (m_aEnemySoldiers.Count() == 0)
61  {
62  Print("All enemies are dead. Wave cleared.");
63  ShowHint("All enemies are dead. Wave cleared.", 5);
64  m_fCurrentTimeout = m_TimeoutBetweenWaves;
65  }
66  }
67 
68  //------------------------------------------------------------------------------------------------
69  void ShowHint(string text, float showTime)
70  {
71  if (!m_wText || !m_wRoot)
72  return;
73 
74  m_wText.SetText(text);
75  AnimateWidget.Opacity(m_wRoot, 1, 1);
76 
77  ScriptCallQueue queue = GetGame().GetCallqueue();
78  queue.CallLater(this.HideHint, showTime * 1000);
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  void HideHint()
83  {
84  if (m_wRoot)
85  AnimateWidget.Opacity(m_wRoot, 0, 1);
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  void SpawnEnemies(int round)
90  {
91  if (m_aEnemySpawnPoints.Count() == 0)
92  return;
93 
94  // Clean up groups
95  for (int i = m_aGroups.Count() - 1; i >= 0; i--)
96  {
97  delete m_aGroups[i];
98  }
99  m_aGroups.Clear();
100  m_aEnemySoldiers.Clear();
101 
102  m_iGroupsToSpawn = m_InitialGroupsCount + (round - 1) * m_AddedGroupsPerRound;
103 
104  for (int i = 0; i < m_iGroupsToSpawn; i++)
105  {
106  RandomGenerator generator = new RandomGenerator;
107  generator.SetSeed(Math.RandomInt(0,100));
108 
109  SCR_SpawnPoint spawnPoint = m_aEnemySpawnPoints.GetRandomElement();
110  if (!spawnPoint)
111  return;
112 
113  vector position = generator.GenerateRandomPointInRadius(0, 2, spawnPoint.GetOrigin());
114  position[1] = spawnPoint.GetOrigin()[1];
115  EntitySpawnParams params = EntitySpawnParams();
116  params.TransformMode = ETransformMode.WORLD;
117  params.Transform[3] = position;
118 
119  Resource res = Resource.Load(m_GroupType);
120  SCR_AIGroup newGrp = SCR_AIGroup.Cast(GetGame().SpawnEntityPrefab(res, null, params));
121  m_aGroups.Insert(newGrp);
122 
123  array<AIAgent> agents = new array<AIAgent>;
124 
125  newGrp.GetAgents(agents);
126  foreach (AIAgent agent : agents)
127  {
128  if (agent)
129  {
130  m_aEnemySoldiers.Insert(agent.GetControlledEntity());
131  }
132  }
133 
134  if (m_AttackWP)
135  {
136  newGrp.AddWaypointToGroup(m_AttackWP);
137  }
138  }
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  override void OnControllableDestroyed(IEntity entity, IEntity killerEntity, notnull Instigator instigator)
143  {
144  super.OnControllableDestroyed(entity, killerEntity, instigator);
145 
146  m_aEnemySoldiers.RemoveItemOrdered(entity);
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  override void EOnInit(IEntity owner)
151  {
152  super.EOnInit(owner);
153 
154  m_fCurrentTimeout = m_TimeoutBetweenWaves;
155 
156  m_wRoot = GetGame().GetWorkspace().CreateWidgets("{EA1CC57D868E94F9}UI/layouts/HUD/Hint.layout");
157  if (m_wRoot)
158  {
159  m_wText = TextWidget.Cast(m_wRoot.FindAnyWidget("Text"));
160  TextWidget title = TextWidget.Cast(m_wRoot.FindAnyWidget("Title"));
161  if (title)
162  title.SetText("LAST STAND");
163 
164  m_wRoot.SetOpacity(0);
165  }
166  BaseWorld world = owner.GetWorld();
167  m_AttackWP = AIWaypoint.Cast(world.FindEntityByName("WP1"));
168  m_aEnemySoldiers = new array<IEntity>;
169  m_aGroups = new array<SCR_AIGroup>;
170  m_aPlayerSpawnPoints = new array<SCR_SpawnPoint>;
171  m_aEnemySpawnPoints = new array<SCR_SpawnPoint>;
172  array<SCR_SpawnPoint> spawnPoints = new array<SCR_SpawnPoint>;
173  spawnPoints = SCR_SpawnPoint.GetSpawnPoints();
174 
175  for (int i = spawnPoints.Count() - 1; i >= 0; i--)
176  {
177  SCR_SpawnPoint spawnPoint = SCR_SpawnPoint.Cast(spawnPoints[i]);
178  if (spawnPoint)
179  {
180  FactionKey faction = spawnPoint.GetFactionKey();
181  if (faction == m_sEnemyFactionKey)
182  m_aEnemySpawnPoints.Insert(spawnPoint);
183 
184  if (faction == m_sFriendlyFactionKey)
185  m_aPlayerSpawnPoints.Insert(spawnPoint);
186  }
187  }
188  }
189 };
190 
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_GameModeLastStand
Definition: SCR_GameModeLastStand.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
Instigator
Definition: Instigator.c:6
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_BaseGameModeClass
Definition: SCR_BaseGameMode.c:12
SCR_GameModeLastStandClass
Definition: SCR_GameModeLastStand.c:2
SCR_AIGroup
Definition: SCR_AIGroup.c:68
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
position
vector position
Definition: SCR_DestructibleTreeV2.c:30