diff --git a/TODO.txt b/TODO.txt index ae4cdf091..a8d100545 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,8 +1,8 @@ * fix conquer expansion DONE * perf improvements on graphics (only draw images to canvas on ticks) DONE * double join lobby bug DONE -* render player info efficiently -* better troop addition logic +* render player info efficiently DONE 8/11/2024 +* better troop addition logic DONE 8/11/2024 * better expansion, add back directed expansion * use pastel theme for territories * improve front page diff --git a/src/client/ClientGame.ts b/src/client/ClientGame.ts index 1c0b32534..652a2bb97 100644 --- a/src/client/ClientGame.ts +++ b/src/client/ClientGame.ts @@ -204,7 +204,7 @@ export class ClientGame { type: "attack", attackerID: this.myPlayer.id(), targetID: targetID, - troops: 2000, + troops: this.myPlayer.troops() / 5, targetX: cell.x, targetY: cell.y } diff --git a/src/core/Game.ts b/src/core/Game.ts index a06a5bb7f..666aa7d3c 100644 --- a/src/core/Game.ts +++ b/src/core/Game.ts @@ -137,7 +137,7 @@ export interface Game { export interface MutableGame extends Game { player(id: PlayerID): MutablePlayer players(): MutablePlayer[] - addPlayer(playerInfo: PlayerInfo): MutablePlayer + addPlayer(playerInfo: PlayerInfo, troops: number): MutablePlayer executions(): Execution[] removeInactiveExecutions(): void removeExecution(exec: Execution) diff --git a/src/core/GameImpl.ts b/src/core/GameImpl.ts index d25e642a8..1e455c193 100644 --- a/src/core/GameImpl.ts +++ b/src/core/GameImpl.ts @@ -256,10 +256,10 @@ export class GameImpl implements MutableGame { return this.player(id) } - addPlayer(playerInfo: PlayerInfo): MutablePlayer { + addPlayer(playerInfo: PlayerInfo, troops: number): MutablePlayer { let id = this.idCounter this.idCounter++ - let player = new PlayerImpl(this, id, playerInfo, 10000) + let player = new PlayerImpl(this, id, playerInfo, troops) this._players.set(id, player) this.eventBus.emit(new PlayerEvent(player)) return player diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index 4efe5638f..6d1738b82 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -12,7 +12,15 @@ export class PlayerExecution implements Execution { } tick(ticks: number) { - this.player.addTroops(Math.sqrt(this.player.numTilesOwned() * this.player.troops() + 1000) / 1000) + let toAdd = Math.sqrt(this.player.numTilesOwned() * this.player.troops()) / 5 + + const max = Math.sqrt(this.player.numTilesOwned()) * 100 + 1000 + const ratio = 1 - this.player.troops() / max + toAdd *= ratio * ratio * ratio + this.player.addTroops( + Math.max(2, toAdd) + ); + this.player.setTroops(Math.min(this.player.troops(), max)) } owner(): MutablePlayer { diff --git a/src/core/execution/SpawnExecution.ts b/src/core/execution/SpawnExecution.ts index 8ad41e27f..4f7a52859 100644 --- a/src/core/execution/SpawnExecution.ts +++ b/src/core/execution/SpawnExecution.ts @@ -22,7 +22,7 @@ export class SpawnExecution implements Execution { if (!this.isActive()) { return } - const player = this.gs.addPlayer(this.playerInfo) + const player = this.gs.addPlayer(this.playerInfo, 1000) getSpawnCells(this.gs, this.cell).forEach(c => { console.log('conquering cell') player.conquer(this.gs.tile(c))