Ejemplo n.º 1
0
        private void SpawnCaravanAtDestinationTile()
        {
            TravelingShipsUtility.tmpPawns.Clear();
            for (int i = 0; i < this.ships.Count; i++)
            {
                ThingOwner innerContainer = this.ships[i].GetDirectlyHeldThings();
                //    Log.Message("SpawningCaravan");
                //    TravelingShipsUtility.MakepawnInfos(innerContainer);
                for (int j = 0; j < innerContainer.Count; j++)
                {
                    Pawn pawn = innerContainer[j] as Pawn;
                    if (pawn != null)
                    {
                        TravelingShipsUtility.tmpPawns.Add(pawn);
                    }
                }
            }
            int startingTile;

            if (!GenWorldClosest.TryFindClosestPassableTile(this.destinationTile, out startingTile))
            {
                startingTile = this.destinationTile;
            }

            LandedShip landedShip = TravelingShipsUtility.MakeLandedShip(this, this.Faction, startingTile, true);

            this.RemoveAllShip();
            Find.WorldObjects.Remove(this);

            Messages.Message("MessageShipsArrived".Translate(), landedShip, MessageTypeDefOf.NeutralEvent);
        }
 private bool TryRecoverFromUnwalkablePosition()
 {
     if (GenWorldClosest.TryFindClosestTile(caravan.Tile, (int t) => IsPassable(t) && WorldVehicleReachability.Instance.CanReach(caravan, t), out int num, 2147483647, true))
     {
         Log.Warning(string.Concat(new object[]
         {
             caravan,
             " on unwalkable tile ",
             caravan.Tile,
             ". Teleporting to ",
             num
         }));
         caravan.Tile = num;
         caravan.Notify_VehicleTeleported();
         return(true);
     }
     Log.Error(string.Concat(new object[]
     {
         caravan,
         " on unwalkable tile ",
         caravan.Tile,
         ". Could not find walkable position nearby. Removed."
     }));
     caravan.Destroy();
     return(false);
 }
Ejemplo n.º 3
0
        private void SpawnCaravanAtDestinationTile()
        {
            PawnFlyersTraveling.tmpPawns.Clear();
            for (int i = 0; i < this.pods.Count; i++)
            {
                ThingOwner innerContainer = this.pods[i].innerContainer;
                for (int j = 0; j < innerContainer.Count; j++)
                {
                    Pawn      pawn      = innerContainer[j] as Pawn;
                    PawnFlyer pawnFlyer = innerContainer[j] as PawnFlyer;
                    if (pawn != null)
                    {
                        PawnFlyersTraveling.tmpPawns.Add(pawn);
                    }
                    else if (pawnFlyer != null)
                    {
                        PawnFlyersTraveling.tmpPawns.Add((Pawn)pawnFlyer);
                    }
                }
            }
            int startingTile;

            if (!GenWorldClosest.TryFindClosestPassableTile(this.destinationTile, out startingTile))
            {
                startingTile = this.destinationTile;
            }
            Caravan o = CaravanMaker.MakeCaravan(PawnFlyersTraveling.tmpPawns, Faction.OfPlayer, startingTile, true);

            o.AddPawn((Pawn)pawnFlyer, false);
            for (int k = 0; k < this.pods.Count; k++)
            {
                ThingOwner innerContainer2 = this.pods[k].innerContainer;
                for (int l = 0; l < innerContainer2.Count; l++)
                {
                    if (!(innerContainer2[l] is Pawn))
                    {
                        Pawn pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(innerContainer2[l],
                                                                                       PawnFlyersTraveling.tmpPawns, null, null);
                        pawn2.inventory.innerContainer.TryAdd(innerContainer2[l], true);
                    }
                    else
                    {
                        Pawn pawn3 = innerContainer2[l] as Pawn;
                        if (!pawn3.IsPrisoner)
                        {
                            if (pawn3.Faction != pawnFlyer.Faction)
                            {
                                pawn3.SetFaction(pawnFlyer.Faction);
                            }
                        }
                    }
                }
            }
            this.RemoveAllPods();
            Find.WorldObjects.Remove(this);
            Messages.Message("MessageTransportPodsArrived".Translate(), o, MessageTypeDefOf.PositiveEvent);
        }
        private void SpawnCaravanAtDestinationTile()
        {
            tmpPawns.Clear();
            for (var i = 0; i < pods.Count; i++)
            {
                var innerContainer = pods[i].innerContainer;
                for (var j = 0; j < innerContainer.Count; j++)
                {
                    if (innerContainer[j] is Pawn pawn)
                    {
                        tmpPawns.Add(pawn);
                    }
                    else if (innerContainer[j] is PawnFlyer pawnFlyer)
                    {
                        tmpPawns.Add(pawnFlyer);
                    }
                }
            }

            if (!GenWorldClosest.TryFindClosestPassableTile(destinationTile, out var startingTile))
            {
                startingTile = destinationTile;
            }

            var o = CaravanMaker.MakeCaravan(tmpPawns, Faction.OfPlayer, startingTile, true);

            o.AddPawn(pawnFlyer, false);
            for (var k = 0; k < pods.Count; k++)
            {
                var innerContainer2 = pods[k].innerContainer;
                for (var l = 0; l < innerContainer2.Count; l++)
                {
                    if (!(innerContainer2[l] is Pawn))
                    {
                        var pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(innerContainer2[l],
                                                                                      tmpPawns, null);
                        pawn2.inventory.innerContainer.TryAdd(innerContainer2[l]);
                    }
                    else
                    {
                        var pawn3 = innerContainer2[l] as Pawn;
                        if (!pawn3.IsPrisoner)
                        {
                            if (pawn3.Faction != pawnFlyer.Faction)
                            {
                                pawn3.SetFaction(pawnFlyer.Faction);
                            }
                        }
                    }
                }
            }

            RemoveAllPods();
            Find.WorldObjects.Remove(this);
            Messages.Message("MessageTransportPodsArrived".Translate(), o, MessageTypeDefOf.PositiveEvent);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Find best tile to snap to when ordering a caravan
        /// </summary>
        /// <param name="c"></param>
        /// <param name="tile"></param>
        public static int BestGotoDestForVehicle(Caravan caravan, int tile)
        {
            Predicate <int> predicate = (int t) => caravan.UniqueVehicleDefsInCaravan().All(v => WorldVehiclePathGrid.Instance.Passable(t, v)) &&
                                        WorldVehicleReachability.Instance.CanReach(caravan, t);

            if (predicate(tile))
            {
                return(tile);
            }
            GenWorldClosest.TryFindClosestTile(tile, predicate, out int result, 50, true);
            return(result);
        }
Ejemplo n.º 6
0
 private bool TryRecoverFromUnwalkablePosition()
 {
     if (GenWorldClosest.TryFindClosestTile(warObject.Tile, (int t) => IsPassable(t), out int foundTile))
     {
         Log.Warning(warObject + " on unwalkable tile " + warObject.Tile + ". Teleporting to " + foundTile);
         warObject.Tile = foundTile;
         warObject.Notify_Teleported();
         return(true);
     }
     Verse.Find.WorldObjects.Remove(warObject);
     Log.Error(warObject + " on unwalkable tile " + warObject.Tile + ". Could not find walkable position nearby. Removed.");
     return(false);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Despawn all <paramref name="pawns"/> and create VehicleCaravan WorldObject on World map
        /// </summary>
        /// <param name="pawns"></param>
        /// <param name="faction"></param>
        /// <param name="exitFromTile"></param>
        /// <param name="directionTile"></param>
        /// <param name="destinationTile"></param>
        /// <param name="sendMessage"></param>
        public static VehicleCaravan ExitMapAndCreateVehicleCaravan(IEnumerable <Pawn> pawns, Faction faction, int exitFromTile, int directionTile, int destinationTile, bool sendMessage = true)
        {
            if (!GenWorldClosest.TryFindClosestPassableTile(exitFromTile, out exitFromTile))
            {
                Log.Error("Could not find any passable tile for a new caravan.");
                return(null);
            }
            if (Find.World.Impassable(directionTile))
            {
                directionTile = exitFromTile;
            }

            List <Pawn> tmpPawns = new List <Pawn>();

            tmpPawns.AddRange(pawns);

            Map map = null;

            for (int i = 0; i < tmpPawns.Count; i++)
            {
                AddCaravanExitTaleIfShould(tmpPawns[i]);
                map = tmpPawns[i].MapHeld;
                if (map != null)
                {
                    break;
                }
            }
            VehicleCaravan caravan = MakeVehicleCaravan(tmpPawns, faction, exitFromTile, false);
            Rot4           exitDir = (map != null) ? Find.WorldGrid.GetRotFromTo(exitFromTile, directionTile) : Rot4.Invalid;

            for (int j = 0; j < tmpPawns.Count; j++)
            {
                tmpPawns[j].ExitMap(false, exitDir);
            }
            List <Pawn> pawnsListForReading = caravan.PawnsListForReading;

            for (int k = 0; k < pawnsListForReading.Count; k++)
            {
                if (!pawnsListForReading[k].IsWorldPawn())
                {
                    Find.WorldPawns.PassToWorld(pawnsListForReading[k], PawnDiscardDecideMode.Decide);
                }
            }
            if (map != null)
            {
                map.Parent.Notify_CaravanFormed(caravan);
                map.retainedCaravanData.Notify_CaravanFormed(caravan);
            }
            if (!caravan.vPather.Moving && caravan.Tile != directionTile)
            {
                caravan.vPather.StartPath(directionTile, null, true, true);
                caravan.vPather.nextTileCostLeft /= 2f;
                caravan.tweener.ResetTweenedPosToRoot();
            }
            if (destinationTile != -1)
            {
                List <FloatMenuOption> list = FloatMenuMakerWorld.ChoicesAtFor(destinationTile, caravan);
                if (list.NotNullAndAny((FloatMenuOption x) => !x.Disabled))
                {
                    list.First((FloatMenuOption x) => !x.Disabled).action();
                }
                else
                {
                    caravan.vPather.StartPath(destinationTile, null, true, true);
                }
            }
            if (sendMessage)
            {
                TaggedString taggedString = "MessageFormedCaravan".Translate(caravan.Name).CapitalizeFirst();
                if (caravan.vPather.Moving && caravan.vPather.ArrivalAction != null)
                {
                    taggedString += " " + "MessageFormedCaravan_Orders".Translate() + ": " + caravan.vPather.ArrivalAction.Label + ".";
                }
                Messages.Message(taggedString, caravan, MessageTypeDefOf.TaskCompletion, true);
            }
            return(caravan);
        }