This commit is contained in:
evanpelle
2024-08-10 20:10:28 -07:00
parent dd94bb4c65
commit 13808f4d70
8 changed files with 24 additions and 24 deletions
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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[]
+11 -11
View File
@@ -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))
}
+1 -1
View File
@@ -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
+6 -6
View File
@@ -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))
}
}
// }
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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) {