diff --git a/src/core/configuration/Config.ts b/src/core/configuration/Config.ts index 1f0b50bc8..3cb6db002 100644 --- a/src/core/configuration/Config.ts +++ b/src/core/configuration/Config.ts @@ -88,6 +88,7 @@ export interface Config { maxPopulation(player: Player | PlayerView): number; cityPopulationIncrease(): number; boatAttackAmount(attacker: Player, defender: Player | TerraNullius): number; + warshipShellLifetime(): number; boatMaxNumber(): number; allianceDuration(): Tick; allianceRequestCooldown(): Tick; diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index 2bdc9ed02..3330f507e 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -470,6 +470,10 @@ export class DefaultConfig implements Config { return Math.floor(attacker.troops() / 5); } + warshipShellLifetime(): number { + return 20; // in ticks (one tick is 100ms) + } + attackAmount(attacker: Player, defender: Player | TerraNullius) { if (attacker.type() == PlayerType.Bot) { return attacker.troops() / 20; diff --git a/src/core/execution/ShellExecution.ts b/src/core/execution/ShellExecution.ts index 559c0efd2..bbf7f409d 100644 --- a/src/core/execution/ShellExecution.ts +++ b/src/core/execution/ShellExecution.ts @@ -8,6 +8,8 @@ export class ShellExecution implements Execution { private active = true; private pathFinder: PathFinder; private shell: Unit; + private mg: Game; + private destroyAtTick: number = -1; constructor( private spawn: TileRef, @@ -18,6 +20,7 @@ export class ShellExecution implements Execution { init(mg: Game, ticks: number): void { this.pathFinder = PathFinder.Mini(mg, 2000, true, 10); + this.mg = mg; } tick(ticks: number): void { @@ -30,13 +33,19 @@ export class ShellExecution implements Execution { } if ( !this.target.isActive() || - !this.ownerUnit.isActive() || - this.target.owner() == this.shell.owner() + this.target.owner() == this.shell.owner() || + (this.destroyAtTick != -1 && this.mg.ticks() >= this.destroyAtTick) ) { this.shell.delete(false); this.active = false; return; } + + if (this.destroyAtTick == -1 && !this.ownerUnit.isActive()) { + this.destroyAtTick = + this.mg.ticks() + this.mg.config().warshipShellLifetime(); + } + for (let i = 0; i < 3; i++) { const result = this.pathFinder.nextTile( this.shell.tile(),