public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn selPawn) { IEnumerator <FloatMenuOption> enumerator = base.GetFloatMenuOptions(selPawn).GetEnumerator(); while (enumerator.MoveNext()) { FloatMenuOption current = enumerator.Current; yield return(current); } Action action = delegate { if (selPawn.CanReach(this, PathEndMode.ClosestTouch, Danger.Deadly)) { Job job = new Job(ShipNamespaceDefOfs.EnterShip, this); selPawn.jobs.TryTakeOrderedJob(job); } }; if (DropShipUtility.AllPawnsInShip(this).Count < this.compShip.sProps.maxPassengers + 1) { yield return(new FloatMenuOption("EnterShip".Translate(), action, MenuOptionPriority.Default, null, null, 0f, null, null)); } else { yield return(new FloatMenuOption("ShipPassengersFull".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null)); } }
public static float ApproxDaysWorthOfFood_Ship(ShipBase ship, List <TransferableOneWay> transferables, bool canEatPlants) { tmpTransferables.Clear(); for (int i = 0; i < transferables.Count; i++) { TransferableOneWay oneWay = new TransferableOneWay(); oneWay.things.AddRange(transferables[i].things); oneWay.AdjustTo(transferables[i].CountToTransfer); Pawn pawn = oneWay.AnyThing as Pawn; tmpTransferables.Add(oneWay); } foreach (Pawn current in ship.GetDirectlyHeldThings().Where(x => x is Pawn)) { DropShipUtility.AddThingsToTransferables(tmpTransferables, current); } for (int i = 0; i < ship.GetDirectlyHeldThings().Count; i++) { if (!(ship.GetDirectlyHeldThings()[i] is Pawn)) { DropShipUtility.AddThingsToTransferables(tmpTransferables, ship.GetDirectlyHeldThings()[i]); } } var potentialFood = tmpTransferables.Where(t => (t.AnyThing is Pawn) == false).SelectMany(x => x.things).ToList(); var pawns = tmpTransferables.Where(t => t.AnyThing is Pawn).SelectMany(x => x.things).Cast <Pawn>().ToList(); return(DaysWorthOfFoodCalculator.ApproxDaysWorthOfFood(pawns, potentialFood, 0, IgnorePawnsInventoryMode.DontIgnore, ship.Faction)); }
public static void RemoveExistingTransferable(TransferableOneWay transferable, Map map = null, ShipBase ship = null) { List <Thing> thingsInCargoToRemov = new List <Thing>(); List <ShipBase> tmpShips = new List <ShipBase>(); if (ship != null) { tmpShips.Add(ship); } else if (map != null) { tmpShips = DropShipUtility.ShipsOnMap(map); } else { Log.Error("Tried removing transferables with neither ship nor map specified"); } for (int j = 0; j < transferable.things.Count; j++) { for (int k = 0; k < tmpShips.Count; k++) { Thing thing = tmpShips[k].GetDirectlyHeldThings().FirstOrDefault(x => x == (transferable.things[j])); if (thing != null) { Log.Message("FoundCargo"); thingsInCargoToRemov.Add(transferable.things[j]); // transferable.CountToTransfer -= transferable.things[j].stackCount; } } } transferable.things.RemoveAll(x => thingsInCargoToRemov.Contains(x)); }
public bool TryInstallTurret(CompShipWeapon comp) { if (comp.SProps.TurretToInstall != null) { ShipWeaponSlot slot = comp.slotToInstall; Building_ShipTurret turret = (Building_ShipTurret)ThingMaker.MakeThing(comp.SProps.TurretToInstall, null); turret.installedByWeaponSystem = comp.parent.def; this.installedTurrets[slot] = turret; turret.AssignParentShip(this); turret.assignedSlotName = slot.SlotName; turret.SetFactionDirect(this.Faction); if (slot.turretMinSize.x != turret.def.size.x) { // turret.def.size.x = slot.turretMinSize.x; } if (slot.turretMinSize.z != turret.def.size.z) { // turret.def.size.z = slot.turretMinSize.z; } IntVec3 drawLoc = this.Position + DropShipUtility.AdjustedIntVecForShip(this, slot.turretPosOffset); if (!turret.Spawned) { GenSpawn.Spawn(turret, drawLoc, this.Map); } this.assignedTurrets.Add(turret); return(true); } return(false); }
public static void DropShipGroups(IntVec3 dropCenter, Map map, List <ShipBase> shipsToDrop, TravelingShipArrivalAction arrivalAction, bool launchdAsSingleShip = false) { foreach (ShipBase current in shipsToDrop) { IntVec3 dropLoc; // if (TryFindShipDropLocationNear(dropCenter, 200, map, out dropLoc, current.def.size)) // if (DropCellFinder.TryFindRaidDropCenterClose(out dropLoc, map)) try { dropLoc = dropCenter; if (dropLoc.IsValid && launchdAsSingleShip) { Log.Message("Dropping single Ship"); } else { if (!DropShipUtility.TryFindShipDropSpotNear(current, dropCenter, map, out dropLoc, true, true)) { DropShipUtility.TryFindShipDropSpotNear(current, DropCellFinder.FindRaidDropCenterDistant(map), map, out dropLoc, true, true); } } current.drawTickOffset = current.compShip.sProps.TicksToImpact + Rand.Range(10, 60); current.ActivatedLaunchSequence = false; current.shipState = ShipState.Incoming; ShipBase_Traveling incomingShip = new ShipBase_Traveling(current, false, arrivalAction); // Log.Message("Dropping " + incomingShip.containingShip.ShipNick); GenSpawn.Spawn(incomingShip, dropLoc, map); } catch (Exception ex) { Log.Error("Couldn't drop ships in map: " + ex.ToString()); } } }
public static void DrawDropSpotShadow(ShipBase ship, int ticks, ShipBase_Traveling travelingShip = null) { if (ticks < 0) { ticks = 0; } Vector3 result = Gen.TrueCenter(ship); if (travelingShip != null) { result = travelingShip.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.FlyingItem); } result += DropShipUtility.drawOffsetFor(ship, ticks, true); result.y = Altitudes.AltitudeFor(AltitudeLayer.Shadows); Color white = Color.white; white.a = Mathf.InverseLerp(200f, 150f, (float)ticks); DropShipUtility.shadowPropertyBlock.SetColor(ShaderIDs.ColorId, white); Matrix4x4 matrix = default(Matrix4x4); matrix.SetTRS(result, ship.compShip.parent.Rotation.AsQuat, new Vector3(1f, 1f, 1f)); Graphics.DrawMesh(ship.compShip.parent.Graphic.MeshAt(ship.compShip.parent.Rotation), matrix, ship.compShip.dropShadow.MatSingle, 0, null, 0, DropShipUtility.shadowPropertyBlock); }
public static void LaunchLandedFleet(LandedShip landedShip, int destinationTile, IntVec3 destinationCell, PawnsArriveMode pawnArriveMode, TravelingShipArrivalAction arrivalAction) { if (destinationTile < 0) { Log.Error("Tried launching landed ship, but its destination tile is " + destinationTile); return; } TravelingShips travelingShips = (TravelingShips)WorldObjectMaker.MakeWorldObject(ShipNamespaceDefOfs.TravelingSuborbitalShip); travelingShips.Tile = landedShip.Tile; travelingShips.SetFaction(landedShip.Faction); travelingShips.destinationTile = destinationTile; travelingShips.destinationCell = destinationCell; // travelingShips.destinationCell = this.destinationCell; travelingShips.arriveMode = pawnArriveMode; travelingShips.arrivalAction = arrivalAction; Find.WorldObjects.Add(travelingShips); foreach (ShipBase current in landedShip.ships) { travelingShips.AddShip(current, true); // current.SavePotentialWorldPawns(); DropShipUtility.ReimbarkWorldPawnsForLandedShip(current); } travelingShips.SetFaction(landedShip.Faction); TravelingShipsUtility.AddAllLandedPawnsToWorld(landedShip); if (Find.World.worldObjects.Contains(landedShip)) { Find.World.worldObjects.Remove(landedShip); } }
public override void SpawnSetup(Map map, bool respawningAfterLoad) { base.SpawnSetup(map, respawningAfterLoad); //this.shouldDeepSave = true; this.DeepsaveTurrets = false; if (shouldSpawnTurrets) { foreach (KeyValuePair <ShipWeaponSlot, Building_ShipTurret> current in this.installedTurrets) { if (current.Value != null && !current.Value.Spawned) { IntVec3 drawLoc = this.Position + DropShipUtility.AdjustedIntVecForShip(this, current.Key.turretPosOffset); GenSpawn.Spawn(current.Value, drawLoc, this.Map); } } } this.shouldSpawnTurrets = false; if (shipState == ShipState.Incoming) { SoundDef.Named("ShipTakeoff_SuborbitalLaunch").PlayOneShotOnCamera(); } if (this.ShouldSpawnFueled) { Thing initialFuel = ThingMaker.MakeThing(ShipNamespaceDefOfs.Chemfuel); initialFuel.stackCount = 800; this.refuelableComp.Refuel(initialFuel); this.ShouldSpawnFueled = false; } DropShipUtility.InitializeDropShipSpawn(this); this.FirstSpawned = false; }
public override void Tick() { base.Tick(); if (containingShip.shipState == ShipState.Incoming) { this.containingShip.drawTickOffset--; if (this.containingShip.drawTickOffset <= 0) { this.ShipImpact(); } this.containingShip.refuelableComp.ConsumeFuel(this.containingShip.refuelableComp.Props.fuelConsumptionRate / 60f); } if (this.containingShip.shipState == ShipState.Outgoing) { this.containingShip.drawTickOffset++; if (this.containingShip.drawTickOffset >= containingShip.compShip.sProps.TicksToDespawn) { if (this.leavingForTarget) { this.ShipsLeaving(); } else { List <Pawn> pawns = DropShipUtility.AllPawnsInShip(this.containingShip); for (int i = 0; i < pawns.Count; i++) { Find.WorldPawns.PassToWorld(pawns[i]); } this.Destroy(); } } } }
private void SpawnShipsInMap(Map map, string extraMessagePart = null) { this.RemoveAllPawnsFromWorldPawns(); IntVec3 intVec; if (this.destinationCell.IsValid && this.destinationCell.InBounds(map)) { intVec = this.destinationCell; } else if (this.arriveMode == PawnsArrivalModeDefOf.CenterDrop) { intVec = DropCellFinder.FindRaidDropCenterDistant(map); } else { if (this.arriveMode != PawnsArrivalModeDefOf.EdgeDrop) { Log.Warning("Unsupported arrive mode " + this.arriveMode); } Log.Message("Invalid Cell"); intVec = DropCellFinder.FindRaidDropCenterDistant(map); } string text = "MessageShipsArrived".Translate(); if (extraMessagePart != null) { text = text + " " + extraMessagePart; } DropShipUtility.DropShipGroups(intVec, map, this.ships, this.arrivalAction, this.isSingularShip); Messages.Message(text, new TargetInfo(intVec, map, false), MessageTypeDefOf.NeutralEvent); this.RemoveAllShip(); Find.WorldObjects.Remove(this); }
public static float ApproxDaysWorthOfFood_Ship(ShipBase ship, List <TransferableOneWay> transferables, bool canEatPlants) { tmpTransferables.Clear(); for (int i = 0; i < transferables.Count; i++) { TransferableOneWay oneWay = new TransferableOneWay(); oneWay.things.AddRange(transferables[i].things); oneWay.AdjustTo(transferables[i].CountToTransfer); Pawn pawn = oneWay.AnyThing as Pawn; tmpTransferables.Add(oneWay); } foreach (Pawn current in ship.GetDirectlyHeldThings().Where(x => x is Pawn)) { DropShipUtility.AddThingsToTransferables(tmpTransferables, current); } for (int i = 0; i < ship.GetDirectlyHeldThings().Count; i++) { if (!(ship.GetDirectlyHeldThings()[i] is Pawn)) { DropShipUtility.AddThingsToTransferables(tmpTransferables, ship.GetDirectlyHeldThings()[i]); } } return(DaysWorthOfFoodCalculator.ApproxDaysWorthOfFood(tmpTransferables, canEatPlants, IgnorePawnsInventoryMode.DontIgnore)); }
public static List <ShipBase> CreateDropShips(List <Pawn> pawns, Faction faction, List <ThingDef> fixedShipDefs = null) { List <ShipBase> shipsToDrop = new List <ShipBase>(); List <ThingDef> defs = new List <ThingDef>(); if (fixedShipDefs.NullOrEmpty()) { defs.AddRange(DropShipUtility.AvailableDropShipsForFaction(faction)); } else { defs.AddRange(fixedShipDefs); } defs.OrderBy(x => x.GetCompProperties <CompProperties_Ship>().maxPassengers); int num = 0; while (num < pawns.Count) { ShipBase newShip = (ShipBase)ThingMaker.MakeThing(defs.RandomElementByWeight(x => x.GetCompProperties <CompProperties_Ship>().maxPassengers)); newShip.SetFaction(faction); newShip.ShouldSpawnFueled = true; shipsToDrop.Add(newShip); num += newShip.compShip.sProps.maxPassengers; } DropShipUtility.LoadNewCargoIntoRandomShips(pawns.Cast <Thing>().ToList(), shipsToDrop); return(shipsToDrop); }
public static float ApproxDaysWorthOfFood_Ship(ShipBase ship, List <TransferableOneWay> transferables) { List <TransferableOneWay> tmp = new List <TransferableOneWay>(); tmp.AddRange(transferables); List <TransferableOneWay> tmpPawns = new List <TransferableOneWay>(); List <TransferableOneWay> tmpItems = new List <TransferableOneWay>(); foreach (Pawn current in ship.GetInnerContainer().Where(x => x is Pawn)) { if (!current.RaceProps.Eats(FoodTypeFlags.Plant)) { DropShipUtility.AddThingsToTransferables(tmp, current); } } for (int i = 0; i < ship.GetInnerContainer().Count; i++) { if (!(ship.GetInnerContainer()[i] is Pawn)) { DropShipUtility.AddThingsToTransferables(tmp, ship.GetInnerContainer()[i]); } } return(DaysWorthOfFoodCalculator.ApproxDaysWorthOfFood(tmp)); }
protected override Job TryGiveJob(Pawn pawn) { if (DropShipUtility.LordShipsDestroyed(pawn)) { return(base.TryGiveJob(pawn)); } return(null); }
public override void Draw() { base.Draw(); DropShipUtility.DrawDropSpotShadow(this, this.drawTickOffset); if (Find.Targeter.IsTargeting && Find.Selector.IsSelected(this)) { GhostDrawer.DrawGhostThing(UI.MouseCell(), this.Rotation, this.def, null, new Color(0.5f, 1f, 0.6f, 0.4f), AltitudeLayer.Blueprint); } }
public Thing FindShip(Pawn pawn) { List <ShipBase> allShips = DropShipUtility.ShipsOnMap(pawn.Map).FindAll(x => DropShipUtility.HasPassengerSeats(x) && x.Faction == pawn.Faction); if (allShips.NullOrEmpty()) { return(null); } return(allShips.RandomElement()); }
public virtual bool TryAcceptThing(Thing thing, bool allowSpecialEffects = true) { if (!this.Accepts(thing)) { return(false); } if (thing is Pawn) { Pawn pawn = thing as Pawn; if (pawn.def.race.Humanlike) { if (!DropShipUtility.HasPassengerSeats(this)) { Messages.Message("MessagePassengersFull".Translate(new object[] { pawn.NameStringShort, this.ShipNick }), this, MessageTypeDefOf.RejectInput); return(false); } if (pawn.Spawned) { pawn.DeSpawn(); } if (!this.innerContainer.Contains(pawn)) { //pawn.InContainerEnclosed this.innerContainer.TryAdd(pawn, 1, false); } } else { if (this.innerContainer.TryAdd(thing.SplitOff(thing.stackCount), true)) { return(true); } else { return(false); } } } bool flag; if (thing.holdingOwner != null) { flag = thing.holdingOwner.TryTransferToContainer(thing, this.innerContainer); } else { flag = this.innerContainer.TryAdd(thing.SplitOff(thing.stackCount), true); } if (flag) { return(true); } return(false); }
private static void Enter(WorldShip worldShip, Map map, IntVec3 targetCell, ShipArrivalAction arrivalAction, PawnsArrivalModeDef pawnsArrivalMode) { List <ShipBase> ships = worldShip.WorldShipData.Select(x => x.Ship).ToList(); IntVec3 cell = GetCellForArrivalMode(worldShip.WorldShipData[0].Ship, targetCell, map, pawnsArrivalMode); DropShipUtility.DropShipGroups(cell, map, ships, arrivalAction, worldShip.WorldShipData.Count == 1); if (worldShip.Spawned) { Find.WorldObjects.Remove(worldShip); } }
public static void Enter(LandedShip caravan, Map map, Func <ShipBase, IntVec3> spawnCellGetter) { List <ShipBase> ships = caravan.ships; DropShipUtility.DropShipGroups(TravelingShipsUtility.CenterCell(map), map, ships, ShipArrivalAction.EnterMapFriendly); //caravan.RemoveAllPawns(); if (caravan.Spawned) { Find.WorldObjects.Remove(caravan); } }
private static void AddThingsToTransferables(List <TransferableOneWay> transferables, Thing thing) { TransferableOneWay transferableOneWay = TransferableUtility.TransferableMatching <TransferableOneWay>(thing, transferables); if (transferableOneWay == null) { transferableOneWay = new TransferableOneWay(); transferables.Add(transferableOneWay); } transferableOneWay.things.Add(thing); DropShipUtility.AdjustToOneWayReflection(transferableOneWay, thing.stackCount); }
public override void Draw() { this.containingShip.DrawAt(DropShipUtility.DrawPosAt(this.containingShip, this.containingShip.drawTickOffset, this)); foreach (KeyValuePair <ShipWeaponSlot, Building_ShipTurret> current in this.containingShip.installedTurrets) { if (current.Value != null) { current.Value.Draw(); } } DropShipUtility.DrawDropSpotShadow(this.containingShip, this.containingShip.drawTickOffset, this); }
protected override bool TryResolveRaidFaction(IncidentParms parms) { if (base.TryResolveRaidFaction(parms)) { if (DropShipUtility.FactionHasDropShips(parms.faction)) { return(true); } return(false); } return(false); }
public override void Tick() { base.Tick(); for (int i = 0; i < DropShipUtility.AllPawnsInShip(this).Count; i++) { Pawn pawn = DropShipUtility.AllPawnsInShip(this)[i]; float num = 0.6f; float num2 = RestUtility.PawnHealthRestEffectivenessFactor(pawn); num = 0.7f * num + 0.3f * num * num2; pawn.needs.rest.TickResting(num); } if (this.shipState == ShipState.Incoming) { this.drawTickOffset--; if (this.drawTickOffset <= 0) { this.drawTickOffset = 0; } this.refuelableComp.ConsumeFuel(this.refuelableComp.Props.fuelConsumptionRate / 100f); } if (ReadyForTakeoff && ActivatedLaunchSequence) { this.timeToLiftoff--; if (this.ShouldWait) { int num = GenDate.TicksPerHour; this.timeToLiftoff += num; this.timeWaited += num; if (this.timeWaited >= maxTimeToWait) { this.ShouldWait = false; this.timeToLiftoff = 0; } } if (this.timeToLiftoff == 0) { this.shipState = ShipState.Outgoing; this.ActivatedLaunchSequence = false; } } if (shipState == ShipState.Outgoing) { this.drawTickOffset++; this.refuelableComp.ConsumeFuel(this.refuelableComp.Props.fuelConsumptionRate / 100f); if (this.Spawned) { } } }
public static void Enter(LandedShip caravan, Map map) { List <ShipBase> ships = caravan.ships; IntVec3 randomEdgeCell = CellFinder.RandomEdgeCell(map); IntVec3 randomSpawnEdgeCell = new IntVec3(); DropShipUtility.TryFindShipDropLocationNear(randomEdgeCell, 100, map, out randomSpawnEdgeCell, new IntVec2(4, 4)); DropShipUtility.DropShipGroups(randomSpawnEdgeCell, map, ships, TravelingShipArrivalAction.EnterMapFriendly); if (caravan.Spawned) { Find.WorldObjects.Remove(caravan); } }
public static void MaxCountTransferablePostFix(TransferableOneWay __instance) { Map map = Find.VisibleMap; List <ShipBase> ships = DropShipUtility.ShipsOnMap(map); for (int i = 0; i < ships.Count; i++) { for (int j = 0; j < ships[i].GetDirectlyHeldThings().Count; j++) { __instance.things.RemoveAll(x => ships[i].GetDirectlyHeldThings().Contains(x)); } } }
public override void GenerateIntoMap(Map map) { if (Find.TickManager.TicksGame < 1000) { ShipBase newShip = (ShipBase)ThingMaker.MakeThing(this.ShipDef); newShip.SetFaction(Faction.OfPlayer); Thing initialFuel = ThingMaker.MakeThing(ShipNamespaceDefOfs.Chemfuel); newShip.refuelableComp.Refuel(500); this.StartingShips.Add(newShip); DropShipUtility.LoadNewCargoIntoRandomShips(this.PlayerStartingThings().ToList(), this.StartingShips); DropShipUtility.DropShipGroups(map.Center, map, this.StartingShips, ShipArrivalAction.EnterMapFriendly); } }
public static void Enter(List <ShipBase> ships, Map map, bool centerDrop = true) { IntVec3 loc; if (centerDrop) { loc = TravelingShipsUtility.CenterCell(map); } else { loc = DropCellFinder.FindRaidDropCenterDistant(map); } DropShipUtility.DropShipGroups(loc, map, ships, ShipArrivalAction.EnterMapFriendly); }
protected override Job TryGiveJob(Pawn pawn) { List <Thing> ships = DropShipUtility.CurrentFactionShips(pawn).FindAll(x => x.Map == pawn.Map); if (!ships.NullOrEmpty()) { Thing ship = ships.RandomElement(); if (ship != null && ship.Map.reservationManager.CanReserve(pawn, ship, ship.TryGetComp <CompShip>().sProps.maxPassengers)) { Job job = new Job(ShipNamespaceDefOfs.LeaveInShip, pawn, ship); return(job); } } return(null); }
public static Vector3 DrawPosAt(ShipBase ship, int ticks, ShipBase_Traveling travelingShip = null) { if (ticks < 0) { ticks = 0; } Vector3 result = Gen.TrueCenter(ship); if (travelingShip != null) { result = Gen.TrueCenter(travelingShip.Position, travelingShip.containingShip.Rotation, travelingShip.containingShip.def.size, Altitudes.AltitudeFor(AltitudeLayer.FlyingItem)); } result += DropShipUtility.drawOffsetFor(ship, ticks, false); return(result); }
public static bool CreateAndDropSingleShip(Map map, Faction faction, ThingDef shipDef, List <Pawn> pawns, bool dropPawns, out ShipBase newShip) { List <ShipBase> ships = CreateDropShips(pawns, faction, new List <ThingDef> { shipDef }); if (!ships.NullOrEmpty()) { ShipBase ship = ships[0]; List <Zone> runways = map.zoneManager.AllZones.FindAll(x => x is Zone_Runway); bool wipeBuildings; bool doesntFit; IntVec3 dropCell = IntVec3.Zero; Rot4? rot = ship.Rotation; foreach (var runway in runways) { List <IntVec3> cells = runway.Cells; int x = cells.Min(c => c.x); int z = cells.Min(c => c.z); int width = cells.Max(c => c.x) - x; int height = cells.Max(c => c.z) - z; CellRect rect = new CellRect(x, z, width, height); dropCell = (RunwayUtility.FindShipDropPoint(map, rect, ship.def, ref rot, out wipeBuildings, out doesntFit)); if (doesntFit == true) { newShip = null; return(false); } if (wipeBuildings == true) { Messages.Message("LandingZoneBlocked".Translate(), MessageTypeDefOf.RejectInput); newShip = null; return(false); } } newShip = ship; DropShipUtility.DropSingleShip(map, dropCell, ship, ShipArrivalAction.EnterMapFriendly, dropPawns); return(true); } newShip = null; return(false); }