mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 12:00:44 +00:00
expanded terrain type enums
This commit is contained in:
+9
-1
@@ -18,6 +18,14 @@ export class Cell {
|
||||
toString(): string {return this.strRepr}
|
||||
}
|
||||
|
||||
export enum TerrainType {
|
||||
Plains,
|
||||
Highland,
|
||||
Mountain,
|
||||
Lake,
|
||||
Ocean
|
||||
}
|
||||
|
||||
export interface ExecutionView {
|
||||
isActive(): boolean
|
||||
owner(): Player
|
||||
@@ -48,6 +56,7 @@ export interface Tile {
|
||||
isShorelineWater(): boolean
|
||||
isOcean(): boolean
|
||||
isLake(): boolean
|
||||
terrain(): TerrainType
|
||||
magnitude(): number
|
||||
owner(): Player | TerraNullius
|
||||
hasOwner(): boolean
|
||||
@@ -55,7 +64,6 @@ export interface Tile {
|
||||
borders(other: Player | TerraNullius): boolean
|
||||
isInterior(): boolean
|
||||
cell(): Cell
|
||||
game(): Game
|
||||
neighbors(): Tile[]
|
||||
neighborsWrapped(): Tile[]
|
||||
onShore(): boolean
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {Config} from "./configuration/Config";
|
||||
import {EventBus} from "./EventBus";
|
||||
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, MutableBoat, BoatEvent} from "./Game";
|
||||
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, MutableBoat, BoatEvent, TerrainType} from "./Game";
|
||||
import {ClientID} from "./Schemas";
|
||||
import {Terrain, TerrainMap, TerrainType} from "./TerrainMapLoader";
|
||||
import {Terrain, TerrainMap} from "./TerrainMapLoader";
|
||||
import {simpleHash} from "./Util";
|
||||
|
||||
export function createGame(terrainMap: TerrainMap, eventBus: EventBus, config: Config): Game {
|
||||
@@ -70,17 +70,19 @@ class TileImpl implements Tile {
|
||||
return this.isLand() && this._terrain.shoreline
|
||||
}
|
||||
isOceanShore(): boolean {
|
||||
return this.isShore() && this.neighbors().find(t => t.isOcean()) != null
|
||||
return this.isShore() && this.isOcean()
|
||||
}
|
||||
|
||||
isShorelineWater(): boolean {
|
||||
return this.isWater() && this._terrain.shoreline
|
||||
}
|
||||
isLand(): boolean {
|
||||
return this._terrain.type == TerrainType.Land
|
||||
return this._terrain.land
|
||||
}
|
||||
isWater(): boolean {
|
||||
return this._terrain.type == TerrainType.Water
|
||||
return !this._terrain.land
|
||||
}
|
||||
terrain(): TerrainType {
|
||||
return this._terrain.type
|
||||
}
|
||||
|
||||
borders(other: Player | TerraNullius): boolean {
|
||||
@@ -110,8 +112,6 @@ class TileImpl implements Tile {
|
||||
}
|
||||
return this._neighbors
|
||||
}
|
||||
|
||||
game(): Game {return this.gs}
|
||||
}
|
||||
|
||||
export class BoatImpl implements MutableBoat {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Cell} from './Game';
|
||||
import {Cell, TerrainType} from './Game';
|
||||
import binAsString from "!!binary-loader!../../resources/TopoWorldMap.bin";
|
||||
|
||||
export class TerrainMap {
|
||||
@@ -17,15 +17,11 @@ export class TerrainMap {
|
||||
}
|
||||
}
|
||||
|
||||
export enum TerrainType {
|
||||
Land,
|
||||
Water
|
||||
}
|
||||
|
||||
export class Terrain {
|
||||
public shoreline: boolean = false
|
||||
public ocean: boolean = false
|
||||
public magnitude: number = 0
|
||||
public ocean = false
|
||||
public land = false
|
||||
constructor(public type: TerrainType) { }
|
||||
}
|
||||
|
||||
@@ -54,15 +50,35 @@ export async function loadTerrainMap(): Promise<TerrainMap> {
|
||||
for (let x = 0; x < width; x++) {
|
||||
for (let y = 0; y < height; y++) {
|
||||
const packedByte = fileData.charCodeAt(4 + y * width + x); // +4 to skip dimension bytes
|
||||
const type = (packedByte & 0b10000000) ? TerrainType.Land : TerrainType.Water;
|
||||
const isLand = (packedByte & 0b10000000)
|
||||
const shoreline = !!(packedByte & 0b01000000);
|
||||
const ocean = !!(packedByte & 0b00100000);
|
||||
const magnitude = packedByte & 0b00011111;
|
||||
|
||||
let type: TerrainType = null
|
||||
let land = false
|
||||
if (isLand) {
|
||||
land = true
|
||||
if (magnitude < 10) {
|
||||
type = TerrainType.Plains
|
||||
} else if (magnitude < 20) {
|
||||
type = TerrainType.Highland
|
||||
} else {
|
||||
type = TerrainType.Mountain
|
||||
}
|
||||
} else {
|
||||
if (ocean) {
|
||||
type = TerrainType.Ocean
|
||||
} else {
|
||||
type = TerrainType.Lake
|
||||
}
|
||||
}
|
||||
|
||||
terrain[x][y] = new Terrain(type);
|
||||
terrain[x][y].shoreline = shoreline;
|
||||
terrain[x][y].ocean = ocean;
|
||||
terrain[x][y].magnitude = magnitude;
|
||||
terrain[x][y].ocean = ocean
|
||||
terrain[x][y].land = land
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {Colord, colord, random} from "colord";
|
||||
import {PlayerID, Tile} from "../Game";
|
||||
import {PlayerID, TerrainType, Tile} from "../Game";
|
||||
import {Theme} from "./Config";
|
||||
import {time} from "console";
|
||||
import {PseudoRandom} from "../PseudoRandom";
|
||||
@@ -86,59 +86,43 @@ export const pastelTheme = new class implements Theme {
|
||||
}
|
||||
|
||||
terrainColor(tile: Tile): Colord {
|
||||
if (tile.isLand()) {
|
||||
if (tile.isShore()) {
|
||||
return this.shore
|
||||
}
|
||||
// let mag = Math.min(tile.magnitude() + 4, 15)
|
||||
// if (mag < 3) {
|
||||
// mag = 0
|
||||
// }
|
||||
let mag = tile.magnitude()
|
||||
|
||||
if (mag > 20) {
|
||||
return colord({
|
||||
r: 250,
|
||||
g: 250,
|
||||
b: 250
|
||||
})
|
||||
}
|
||||
|
||||
if (mag < 5) {
|
||||
return colord({
|
||||
r: 180,
|
||||
g: 200,
|
||||
b: 128
|
||||
})
|
||||
}
|
||||
if (mag < 10) {
|
||||
let mag = tile.magnitude()
|
||||
if (tile.isShore()) {
|
||||
return this.shore
|
||||
}
|
||||
switch (tile.terrain()) {
|
||||
case TerrainType.Ocean:
|
||||
case TerrainType.Lake:
|
||||
const w = this.water.rgba
|
||||
if (tile.isShorelineWater()) {
|
||||
return this.shorelineWater
|
||||
}
|
||||
if (tile.magnitude() < 7) {
|
||||
return colord({
|
||||
r: Math.max(w.r - 7 + mag, 0),
|
||||
g: Math.max(w.g - 7 + mag, 0),
|
||||
b: Math.max(w.b - 7 + mag, 0)
|
||||
})
|
||||
}
|
||||
return this.water
|
||||
case TerrainType.Plains:
|
||||
return colord({
|
||||
r: 190,
|
||||
g: 200,
|
||||
g: 200 + 20 - 2 * mag,
|
||||
b: 138
|
||||
})
|
||||
}
|
||||
|
||||
const delta = 2 * mag
|
||||
|
||||
return colord({
|
||||
r: 190 + delta,
|
||||
g: 193 + delta,
|
||||
b: 138 + delta
|
||||
})
|
||||
} else {
|
||||
const w = this.water.rgba
|
||||
if (tile.isShorelineWater()) {
|
||||
return this.shorelineWater
|
||||
}
|
||||
if (tile.magnitude() < 7) {
|
||||
case TerrainType.Highland:
|
||||
return colord({
|
||||
r: Math.max(w.r - 7 + tile.magnitude(), 0),
|
||||
g: Math.max(w.g - 7 + tile.magnitude(), 0),
|
||||
b: Math.max(w.b - 7 + tile.magnitude(), 0)
|
||||
r: 190 + 2 * mag,
|
||||
g: 193 + 2 * mag,
|
||||
b: 138 + 2 * mag
|
||||
})
|
||||
case TerrainType.Mountain:
|
||||
return colord({
|
||||
r: 220 + mag,
|
||||
g: 220 + mag,
|
||||
b: 220 + mag
|
||||
})
|
||||
}
|
||||
return this.water
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user