2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2018-02-08 15:16:03 +00:00
|
|
|
/**
|
2019-05-21 21:29:47 +00:00
|
|
|
* Configuration of a move action
|
2018-02-08 15:16:03 +00:00
|
|
|
*/
|
|
|
|
export interface MoveActionConfig {
|
2019-05-21 21:29:47 +00:00
|
|
|
// Power cost
|
|
|
|
power_cost: number
|
|
|
|
// Minimal distance to be used
|
|
|
|
min_distance: number
|
|
|
|
// Maximal distance reachable in one turn
|
|
|
|
max_distance: number
|
2018-02-08 15:16:03 +00:00
|
|
|
}
|
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
/**
|
|
|
|
* Action to move the ship to a specific location
|
|
|
|
*/
|
2018-02-08 15:16:03 +00:00
|
|
|
export class MoveAction extends BaseAction implements MoveActionConfig {
|
2019-05-21 21:29:47 +00:00
|
|
|
power_cost = 1
|
|
|
|
min_distance = 50
|
|
|
|
max_distance = 100
|
2018-02-08 15:16:03 +00:00
|
|
|
|
|
|
|
constructor(name = "Engine", config?: Partial<MoveActionConfig>, code = "move") {
|
|
|
|
super(name, code);
|
|
|
|
|
|
|
|
if (config) {
|
|
|
|
this.configureEngine(config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 22:53:44 +00:00
|
|
|
getCategory(): ActionCategory {
|
|
|
|
return ActionCategory.MOVE;
|
|
|
|
}
|
|
|
|
|
2018-02-08 15:16:03 +00:00
|
|
|
/**
|
|
|
|
* Configure the engine
|
|
|
|
*/
|
|
|
|
configureEngine(config: Partial<MoveActionConfig>): void {
|
|
|
|
copyfields(config, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
getVerb(ship: Ship): string {
|
2017-11-29 22:03:58 +00:00
|
|
|
return "Move";
|
|
|
|
}
|
|
|
|
|
2018-02-08 15:16:03 +00:00
|
|
|
getTitle(ship: Ship): string {
|
|
|
|
return `Use ${this.name}`;
|
|
|
|
}
|
|
|
|
|
2017-09-19 15:09:06 +00:00
|
|
|
getTargettingMode(ship: Ship): ActionTargettingMode {
|
|
|
|
return ActionTargettingMode.SPACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
getDefaultTarget(ship: Ship): Target {
|
|
|
|
return Target.newFromLocation(ship.arena_x + Math.cos(ship.arena_angle) * 100, ship.arena_y + Math.sin(ship.arena_angle) * 100);
|
|
|
|
}
|
|
|
|
|
2018-04-04 16:17:10 +00:00
|
|
|
checkCannotBeApplied(ship: Ship, remaining_ap: number | null = null): ActionUnavailability | null {
|
2017-03-07 19:27:46 +00:00
|
|
|
let base = super.checkCannotBeApplied(ship, Infinity);
|
|
|
|
if (base) {
|
|
|
|
return base;
|
2015-02-26 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 16:17:10 +00:00
|
|
|
// Check vigilance actions
|
|
|
|
if (any(ship.getToggleActions(true), action => action instanceof VigilanceAction)) {
|
|
|
|
return ActionUnavailability.VIGILANCE;
|
2017-03-07 19:27:46 +00:00
|
|
|
}
|
2018-04-04 16:17:10 +00:00
|
|
|
|
2018-06-13 18:17:46 +00:00
|
|
|
// Check pinned status
|
|
|
|
if (any(ship.getEffects(), effect => effect instanceof PinnedEffect)) {
|
|
|
|
return ActionUnavailability.PINNED;
|
|
|
|
}
|
|
|
|
|
2018-04-04 16:17:10 +00:00
|
|
|
return null;
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 21:29:47 +00:00
|
|
|
getPowerUsage(ship: Ship): number {
|
|
|
|
return this.power_cost;
|
2015-02-26 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 00:00:00 +00:00
|
|
|
getRangeRadius(ship: Ship): number {
|
2019-05-21 21:29:47 +00:00
|
|
|
return this.max_distance;
|
2017-01-19 18:33:56 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 23:32:18 +00:00
|
|
|
/**
|
|
|
|
* Apply reachable range, with remaining power
|
|
|
|
*/
|
|
|
|
applyReachableRange(ship: Ship, target: Target, margin = 0.1): Target {
|
|
|
|
let max_distance = this.getRangeRadius(ship);
|
|
|
|
max_distance = Math.max(0, max_distance - margin);
|
|
|
|
return target.constraintInRange(ship.arena_x, ship.arena_y, max_distance);
|
|
|
|
}
|
2017-06-19 23:04:27 +00:00
|
|
|
|
2017-07-31 22:49:00 +00:00
|
|
|
checkLocationTarget(ship: Ship, target: Target): Target | null {
|
2017-06-21 23:32:18 +00:00
|
|
|
target = this.applyReachableRange(ship, target);
|
2017-07-31 22:49:00 +00:00
|
|
|
return target.getDistanceTo(ship.location) > 0 ? target : null;
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
2015-01-02 00:00:00 +00:00
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
protected getSpecificDiffs(ship: Ship, battle: Battle, target: Target): BaseBattleDiff[] {
|
|
|
|
let angle = (arenaDistance(target, ship.location) < 0.00001) ? ship.arena_angle : arenaAngle(ship.location, target);
|
|
|
|
let destination = new ArenaLocationAngle(target.x, target.y, angle);
|
2018-02-08 15:16:03 +00:00
|
|
|
return [new ShipMoveDiff(ship, ship.location, destination, this)];
|
2015-01-02 00:00:00 +00:00
|
|
|
}
|
2017-04-18 22:55:59 +00:00
|
|
|
|
|
|
|
getEffectsDescription(): string {
|
2019-05-21 21:29:47 +00:00
|
|
|
let result = `Move: up to ${this.max_distance}km`;
|
2017-08-17 22:53:21 +00:00
|
|
|
return result;
|
2017-04-18 22:55:59 +00:00
|
|
|
}
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|