diff --git a/src/core/MoveFireSimulator.spec.ts b/src/core/MoveFireSimulator.spec.ts index 1964b27..0856110 100644 --- a/src/core/MoveFireSimulator.spec.ts +++ b/src/core/MoveFireSimulator.spec.ts @@ -10,17 +10,20 @@ module TK.SpaceTac.Specs { return [ship, simulator, action]; } - test.case("finds the best engine to make a move", check => { + test.case("finds a suitable engine to make an approach", check => { let ship = new Ship(); let simulator = new MoveFireSimulator(ship); - check.equals(simulator.findBestEngine(), null); + check.equals(simulator.findEngine(), null); let engine1 = TestTools.addEngine(ship, 100); - check.same(simulator.findBestEngine(), engine1); + check.same(simulator.findEngine(), engine1); let engine2 = TestTools.addEngine(ship, 120); - let engine3 = TestTools.addEngine(ship, 150); - let engine4 = TestTools.addEngine(ship, 70); - let best = simulator.findBestEngine(); - check.same(best, engine3); + check.same(simulator.findEngine(), engine1); + engine1.configureCooldown(1, 1); + engine1.getCooldown().use(); + check.same(simulator.findEngine(), engine2); + engine2.configureCooldown(1, 1); + engine2.getCooldown().use(); + check.equals(simulator.findEngine(), null); }); test.case("fires directly when in range", check => { @@ -110,7 +113,7 @@ module TK.SpaceTac.Specs { let battle = new Battle(); battle.fleets[0].addShip(ship); let ship1 = battle.fleets[0].addShip(); - let moveaction = nn(simulator.findBestEngine()); + let moveaction = nn(simulator.findEngine()); (moveaction).safety_distance = 30; battle.ship_separation = 30; diff --git a/src/core/MoveFireSimulator.ts b/src/core/MoveFireSimulator.ts index 6d1d6c2..41339b2 100644 --- a/src/core/MoveFireSimulator.ts +++ b/src/core/MoveFireSimulator.ts @@ -53,15 +53,12 @@ module TK.SpaceTac { } /** - * Find the best available move action + * Find an engine action, to make an approach + * + * This will return the first available engine, in the definition order */ - findBestEngine(): MoveAction | null { - let actions = this.ship.actions.listAll().filter(action => action instanceof MoveAction); - if (actions.length == 0) { - return null; - } else { - return maxBy(actions, action => action.getDistanceByActionPoint(this.ship)); - } + findEngine(): MoveAction | null { + return first(cfilter(this.ship.actions.listAll(), MoveAction), action => action.getCooldown().canUse()); } /** @@ -140,7 +137,7 @@ module TK.SpaceTac { move_target = corrected_target; } } else { - let engine = this.findBestEngine(); + let engine = this.findEngine(); if (engine) { let approach_radius = action.getRangeRadius(this.ship); let approach = this.getApproach(engine, target, approach_radius, move_margin); @@ -161,7 +158,7 @@ module TK.SpaceTac { // Check move AP if (result.need_move && move_target) { - let engine = this.findBestEngine(); + let engine = this.findEngine(); if (engine) { result.total_move_ap = engine.getActionPointsUsage(this.ship, move_target); result.can_move = ap > 0; diff --git a/src/core/models/ModelXander.ts b/src/core/models/ModelXander.ts index 8a69e26..d1846a0 100644 --- a/src/core/models/ModelXander.ts +++ b/src/core/models/ModelXander.ts @@ -29,7 +29,6 @@ module TK.SpaceTac { }, "fractalhull"); hull.configureCooldown(1, 4); - // TODO Is currently always used by move-fire simulator let disengage = new MoveAction("Disengage", { distance_per_power: 1000, safety_distance: 200, diff --git a/src/ui/battle/Targetting.ts b/src/ui/battle/Targetting.ts index 124a267..d487021 100644 --- a/src/ui/battle/Targetting.ts +++ b/src/ui/battle/Targetting.ts @@ -257,7 +257,7 @@ module TK.SpaceTac.UI { move_action = last_move.action; } } else { - let engine = new MoveFireSimulator(this.ship).findBestEngine(); + let engine = new MoveFireSimulator(this.ship).findEngine(); if (engine) { move_action = engine; }