Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 29 additions & 35 deletions Source/Client/Factions/FactionCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public static void SendPawn(int playerId, Pawn p)
[SyncMethod]
public static void CreateFaction(int playerId, FactionCreationData creationData)
{
var self = TickPatch.currentExecutingCmdIssuedBySelf;
var executingOnlyOnIssuer = TickPatch.currentExecutingCmdIssuedBySelf;

LongEventHandler.QueueLongEvent(() =>
{
var scenario = creationData.scenarioDef?.scenario ?? Current.Game.Scenario;
Map newMap = null;

PrepareGameInitData(playerId, scenario, self, creationData.startingPossessions);
PrepareGameInitData(playerId, scenario, executingOnlyOnIssuer, creationData.startingPossessions);

var newFaction = NewFactionWithIdeo(
creationData.factionName,
Expand All @@ -62,17 +62,15 @@ public static void CreateFaction(int playerId, FactionCreationData creationData)
map.attackTargetsCache.Notify_FactionHostilityChanged(f, newFaction);

using (MpScope.PushFaction(newFaction))
InitNewGame();
InitNewGame(scenario);

if (self)
if (executingOnlyOnIssuer)
{
Current.Game.CurrentMap = newMap;

Multiplayer.game.ChangeRealPlayerFaction(newFaction);

CameraJumper.TryJump(MapGenerator.playerStartSpotInt, newMap);

PostGameStart(scenario);
InitLocalVisuals(scenario, newMap);

// todo setting faction of self
Multiplayer.Client.Send(
Expand All @@ -84,35 +82,15 @@ public static void CreateFaction(int playerId, FactionCreationData creationData)
}, "GeneratingMap", doAsynchronously: true, GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap);
}

private static void PostGameStart(Scenario scenario)
private static void InitLocalVisuals(Scenario scenario, Map generatedMap)
{
/**
ScenPart_StartingResearch.cs
ScenPart_AutoActivateMonolith.cs
ScenPart_CreateIncident.cs
ScenPart_GameStartDialog.cs
ScenPart_PlayerFaction.cs
ScenPart_Rule.cs

Would like to call PostGameStart on all implementations (scenario.PostGameStart) -
but dont know if it breaks with dlcs other than biotech - especially while only called
on self
**/

HashSet<Type> types = new HashSet<Type>
{
typeof(ScenPart_PlayerFaction),
typeof(ScenPart_GameStartDialog),
typeof(ScenPart_StartingResearch),
};
// TODO #587: There may be other logical ScenParts (e.g., ScenPart_StartingResearch) that
// need to be executed by all players in the game.
var onlyVisualScenParts = new HashSet<Type>() { typeof(ScenPart_GameStartDialog) };

foreach (ScenPart part in scenario.AllParts)
{
if (types.Contains(part.GetType()))
{
part.PostGameStart();
}
}
PostGameStart(scenario, onlyVisualScenParts);

CameraJumper.TryJump(MapGenerator.playerStartSpotInt, generatedMap);
}

private static Map GenerateNewMap(PlanetTile tile, Scenario scenario, bool setupNextMapFromTickZero)
Expand Down Expand Up @@ -173,17 +151,33 @@ private static void SetAllThingWithCompsOnMapForbidden(Map map)
}
}

private static void InitNewGame()
private static void InitNewGame(Scenario scenario)
{
PawnUtility.GiveAllStartingPlayerPawnsThought(ThoughtDefOf.NewColonyOptimism);

ResearchUtility.ApplyPlayerStartingResearch();

// TODO #587: There may be other only visual ScenParts (e.g., ScenPart_GameStartDialog) that only need to
// be executed by the local client (the issuer/creator of the new faction).
PostGameStart(scenario, new HashSet<Type>() { typeof(ScenPart_StartingResearch) });

// Initialize anomaly. Since the Anomaly comp is currently shared by all players,
// we need to ensure that any new factions have access to anomaly research if
// anomaly content was started.
Find.ResearchManager.Notify_MonolithLevelChanged(Find.Anomaly.Level);
}

private static void PostGameStart(Scenario scenario, IEnumerable<Type> scenPartTypesToInvoke)
{
foreach (ScenPart part in scenario.AllParts)
{
if (scenPartTypesToInvoke.Contains(part.GetType()))
{
part.PostGameStart();
}
}
}

private static void PrepareGameInitData(int sessionId, Scenario scenario, bool self, List<ThingDefCount> startingPossessions)
{
if (!self)
Expand Down
Loading