mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-17 07:12:10 +00:00
thread_split: enable spawn highlight
This commit is contained in:
@@ -68,7 +68,7 @@ export class GameRunner {
|
||||
this.currTurn++
|
||||
this.game.executeNextTick()
|
||||
|
||||
if (this.game.ticks() % 10 == 0) {
|
||||
if (this.game.inSpawnPhase() || this.game.ticks() % 10 == 0) {
|
||||
this.game.players()
|
||||
.forEach(p => this.playerToName.set(p.id(), placeName(this.game, p)))
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export class DevConfig extends DefaultConfig {
|
||||
}
|
||||
|
||||
numSpawnPhaseTurns(): number {
|
||||
return this.gameConfig().gameType == GameType.Singleplayer ? 40 : 200
|
||||
return this.gameConfig().gameType == GameType.Singleplayer ? 400 : 200
|
||||
// return 100
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Cell, Execution, MutableGame, MutablePlayer, PlayerInfo, PlayerType } from "../game/Game"
|
||||
import { BotExecution } from "./BotExecution"
|
||||
import { PlayerExecution } from "./PlayerExecution"
|
||||
import { getSpawnCells } from "./Util"
|
||||
import { getSpawnTiles } from "./Util"
|
||||
|
||||
export class SpawnExecution implements Execution {
|
||||
|
||||
@@ -25,17 +25,18 @@ export class SpawnExecution implements Execution {
|
||||
}
|
||||
|
||||
const existing = this.mg.players().find(p => p.id() == this.playerInfo.id)
|
||||
const tile = this.mg.tile(this.cell)
|
||||
if (existing) {
|
||||
existing.tiles().forEach(t => existing.relinquish(t))
|
||||
getSpawnCells(this.mg, this.cell).forEach(c => {
|
||||
existing.conquer(this.mg.tile(c))
|
||||
getSpawnTiles(tile).forEach(t => {
|
||||
existing.conquer(t)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const player = this.mg.addPlayer(this.playerInfo, this.mg.config().startManpower(this.playerInfo))
|
||||
getSpawnCells(this.mg, this.cell).forEach(c => {
|
||||
player.conquer(this.mg.tile(c))
|
||||
getSpawnTiles(tile).forEach(t => {
|
||||
player.conquer(t)
|
||||
})
|
||||
this.mg.addExecution(new PlayerExecution(player.id()))
|
||||
if (player.type() == PlayerType.Bot) {
|
||||
|
||||
@@ -1,27 +1,10 @@
|
||||
import { Game, Cell, Tile } from "../game/Game";
|
||||
import { and, bfs, euclDist } from "../Util";
|
||||
|
||||
|
||||
export function getSpawnCells(gs: Game, cell: Cell): Cell[] {
|
||||
let result: Cell[] = [];
|
||||
for (let dx = -2; dx <= 2; dx++) {
|
||||
for (let dy = -2; dy <= 2; dy++) {
|
||||
let c = new Cell(cell.x + dx, cell.y + dy);
|
||||
if (!gs.isOnMap(c)) {
|
||||
continue;
|
||||
}
|
||||
if (Math.abs(dx) === 2 && Math.abs(dy) === 2) {
|
||||
continue;
|
||||
}
|
||||
if (gs.tile(c).terrain().isWater()) {
|
||||
continue;
|
||||
}
|
||||
if (gs.tile(c).hasOwner()) {
|
||||
continue;
|
||||
}
|
||||
result.push(c);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
export function getSpawnTiles(tile: Tile): Tile[] {
|
||||
return Array.from(bfs(tile, euclDist(tile, 4)))
|
||||
.filter(t => !t.hasOwner() && t.terrain().isLand())
|
||||
}
|
||||
|
||||
export function closestTwoTiles(x: Iterable<Tile>, y: Iterable<Tile>): { x: Tile, y: Tile } {
|
||||
|
||||
@@ -332,6 +332,9 @@ export class GameImpl implements MutableGame {
|
||||
}
|
||||
|
||||
conquer(owner: PlayerImpl, tile: Tile): void {
|
||||
if (!tile.terrain().isLand()) {
|
||||
throw Error(`cannot conquer water`)
|
||||
}
|
||||
const tileImpl = tile as TileImpl
|
||||
let previousOwner = tileImpl._owner
|
||||
if (previousOwner.isPlayer()) {
|
||||
|
||||
Reference in New Issue
Block a user