private void DrawTargetingPoints()
        {
            this.targetingLength = Vector3.Distance(selections[0].CenterVector3, UI.MouseMapPosition().ToIntVec3().ToVector3Shifted());
            GenDraw.DrawTargetHighlight(new LocalTargetInfo(selections[0].Cell));
            if (bombType == BombingType.carpet)
            {
                GenDraw.DrawRadiusRing(selections[0].Cell, SRTSMod.GetStatFor <int>(bomber.defName, StatName.radiusDrop));

                this.numRings = ((int)(targetingLength / SRTSMod.GetStatFor <float>(this.bomber.defName, StatName.distanceBetweenDrops))).Clamp <int>(0, SRTSMod.GetStatFor <int>(this.bomber.defName, StatName.numberBombs));

                if (SRTSMod.mod.settings.expandBombPoints && numRings >= 1)
                {
                    GenDraw.DrawRadiusRing(UI.MouseMapPosition().ToIntVec3(), SRTSMod.GetStatFor <int>(bomber.defName, StatName.radiusDrop));
                    GenDraw.DrawTargetHighlight(new LocalTargetInfo(UI.MouseMapPosition().ToIntVec3()));
                }
                for (int i = 1; i < numRings - (SRTSMod.mod.settings.expandBombPoints ? 1 : 0); i++)
                {
                    IntVec3 cellTargeted = this.TargeterToCell(i);
                    GenDraw.DrawRadiusRing(cellTargeted, SRTSMod.GetStatFor <int>(bomber.defName, StatName.radiusDrop));
                    GenDraw.DrawTargetHighlight(new LocalTargetInfo(cellTargeted));
                }
            }
            else if (bombType == BombingType.precise)
            {
                IntVec3 centeredTarget = this.TargeterCentered();
                GenDraw.DrawTargetHighlight(new LocalTargetInfo(centeredTarget));
                GenDraw.DrawTargetHighlight(new LocalTargetInfo(UI.MouseMapPosition().ToIntVec3()));
                GenDraw.DrawRadiusRing(centeredTarget, SRTSMod.GetStatFor <int>(bomber.defName, StatName.radiusDrop) * RadiusPreciseMultiplier);
            }
        }
Esempio n. 2
0
        /* =========================== Redacted but used as helper methods to ErrorOnNoPawnsTranspiler =========================== */
        public static string MinMaxString(List <CompTransporter> transporters, bool min)
        {
            var srts = transporters.First(x => x.parent.GetComp <CompLaunchableSRTS>() != null).parent;

            return(min ? "Minimum Required Pawns for " + srts.def.LabelCap + ": " + (SRTSMod.GetStatFor <int>(srts.def.defName, StatName.minPassengers)) :
                   "Maximum Pawns able to board " + srts.def.LabelCap + ": " + (SRTSMod.GetStatFor <int>(srts.def.defName, StatName.maxPassengers)));
        }
Esempio n. 3
0
 public static bool SRTSMassCapacityCaravan(List<Thing> allCurrentThings, List<Tradeable> tradeables, StringBuilder explanation, ref float __result)
 {
   if (allCurrentThings.Any(x => x.TryGetComp<CompLaunchableSRTS>() != null))
   {
     Thing srts = allCurrentThings.First(x => x.TryGetComp<CompLaunchableSRTS>() != null);
     __result = SRTSMod.GetStatFor<float>(srts.def.defName, StatName.massCapacity);
     return false;
   }
   return true;
 }
Esempio n. 4
0
 public static bool MinPawnRestrictionsSRTS(List <CompTransporter> transporters, List <Pawn> pawns)
 {
     if (transporters.Any(x => x.parent.GetComp <CompLaunchableSRTS>() != null))
     {
         int minPawns = transporters.Min(x => SRTSMod.GetStatFor <int>(x.parent.def.defName, StatName.minPassengers));
         if (pawns.Where(x => x.IsColonistPlayerControlled).Count() < minPawns)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 5
0
 public static bool MaxPawnRestrictionsSRTS(List <CompTransporter> transporters, List <Pawn> pawns)
 {
     if (transporters.Any(x => x.parent.GetComp <CompLaunchableSRTS>() != null))
     {
         int maxPawns = transporters.Max(x => SRTSMod.GetStatFor <int>(x.parent.def.defName, StatName.maxPassengers));
         if (pawns.Count > maxPawns)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 6
0
 public static bool CustomSRTSMassCapacity(ref float __result, List<CompTransporter> ___transporters)
 {
   if (___transporters.Any(x => x.parent.TryGetComp<CompLaunchableSRTS>() != null))
   {
     float num = 0f;
     foreach (CompTransporter comp in ___transporters)
     {
       num += SRTSMod.GetStatFor<float>(comp.parent.def.defName, StatName.massCapacity);
     }
     __result = num;
     return false;
   }
   return true;
 }
Esempio n. 7
0
        public static BomberSkyfaller SpawnSkyfaller(ThingDef skyfaller, Thing innerThing, IntVec3 start, IntVec3 end, List <IntVec3> bombCells, BombingType bombType, Map map, int idNumber, Thing original, Map originalMap, IntVec3 landingSpot)
        {
            BomberSkyfaller thing = BomberSkyfallerMaker.MakeSkyfaller(skyfaller, innerThing);

            thing.originalMap              = originalMap;
            thing.sourceLandingSpot        = landingSpot;
            thing.numberOfBombs            = SRTSMod.GetStatFor <int>(original.def.defName, StatName.numberBombs);
            thing.precisionBombingNumBombs = SRTSMod.GetStatFor <int>(original.def.defName, StatName.precisionBombingNumBombs);
            thing.speed    = SRTSMod.GetStatFor <float>(original.def.defName, StatName.bombingSpeed);
            thing.radius   = SRTSMod.GetStatFor <int>(original.def.defName, StatName.radiusDrop);
            thing.sound    = original.TryGetComp <CompBombFlyer>().Props.soundFlyBy;
            thing.bombType = bombType;

            double angle = start.AngleToPointRelative(end);

            thing.angle = (float)(angle + 90) * -1;
            IntVec3 exitPoint = SPTrig.ExitPointCustom(angle, start, map);

            BomberSkyfaller bomber = (BomberSkyfaller)GenSpawn.Spawn(thing, exitPoint, map, WipeMode.Vanish);

            bomber.bombCells = bombCells;
            return(bomber);
        }
Esempio n. 8
0
    public static bool CustomTravelSpeedSRTS(int ___initialTile, int ___destinationTile, List<ActiveDropPodInfo> ___pods, ref float __result)
    {
      if (___pods.Any(x => x.innerContainer.Any(y => y.TryGetComp<CompLaunchableSRTS>() != null)))
      {
        Vector3 start = Find.WorldGrid.GetTileCenter(___initialTile);
        Vector3 end = Find.WorldGrid.GetTileCenter(___destinationTile);

        if (start == end)
        {
          __result = 1f;
          return false;
        }
        float num = GenMath.SphericalDistance(start.normalized, end.normalized) * 100000;
        if (num == 0f)
        {
          __result = 1f;
          return false;
        }
        Thing ship = ___pods.Find(x => x.innerContainer.First(y => y.TryGetComp<CompLaunchableSRTS>() != null) != null).innerContainer.First(z => z.TryGetComp<CompLaunchableSRTS>() != null);
        __result = SRTSMod.GetStatFor<float>(ship.def.defName, StatName.flightSpeed) / num;
        return false;
      }
      return true;
    }
Esempio n. 9
0
        public override IEnumerable <Gizmo> CompGetGizmosExtra()
        {
            if (SRTS_Launcher.GetComp <CompLaunchableSRTS>().LoadingInProgressOrReadyToLaunch)
            {
                yield return(new Command_Action()
                {
                    defaultLabel = "BombTarget".Translate(),
                    defaultDesc = "BombTargetDesc".Translate(),
                    icon = TexCommand.Attack,
                    action = delegate()
                    {
                        int num = 0;
                        foreach (Thing t in CompLauncher.Transporter.innerContainer)
                        {
                            if (t is Pawn && (t as Pawn).IsColonist)
                            {
                                num++;
                            }
                        }
                        if (SRTSMod.mod.settings.passengerLimits)
                        {
                            if (num < SRTSMod.GetStatFor <int>(this.parent.def.defName, StatName.minPassengers))
                            {
                                Messages.Message("NotEnoughPilots".Translate(), MessageTypeDefOf.RejectInput, false);
                                return;
                            }
                            else if (num > SRTSMod.GetStatFor <int>(this.parent.def.defName, StatName.maxPassengers))
                            {
                                Messages.Message("TooManyPilots".Translate(), MessageTypeDefOf.RejectInput, false);
                                return;
                            }
                        }

                        FloatMenuOption carpetBombing = new FloatMenuOption("CarpetBombing".Translate(), delegate()
                        {
                            bombType = BombingType.carpet;
                            if (CompLauncher.AnyInGroupHasAnythingLeftToLoad)
                            {
                                Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmSendNotCompletelyLoadedPods".Translate(CompLauncher.FirstThingLeftToLoadInGroup.LabelCapNoCount,
                                                                                                                                         CompLauncher.FirstThingLeftToLoadInGroup), StartChoosingDestinationBomb));
                            }
                            this.StartChoosingDestinationBomb();
                        });
                        FloatMenuOption preciseBombing = new FloatMenuOption("PreciseBombing".Translate(), delegate()
                        {
                            bombType = BombingType.precise;
                            if (CompLauncher.AnyInGroupHasAnythingLeftToLoad)
                            {
                                Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmSendNotCompletelyLoadedPods".Translate(CompLauncher.FirstThingLeftToLoadInGroup.LabelCapNoCount,
                                                                                                                                         CompLauncher.FirstThingLeftToLoadInGroup), StartChoosingDestinationBomb));
                            }
                            this.StartChoosingDestinationBomb();
                        });
                        Find.WindowStack.Add(new FloatMenuGizmo(new List <FloatMenuOption>()
                        {
                            carpetBombing, preciseBombing
                        }, this.parent, this.parent.LabelCap, UI.MouseMapPosition()));
                    }
                });
            }
        }
Esempio n. 10
0
        private bool ChoseWorldTarget(GlobalTargetInfo target)
        {
            if (this.carr == null && !this.LoadingInProgressOrReadyToLaunch)
            {
                return(true);
            }
            if (!target.IsValid)
            {
                Messages.Message("MessageTransportPodsDestinationIsInvalid".Translate(), MessageTypeDefOf.RejectInput, false);
                return(false);
            }

            int num = Find.WorldGrid.TraversalDistanceBetween(this.carr != null ? this.carr.Tile : this.parent.Map.Tile, target.Tile, true, int.MaxValue);

            if (num > this.MaxLaunchDistance)
            {
                Messages.Message("MessageTransportPodsDestinationIsTooFar".Translate(CompLaunchableSRTS.FuelNeededToLaunchAtDist((float)num, this.BaseFuelPerTile).ToString("0.#")), MessageTypeDefOf.RejectInput, false);
                return(false);
            }
            if ((Find.WorldGrid[target.Tile].biome.impassable || Find.World.Impassable(target.Tile)) && (!SRTSHelper.SOS2ModLoaded || target.WorldObject?.def?.defName != "ShipOrbiting"))
            {
                Messages.Message("MessageTransportPodsDestinationIsInvalid".Translate(), MessageTypeDefOf.RejectInput, false);
                return(false);
            }
            if (SRTSHelper.SOS2ModLoaded && target.WorldObject?.def?.defName == "ShipOrbiting")
            {
                if (!SRTSMod.GetStatFor <bool>(this.parent.def.defName, StatName.spaceFaring))
                {
                    Messages.Message("NonSpaceFaringSRTS".Translate(parent.def.defName), MessageTypeDefOf.RejectInput, false);
                    return(false);
                }
                if (SRTSMod.GetStatFor <bool>(parent.def.defName, StatName.shuttleBayLanding))
                {
                    IntVec3 shuttleBayPos = (IntVec3)AccessTools.Method(type: SRTSHelper.SOS2LaunchableType, "FirstShuttleBayOpen").Invoke(null, new object[] { (target.WorldObject as MapParent).Map });
                    if (shuttleBayPos == IntVec3.Zero)
                    {
                        Messages.Message("NeedOpenShuttleBay".Translate(), MessageTypeDefOf.RejectInput);
                        return(false);
                    }
                    this.TryLaunch(target.Tile, new TransportPodsArrivalAction_LandInSpecificCell((target.WorldObject as MapParent).Map.Parent, shuttleBayPos));
                    return(true);
                }
            }
            Find.WorldObjects.MapParentAt(target.Tile);
            IEnumerable <FloatMenuOption> floatMenuOptionsAt = this.GetTransportPodsFloatMenuOptionsAt(target.Tile, this.carr);

            if (!floatMenuOptionsAt.Any <FloatMenuOption>())
            {
                if (Find.WorldGrid[target.Tile].biome.impassable || Find.World.Impassable(target.Tile))
                {
                    Messages.Message("MessageTransportPodsDestinationIsInvalid".Translate(), MessageTypeDefOf.RejectInput, false);
                    return(false);
                }
                this.TryLaunch(target.Tile, (TransportPodsArrivalAction)null, (Caravan)null);
                return(true);
            }
            if (floatMenuOptionsAt.Count <FloatMenuOption>() == 1)
            {
                if (!floatMenuOptionsAt.First <FloatMenuOption>().Disabled)
                {
                    floatMenuOptionsAt.First <FloatMenuOption>().action();
                }
                return(false);
            }
            Find.WindowStack.Add((Window) new FloatMenu(floatMenuOptionsAt.ToList <FloatMenuOption>()));
            return(false);
        }
Esempio n. 11
0
        public override IEnumerable <Gizmo> CompGetGizmosExtra()
        {
            foreach (Gizmo gizmo in base.CompGetGizmosExtra())
            {
                Gizmo g = gizmo;
                yield return(g);

                g = null;
            }
            if (this.LoadingInProgressOrReadyToLaunch)
            {
                Command_Action launch = new Command_Action();
                launch.defaultLabel = "CommandLaunchGroup".Translate();
                launch.defaultDesc  = "CommandLaunchGroupDesc".Translate();
                launch.icon         = LaunchCommandTex;
                launch.alsoClickIfOtherInGroupClicked = false;
                launch.action = (Action)(() =>
                {
                    int num = 0;
                    foreach (Thing t in this.Transporter.innerContainer)
                    {
                        if (t is Pawn && (t as Pawn).IsColonist)
                        {
                            num++;
                        }
                    }
                    if (SRTSMod.mod.settings.passengerLimits)
                    {
                        if (num < SRTSMod.GetStatFor <int>(this.parent.def.defName, StatName.minPassengers))
                        {
                            Messages.Message("NotEnoughPilots".Translate(), MessageTypeDefOf.RejectInput, false);
                            return;
                        }
                        else if (num > SRTSMod.GetStatFor <int>(this.parent.def.defName, StatName.maxPassengers))
                        {
                            Messages.Message("TooManyPilots".Translate(), MessageTypeDefOf.RejectInput, false);
                            return;
                        }
                    }

                    if (this.AnyInGroupHasAnythingLeftToLoad)
                    {
                        Find.WindowStack.Add((Window)Dialog_MessageBox.CreateConfirmation("ConfirmSendNotCompletelyLoadedPods".Translate(this.FirstThingLeftToLoadInGroup.LabelCapNoCount), new Action(this.StartChoosingDestination), false, (string)null));
                    }
                    else
                    {
                        this.StartChoosingDestination();
                    }
                });
                if (!this.AllInGroupConnectedToFuelingPort)
                {
                    launch.Disable("CommandLaunchGroupFailNotConnectedToFuelingPort".Translate());
                }
                else if (!this.AllFuelingPortSourcesInGroupHaveAnyFuel)
                {
                    launch.Disable("CommandLaunchGroupFailNoFuel".Translate());
                }
                else if (this.AnyInGroupIsUnderRoof && !this.parent.Position.GetThingList(this.parent.Map).Any(x => x.def.defName == "ShipShuttleBay"))
                {
                    launch.Disable("CommandLaunchGroupFailUnderRoof".Translate());
                }
                yield return(launch);
            }
        }
        private IntVec3 TargeterToCell(int bombNumber)
        {
            IntVec3 mousePosition      = UI.MouseMapPosition().ToIntVec3();
            IntVec3 targetedCell       = new IntVec3(mousePosition.x, selections[0].Cell.y, mousePosition.z);
            double  angle              = selections[0].Cell.AngleToPoint(targetedCell);
            float   distanceToNextBomb = SRTSMod.mod.settings.expandBombPoints ? this.targetingLength / (this.numRings - 1) * bombNumber : SRTSMod.GetStatFor <float>(this.bomber.defName, StatName.distanceBetweenDrops) * bombNumber;
            float   xDiff              = selections[0].Cell.x + Math.Sign(UI.MouseMapPosition().x - selections[0].CenterVector3.x) *
                                         (float)(distanceToNextBomb * Math.Cos(angle.DegreesToRadians()));
            float zDiff = selections[0].Cell.z + Math.Sign(UI.MouseMapPosition().z - selections[0].CenterVector3.z) *
                          (float)(distanceToNextBomb * Math.Sin(angle.DegreesToRadians()));

            return(new IntVec3((int)xDiff, 0, (int)zDiff));
        }
Esempio n. 13
0
 public static NamedArgument GetResearchStatString(ResearchProjectDef project) => SRTSMod.GetStatFor <float>(srtsDefProjects.FirstOrDefault(x => x.Value == project).Key.defName, StatName.researchPoints).ToString("F0");
Esempio n. 14
0
 public static float GetResearchStat(ResearchProjectDef project) => SRTSMod.GetStatFor <float>(srtsDefProjects.FirstOrDefault(x => x.Value == project).Key.defName, StatName.researchPoints);
Esempio n. 15
0
 public SRTSMod(ModContentPack content) : base(content)
 {
     this.settings = GetSettings <SRTS_ModSettings>();
     mod           = this;
 }
Esempio n. 16
0
    public static IEnumerable<Gizmo> LaunchAndBombGizmosPassthrough(IEnumerable<Gizmo> __result, Caravan __instance)
    {
      IEnumerator<Gizmo> enumerator = __result.GetEnumerator();
      while (enumerator.MoveNext())
      {
        var element = enumerator.Current;
        yield return element;
        if ((element as Command_Action)?.defaultLabel == "CommandSettle".Translate() && __instance.PawnsListForReading.Any(x => x.inventory.innerContainer.Any(y => y.TryGetComp<CompLaunchableSRTS>() != null)))
        {
          float massUsage = 0f;
          Thing srts = null;
          foreach (Pawn p in __instance.PawnsListForReading)
          {
            foreach (Thing t in p.inventory?.innerContainer)
            {
              if (t.TryGetComp<CompLaunchableSRTS>() != null)
                srts = t;
              else
              {
                massUsage += t.GetStatValue(StatDefOf.Mass, true) * t.stackCount;
              }
            }
            massUsage += p.GetStatValue(StatDefOf.Mass, true);
            massUsage -= MassUtility.InventoryMass(p) * p.stackCount;
          }
          yield return new Command_Action
          {
            defaultLabel = "CommandLaunchGroup".Translate(),
            defaultDesc = "CommandLaunchGroupDesc".Translate(),
            icon = Tex2D.LaunchSRTS,
            alsoClickIfOtherInGroupClicked = false,
            action = delegate ()
            {
              if (massUsage > SRTSMod.GetStatFor<float>(srts.def.defName, StatName.massCapacity))
                Messages.Message("TooBigTransportersMassUsage".Translate(), MessageTypeDefOf.RejectInput, false);
              else
                srts.TryGetComp<CompLaunchableSRTS>().WorldStartChoosingDestination(__instance);
            }
          };
          /* Not Yet Implemented */
          /*yield return new Command_Action
          {
              defaultLabel = "BombTarget".Translate(),
              defaultDesc = "BombTargetDesc".Translate(),
              icon = TexCommand.Attack,
              action = delegate ()
              {
                  if(SRTSMod.mod.settings.passengerLimits)
                  {
                      if(__instance.PawnsListForReading.Count < SRTSMod.GetStatFor<int>(srts.def.defName, StatName.minPassengers))
                      {
                          Messages.Message("NotEnoughPilots".Translate(), MessageTypeDefOf.RejectInput, false);
                          return;
                      }
                      else if(__instance.PawnsListForReading.Count > SRTSMod.GetStatFor<int>(srts.def.defName, StatName.maxPassengers))
                      {
                          Messages.Message("TooManyPilots".Translate(), MessageTypeDefOf.RejectInput, false);
                          return;
                      }
                  }

                  FloatMenuOption carpetBombing = new FloatMenuOption("CarpetBombing".Translate(), delegate ()
                  {
                      srts.TryGetComp<CompBombFlyer>().bombType = BombingType.carpet;
                      srts.TryGetComp<CompBombFlyer>().StartChoosingWorldDestinationBomb(__instance);
                  });
                  FloatMenuOption preciseBombing = new FloatMenuOption("PreciseBombing".Translate(), delegate ()
                  {
                      srts.TryGetComp<CompBombFlyer>().bombType = BombingType.precise;
                      srts.TryGetComp<CompBombFlyer>().StartChoosingWorldDestinationBomb(__instance);
                  });
                  Find.WindowStack.Add(new FloatMenuGizmo(new List<FloatMenuOption>() { carpetBombing, preciseBombing }, srts, srts.LabelCap, UI.MouseMapPosition()));
              }
          };*/

          Command_Action RefuelSRTS = new Command_Action()
          {
            defaultLabel = "CommandAddFuelSRTS".Translate(srts.TryGetComp<CompRefuelable>().parent.Label),
            defaultDesc = "CommandAddFuelDescSRTS".Translate(),
            icon = Tex2D.FuelSRTS,
            alsoClickIfOtherInGroupClicked = false,
            action = delegate ()
            {
              bool flag = false;
              int count = 0;
              List<Thing> thingList = CaravanInventoryUtility.AllInventoryItems(__instance);
              for (int index = 0; index < thingList.Count; ++index)
              {
                if (thingList[index].def == ThingDefOf.Chemfuel)
                {
                  count = thingList[index].stackCount;
                  Pawn ownerOf = CaravanInventoryUtility.GetOwnerOf(__instance, thingList[index]);
                  float num = srts.TryGetComp<CompRefuelable>().Props.fuelCapacity - srts.TryGetComp<CompRefuelable>().Fuel;
                  if ((double)num < 1.0 && (double)num > 0.0)
                    count = 1;
                  if ((double)count * 1.0 >= (double)num)
                    count = (int)num;
                  if ((double)thingList[index].stackCount * 1.0 <= (double)count)
                  {
                    thingList[index].stackCount -= count;
                    Thing thing = thingList[index];
                    ownerOf.inventory.innerContainer.Remove(thing);
                    thing.Destroy(DestroyMode.Vanish);
                  }
                  else if ((uint)count > 0U)
                    thingList[index].SplitOff(count).Destroy(DestroyMode.Vanish);
                  srts.TryGetComp<CompRefuelable>().GetType().GetField("fuel", BindingFlags.Instance | BindingFlags.NonPublic).SetValue((object)srts.TryGetComp<CompRefuelable>(), (object)(float)((double)srts.TryGetComp<CompRefuelable>().Fuel + (double)count));
                  flag = true;
                  break;
                }
              }
              if (flag)
                Messages.Message("AddFuelSRTSCaravan".Translate(count, srts.LabelCap), MessageTypeDefOf.PositiveEvent, false);
              else
                Messages.Message("NoFuelSRTSCaravan".Translate(), MessageTypeDefOf.RejectInput, false);
            }
          };
          if (srts.TryGetComp<CompRefuelable>().IsFull)
            RefuelSRTS.Disable();
          yield return RefuelSRTS;
          yield return new Gizmo_MapRefuelableFuelStatus
          {

            nowFuel = srts.TryGetComp<CompRefuelable>().Fuel,
            maxFuel = srts.TryGetComp<CompRefuelable>().Props.fuelCapacity,
            compLabel = srts.TryGetComp<CompRefuelable>().Props.FuelGizmoLabel
          };
        }
      }
    }