protected override IEnumerable <Toil> MakeNewToils() { Building_SpaceshipCargo cargoSpaceship = this.TargetThingA as Building_SpaceshipCargo; yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(delegate() { return (cargoSpaceship.DestroyedOrNull() || (cargoSpaceship.CanTradeNow == false)); })); Toil faceSpaceshipToil = new Toil() { initAction = () => { this.GetActor().rotationTracker.FaceCell(cargoSpaceship.Position); } }; yield return(faceSpaceshipToil); Toil tradeWithSpacehipToil = new Toil() { initAction = () => { Find.WindowStack.Add(new Dialog_Trade(this.GetActor(), cargoSpaceship as ITrader)); }, defaultCompleteMode = ToilCompleteMode.Instant }; yield return(tradeWithSpacehipToil); yield return(Toils_Reserve.Release(cargoSpaceshipIndex)); }
// ===================== 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(); } }