diff --git a/TODO.md b/TODO.md index f8b9b81..186020b 100644 --- a/TODO.md +++ b/TODO.md @@ -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) diff --git a/src/core/Target.ts b/src/core/Target.ts index 971a5c7..20c5016 100644 --- a/src/core/Target.ts +++ b/src/core/Target.ts @@ -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); } /** diff --git a/src/core/TestTools.ts b/src/core/TestTools.ts index b4a2477..e26cb09 100644 --- a/src/core/TestTools.ts +++ b/src/core/TestTools.ts @@ -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); diff --git a/src/core/actions/DeployDroneAction.spec.ts b/src/core/actions/DeployDroneAction.spec.ts index 1347542..788b2ec 100644 --- a/src/core/actions/DeployDroneAction.spec.ts +++ b/src/core/actions/DeployDroneAction.spec.ts @@ -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 => { diff --git a/src/core/actions/DeployDroneAction.ts b/src/core/actions/DeployDroneAction.ts index d88adc7..fbaaa8e 100644 --- a/src/core/actions/DeployDroneAction.ts +++ b/src/core/actions/DeployDroneAction.ts @@ -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[] { diff --git a/src/core/actions/MoveAction.spec.ts b/src/core/actions/MoveAction.spec.ts index b386dae..7323de2 100644 --- a/src/core/actions/MoveAction.spec.ts +++ b/src/core/actions/MoveAction.spec.ts @@ -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 => {