1
0
Fork 0
This commit is contained in:
Michaël Lemaire 2018-07-09 15:33:37 +02:00
parent bb67458180
commit 7079001885
6 changed files with 49 additions and 17 deletions

View File

@ -56,6 +56,7 @@ Battle
* Display the grid in targetting mode, with colors (replaces range hint)
* Fix move-fire simulator's scanCircle
* Fix tactical AI scanArea
* Apply to action's default targets
* Add engine trail effect, and sound
* Find incentives to move from starting position (permanent drones or anomalies?)
* Mark targetting in error when target is refused by the action (there is already an arrow for this)

View File

@ -92,9 +92,11 @@ module TK.SpaceTac {
/**
* Returns true if the target is a ship
*
* If a ship or ship id is passed, also check that it is the targetted one
*/
isShip(): boolean {
return this.ship_id !== null;
isShip(ship?: Ship | RObject): boolean {
return this.ship_id !== null && (typeof ship == "undefined" || rid(ship) == this.ship_id);
}
/**

View File

@ -17,7 +17,6 @@ module TK.SpaceTac {
var battle = new Battle(fleet1, fleet2);
if (!hexgrid) {
battle.grid = new PixelGrid();
battle.placeShips();
}
battle.ships.list().forEach(ship => TestTools.setShipModel(ship, 1, 0));
battle.play_order = fleet1.ships.concat(fleet2.ships);

View File

@ -12,19 +12,37 @@ module TK.SpaceTac.Specs {
check.equals(action.getVerb(ship), "Recall");
});
test.case("provides a default target", check => {
let ship = new Ship();
let action = new DeployDroneAction("testdrone", undefined, { drone_radius: 50 });
ship.actions.addCustom(action);
check.equals(action.getDefaultTarget(ship), Target.newFromLocation(45, 0));
ship.actions.toggle(action, true);
check.equals(action.getDefaultTarget(ship), Target.newFromShip(ship));
});
test.case("allows to deploy in range", check => {
let ship = new Ship();
ship.setArenaPosition(0, 0);
let action = new DeployDroneAction("testdrone", { power: 0 }, { deploy_distance: 8 });
ship.actions.addCustom(action);
check.equals(action.checkTarget(ship, new Target(8, 0, null)), true);
check.equals(action.checkTarget(ship, new Target(12, 0, null)), false);
check.equals(action.checkTarget(ship, Target.newFromShip(ship)), false);
check.equals(action.checkTarget(ship, new Target(8, 0, null)), true, "deploy");
check.equals(action.checkTarget(ship, new Target(12, 0, null)), false, "too far");
check.equals(action.checkTarget(ship, Target.newFromShip(ship)), false, "activate on self");
let other = new Ship();
other.setArenaPosition(8, 0);
check.equals(action.checkTarget(ship, new Target(8, 0, other)), false);
check.equals(action.checkTarget(ship, Target.newFromShip(other)), false, "activate on other");
ship.actions.toggle(action, true);
check.equals(action.checkTarget(ship, new Target(8, 0, null)), false, "already activated");
check.equals(action.checkTarget(ship, Target.newFromShip(ship)), true, "recall");
check.equals(action.checkTarget(ship, Target.newFromShip(other)), false, "recall other");
});
test.case("deploys a new drone", check => {

View File

@ -49,12 +49,16 @@ module TK.SpaceTac {
}
getDefaultTarget(ship: Ship): Target {
let harmful = any(this.effects, effect => !effect.isBeneficial());
let distance = this.drone_radius * (harmful ? 1.1 : 0.9);
return Target.newFromLocation(
ship.arena_x + Math.cos(ship.arena_angle) * distance,
ship.arena_y + Math.sin(ship.arena_angle) * distance
);
if (ship.actions.isToggled(this)) {
return Target.newFromShip(ship);
} else {
let harmful = any(this.effects, effect => !effect.isBeneficial());
let distance = this.drone_radius * (harmful ? 1.1 : 0.9);
return Target.newFromLocation(
ship.arena_x + Math.cos(ship.arena_angle) * distance,
ship.arena_y + Math.sin(ship.arena_angle) * distance
);
}
}
getRangeRadius(ship: Ship): number {
@ -68,11 +72,19 @@ module TK.SpaceTac {
}
checkShipTarget(ship: Ship, target: Target): boolean {
return false;
if (ship.actions.isToggled(this)) {
return target.isShip(ship);
} else {
return false;
}
}
checkLocationTarget(ship: Ship, target: Target): boolean {
return arenaInRange(ship.location, target, this.deploy_distance);
if (ship.actions.isToggled(this)) {
return false;
} else {
return arenaInRange(ship.location, target, this.deploy_distance);
}
}
getSpecificDiffs(ship: Ship, battle: Battle, target: Target): BaseBattleDiff[] {

View File

@ -28,10 +28,10 @@ module TK.SpaceTac.Specs {
ship1.actions.addCustom(action);
var result = action.checkTarget(ship1, Target.newFromShip(ship1));
check.equals(result, null);
check.equals(result, false);
result = action.checkTarget(ship1, Target.newFromShip(ship2));
check.equals(result, null);
check.equals(result, false);
});
test.case("applies and reverts", check => {