From 3a2f8c9538ef700ea2c94d9a1fd67b489ef3427a Mon Sep 17 00:00:00 2001 From: Evan Date: Sat, 23 Nov 2024 10:13:03 -0800 Subject: [PATCH] have playerexecution check & delete units on death. fixes bug where units weren't being captured when player dies --- TODO.txt | 4 +-- src/core/configuration/DevConfig.ts | 2 +- src/core/execution/PlayerExecution.ts | 39 ++++++++++++++++----------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/TODO.txt b/TODO.txt index f13fdcf64..083216d5d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -190,14 +190,14 @@ * make two nukes: atom & hydrogen DONE 11/20/2024 * NPC builds ports DONE 11/20/2024 * BUG: fix matchmaking DONE 11/22/2024 -* destroyer can capture trade ships +* destroyer can capture trade ships DONE 11/22/2024 +* NPC has relations * make NPC difficult scale better (not just start troops) * add battleship * add defense post * add radiation from nuke * only show units you can build in the build menu * REFACTOR: make TransportShip follow build unit flow -* NPC has relations * use twitter emojis * private game shows how many players joined * optimize sendBoat function diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index d43510abf..700a32ce3 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -4,7 +4,7 @@ import { DefaultConfig } from "./DefaultConfig"; export const devConfig = new class extends DefaultConfig { unitInfo(type: UnitType): UnitInfo { const info = super.unitInfo(type) - info.cost = 100 + info.cost = 0 return info } diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index f754bea90..db7a5535d 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -11,6 +11,7 @@ export class PlayerExecution implements Execution { private config: Config private lastCalc = 0 private mg: MutableGame + private active = true constructor(private playerID: PlayerID) { } @@ -30,8 +31,28 @@ export class PlayerExecution implements Execution { if (ticks < this.config.numSpawnPhaseTurns()) { return } - const popInc = this.config.populationIncreaseRate(this.player) + this.player.units().forEach(u => { + const tileOwner = u.tile().owner() + if (u.info().territoryBound) { + if (tileOwner.isPlayer()) { + if (tileOwner != this.player) { + this.mg.player(tileOwner.id()).captureUnit(u) + } + } else { + u.delete() + } + } + }) + + if (!this.player.isAlive()) { + this.player.units().forEach(u => u.delete()) + this.active = false + return + } + + + const popInc = this.config.populationIncreaseRate(this.player) this.player.addWorkers(popInc * (1 - this.player.targetTroopRatio()))// (1 - this.player.targetTroopRatio())) this.player.addTroops(popInc * this.player.targetTroopRatio()) this.player.addGold(this.config.goldAdditionRate(this.player)) @@ -46,20 +67,6 @@ export class PlayerExecution implements Execution { } } - this.player.units().forEach(u => { - const tileOwner = u.tile().owner() - if (u.info().territoryBound) { - if (tileOwner.isPlayer()) { - if (tileOwner != this.player) { - this.mg.player(tileOwner.id()).captureUnit(u) - } - } else { - u.delete() - } - } - - - }) if (ticks - this.lastCalc > this.ticksPerClusterCalc) { this.lastCalc = ticks @@ -187,6 +194,6 @@ export class PlayerExecution implements Execution { } isActive(): boolean { - return this.player == null || this.player.isAlive() + return this.active } } \ No newline at end of file