better troop addition

This commit is contained in:
evanpelle
2024-08-11 17:28:34 -07:00
parent 1070a5171a
commit 14e7cb2ac9
6 changed files with 16 additions and 8 deletions
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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
+9 -1
View File
@@ -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 {
+1 -1
View File
@@ -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))