mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-06 03:05:12 +00:00
builds
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { utcDay } from "d3";
|
||||
import { placeName } from "../client/graphics/NameBoxCalculator";
|
||||
import { getConfig } from "./configuration/Config";
|
||||
import { EventBus } from "./EventBus";
|
||||
import { Executor } from "./execution/ExecutionManager";
|
||||
import { WinCheckExecution } from "./execution/WinCheckExecution";
|
||||
import { Cell, DisplayMessageEvent, Game, MessageType, MutableGame, MutableTile, Player, PlayerID, Tile, UnitType } from "./game/Game";
|
||||
import { Cell, DisplayMessageUpdate, Game, GameUpdateType, MessageType, MutableGame, MutableTile, Player, PlayerID, Tile, UnitType } from "./game/Game";
|
||||
import { createGame } from "./game/GameImpl";
|
||||
import { loadTerrainMap } from "./game/TerrainMapLoader";
|
||||
import { GameUpdateViewData, NameViewData, packTileData, PlayerActions, PlayerViewData } from "./GameView";
|
||||
@@ -20,7 +21,6 @@ export async function createGameRunner(gameID: string, gameConfig: GameConfig, c
|
||||
}
|
||||
|
||||
export class GameRunner {
|
||||
private updatedTiles: Set<MutableTile> = new Set()
|
||||
private tickInterval = null
|
||||
private turns: Turn[] = []
|
||||
private currTurn = 0
|
||||
@@ -56,12 +56,11 @@ export class GameRunner {
|
||||
return
|
||||
}
|
||||
this.isExecuting = true
|
||||
this.updatedTiles.clear()
|
||||
|
||||
|
||||
this.game.addExecution(...this.execManager.createExecs(this.turns[this.currTurn]))
|
||||
this.currTurn++
|
||||
this.game.executeNextTick()
|
||||
const updates = this.game.executeNextTick()
|
||||
|
||||
if (this.game.inSpawnPhase() || this.game.ticks() % 10 == 0) {
|
||||
this.game.players()
|
||||
@@ -78,7 +77,7 @@ export class GameRunner {
|
||||
this.callBack({
|
||||
tick: this.game.ticks(),
|
||||
units: this.game.units().map(u => u.toViewData()),
|
||||
packedTileUpdates: Array.from(this.updatedTiles).map(t => packTileData(t.toViewData())),
|
||||
packedTileUpdates: updates.filter(u => u.type == GameUpdateType.Tile).map(u => packTileData(u)),
|
||||
players: playerViewData
|
||||
})
|
||||
this.isExecuting = false
|
||||
|
||||
+18
-15
@@ -1,4 +1,4 @@
|
||||
import { MessageType, Player, Tile, Unit } from './game/Game';
|
||||
import { GameUpdateType, MessageType, Player, Tile, TileUpdate, Unit } from './game/Game';
|
||||
import { Config } from "./configuration/Config";
|
||||
import { Alliance, AllianceRequest, AllPlayers, Cell, DefenseBonus, EmojiMessage, Execution, ExecutionView, Game, Gold, MutableTile, Nation, PlayerID, PlayerInfo, PlayerType, Relation, TerrainMap, TerrainTile, TerrainType, TerraNullius, Tick, UnitInfo, UnitType } from "./game/Game";
|
||||
import { ClientID } from "./Schemas";
|
||||
@@ -24,7 +24,7 @@ export interface TileViewData extends ViewData<TileViewData> {
|
||||
|
||||
export class TileView {
|
||||
|
||||
constructor(private game: GameView, public data: TileViewData, private _terrain: TerrainTile) { }
|
||||
constructor(private game: GameView, public data: TileUpdate, private _terrain: TerrainTile) { }
|
||||
|
||||
type(): TerrainType {
|
||||
return this._terrain.type()
|
||||
@@ -33,10 +33,10 @@ export class TileView {
|
||||
if (!this.hasOwner()) {
|
||||
return new TerraNulliusImpl()
|
||||
}
|
||||
return this.game.playerBySmallID(this.data?.smallID)
|
||||
return this.game.playerBySmallID(this.data?.ownerID)
|
||||
}
|
||||
hasOwner(): boolean {
|
||||
return this.data?.smallID !== undefined && this.data.smallID !== 0;
|
||||
return this.data?.ownerID !== undefined && this.data.ownerID !== 0;
|
||||
}
|
||||
isBorder(): boolean {
|
||||
return this.data?.isBorder
|
||||
@@ -276,7 +276,7 @@ export interface GameUpdateViewData extends ViewData<GameUpdateViewData> {
|
||||
tick: number
|
||||
units: UnitViewData[]
|
||||
players: Record<PlayerID, PlayerViewData>
|
||||
tileUpdates?: TileViewData[]
|
||||
tileUpdates?: TileUpdate[]
|
||||
packedTileUpdates: Uint16Array[]
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ export class GameView {
|
||||
this.lastUpdate = gu
|
||||
this.lastUpdate.tileUpdates = this.lastUpdate.packedTileUpdates.map(tu => unpackTileData(tu))
|
||||
this.lastUpdate.tileUpdates.forEach(tu => {
|
||||
this.tiles[tu.x][tu.y].data = tu
|
||||
this.tiles[tu.pos.x][tu.pos.y].data = tu
|
||||
})
|
||||
Object.entries(gu.players).forEach(([key, value]) => {
|
||||
this.smallIDToID.set(value.smallID, key);
|
||||
@@ -330,7 +330,7 @@ export class GameView {
|
||||
}
|
||||
|
||||
recentlyUpdatedTiles(): TileView[] {
|
||||
return this.lastUpdate.tileUpdates.filter(d => true).map(tu => new TileView(this, tu, this._terrainMap.terrain(new Cell(tu.x, tu.y))))
|
||||
return this.lastUpdate.tileUpdates.map(tu => new TileView(this, tu, this._terrainMap.terrain(new Cell(tu.pos.x, tu.pos.y))))
|
||||
}
|
||||
|
||||
player(id: PlayerID): PlayerView {
|
||||
@@ -404,11 +404,11 @@ export class GameView {
|
||||
}
|
||||
}
|
||||
|
||||
export function packTileData(tile: TileViewData): Uint16Array {
|
||||
export function packTileData(tile: TileUpdate): Uint16Array {
|
||||
const packed = new Uint16Array(4);
|
||||
packed[0] = tile.x;
|
||||
packed[1] = tile.y;
|
||||
packed[2] = tile.smallID;
|
||||
packed[0] = tile.pos.x;
|
||||
packed[1] = tile.pos.y;
|
||||
packed[2] = tile.ownerID;
|
||||
|
||||
// Pack booleans into bits
|
||||
packed[3] = (tile.hasFallout ? 1 : 0) |
|
||||
@@ -418,11 +418,14 @@ export function packTileData(tile: TileViewData): Uint16Array {
|
||||
return packed;
|
||||
}
|
||||
|
||||
export function unpackTileData(packed: Uint16Array): TileViewData {
|
||||
export function unpackTileData(packed: Uint16Array): TileUpdate {
|
||||
return {
|
||||
x: packed[0],
|
||||
y: packed[1],
|
||||
smallID: packed[2],
|
||||
type: GameUpdateType.Tile,
|
||||
pos: {
|
||||
x: packed[0],
|
||||
y: packed[1],
|
||||
},
|
||||
ownerID: packed[2],
|
||||
hasFallout: !!(packed[3] & 1),
|
||||
hasDefenseBonus: !!(packed[3] & 2),
|
||||
isBorder: !!(packed[3] & 4),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Unit, Cell, Execution, MutableUnit, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile, UnitType, TerrainType } from "../game/Game";
|
||||
import { Unit, Cell, Execution, MutableUnit, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile, UnitType, TerrainType } from "../game/Game";
|
||||
import { and, bfs, manhattanDistWrapped, sourceDstOceanShore, targetTransportTile } from "../Util";
|
||||
import { AttackExecution } from "./AttackExecution";
|
||||
import { MessageType } from '../game/Game';
|
||||
import { DisplayMessageEvent } from '../game/Game';
|
||||
import { DisplayMessageUpdate } from '../game/Game';
|
||||
import { PathFinder } from "../pathfinding/PathFinding";
|
||||
import { PathFindResultType } from "../pathfinding/AStar";
|
||||
import { SerialAStar } from "../pathfinding/SerialAStar";
|
||||
|
||||
@@ -344,7 +344,7 @@ export interface Game {
|
||||
forEachTile(fn: (tile: Tile) => void): void
|
||||
executions(): ExecutionView[]
|
||||
terraNullius(): TerraNullius
|
||||
executeNextTick(): void
|
||||
executeNextTick(): GameUpdate[]
|
||||
ticks(): Tick
|
||||
inSpawnPhase(): boolean
|
||||
addExecution(...exec: Execution[]): void
|
||||
@@ -391,17 +391,16 @@ export type GameUpdate = TileUpdate
|
||||
| AllianceRequestReplyUpdate
|
||||
| BrokeAllianceUpdate
|
||||
| AllianceExpiredUpdate
|
||||
| DisplayMessageEvent
|
||||
| DisplayMessageUpdate
|
||||
| TargetPlayerUpdate
|
||||
| EmojiUpdate
|
||||
| WinUpdate
|
||||
|
||||
export interface TileUpdate {
|
||||
type: GameUpdateType.Tile
|
||||
owner: number
|
||||
ownerID: number
|
||||
pos: MapPos
|
||||
isBorder: boolean
|
||||
borderOnlyChange: boolean
|
||||
hasFallout: boolean
|
||||
hasDefenseBonus: boolean
|
||||
}
|
||||
@@ -457,7 +456,7 @@ export interface EmojiUpdate {
|
||||
createdAt: Tick
|
||||
}
|
||||
|
||||
export interface DisplayMessageEvent {
|
||||
export interface DisplayMessageUpdate {
|
||||
type: GameUpdateType.DisplayEvent
|
||||
message: string
|
||||
messageType: MessageType
|
||||
|
||||
@@ -79,7 +79,7 @@ export class GameImpl implements MutableGame {
|
||||
throw Error(`cannot set fallout, tile ${tile} has owner`)
|
||||
}
|
||||
ti._hasFallout = true
|
||||
this.updates.push(ti.toUpdate(false))
|
||||
this.updates.push(ti.toUpdate())
|
||||
}
|
||||
|
||||
addTileDefenseBonus(tile: Tile, unit: Unit, amount: number): DefenseBonus {
|
||||
@@ -164,7 +164,8 @@ export class GameImpl implements MutableGame {
|
||||
return this._ticks
|
||||
}
|
||||
|
||||
executeNextTick() {
|
||||
executeNextTick(): GameUpdate[] {
|
||||
this.updates = []
|
||||
this.execs.forEach(e => {
|
||||
if (e.isActive() && (!this.inSpawnPhase() || e.activeDuringSpawnPhase())) {
|
||||
e.tick(this._ticks)
|
||||
@@ -193,6 +194,7 @@ export class GameImpl implements MutableGame {
|
||||
})
|
||||
consolex.log(`tick ${this._ticks}: hash ${hash}`)
|
||||
}
|
||||
return this.updates
|
||||
}
|
||||
|
||||
terraNullius(): TerraNullius {
|
||||
@@ -386,7 +388,6 @@ export class GameImpl implements MutableGame {
|
||||
tile.neighbors().forEach(t => tiles.push(t as TileImpl))
|
||||
|
||||
for (const t of tiles) {
|
||||
this.updates.push(t.toUpdate(true))
|
||||
if (!t.hasOwner()) {
|
||||
t._isBorder = false
|
||||
continue
|
||||
@@ -398,6 +399,7 @@ export class GameImpl implements MutableGame {
|
||||
(t.owner() as PlayerImpl)._borderTiles.delete(t);
|
||||
t._isBorder = false
|
||||
}
|
||||
this.updates.push(t.toUpdate())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,18 +27,17 @@ export class TileImpl implements MutableTile {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
toUpdate(borderOnlyChange: boolean = false): TileUpdate {
|
||||
toUpdate(): TileUpdate {
|
||||
return {
|
||||
type: GameUpdateType.Tile,
|
||||
pos: {
|
||||
x: this._cell.x,
|
||||
y: this._cell.y
|
||||
},
|
||||
owner: this._owner.isPlayer() ? this._owner.smallID() : 0,
|
||||
ownerID: this._owner.isPlayer() ? this._owner.smallID() : 0,
|
||||
hasFallout: this._hasFallout,
|
||||
hasDefenseBonus: this.hasDefenseBonus(),
|
||||
isBorder: this.isBorder(),
|
||||
borderOnlyChange: borderOnlyChange
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user