9 [
Attribute(
"10", UIWidgets.EditBox,
"How long between clearing the last wave and a new one")]
10 float m_TimeoutBetweenWaves;
12 [
Attribute(
"4", UIWidgets.EditBox,
"How many groups spawned each wave")]
13 int m_InitialGroupsCount;
15 [
Attribute(
"1", UIWidgets.EditBox,
"How many new groups should spawn each round")]
16 int m_AddedGroupsPerRound;
18 [
Attribute(
"", UIWidgets.ResourceNamePicker,
"What group type should spawn")]
19 ResourceName m_GroupType;
21 [
Attribute(
"USSR", UIWidgets.EditBox,
"Enemy faction key")]
22 protected FactionKey m_sEnemyFactionKey;
24 [
Attribute(
"US", UIWidgets.EditBox,
"Friendly faction key")]
25 protected FactionKey m_sFriendlyFactionKey;
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;
40 override void EOnFrame(IEntity owner,
float timeSlice)
43 super.EOnFrame(owner, timeSlice);
45 if (m_fCurrentTimeout > 0)
47 m_fCurrentTimeout -= timeSlice;
48 if (m_fCurrentTimeout < 0)
50 m_fCurrentTimeout = 0;
52 if (m_iRoundNumber > 0)
54 SpawnEnemies(m_iRoundNumber);
55 Print(
"Sending next wave of enemies.");
56 ShowHint(
"Sending next wave of enemies.", 5);
60 else if (m_aEnemySoldiers.Count() == 0)
62 Print(
"All enemies are dead. Wave cleared.");
63 ShowHint(
"All enemies are dead. Wave cleared.", 5);
64 m_fCurrentTimeout = m_TimeoutBetweenWaves;
69 void ShowHint(
string text,
float showTime)
74 m_wText.SetText(text);
75 AnimateWidget.Opacity(
m_wRoot, 1, 1);
77 ScriptCallQueue queue =
GetGame().GetCallqueue();
78 queue.CallLater(this.HideHint, showTime * 1000);
85 AnimateWidget.Opacity(
m_wRoot, 0, 1);
89 void SpawnEnemies(
int round)
91 if (m_aEnemySpawnPoints.Count() == 0)
95 for (
int i = m_aGroups.Count() - 1; i >= 0; i--)
100 m_aEnemySoldiers.Clear();
102 m_iGroupsToSpawn = m_InitialGroupsCount + (round - 1) * m_AddedGroupsPerRound;
104 for (
int i = 0; i < m_iGroupsToSpawn; i++)
106 RandomGenerator generator =
new RandomGenerator;
107 generator.SetSeed(Math.RandomInt(0,100));
109 SCR_SpawnPoint spawnPoint = m_aEnemySpawnPoints.GetRandomElement();
113 vector
position = generator.GenerateRandomPointInRadius(0, 2, spawnPoint.GetOrigin());
114 position[1] = spawnPoint.GetOrigin()[1];
115 EntitySpawnParams
params = EntitySpawnParams();
116 params.TransformMode = ETransformMode.WORLD;
119 Resource res = Resource.Load(m_GroupType);
121 m_aGroups.Insert(newGrp);
123 array<AIAgent> agents =
new array<AIAgent>;
125 newGrp.GetAgents(agents);
126 foreach (AIAgent agent : agents)
130 m_aEnemySoldiers.Insert(agent.GetControlledEntity());
136 newGrp.AddWaypointToGroup(m_AttackWP);
142 override void OnControllableDestroyed(IEntity entity, IEntity killerEntity, notnull
Instigator instigator)
144 super.OnControllableDestroyed(entity, killerEntity, instigator);
146 m_aEnemySoldiers.RemoveItemOrdered(entity);
150 override void EOnInit(IEntity owner)
152 super.EOnInit(owner);
154 m_fCurrentTimeout = m_TimeoutBetweenWaves;
156 m_wRoot =
GetGame().GetWorkspace().CreateWidgets(
"{EA1CC57D868E94F9}UI/layouts/HUD/Hint.layout");
159 m_wText = TextWidget.Cast(
m_wRoot.FindAnyWidget(
"Text"));
160 TextWidget title = TextWidget.Cast(
m_wRoot.FindAnyWidget(
"Title"));
162 title.SetText(
"LAST STAND");
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>;
175 for (
int i = spawnPoints.Count() - 1; i >= 0; i--)
180 FactionKey faction = spawnPoint.GetFactionKey();
181 if (faction == m_sEnemyFactionKey)
182 m_aEnemySpawnPoints.Insert(spawnPoint);
184 if (faction == m_sFriendlyFactionKey)
185 m_aPlayerSpawnPoints.Insert(spawnPoint);