public ShipTask Join(ShipTask args) { Tail.NextTask = args; args.index = Tail.index + 1; return this; }
private void GetNextTask() { if (this.task == null || this.task.NextTask == null) { this.task = null; this.target = null; this.targetAction = null; } else { this.task = this.task.NextTask; this.target = this.task.Target; this.targetAction = this.task.Action; } }
public void ClearCurrentTask() { this.task = null; this.target = null; this.targetAction = null; }
public void SetTask(ShipTask args) { if (Pilot == null) throw new InvalidOperationException("Unable to set ship task without a pilot"); this.task = args; this.target = this.task.Target; this.targetAction = this.task.Action; }
public void RefineOre() { Rand.Initialise(0); var universe = new Universe(); var sol = new SolarSystem { Location = universe }; var corporation = new Corporation() { Location = universe }; var mPilot = corporation.Recruit(); var tPilot = corporation.Recruit(); var asteroidBelt = new AsteroidBelt(sol) {Richness = 100}; sol.OrbitSun(asteroidBelt, 100d); var refinery = new Refinery(sol, corporation) {OreProcessedPerTick = 5, Efficiency = 2.5d }; sol.OrbitSun(refinery, 200d); var manufactory = new Manufactory(sol, corporation); sol.OrbitSun(manufactory, 400d); var m1 = new Ship(mPilot) { Speed = 5d, CargoHoldSize = 100d, Name = "M1", UniversalCoordinates = refinery.UniversalCoordinates }; refinery.Dock(m1); var t1 = new Ship(tPilot) { Speed = 5d, CargoHoldSize = 10d, Name = "T1", UniversalCoordinates = refinery.UniversalCoordinates }; refinery.Dock(t1); var start = new ShipTask(asteroidBelt, (ship, target) => asteroidBelt.Mine(ship)); start = start.Join(refinery, (ship, target) => refinery.UnloadOre(ship)).Join(start); refinery.Undock(m1, mPilot); m1.SetTask(start); start = new ShipTask(refinery, (ship, target) => { refinery.LoadRefinedOre(ship); return ship.Cargo.Count > 0 && ship.Cargo[0].Quantity > 50; }); start = start.Join(manufactory, (ship, target) => manufactory.UnloadRefinedOre(ship)).Join(start); refinery.Undock(t1, tPilot); t1.SetTask(start); CollectionAssert.Contains(sol.Objects, m1); CollectionAssert.Contains(sol.Objects, t1); ulong tick = 0L; while ( manufactory.OreRemaining < 100 ) { Assert.Less(tick, 1000, "Ssytem took more than 1000 days to complete the task. {0:n0} products manufactured", manufactory.ProductCount); sol.Tick(tick); tick++; } Console.WriteLine("System took {0} days to manufacture {1:n0} items", tick, manufactory.ProductCount); Console.WriteLine("The refinery had {0:n0} unprocessed ore", refinery.UnrefinedOre); Console.WriteLine("The manufactory has {0:n0} unprocessed ore for building", manufactory.OreRemaining); }