public static string GenerateCaravanName(Caravan caravan)
        {
            Pawn arg_4D_0;

            if ((arg_4D_0 = BestCaravanPawnUtility.FindBestNegotiator(caravan)) == null)
            {
                arg_4D_0 = (BestCaravanPawnUtility.FindBestDiplomat(caravan) ?? caravan.PawnsListForReading.Find((Pawn x) => caravan.IsOwner(x)));
            }
            Pawn   pawn = arg_4D_0;
            string text = (pawn == null) ? caravan.def.label : "CaravanLeaderCaravanName".Translate(pawn.LabelShort, pawn).CapitalizeFirst();

            for (int i = 1; i <= 1000; i++)
            {
                string text2 = text;
                if (i != 1)
                {
                    text2 = text2 + " " + i;
                }
                if (!CaravanNameGenerator.CaravanNameInUse(text2))
                {
                    return(text2);
                }
            }
            Log.Error("Ran out of caravan names.", false);
            return(caravan.def.label);
        }
Esempio n. 2
0
 public static string GenerateCaravanName(Caravan caravan)
 {
     for (int i = 1; i <= 1000; i++)
     {
         string text = caravan.def.label + " " + i;
         if (!CaravanNameGenerator.CaravanNameInUse(text))
         {
             return(text);
         }
     }
     Log.Error("Ran out of caravan names.");
     return(caravan.def.label);
 }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }