1
0
Fork 0

Removed power value (will only use power_capacity)

This commit is contained in:
Michaël Lemaire 2019-05-21 23:29:47 +02:00
parent bac2c6fe0a
commit 542eda792b
42 changed files with 96 additions and 680 deletions

View File

@ -17,32 +17,26 @@ module TK.SpaceTac {
], [
check => {
check.equals(ship.active_effects.count(), 0, "active effects");
check.equals(ship.getValue("power"), 10, "power");
check.equals(battle.drones.count(), 0, "drone count");
},
check => {
check.equals(ship.active_effects.count(), 0, "active effects");
check.equals(ship.getValue("power"), 8, "power");
check.equals(battle.drones.count(), 1, "drone count");
},
check => {
check.equals(ship.active_effects.count(), 0, "active effects");
check.equals(ship.getValue("power"), 7, "power");
check.equals(battle.drones.count(), 1, "drone count");
},
check => {
check.equals(ship.active_effects.count(), 1, "active effects");
check.equals(ship.getValue("power"), 6, "power");
check.equals(battle.drones.count(), 1, "drone count");
},
check => {
check.equals(ship.active_effects.count(), 0, "active effects");
check.equals(ship.getValue("power"), 8, "power");
check.equals(battle.drones.count(), 0, "drone count");
},
check => {
check.equals(ship.active_effects.count(), 1, "active effects");
check.equals(ship.getValue("power"), 6, "power");
check.equals(battle.drones.count(), 1, "drone count");
},
]);

View File

@ -1,181 +0,0 @@
module TK.SpaceTac.Specs {
testing("MoveFireSimulator", test => {
function simpleWeaponCase(distance = 10, ship_ap = 5, weapon_ap = 3, engine_distance = 5): [Ship, MoveFireSimulator, BaseAction] {
let ship = new Ship();
TestTools.setShipModel(ship, 100, 0, ship_ap);
TestTools.addEngine(ship, engine_distance);
let action = new TriggerAction("weapon", { power: weapon_ap, range: distance });
let simulator = new MoveFireSimulator(ship);
return [ship, simulator, action];
}
test.case("finds a suitable engine to make an approach", check => {
let ship = new Ship();
let simulator = new MoveFireSimulator(ship);
check.equals(simulator.findEngine(), null, "no engine");
let engine1 = TestTools.addEngine(ship, 100);
engine1.configureCooldown(1, 1);
check.same(simulator.findEngine(), engine1, "one engine");
let engine2 = TestTools.addEngine(ship, 120);
engine2.configureCooldown(1, 1);
check.same(simulator.findEngine(), engine1, "two engines, choose first one");
ship.actions.storeUsage(engine1);
check.same(simulator.findEngine(), engine2, "first engine overheated, choose second one");
ship.actions.storeUsage(engine2);
check.equals(simulator.findEngine(), null, "both engines overheated");
});
test.case("fires directly when in range", check => {
let [ship, simulator, action] = simpleWeaponCase();
let result = simulator.simulateAction(action, new Target(ship.arena_x + 5, ship.arena_y, null));
check.same(result.success, true, 'success');
check.same(result.need_move, false, 'need_move');
check.same(result.need_fire, true, 'need_fire');
check.same(result.can_fire, true, 'can_fire');
check.same(result.total_fire_ap, 3, 'total_fire_ap');
check.equals(result.parts, [
{ action: action, target: new Target(ship.arena_x + 5, ship.arena_y, null), ap: 3, possible: true }
]);
});
test.case("can't fire when in range, but not enough AP", check => {
let [ship, simulator, action] = simpleWeaponCase(10, 2, 3);
let result = simulator.simulateAction(action, new Target(ship.arena_x + 5, ship.arena_y, null));
check.same(result.success, true, 'success');
check.same(result.need_move, false, 'need_move');
check.same(result.need_fire, true, 'need_fire');
check.same(result.can_fire, false, 'can_fire');
check.same(result.total_fire_ap, 3, 'total_fire_ap');
check.equals(result.parts, [
{ action: action, target: new Target(ship.arena_x + 5, ship.arena_y, null), ap: 3, possible: false }
]);
});
test.case("moves straight to get within range", check => {
let [ship, simulator, action] = simpleWeaponCase();
let result = simulator.simulateAction(action, new Target(ship.arena_x + 15, ship.arena_y, null));
check.same(result.success, true, 'success');
check.same(result.need_move, true, 'need_move');
check.same(result.can_end_move, true, 'can_end_move');
check.equals(result.move_location, new Target(ship.arena_x + 5, ship.arena_y, null));
check.equals(result.total_move_ap, 1);
check.same(result.need_fire, true, 'need_fire');
check.same(result.can_fire, true, 'can_fire');
check.same(result.total_fire_ap, 3, 'total_fire_ap');
let move_action = ship.actions.listAll().filter(action => action instanceof MoveAction)[0];
check.equals(result.parts, [
{ action: move_action, target: new Target(ship.arena_x + 5, ship.arena_y, null), ap: 1, possible: true },
{ action: action, target: new Target(ship.arena_x + 15, ship.arena_y, null), ap: 3, possible: true }
]);
});
test.case("scans a circle for move targets", check => {
let simulator = new MoveFireSimulator(new Ship());
let result = simulator.scanCircle(50, 30, 10, 1, 1);
check.equals(imaterialize(result), [
new Target(50, 30)
]);
result = simulator.scanCircle(50, 30, 10, 2, 1);
check.equals(imaterialize(result), [
new Target(50, 30),
new Target(60, 30)
]);
result = simulator.scanCircle(50, 30, 10, 2, 2);
check.equals(imaterialize(result), [
new Target(50, 30),
new Target(60, 30),
new Target(40, 30)
]);
result = simulator.scanCircle(50, 30, 10, 3, 4);
check.equals(imaterialize(result), [
new Target(50, 30),
new Target(55, 30),
new Target(45, 30),
new Target(60, 30),
new Target(50, 40),
new Target(40, 30),
new Target(50, 20)
]);
});
test.case("moves to get in range, even if not enough AP to fire", check => {
let [ship, simulator, action] = simpleWeaponCase(8, 3, 2, 5);
let result = simulator.simulateAction(action, new Target(ship.arena_x + 18, ship.arena_y, null));
check.same(result.success, true, 'success');
check.same(result.need_move, true, 'need_move');
check.same(result.can_end_move, true, 'can_end_move');
check.equals(result.move_location, new Target(ship.arena_x + 10, ship.arena_y, null));
check.equals(result.total_move_ap, 2);
check.same(result.need_fire, true, 'need_fire');
check.same(result.can_fire, false, 'can_fire');
check.same(result.total_fire_ap, 2, 'total_fire_ap');
let move_action = ship.actions.listAll().filter(action => action instanceof MoveAction)[0];
check.equals(result.parts, [
{ action: move_action, target: new Target(ship.arena_x + 10, ship.arena_y, null), ap: 2, possible: true },
{ action: action, target: new Target(ship.arena_x + 18, ship.arena_y, null), ap: 2, possible: false }
]);
});
test.case("does nothing if trying to move in the same spot", check => {
let [ship, simulator, action] = simpleWeaponCase();
let move_action = ship.actions.listAll().filter(action => action instanceof MoveAction)[0];
let result = simulator.simulateAction(move_action, new Target(ship.arena_x, ship.arena_y, null));
check.equals(result.success, false);
check.equals(result.need_move, false);
check.equals(result.need_fire, false);
check.equals(result.parts, []);
});
test.case("does not move if already in range, even if in the safety margin", check => {
let [ship, simulator, action] = simpleWeaponCase(100);
let result = simulator.simulateAction(action, new Target(ship.arena_x + 97, ship.arena_y, null), 5);
check.equals(result.success, true);
check.equals(result.need_move, false);
result = simulator.simulateAction(action, new Target(ship.arena_x + 101, ship.arena_y, null), 5);
check.equals(result.success, true);
check.equals(result.need_move, true);
check.equals(result.move_location, new Target(ship.arena_x + 6, ship.arena_y));
});
test.case("simulates the results on a fake battle, to provide a list of expected diffs", check => {
let battle = TestTools.createBattle();
let ship = battle.fleets[0].ships[0];
let enemy = battle.fleets[1].ships[0];
ship.setArenaPosition(100, 100);
enemy.setArenaPosition(300, 100);
TestTools.setShipModel(ship, 1, 1, 3);
TestTools.setShipModel(enemy, 2, 1);
let engine = TestTools.addEngine(ship, 80);
let weapon = TestTools.addWeapon(ship, 5, 1, 150);
let simulator = new MoveFireSimulator(ship);
let result = simulator.simulateAction(weapon, Target.newFromShip(enemy), 5);
let diffs = simulator.getExpectedDiffs(nn(ship.getBattle()), result);
check.equals(diffs, [
new ShipActionUsedDiff(ship, engine, Target.newFromLocation(155, 100)),
new ShipValueDiff(ship, "power", -1),
new ShipMoveDiff(ship, ship.location, new ArenaLocationAngle(155, 100), engine),
new ShipActionUsedDiff(ship, weapon, Target.newFromShip(enemy)),
new ShipValueDiff(ship, "power", -1),
new ProjectileFiredDiff(ship, weapon, Target.newFromShip(enemy)),
new ShipDamageDiff(enemy, 2, 1, 0, 5),
new ShipValueDiff(enemy, "shield", -1),
new ShipValueDiff(enemy, "hull", -2),
new ShipDeathDiff(battle, enemy),
new EndBattleDiff(battle.fleets[0], 0)
]);
check.equals(enemy.getValue("hull"), 2);
check.equals(enemy.getValue("hull"), 2);
});
});
}

View File

@ -125,7 +125,7 @@ module TK.SpaceTac {
*/
simulateAction(action: BaseAction, target: Target, move_margin = 0): MoveFireResult {
let result = new MoveFireResult();
let ap = this.ship.getValue("power");
let ap = this.ship.getAttribute("power_capacity");
// Move or approach needed ?
let move_target: Target | null = null;
@ -160,7 +160,7 @@ module TK.SpaceTac {
// Check move AP
if (result.need_move && move_target && move_action) {
result.total_move_ap = move_action.getPowerUsage(this.ship, move_target);
result.total_move_ap = move_action.getPowerUsage(this.ship);
result.can_move = ap > 0;
result.can_end_move = result.total_move_ap <= ap;
result.move_location = move_target;
@ -175,7 +175,7 @@ module TK.SpaceTac {
result.success = result.need_move && result.can_move;
} else {
result.need_fire = true;
result.total_fire_ap = action.getPowerUsage(this.ship, target);
result.total_fire_ap = action.getPowerUsage(this.ship);
result.can_fire = result.total_fire_ap <= ap;
result.fire_location = target;
result.parts.push({ action: action, target: target, ap: result.total_fire_ap, possible: (!result.need_move || result.can_end_move) && result.can_fire });

View File

@ -62,25 +62,6 @@ module TK.SpaceTac.Specs {
check.equals(ship.getValue("shield"), 150);
});
test.case("checks if a ship is able to play", check => {
let battle = new Battle();
let ship = battle.fleets[0].addShip();
ship.setValue("hull", 10);
check.equals(ship.isAbleToPlay(), false);
check.equals(ship.isAbleToPlay(false), true);
ship.setValue("power", 5);
check.equals(ship.isAbleToPlay(), true);
check.equals(ship.isAbleToPlay(false), true);
ship.setDead();
check.equals(ship.isAbleToPlay(), false);
check.equals(ship.isAbleToPlay(false), false);
});
test.case("checks if a ship is inside a given circle", check => {
let ship = new Ship();
ship.arena_x = 5;
@ -100,7 +81,6 @@ module TK.SpaceTac.Specs {
TestTools.setShipModel(ship, 10, 20, 5);
ship.setValue("hull", 5);
ship.setValue("shield", 15);
ship.setValue("power", 2);
ship.active_effects.add(new StickyEffect(new AttributeLimitEffect("power_capacity", 3), 12));
ship.updateAttributes();
let action1 = new BaseAction("action1");
@ -114,7 +94,6 @@ module TK.SpaceTac.Specs {
check.in("before", check => {
check.equals(ship.getValue("hull"), 5, "hull");
check.equals(ship.getValue("shield"), 15, "shield");
check.equals(ship.getValue("power"), 2, "power");
check.equals(ship.active_effects.count(), 1, "effects count");
check.equals(ship.getAttribute("power_capacity"), 3, "power capacity");
check.equals(ship.actions.isToggled(action2), true, "action 2 activation");
@ -126,7 +105,6 @@ module TK.SpaceTac.Specs {
check.in("after", check => {
check.equals(ship.getValue("hull"), 10, "hull");
check.equals(ship.getValue("shield"), 20, "shield");
check.equals(ship.getValue("power"), 5, "power");
check.equals(ship.active_effects.count(), 0, "effects count");
check.equals(ship.getAttribute("power_capacity"), 5, "power capacity");
check.equals(ship.actions.isToggled(action2), false, "action 2 activation");

View File

@ -80,13 +80,6 @@ module TK.SpaceTac {
return level ? `Level ${this.level.get()} ${name}` : name;
}
// Returns true if the ship is able to play
// If *check_ap* is true, ap_current=0 will make this function return false
isAbleToPlay(check_ap: boolean = true): boolean {
var ap_checked = !check_ap || this.getValue("power") > 0;
return this.alive && ap_checked;
}
// Set position in the arena
// This does not consumes action points
setArenaPosition(x: number, y: number) {
@ -211,18 +204,6 @@ module TK.SpaceTac {
return this.attributes[name].get();
}
/**
* Initialize the action points counter
* This should be called once at the start of a battle
* If no value is provided, the attribute power_capacity will be used
*/
private initializePower(value: number | null = null): void {
if (value === null) {
value = this.getAttribute("power_capacity");
}
this.setValue("power", value);
}
/**
* Method called at the start of battle, to restore a pristine condition on the ship
*/
@ -234,7 +215,6 @@ module TK.SpaceTac {
this.updateAttributes();
this.restoreHealth();
this.initializePower();
}
/**

View File

@ -7,7 +7,6 @@ module TK.SpaceTac {
"initiative": "Capacity to play before others in a battle",
"hull": "Physical structure of the ship",
"shield": "Shield around the ship that may absorb damage",
"power": "Power available to supply the equipments",
"hull_capacity": "Maximal Hull value before the ship risks collapsing",
"shield_capacity": "Maximal Shield value to protect the hull from damage",
"power_capacity": "Maximal Power value to use equipment",
@ -18,7 +17,6 @@ module TK.SpaceTac {
"initiative": "initiative",
"hull": "hull",
"shield": "shield",
"power": "power",
"hull_capacity": "hull capacity",
"shield_capacity": "shield capacity",
"power_capacity": "power capacity",
@ -134,7 +132,6 @@ module TK.SpaceTac {
export class ShipValues {
hull = 0
shield = 0
power = 0
}
/**

View File

@ -8,7 +8,6 @@ module TK.SpaceTac.Specs {
check.equals(ship.getAttribute("power_capacity"), 0);
check.equals(ship.getValue("hull"), 0);
check.equals(ship.getValue("shield"), 0);
check.equals(ship.getValue("power"), 0);
TestTools.setShipModel(ship, 100, 200, 12);
@ -17,7 +16,6 @@ module TK.SpaceTac.Specs {
check.equals(ship.getAttribute("power_capacity"), 12);
check.equals(ship.getValue("hull"), 100);
check.equals(ship.getValue("shield"), 200);
check.equals(ship.getValue("power"), 12);
});
});
}

View File

@ -20,10 +20,10 @@ module TK.SpaceTac {
}
/**
* Add an engine, allowing a ship to move *distance*, for each action points
* Add an engine, allowing a ship to move up to *distance*
*/
static addEngine(ship: Ship, distance: number): MoveAction {
let action = new MoveAction("Engine", { distance_per_power: distance });
let action = new MoveAction("Engine", { max_distance: distance });
ship.actions.addCustom(action);
return action;
}
@ -59,11 +59,7 @@ module TK.SpaceTac {
new AttributeEffect("power_capacity", power),
]);
ship.actions.updateFromShip(ship);
ship.updateAttributes();
ship.restoreHealth();
ship.setValue("power", power);
ship.restoreInitialState();
}
/**

View File

@ -12,19 +12,16 @@ module TK.SpaceTac.Specs {
[ship, action, Target.newFromLocation(0, 0)],
], [
check => {
check.equals(ship.getValue("power"), 10, "power");
let cooldown = ship.actions.getCooldown(action);
check.equals(cooldown.uses, 0, "uses");
check.equals(cooldown.heat, 0, "heat");
},
check => {
check.equals(ship.getValue("power"), 7, "power");
let cooldown = ship.actions.getCooldown(action);
check.equals(cooldown.uses, 1, "uses");
check.equals(cooldown.heat, 0, "heat");
},
check => {
check.equals(ship.getValue("power"), 4, "power");
let cooldown = ship.actions.getCooldown(action);
check.equals(cooldown.uses, 2, "uses");
check.equals(cooldown.heat, 1, "heat");
@ -32,29 +29,6 @@ module TK.SpaceTac.Specs {
]);
})
test.case("checks against remaining power", check => {
let action = new BaseAction("test");
check.patch(action, "getPowerUsage", () => 3);
let ship = new Ship();
check.equals(action.checkCannotBeApplied(ship), ActionUnavailability.NO_SUCH_ACTION);
ship.actions.addCustom(action);
check.equals(action.checkCannotBeApplied(ship), ActionUnavailability.POWER);
ship.setValue("power", 5);
check.equals(action.checkCannotBeApplied(ship), null);
check.equals(action.checkCannotBeApplied(ship, 4), null);
check.equals(action.checkCannotBeApplied(ship, 3), null);
check.equals(action.checkCannotBeApplied(ship, 2), ActionUnavailability.POWER);
ship.setValue("power", 3);
check.equals(action.checkCannotBeApplied(ship), null);
ship.setValue("power", 2);
check.equals(action.checkCannotBeApplied(ship), ActionUnavailability.POWER);
})
test.case("checks against overheat", check => {
let action = new BaseAction("test");
let ship = new Ship();

View File

@ -52,8 +52,6 @@ module TK.SpaceTac {
NOT_PLAYING = "Not this ship turn",
// Action is not available
NO_SUCH_ACTION = "Action not available",
// Not enough power remaining
POWER = "Not enough power",
// Action is overheated
OVERHEATED = "Overheated",
// Vigilance is activated
@ -147,15 +145,6 @@ module TK.SpaceTac {
return ActionUnavailability.NO_SUCH_ACTION;
}
// Check AP usage
if (remaining_ap === null) {
remaining_ap = ship.getValue("power");
}
var ap_usage = this.getPowerUsage(ship, null);
if (remaining_ap < ap_usage) {
return ActionUnavailability.POWER;
}
// Check cooldown
if (!ship.actions.isUsable(this)) {
return ActionUnavailability.OVERHEATED;
@ -165,11 +154,9 @@ module TK.SpaceTac {
}
/**
* Get the power usage, for applying this action on an hypothetical target
*
* If target is null, an estimated cost is returned.
* Get the power cost of this action
*/
getPowerUsage(ship: Ship, target: Target | null): number {
getPowerUsage(ship: Ship): number {
return 0;
}
@ -281,12 +268,6 @@ module TK.SpaceTac {
// Action usage
result.push(new ShipActionUsedDiff(ship, this, target));
// Power usage
let cost = this.getPowerUsage(ship, target);
if (cost) {
result = result.concat(ship.getValueDiffs("power", -cost, true));
}
// Action effects
result = result.concat(this.getSpecificDiffs(ship, battle, target));
@ -318,12 +299,6 @@ module TK.SpaceTac {
return false;
}
let cost = this.getPowerUsage(ship, checked_target);
if (ship.getValue("power") < cost) {
console.warn("Action rejected - not enough power", ship, this, checked_target);
return false;
}
let diffs = this.getDiffs(ship, battle, checked_target);
if (diffs.length) {
battle.applyDiffs(diffs);

View File

@ -39,11 +39,9 @@ module TK.SpaceTac.Specs {
[ship, action, new Target(5, 0)],
], [
check => {
check.equals(ship.getValue("power"), 3, "power=3");
check.equals(battle.drones.count(), 0, "drones=0");
},
check => {
check.equals(ship.getValue("power"), 1, "power=1");
check.equals(battle.drones.count(), 1, "drones=1");
let drone = battle.drones.list()[0];

View File

@ -1,25 +1,5 @@
module TK.SpaceTac.Specs {
testing("MoveAction", test => {
test.case("checks movement against remaining AP", check => {
const battle = new Battle();
const ship = battle.fleets[0].addShip();
ship.setValue("power", 6);
ship.arena_x = 0;
ship.arena_y = 0;
var action = new MoveAction("Engine", { distance_per_power: 10 });
ship.actions.addCustom(action);
var result = action.checkTarget(ship, Target.newFromLocation(0, 20));
check.equals(result, Target.newFromLocation(0, 20));
result = action.checkTarget(ship, Target.newFromLocation(0, 80));
check.nears(nn(result).y, 59.9);
ship.setValue("power", 0);
result = action.checkTarget(ship, Target.newFromLocation(0, 80));
check.equals(result, null);
});
test.case("forbids targetting a ship", check => {
var ship1 = new Ship(null, "Test1");
var ship2 = new Ship(null, "Test2");
@ -38,9 +18,8 @@ module TK.SpaceTac.Specs {
let ship = battle.fleets[0].ships[0];
ship.setArenaPosition(500, 600)
TestTools.setShipModel(ship, 100, 0, 20);
ship.setValue("power", 5);
let action = new MoveAction("Engine", { distance_per_power: 1 });
let action = new MoveAction("Engine", { max_distance: 5 });
ship.actions.addCustom(action);
TestTools.actionChain(check, battle, [
@ -49,22 +28,17 @@ module TK.SpaceTac.Specs {
check => {
check.equals(ship.arena_x, 500, "ship X");
check.equals(ship.arena_y, 600, "ship Y");
check.equals(ship.getValue("power"), 5, "power");
},
check => {
check.nears(ship.arena_x, 504.382693, 5, "ship X");
check.nears(ship.arena_y, 602.191346, 5, "ship Y");
check.equals(ship.getValue("power"), 0, "power");
}
]);
});
test.case("builds a textual description", check => {
let action = new MoveAction("Engine", { distance_per_power: 58, safety_distance: 0 });
check.equals(action.getEffectsDescription(), "Move: 58km per power point");
action = new MoveAction("Engine", { distance_per_power: 58, safety_distance: 12 });
check.equals(action.getEffectsDescription(), "Move: 58km per power point (safety: 12km)");
let action = new MoveAction("Engine", { max_distance: 58 });
check.equals(action.getEffectsDescription(), "Move: up to 58km");
});
test.case("can't be used while in vigilance", check => {

View File

@ -1,21 +1,23 @@
module TK.SpaceTac {
/**
* Configuration of a trigger action
* Configuration of a move action
*/
export interface MoveActionConfig {
// Distance allowed for each power point (raw, without applying maneuvrability)
distance_per_power: number
// Safety distance from other ships
safety_distance: number
// Power cost
power_cost: number
// Minimal distance to be used
min_distance: number
// Maximal distance reachable in one turn
max_distance: number
}
/**
* Action to move the ship to a specific location
*/
export class MoveAction extends BaseAction implements MoveActionConfig {
distance_per_power = 0
safety_distance = 120
maneuvrability_factor = 0
power_cost = 1
min_distance = 50
max_distance = 100
constructor(name = "Engine", config?: Partial<MoveActionConfig>, code = "move") {
super(name, code);
@ -58,14 +60,6 @@ module TK.SpaceTac {
return base;
}
// Check AP usage
if (remaining_ap === null) {
remaining_ap = ship.getValue("power");
}
if (remaining_ap < 0.0001) {
return ActionUnavailability.POWER;
}
// Check vigilance actions
if (any(ship.getToggleActions(true), action => action instanceof VigilanceAction)) {
return ActionUnavailability.VIGILANCE;
@ -79,26 +73,12 @@ module TK.SpaceTac {
return null;
}
getPowerUsage(ship: Ship, target: Target | null): number {
if (this.distance_per_power == 0) {
return Infinity;
} else if (target) {
let distance = Target.newFromShip(ship).getDistanceTo(target);
return Math.ceil(distance / this.distance_per_power);
} else {
return 0;
}
getPowerUsage(ship: Ship): number {
return this.power_cost;
}
getRangeRadius(ship: Ship): number {
return this.getRangeRadiusForPower(ship);
}
/**
* Get the distance reachable with a given power
*/
getRangeRadiusForPower(ship: Ship, power = ship.getValue("power")): number {
return power * this.distance_per_power;
return this.max_distance;
}
/**
@ -122,12 +102,7 @@ module TK.SpaceTac {
}
getEffectsDescription(): string {
let result = `Move: ${this.distance_per_power}km per power point`;
if (this.safety_distance) {
result += ` (safety: ${this.safety_distance}km)`;
}
let result = `Move: up to ${this.max_distance}km`;
return result;
}
}

View File

@ -53,7 +53,7 @@ module TK.SpaceTac {
}
}
getPowerUsage(ship: Ship, target: Target | null): number {
getPowerUsage(ship: Ship): number {
return ship.actions.isToggled(this) ? -this.power : this.power;
}

View File

@ -86,7 +86,7 @@ module TK.SpaceTac {
}
}
getPowerUsage(ship: Ship, target: Target | null): number {
getPowerUsage(ship: Ship): number {
return this.power;
}

View File

@ -6,7 +6,7 @@ module TK.SpaceTac.Specs {
ship.actions.addCustom(action);
check.equals(action.code, "reactfire");
check.equals(action.getPowerUsage(ship, null), 2);
check.equals(action.getPowerUsage(ship), 2);
check.equals(action.radius, 120);
check.equals(action.intruder_count, 3);
check.equals(action.getRangeRadius(ship), 0);
@ -15,7 +15,7 @@ module TK.SpaceTac.Specs {
ship.actions.toggle(action, true);
check.equals(action.getVerb(ship), "Stop");
check.equals(action.getPowerUsage(ship, null), -2);
check.equals(action.getPowerUsage(ship), -2);
check.equals(action.getTargettingMode(ship), ActionTargettingMode.SELF_CONFIRM);
});
@ -59,7 +59,7 @@ module TK.SpaceTac.Specs {
let ship2b = battle.fleets[1].addShip();
ship2b.setArenaPosition(1200, 0);
TestTools.setShipModel(ship2b, 10, 0, 5);
let engine = ship2b.actions.addCustom(new MoveAction("Move", { distance_per_power: 1000, safety_distance: 100 }));
let engine = ship2b.actions.addCustom(new MoveAction("Move", { max_distance: 1000 }));
let action = ship1a.actions.addCustom(new VigilanceAction("Reactive Shot", { radius: 1000, filter: ActionTargettingFilter.ENEMIES }, {
intruder_effects: [new DamageEffect(1)]
@ -68,7 +68,6 @@ module TK.SpaceTac.Specs {
let diffs = action.getDiffs(ship1a, battle);
check.equals(diffs, [
new ShipActionUsedDiff(ship1a, action, Target.newFromShip(ship1a)),
new ShipValueDiff(ship1a, "power", -1),
new ShipActionToggleDiff(ship1a, action, true),
new ShipEffectAddedDiff(ship2a, action.effects[0])
]);

View File

@ -16,15 +16,13 @@ module TK.SpaceTac.Specs {
TestTools.setShipModel(ship4, 30, 30);
let weapon = TestTools.addWeapon(ship1, 50, 2, 200, 100);
let engine = TestTools.addEngine(ship1, 100);
let engine = TestTools.addEngine(ship1, 1000);
let maneuver = new Maneuver(ship1, weapon, Target.newFromLocation(530, 0));
check.contains(maneuver.effects, new ShipActionUsedDiff(ship1, engine, Target.newFromLocation(331, 0)), "engine use");
check.contains(maneuver.effects, new ShipValueDiff(ship1, "power", -4), "engine power");
check.contains(maneuver.effects, new ShipMoveDiff(ship1, ship1.location, new ArenaLocationAngle(331, 0), engine), "move");
check.contains(maneuver.effects, new ShipActionUsedDiff(ship1, weapon, Target.newFromLocation(530, 0)), "weapon use");
check.contains(maneuver.effects, new ProjectileFiredDiff(ship1, weapon, Target.newFromLocation(530, 0)), "weapon power");
check.contains(maneuver.effects, new ShipValueDiff(ship1, "power", -2), "weapon power");
check.contains(maneuver.effects, new ProjectileFiredDiff(ship1, weapon, Target.newFromLocation(530, 0)), "weapon projectile");
check.contains(maneuver.effects, new ShipValueDiff(ship2, "shield", -50), "ship2 shield value");
check.contains(maneuver.effects, new ShipValueDiff(ship3, "shield", -30), "ship3 shield value");
check.contains(maneuver.effects, new ShipValueDiff(ship3, "hull", -20), "ship3 hull value");

View File

@ -113,7 +113,6 @@ module TK.SpaceTac {
}
let evaluators: EvaluatorHelper[] = [
scaled(TacticalAIHelpers.evaluateTurnCost, 1),
scaled(TacticalAIHelpers.evaluateOverheat, 3),
scaled(TacticalAIHelpers.evaluateEnemyHealth, 5),
scaled(TacticalAIHelpers.evaluateAllyHealth, 20),

View File

@ -102,42 +102,10 @@ module TK.SpaceTac.Specs {
]);
});
test.case("evaluates turn cost", check => {
let battle = new Battle();
let ship = battle.fleets[0].addShip();
let weapon = TestTools.addWeapon(ship, 50, 5, 100);
let action = weapon;
let engine = TestTools.addEngine(ship, 25);
let maneuver = new Maneuver(ship, new BaseAction("fake"), new Target(0, 0), 0);
check.same(TacticalAIHelpers.evaluateTurnCost(ship, battle, maneuver), -1);
maneuver = new Maneuver(ship, action, Target.newFromLocation(100, 0), 0);
check.same(TacticalAIHelpers.evaluateTurnCost(ship, battle, maneuver), -Infinity);
TestTools.setShipModel(ship, 100, 0, 4, 1, [engine, action]);
maneuver = new Maneuver(ship, action, Target.newFromLocation(100, 0), 0);
check.same(TacticalAIHelpers.evaluateTurnCost(ship, battle, maneuver), -Infinity);
TestTools.setShipModel(ship, 100, 0, 10, 1, [engine, action]);
maneuver = new Maneuver(ship, action, Target.newFromLocation(100, 0), 0);
check.equals(TacticalAIHelpers.evaluateTurnCost(ship, battle, maneuver), 0.5); // 5 power remaining on 10
maneuver = new Maneuver(ship, action, Target.newFromLocation(110, 0), 0);
check.equals(TacticalAIHelpers.evaluateTurnCost(ship, battle, maneuver), 0.4); // 4 power remaining on 10
maneuver = new Maneuver(ship, action, Target.newFromLocation(140, 0), 0);
check.equals(TacticalAIHelpers.evaluateTurnCost(ship, battle, maneuver), 0.3); // 3 power remaining on 10
maneuver = new Maneuver(ship, action, Target.newFromLocation(310, 0), 0);
check.same(TacticalAIHelpers.evaluateTurnCost(ship, battle, maneuver), -1); // can't do in one turn
});
test.case("evaluates the drawback of doing nothing", check => {
let battle = new Battle();
let ship = battle.fleets[0].addShip();
TestTools.setShipModel(ship, 100, 0, 10);
let engine = TestTools.addEngine(ship, 50);
let weapon = TestTools.addWeapon(ship, 10, 2, 100, 10);
let toggle = ship.actions.addCustom(new ToggleAction("test"));
@ -150,14 +118,6 @@ module TK.SpaceTac.Specs {
ship.actions.toggle(toggle, true);
maneuver = new Maneuver(ship, toggle, Target.newFromShip(ship));
check.equals(TacticalAIHelpers.evaluateIdling(ship, battle, maneuver), -0.2, "toggle off");
maneuver = new Maneuver(ship, engine, Target.newFromLocation(0, 48));
check.equals(TacticalAIHelpers.evaluateIdling(ship, battle, maneuver), -0.9, "move only, at full power");
ship.setValue("power", 2);
maneuver = new Maneuver(ship, engine, Target.newFromLocation(0, 48));
check.equals(TacticalAIHelpers.evaluateIdling(ship, battle, maneuver), -0.1, "move only, at reduced power");
});
test.case("evaluates damage to enemies", check => {
@ -189,7 +149,7 @@ module TK.SpaceTac.Specs {
let battle = new Battle();
let ship = battle.fleets[0].addShip();
TestTools.setShipModel(ship, 100, 0, 10);
TestTools.addEngine(ship, 100);
TestTools.addEngine(ship, 1000);
let weapon = TestTools.addWeapon(ship, 100, 1, 100, 10);
let maneuver = new Maneuver(ship, weapon, Target.newFromLocation(200, 0), 0.5);

View File

@ -122,22 +122,6 @@ module TK.SpaceTac {
return ichain(self_maneuvers, distant_maneuvers);
}
/**
* Evaluate the number of turns necessary for the maneuver, between -1 and 1
*/
static evaluateTurnCost(ship: Ship, battle: Battle, maneuver: Maneuver): number {
let powerusage = maneuver.simulation.total_move_ap + maneuver.simulation.total_fire_ap;
if (powerusage == 0) {
return -1;
} else if (maneuver.simulation.total_fire_ap > ship.getAttribute("power_capacity")) {
return -Infinity;
} else if (powerusage > ship.getValue("power")) {
return -1;
} else {
return (ship.getValue("power") - powerusage) / ship.getAttribute("power_capacity");
}
}
/**
* Evaluate doing nothing, between -1 and 1
*/
@ -148,8 +132,6 @@ module TK.SpaceTac {
return 0.5;
} else if (maneuver.action instanceof ToggleAction) {
return ship.actions.isToggled(maneuver.action) ? -0.2 : 0.5;
} else if (maneuver.action instanceof MoveAction) {
return -(ship.getValue("power") - maneuver.getPowerUsage()) / power_capacity;
} else {
return 0;
}

View File

@ -1,18 +1,18 @@
module TK.SpaceTac {
testing("ValueEffect", test => {
test.case("adds an amount to a ship value", check => {
let effect = new ValueEffect("shield", 20);
let effect = new ValueEffect("hull", 20);
let battle = new Battle();
let ship = battle.fleets[0].addShip();
ship.setValue("shield", 55);
check.equals(ship.getValue("shield"), 55);
ship.setValue("hull", 55);
check.equals(ship.getValue("hull"), 55);
battle.applyDiffs(effect.getOnDiffs(ship, ship));
check.equals(ship.getValue("shield"), 75);
check.equals(ship.getValue("hull"), 75);
battle.applyDiffs(effect.getOnDiffs(ship, ship));
check.equals(ship.getValue("shield"), 95);
check.equals(ship.getValue("hull"), 95);
});
test.case("estimates if the effect is beneficial", check => {
@ -66,38 +66,38 @@ module TK.SpaceTac {
});
test.case("has a description", check => {
let effect = new ValueEffect("power", 12);
check.equals(effect.getDescription(), "power +12");
let effect = new ValueEffect("hull", 12);
check.equals(effect.getDescription(), "hull +12");
effect = new ValueEffect("power", -4);
check.equals(effect.getDescription(), "power -4");
effect = new ValueEffect("hull", -4);
check.equals(effect.getDescription(), "hull -4");
effect = new ValueEffect("power");
effect = new ValueEffect("hull");
check.equals(effect.getDescription(), "no effect");
effect = new ValueEffect("power", 0, -5);
check.equals(effect.getDescription(), "power -5 when removed");
effect = new ValueEffect("hull", 0, -5);
check.equals(effect.getDescription(), "hull -5 when removed");
effect = new ValueEffect("power", 5, -5);
check.equals(effect.getDescription(), "power +5 while active");
effect = new ValueEffect("hull", 5, -5);
check.equals(effect.getDescription(), "hull +5 while active");
effect = new ValueEffect("power", 5, -6);
check.equals(effect.getDescription(), "power +5 on, -6 off");
effect = new ValueEffect("hull", 5, -6);
check.equals(effect.getDescription(), "hull +5 on, -6 off");
effect = new ValueEffect("power", 0, 0, 6);
check.equals(effect.getDescription(), "power +6 on turn start");
effect = new ValueEffect("hull", 0, 0, 6);
check.equals(effect.getDescription(), "hull +6 on turn start");
effect = new ValueEffect("power", 0, 0, 0, -3);
check.equals(effect.getDescription(), "power -3 on turn end");
effect = new ValueEffect("hull", 0, 0, 0, -3);
check.equals(effect.getDescription(), "hull -3 on turn end");
effect = new ValueEffect("power", 0, 0, 3, -3);
check.equals(effect.getDescription(), "power +3 during turn");
effect = new ValueEffect("hull", 0, 0, 3, -3);
check.equals(effect.getDescription(), "hull +3 during turn");
effect = new ValueEffect("power", 0, 0, 4, -3);
check.equals(effect.getDescription(), "power +4 on turn start, -3 on turn end");
effect = new ValueEffect("hull", 0, 0, 4, -3);
check.equals(effect.getDescription(), "hull +4 on turn start, -3 on turn end");
effect = new ValueEffect("power", 1, 2, 3, 4);
check.equals(effect.getDescription(), "power +1 on, +2 off, +3 on turn start, +4 on turn end");
effect = new ValueEffect("hull", 1, 2, 3, 4);
check.equals(effect.getDescription(), "hull +1 on, +2 off, +3 on turn start, +4 on turn end");
});
});
}

View File

@ -20,12 +20,12 @@ module TK.SpaceTac.Specs {
})
test.case("builds a description", check => {
let effect = new ValueTransferEffect("power", 12);
check.equals(effect.getDescription(), "give 12 power");
let effect = new ValueTransferEffect("hull", 12);
check.equals(effect.getDescription(), "give 12 hull");
check.equals(effect.isBeneficial(), true);
effect = new ValueTransferEffect("shield", -20);
check.equals(effect.getDescription(), "steal 20 shield");
effect = new ValueTransferEffect("hull", -20);
check.equals(effect.getDescription(), "steal 20 hull");
check.equals(effect.isBeneficial(), false);
})
})

View File

@ -12,8 +12,8 @@ module TK.SpaceTac {
getLevelUpgrades(level: number): ShipUpgrade[] {
let engine = new MoveAction("Engine", {
distance_per_power: 60,
safety_distance: 250,
max_distance: 300,
min_distance: 100,
});
engine.configureCooldown(1, 1);

View File

@ -13,8 +13,7 @@ module TK.SpaceTac {
getLevelUpgrades(level: number): ShipUpgrade[] {
if (level == 1) {
let engine = new MoveAction("Engine", {
distance_per_power: 460,
safety_distance: 100
max_distance: 1000
});
engine.configureCooldown(2, 1);

View File

@ -13,7 +13,7 @@ module TK.SpaceTac {
getLevelUpgrades(level: number): ShipUpgrade[] {
if (level == 1) {
let engine = new MoveAction("Engine", {
distance_per_power: 120,
max_distance: 400,
});
let laser = new TriggerAction("Wingspan Laser", {
@ -28,12 +28,12 @@ module TK.SpaceTac {
intruder_effects: [new DamageEffect(4, DamageEffectMode.SHIELD_THEN_HULL)]
}, "interceptors");
let power_steal = new TriggerAction("Power Thief", {
effects: [new ValueTransferEffect("power", -1)],
let structural_thief = new TriggerAction("Structural Thief", {
effects: [new ValueTransferEffect("hull", -1)],
power: 1,
blast: 250
}, "powerdepleter");
power_steal.configureCooldown(1, 1);
structural_thief.configureCooldown(1, 1);
return [
{
@ -55,7 +55,7 @@ module TK.SpaceTac {
},
{
code: "Power Thief",
actions: [power_steal]
actions: [structural_thief]
},
{
code: "Interceptors Field",

View File

@ -13,7 +13,7 @@ module TK.SpaceTac {
getLevelUpgrades(level: number): ShipUpgrade[] {
if (level == 1) {
let engine = new MoveAction("Engine", {
distance_per_power: 240,
max_distance: 600,
});
let gatling = new TriggerAction("Gatling Gun", {

View File

@ -13,7 +13,7 @@ module TK.SpaceTac {
getLevelUpgrades(level: number): ShipUpgrade[] {
if (level == 1) {
let engine = new MoveAction("Engine", {
distance_per_power: 130,
max_distance: 500,
});
let missile = new TriggerAction("SubMunition Missile", {

View File

@ -13,7 +13,7 @@ module TK.SpaceTac {
getLevelUpgrades(level: number): ShipUpgrade[] {
if (level == 1) {
let engine = new MoveAction("Main Engine", {
distance_per_power: 420,
max_distance: 850,
});
let depleter = new TriggerAction("Power Depleter", {

View File

@ -13,8 +13,7 @@ module TK.SpaceTac {
getLevelUpgrades(level: number): ShipUpgrade[] {
if (level == 1) {
let engine = new MoveAction("Engine", {
distance_per_power: 310,
safety_distance: 160,
max_distance: 650,
});
let missile = new TriggerAction("SubMunition Missile", {

View File

@ -13,7 +13,7 @@ module TK.SpaceTac {
getLevelUpgrades(level: number): ShipUpgrade[] {
if (level == 1) {
let engine = new MoveAction("Engine", {
distance_per_power: 120,
max_distance: 400,
});
let gatling = new TriggerAction("Gatling Gun", {

View File

@ -13,7 +13,7 @@ module TK.SpaceTac {
getLevelUpgrades(level: number): ShipUpgrade[] {
if (level == 1) {
let engine = new MoveAction("Engine", {
distance_per_power: 120,
max_distance: 450,
});
let gatling1 = new TriggerAction("Primary Gatling", {

View File

@ -13,7 +13,7 @@ module TK.SpaceTac {
getLevelUpgrades(level: number): ShipUpgrade[] {
if (level == 1) {
let engine = new MoveAction("Engine", {
distance_per_power: 220,
max_distance: 550,
});
engine.configureCooldown(1, 1);

View File

@ -13,7 +13,7 @@ module TK.SpaceTac {
getLevelUpgrades(level: number): ShipUpgrade[] {
if (level == 1) {
let engine = new MoveAction("Engine", {
distance_per_power: 280,
max_distance: 500,
});
let laser = new TriggerAction("Prokhorov Laser", {
@ -29,8 +29,8 @@ module TK.SpaceTac {
hull.configureCooldown(1, 4);
let disengage = new MoveAction("Disengage", {
distance_per_power: 1000,
safety_distance: 200,
max_distance: 1000,
min_distance: 600,
}, "ionthruster");
disengage.configureCooldown(1, 3);

View File

@ -34,34 +34,6 @@ module TK.SpaceTac.UI {
this.actions = builder.container("actions", 86, 6);
builder.in(this.actions).image("battle-actionbar-actions-background");
// Log processing
battleview.log_processor.register(diff => {
if (!(diff instanceof BaseBattleShipDiff) || !this.ship || !this.ship.is(diff.ship_id)) {
return {};
}
if (diff instanceof ShipValueDiff && diff.code == "power") {
return {
background: async () => {
this.action_icons.forEach(action => action.refresh());
}
}
} else if (diff instanceof ShipActionUsedDiff || diff instanceof ShipActionToggleDiff) {
return {
background: async () => this.action_icons.forEach(action => action.refresh())
}
} else if (diff instanceof ShipCooldownDiff) {
return {
background: async () => {
let icons = this.action_icons.filter(icon => icon.action.is(diff.action));
icons.forEach(icon => icon.refresh());
}
}
} else {
return {}
}
});
this.setInteractivity(false);
}

View File

@ -1,139 +0,0 @@
module TK.SpaceTac.UI.Specs {
testing("ActionIcon", test => {
let testgame = setupBattleview(test);
test.case("displays power usage", check => {
let bar = testgame.view.action_bar;
let ship = new Ship();
let action = new BaseAction("something");
let icon = new ActionIcon(bar, ship, action, 0);
check.same(icon.power_container.visible, false, "initial state");
icon.refresh();
check.same(icon.power_container.visible, false, "no change");
let cost = 3;
check.patch(action, "getPowerUsage", () => cost);
icon.refresh();
check.in("power cost = 3", check => {
check.equals(icon.power_container.visible, true);
check.equals(icon.power_text.text, "3\n-");
});
cost = -2;
icon.refresh();
check.in("power cost = -2", check => {
check.equals(icon.power_container.visible, true);
check.equals(icon.power_text.text, "2\n+");
});
})
test.case("displays disabled and fading states", check => {
let bar = testgame.view.action_bar;
let ship = new Ship();
TestTools.setShipModel(ship, 100, 0, 5);
let action = TestTools.addWeapon(ship, 50, 3);
let icon = new ActionIcon(bar, ship, action, 0);
check.equals(icon.container.name, "battle-actionbar-frame-enabled", "5/5");
check.equals(icon.power_bg.name, "battle-actionbar-consumption-enabled", "5/5");
check.same(icon.power_bg.visible, true, "5/5");
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-enabled", "5/5");
icon.refresh(null, 1);
check.equals(icon.container.name, "battle-actionbar-frame-enabled", "4/5");
check.equals(icon.power_bg.name, "battle-actionbar-consumption-enabled", "4/5");
check.same(icon.power_bg.visible, true, "4/5");
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-enabled", "4/5");
icon.refresh(null, 4);
check.equals(icon.container.name, "battle-actionbar-frame-fading", "1/5");
check.equals(icon.power_bg.name, "battle-actionbar-consumption-enabled", "1/5");
check.same(icon.power_bg.visible, true, "1/5");
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-enabled", "1/5");
ship.setValue("power", 2);
icon.refresh();
check.equals(icon.container.name, "battle-actionbar-frame-disabled", "2/2");
check.equals(icon.power_bg.name, "battle-actionbar-consumption-disabled", "2/2");
check.same(icon.power_bg.visible, true, "2/2");
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-disabled", "2/2");
icon.refresh(null, 6);
check.equals(icon.container.name, "battle-actionbar-frame-disabled", "0/2");
check.equals(icon.power_bg.name, "battle-actionbar-consumption-disabled", "0/2");
check.same(icon.power_bg.visible, true, "0/2");
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-disabled", "0/2");
})
test.case("displays toggle state", check => {
let bar = testgame.view.action_bar;
let ship = new Ship();
TestTools.setShipModel(ship, 100, 0, 5);
let action = new ToggleAction("toggle", { power: 2 });
ship.actions.addCustom(action);
let icon = new ActionIcon(bar, ship, action, 0);
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-enabled", "initial");
check.equals(icon.power_bg.name, "battle-actionbar-consumption-enabled", "initial");
check.equals(icon.img_cooldown.name, "battle-actionbar-sticky-untoggled", "initial");
check.same(icon.img_cooldown.visible, true, "initial");
ship.actions.toggle(action, true);
icon.refresh();
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-toggled", "initial");
check.equals(icon.power_bg.name, "battle-actionbar-consumption-toggled", "initial");
check.equals(icon.img_cooldown.name, "battle-actionbar-sticky-toggled", "initial");
check.same(icon.img_cooldown.visible, true, "initial");
})
test.case("displays overheat/cooldown", check => {
let bar = testgame.view.action_bar;
let ship = new Ship();
let action = new TriggerAction("weapon");
action.configureCooldown(1, 3);
TestTools.setShipModel(ship, 100, 0, 5, 1, [action]);
let icon = new ActionIcon(bar, ship, action, 0);
check.same(icon.img_cooldown.visible, false, "initial");
check.equals(icon.img_cooldown.name, "battle-actionbar-sticky-untoggled", "initial");
check.same(icon.img_cooldown_group.length, 1, "initial");
icon.refresh(action);
check.same(icon.img_cooldown.visible, true, "overheat");
check.equals(icon.img_cooldown.name, "battle-actionbar-sticky-overheat", "overheat");
check.same(icon.img_cooldown_group.length, 4, "overheat");
action.configureCooldown(1, 12);
TestTools.setShipModel(ship, 100, 0, 5, 1, [action]);
icon.refresh(action);
check.same(icon.img_cooldown.visible, true, "superheat");
check.equals(icon.img_cooldown.name, "battle-actionbar-sticky-overheat", "superheat");
check.same(icon.img_cooldown_group.length, 6, "superheat");
action.configureCooldown(1, 4);
TestTools.setShipModel(ship, 100, 0, 5, 1, [action]);
ship.actions.getCooldown(action).use();
icon.refresh(action);
check.same(icon.img_cooldown.visible, true, "cooling");
check.equals(icon.img_cooldown.name, "battle-actionbar-sticky-disabled", "cooling");
check.same(icon.img_cooldown_group.length, 5, "cooling");
})
test.case("displays currently targetting", check => {
testgame.view.animations.setImmediate();
let bar = testgame.view.action_bar;
let ship = new Ship();
TestTools.setShipModel(ship, 100, 0, 5);
let action = TestTools.addWeapon(ship, 50, 3);
let icon = new ActionIcon(bar, ship, action, 0);
check.same(icon.img_targetting.visible, false, "initial");
icon.refresh(action);
check.same(icon.img_targetting.visible, true, "selected");
icon.refresh(new BaseAction("other"));
check.same(icon.img_targetting.visible, false, "other");
})
});
}

View File

@ -160,7 +160,7 @@ module TK.SpaceTac.UI {
let disabled = bool(this.action.checkCannotBeApplied(this.ship));
let selected = (used === this.action);
let toggled = (this.action instanceof ToggleAction) && this.ship.actions.isToggled(this.action);
let fading = bool(this.action.checkCannotBeApplied(this.ship, this.ship.getValue("power") - power_consumption));
let fading = bool(this.action.checkCannotBeApplied(this.ship, this.ship.getAttribute("power_capacity") - power_consumption));
let cooldown = this.ship.actions.getCooldown(this.action);
let heat = cooldown.heat;
let targetting = used !== null;
@ -210,7 +210,7 @@ module TK.SpaceTac.UI {
}
// left
let cost = this.action.getPowerUsage(this.ship, null);
let cost = this.action.getPowerUsage(this.ship);
this.power_container.setVisible(bool(cost));
this.power_text.setText(`${Math.abs(cost)}\n${cost < 0 ? "+" : "-"}`);
this.power_text.setColor((cost > 0) ? "#ffdd4b" : "#dbe748");

View File

@ -12,8 +12,8 @@ module TK.SpaceTac.UI.Specs {
ActionTooltip.fill(tooltip.getBuilder(), ship, action1, 0);
checkText(check, tooltip.container.content.list[1], "Use Thruster");
checkText(check, tooltip.container.content.list[2], "Cost: 1 power per 0km");
checkText(check, tooltip.container.content.list[3], "Move: 0km per power point (safety: 120km)");
checkText(check, tooltip.container.content.list[2], "Cost: 1 power");
checkText(check, tooltip.container.content.list[3], "Move: up to 100km");
checkText(check, tooltip.container.content.list[4], "[ 1 ]");
tooltip.hide();

View File

@ -17,11 +17,8 @@ module TK.SpaceTac.UI {
let unavailable = action.checkCannotBeApplied(ship);
if (unavailable != null) {
builder.text(unavailable, 150, 40, { color: "#e54d2b" });
} else if (action instanceof MoveAction) {
let cost = `Cost: 1 power per ${action.distance_per_power}km`;
builder.text(cost, 150, 40, { color: "#ffdd4b" });
} else {
let power_usage = action.getPowerUsage(ship, null);
let power_usage = action.getPowerUsage(ship);
if (power_usage) {
let cost = (power_usage > 0) ? `Cost: ${power_usage} power` : `Recover: ${-power_usage} power`;
builder.text(cost, 150, 40, { color: "#ffdd4b" });

View File

@ -13,7 +13,6 @@ module TK.SpaceTac.UI.Specs {
TestTools.setAttribute(ship, "evasion", 7);
ship.setValue("hull", 57);
ship.setValue("shield", 100);
ship.setValue("power", 9);
ship.active_effects.add(new AttributeEffect("hull_capacity", 50));
ship.active_effects.add(new StickyEffect(new AttributeLimitEffect("shield_capacity", 2), 3));
tooltip.setShip(ship);
@ -26,7 +25,7 @@ module TK.SpaceTac.UI.Specs {
check.contains(images, "battle-hud-ship-effect-bad");
check.equals(texts, [
"Level 1 Fury",
"57", "max", "58", "100", "max", "140", "7", "9", "max", "12",
"57", "max", "58", "12",
"Weapon", "hull capacity +50", "limit shield capacity to 2 for 3 turns",
"Super ship model !"
]);

View File

@ -45,9 +45,7 @@ module TK.SpaceTac.UI {
if (ship.alive) {
ShipTooltip.addValue(builder, 0, "#eb4e4a", "attribute-hull_capacity", ship.getValue("hull"), ship.getAttribute("hull_capacity"));
ShipTooltip.addValue(builder, 1, "#2ad8dc", "attribute-shield_capacity", ship.getValue("shield"), ship.getAttribute("shield_capacity"));
ShipTooltip.addValue(builder, 2, "#c1f06b", "attribute-evasion", ship.getAttribute("evasion"));
ShipTooltip.addValue(builder, 3, "#ffdd4b", "attribute-power_capacity", ship.getValue("power"), ship.getAttribute("power_capacity"));
ShipTooltip.addValue(builder, 1, "#ffdd4b", "attribute-power_capacity", ship.getAttribute("power_capacity"));
let iy = 210;

View File

@ -28,19 +28,19 @@ module TK.SpaceTac.UI.Specs {
};
targetting.drawPart(part, true, null);
check.called(drawvector, [
[0xdc6441, 10, 20, 50, 30, 0]
[0xdc6441, 10, 20, 50, 30]
]);
targetting.drawPart(part, false, null);
check.called(drawvector, [
[0x8e8e8e, 10, 20, 50, 30, 0]
[0x8e8e8e, 10, 20, 50, 30]
]);
targetting.action = engine;
part.action = engine;
targetting.drawPart(part, true, null);
check.called(drawvector, [
[0xe09c47, 10, 20, 50, 30, 12]
[0xe09c47, 10, 20, 50, 30]
]);
})
@ -158,8 +158,8 @@ module TK.SpaceTac.UI.Specs {
let targetting = newTargetting();
let ship = testgame.view.battle.fleets[0].ships[0];
ship.setArenaPosition(0, 0);
TestTools.setShipModel(ship, 100, 0, 8);
let move = TestTools.addEngine(ship, 100);
TestTools.setShipModel(ship, 100, 0, 10);
let move = TestTools.addEngine(ship, 800);
let fire = TestTools.addWeapon(ship, 50, 2, 300, 100);
let last_call: any = null;
check.patch(targetting.range_hint, "clear", () => {
@ -182,7 +182,7 @@ module TK.SpaceTac.UI.Specs {
// move+fire
targetting.setAction(ship, fire);
targetting.setTargetFromLocation({ x: 400, y: 0 });
check.equals(last_call, [ship, move, 600]);
check.equals(last_call, [ship, move, 800]);
});
});
}

View File

@ -125,8 +125,7 @@ module TK.SpaceTac.UI {
let move = part.action instanceof MoveAction;
let color = (enabled && part.possible) ? (move ? 0xe09c47 : 0xdc6441) : 0x8e8e8e;
let src = previous ? previous.target : this.ship.location;
let gradation = (part.action instanceof MoveAction) ? part.action.distance_per_power : 0;
this.drawVector(color, src.x, src.y, part.target.x, part.target.y, gradation);
this.drawVector(color, src.x, src.y, part.target.x, part.target.y);
}
/**
@ -306,11 +305,7 @@ module TK.SpaceTac.UI {
}
}
if (move_action) {
let power = this.ship.getValue("power");
if (this.action !== move_action) {
power = Math.max(power - this.action.getPowerUsage(this.ship, this.target), 0);
}
let radius = move_action.getRangeRadiusForPower(this.ship, power);
let radius = move_action.max_distance;
this.range_hint.update(this.ship, move_action, radius);
} else {
this.range_hint.clear();