mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 12:00:44 +00:00
thread_split: enable spawn highlight
This commit is contained in:
@@ -37,8 +37,8 @@ export function placeName(game: Game, player: Player): NameViewData {
|
||||
center = new Cell(center.x, center.y - fontSize / 3)
|
||||
|
||||
return {
|
||||
x: center.x,
|
||||
y: center.y,
|
||||
x: Math.ceil(center.x),
|
||||
y: Math.ceil(center.y),
|
||||
size: fontSize,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,9 @@ import { colord, Colord } from "colord";
|
||||
import { bfs, dist, euclDist, euclideanDist } from "../../../core/Util";
|
||||
import { Theme } from "../../../core/configuration/Config";
|
||||
import { Layer } from "./Layer";
|
||||
import { TransformHandler } from "../TransformHandler";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
import { initRemoteSender } from "../../../core/Consolex";
|
||||
import { AlternateViewEvent, DragEvent, MouseDownEvent } from "../../InputHandler";
|
||||
import { GameView } from "../../../core/GameView";
|
||||
import { GameView, PlayerView } from "../../../core/GameView";
|
||||
|
||||
export class TerritoryLayer implements Layer {
|
||||
private canvas: HTMLCanvasElement
|
||||
@@ -42,7 +40,7 @@ export class TerritoryLayer implements Layer {
|
||||
|
||||
tick() {
|
||||
this.game.recentlyUpdatedTiles()
|
||||
.forEach(t => this.enqueue(t))
|
||||
.forEach(t => this.enqueueTile(t))
|
||||
|
||||
|
||||
if (!this.game.inSpawnPhase()) {
|
||||
@@ -53,24 +51,27 @@ export class TerritoryLayer implements Layer {
|
||||
}
|
||||
|
||||
this.highlightContext.clearRect(0, 0, this.game.width(), this.game.height());
|
||||
const humans = this.game.players()
|
||||
const humans = this.game.playerViews()
|
||||
.filter(p => p.type() == PlayerType.Human)
|
||||
|
||||
const alreadyPainted = new Set<Tile>()
|
||||
for (const human of humans) {
|
||||
for (const borderTile of human.borderTiles()) {
|
||||
for (const neighbor of bfs(borderTile, euclDist(borderTile, 5))) {
|
||||
if (!neighbor.hasOwner() && !alreadyPainted.has(neighbor)) {
|
||||
this.paintHighlightCell(neighbor.cell(), this.theme.spawnHighlightColor(), 120)
|
||||
alreadyPainted.add(neighbor)
|
||||
}
|
||||
const center = human.nameLocation()
|
||||
if (!center) {
|
||||
continue
|
||||
}
|
||||
const centerTile = this.game.tile(new Cell(center.x, center.y))
|
||||
if (!centerTile) {
|
||||
continue
|
||||
}
|
||||
for (const tile of bfs(centerTile, euclDist(centerTile, 9))) {
|
||||
if (!tile.hasOwner()) {
|
||||
this.paintHighlightCell(tile.cell(), this.theme.spawnHighlightColor(), 255)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
this.eventBus.on(TileEvent, e => this.tileUpdate(e))
|
||||
this.eventBus.on(AlternateViewEvent, e => { this.alternativeView = e.alternateView })
|
||||
this.eventBus.on(DragEvent, e => { this.lastDragTime = Date.now() })
|
||||
this.redraw()
|
||||
@@ -203,28 +204,13 @@ export class TerritoryLayer implements Layer {
|
||||
dist(event.unit.tile(), this.game.config().defensePostRange())
|
||||
).forEach(t => {
|
||||
if (t.isBorder()) {
|
||||
this.enqueue(t)
|
||||
this.enqueueTile(t)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
tileUpdate(event: TileEvent) {
|
||||
this.enqueue(event.tile)
|
||||
// if (this.game.inSpawnPhase()) {
|
||||
// if (event.tile.owner().isPlayer()) {
|
||||
// for (const border of (event.tile.owner() as Player).borderTiles()) {
|
||||
// for (const neighbor of border.neighbors()) {
|
||||
// if (!neighbor.hasOwner()) {
|
||||
// this.paintHighlightCell(neighbor.cell(), this.theme.spawnHighlightColor(), 255)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
enqueue(tile: Tile) {
|
||||
enqueueTile(tile: Tile) {
|
||||
this.tileToRenderQueue.push({ tile: tile, lastUpdate: this.game.ticks() + this.random.nextFloat(0, .5) })
|
||||
}
|
||||
|
||||
|
||||
@@ -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