public override void VehicleArrived(AerialVehicleInFlight aerialVehicle, LaunchProtocol launchProtocol, Map map)
        {
            Rot4    vehicleRotation             = launchProtocol.landingProperties.forcedRotation ?? Rot4.Random;
            IntVec3 cell                        = CellFinderExtended.RandomCenterCell(map, (IntVec3 cell) => !MapHelper.VehicleBlockedInPosition(aerialVehicle.vehicle, Current.Game.CurrentMap, cell, vehicleRotation));
            VehicleSkyfaller_Arriving skyfaller = (VehicleSkyfaller_Arriving)ThingMaker.MakeThing(aerialVehicle.vehicle.CompVehicleLauncher.Props.skyfallerIncoming);

            skyfaller.vehicle = aerialVehicle.vehicle;
            GenSpawn.Spawn(skyfaller, cell, map, vehicleRotation);
        }
Ejemplo n.º 2
0
        private static IntVec3 FindNearEdgeWaterCell(Map map)
        {
            Predicate <IntVec3> validator   = (IntVec3 x) => GenGridVehicles.Standable(x, map) && !x.Fogged(map);
            Faction             hostFaction = map.ParentFaction;
            IntVec3             root;

            if (CellFinder.TryFindRandomEdgeCellWith(validator, map, CellFinder.EdgeRoadChance_Ignore, out root))
            {
                return(CellFinderExtended.RandomClosewalkCellNear(root, map, 5, null));
            }
            if (CellFinder.TryFindRandomEdgeCellWith(validator, map, CellFinder.EdgeRoadChance_Ignore, out root))
            {
                return(CellFinderExtended.RandomClosewalkCellNear(root, map, 5, null));
            }
            Log.Warning("Could not find any valid edge cell.");
            return(CellFinder.RandomCell(map));
        }
Ejemplo n.º 3
0
        public static void EnterAndSpawn(Caravan caravan, Map map, CaravanEnterMode enterMode, CaravanDropInventoryMode dropInventoryMode = CaravanDropInventoryMode.DoNotDrop,
                                         bool draftColonists = false, Predicate <IntVec3> extraValidator = null)
        {
            bool coastalSpawn = caravan.HasBoat();

            if (enterMode == CaravanEnterMode.None)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Caravan ", caravan, " tried to enter map ", map, " with no enter mode. Defaulting to edge."
                }));
                enterMode = CaravanEnterMode.Edge;
            }
            List <Pawn> pawns = new List <Pawn>(caravan.PawnsListForReading).ToList();

            IntVec3             enterCell = pawns.NotNullAndAny(v => v.IsBoat()) ? GetWaterCell(caravan, map, CaravanEnterMode.Edge) : GetEnterCellVehicle(caravan, map, enterMode, extraValidator);
            Rot4                edge      = enterMode == CaravanEnterMode.Edge ? CellRect.WholeMap(map).GetClosestEdge(enterCell) : Rot4.North;
            Predicate <IntVec3> validator = (IntVec3 c) => coastalSpawn?GenGridVehicles.Standable(c, map) : GenGrid.Standable(c, map);

            Func <Pawn, IntVec3> spawnCellGetter = (Pawn p) => CellFinderExtended.RandomSpawnCellForPawnNear(enterCell, map, p, validator);

            SpawnVehicles(caravan, pawns, map, spawnCellGetter, edge, draftColonists);
        }
Ejemplo n.º 4
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            foreach (Gizmo gizmo in base.GetGizmos())
            {
                yield return(gizmo);
            }

            if (IsPlayerControlled)
            {
                if (vehicle.CompFueledTravel != null)
                {
                    yield return(vehicle.CompFueledTravel.FuelCountGizmo);

                    foreach (Gizmo fuelGizmo in vehicle.CompFueledTravel.DevModeGizmos())
                    {
                        yield return(fuelGizmo);
                    }
                }
                if (!vehicle.CompVehicleLauncher.inFlight && Find.WorldObjects.SettlementAt(Tile) is Settlement settlement2)
                {
                    yield return(GizmoHelper.AerialVehicleTradeCommand(this, settlement2.Faction, settlement2.TraderKind));
                }
                if (vehicle.CompVehicleLauncher.ControlInFlight || !vehicle.CompVehicleLauncher.inFlight)
                {
                    Command_Action launchCommand = new Command_Action()
                    {
                        defaultLabel = "CommandLaunchGroup".Translate(),
                        defaultDesc  = "CommandLaunchGroupDesc".Translate(),
                        icon         = VehicleTex.LaunchCommandTex,
                        alsoClickIfOtherInGroupClicked = false,
                        action = delegate()
                        {
                            LaunchTargeter.Instance.BeginTargeting(vehicle, new Func <GlobalTargetInfo, float, bool>(ChoseTargetOnMap), this, true, VehicleTex.TargeterMouseAttachment, false, null,
                                                                   (GlobalTargetInfo target, List <FlightNode> path, float fuelCost) => vehicle.CompVehicleLauncher.launchProtocol.TargetingLabelGetter(target, Tile, path, fuelCost));
                        }
                    };
                    if (vehicle.CompFueledTravel.EmptyTank)
                    {
                        launchCommand.Disable("VehicleLaunchOutOfFuel".Translate());
                    }
                    yield return(launchCommand);
                }
                if (!vehicle.CompVehicleLauncher.inFlight)
                {
                    foreach (Settlement settlement in Find.WorldObjects.ObjectsAt(flightPath.First.tile).Where(o => o is Settlement).Cast <Settlement>())
                    {
                        yield return(GizmoHelper.ShuttleTradeCommand(this, settlement));

                        if (WorldHelper.CanOfferGiftsTo(this, settlement))
                        {
                            yield return(new Command_Action
                            {
                                defaultLabel = "CommandOfferGifts".Translate(),
                                defaultDesc = "CommandOfferGiftsDesc".Translate(),
                                icon = VehicleTex.OfferGiftsCommandTex,
                                action = delegate()
                                {
                                    Pawn playerNegotiator = WorldHelper.FindBestNegotiator(vehicle, null, null);
                                    Find.WindowStack.Add(new Dialog_Trade(playerNegotiator, settlement, true));
                                }
                            });
                        }
                    }
                    Command_Settle commandSettle = new Command_Settle
                    {
                        defaultLabel = "CommandSettle".Translate(),
                        defaultDesc  = "CommandSettleDesc".Translate(),
                        icon         = SettleUtility.SettleCommandTex,
                        action       = delegate()
                        {
                            SoundDefOf.Tick_High.PlayOneShotOnCamera(null);
                            void settleHere()
                            {
                                SettlementVehicleUtility.Settle(this);
                            };
                            SettlementProximityGoodwillUtility.CheckConfirmSettle(Tile, settleHere);
                        }
                    };
                    if (!TileFinder.IsValidTileForNewSettlement(Tile, tmpSettleFailReason))
                    {
                        commandSettle.Disable(tmpSettleFailReason.ToString());
                    }
                    else if (SettleUtility.PlayerSettlementsCountLimitReached)
                    {
                        if (Prefs.MaxNumberOfPlayerSettlements > 1)
                        {
                            commandSettle.Disable("CommandSettleFailReachedMaximumNumberOfBases".Translate());
                        }
                        else
                        {
                            commandSettle.Disable("CommandSettleFailAlreadyHaveBase".Translate());
                        }
                    }
                    yield return(commandSettle);
                }
                if (Prefs.DevMode)
                {
                    yield return(new Command_Action
                    {
                        defaultLabel = "Debug: Land at Nearest Player Settlement",
                        action = delegate()
                        {
                            List <Settlement> playerSettlements = Find.WorldObjects.Settlements.Where(s => s.Faction == Faction.OfPlayer).ToList();
                            Settlement nearestSettlement = playerSettlements.MinBy(s => Ext_Math.SphericalDistance(s.DrawPos, DrawPos));

                            LaunchProtocol launchProtocol = vehicle.CompVehicleLauncher.launchProtocol;
                            Rot4 vehicleRotation = launchProtocol.landingProperties.forcedRotation ?? Rot4.Random;
                            IntVec3 cell = CellFinderExtended.RandomCenterCell(nearestSettlement.Map, (IntVec3 cell) => !MapHelper.VehicleBlockedInPosition(vehicle, Current.Game.CurrentMap, cell, vehicleRotation));
                            VehicleSkyfaller_Arriving skyfaller = (VehicleSkyfaller_Arriving)ThingMaker.MakeThing(vehicle.CompVehicleLauncher.Props.skyfallerIncoming);
                            skyfaller.vehicle = vehicle;

                            GenSpawn.Spawn(skyfaller, cell, nearestSettlement.Map, vehicleRotation);
                            Destroy();
                        }
                    });

                    yield return(new Command_Action
                    {
                        defaultLabel = "Debug: Initiate Crash Event",
                        action = delegate()
                        {
                            InitiateCrashEvent(null);
                        }
                    });
                }
            }
        }