11 [
Attribute(defvalue:
"1",
desc:
"Whether or not the isPlayable state of a faction can be changed on run time")]
12 protected bool m_bCanChangeFactionsPlayable;
14 [
Attribute(
"", UIWidgets.Object,
"List of rank types")]
15 protected ref array<ref SCR_RankID>
m_aRanks;
17 protected ref SCR_SortedArray<SCR_Faction> m_SortedFactions =
new SCR_SortedArray<SCR_Faction>();
18 protected ref map<string, ref array<string>>
m_aAncestors =
new map<string, ref array<string>>();
21 [
RplProp(onRplName:
"OnPlayerFactionInfoChanged")]
22 protected ref array<ref SCR_PlayerFactionInfo> m_aPlayerFactionInfo = {};
70 int factionIndex = -1;
72 factionIndex = factionInfo.GetFactionIndex();
80 for (
int i = 0, cnt = m_aPlayerFactionInfo.Count(); i < cnt; i++)
83 int playerId = m_aPlayerFactionInfo[i].GetPlayerId();
87 int playerFactionIndex = m_aPlayerFactionInfo[i].GetFactionIndex();
88 if (playerFactionIndex != -1)
96 int previousFactionIndex;
98 previousFactionIndex = -1;
100 if (previousFactionIndex != playerFactionIndex)
111 if (factionIndex == -1)
129 #ifdef _ENABLE_RESPAWN_LOGS
130 Print(
string.Format(
"%1::OnPlayerFactionSet_S(playerId: %2, faction: %3)", Type().ToString(), playerComponent.GetPlayerId(), faction), LogLevel.NORMAL);
147 #ifdef _ENABLE_RESPAWN_LOGS
150 key = faction.GetFactionKey();
152 Print(
string.Format(
"%1::OnPlayerFactionCountChanged(faction: %2 [%3], count: %4)", Type().ToString(), faction, key, newCount), LogLevel.NORMAL);
166 int factionIndex = info.GetFactionIndex();
180 static Faction SGetPlayerFaction(
int playerId)
183 return factionManager.GetPlayerFaction(playerId);
202 static Faction SGetLocalPlayerFaction()
208 return factionManager.GetLocalPlayerFaction();
232 static int SGetFactionPlayerCount(
Faction faction)
235 return factionManager.GetFactionPlayerCount(faction);
244 return outFactions.CopyFrom(m_SortedFactions);
257 if (rank && rank.GetRankID() == rankID)
268 array<ref SCR_RankID> outArray = {};
271 outArray.Insert(rank);
285 return rank.IsRankRenegade();
295 SCR_RankID rank = SCR_RankID.Cast(
GetRankByID(rankID));
300 return rank.GetRequiredRankXP();
308 if (rank && rank.IsRankRenegade())
309 return rank.GetRankID();
323 int maxFoundXP = -100000;
330 if (reqXP <= XP && reqXP > maxFoundXP)
333 rankFound = rank.GetRankID();
346 int higherXP = 99999;
357 if (thisXP > rankXP && thisXP < higherXP)
373 int lowerXP = -99999;
384 if (thisXP < rankXP && thisXP > lowerXP)
397 array<string> ancestors;
398 array<Faction> factions = {};
400 for (
int i = factions.Count() - 1; i >= 0; i--)
405 if (
m_aAncestors.Find(scriptedFaction.GetFactionKey(), ancestors))
406 scriptedFaction.SetAncestors(ancestors);
408 m_SortedFactions.Insert(scriptedFaction.GetOrder(), scriptedFaction);
410 scriptedFaction.InitializeFaction();
417 array<Managed> components = {};
421 component.OnFactionsInit(factions);
436 protected override void EOnDiag(IEntity owner,
float timeSlice)
438 super.EOnDiag(owner, timeSlice);
440 if (!DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_RESPAWN_PLAYER_FACTION_DIAG))
443 DbgUI.Begin(
"SCR_FactionManager");
445 DbgUI.Text(
"* Faction Player Count *");
446 array<Faction> factions = {};
448 foreach (
Faction faction : factions)
450 DbgUI.Text(
string.Format(
"%1: %2 player(s)", faction.GetFactionKey(),
GetFactionPlayerCount(faction)));
463 SetEventMask(EntityEvent.INIT);
465 ConnectToDiagSystem();
469 BaseContainerList factionSources = src.GetObjectArray(
"Factions");
470 BaseContainer factionSource;
471 string factionKey, parentKey;
472 for (
int i, count = factionSources.Count(); i < count; i++)
474 factionSource = factionSources.Get(i);
475 factionSource.Get(
"FactionKey", factionKey);
477 array<string> ancestors = {};
478 while (factionSource)
480 factionSource.Get(
"FactionKey", parentKey);
481 if (!ancestors.Contains(parentKey))
482 ancestors.Insert(parentKey);
484 factionSource = factionSource.GetAncestor();
496 DisconnectFromDiagSystem();
506 return m_bCanChangeFactionsPlayable;
520 if (factionA.DoCheckIfFactionFriendly(factionB))
524 if (factionA == factionB)
526 factionA.SetFactionFriendly(factionA);
528 if (playerChanged > 0)
535 factionA.SetFactionFriendly(factionB);
536 factionB.SetFactionFriendly(factionA);
540 if (playerChanged > 0)
553 if (!factionA.DoCheckIfFactionFriendly(factionB))
557 if (factionA == factionB)
559 factionA.SetFactionHostile(factionA);
561 if (playerChanged > 0)
568 factionA.SetFactionHostile(factionB);
569 factionB.SetFactionHostile(factionA);
573 if (playerChanged > 0)
582 PerceptionManager pm =
GetGame().GetPerceptionManager();
584 pm.RequestUpdateAllTargetsFactions();
593 int targetPlayerId = playerFactionComponent.GetPlayerController().GetPlayerId();
594 Faction targetFaction = playerFactionComponent.GetAffiliatedFaction();
607 if (previousIndex != -1)
611 int newCount = previousCount - 1;
618 foundInfo.SetFactionIndex(targetFactionIndex);
621 if (targetFactionIndex != -1)
625 int newCount = previousCount + 1;
633 Replication.BumpMe();
639 newInfo.SetFactionIndex(targetFactionIndex);
640 m_aPlayerFactionInfo.Insert(newInfo);
644 if (targetFactionIndex != -1)
648 int newCount = previousCount + 1;
655 Replication.BumpMe();
666 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
670 if (!playerFactionAffiliation)
674 if (!playerFactionAffiliation.GetAffiliatedFaction())
678 playerFactionAffiliation.RequestFaction(
null);