mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:50:43 +00:00
add terrain to map
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {Cell} from './Game';
|
||||
import binAsString from "!!binary-loader!../../resources/World.bin";
|
||||
import binAsString from "!!binary-loader!../../resources/TopoWorldMap.bin";
|
||||
|
||||
export class TerrainMap {
|
||||
constructor(public readonly tiles: Terrain[][]) { }
|
||||
|
||||
@@ -16,7 +16,7 @@ export const devConfig = new class extends DefaultConfig {
|
||||
}
|
||||
|
||||
numBots(): number {
|
||||
return 250
|
||||
return 0
|
||||
}
|
||||
|
||||
startTroops(playerInfo: PlayerInfo): number {
|
||||
|
||||
@@ -90,7 +90,11 @@ export const pastelTheme = new class implements Theme {
|
||||
if (tile.isShore()) {
|
||||
return this.shore
|
||||
}
|
||||
return this.land;
|
||||
return colord({
|
||||
r: 174 + 5 * tile.magnitude(),
|
||||
g: 163 + 5 * tile.magnitude(),
|
||||
b: 128 + 5 * tile.magnitude()
|
||||
})
|
||||
} else {
|
||||
const w = this.water.rgba
|
||||
if (tile.isShorelineWater()) {
|
||||
|
||||
@@ -80,6 +80,9 @@ export class PlayerExecution implements Execution {
|
||||
const tiles = bfs(firstTile, filter)
|
||||
|
||||
const modePlayer = this.mg.player(mode)
|
||||
if (modePlayer == null) {
|
||||
console.warn('mode player is null')
|
||||
}
|
||||
for (const tile of tiles) {
|
||||
modePlayer.conquer(tile)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export class Terrain {
|
||||
}
|
||||
|
||||
export async function loadTerrainMap(): Promise<void> {
|
||||
const imagePath = path.resolve(__dirname, '..', '..', 'resources', 'maps', 'World.png');
|
||||
const imagePath = path.resolve(__dirname, '..', '..', 'resources', 'maps', 'TopoWorldMap.png');
|
||||
|
||||
const readStream = createReadStream(imagePath);
|
||||
const img = await PImage.decodePNGFromStream(readStream);
|
||||
@@ -59,11 +59,64 @@ export async function loadTerrainMap(): Promise<void> {
|
||||
for (let y = 0; y < img.height; y++) {
|
||||
const color = img.getPixelRGBA(x, y);
|
||||
const alpha = color & 0xff;
|
||||
const blue = (color >> 8) & 0xff;
|
||||
|
||||
|
||||
if (alpha < 20) { // transparent
|
||||
terrain[x][y] = new Terrain(TerrainType.Water);
|
||||
} else {
|
||||
terrain[x][y] = new Terrain(TerrainType.Land)
|
||||
terrain[x][y].magnitude = 0
|
||||
|
||||
// 150 -> 220
|
||||
switch (true) {
|
||||
case (blue > 220):
|
||||
terrain[x][y].magnitude = 14;
|
||||
break;
|
||||
case (blue > 215):
|
||||
terrain[x][y].magnitude = 13;
|
||||
break;
|
||||
case (blue > 210):
|
||||
terrain[x][y].magnitude = 12;
|
||||
break;
|
||||
case (blue > 205):
|
||||
terrain[x][y].magnitude = 11;
|
||||
break;
|
||||
case (blue > 200):
|
||||
terrain[x][y].magnitude = 10;
|
||||
break;
|
||||
case (blue > 195):
|
||||
terrain[x][y].magnitude = 9;
|
||||
break;
|
||||
case (blue > 185):
|
||||
terrain[x][y].magnitude = 8;
|
||||
break;
|
||||
case (blue > 180):
|
||||
terrain[x][y].magnitude = 7;
|
||||
break;
|
||||
case (blue > 175):
|
||||
terrain[x][y].magnitude = 6;
|
||||
break;
|
||||
case (blue > 170):
|
||||
terrain[x][y].magnitude = 5;
|
||||
break;
|
||||
case (blue > 165):
|
||||
terrain[x][y].magnitude = 4;
|
||||
break;
|
||||
case (blue > 160):
|
||||
terrain[x][y].magnitude = 3;
|
||||
break;
|
||||
case (blue > 155):
|
||||
terrain[x][y].magnitude = 2;
|
||||
break;
|
||||
case (blue > 150):
|
||||
terrain[x][y].magnitude = 1;
|
||||
break;
|
||||
default:
|
||||
terrain[x][y].magnitude = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +126,7 @@ export async function loadTerrainMap(): Promise<void> {
|
||||
processDistToLand(shorelineWaters, terrain)
|
||||
processOcean(terrain)
|
||||
const packed = packTerrain(terrain)
|
||||
const outputPath = path.join(__dirname, '..', '..', 'resources', 'World.bin');
|
||||
const outputPath = path.join(__dirname, '..', '..', 'resources', 'TopoWorldMap.bin');
|
||||
fs.writeFile(outputPath, packed);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user