2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac {
|
2014-12-31 00:00:00 +00:00
|
|
|
// Action to move to a given location
|
|
|
|
export class MoveAction extends BaseAction {
|
2017-04-18 19:51:23 +00:00
|
|
|
// Distance allowed for each power point
|
|
|
|
distance_per_power: number;
|
2015-04-21 20:14:17 +00:00
|
|
|
|
|
|
|
// Safety distance from other ships
|
|
|
|
safety_distance: number;
|
|
|
|
|
2017-03-09 17:11:00 +00:00
|
|
|
// Equipment cannot be null (engine)
|
|
|
|
equipment: Equipment;
|
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
constructor(equipment: Equipment, distance_per_power = 0) {
|
2017-01-08 22:42:53 +00:00
|
|
|
super("move", "Move", true, equipment);
|
2015-04-21 20:14:17 +00:00
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
this.distance_per_power = distance_per_power;
|
2015-04-21 20:14:17 +00:00
|
|
|
this.safety_distance = 50;
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 17:11:00 +00:00
|
|
|
checkCannotBeApplied(ship: Ship, remaining_ap: number | null = null): string | 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-02-07 19:15:21 +00:00
|
|
|
remaining_ap = ship.values.power.get();
|
2015-02-26 00:00:00 +00:00
|
|
|
}
|
2017-03-07 19:27:46 +00:00
|
|
|
if (remaining_ap > 0.0001) {
|
2017-03-08 23:18:40 +00:00
|
|
|
return null;
|
2017-03-07 19:27:46 +00:00
|
|
|
} else {
|
|
|
|
return "not enough power";
|
|
|
|
}
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 19:27:46 +00:00
|
|
|
getActionPointsUsage(ship: Ship, target: Target): number {
|
2015-02-26 00:00:00 +00:00
|
|
|
if (target === null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var distance = Target.newFromShip(ship).getDistanceTo(target);
|
2017-04-18 19:51:23 +00:00
|
|
|
return Math.ceil(distance / this.distance_per_power);
|
2015-02-26 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 00:00:00 +00:00
|
|
|
getRangeRadius(ship: Ship): number {
|
2017-04-18 19:51:23 +00:00
|
|
|
return ship.values.power.get() * this.distance_per_power;
|
2015-03-03 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 18:33:56 +00:00
|
|
|
/**
|
|
|
|
* Get the distance that may be traveled with 1 action point
|
|
|
|
*/
|
|
|
|
getDistanceByActionPoint(ship: Ship): number {
|
2017-04-18 19:51:23 +00:00
|
|
|
return this.distance_per_power;
|
2017-01-19 18:33:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 19:27:46 +00:00
|
|
|
checkLocationTarget(ship: Ship, target: Target): Target {
|
2015-04-21 20:14:17 +00:00
|
|
|
// Apply maximal distance
|
2017-01-19 18:33:56 +00:00
|
|
|
var max_distance = this.getRangeRadius(ship);
|
2015-04-21 20:14:17 +00:00
|
|
|
target = target.constraintInRange(ship.arena_x, ship.arena_y, max_distance);
|
|
|
|
|
|
|
|
// Apply collision prevention
|
2017-03-07 19:27:46 +00:00
|
|
|
let battle = ship.getBattle();
|
|
|
|
if (battle) {
|
|
|
|
battle.play_order.forEach((iship: Ship) => {
|
|
|
|
if (iship !== ship) {
|
|
|
|
target = target.moveOutOfCircle(iship.arena_x, iship.arena_y, this.safety_distance,
|
|
|
|
ship.arena_x, ship.arena_y);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-04-21 20:14:17 +00:00
|
|
|
|
|
|
|
return target;
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
2015-01-02 00:00:00 +00:00
|
|
|
|
2017-03-07 19:27:46 +00:00
|
|
|
protected customApply(ship: Ship, target: Target) {
|
2015-01-02 00:00:00 +00:00
|
|
|
ship.moveTo(target.x, target.y);
|
|
|
|
}
|
2017-04-18 22:55:59 +00:00
|
|
|
|
|
|
|
getEffectsDescription(): string {
|
|
|
|
return `Move: ${this.distance_per_power}km per power point`;
|
|
|
|
}
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|