Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RestrictedDeployableSpawnPoint.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/DeployableItems", description: "", visible: false)]
3 {
4 };
5 
6 //------------------------------------------------------------------------------------------------
9 {
10  [RplProp()]
11  protected bool m_bAllowAllGroupsToSpawn;
12 
13  [RplProp()]
14  protected int m_iGroupID = -1;
15 
16  protected int m_iMaxRespawns;
17 
18  protected int m_iRespawnCount;
19 
20  //------------------------------------------------------------------------------------------------
21  protected bool CanSpawn(notnull array<SCR_ChimeraCharacter> characters, Faction spawnPointFaction, vector spawnPointOrigin)
22  {
23  SCR_RestrictedDeployableSpawnPointComponent restrictedDeployableSpawnPointComp = SCR_RestrictedDeployableSpawnPointComponent.Cast(m_DeployableSpawnPointComp);
24  if (!restrictedDeployableSpawnPointComp)
25  return false;
26 
27  if (restrictedDeployableSpawnPointComp.GetIgnoreEnemyCharacters())
28  return true;
29 
30  int friendlyCharactersCount, enemyCharactersCount = 0;
31 
32  foreach (SCR_ChimeraCharacter character : characters)
33  {
34  if (character.GetCharacterController().IsDead())
35  continue;
36 
37  float distanceToItemSq = (spawnPointOrigin - character.GetOrigin()).LengthSq();
38  float queryRadius = restrictedDeployableSpawnPointComp.GetQueryRadiusCharacters();
39  float queryRadiusSq = queryRadius * queryRadius;
40 
41  if (distanceToItemSq > queryRadiusSq)
42  continue;
43 
44  SCR_Faction faction = SCR_Faction.Cast(SCR_Faction.GetEntityFaction(character));
45 
46  if (faction.DoCheckIfFactionFriendly(spawnPointFaction))
47  friendlyCharactersCount++;
48  else
49  enemyCharactersCount++;
50  }
51 
52  return friendlyCharactersCount - enemyCharactersCount >= 0;
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  override bool IsSpawnPointVisibleForPlayer(int pid)
57  {
58  if (m_bAllowAllGroupsToSpawn)
59  return true;
60 
61  /*PlayerManager playerManager = GetGame().GetPlayerManager();
62  if (!playerManager)
63  return false;
64 
65  IEntity playerEntity = playerManager.GetPlayerControlledEntity(pid);
66  if (!playerEntity)
67  return false;
68 
69  FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(playerEntity.FindComponent(FactionAffiliationComponent));
70  if (!factionAffiliation)
71  return false;
72 
73  Faction playerFaction = factionAffiliation.GetAffiliatedFaction();
74  if (!playerFaction)
75  return false;
76 
77  FactionManager factionManager = GetGame().GetFactionManager();
78  if (!factionManager)
79  return false;
80 
81  SCR_Faction faction = SCR_Faction.Cast(factionManager.GetFactionByKey(GetFactionKey()));
82 
83  if (!faction.DoCheckIfFactionFriendly(playerFaction))
84  return false;*/
85 
86  SCR_PlayerControllerGroupComponent playerControllerGroupComp = SCR_PlayerControllerGroupComponent.GetPlayerControllerComponent(pid);
87  if (!playerControllerGroupComp)
88  return false;
89 
90  int localPlayerGroupID = playerControllerGroupComp.GetGroupID();
91 
92  return m_iGroupID == localPlayerGroupID;
93  }
94 
95  //------------------------------------------------------------------------------------------------
96  override void OnFinalizeSpawnDone_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnData data, IEntity entity)
97  {
98  super.OnFinalizeSpawnDone_S(requestComponent, data, entity);
99 
100  m_iRespawnCount++;
101 
102  SCR_RestrictedDeployableSpawnPointComponent restrictedDeployableSpawnPointComp = SCR_RestrictedDeployableSpawnPointComponent.Cast(m_DeployableSpawnPointComp);
103  if (!restrictedDeployableSpawnPointComp)
104  return;
105 
106  restrictedDeployableSpawnPointComp.SetRespawnCount(m_iRespawnCount);
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  override bool CanReserveFor_S(int playerId, out SCR_ESpawnResult result = SCR_ESpawnResult.SPAWN_NOT_ALLOWED)
111  {
112  if (!super.CanReserveFor_S(playerId, result))
113  return false;
114 
115  // Deny spawning when respawn limit is reached
116  if (m_iRespawnCount >= m_iMaxRespawns)
117  {
118  result = SCR_ESpawnResult.NOT_ALLOWED_SPAWNPOINT_DISABLED_OUT_OF_RESPAWNS;
119  return false;
120  }
121 
122  // Deny spawning when enemies are near spawnpoint
123  array<SCR_ChimeraCharacter> characters = SCR_CharacterRegistrationComponent.GetChimeraCharacters();
124 
125  FactionManager factionManager = GetGame().GetFactionManager();
126  if (!factionManager)
127  return false;
128 
129  SCR_Faction faction = SCR_Faction.Cast(factionManager.GetFactionByKey(GetFactionKey()));
130 
131  if (!CanSpawn(characters, faction, GetOrigin()))
132  {
133  result = SCR_ESpawnResult.NOT_ALLOWED_SPAWNING_DISABLED_ENEMIES_NEARBY;
134  return false;
135  }
136 
137  return true;
138  }
139 
140  //------------------------------------------------------------------------------------------------
141  void SetAllowAllGroupsToSpawn(bool allowAllGroupsToSpawn)
142  {
143  m_bAllowAllGroupsToSpawn = allowAllGroupsToSpawn;
144  Replication.BumpMe();
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  void SetGroupID(int groupID)
149  {
150  m_iGroupID = groupID;
151  Replication.BumpMe();
152  }
153 
154  //------------------------------------------------------------------------------------------------
155  int GetMaxRespawns()
156  {
157  return m_iMaxRespawns;
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  void SetMaxRespawns(int maxRespawns)
162  {
163  m_iMaxRespawns = maxRespawns;
164  }
165 
166  //------------------------------------------------------------------------------------------------
167  int GetRespawnCount()
168  {
169  return m_iRespawnCount;
170  }
171 
172  //------------------------------------------------------------------------------------------------
173  void SetRespawnCount(int respawnCount)
174  {
175  m_iRespawnCount = respawnCount;
176  }
177 }
SCR_ESpawnResult
SCR_ESpawnResult
Definition: SCR_ESpawnResult.c:8
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SpawnData
Definition: SCR_SpawnData.c:9
SCR_RestrictedDeployableSpawnPointClass
Definition: SCR_RestrictedDeployableSpawnPoint.c:2
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
SCR_CharacterRegistrationComponent
void SCR_CharacterRegistrationComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_CharacterRegistrationComponent.c:48
SCR_RestrictedDeployableSpawnPoint
Basically SCR_SpawnPoint with the ability to limit respawn amount.
Definition: SCR_RestrictedDeployableSpawnPoint.c:8
SCR_DeployableSpawnPointClass
Definition: SCR_DeployableSpawnPoint.c:2
m_iRespawnCount
protected int m_iRespawnCount
Definition: SCR_RestrictedDeployableSpawnPointComponent.c:82
m_iGroupID
SCR_PlayerControllerGroupComponentClass m_iGroupID
GetFactionKey
protected FactionKey GetFactionKey()
Definition: SCR_ScenarioFrameworkLayerBase.c:248
Faction
Definition: Faction.c:12
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
SCR_Faction
Definition: SCR_Faction.c:6
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_DeployableSpawnPoint
Definition: SCR_DeployableSpawnPoint.c:11