private bool ChoseWorldTarget(GlobalTargetInfo target) { bool result; if (!this.LoadingInProgressOrReadyToLaunch) { result = true; } else if (!target.IsValid) { Messages.Message("MessageTransportPodsDestinationIsInvalid".Translate(), MessageTypeDefOf.RejectInput, false); result = false; } else { int num = Find.WorldGrid.TraversalDistanceBetween(this.parent.Map.Tile, target.Tile, true, int.MaxValue); if (num > this.MaxLaunchDistance) { Messages.Message("MessageTransportPodsDestinationIsTooFar".Translate(new object[] { CompLaunchable.FuelNeededToLaunchAtDist((float)num).ToString("0.#") }), MessageTypeDefOf.RejectInput, false); result = false; } else { IEnumerable <FloatMenuOption> transportPodsFloatMenuOptionsAt = this.GetTransportPodsFloatMenuOptionsAt(target.Tile); if (!transportPodsFloatMenuOptionsAt.Any <FloatMenuOption>()) { if (Find.World.Impassable(target.Tile)) { Messages.Message("MessageTransportPodsDestinationIsInvalid".Translate(), MessageTypeDefOf.RejectInput, false); result = false; } else { this.TryLaunch(target.Tile, null); result = true; } } else if (transportPodsFloatMenuOptionsAt.Count <FloatMenuOption>() == 1) { if (!transportPodsFloatMenuOptionsAt.First <FloatMenuOption>().Disabled) { transportPodsFloatMenuOptionsAt.First <FloatMenuOption>().action(); } result = false; } else { Find.WindowStack.Add(new FloatMenu(transportPodsFloatMenuOptionsAt.ToList <FloatMenuOption>())); result = false; } } } return(result); }
private void TryLaunch(GlobalTargetInfo target, PawnsArriveMode arriveMode, bool attackOnArrival) { if (!this.parent.Spawned) { Log.Error("Tried to launch " + this.parent + ", but it's unspawned."); return; } List <CompTransporter> transportersInGroup = this.TransportersInGroup; if (transportersInGroup == null) { Log.Error("Tried to launch " + this.parent + ", but it's not in any group."); return; } if (!this.LoadingInProgressOrReadyToLaunch || !this.AllInGroupConnectedToFuelingPort || !this.AllFuelingPortSourcesInGroupHaveAnyFuel) { return; } Map map = this.parent.Map; int num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, target.Tile); if (num > this.MaxLaunchDistance) { return; } this.Transporter.TryRemoveLord(map); int groupID = this.Transporter.groupID; float amount = Mathf.Max(CompLaunchable.FuelNeededToLaunchAtDist((float)num), 1f); for (int i = 0; i < transportersInGroup.Count; i++) { CompTransporter compTransporter = transportersInGroup[i]; Building fuelingPortSource = compTransporter.Launchable.FuelingPortSource; if (fuelingPortSource != null) { fuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount); } ThingOwner directlyHeldThings = compTransporter.GetDirectlyHeldThings(); ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDefOf.ActiveDropPod, null); activeDropPod.Contents = new ActiveDropPodInfo(); activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer(directlyHeldThings, true, true); DropPodLeaving dropPodLeaving = (DropPodLeaving)SkyfallerMaker.MakeSkyfaller(ThingDefOf.DropPodLeaving, activeDropPod); dropPodLeaving.groupID = groupID; dropPodLeaving.destinationTile = target.Tile; dropPodLeaving.destinationCell = target.Cell; dropPodLeaving.arriveMode = arriveMode; dropPodLeaving.attackOnArrival = attackOnArrival; compTransporter.CleanUpLoadingVars(map); compTransporter.parent.Destroy(DestroyMode.Vanish); GenSpawn.Spawn(dropPodLeaving, compTransporter.parent.Position, map); } }
public void TryLaunch(int destinationTile, TransportPodsArrivalAction arrivalAction) { if (!this.parent.Spawned) { Log.Error("Tried to launch " + this.parent + ", but it's unspawned.", false); } else { List <CompTransporter> transportersInGroup = this.TransportersInGroup; if (transportersInGroup == null) { Log.Error("Tried to launch " + this.parent + ", but it's not in any group.", false); } else if (this.LoadingInProgressOrReadyToLaunch && this.AllInGroupConnectedToFuelingPort && this.AllFuelingPortSourcesInGroupHaveAnyFuel) { Map map = this.parent.Map; int num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, destinationTile, true, int.MaxValue); if (num <= this.MaxLaunchDistance) { this.Transporter.TryRemoveLord(map); int groupID = this.Transporter.groupID; float amount = Mathf.Max(CompLaunchable.FuelNeededToLaunchAtDist((float)num), 1f); for (int i = 0; i < transportersInGroup.Count; i++) { CompTransporter compTransporter = transportersInGroup[i]; Building fuelingPortSource = compTransporter.Launchable.FuelingPortSource; if (fuelingPortSource != null) { fuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount); } ThingOwner directlyHeldThings = compTransporter.GetDirectlyHeldThings(); ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDefOf.ActiveDropPod, null); activeDropPod.Contents = new ActiveDropPodInfo(); activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer(directlyHeldThings, true, true); DropPodLeaving dropPodLeaving = (DropPodLeaving)SkyfallerMaker.MakeSkyfaller(ThingDefOf.DropPodLeaving, activeDropPod); dropPodLeaving.groupID = groupID; dropPodLeaving.destinationTile = destinationTile; dropPodLeaving.arrivalAction = arrivalAction; compTransporter.CleanUpLoadingVars(map); compTransporter.parent.Destroy(DestroyMode.Vanish); GenSpawn.Spawn(dropPodLeaving, compTransporter.parent.Position, map, WipeMode.Vanish); } CameraJumper.TryHideWorld(); } } } }
private bool ChoseWorldTarget(GlobalTargetInfo target) { if (!this.LoadingInProgressOrReadyToLaunch) { return(true); } if (!target.IsValid) { Messages.Message("MessageTransportPodsDestinationIsInvalid".Translate(), MessageTypeDefOf.RejectInput); return(false); } int num = Find.WorldGrid.TraversalDistanceBetween(this.parent.Map.Tile, target.Tile); if (num > this.MaxLaunchDistance) { Messages.Message("MessageTransportPodsDestinationIsTooFar".Translate(new object[] { CompLaunchable.FuelNeededToLaunchAtDist((float)num).ToString("0.#") }), MessageTypeDefOf.RejectInput); return(false); } MapParent mapParent = target.WorldObject as MapParent; if (mapParent != null && mapParent.HasMap) { Map myMap = this.parent.Map; Map map = mapParent.Map; Current.Game.VisibleMap = map; Find.Targeter.BeginTargeting(TargetingParameters.ForDropPodsDestination(), delegate(LocalTargetInfo x) { if (!this.LoadingInProgressOrReadyToLaunch) { return; } this.TryLaunch(x.ToGlobalTargetInfo(map), PawnsArriveMode.Undecided, false); }, null, delegate { if (Find.Maps.Contains(myMap)) { Current.Game.VisibleMap = myMap; } }, CompLaunchable.TargeterMouseAttachment); return(true); } bool flag; if (mapParent != null) { Settlement settlement = mapParent as Settlement; List <FloatMenuOption> list = new List <FloatMenuOption>(); if (settlement != null && settlement.Visitable) { list.Add(new FloatMenuOption("VisitSettlement".Translate(new object[] { target.WorldObject.Label }), delegate { if (!this.LoadingInProgressOrReadyToLaunch) { return; } this.TryLaunch(target, PawnsArriveMode.Undecided, false); CameraJumper.TryHideWorld(); }, MenuOptionPriority.Default, null, null, 0f, null, null)); } if (mapParent.TransportPodsCanLandAndGenerateMap) { list.Add(new FloatMenuOption("DropAtEdge".Translate(), delegate { if (!this.LoadingInProgressOrReadyToLaunch) { return; } this.TryLaunch(target, PawnsArriveMode.EdgeDrop, true); CameraJumper.TryHideWorld(); }, MenuOptionPriority.Default, null, null, 0f, null, null)); list.Add(new FloatMenuOption("DropInCenter".Translate(), delegate { if (!this.LoadingInProgressOrReadyToLaunch) { return; } this.TryLaunch(target, PawnsArriveMode.CenterDrop, true); CameraJumper.TryHideWorld(); }, MenuOptionPriority.Default, null, null, 0f, null, null)); } if (list.Any <FloatMenuOption>()) { Find.WorldTargeter.closeWorldTabWhenFinished = false; Find.WindowStack.Add(new FloatMenu(list)); return(true); } flag = true; } else { flag = true; } if (!flag) { return(false); } if (Find.World.Impassable(target.Tile)) { Messages.Message("MessageTransportPodsDestinationIsInvalid".Translate(), MessageTypeDefOf.RejectInput); return(false); } this.TryLaunch(target, PawnsArriveMode.Undecided, false); return(true); }