public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (forced == false)
            {
                return(false);
            }
            Pawn otherPawn = t as Pawn;

            if ((otherPawn == null) ||
                (pawn.Faction != otherPawn.Faction) ||
                otherPawn.def.race.Animal)
            {
                return(false);
            }
            if (Util_Misc.OrbitalHealing.HasAnyTreatableHediff(otherPawn) == false)
            {
                return(false);
            }
            foreach (Thing spaceship in pawn.Map.listerThings.ThingsOfDef(Util_Spaceship.SpaceshipMedical))
            {
                Building_SpaceshipMedical medicalSpaceship = spaceship as Building_SpaceshipMedical;
                if ((medicalSpaceship != null) &&
                    otherPawn.Downed &&
                    pawn.CanReserveAndReach(otherPawn, this.PathEndMode, Danger.Deadly, ignoreOtherReservations: true) &&
                    pawn.CanReach(spaceship, this.PathEndMode, Danger.Deadly) &&
                    (medicalSpaceship.orbitalHealingPawnsAboardCount < Building_SpaceshipMedical.orbitalHealingPawnsAboardMaxCount) &&
                    TradeUtility.ColonyHasEnoughSilver(pawn.Map, Util_Spaceship.orbitalHealingCost))
                {
                    return(true);
                }
            }
            return(false);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Pawn downedPawn = this.TargetThingA as Pawn;

            Toil gotoDownedPawnToil = Toils_Goto.GotoCell(downedPawnIndex, PathEndMode.OnCell).FailOn(delegate()
            {
                return(downedPawn.DestroyedOrNull() ||
                       (downedPawn.Downed == false));
            });

            yield return(gotoDownedPawnToil);

            yield return(Toils_Haul.StartCarryThing(downedPawnIndex));

            Toil gotoTravelDestToil = Toils_Haul.CarryHauledThingToCell(medicalSPaceshipCellIndex).FailOn(delegate()
            {
                return(this.pawn.carryTracker.CarriedThing.DestroyedOrNull() ||
                       (this.pawn.CanReach(this.pawn.jobs.curJob.targetB.Cell, PathEndMode.OnCell, Danger.Some) == false));
            });

            yield return(gotoTravelDestToil);

            Toil arrivedToil = new Toil()
            {
                initAction = () =>
                {
                    Thing carriedPawn = null;
                    this.pawn.carryTracker.TryDropCarriedThing(this.pawn.Position, ThingPlaceMode.Near, out carriedPawn);
                    Building_SpaceshipMedical medicalSpaceship = this.pawn.Position.GetFirstThing(this.pawn.Map, Util_Spaceship.SpaceshipMedical) as Building_SpaceshipMedical;
                    if (medicalSpaceship != null)
                    {
                        if (medicalSpaceship.orbitalHealingPawnsAboardCount >= Building_SpaceshipMedical.orbitalHealingPawnsAboardMaxCount)
                        {
                            Messages.Message((carriedPawn as Pawn).Name.ToStringShort + " cannot board MiningCo. medical spaceship.. There is no more any free slot.", carriedPawn, MessageTypeDefOf.RejectInput);
                        }
                        else if (TradeUtility.ColonyHasEnoughSilver(this.pawn.Map, Util_Spaceship.orbitalHealingCost))
                        {
                            TradeUtility.LaunchSilver(this.pawn.Map, Util_Spaceship.orbitalHealingCost);
                            medicalSpaceship.Notify_PawnBoarding(carriedPawn as Pawn, false);
                        }
                        else
                        {
                            Messages.Message((carriedPawn as Pawn).Name.ToStringShort + " cannot board MiningCo. medical spaceship.. You have not enough silver to pay for " + this.pawn.gender.GetPossessive() + " orbital healing.", carriedPawn, MessageTypeDefOf.RejectInput);
                        }
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            };

            yield return(arrivedToil);
        }
 public override bool ActivateOn(Lord lord, TriggerSignal signal)
 {
     if (signal.type == TriggerSignalType.Tick && Find.TickManager.TicksGame % checkInterval == 0)
     {
         foreach (Building spaceship in lord.Map.listerBuildings.AllBuildingsColonistOfDef(Util_Spaceship.SpaceshipMedical))
         {
             Building_SpaceshipMedical medicalSpaceship = spaceship as Building_SpaceshipMedical;
             if ((medicalSpaceship != null) &&
                 medicalSpaceship.IsTakeOffImminent(Util_Spaceship.medicsRecallBeforeTakeOffMarginInTicks))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            // Get nearest reachable medical spaceship.
            float minDistance = 99999f;
            Building_SpaceshipMedical nearestMedicalSpaceship = null;

            foreach (Thing spaceship in pawn.Map.listerThings.ThingsOfDef(Util_Spaceship.SpaceshipMedical))
            {
                float distance = IntVec3Utility.DistanceTo(t.Position, spaceship.Position);
                if ((distance < minDistance) &&
                    pawn.CanReach(spaceship, this.PathEndMode, Danger.Deadly))
                {
                    minDistance             = distance;
                    nearestMedicalSpaceship = spaceship as Building_SpaceshipMedical;
                }
            }
            return(new Job(Util_JobDefOf.TransferToMedibay, t, nearestMedicalSpaceship)
            {
                count = 1
            });
        }
Esempio n. 5
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Building_SpaceshipMedical medicalSpaceship = this.TargetThingA as Building_SpaceshipMedical;

            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(delegate()
            {
                return medicalSpaceship.DestroyedOrNull();
            }));

            yield return(Toils_General.Wait(5 * GenTicks.TicksPerRealSecond).WithProgressBarToilDelay(medicalSpaceshipIndex).FailOn(delegate()
            {
                return medicalSpaceship.DestroyedOrNull();
            }));

            Toil boardToil = new Toil()
            {
                initAction = () =>
                {
                    if (medicalSpaceship.orbitalHealingPawnsAboardCount >= Building_SpaceshipMedical.orbitalHealingPawnsAboardMaxCount)
                    {
                        Messages.Message(this.pawn.Name.ToStringShort + " cannot board MiningCo. medical spaceship.. There is no more any free slot.", this.pawn, MessageTypeDefOf.RejectInput);
                    }
                    else if (TradeUtility.ColonyHasEnoughSilver(this.pawn.Map, Util_Spaceship.orbitalHealingCost))
                    {
                        TradeUtility.LaunchSilver(this.Map, Util_Spaceship.orbitalHealingCost);
                        medicalSpaceship.Notify_PawnBoarding(pawn, false);
                    }
                    else
                    {
                        Messages.Message(this.pawn.Name.ToStringShort + " cannot board MiningCo. medical spaceship.. You have not enough silver to pay for " + this.pawn.gender.GetPossessive() + " orbital healing.", this.pawn, MessageTypeDefOf.RejectInput);
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            };

            yield return(boardToil);
        }
        // ===================== Main function =====================
        public override void Tick()
        {
            base.Tick();

            if (this.ticksToLanding == horizontalTrajectoryDurationInTicks + verticalTrajectoryDurationInTicks)
            {
                // Atmosphere entry sound.
                FlyingSpaceshipLanding.preLandingSound.PlayOneShot(new TargetInfo(this.Position, this.Map));
            }
            this.ticksToLanding--;
            if (this.ticksToLanding == verticalTrajectoryDurationInTicks)
            {
                // Landing on sound.
                FlyingSpaceshipLanding.landingSound.PlayOneShot(new TargetInfo(this.Position, this.Map));
            }
            if (this.ticksToLanding <= verticalTrajectoryDurationInTicks)
            {
                // Throw dust during descent.
                MoteMaker.ThrowDustPuff(GenAdj.CellsAdjacentCardinal(this.landingPadPosition, this.landingPadRotation, Util_ThingDefOf.LandingPad.Size).RandomElement(), this.Map, 3f * (1f - (float)this.ticksToLanding / (float)verticalTrajectoryDurationInTicks));
            }
            if (this.ticksToLanding == 0)
            {
                Building_Spaceship spaceship = null;
                switch (this.spaceshipKind)
                {
                case SpaceshipKind.CargoPeriodic:
                case SpaceshipKind.CargoRequested:
                    // Spawn cargo spaceship.
                    Building_SpaceshipCargo cargoSpaceship = ThingMaker.MakeThing(Util_Spaceship.SpaceshipCargo) as Building_SpaceshipCargo;
                    cargoSpaceship.InitializeData_Cargo(Util_Faction.MiningCoFaction, this.HitPoints, this.landingDuration, this.spaceshipKind);
                    spaceship = GenSpawn.Spawn(cargoSpaceship, this.landingPadPosition, this.Map, this.landingPadRotation) as Building_Spaceship;
                    break;

                case SpaceshipKind.Damaged:
                    // Spawn damaged spaceship.
                    Building_SpaceshipDamaged damagedSpaceship = ThingMaker.MakeThing(Util_Spaceship.SpaceshipDamaged) as Building_SpaceshipDamaged;
                    damagedSpaceship.InitializeData_Damaged(Util_Faction.MiningCoFaction, this.HitPoints, this.landingDuration, this.spaceshipKind, this.HitPoints);
                    // Faction will be set to player when repair materials are delivered.
                    spaceship = GenSpawn.Spawn(damagedSpaceship, this.landingPadPosition, this.Map, this.landingPadRotation) as Building_Spaceship;
                    break;

                case SpaceshipKind.DispatcherDrop:
                    // Spawn dispatcher spaceship.
                    Building_SpaceshipDispatcherDrop dispatcherSpaceshipDrop = ThingMaker.MakeThing(Util_Spaceship.SpaceshipDispatcherDrop) as Building_SpaceshipDispatcherDrop;
                    dispatcherSpaceshipDrop.InitializeData_DispatcherDrop(Util_Faction.MiningCoFaction, this.HitPoints, this.landingDuration, this.spaceshipKind);
                    spaceship = GenSpawn.Spawn(dispatcherSpaceshipDrop, this.landingPadPosition, this.Map, this.landingPadRotation) as Building_Spaceship;
                    break;

                case SpaceshipKind.DispatcherPick:
                    // Spawn dispatcher spaceship.
                    Building_SpaceshipDispatcherPick dispatcherSpaceshipPick = ThingMaker.MakeThing(Util_Spaceship.SpaceshipDispatcherPick) as Building_SpaceshipDispatcherPick;
                    dispatcherSpaceshipPick.InitializeData_DispatcherPick(Util_Faction.MiningCoFaction, this.HitPoints, this.landingDuration, this.spaceshipKind);
                    spaceship = GenSpawn.Spawn(dispatcherSpaceshipPick, this.landingPadPosition, this.Map, this.landingPadRotation) as Building_Spaceship;
                    break;

                case SpaceshipKind.Medical:
                    // Spawn medical spaceship.
                    Building_SpaceshipMedical medicalSpaceship = ThingMaker.MakeThing(Util_Spaceship.SpaceshipMedical) as Building_SpaceshipMedical;
                    medicalSpaceship.InitializeData_Medical(Util_Faction.MiningCoFaction, this.HitPoints, this.landingDuration, this.spaceshipKind);
                    spaceship = GenSpawn.Spawn(medicalSpaceship, this.landingPadPosition, this.Map, this.landingPadRotation) as Building_Spaceship;
                    break;

                default:
                    Log.ErrorOnce("MiningCo. Spaceship: unhandled SpaceshipKind (" + this.spaceshipKind.ToString() + ").", 123456783);
                    break;
                }
                this.Destroy();
            }
        }