示例#1
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);
        }