1
0
Fork 0
spacetac/src/core/ai/Maneuver.ts

54 lines
1.6 KiB
TypeScript
Raw Normal View History

module TS.SpaceTac {
/**
* Ship maneuver for an artifical intelligence
*
* A maneuver is like a human player action, choosing an equipment and using it
*/
2015-03-12 00:00:00 +00:00
export class Maneuver {
// Concerned ship
ship: Ship;
// Equipment to use
equipment: Equipment;
// Target for the action;
target: Target;
// Result of move-fire simulation
simulation: MoveFireResult;
constructor(ship: Ship, equipment: Equipment, target: Target, move_margin = 0.1) {
this.ship = ship;
this.equipment = equipment;
this.target = target;
let simulator = new MoveFireSimulator(this.ship);
2017-03-07 22:16:47 +00:00
this.simulation = simulator.simulateAction(this.equipment.action, this.target, move_margin);
}
/**
* Apply the maneuver in current battle
*/
apply(): void {
if (this.simulation.success) {
2017-03-07 22:16:47 +00:00
this.simulation.parts.filter(part => part.possible).forEach(part => {
if (!part.action.apply(this.ship, part.target)) {
console.error("AI cannot apply maneuver", this, part);
}
});
}
}
/**
* Get the location of the ship after the action
*/
getFinalLocation(): { x: number, y: number } {
if (this.simulation.need_move) {
return this.simulation.move_location;
} else {
return { x: this.ship.arena_x, y: this.ship.arena_y };
}
}
}
}