WIP
This commit is contained in:
parent
17b8668e9a
commit
c9bc7f1984
1
TODO.md
1
TODO.md
|
@ -51,7 +51,6 @@ Battle
|
|||
* Toggle bar/text display in power section of action bar
|
||||
* Show a cooldown indicator on move action icon, if the simulation would cause the engine to overheat
|
||||
* [WIP] Add an hexagonal grid
|
||||
* Use the grid for "border" exclusion areas
|
||||
* Fix repel effect to snap to grid and use grid units (beware of two ships being moved to the same location!)
|
||||
* Apply to action's default targets
|
||||
* Add engine trail effect, and sound
|
||||
|
|
|
@ -8,7 +8,7 @@ module TK.SpaceTac {
|
|||
* It only applies optional boundaries (which does not impact *snap*, but *check* and *iterate*)
|
||||
*/
|
||||
export class ArenaGrid {
|
||||
constructor(private bounds?: ArenaBounds) {
|
||||
constructor(readonly bounds?: ArenaBounds) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -297,13 +297,14 @@ module TK.SpaceTac {
|
|||
* *facing_angle* is the forward angle in radians
|
||||
*/
|
||||
private placeFleetShips(fleet: Fleet, x: number, y: number, facing_angle: number): void {
|
||||
let spacing = Math.max(50, this.grid.getUnit() * 4);
|
||||
let spacing = Math.max(50, Math.round(this.grid.getUnit() * 4 * 0.866));
|
||||
let loc = this.grid.snap({ x: x, y: y - ((fleet.ships.length % 2 == 0) ? spacing * 0.5 : 0) });
|
||||
let offset = 0;
|
||||
let side = -1;
|
||||
|
||||
fleet.ships.forEach(ship => {
|
||||
ship.setArenaPosition(loc.x, loc.y + side * offset * spacing);
|
||||
let sloc = this.grid.snap({ x: loc.x, y: loc.y + side * offset * spacing });
|
||||
ship.setArenaPosition(sloc.x, sloc.y);
|
||||
ship.setArenaFacingAngle(facing_angle);
|
||||
|
||||
if (side == -1) {
|
||||
|
|
|
@ -84,6 +84,23 @@ module TK.SpaceTac.Specs {
|
|||
check.equals(result, true, "1200");
|
||||
});
|
||||
|
||||
test.case("can't move too much near arena borders", check => {
|
||||
let battle = new Battle();
|
||||
battle.grid = new ArenaGrid({ xmin: 0, ymin: 0, xmax: 1000, ymax: 1000 });
|
||||
let ship = battle.fleets[0].addShip();
|
||||
let action = ship.actions.addCustom(new MoveAction());
|
||||
|
||||
check.equals(action.checkTarget(ship, Target.newFromLocation(500, 500)), true, "500,500");
|
||||
|
||||
check.equals(action.checkTarget(ship, Target.newFromLocation(51, 500)), true, "51,500");
|
||||
check.equals(action.checkTarget(ship, Target.newFromLocation(49, 500)), false, "49,500");
|
||||
check.equals(action.checkTarget(ship, Target.newFromLocation(951, 500)), false, "951,500");
|
||||
|
||||
check.equals(action.checkTarget(ship, Target.newFromLocation(500, 61)), true, "500,61");
|
||||
check.equals(action.checkTarget(ship, Target.newFromLocation(500, 59)), false, "500,59");
|
||||
check.equals(action.checkTarget(ship, Target.newFromLocation(500, 941)), false, "500,941");
|
||||
});
|
||||
|
||||
test.case("builds a textual description", check => {
|
||||
let action = new MoveAction("Engine", { distance_per_power: 58 });
|
||||
check.equals(action.getEffectsDescription(), "Move: 58km per power point");
|
||||
|
|
|
@ -96,6 +96,14 @@ module TK.SpaceTac {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Do not move near the grid bounds
|
||||
if (ship.grid.bounds) {
|
||||
let rbounds = { xmin: ship.grid.bounds.xmin + 50, xmax: ship.grid.bounds.xmax - 50, ymin: ship.grid.bounds.ymin + 60, ymax: ship.grid.bounds.ymax - 60 };
|
||||
if (!ship.grid.check(target, rbounds)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check the space is not occupied
|
||||
let battle = ship.getBattle();
|
||||
if (battle && battle.isOccupied(target, [ship])) {
|
||||
|
|
Loading…
Reference in New Issue