21 array<Faction> factions();
22 factionManager.GetFactionsList(factions);
24 array<ref SCR_PersistentFaction> changedFactions();
27 foreach (
auto faction : factions)
29 friendlyDefaultMapping.Insert(faction.GetFactionKey(),
new set<FactionKey>);
32 for (
int i = 0, count = factions.Count(); i < count; ++i)
38 const FactionKey key = faction.GetFactionKey();
42 set<FactionKey> friendlies = friendlyDefaultMapping.Get(key);
44 if (defaultFriendlySelf)
45 friendlies.Insert(key);
47 foreach (
auto friendly : defaultFriendlies)
49 friendlies.Insert(friendly);
52 set<FactionKey> reverseMapping = friendlyDefaultMapping.Get(friendly);
54 reverseMapping.Insert(key);
58 for (
int i = 0, count = factions.Count(); i < count; ++i)
64 const FactionKey key = faction.GetFactionKey();
66 array<FactionKey> friendlyFactions();
67 foreach (
int idx,
auto otherFaction : factions)
69 if (faction.IsFactionFriendly(otherFaction))
70 friendlyFactions.Insert(otherFaction.GetFactionKey());
76 array<FactionKey> hostileFactions();
77 foreach (
auto defaultFriendly : friendlyDefaultMapping.Get(key))
79 if (!friendlyFactions.RemoveItem(defaultFriendly))
80 hostileFactions.Insert(defaultFriendly);
83 if (isPlayable == isPlayableDefault && friendlyFactions.IsEmpty() && hostileFactions.IsEmpty())
87 changedFaction.m_sKey = faction.GetFactionKey();
88 changedFaction.m_bPlayable = isPlayable;
89 changedFaction.m_aFriendlies = friendlyFactions;
90 changedFaction.m_aHostiles = hostileFactions;
91 changedFactions.Insert(changedFaction);
94 if (changedFactions.IsEmpty())
97 context.WriteValue(
"version", 1);
98 const bool prev = context.EnableTypeDiscriminator(
false);
99 context.WriteValue(
"factions", changedFactions);
100 context.EnableTypeDiscriminator(prev);
111 context.Read(version);
113 array<ref SCR_PersistentFaction> changedFactions();
114 const bool prev = context.EnableTypeDiscriminator(
false);
115 context.ReadValue(
"factions", changedFactions);
116 context.EnableTypeDiscriminator(prev);
118 array<Faction> factions();
119 factionManager.GetFactionsList(factions);
127 if (faction.
IsPlayable() != changedFaction.m_bPlayable)
130 if (delegateFactionManager)
133 SCR_EditableFactionComponent delegate = delegateFactionManager.
GetFactionDelegate(faction);
135 delegate.SetVisible(changedFaction.m_bPlayable);
139 bool anyChanged =
false;
140 foreach (
auto otherFaction : factions)
143 if (!scrOtherFaction)
146 const FactionKey otherKey = scrOtherFaction.GetFactionKey();
147 const bool currentFriendly = faction.IsFactionFriendly(scrOtherFaction);
148 if (changedFaction.m_aFriendlies.Contains(otherKey) && !currentFriendly)
151 factionManager.SetFactionsFriendly(faction, scrOtherFaction, updateAIs:
false);
153 else if (changedFaction.m_aHostiles.Contains(otherKey) && currentFriendly)
156 factionManager.SetFactionsHostile(faction, scrOtherFaction, updateAIs:
false);