From c9c11d23cec8f0f622245354a0653c688e1eb14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 7 Apr 2015 02:00:00 +0200 Subject: [PATCH] Added encounter fleet generation (unbalanced) --- src/app/game/FleetGenerator.ts | 27 +++++++++++++++++++++++++++ src/app/game/GameSession.ts | 3 +++ src/app/game/StarLocation.ts | 5 ++++- src/app/game/ai/AbstractAI.ts | 6 +----- 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 src/app/game/FleetGenerator.ts diff --git a/src/app/game/FleetGenerator.ts b/src/app/game/FleetGenerator.ts new file mode 100644 index 0000000..788173e --- /dev/null +++ b/src/app/game/FleetGenerator.ts @@ -0,0 +1,27 @@ +module SpaceTac.Game { + "use strict"; + + // Generator of balanced ships to form a fleet + export class FleetGenerator { + // Random generator to use + random: RandomGenerator; + + constructor(random: RandomGenerator = new RandomGenerator()) { + this.random = random; + } + + // Generate a fleet of a given level + generate(level: number, player: Player = null, ship_count: number = 3): Fleet { + var fleet = new Fleet(player); + var ship_generator = new ShipGenerator(this.random); + + while (ship_count--) { + var ship = ship_generator.generate(level); + ship.name = "Ship " + ship_count.toString(); + fleet.addShip(ship); + } + + return fleet; + } + } +} diff --git a/src/app/game/GameSession.ts b/src/app/game/GameSession.ts index 9321197..740c946 100644 --- a/src/app/game/GameSession.ts +++ b/src/app/game/GameSession.ts @@ -32,6 +32,8 @@ module SpaceTac.Game { // Generate a real single player game startNewGame(): void { + var fleet_generator = new FleetGenerator(); + this.universe = new Universe(); this.universe.generate(); @@ -40,6 +42,7 @@ module SpaceTac.Game { start_location.encounter = null; this.player = new Game.Player(this.universe); + this.player.fleet = fleet_generator.generate(1, this.player); this.player.fleet.setLocation(start_location); } diff --git a/src/app/game/StarLocation.ts b/src/app/game/StarLocation.ts index d3068c8..4cb86c6 100644 --- a/src/app/game/StarLocation.ts +++ b/src/app/game/StarLocation.ts @@ -57,7 +57,10 @@ module SpaceTac.Game { this.encounter_gen = true; if (random.throw() < 0.8) { - this.encounter = new Fleet(); + var fleet_generator = new FleetGenerator(random); + var ship_count = random.throwInt(1, 5); + this.encounter = fleet_generator.generate(this.star.level, null, ship_count); + this.encounter.player.ai = new AI.BullyAI(this.encounter); } } diff --git a/src/app/game/ai/AbstractAI.ts b/src/app/game/ai/AbstractAI.ts index 0eb6d15..6fab782 100644 --- a/src/app/game/ai/AbstractAI.ts +++ b/src/app/game/ai/AbstractAI.ts @@ -5,9 +5,6 @@ module SpaceTac.Game.AI { // Base class for all Artificial Intelligence interaction export class AbstractAI extends Serializable { - // The battle this AI is involved in - battle: Battle; - // The fleet controlled by this AI fleet: Fleet; @@ -30,7 +27,6 @@ module SpaceTac.Game.AI { super(); this.fleet = fleet; - this.battle = fleet.battle; this.async = true; this.workqueue = []; } @@ -104,7 +100,7 @@ module SpaceTac.Game.AI { } } this.ship = null; - this.battle.advanceToNextShip(); + this.fleet.battle.advanceToNextShip(); } } }