public static LandedShip MakeLandedShip(TravelingShips incomingShips, Faction faction, int startingTile, bool addToWorldPawnsIfNotAlready) { // Log.Message("Making LandedShip"); // TravelingShipsUtility.MakepawnInfos(incomingShips.ships[0].GetInnerContainer()); if (startingTile < 0 && addToWorldPawnsIfNotAlready) { Log.Warning("Tried to create a caravan but chose not to spawn a caravan but pass pawns to world. This can cause bugs because pawns can be discarded."); } TravelingShipsUtility.tmpPawns.Clear(); TravelingShipsUtility.tmpPawns.AddRange(incomingShips.Pawns); LandedShip caravan = (LandedShip)WorldObjectMaker.MakeWorldObject(ShipNamespaceDefOfs.LandedShip); if (startingTile >= 0) { caravan.Tile = startingTile; } caravan.SetFaction(faction); if (startingTile >= 0) { Find.WorldObjects.Add(caravan); } for (int i = 0; i < TravelingShipsUtility.tmpPawns.Count; i++) { Pawn pawn = TravelingShipsUtility.tmpPawns[i]; if (pawn.Dead) { Log.Warning("Tried to form a caravan with a dead pawn " + pawn); } else { caravan.AddPawn(pawn, addToWorldPawnsIfNotAlready); if (addToWorldPawnsIfNotAlready && !pawn.IsWorldPawn()) { if (pawn.Spawned) { pawn.DeSpawn(); } Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide); } } } string name; if (incomingShips.ships[0].fleetID != -1 && DropShipUtility.currentShipTracker.PlayerFleetManager.ContainsKey(incomingShips.ships[0].fleetID)) { name = DropShipUtility.currentShipTracker.PlayerFleetManager[incomingShips.ships[0].fleetID]; } else { name = incomingShips.ships[0].ShipNick; } caravan.Name = name; caravan.ships.AddRange(incomingShips.ships); foreach (ShipBase ship in caravan.ships) { DropShipUtility.PassWorldPawnsForLandedShip(ship); } return(caravan); }
public static LandedShip MakeLandedShip(TravelingShips incomingShips, Faction faction, int startingTile, bool addToWorldPawnsIfNotAlready) { // TravelingShipsUtility.MakepawnInfos(incomingShips.ships[0].GetDirectlyHeldThings()); if (startingTile < 0 && addToWorldPawnsIfNotAlready) { Log.Warning("Tried to create a caravan but chose not to spawn a caravan but pass pawns to world. This can cause bugs because pawns can be discarded."); } TravelingShipsUtility.tmpPawns.Clear(); TravelingShipsUtility.tmpPawns.AddRange(incomingShips.Pawns); LandedShip caravan = (LandedShip)WorldObjectMaker.MakeWorldObject(ShipNamespaceDefOfs.LandedShip); if (startingTile >= 0) { caravan.Tile = startingTile; } caravan.SetFaction(faction); if (startingTile >= 0) { Find.WorldObjects.Add(caravan); } foreach (ShipBase current in incomingShips.ships) { // current.shouldDeepSave = false; List <Thing> passengers = current.GetDirectlyHeldThings().ToList(); List <string> passengerIDs = new List <string>(); for (int i = 0; i < passengers.Count; i++) { Pawn pawn = passengers[i] as Pawn; if (pawn != null) { if (pawn.Dead) { Log.Warning("Tried to form a caravan with a dead pawn " + pawn); } else { passengerIDs.Add(pawn.ThingID); //pawn.holdingOwner = null; current.GetDirectlyHeldThings().Remove(pawn); caravan.AddPawn(pawn, addToWorldPawnsIfNotAlready); if (addToWorldPawnsIfNotAlready && !pawn.IsWorldPawn()) { if (pawn.Spawned) { pawn.DeSpawn(); } Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide); } } } } caravan.shipsPassengerList.Add(current, passengerIDs); } string name; if (incomingShips.ships[0].fleetID != -1 && DropShipUtility.currentShipTracker.PlayerFleetManager.ContainsKey(incomingShips.ships[0].fleetID)) { name = DropShipUtility.currentShipTracker.PlayerFleetManager[incomingShips.ships[0].fleetID]; } else { name = incomingShips.ships[0].ShipNick; } caravan.Name = name; caravan.ships.AddRange(incomingShips.ships); foreach (ShipBase ship in caravan.ships) { //DropShipUtility.PassWorldPawnsForLandedShip(ship); } return(caravan); }