18 protected ResourceName m_FactionDelegatePrefab;
20 protected ref map<Faction, SCR_EditableFactionComponent> m_FactionDelegates =
new map<Faction, SCR_EditableFactionComponent>;
29 FactionManager factionManager =
GetGame().GetFactionManager();
40 int GetFactionDelegates(notnull out map<Faction, SCR_EditableFactionComponent> outDelegates)
42 int count = m_FactionDelegates.Count();
43 for (
int i = 0; i < count; i++)
45 outDelegates.Insert(m_FactionDelegates.GetKey(i), m_FactionDelegates.GetElement(i));
54 int GetSortedFactionDelegates(notnull out SCR_SortedArray<SCR_EditableFactionComponent> outDelegates)
56 int count = m_FactionDelegates.Count();
58 SCR_EditableFactionComponent factionDelegate;
59 for (
int i = 0; i < count; i++)
61 factionDelegate = m_FactionDelegates.GetElement(i);
63 faction =
SCR_Faction.Cast(factionDelegate.GetFaction());
65 order = faction.GetOrder();
67 outDelegates.Insert(order, factionDelegate);
75 int GetFactionDelegateCount()
77 return m_FactionDelegates.Count();
83 int GetPlayableFactionDelegates(notnull out map<Faction, SCR_EditableFactionComponent> outDelegates)
85 foreach (
Faction faction, SCR_EditableFactionComponent delegate: m_FactionDelegates)
88 if (scrFaction && scrFaction.IsPlayable())
90 outDelegates.Insert(scrFaction, delegate);
94 return outDelegates.Count();
100 int GetPlayableFactionDelegateCount()
104 foreach (
Faction faction, SCR_EditableFactionComponent delegate: m_FactionDelegates)
107 if (scrFaction && scrFaction.IsPlayable())
118 SCR_EditableFactionComponent GetFactionDelegate(
Faction faction)
120 return m_FactionDelegates.Get(faction);
127 void SetFactionDelegate(
Faction faction, SCR_EditableFactionComponent delegate)
129 m_FactionDelegates.Set(faction, delegate);
132 override void OnFactionsInit(array<Faction> factions)
134 if (
SCR_Global.IsEditMode(
GetOwner()) || factions.IsEmpty() || (Replication.IsClient() && Replication.Runtime()))
137 Resource entityResource = Resource.Load(m_FactionDelegatePrefab);
139 if (!componentSource)
141 Print(
string.Format(
"SCR_EditableFactionComponent missing in '%1'!", m_FactionDelegatePrefab.GetPath()), LogLevel.WARNING);
145 SCR_EditableFactionComponent editableEntity;
146 foreach (
int i,
Faction faction: factions)
148 IEntity delegateEntity =
GetGame().SpawnEntityPrefab(entityResource);
149 editableEntity = SCR_EditableFactionComponent.Cast(SCR_EditableFactionComponent.GetEditableEntity(delegateEntity));
150 editableEntity.SetFactionIndex(i);