Fixed Xander's "Disengage" being used instead of main engine
This commit is contained in:
parent
8d983258f8
commit
ea8771fc75
|
@ -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());
|
||||
(<any>moveaction).safety_distance = 30;
|
||||
battle.ship_separation = 30;
|
||||
|
||||
|
|
|
@ -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 = <MoveAction[]>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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -257,7 +257,7 @@ module TK.SpaceTac.UI {
|
|||
move_action = <MoveAction>last_move.action;
|
||||
}
|
||||
} else {
|
||||
let engine = new MoveFireSimulator(this.ship).findBestEngine();
|
||||
let engine = new MoveFireSimulator(this.ship).findEngine();
|
||||
if (engine) {
|
||||
move_action = engine;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue