8 [
Attribute(defvalue:
"0",
desc:
"Order in which the faction appears in the list. Lower values are first.")]
9 protected int m_iOrder;
11 [
Attribute(
"1 1 1", UIWidgets.ColorPicker,
desc:
"Outline faction color")]
12 private ref Color m_OutlineFactionColor;
14 [
Attribute(defvalue:
"1",
desc:
"Will the faction appear in the respawn menu?")]
15 private bool m_bIsPlayable;
17 [
Attribute(
"", UIWidgets.ResourcePickerThumbnail,
"Flag icon of this particular faction.",
params:
"edds")]
18 private ResourceName m_sFactionFlag;
20 [
Attribute(
"", UIWidgets.ResourcePickerThumbnail,
"Faction flag material, used on flag poles.",
params:
"emat")]
21 protected ResourceName m_FactionFlagMaterial;
26 [
Attribute(
"1",
desc:
"If this is false it would mean that every AI will be hostile towards their own faction members and essentially allow for Deathmatch. Use with caution, only checked on init, you can still set the faction hostile towards itself in runtime. This essentially makes sure it adds itself to FriendlyFactionsIds.")]
27 protected bool m_bFriendlyToSelf;
29 [
Attribute(
desc:
"List of faction IDs that are considered friendly for this faction. Note: If factionA has factionB as friendly but FactionB does not have FactionA as friendly then they are still both set as friendly so for init it is only required for one faction.")]
30 protected ref array<string> m_aFriendlyFactionsIds;
36 protected ref array<ref SCR_GroupPreset> m_aPredefinedGroups;
39 protected bool m_bCreateOnlyPredefinedGroups;
42 protected string m_sFactionRadioEncryptionKey;
45 protected int m_iFactionRadioFrequency;
47 protected ref array<string>> m_aAncestors;
51 protected ref array<ref SCR_CharacterRank> m_aRanks;
53 [
Attribute(
desc:
"List of Entity catalogs. Each holds a list of entity Prefab and data of a given type. Catalogs of the same type are merged into one. Note this array is moved to a map on init and set to null")]
54 protected ref array<ref SCR_EntityCatalog> m_aEntityCatalogs;
56 [
Attribute(
"", UIWidgets.ResourcePickerThumbnail,
"Flag icons for group.",
params:
"edds")]
57 protected ref array<ResourceName> m_aGroupFlags;
59 [
Attribute(
"", UIWidgets.ResourcePickerThumbnail,
"Flag imageset for groups of this faction.",
params:
"imageset")]
60 protected ResourceName m_sGroupFlagsImageSet;
63 protected ref array<string> m_aFlagNames;
66 protected ref array<ref SCR_MilitaryBaseCallsign> m_aBaseCallsigns;
69 protected ref map<EEntityCatalogType, ref SCR_EntityCatalog> m_mEntityCatalogs =
new map<EEntityCatalogType, ref SCR_EntityCatalog>();
71 protected bool m_bCatalogInitDone;
73 protected ref set<Faction> m_FriendlyFactions =
new set<Faction>;
89 bool GetCanCreateOnlyPredefinedGroups()
96 void GetPredefinedGroups(notnull array<ref SCR_GroupPreset> groupArray)
107 ResourceName GetFlagName(
int index)
115 int GetFlagNames(out array<string> flagNames)
122 ResourceName GetGroupFlagImageSet()
130 int GetGroupFlagTextures(out array<ResourceName> textures)
137 ResourceName GetFactionFlag()
144 ResourceName GetFactionFlagMaterial()
151 void SetFactionFlagMaterial(ResourceName materialResource)
172 Color GetOutlineFactionColor()
180 void InitializeFaction()
186 void SetAncestors(notnull array<string> ancestors)
216 void InitFactionIsPlayable(
bool isPlayable)
231 bool IsInherited(
string factionKey)
248 void SetIsPlayable(
bool isPlayable,
bool killPlayersIfNotPlayable =
false)
250 if (m_bIsPlayable == isPlayable)
254 if (!factionManager || !factionManager.CanChangeFactionsPlayable())
258 if (m_OnFactionPlayableChanged)
262 if (!m_bIsPlayable && killPlayersIfNotPlayable && Replication.IsServer())
264 array<int> playerList = {};
265 GetGame().GetPlayerManager().GetPlayers(playerList);
268 IEntity playerEntity;
270 foreach (
int playerId : playerList)
272 Faction playerFaction = factionManager.GetPlayerFaction(playerId);
286 if (!editorManager.IsLimited())
291 playerEntity = SCR_PossessingManagerComponent.GetPlayerMainEntity(playerId);
297 damageManager.SetHealthScaled(0);
312 if (!m_OnFactionPlayableChanged)
324 override bool DoCheckIfFactionFriendly(
Faction faction)
339 void SetFactionFriendly(notnull
Faction faction)
354 void SetFactionHostile(notnull
Faction faction)
375 return factionManager.GetFactionPlayerCount(
this);
406 int GetPlayersInFaction(notnull out array<int> players)
414 array<int> allPlayers = {};
415 GetGame().GetPlayerManager().GetPlayers(allPlayers);
417 foreach (
int playerId : allPlayers)
419 Faction playerFaction = factionManager.GetPlayerFaction(playerId);
420 if (playerFaction ==
this)
421 players.Insert(playerId);
424 return players.Count();
429 string GetFactionRadioEncryptionKey()
436 int GetFactionRadioFrequency()
449 if (rank.GetRankID() == rankID)
464 return rank.GetRankName();
477 return rank.GetRankNameUpperCase();
490 return rank.GetRankNameShort();
503 return rank.GetRankInsignia();
523 if (!m_bCatalogInitDone)
525 Debug.Error2(
"SCR_EntityCatalogManagerComponent",
"Trying to obtain catalog of type: '" +
typename.EnumToString(
EEntityCatalogType, catalogType) +
"' (faction: " +
GetFactionKey() +
") but catalog is not yet initialized! Call your function one frame later!");
533 return entityCatalog;
536 Print(
string.Format(
"'SCR_Faction' trying to get entity list of type '%1' but there is no catalog with that type for faction '%2'",
typename.EnumToString(
EEntityCatalogType, catalogType),
GetFactionKey()), LogLevel.WARNING);
551 int GetAllFactionEntityCatalogs(notnull out array<SCR_EntityCatalog> outEntityCatalogs)
553 outEntityCatalogs.Clear();
556 outEntityCatalogs.Insert(entityCatalog);
559 return outEntityCatalogs.Count();
563 override void Init(IEntity owner)
576 SetFactionFriendly(
this);
578 Print(
"'SCR_Faction' is trying to set friendly factions but no SCR_FactionManager could be found!", LogLevel.ERROR);
583 if (m_bFriendlyToSelf)
584 factionManager.SetFactionsFriendly(
this,
this);
592 foreach (
string factionId : m_aFriendlyFactionsIds)
594 faction =
SCR_Faction.Cast(factionManager.GetFactionByKey(factionId));
598 Print(
string.Format(
"'SCR_Faction' is trying to set friendly factions on init but '%1' is not a valid SCR_Faction!", factionId), LogLevel.ERROR);
607 factionManager.SetFactionsFriendly(
this, faction);
613 SCR_EntityCatalogManagerComponent.InitCatalogs(m_aEntityCatalogs, m_mEntityCatalogs);
624 static Faction GetEntityFaction(notnull IEntity entity)
626 FactionAffiliationComponent factionComp = FactionAffiliationComponent.Cast(entity.FindComponent(FactionAffiliationComponent));
630 Faction faction = factionComp.GetAffiliatedFaction();
632 faction = factionComp.GetDefaultAffiliatedFaction();
639 array<int> GetBaseCallsignIndexes()
641 array<int> indexes = {};
643 foreach (SCR_MilitaryBaseCallsign callsign : m_aBaseCallsigns)
645 indexes.Insert(callsign.GetSignalIndex());
655 SCR_MilitaryBaseCallsign GetBaseCallsignByIndex(
int index,
int offset = 0)
673 class SCR_MilitaryBaseCallsign
676 protected string m_sCallsign;
679 protected string m_sCallsignShort;
682 protected string m_sCallsignUpperCase;
685 protected int m_iSignalIndex;
696 string GetCallsignShort()
698 return m_sCallsignShort;
703 string GetCallsignUpperCase()
705 return m_sCallsignUpperCase;
712 return m_iSignalIndex;