Beispiel #1
0
        /// <summary>
        /// Trade dialog for AerialVehicle located on a Settlement
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="settlement"></param>
        public static Command ShuttleTradeCommand(AerialVehicleInFlight vehicle, Settlement settlement)
        {
            Pawn           bestNegotiator = WorldHelper.FindBestNegotiator(vehicle.vehicle, settlement.Faction, settlement.TraderKind);
            Command_Action command_Action = new Command_Action
            {
                defaultLabel = "CommandTrade".Translate(),
                defaultDesc  = "CommandTradeDesc".Translate(),
                icon         = VehicleTex.TradeCommandTex,
                action       = delegate()
                {
                    if (settlement != null && settlement.CanTradeNow)
                    {
                        Find.WindowStack.Add(new Dialog_Trade(bestNegotiator, settlement, false));
                        PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(settlement.Goods.OfType <Pawn>(), "LetterRelatedPawnsTradingWithSettlement".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent, false, true);
                    }
                }
            };

            if (bestNegotiator is null)
            {
                if (settlement.TraderKind != null && settlement.TraderKind.permitRequiredForTrading != null && !vehicle.vehicle.AllPawnsAboard.Any((Pawn p) => p.royalty != null && p.royalty.HasPermit(settlement.TraderKind.permitRequiredForTrading, settlement.Faction)))
                {
                    command_Action.Disable("CommandTradeFailNeedPermit".Translate(settlement.TraderKind.permitRequiredForTrading.LabelCap));
                }
                else
                {
                    command_Action.Disable("CommandTradeFailNoNegotiator".Translate());
                }
            }
            if (bestNegotiator != null && bestNegotiator.skills.GetSkill(SkillDefOf.Social).TotallyDisabled)
            {
                command_Action.Disable("CommandTradeFailSocialDisabled".Translate());
            }
            return(command_Action);
        }
Beispiel #2
0
 public void InitiateCrashEvent(WorldObject worldObject)
 {
     vehicle.CompVehicleLauncher.inFlight = false;
     Tile = WorldHelper.GetNearestTile(DrawPos);
     ResetPosition(Find.WorldGrid.GetTileCenter(Tile));
     flightPath.ResetPath();
     AirDefensePositionTracker.DeregisterAerialVehicle(this);
     (VehicleIncidentDefOf.BlackHawkDown.Worker as IncidentWorker_ShuttleDowned).TryExecuteEvent(this, worldObject);
 }
Beispiel #3
0
        public static float CalculatedMovementDifficultyAt(int tile, VehicleDef vehicleDef, int?ticksAbs = null, StringBuilder explanation = null)
        {
            Tile worldTile = Find.WorldGrid[tile];

            if (explanation != null && explanation.Length > 0)
            {
                explanation.AppendLine();
            }

            if (vehicleDef.CoastalTravel(tile))
            {
                return(vehicleDef.properties.customBiomeCosts[BiomeDefOf.Ocean] / vehicleDef.properties.worldSpeedMultiplier);
            }
            else if (vehicleDef.vehicleType == VehicleType.Sea)
            {
                return(WorldHelper.WaterCovered(tile) ? vehicleDef.properties.customBiomeCosts[worldTile.biome] / vehicleDef.properties.worldSpeedMultiplier : ImpassableMovementDifficulty);
            }
            float biomeCost     = vehicleDef.properties.customBiomeCosts.TryGetValue(worldTile.biome, WorldPathGrid.CalculatedMovementDifficultyAt(tile, false, ticksAbs, explanation));
            float hillinessCost = vehicleDef.properties.customHillinessCosts.TryGetValue(worldTile.hilliness, HillinessMovementDifficultyOffset(worldTile.hilliness));

            if (ImpassableCost(biomeCost) || ImpassableCost(hillinessCost))
            {
                if (explanation != null)
                {
                    explanation.Append("Impassable".Translate());
                }
                return(ImpassableMovementDifficulty);
            }

            float finalBiomeCost = biomeCost / vehicleDef.properties.worldSpeedMultiplier;

            if (explanation != null)
            {
                explanation.Append(worldTile.biome.LabelCap + ": " + biomeCost.ToStringWithSign("0.#"));
            }

            float num3 = finalBiomeCost + hillinessCost;

            if (explanation != null && hillinessCost != 0f)
            {
                explanation.AppendLine();
                explanation.Append(worldTile.hilliness.GetLabelCap() + ": " + hillinessCost.ToStringWithSign("0.#"));
            }
            return(num3 + GetCurrentWinterMovementDifficultyOffset(tile, vehicleDef, new int?(ticksAbs ?? GenTicks.TicksAbs), explanation));
        }
Beispiel #4
0
 /// <summary>
 /// Intercept AutoOrderToTileNow method to StartPath on VehicleCaravan_PathFollower
 /// Necessary due to CaravanUtility.BestGotoDestNear returning incorrect positions based on custom tile values for vehicles
 /// </summary>
 /// <param name="c"></param>
 /// <param name="tile"></param>
 /// <returns></returns>
 public static bool AutoOrderVehicleCaravanPathing(Caravan c, int tile)
 {
     if (c is VehicleCaravan caravan && caravan.HasVehicle())
     {
         if (tile < 0 || (tile == caravan.Tile && !caravan.vPather.Moving))
         {
             return(false);
         }
         int num = WorldHelper.BestGotoDestForVehicle(caravan, tile);
         if (num >= 0)
         {
             caravan.vPather.StartPath(num, null, true, true);
             caravan.gotoMote.OrderedToTile(num);
             SoundDefOf.ColonistOrdered.PlayOneShotOnCamera(null);
         }
         return(false);
     }
     return(true);
 }
Beispiel #5
0
 public override void WorldComponentTick()
 {
     foreach (var defense in searchingDefenses)
     {
         AerialVehicleInFlight aerialVehicleSearchingFor = defense.Key;
         for (int j = defense.Value.Count - 1; j >= 0; j--)
         {
             AirDefense airDefense        = defense.Value.ElementAt(j);
             float      distance          = Ext_Math.SphericalDistance(airDefense.parent.DrawPos, aerialVehicleSearchingFor.DrawPos);
             bool       withinMaxDistance = distance <= airDefense.MaxDistance;
             if (airDefense.CurrentTarget != aerialVehicleSearchingFor)
             {
                 airDefense.angle = (airDefense.angle + RotationRate * airDefense.searchDirection).ClampAndWrap(0, 360);
                 float angleToTarget = airDefense.parent.DrawPos.AngleToPoint(aerialVehicleSearchingFor.DrawPos);
                 if (withinMaxDistance && Mathf.Abs(angleToTarget - airDefense.angle) <= (airDefense.Arc / 2))
                 {
                     airDefense.activeTargets.Add(aerialVehicleSearchingFor);
                 }
             }
             else
             {
                 float headingToTarget   = WorldHelper.TryFindHeading(airDefense.parent.DrawPos, airDefense.CurrentTarget.DrawPos);
                 int   dirSignMultiplier = headingToTarget < airDefense.angle ? -2 : 2;
                 if (Mathf.Abs(headingToTarget - airDefense.angle) < 1 || Mathf.Abs(headingToTarget - airDefense.angle) > 359)
                 {
                     airDefense.angle = headingToTarget;
                     airDefense.Attack();
                 }
                 else
                 {
                     airDefense.angle = (airDefense.angle + RotationRate * dirSignMultiplier).ClampAndWrap(0, 360);
                 }
                 if (!withinMaxDistance)
                 {
                     airDefense.activeTargets.Remove(aerialVehicleSearchingFor);
                 }
             }
         }
     }
 }
Beispiel #6
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            if (Find.WorldSelector.SingleSelectedObject == this)
            {
                yield return(new Gizmo_CaravanInfo(this));
            }
            foreach (Gizmo gizmo in base.GetGizmos().Where(g => g is Command_Action && (g as Command_Action).defaultLabel != "Dev: Mental break" &&
                                                           (g as Command_Action).defaultLabel != "Dev: Make random pawn hungry" && (g as Command_Action).defaultLabel != "Dev: Kill random pawn" &&
                                                           (g as Command_Action).defaultLabel != "Dev: Harm random pawn" && (g as Command_Action).defaultLabel != "Dev: Down random pawn" &&
                                                           (g as Command_Action).defaultLabel != "Dev: Plague on random pawn" && (g as Command_Action).defaultLabel != "Dev: Teleport to destination"))
            {
                yield return(gizmo);
            }

            if (IsPlayerControlled)
            {
                if (vPather.Moving)
                {
                    yield return(new Command_Toggle
                    {
                        hotKey = KeyBindingDefOf.Misc1,
                        isActive = (() => vPather.Paused),
                        toggleAction = delegate()
                        {
                            if (!vPather.Moving)
                            {
                                return;
                            }
                            vPather.Paused = !vPather.Paused;
                        },
                        defaultDesc = "CommandToggleCaravanPauseDesc".Translate(2f.ToString("0.#"), 0.3f.ToStringPercent()),
                        icon = TexCommand.PauseCaravan,
                        defaultLabel = "CommandPauseCaravan".Translate()
                    });
                }
                if (CaravanMergeUtility.ShouldShowMergeCommand)
                {
                    yield return(CaravanMergeUtility.MergeCommand(this));
                }
                foreach (Gizmo gizmo2 in this.forage.GetGizmos())
                {
                    yield return(gizmo2);
                }

                foreach (WorldObject worldObject in Find.WorldObjects.ObjectsAt(base.Tile))
                {
                    foreach (Gizmo gizmo3 in worldObject.GetCaravanGizmos(this))
                    {
                        yield return(gizmo3);
                    }
                }
            }
            if (Prefs.DevMode)
            {
                yield return(new Command_Action
                {
                    defaultLabel = "Vehicle Dev: Teleport to destination",
                    action = delegate()
                    {
                        Tile = vPather.Destination;
                        vPather.StopDead();
                    }
                });
            }
            if (this.HasBoat() && (Find.World.CoastDirectionAt(Tile).IsValid || WorldHelper.RiverIsValid(Tile, PawnsListForReading.Where(p => p.IsBoat()).ToList())))
            {
                if (!vPather.Moving && !PawnsListForReading.NotNullAndAny(p => !p.IsBoat()))
                {
                    Command_Action dock = new Command_Action();
                    dock.icon         = VehicleTex.Anchor;
                    dock.defaultLabel = Find.WorldObjects.AnySettlementBaseAt(Tile) ? "CommandDockShip".Translate() : "CommandDockShipDisembark".Translate();
                    dock.defaultDesc  = Find.WorldObjects.AnySettlementBaseAt(Tile) ? "CommandDockShipDesc".Translate(Find.WorldObjects.SettlementBaseAt(Tile)) : "CommandDockShipObjectDesc".Translate();
                    dock.action       = delegate()
                    {
                        List <WorldObject> objects = Find.WorldObjects.ObjectsAt(Tile).ToList();
                        if (!objects.All(x => x is Caravan))
                        {
                            CaravanHelper.ToggleDocking(this, true);
                        }
                        else
                        {
                            CaravanHelper.SpawnDockedBoatObject(this);
                        }
                    };

                    yield return(dock);
                }
                else if (!vPather.Moving && PawnsListForReading.NotNullAndAny(p => !p.IsBoat()))
                {
                    Command_Action undock = new Command_Action
                    {
                        icon         = VehicleTex.UnloadAll,
                        defaultLabel = "CommandUndockShip".Translate(),
                        defaultDesc  = "CommandUndockShipDesc".Translate(Label),
                        action       = delegate()
                        {
                            CaravanHelper.ToggleDocking(this, false);
                        }
                    };

                    yield return(undock);
                }
            }
        }
Beispiel #7
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);
                        }
                    });
                }
            }
        }