Launch transportpods from non-player owned map cause caravans missing.
Should be multifaction problem.
I believe this is because the World Transportpod's Faction was set in FlyShipLeaving.LeaveMap, which happened when ticking the map, this makes all pods launched given Faction same with map owner. The game checks if any pawn in pods belongs to that Faction when arrived, and if no pawn of faction detected, the caravan got missing.
This affacts a lot. One player can't launch pods from other player's factionbase to anywhere except the ArrivalAction is TransportPodsArrivalAction_LandInSpecificCell.
Also some maps would be created for spectator in some mods...
Fix suggestions:
1.Save the pods’ ownership when TryLauch(or somewhere else)
2.Pre&post patch the FlyShipLeaving.LeaveMap to Push/Pop Faction temporarily to make Faction.OfPlayer works correctly here.
Made a temporarily patch and works fine for myself. Still looking for u guys ideas about better solution.
For me 1st choice is to register these events with Faction and let Maptick handle them
2nd is codes here
3rd transpiler to replace Faction.OfPlayer in FlyShipLeaving.LeaveMap with tmpTransportPodsOwnershipDict[this.groupID]
I'll left my codes here insdead of make a pull request as idk where to put the dict..
static Dictionary<int, Faction> tmpTransportPodsOwnershipDict = new();
[MpPrefix(typeof(CompLaunchable), nameof(CompLaunchable.TryLaunch))]
static bool CompLaunchableTryLaunchPrefix(CompLaunchable __instance, int destinationTile, TransportPodsArrivalAction arrivalAction)
{
if (Multiplayer.Client == null)
return true;
tmpTransportPodsOwnershipDict[__instance.Transporter.groupID] = __instance.parent.Faction;
return true;
}
[MpPrefix(typeof(FlyShipLeaving), nameof(FlyShipLeaving.LeaveMap))]
static void FlyShipLeavingLeaveMapPrefix(FlyShipLeaving __instance)
{
if (Multiplayer.Client == null)
return ;
__instance.Map.PushFaction(tmpTransportPodsOwnershipDict[__instance.groupID]);
return ;
}
[MpPostfix(typeof(FlyShipLeaving), nameof(FlyShipLeaving.LeaveMap))]
static void FlyShipLeavingLeaveMapPostfix(FlyShipLeaving __instance)
{
if (Multiplayer.Client == null)
return;
__instance.Map.PopFaction();
tmpTransportPodsOwnershipDict.Remove(__instance.groupID);
return ;
}
SRTS need same implementions here as SRTS COPIED the comp with a new name complaunchableSRTS extends thingcomp.