2017-02-09 00:26:04 +00:00
|
|
|
module TS.SpaceTac {
|
2017-02-27 00:42:12 +00:00
|
|
|
/**
|
|
|
|
* 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 {
|
2015-03-12 00:00:00 +00:00
|
|
|
// Concerned ship
|
|
|
|
ship: Ship;
|
|
|
|
|
|
|
|
// Equipment to use
|
|
|
|
equipment: Equipment;
|
|
|
|
|
|
|
|
// Target for the action;
|
|
|
|
target: Target;
|
|
|
|
|
2017-02-27 00:42:12 +00:00
|
|
|
// Result of move-fire simulation
|
|
|
|
simulation: MoveFireResult;
|
|
|
|
|
2015-03-12 00:00:00 +00:00
|
|
|
constructor(ship: Ship, equipment: Equipment, target: Target) {
|
|
|
|
this.ship = ship;
|
|
|
|
this.equipment = equipment;
|
|
|
|
this.target = target;
|
2017-02-27 00:42:12 +00:00
|
|
|
|
|
|
|
let simulator = new MoveFireSimulator(this.ship);
|
|
|
|
this.simulation = simulator.simulateAction(this.equipment.action, this.target);
|
2015-03-12 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-02-27 00:42:12 +00:00
|
|
|
/**
|
|
|
|
* Apply the maneuver in current battle
|
|
|
|
*/
|
2015-03-12 00:00:00 +00:00
|
|
|
apply(): void {
|
2017-02-27 00:42:12 +00:00
|
|
|
if (this.simulation.success) {
|
|
|
|
this.simulation.parts.forEach(part => {
|
2017-03-07 19:27:46 +00:00
|
|
|
if (!part.action.apply(this.ship, part.target)) {
|
|
|
|
console.error("AI cannot apply maneuver", this, part);
|
2017-02-27 00:42:12 +00:00
|
|
|
}
|
|
|
|
});
|
2017-02-22 01:14:14 +00:00
|
|
|
}
|
2015-03-12 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|