Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SpawnerAIGroupManager.c
Go to the documentation of this file.
2 {
3 }
4 
5 class SCR_SpawnerAIGroupManagerComponent : SCR_BaseGameModeComponent
6 {
7  [Attribute(defvalue: "1.5", params: "0.1 inf", desc: "Delay between spawning group members.")]
8  protected float m_fGroupMemberSpawnDelay;
9 
10  [RplProp()]
11  protected bool m_bIsAtAILimit;
12 
13  protected ref array<ref SCR_SpawnerAIRequest> m_aAIQueue;
14  protected float m_fCurrentGroupMemberSpawnDelay;
15 
16  //------------------------------------------------------------------------------------------------
18  void SetIsAtAILimit(bool value)
19  {
20  m_bIsAtAILimit = value;
21  Replication.BumpMe();
22  }
23 
24  //------------------------------------------------------------------------------------------------
26  bool IsAtAILimit()
27  {
28  return m_bIsAtAILimit;
29  }
30 
31  //------------------------------------------------------------------------------------------------
38  void QueueSpawn(notnull SCR_CatalogEntitySpawnerComponent spawner, ResourceName resName, notnull IEntity user, notnull IEntity slotEntity, notnull SCR_EntityLabelPointComponent rallyPoint)
39  {
40  if (!GetGameMode().IsMaster())
41  return;
42 
43  if (SCR_StringHelper.IsEmptyOrWhiteSpace(resName))
44  {
45  Print("'SCR_SpawnerAIGroupManagerComponent' resName is empty!", LogLevel.ERROR);
46  return;
47  }
48 
49  if (!m_aAIQueue)
50  m_aAIQueue = new array<ref SCR_SpawnerAIRequest>;
51 
52  m_aAIQueue.Insert(new SCR_SpawnerAIRequest(spawner, resName, user, slotEntity, rallyPoint));
53 
54  if (m_aAIQueue.Count() == 1)
55  SetEventMask(GetOwner(), EntityEvent.FRAME);
56  }
57 
58  //------------------------------------------------------------------------------------------------
59  protected void OnAgentsUpdated(AIAgent agent)
60  {
61  AIWorld aiWorld = GetGame().GetAIWorld();
62  if (!aiWorld && m_bIsAtAILimit)
63  {
64  SetIsAtAILimit(false);
65  return;
66  }
67 
68  bool change = (aiWorld.GetCurrentAmountOfLimitedAIs() + 1) >= aiWorld.GetAILimit();
69 
70  //No need to replicate something that didn't change
71  if (change == m_bIsAtAILimit)
72  return;
73 
74  SetIsAtAILimit(change);
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  override void EOnFrame(IEntity owner, float timeSlice)
79  {
80  m_fCurrentGroupMemberSpawnDelay += timeSlice;
81  if (m_fCurrentGroupMemberSpawnDelay < m_fGroupMemberSpawnDelay)
82  return;
83 
84  SCR_SpawnerAIRequest spawnerRequest = m_aAIQueue[0];
85 
86  spawnerRequest.m_Spawner.SpawnAIGroupMember(spawnerRequest.m_ResourceName, spawnerRequest.m_UserEntity, spawnerRequest.m_SlotEntity, spawnerRequest.m_RallyPoint);
87  m_aAIQueue.RemoveOrdered(0);
88  m_fCurrentGroupMemberSpawnDelay = 0;
89 
90  if (m_aAIQueue.IsEmpty())
91  ClearEventMask(owner, EntityEvent.FRAME);
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  override void EOnInit(IEntity owner)
96  {
97  if (!SCR_AIWorld.Cast(GetGame().GetAIWorld()))
98  return;
99 
100  SCR_AIWorld.s_OnAgentSpawned.Insert(OnAgentsUpdated);
101  SCR_AIWorld.s_OnAgentRemoved.Insert(OnAgentsUpdated);
102  }
103 
104  //------------------------------------------------------------------------------------------------
105  override void OnPostInit(IEntity owner)
106  {
107  SetEventMask(owner, EntityEvent.INIT);
108  }
109 
110  //------------------------------------------------------------------------------------------------
111  // destructor
113  {
114  if (!SCR_AIWorld.Cast(GetGame().GetAIWorld()))
115  return;
116 
117  SCR_AIWorld.s_OnAgentSpawned.Remove(OnAgentsUpdated);
118  SCR_AIWorld.s_OnAgentRemoved.Remove(OnAgentsUpdated);
119  }
120 }
121 
123 {
124  SCR_CatalogEntitySpawnerComponent m_Spawner;
125  ResourceName m_ResourceName;
126  IEntity m_UserEntity;
127  IEntity m_SlotEntity;
128  SCR_EntityLabelPointComponent m_RallyPoint;
129 
130  //------------------------------------------------------------------------------------------------
131  // constructor
137  void SCR_SpawnerAIRequest(SCR_CatalogEntitySpawnerComponent spawner, ResourceName resName, IEntity userEntity, IEntity slotEntity, SCR_EntityLabelPointComponent labelComp)
138  {
139  m_Spawner = spawner;
140  m_ResourceName = resName;
141  m_UserEntity = userEntity;
142  m_SlotEntity = slotEntity;
143  m_RallyPoint = labelComp;
144  }
145 }
IsMaster
protected bool IsMaster()
Definition: SCR_DataCollectorComponent.c:190
OnAgentsUpdated
protected void OnAgentsUpdated(AIAgent agent)
Definition: SCR_SpawnerAIGroupManager.c:59
IsAtAILimit
bool IsAtAILimit()
Definition: SCR_SpawnerAIGroupManager.c:26
Attribute
SCR_SpawnerAIGroupManagerComponentClass SCR_BaseGameModeComponentClass Attribute(defvalue:"1.5", params:"0.1 inf", desc:"Delay between spawning group members.")
Definition: SCR_SpawnerAIGroupManager.c:7
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
~SCR_SpawnerAIGroupManagerComponent
void ~SCR_SpawnerAIGroupManagerComponent()
Definition: SCR_SpawnerAIGroupManager.c:112
SCR_StringHelper
Definition: SCR_StringHelper.c:1
EOnFrame
override void EOnFrame(IEntity owner, float timeSlice)
Definition: SCR_SpawnerAIGroupManager.c:78
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_SpawnerAIGroupManagerComponentClass
Definition: SCR_SpawnerAIGroupManager.c:1
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
SCR_AIWorld
Definition: SCR_AIWorld.c:23
QueueSpawn
void QueueSpawn(notnull SCR_CatalogEntitySpawnerComponent spawner, ResourceName resName, notnull IEntity user, notnull IEntity slotEntity, notnull SCR_EntityLabelPointComponent rallyPoint)
Definition: SCR_SpawnerAIGroupManager.c:38
SCR_SpawnerAIRequest
Definition: SCR_SpawnerAIGroupManager.c:122
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_SpawnerAIGroupManager.c:105
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_SpawnerAIGroupManager.c:95
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_BaseGameModeComponentClass
Definition: SCR_BaseGameModeComponent.c:2
SCR_BaseGameModeComponent
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_BaseGameModeComponent.c:199