2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2018-02-08 15:16:03 +00:00
|
|
|
/**
|
|
|
|
* Configuration of a trigger action
|
|
|
|
*/
|
|
|
|
export interface MoveActionConfig {
|
2018-07-09 14:04:40 +00:00
|
|
|
// Distance allowed for each power point
|
2018-02-08 15:16:03 +00:00
|
|
|
distance_per_power: number
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
distance_per_power = 0
|
|
|
|
|
|
|
|
constructor(name = "Engine", config?: Partial<MoveActionConfig>, code = "move") {
|
|
|
|
super(name, code);
|
|
|
|
|
|
|
|
if (config) {
|
|
|
|
this.configureEngine(config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|
|
|
|
|
|
|
|
// Check AP usage
|
|
|
|
if (remaining_ap === null) {
|
2017-11-14 00:07:06 +00:00
|
|
|
remaining_ap = ship.getValue("power");
|
2015-02-26 00:00:00 +00:00
|
|
|
}
|
2018-04-04 16:17:10 +00:00
|
|
|
if (remaining_ap < 0.0001) {
|
|
|
|
return ActionUnavailability.POWER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2018-03-05 21:28:06 +00:00
|
|
|
getPowerUsage(ship: Ship, target: Target | null): number {
|
2018-03-20 23:23:00 +00:00
|
|
|
if (this.distance_per_power == 0) {
|
|
|
|
return Infinity;
|
|
|
|
} else if (target) {
|
2018-07-09 14:59:17 +00:00
|
|
|
let distance = ship.grid.measure(ship.location, target);
|
2018-03-20 23:23:00 +00:00
|
|
|
return Math.ceil(distance / this.distance_per_power);
|
2017-09-19 15:09:06 +00:00
|
|
|
} else {
|
2015-02-26 00:00:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-03 00:00:00 +00:00
|
|
|
getRangeRadius(ship: Ship): number {
|
2018-07-10 14:23:32 +00:00
|
|
|
return ship.getValue("power") * this.getDistancePerPower(ship);
|
|
|
|
}
|
|
|
|
|
|
|
|
getDistancePerPower(ship: Ship): number {
|
|
|
|
return this.distance_per_power * ship.grid.getUnit();
|
2017-01-19 18:33:56 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 10:28:18 +00:00
|
|
|
checkLocationTarget(ship: Ship, target: Target): boolean {
|
2018-07-10 14:23:32 +00:00
|
|
|
if (!ship.grid.check(target) || ship.grid.measure(ship.location, target) < 1e-8) {
|
2018-07-09 14:59:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-09 14:04:40 +00:00
|
|
|
// TODO Check the space is not occupied
|
2018-07-09 14:59:17 +00:00
|
|
|
|
2018-07-10 14:23:32 +00:00
|
|
|
return ship.getValue("power") >= this.getPowerUsage(ship, target);
|
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[] {
|
2018-07-09 09:38:42 +00:00
|
|
|
let angle = (arenaDistance(target, ship.location) < 1e-8) ? ship.arena_angle : arenaAngle(ship.location, target);
|
2017-11-14 00:07:06 +00:00
|
|
|
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 {
|
2018-03-20 23:23:00 +00:00
|
|
|
let result = `Move: ${this.distance_per_power}km per power point`;
|
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
|
|
|
}
|