public DiaOption GetMedicalSupplyDiaOption(Building_OrbitalRelay orbitalRelay) { DiaOption medicalSupplyDiaOption = new DiaOption("Request medical supply (" + Util_Spaceship.medicalSupplyCostInSilver + " silver)"); Building_LandingPad landingPad = Util_LandingPad.GetBestAvailableLandingPad(this.Map); if (Find.TickManager.TicksGame <= Util_Misc.Partnership.nextMedicalSupplyMinTick[this.Map]) { medicalSupplyDiaOption.Disable("no available ship for now"); } else if (TradeUtility.ColonyHasEnoughSilver(this.Map, Util_Spaceship.medicalSupplyCostInSilver) == false) { medicalSupplyDiaOption.Disable("not enough silver"); } else if (landingPad == null) { medicalSupplyDiaOption.Disable("no available landing pad"); } medicalSupplyDiaOption.action = delegate { TradeUtility.LaunchSilver(this.Map, Util_Spaceship.medicalSupplyCostInSilver); Util_Spaceship.SpawnSpaceship(landingPad, SpaceshipKind.Medical); }; DiaNode supplyShipAcceptedDiaNode = new DiaNode("\"We are sending you a medical ship immediately.\n\n" + "Hold on down there, we're coming!\n\n" + "-- End of transmission --"); DiaOption supplyShipAcceptedDiaOption = new DiaOption("OK"); supplyShipAcceptedDiaOption.resolveTree = true; supplyShipAcceptedDiaNode.options.Add(supplyShipAcceptedDiaOption); medicalSupplyDiaOption.link = supplyShipAcceptedDiaNode; return(medicalSupplyDiaOption); }
public DiaOption GetCargoSupplyDiaOption(Building_OrbitalRelay orbitalRelay) { DiaOption cargoSupplyDiaOption = new DiaOption("Request cargo supply (" + Util_Spaceship.cargoSupplyCostInSilver + " silver)"); Building_LandingPad landingPad = Util_LandingPad.GetBestAvailableLandingPad(this.Map); if (Find.TickManager.TicksGame <= Util_Misc.Partnership.nextRequestedSupplyMinTick[this.Map]) { cargoSupplyDiaOption.Disable("no available ship for now"); } else if (TradeUtility.ColonyHasEnoughSilver(this.Map, Util_Spaceship.cargoSupplyCostInSilver) == false) { cargoSupplyDiaOption.Disable("not enough silver"); } else if (landingPad == null) { cargoSupplyDiaOption.Disable("no available landing pad"); } cargoSupplyDiaOption.action = delegate { TradeUtility.LaunchSilver(this.Map, Util_Spaceship.cargoSupplyCostInSilver); Util_Spaceship.SpawnSpaceship(landingPad, SpaceshipKind.CargoRequested); }; DiaNode supplyShipAcceptedDiaNode = new DiaNode("\"Alright, a supply ship should arrive soon with our best stuff.\n" + "Greetings partner!\"\n\n" + "-- End of transmission --"); DiaOption supplyShipAcceptedDiaOption = new DiaOption("OK"); supplyShipAcceptedDiaOption.resolveTree = true; supplyShipAcceptedDiaNode.options.Add(supplyShipAcceptedDiaOption); cargoSupplyDiaOption.link = supplyShipAcceptedDiaNode; return(cargoSupplyDiaOption); }
protected override bool CanFireNowSub(IIncidentTarget target) { if (base.CanFireNowSub(target) == false) { return(false); } if (Util_Faction.MiningCoFaction.HostileTo(Faction.OfPlayer)) { return(false); } Map map = (Map)target; if (Expedition.IsTemperatureValidForExpedition(map)) { Building_OrbitalRelay orbitalRelay = Util_OrbitalRelay.GetOrbitalRelay(map); if ((orbitalRelay != null) && (orbitalRelay.powerComp.PowerOn)) { Building_LandingPad landingPad = Util_LandingPad.GetBestAvailableLandingPadReachingMapEdge(map); if (landingPad != null) { return(true); } } } return(false); }
// Return the primary landing pad if available and reaching map edge // else a random one // else null. public static Building_LandingPad GetBestAvailableLandingPadReachingMapEdge(Map map) { IntVec3 exitSpot = IntVec3.Invalid; // Check pawns can reach map edge from best landing pad. Building_LandingPad bestLandingPad = GetBestAvailableLandingPad(map); if (bestLandingPad != null) { if (Expedition.TryFindRandomExitSpot(map, bestLandingPad.Position, out exitSpot)) { return(bestLandingPad); } } // Check pawns can exit map from any landing pad. List <Building_LandingPad> allAvailableLandingPads = Util_LandingPad.GetAllFreeAndPoweredLandingPads(map); if (allAvailableLandingPads != null) { foreach (Building_LandingPad landingPad in allAvailableLandingPads.InRandomOrder()) { if (Expedition.TryFindRandomExitSpot(map, landingPad.Position, out exitSpot)) { return(landingPad); } } } return(null); }
// ===================== Main function ===================== public override void Tick() { base.Tick(); if (powerComp.PowerOn == false) { StopRotationSound(); } else { if (Find.TickManager.TicksGame >= this.nextSpaceshipLandingCheckTick) { // Update landing pads availability. this.nextSpaceshipLandingCheckTick = Find.TickManager.TicksGame + spaceshipLandingCheckPeriodInTick; UpdateLandingPadAvailability(); // Try spawn periodic supply spaceship. if ((Util_Faction.MiningCoFaction.HostileTo(Faction.OfPlayer) == false) && (Util_Misc.Partnership.feeInSilver[this.Map] == 0) && (Find.TickManager.TicksGame >= Util_Misc.Partnership.nextPeriodicSupplyTick[this.Map])) { Building_LandingPad landingPad = Util_LandingPad.GetBestAvailableLandingPad(this.Map); if (landingPad != null) { // Found an available landing pad. Spawn periodic supply spaceship. Util_Spaceship.SpawnSpaceship(landingPad, SpaceshipKind.CargoPeriodic); } } } // Satellite dish rotation. UpdateDishRotation(); } }
// ===================== Setup work ===================== public override void SpawnSetup(Map map, bool respawningAfterLoad) { base.SpawnSetup(map, respawningAfterLoad); this.powerComp = base.GetComp <CompPowerTrader>(); this.powerComp.powerStartedAction = Notify_PowerStarted; this.powerComp.powerStoppedAction = Notify_PowerStopped; // Check if there is already another primary landing pad. if (this.Map.listerBuildings.ColonistsHaveBuilding(Util_ThingDefOf.LandingPad)) { foreach (Building building in this.Map.listerBuildings.AllBuildingsColonistOfDef(Util_ThingDefOf.LandingPad)) { Building_LandingPad landingPad = building as Building_LandingPad; if ((landingPad != this) && landingPad.isPrimary) { this.isPrimary = false; break; } } } if (respawningAfterLoad == false) { // Only spawn beacons once. SpawnBeacons(); } }
protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; List <Building_LandingPad> freeLandingPads = Util_LandingPad.GetAllFreeLandingPads(map); if (freeLandingPads == null) { // Should not happen if CanFireNowSub returned true. return(false); } Building_LandingPad landingPad = freeLandingPads.RandomElement(); // Spawn landing damaged spaceship. FlyingSpaceshipLanding damagedSpaceship = Util_Spaceship.SpawnSpaceship(landingPad, SpaceshipKind.Damaged); damagedSpaceship.HitPoints = Mathf.RoundToInt(Rand.Range(0.15f, 0.45f) * damagedSpaceship.HitPoints); string letterText = "-- Comlink with MiningCo. --\n\n" + "MiningCo. pilot:\n\n" + "\"Hello partner!\n" + "Our ship is damaged and we need some repairs before going back to the orbital station.\n" + "Help us and we will reward you. Business as usual!\n\n" + "-- End of transmission --\n\n" + "WARNING! Not helping the ship will negatively impact your partnership with MiningCo.."; Find.LetterStack.ReceiveLetter("Repairs request", letterText, LetterDefOf.NeutralEvent, new TargetInfo(landingPad.Position, landingPad.Map)); return(true); }
// ===================== Setup work ===================== public override void SpawnSetup(Map map, bool respawningAfterLoad) { base.SpawnSetup(map, respawningAfterLoad); this.powerComp = base.GetComp <CompPowerTrader>(); // Check if there is already another primary landing pad. if (this.Map.listerBuildings.ColonistsHaveBuilding(Util_ThingDefOf.LandingPad)) { foreach (Building building in this.Map.listerBuildings.AllBuildingsColonistOfDef(Util_ThingDefOf.LandingPad)) { Building_LandingPad landingPad = building as Building_LandingPad; if ((landingPad != this) && landingPad.isPrimary) { this.isPrimary = false; break; } } } if (this.beaconsAreSpawned == false) { SpawnBeacons(); this.beaconsAreSpawned = true; } if (Scribe.mode == LoadSaveMode.PostLoadInit) { CheckForBlockingThing(); } Util_OrbitalRelay.TryUpdateLandingPadAvailability(this.Map); }
public static FlyingSpaceshipLanding SpawnSpaceship(Building_LandingPad landingPad, SpaceshipKind spaceshipKind) { Building_OrbitalRelay orbitalRelay = Util_OrbitalRelay.GetOrbitalRelay(landingPad.Map); int landingDuration = 0; switch (spaceshipKind) { case SpaceshipKind.CargoPeriodic: landingDuration = cargoPeriodicSupplyLandingDuration; if (orbitalRelay != null) { orbitalRelay.Notify_CargoSpaceshipPeriodicLanding(); } Util_Misc.Partnership.nextPeriodicSupplyTick[landingPad.Map] = Find.TickManager.TicksGame + WorldComponent_Partnership.cargoSpaceshipPeriodicSupplyPeriodInTicks; Messages.Message("A MiningCo. cargo spaceship is landing.", new TargetInfo(landingPad.Position, landingPad.Map), MessageTypeDefOf.NeutralEvent); break; case SpaceshipKind.CargoRequested: landingDuration = cargoRequestedSupplyLandingDuration; if (orbitalRelay != null) { orbitalRelay.Notify_CargoSpaceshipRequestedLanding(); } Util_Misc.Partnership.nextRequestedSupplyMinTick[landingPad.Map] = Find.TickManager.TicksGame + WorldComponent_Partnership.cargoSpaceshipRequestedSupplyPeriodInTicks; Messages.Message("A MiningCo. cargo spaceship is landing.", new TargetInfo(landingPad.Position, landingPad.Map), MessageTypeDefOf.NeutralEvent); break; case SpaceshipKind.Damaged: landingDuration = damagedSpaceshipLandingDuration.RandomInRange; // Letter is sent by incident worker. break; case SpaceshipKind.DispatcherDrop: landingDuration = dispatcherDropDurationInTicks; Messages.Message("A MiningCo. dispatcher is dropping an expedition team.", new TargetInfo(landingPad.Position, landingPad.Map), MessageTypeDefOf.NeutralEvent); break; case SpaceshipKind.DispatcherPick: landingDuration = dispatcherPickDurationInTicks; Messages.Message("A MiningCo. dispatcher is picking an expedition team.", new TargetInfo(landingPad.Position, landingPad.Map), MessageTypeDefOf.NeutralEvent); break; case SpaceshipKind.Medical: landingDuration = medicalSupplyLandingDuration; if (orbitalRelay != null) { orbitalRelay.Notify_MedicalSpaceshipLanding(); } Util_Misc.Partnership.nextMedicalSupplyMinTick[landingPad.Map] = Find.TickManager.TicksGame + WorldComponent_Partnership.medicalSpaceshipRequestedSupplyPeriodInTicks; Messages.Message("A MiningCo. medical spaceship is landing.", new TargetInfo(landingPad.Position, landingPad.Map), MessageTypeDefOf.NeutralEvent); break; } FlyingSpaceshipLanding flyingSpaceship = ThingMaker.MakeThing(Util_Spaceship.SpaceshipLanding) as FlyingSpaceshipLanding; GenSpawn.Spawn(flyingSpaceship, landingPad.Position, landingPad.Map, landingPad.Rotation); flyingSpaceship.InitializeLandingParameters(landingPad, landingDuration, spaceshipKind); return(flyingSpaceship); }
// ===================== Setup work ===================== public void InitializeParameters(Building_LandingPad landingPad, Color color, int periodInTicks, int durationInTicks, int initialOffsetInTicks) { this.landingPad = landingPad; this.color = color; this.lightPeriodInTicks = periodInTicks; this.lightDurationInTicks = durationInTicks; this.lightInitialOffsetInTicks = initialOffsetInTicks; }
// ===================== Setup work ===================== public void InitializeParameters(Building_LandingPad landingPad, Color color, int periodInTicks, int durationInTicks, int delayInTicks) { this.landingPad = landingPad; this.SetFaction(landingPad.Faction); this.color = color; this.lightPeriodInTicks = periodInTicks; this.lightDurationInTicks = durationInTicks; this.lightDelayInTicks = delayInTicks; }
// ===================== Setup work ===================== /// <summary> /// Must be called just after spawning the ship to set the correct texture. /// </summary> public void InitializeLandingParameters(Building_LandingPad landingPad, int landingDuration, SpaceshipKind spaceshipKind) { landingPad.Notify_ShipLanding(); this.landingPadPosition = landingPad.Position; this.landingPadRotation = landingPad.Rotation; this.spaceshipExactRotation = this.landingPadRotation.AsAngle; this.landingDuration = landingDuration; this.spaceshipKind = spaceshipKind; ConfigureShipTexture(this.spaceshipKind); this.Tick(); // To update exact position for drawing purpose. }
/// <summary> /// Set selected landing pad as primary. /// </summary> public void SetAsPrimary() { foreach (Building building in this.Map.listerBuildings.AllBuildingsColonistOfDef(Util_ThingDefOf.LandingPad)) { Building_LandingPad landingPad = building as Building_LandingPad; if (landingPad != this) { landingPad.isPrimary = false; } } this.isPrimary = true; }
protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; Building_LandingPad landingPad = Util_LandingPad.GetBestAvailableLandingPadReachingMapEdge(map); if (landingPad == null) { // Should not happen if CanFireNowSub returned true. return(false); } // Spawn landing dispatcher spaceship. FlyingSpaceshipLanding dispatcherSpaceship = Util_Spaceship.SpawnSpaceship(landingPad, SpaceshipKind.DispatcherDrop); return(true); }
// Return a list of all free and powered landing pads. public static List <Building_LandingPad> GetAllFreeAndPoweredLandingPads(Map map) { if (map.listerBuildings.ColonistsHaveBuilding(Util_ThingDefOf.LandingPad) == false) { // No landing pad on the map. return(null); } List <Building_LandingPad> allFreeAndPoweredLandingPads = new List <Building_LandingPad>(); foreach (Building building in map.listerBuildings.AllBuildingsColonistOfDef(Util_ThingDefOf.LandingPad)) { Building_LandingPad landingPad = building as Building_LandingPad; if (landingPad.isFreeAndPowered) { allFreeAndPoweredLandingPads.Add(landingPad); } } if (allFreeAndPoweredLandingPads.Count > 0) { return(allFreeAndPoweredLandingPads); } return(null); }
protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; Building_LandingPad landingPad = Util_LandingPad.GetBestAvailableLandingPadReachingMapEdge(map); if (landingPad == null) { // Should not happen if CanFireNowSub returned true. return(false); } // Spawn landing dispatcher spaceship. FlyingSpaceshipLanding dispatcherSpaceship = Util_Spaceship.SpawnLandingSpaceship(landingPad, SpaceshipKind.DispatcherPick); // Spawn expedition team. List <Pawn> teamPawns = Expedition.GenerateExpeditionPawns(map); if (Rand.Value < 0.2f) { ApplyInjuriesOrIllnessToTeam(map, teamPawns); } return(SpawnTeamOnMapEdge(landingPad.Position, map, teamPawns)); }
// ===================== Main function ===================== /// <summary> /// When powered on, periodically spawn a supply spaceship and update dish rotation. /// </summary> public override void Tick() { base.Tick(); if (powerComp.PowerOn == false) { StopRotationSound(); } else { if (Find.TickManager.TicksGame >= this.nextSpaceshipLandingCheckTick) { this.nextSpaceshipLandingCheckTick = Find.TickManager.TicksGame + spaceshipLandingCheckPeriodInTick; // Update landing pads availability: it can change due to blocking trees for example. UpdateLandingPadAvailability(); // Try spawn periodic supply spaceship. if ((Util_Faction.MiningCoFaction.HostileTo(Faction.OfPlayer) == false) && (Util_Misc.Partnership.feeInSilver[this.Map] == 0) && (Find.TickManager.TicksGame >= Util_Misc.Partnership.nextPeriodicSupplyTick[this.Map]) && this.landingPadIsAvailable && (this.Map.GameConditionManager.ConditionIsActive(GameConditionDefOf.SolarFlare) == false) && (this.Map.GameConditionManager.ConditionIsActive(GameConditionDefOf.ToxicFallout) == false)) { Building_LandingPad landingPad = Util_LandingPad.GetBestAvailableLandingPad(this.Map); if (landingPad != null) { // Found an available landing pad. Spawn periodic supply spaceship. Util_Spaceship.SpawnLandingSpaceship(landingPad, SpaceshipKind.CargoPeriodic); } } } // Satellite dish rotation. UpdateDishRotation(); } }
public bool SendPawnBackToMap(Pawn pawn, Map map) { IntVec3 dropSpot = IntVec3.Invalid; bool dropSpotIsValid = false; // Check orbital relay is powered on. Building_OrbitalRelay orbitalRelay = Util_OrbitalRelay.GetOrbitalRelay(map); if (orbitalRelay == null) { return(false); } if (orbitalRelay.powerComp.PowerOn == false) { return(false); } // Look for an available landing pad. Building_LandingPad landingPad = Util_LandingPad.GetBestAvailableLandingPad(map); if (landingPad == null) { return(false); } // Get a nearby drop spot. dropSpotIsValid = DropCellFinder.TryFindDropSpotNear(landingPad.Position, map, out dropSpot, false, false); if (dropSpot.IsValid) { string hisHerIts = GenderUtility.GetPossessive(pawn.gender); string heSheIt = GenderUtility.GetPronoun(pawn.gender); string himHerIt = GenderUtility.GetObjective(pawn.gender); // Restore needs level. pawn.needs.food.ForceSetLevel(Rand.Range(0.75f, 1f)); pawn.needs.rest.ForceSetLevel(Rand.Range(0.75f, 1f)); pawn.needs.joy.ForceSetLevel(Rand.Range(0.5f, 0.8f)); pawn.needs.comfort.ForceSetLevel(Rand.Range(0.6f, 0.9f)); pawn.needs.space.ForceSetLevel(Rand.Range(0.1f, 0.3f)); // Drop-pod is very small. ActiveDropPodInfo dropPodInfo = new ActiveDropPodInfo(); bool healingSuccessful = (Rand.Value < 0.98f); if (healingSuccessful) { string orbitalHealingFailedText = "-- Comlink with MiningCo. --\n\n" + "\"Healing of " + pawn.NameStringShort + " is now finished. Everything went fine during the treatment.\n" + "We just launched " + hisHerIts + " drop pod toward your colony.\n\n" + "I hope you are satisfied of our services.\n\n" + "MiningCo. medibay officer out.\"\n\n" + "-- End of transmission --"; Find.LetterStack.ReceiveLetter("Orbital healing finished", orbitalHealingFailedText, LetterDefOf.PositiveEvent, new TargetInfo(dropSpot, map)); } else { // Dying pawn with heart attack. string orbitalHealingSuccessfulText = "-- Comlink with MiningCo. --\n\n" + "\"Though we did our best to heal " + pawn.NameStringShort + ", it seems " + hisHerIts + " metabolism was disturbed by the last injection.\n\n" + "I am affraid that we need to immediately send " + himHerIt + " back to you as our rules strictly forbid civilian bodies storage.\n\n" + "Please accept those silvers as a compensation.\n\n" + "MiningCo. medibay officer out.\"\n\n" + "-- End of transmission --"; Find.LetterStack.ReceiveLetter("Orbital healing interrupted", orbitalHealingSuccessfulText, LetterDefOf.NegativeEvent, new TargetInfo(dropSpot, map)); pawn.health.AddHediff(HediffDef.Named("HeartAttack")); pawn.health.AddHediff(HediffDefOf.Anesthetic); Thing compensation = ThingMaker.MakeThing(ThingDefOf.Silver); compensation.stackCount = Mathf.RoundToInt(0.5f * Util_Spaceship.orbitalHealingCost); dropPodInfo.innerContainer.TryAdd(compensation); } dropPodInfo.innerContainer.TryAdd(pawn); dropPodInfo.leaveSlag = true; DropPodUtility.MakeDropPodAt(dropSpot, map, dropPodInfo); return(true); } return(false); }