From 13808f4d706bceed1ed68d89557cad93d34626a2 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Sat, 10 Aug 2024 20:10:28 -0700 Subject: [PATCH] working --- TODO.txt | 4 ++-- src/core/Game.ts | 2 +- src/core/GameImpl.ts | 22 +++++++++++----------- src/core/Settings.ts | 2 +- src/core/execution/AttackExecution.ts | 12 ++++++------ src/core/execution/BoatAttackExecution.ts | 2 +- src/core/execution/PlayerExecution.ts | 2 +- src/core/execution/SpawnExecution.ts | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/TODO.txt b/TODO.txt index 3185e01b6..b928d66c7 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,11 +1,11 @@ * fix conquer expansion DONE * perf improvements on graphics (only draw images to canvas on ticks) DONE * double join lobby bug +* render player info efficiently * better troop addition logic -* use draw rect instead of image data +* use draw rect instead of image data ? * improve front page * make boats larger -* maybe cache neigbors? * have boats not get close to shore * better algorithm for name render placement * re-enable directed expansion \ No newline at end of file diff --git a/src/core/Game.ts b/src/core/Game.ts index 1a119b936..a06a5bb7f 100644 --- a/src/core/Game.ts +++ b/src/core/Game.ts @@ -111,7 +111,7 @@ export interface MutablePlayer extends Player { setTroops(troops: number): void addTroops(troops: number): void removeTroops(troops: number): void - conquer(cell: Cell): void + conquer(tile: Tile): void executions(): Execution[] neighbors(): (MutablePlayer | TerraNullius)[] boats(): MutableBoat[] diff --git a/src/core/GameImpl.ts b/src/core/GameImpl.ts index ca97c6ad2..d25e642a8 100644 --- a/src/core/GameImpl.ts +++ b/src/core/GameImpl.ts @@ -128,7 +128,7 @@ export class PlayerImpl implements MutablePlayer { isPlayer(): this is MutablePlayer {return true as const} ownsTile(cell: Cell): boolean {return this.tiles.has(cell.toString())} setTroops(troops: number) {this._troops = troops} - conquer(cell: Cell) {this.gs.conquer(this, cell)} + conquer(tile: Tile) {this.gs.conquer(this, tile)} info(): PlayerInfo {return this.playerInfo} id(): PlayerID {return this._id} troops(): number {return this._troops} @@ -310,26 +310,26 @@ export class GameImpl implements MutableGame { } } - conquer(owner: PlayerImpl, cell: Cell): void { - if (owner.ownsTile(cell)) { - throw new Error(`Player ${owner} already owns cell ${cell.toString()}`) + conquer(owner: PlayerImpl, tile: Tile): void { + if (tile.owner() == owner) { + throw new Error(`Player ${owner} already owns cell ${tile.cell().toString()}`) } if (!owner.isPlayer()) { throw new Error("Must be a player") } - let tile = this.tile(cell) as TileImpl if (tile.terrain() == TerrainTypes.Water) { throw new Error("Cannot conquer water") } - let previousOwner = tile._owner + const tileImpl = tile as TileImpl + let previousOwner = tileImpl._owner if (previousOwner.isPlayer()) { - previousOwner.tiles.delete(cell.toString()) - previousOwner._borderTiles.delete(cell.toString()) + previousOwner.tiles.delete(tile.cell().toString()) + previousOwner._borderTiles.delete(tile.cell().toString()) previousOwner._borderTileSet.delete(tile) - tile._isBorder = false + tileImpl._isBorder = false } - tile._owner = owner - owner.tiles.set(cell.toString(), tile) + tileImpl._owner = owner + owner.tiles.set(tile.cell().toString(), tile) this.updateBorders(tile) this.eventBus.emit(new TileEvent(tile)) } diff --git a/src/core/Settings.ts b/src/core/Settings.ts index 88359276a..ea606fc58 100644 --- a/src/core/Settings.ts +++ b/src/core/Settings.ts @@ -25,7 +25,7 @@ export const defaultSettings = new class implements Settings { return 1 } turnIntervalMs(): number { - return 1000 / 5 + return 100 } lobbyCreationRate(): number { return 5 * 1000 diff --git a/src/core/execution/AttackExecution.ts b/src/core/execution/AttackExecution.ts index 5abed3e12..6970c78af 100644 --- a/src/core/execution/AttackExecution.ts +++ b/src/core/execution/AttackExecution.ts @@ -65,7 +65,7 @@ export class AttackExecution implements Execution { if (tileToConquer.owner() != this.target || !onBorder) { continue } - this._owner.conquer(tileToConquer.cell()) + this._owner.conquer(tileToConquer) this.troops -= 1 numTilesPerTick -= 1 } @@ -126,11 +126,11 @@ export class AttackExecution implements Execution { if (neighbor.terrain() == TerrainTypes.Water || neighbor.owner() != this.target) { continue } - // const numOwnedByMe = tile.neighbors() - // .filter(t => t.terrain() == TerrainTypes.Land) - // .filter(t => t.owner() == this._owner) - // .length - this.toConquer.add(new TileContainer(neighbor, 1)) + const numOwnedByMe = tile.neighbors() + .filter(t => t.terrain() == TerrainTypes.Land) + .filter(t => t.owner() == this._owner) + .length + this.toConquer.add(new TileContainer(neighbor, -numOwnedByMe)) } } // } diff --git a/src/core/execution/BoatAttackExecution.ts b/src/core/execution/BoatAttackExecution.ts index 5f8307933..c00bb0f55 100644 --- a/src/core/execution/BoatAttackExecution.ts +++ b/src/core/execution/BoatAttackExecution.ts @@ -73,7 +73,7 @@ export class BoatAttackExecution implements Execution { this.active = false return } - this.attacker.conquer(this.dst.cell()) + this.attacker.conquer(this.dst) this.mg.addExecution(new AttackExecution(this.troops, this.attacker.id(), this.targetID, null)) this.active = false return diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index 4efe5638f..671a08824 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -12,7 +12,7 @@ export class PlayerExecution implements Execution { } tick(ticks: number) { - this.player.addTroops(Math.sqrt(this.player.numTilesOwned() * this.player.troops() + 1000) / 1000) + this.player.addTroops(Math.sqrt(this.player.numTilesOwned() * this.player.troops() + 1000) / 1000 + 100) } owner(): MutablePlayer { diff --git a/src/core/execution/SpawnExecution.ts b/src/core/execution/SpawnExecution.ts index e4f43ea0a..8ad41e27f 100644 --- a/src/core/execution/SpawnExecution.ts +++ b/src/core/execution/SpawnExecution.ts @@ -25,7 +25,7 @@ export class SpawnExecution implements Execution { const player = this.gs.addPlayer(this.playerInfo) getSpawnCells(this.gs, this.cell).forEach(c => { console.log('conquering cell') - player.conquer(c) + player.conquer(this.gs.tile(c)) }) this.gs.addExecution(new PlayerExecution(player.id())) if (player.info().isBot) {