Ejemplo n.º 1
0
        private bool TrySplitCaravan()
        {
            List <Pawn> pawns = TransferableUtility.GetPawnsFromTransferables(this.transferables);

            if (!this.CheckForErrors(pawns))
            {
                return(false);
            }
            for (int i = 0; i < pawns.Count; i++)
            {
                CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawns[i], this.caravan.PawnsListForReading, pawns);
            }
            Caravan caravan = (Caravan)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Caravan);

            caravan.Tile = this.caravan.Tile;
            caravan.SetFaction(this.caravan.Faction);
            caravan.Name = CaravanNameGenerator.GenerateCaravanName(caravan);
            Find.WorldObjects.Add(caravan);
            for (int j = 0; j < pawns.Count; j++)
            {
                this.caravan.RemovePawn(pawns[j]);
                caravan.AddPawn(pawns[j], true);
            }
            this.transferables.RemoveAll((TransferableOneWay x) => x.AnyThing is Pawn);
            for (int k = 0; k < this.transferables.Count; k++)
            {
                TransferableUtility.TransferNoSplit(this.transferables[k].things, this.transferables[k].CountToTransfer, delegate(Thing thing, int numToTake)
                {
                    Pawn ownerOf = CaravanInventoryUtility.GetOwnerOf(this.caravan, thing);
                    if (ownerOf == null)
                    {
                        Log.Error("Error while splitting a caravan: Thing " + thing + " has no owner. Where did it come from then?");
                    }
                    else
                    {
                        CaravanInventoryUtility.MoveInventoryToSomeoneElse(ownerOf, thing, pawns, null, numToTake);
                    }
                }, true, true);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static Caravan MakeCaravan(IEnumerable <Pawn> pawns, Faction faction, int startingTile, bool addToWorldPawnsIfNotAlready)
        {
            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.", false);
            }
            CaravanMaker.tmpPawns.Clear();
            CaravanMaker.tmpPawns.AddRange(pawns);
            Caravan caravan = (Caravan)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Caravan);

            if (startingTile >= 0)
            {
                caravan.Tile = startingTile;
            }
            caravan.SetFaction(faction);
            if (startingTile >= 0)
            {
                Find.WorldObjects.Add(caravan);
            }
            for (int i = 0; i < CaravanMaker.tmpPawns.Count; i++)
            {
                Pawn pawn = CaravanMaker.tmpPawns[i];
                if (pawn.Dead)
                {
                    Log.Warning("Tried to form a caravan with a dead pawn " + pawn, false);
                }
                else
                {
                    caravan.AddPawn(pawn, addToWorldPawnsIfNotAlready);
                    if (addToWorldPawnsIfNotAlready && !pawn.IsWorldPawn())
                    {
                        Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide);
                    }
                }
            }
            caravan.Name = CaravanNameGenerator.GenerateCaravanName(caravan);
            CaravanMaker.tmpPawns.Clear();
            caravan.SetUniqueId(Find.UniqueIDsManager.GetNextCaravanID());
            return(caravan);
        }