mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 10:00:44 +00:00
made boats larger, same color as owner
This commit is contained in:
@@ -3,6 +3,8 @@ import {Cell, Game, PlayerEvent, Tile, TileEvent, Player, Execution, BoatEvent}
|
||||
import {Theme} from "../../core/configuration/Config";
|
||||
import {DragEvent, ZoomEvent} from "../InputHandler";
|
||||
import {NameRenderer} from "./NameRenderer";
|
||||
import {manhattanDist} from "../../core/Util";
|
||||
import {PseudoRandom} from "../../core/PseudoRandom";
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +21,7 @@ export class GameRenderer {
|
||||
|
||||
private nameRenderer: NameRenderer;
|
||||
|
||||
private random = new PseudoRandom(123)
|
||||
|
||||
constructor(private gs: Game, private theme: Theme, private canvas: HTMLCanvasElement) {
|
||||
this.context = canvas.getContext("2d")
|
||||
@@ -132,8 +135,26 @@ export class GameRenderer {
|
||||
}
|
||||
|
||||
boatEvent(event: BoatEvent) {
|
||||
this.paintCell(event.boat.tile().cell(), new Colord({r: 255, g: 255, b: 255}))
|
||||
this.gs.neighbors(event.boat.tile()).forEach(t => this.paintTile(t))
|
||||
this.bfs(event.oldTile, 2).forEach(t => this.paintTile(t))
|
||||
|
||||
this.bfs(event.boat.tile(), 2).forEach(t => this.paintCell(t.cell(), this.theme.borderColor(event.boat.owner().id())))
|
||||
this.bfs(event.boat.tile(), 1).forEach(t => this.paintCell(t.cell(), this.theme.territoryColor(event.boat.owner().id())))
|
||||
}
|
||||
|
||||
private bfs(tile: Tile, dist: number): Set<Tile> {
|
||||
const seen = new Set<Tile>
|
||||
const q: Tile[] = []
|
||||
q.push(tile)
|
||||
while (q.length > 0) {
|
||||
const curr = q.pop()
|
||||
seen.add(curr)
|
||||
for (const n of curr.neighbors()) {
|
||||
if (!seen.has(n) && manhattanDist(tile.cell(), n.cell()) <= dist) {
|
||||
q.push(n)
|
||||
}
|
||||
}
|
||||
}
|
||||
return seen
|
||||
}
|
||||
|
||||
resize(width: number, height: number): void {
|
||||
|
||||
+1
-1
@@ -154,5 +154,5 @@ export class PlayerEvent implements GameEvent {
|
||||
}
|
||||
|
||||
export class BoatEvent implements GameEvent {
|
||||
constructor(public readonly boat: Boat) { }
|
||||
constructor(public readonly boat: Boat, public oldTile: Tile) { }
|
||||
}
|
||||
|
||||
@@ -62,8 +62,9 @@ export class BoatImpl implements MutableBoat {
|
||||
) { }
|
||||
|
||||
move(tile: Tile): void {
|
||||
const oldTile = this._tile
|
||||
this._tile = tile
|
||||
this.g.fireBoatUpdateEvent(this)
|
||||
this.g.fireBoatUpdateEvent(this, oldTile)
|
||||
}
|
||||
setTroops(troops: number): void {
|
||||
this._troops = troops
|
||||
@@ -95,12 +96,15 @@ export class PlayerImpl implements MutablePlayer {
|
||||
addBoat(troops: number, tile: Tile, target: Player | TerraNullius): BoatImpl {
|
||||
const b = new BoatImpl(this.gs, tile, troops, this, target as PlayerImpl | TerraNulliusImpl)
|
||||
this._boats.push(b)
|
||||
this.gs.fireBoatUpdateEvent(b)
|
||||
this.gs.fireBoatUpdateEvent(b, b.tile())
|
||||
return b
|
||||
}
|
||||
|
||||
boats(): BoatImpl[] {
|
||||
return this._boats
|
||||
|
||||
}
|
||||
|
||||
sharesBorderWith(other: Player | TerraNullius): boolean {
|
||||
for (const border of this._borderTileSet) {
|
||||
for (const neighbor of border.neighbors()) {
|
||||
@@ -400,8 +404,8 @@ export class GameImpl implements MutableGame {
|
||||
return false
|
||||
}
|
||||
|
||||
public fireBoatUpdateEvent(boat: Boat) {
|
||||
this.eventBus.emit(new BoatEvent(boat))
|
||||
public fireBoatUpdateEvent(boat: Boat, oldTile: Tile) {
|
||||
this.eventBus.emit(new BoatEvent(boat, oldTile))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -60,7 +60,7 @@ export class BoatAttackExecution implements Execution {
|
||||
return
|
||||
}
|
||||
this.aStarPre = new AStar(this.src, this.dst)
|
||||
this.aStarPre.compute(10000)
|
||||
this.aStarPre.compute(10)
|
||||
this.path = this.aStarPre.reconstructPath()
|
||||
if (this.path != null) {
|
||||
console.log(`got path ${this.path.map(t => t.cell().toString())}`)
|
||||
|
||||
Reference in New Issue
Block a user