diff --git a/Source/API/Dummy.cs b/Source/API/Dummy.cs index 2a7c3ad..b4d8dd4 100644 --- a/Source/API/Dummy.cs +++ b/Source/API/Dummy.cs @@ -179,4 +179,22 @@ public void SetCurrentSessionWithTransferables(ISessionWithTransferables session { throw new UninitializedAPI(); } + + public bool IsMultifaction => false; + + public Faction SpectatorFaction => null; + + public void PushFaction(Map map, Faction faction) + { + throw new UninitializedAPI(); + } + + public void PopFaction(Map map = null) + { + throw new UninitializedAPI(); + } + + public void RepeatForWorldFactions(Action action) { } + + public void RepeatForMapFactions(Map map, Action action) { } } \ No newline at end of file diff --git a/Source/API/IAPI.cs b/Source/API/IAPI.cs index 78b6293..ba71e61 100644 --- a/Source/API/IAPI.cs +++ b/Source/API/IAPI.cs @@ -61,4 +61,11 @@ public interface IAPI ISessionManager GetGlobalSessionManager(); ISessionManager GetLocalSessionManager(Map map); void SetCurrentSessionWithTransferables(ISessionWithTransferables session); + + bool IsMultifaction { get; } + Faction SpectatorFaction { get; } + void PushFaction(Map map, Faction faction); + void PopFaction(Map map = null); + void RepeatForWorldFactions(Action action); + void RepeatForMapFactions(Map map, Action action); } \ No newline at end of file diff --git a/Source/API/MP.cs b/Source/API/MP.cs index 3bfd23f..63f2000 100644 --- a/Source/API/MP.cs +++ b/Source/API/MP.cs @@ -406,6 +406,38 @@ public static ISyncDelegate RegisterSyncDelegateLocalFunc(Type parentType, strin /// /// The global (world) session manager. /// As long as a multiplayer session is active, there should always be a global session manager. This method should never return in such cases, unless something is very broken. + /// + /// Returns if multifaction is enabled in the current multiplayer session. + /// + public static bool IsMultifaction => Sync.IsMultifaction; + + /// + /// The spectator faction used internally by Multiplayer. Useful for skipping it when iterating player factions. + /// + public static Faction SpectatorFaction => Sync.SpectatorFaction; + + /// + /// Pushes a faction context for the given map. Use to restore the previous context. + /// Pass for map when operating at world level. + /// + public static void PushFaction(Map map, Faction faction) => Sync.PushFaction(map, faction); + + /// + /// Pops the current faction context, restoring the previous one. + /// Pass for map when operating at world level. + /// + public static void PopFaction(Map map = null) => Sync.PopFaction(map); + + /// + /// Calls once for each non-spectator player faction with the world faction context set appropriately. + /// + public static void RepeatForWorldFactions(Action action) => Sync.RepeatForWorldFactions(action); + + /// + /// Calls once for each non-spectator player faction with the map and world faction context set appropriately. + /// + public static void RepeatForMapFactions(Map map, Action action) => Sync.RepeatForMapFactions(map, action); + public static ISessionManager GetGlobalSessionManager() => Sync.GetGlobalSessionManager(); /// /// Retrieves the local (map) session manager.