尽力了,写的我有点恶心
This commit is contained in:
+64
-1
@@ -80,7 +80,7 @@ msgstr "Background Settings"
|
|||||||
msgid "language.en.us"
|
msgid "language.en.us"
|
||||||
msgstr "Language: English(US)"
|
msgstr "Language: English(US)"
|
||||||
|
|
||||||
msgid "language.en.us"
|
msgid "language.zh.cn"
|
||||||
msgstr "Language: Simplified Chinese"
|
msgstr "Language: Simplified Chinese"
|
||||||
|
|
||||||
msgid "cancle"
|
msgid "cancle"
|
||||||
@@ -91,3 +91,66 @@ msgstr "Exit"
|
|||||||
|
|
||||||
msgid "exit.msg"
|
msgid "exit.msg"
|
||||||
msgstr "Are you sure you want to quit the game?"
|
msgstr "Are you sure you want to quit the game?"
|
||||||
|
|
||||||
|
msgid "create_world.title"
|
||||||
|
msgstr "Create World"
|
||||||
|
|
||||||
|
msgid "create_world.default_name"
|
||||||
|
msgstr "New World"
|
||||||
|
|
||||||
|
msgid "create_world.name"
|
||||||
|
msgstr "Name"
|
||||||
|
|
||||||
|
msgid "create_world.seed"
|
||||||
|
msgstr "Seed"
|
||||||
|
|
||||||
|
msgid "create_world.seed.random"
|
||||||
|
msgstr "Random"
|
||||||
|
|
||||||
|
msgid "create_world.difficulty"
|
||||||
|
msgstr "Difficulty"
|
||||||
|
|
||||||
|
msgid "create_world.ore"
|
||||||
|
msgstr "Ore"
|
||||||
|
|
||||||
|
msgid "create_world.realism"
|
||||||
|
msgstr "Realism"
|
||||||
|
|
||||||
|
msgid "create_world.create"
|
||||||
|
msgstr "Create"
|
||||||
|
|
||||||
|
msgid "back"
|
||||||
|
msgstr "Back"
|
||||||
|
|
||||||
|
msgid "difficulty.easy"
|
||||||
|
msgstr "Easy"
|
||||||
|
|
||||||
|
msgid "difficulty.normal"
|
||||||
|
msgstr "Noraml"
|
||||||
|
|
||||||
|
msgid "difficulty.hard"
|
||||||
|
msgstr "Hard"
|
||||||
|
|
||||||
|
msgid "difficulty.brutal"
|
||||||
|
msgstr "Brutal"
|
||||||
|
|
||||||
|
msgid "ore.scarce"
|
||||||
|
msgstr "Scarce"
|
||||||
|
|
||||||
|
msgid "ore.normal"
|
||||||
|
msgstr "Noraml"
|
||||||
|
|
||||||
|
msgid "ore.abundant"
|
||||||
|
msgstr "Abundant"
|
||||||
|
|
||||||
|
msgid "ore.paradise"
|
||||||
|
msgstr "Paradise"
|
||||||
|
|
||||||
|
msgid "realism.casual"
|
||||||
|
msgstr "Casual"
|
||||||
|
|
||||||
|
msgid "realism.standard"
|
||||||
|
msgstr "Standard"
|
||||||
|
|
||||||
|
msgid "realism.hardcore"
|
||||||
|
msgstr "Hardcore"
|
||||||
+64
-1
@@ -80,7 +80,7 @@ msgstr "背景设置"
|
|||||||
msgid "language.en.us"
|
msgid "language.en.us"
|
||||||
msgstr "语言: 美式英语"
|
msgstr "语言: 美式英语"
|
||||||
|
|
||||||
msgid "language.en.us"
|
msgid "language.zh.cn"
|
||||||
msgstr "语言: 简体中文"
|
msgstr "语言: 简体中文"
|
||||||
|
|
||||||
msgid "cancle"
|
msgid "cancle"
|
||||||
@@ -91,3 +91,66 @@ msgstr "退出"
|
|||||||
|
|
||||||
msgid "exit.msg"
|
msgid "exit.msg"
|
||||||
msgstr "你确定要退出游戏吗?"
|
msgstr "你确定要退出游戏吗?"
|
||||||
|
|
||||||
|
msgid "create_world.title"
|
||||||
|
msgstr "创建世界"
|
||||||
|
|
||||||
|
msgid "create_world.default_name"
|
||||||
|
msgstr "新世界"
|
||||||
|
|
||||||
|
msgid "create_world.name"
|
||||||
|
msgstr "世界名称"
|
||||||
|
|
||||||
|
msgid "create_world.seed"
|
||||||
|
msgstr "世界种子"
|
||||||
|
|
||||||
|
msgid "create_world.seed.random"
|
||||||
|
msgstr "随机"
|
||||||
|
|
||||||
|
msgid "create_world.difficulty"
|
||||||
|
msgstr "难度"
|
||||||
|
|
||||||
|
msgid "create_world.ore"
|
||||||
|
msgstr "矿物丰度"
|
||||||
|
|
||||||
|
msgid "create_world.realism"
|
||||||
|
msgstr "拟真程度"
|
||||||
|
|
||||||
|
msgid "create_world.create"
|
||||||
|
msgstr "创建"
|
||||||
|
|
||||||
|
msgid "back"
|
||||||
|
msgstr "返回"
|
||||||
|
|
||||||
|
msgid "difficulty.easy"
|
||||||
|
msgstr "简单"
|
||||||
|
|
||||||
|
msgid "difficulty.normal"
|
||||||
|
msgstr "普通"
|
||||||
|
|
||||||
|
msgid "difficulty.hard"
|
||||||
|
msgstr "困难"
|
||||||
|
|
||||||
|
msgid "difficulty.brutal"
|
||||||
|
msgstr "残酷"
|
||||||
|
|
||||||
|
msgid "ore.scarce"
|
||||||
|
msgstr "稀少"
|
||||||
|
|
||||||
|
msgid "ore.normal"
|
||||||
|
msgstr "正常"
|
||||||
|
|
||||||
|
msgid "ore.abundant"
|
||||||
|
msgstr "丰富"
|
||||||
|
|
||||||
|
msgid "ore.paradise"
|
||||||
|
msgstr "天堂"
|
||||||
|
|
||||||
|
msgid "realism.casual"
|
||||||
|
msgstr "休闲"
|
||||||
|
|
||||||
|
msgid "realism.standard"
|
||||||
|
msgstr "标准"
|
||||||
|
|
||||||
|
msgid "realism.hardcore"
|
||||||
|
msgstr "硬核"
|
||||||
+255
@@ -0,0 +1,255 @@
|
|||||||
|
#include "chunk.h"
|
||||||
|
#include "noise.h"
|
||||||
|
|
||||||
|
// ---------- 坐标辅助 ----------
|
||||||
|
|
||||||
|
struct Vector2_double chunk_origin(int cx, int cy) {
|
||||||
|
struct Vector2_double o;
|
||||||
|
o.x = (double)cx * CHUNK_SIZE - CHUNK_HALF;
|
||||||
|
o.y = (double)cy * CHUNK_SIZE - CHUNK_HALF;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Vector2_double tile_world_pos(int cx, int cy, int tx, int ty) {
|
||||||
|
struct Vector2_double o = chunk_origin(cx, cy);
|
||||||
|
struct Vector2_double p;
|
||||||
|
p.x = o.x + (double)tx + 0.5;
|
||||||
|
p.y = o.y + (double)ty + 0.5;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 宏观高程:从 World_Block 插值 ----------
|
||||||
|
|
||||||
|
static int wrap_block_x(int bx) {
|
||||||
|
bx = bx % (int)WORLD_BLOCK_COUNT_X;
|
||||||
|
if (bx < 0) bx += (int)WORLD_BLOCK_COUNT_X;
|
||||||
|
return bx;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int wrap_block_y(int by) {
|
||||||
|
if (by < 0) by = 0;
|
||||||
|
if (by >= (int)WORLD_BLOCK_COUNT_Y) by = (int)WORLD_BLOCK_COUNT_Y - 1;
|
||||||
|
return by;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double block_elev_at(struct World_Block *blocks, int bx, int by) {
|
||||||
|
bx = wrap_block_x(bx);
|
||||||
|
by = wrap_block_y(by);
|
||||||
|
return blocks[by * WORLD_BLOCK_COUNT_X + bx].elevation;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double macro_elevation_at(struct World_Block *blocks,
|
||||||
|
double wx, double wy) {
|
||||||
|
double bx = wx / (double)WORLD_BLOCK_SIZE - 0.5;
|
||||||
|
double by = wy / (double)WORLD_BLOCK_SIZE - 0.5;
|
||||||
|
int ix = (int)floor(bx);
|
||||||
|
int iy = (int)floor(by);
|
||||||
|
double fx = bx - ix;
|
||||||
|
double fy = by - iy;
|
||||||
|
|
||||||
|
double e00 = block_elev_at(blocks, ix, iy);
|
||||||
|
double e10 = block_elev_at(blocks, ix + 1, iy);
|
||||||
|
double e01 = block_elev_at(blocks, ix, iy + 1);
|
||||||
|
double e11 = block_elev_at(blocks, ix + 1, iy + 1);
|
||||||
|
|
||||||
|
double a = e00 * (1.0 - fx) + e10 * fx;
|
||||||
|
double b = e01 * (1.0 - fx) + e11 * fx;
|
||||||
|
return a * (1.0 - fy) + b * fy;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 高程场 ----------
|
||||||
|
|
||||||
|
static double elevation_at(struct World_Block *blocks,
|
||||||
|
double wx, double wy, uint64_t seed) {
|
||||||
|
double e = macro_elevation_at(blocks, wx, wy);
|
||||||
|
|
||||||
|
double med = fractal_noise(seed, CHUNK_NOISE_MED, wx, wy, 100.0, 4, 0.5);
|
||||||
|
double fine = fractal_noise(seed, CHUNK_NOISE_FINE, wx, wy, 15.0, 3, 0.5);
|
||||||
|
double detail = fractal_noise(seed, CHUNK_NOISE_DETAIL, wx, wy, 3.0, 2, 0.5);
|
||||||
|
|
||||||
|
e += (med - 0.5) * 60.0;
|
||||||
|
e += (fine - 0.5) * 6.0;
|
||||||
|
e += (detail - 0.5) * 1.0;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 气候 ----------
|
||||||
|
|
||||||
|
static double latitude_of(double wy) {
|
||||||
|
double half = WORLD_H * 0.5;
|
||||||
|
double t = wy / half;
|
||||||
|
return -t * 90.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double base_temperature(double lat, double elevation) {
|
||||||
|
double T = 30.0 - 60.0 * fabs(lat) / 90.0;
|
||||||
|
T -= elevation * 0.0065;
|
||||||
|
return T;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double base_moisture(double lat, double wx, double wy, uint64_t seed) {
|
||||||
|
double abs_lat = fabs(lat);
|
||||||
|
double m;
|
||||||
|
if (abs_lat < 10.0) m = 0.85;
|
||||||
|
else if (abs_lat < 25.0) m = 0.85 - (abs_lat - 10.0) * 0.05;
|
||||||
|
else if (abs_lat < 35.0) m = 0.10;
|
||||||
|
else if (abs_lat < 55.0) m = 0.10 + (abs_lat - 35.0) * 0.025;
|
||||||
|
else m = 0.60;
|
||||||
|
|
||||||
|
double n = fractal_noise(seed, CHUNK_NOISE_MOIST, wx, wy, 2000.0, 3, 0.5);
|
||||||
|
m = m * (0.7 + 0.6 * n);
|
||||||
|
if (m < 0.0) m = 0.0;
|
||||||
|
if (m > 1.0) m = 1.0;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 岩石类型 ----------
|
||||||
|
|
||||||
|
static enum Rock_Type rock_from_plate(struct Plate *plate, uint64_t seed,
|
||||||
|
double wx, double wy) {
|
||||||
|
double n = fractal_noise(seed, CHUNK_NOISE_ROCK, wx, wy, 800.0, 3, 0.5);
|
||||||
|
|
||||||
|
if (plate->is_ocean) return ROCK_BASALT;
|
||||||
|
|
||||||
|
if (plate->age > 2500) {
|
||||||
|
if (n < 0.4) return ROCK_GRANITE;
|
||||||
|
if (n < 0.7) return ROCK_GNEISS;
|
||||||
|
return ROCK_SCHIST;
|
||||||
|
}
|
||||||
|
if (plate->thick > 50) {
|
||||||
|
if (n < 0.5) return ROCK_GRANITE;
|
||||||
|
if (n < 0.8) return ROCK_SCHIST;
|
||||||
|
return ROCK_GNEISS;
|
||||||
|
}
|
||||||
|
if (n < 0.35) return ROCK_LIMESTONE;
|
||||||
|
if (n < 0.70) return ROCK_SANDSTONE;
|
||||||
|
return ROCK_SHALE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 地表、土壤、植被 ----------
|
||||||
|
|
||||||
|
static void surface_from_climate(struct Tile *t, enum Rock_Type rock) {
|
||||||
|
double T = t->temperature;
|
||||||
|
double M = t->moisture;
|
||||||
|
double S = t->slope;
|
||||||
|
|
||||||
|
if (t->elevation < 0.0) {
|
||||||
|
t->surface_type = SURFACE_WATER;
|
||||||
|
t->soil_type = SOIL_NONE;
|
||||||
|
t->vegetation = 0.0;
|
||||||
|
t->fertility = 0.0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (T < -5.0) {
|
||||||
|
t->surface_type = (T < -20.0) ? SURFACE_ICE : SURFACE_SNOW;
|
||||||
|
t->soil_type = SOIL_NONE;
|
||||||
|
t->vegetation = 0.0;
|
||||||
|
t->fertility = 0.0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (S > 0.8) {
|
||||||
|
t->surface_type = SURFACE_BARE_ROCK;
|
||||||
|
t->soil_type = SOIL_NONE;
|
||||||
|
t->vegetation = 0.0;
|
||||||
|
t->fertility = 0.0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double veg = 0.0;
|
||||||
|
if (T > 5.0 && M > 0.3) {
|
||||||
|
double base = M * (T / 30.0);
|
||||||
|
if (base > 1.0) base = 1.0;
|
||||||
|
veg = base * (1.0 - S);
|
||||||
|
}
|
||||||
|
t->vegetation = veg;
|
||||||
|
|
||||||
|
if (M < 0.25 && T > 15.0) {
|
||||||
|
t->surface_type = SURFACE_SAND;
|
||||||
|
t->soil_type = SOIL_SAND;
|
||||||
|
} else if (veg > 0.5) {
|
||||||
|
t->surface_type = SURFACE_FOREST;
|
||||||
|
t->soil_type = SOIL_LOAM;
|
||||||
|
} else if (veg > 0.15) {
|
||||||
|
t->surface_type = SURFACE_GRASS;
|
||||||
|
t->soil_type = SOIL_LOAM;
|
||||||
|
} else {
|
||||||
|
t->surface_type = SURFACE_SOIL;
|
||||||
|
t->soil_type = (rock == ROCK_LIMESTONE) ? SOIL_CLAY : SOIL_SILT;
|
||||||
|
}
|
||||||
|
|
||||||
|
t->fertility = veg * M;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 主生成函数 ----------
|
||||||
|
|
||||||
|
struct Chunk *chunk_generate(int cx, int cy, uint64_t seed,
|
||||||
|
struct World_Block *blocks,
|
||||||
|
struct Plate_list plates) {
|
||||||
|
struct Chunk *chunk = malloc(sizeof(struct Chunk));
|
||||||
|
chunk->cx = cx;
|
||||||
|
chunk->cy = cy;
|
||||||
|
|
||||||
|
// 第一遍:高程
|
||||||
|
for (int ty = 0; ty < CHUNK_TILE_COUNT; ty++) {
|
||||||
|
for (int tx = 0; tx < CHUNK_TILE_COUNT; tx++) {
|
||||||
|
struct Vector2_double pos = tile_world_pos(cx, cy, tx, ty);
|
||||||
|
struct Tile *t = &chunk->tiles[ty][tx];
|
||||||
|
t->elevation = elevation_at(blocks, pos.x, pos.y, seed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 第二遍:坡度
|
||||||
|
for (int ty = 0; ty < CHUNK_TILE_COUNT; ty++) {
|
||||||
|
for (int tx = 0; tx < CHUNK_TILE_COUNT; tx++) {
|
||||||
|
struct Vector2_double pos = tile_world_pos(cx, cy, tx, ty);
|
||||||
|
struct Tile *t = &chunk->tiles[ty][tx];
|
||||||
|
|
||||||
|
double eE = elevation_at(blocks, pos.x + TILE_SIZE, pos.y, seed);
|
||||||
|
double eW = elevation_at(blocks, pos.x - TILE_SIZE, pos.y, seed);
|
||||||
|
double eS = elevation_at(blocks, pos.x, pos.y + TILE_SIZE, seed);
|
||||||
|
double eN = elevation_at(blocks, pos.x, pos.y - TILE_SIZE, seed);
|
||||||
|
|
||||||
|
double dx = (eE - eW) * 0.5;
|
||||||
|
double dy = (eS - eN) * 0.5;
|
||||||
|
double grad = sqrt(dx * dx + dy * dy);
|
||||||
|
|
||||||
|
t->slope = atan(grad);
|
||||||
|
t->aspect = atan2(dy, dx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int ty = 0; ty < CHUNK_TILE_COUNT; ty++) {
|
||||||
|
for (int tx = 0; tx < CHUNK_TILE_COUNT; tx++) {
|
||||||
|
struct Vector2_double pos = tile_world_pos(cx, cy, tx, ty);
|
||||||
|
struct Tile *t = &chunk->tiles[ty][tx];
|
||||||
|
|
||||||
|
double lat = latitude_of(pos.y);
|
||||||
|
t->temperature = base_temperature(lat, t->elevation);
|
||||||
|
t->moisture = base_moisture(lat, pos.x, pos.y, seed);
|
||||||
|
|
||||||
|
int bx = (int)(pos.x / (double)WORLD_BLOCK_SIZE);
|
||||||
|
int by = (int)(pos.y / (double)WORLD_BLOCK_SIZE);
|
||||||
|
bx = wrap_block_x(bx);
|
||||||
|
by = wrap_block_y(by);
|
||||||
|
int b_idx = by * WORLD_BLOCK_COUNT_X + bx;
|
||||||
|
struct Plate *plate = plates._p + blocks[b_idx].plate_id;
|
||||||
|
|
||||||
|
enum Rock_Type rock = rock_from_plate(plate, seed, pos.x, pos.y);
|
||||||
|
t->rock_type = (uint8_t)rock;
|
||||||
|
|
||||||
|
// 化合物级组分生成
|
||||||
|
tile_generate_compounds(t, (int)rock, plate,
|
||||||
|
pos.x, pos.y, seed, NULL);
|
||||||
|
|
||||||
|
surface_from_climate(t, rock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
void chunk_free(struct Chunk *c) {
|
||||||
|
free(c);
|
||||||
|
}
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
#include "terrain.h"
|
||||||
|
#include "compound.h"
|
||||||
|
|
||||||
|
#ifndef TERRAIN_CHUNK_H
|
||||||
|
#define TERRAIN_CHUNK_H
|
||||||
|
|
||||||
|
#define TILE_SIZE 1.0
|
||||||
|
#define CHUNK_SIZE 16.0
|
||||||
|
#define CHUNK_HALF 8.0
|
||||||
|
#define CHUNK_TILE_COUNT 16
|
||||||
|
|
||||||
|
enum Surface_Type {
|
||||||
|
SURFACE_BARE_ROCK = 0,
|
||||||
|
SURFACE_SOIL,
|
||||||
|
SURFACE_SAND,
|
||||||
|
SURFACE_GRASS,
|
||||||
|
SURFACE_FOREST,
|
||||||
|
SURFACE_WATER,
|
||||||
|
SURFACE_SNOW,
|
||||||
|
SURFACE_ICE,
|
||||||
|
SURFACE_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Soil_Type {
|
||||||
|
SOIL_NONE = 0,
|
||||||
|
SOIL_SAND,
|
||||||
|
SOIL_SILT,
|
||||||
|
SOIL_CLAY,
|
||||||
|
SOIL_LOAM,
|
||||||
|
SOIL_PEAT,
|
||||||
|
SOIL_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Tile {
|
||||||
|
double elevation;
|
||||||
|
double slope;
|
||||||
|
double aspect;
|
||||||
|
double temperature;
|
||||||
|
double moisture;
|
||||||
|
double fertility;
|
||||||
|
double vegetation;
|
||||||
|
uint8_t surface_type;
|
||||||
|
uint8_t soil_type;
|
||||||
|
uint8_t rock_type;
|
||||||
|
uint8_t _pad;
|
||||||
|
// 归一化化合物组分,sum ≈ 1.0,索引见 Compound_Id
|
||||||
|
float compound[COMPOUND_COUNT];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Chunk {
|
||||||
|
int cx, cy;
|
||||||
|
struct Tile tiles[CHUNK_TILE_COUNT][CHUNK_TILE_COUNT];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Chunk *chunk_generate(int cx, int cy, uint64_t seed,
|
||||||
|
struct World_Block *blocks,
|
||||||
|
struct Plate_list plates);
|
||||||
|
|
||||||
|
void chunk_free(struct Chunk *c);
|
||||||
|
|
||||||
|
struct Vector2_double chunk_origin(int cx, int cy);
|
||||||
|
struct Vector2_double tile_world_pos(int cx, int cy, int tx, int ty);
|
||||||
|
|
||||||
|
#endif
|
||||||
+615
@@ -0,0 +1,615 @@
|
|||||||
|
#include "compound.h"
|
||||||
|
#include "chunk.h"
|
||||||
|
#include "terrain.h"
|
||||||
|
#include "random.h"
|
||||||
|
#include "noise.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
// 板块属性空间混合
|
||||||
|
// ================================================================
|
||||||
|
// 板块分配是 512km 的 World_Block 级别离散值,直接在边界硬切换会产生
|
||||||
|
// 视觉硬缝。这里用高斯核对附近 World_Block 的板块属性做加权平均。
|
||||||
|
// sigma 取 0.7 个 World_Block,过渡带约 ±500km,看起来是自然的渐变。
|
||||||
|
|
||||||
|
#define PLATE_BLEND_RADIUS 2
|
||||||
|
#define PLATE_BLEND_SIGMA (WORLD_BLOCK_SIZE * 0.2)
|
||||||
|
|
||||||
|
void plate_blend_at(struct World_Block *blocks,
|
||||||
|
struct Plate_list plates,
|
||||||
|
double wx, double wy,
|
||||||
|
struct Plate_Blend *out) {
|
||||||
|
int cx = (int)floor(wx / (double)WORLD_BLOCK_SIZE);
|
||||||
|
int cy = (int)floor(wy / (double)WORLD_BLOCK_SIZE);
|
||||||
|
|
||||||
|
const double sigma2 = PLATE_BLEND_SIGMA * PLATE_BLEND_SIGMA;
|
||||||
|
const double inv_2s2 = 1.0 / (2.0 * sigma2);
|
||||||
|
|
||||||
|
double total = 0.0;
|
||||||
|
double sum_oc = 0.0;
|
||||||
|
double sum_age = 0.0;
|
||||||
|
double sum_thk = 0.0;
|
||||||
|
double sum_sx = 0.0;
|
||||||
|
double sum_sy = 0.0;
|
||||||
|
|
||||||
|
for (int dy = -PLATE_BLEND_RADIUS; dy <= PLATE_BLEND_RADIUS; dy++) {
|
||||||
|
for (int dx = -PLATE_BLEND_RADIUS; dx <= PLATE_BLEND_RADIUS; dx++) {
|
||||||
|
int bx = wrap_block_x(cx + dx);
|
||||||
|
int by = wrap_block_y(cy + dy);
|
||||||
|
int bi = by * WORLD_BLOCK_COUNT_X + bx;
|
||||||
|
|
||||||
|
double bxc = ((double)bx + 0.5) * WORLD_BLOCK_SIZE;
|
||||||
|
double byc = ((double)by + 0.5) * WORLD_BLOCK_SIZE;
|
||||||
|
|
||||||
|
double ddx = bxc - wx;
|
||||||
|
if (ddx > WORLD_W * 0.5) ddx -= WORLD_W;
|
||||||
|
if (ddx < -WORLD_W * 0.5) ddx += WORLD_W;
|
||||||
|
double ddy = byc - wy;
|
||||||
|
|
||||||
|
double w = exp(-(ddx*ddx + ddy*ddy) * inv_2s2);
|
||||||
|
|
||||||
|
int pid = blocks[bi].plate_id;
|
||||||
|
struct Plate *p = plates._p + pid;
|
||||||
|
|
||||||
|
sum_oc += w * (p->is_ocean ? 1.0 : 0.0);
|
||||||
|
sum_age += w * (double)p->age;
|
||||||
|
sum_thk += w * p->thick;
|
||||||
|
sum_sx += w * p->speed.x;
|
||||||
|
sum_sy += w * p->speed.y;
|
||||||
|
total += w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (total < 1e-12) {
|
||||||
|
out->is_ocean = 0; out->age = 0; out->thick = 0;
|
||||||
|
out->speed_x = 0; out->speed_y = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
out->is_ocean = sum_oc / total;
|
||||||
|
out->age = sum_age / total;
|
||||||
|
out->thick = sum_thk / total;
|
||||||
|
out->speed_x = sum_sx / total;
|
||||||
|
out->speed_y = sum_sy / total;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
// 岩石类型权重(连续)
|
||||||
|
// ================================================================
|
||||||
|
|
||||||
|
static double clamp01(double x) {
|
||||||
|
return x < 0.0 ? 0.0 : (x > 1.0 ? 1.0 : x);
|
||||||
|
}
|
||||||
|
static double smooth01(double x) {
|
||||||
|
x = clamp01(x);
|
||||||
|
return x * x * (3.0 - 2.0 * x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 三分类平滑分配:n < lo → (1,0,0),n > hi → (0,0,1),中间平滑过渡
|
||||||
|
// 过渡带宽度 0.10(可调)
|
||||||
|
static void tri_weights(double n, double lo, double hi, double w[3]) {
|
||||||
|
double a = smooth01((n - lo) / 0.10 + 0.5);
|
||||||
|
double b = smooth01((n - hi) / 0.10 + 0.5);
|
||||||
|
w[0] = 1.0 - a;
|
||||||
|
w[1] = a - b;
|
||||||
|
w[2] = b;
|
||||||
|
if (w[0] < 0) w[0] = 0;
|
||||||
|
if (w[1] < 0) w[1] = 0;
|
||||||
|
if (w[2] < 0) w[2] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rock_weights_blend(const struct Plate_Blend *pb,
|
||||||
|
double rock_n,
|
||||||
|
double out_w[ROCK_COUNT]) {
|
||||||
|
for (int i = 0; i < ROCK_COUNT; i++) out_w[i] = 0.0;
|
||||||
|
|
||||||
|
double ocean = pb->is_ocean;
|
||||||
|
double land = 1.0 - ocean;
|
||||||
|
|
||||||
|
// --- 海洋端元:纯玄武岩 ---
|
||||||
|
out_w[ROCK_BASALT] += ocean;
|
||||||
|
|
||||||
|
if (land < 1e-12) return;
|
||||||
|
|
||||||
|
// --- 陆地端元的三个"组合"互相竞争 ---
|
||||||
|
// 古老地盾(age 驱动)
|
||||||
|
// 厚地壳(thick 驱动)
|
||||||
|
// 年轻地壳(基线)
|
||||||
|
// 用平滑阶跃让 age / thick 从阈值以下慢慢起作用。
|
||||||
|
double g_old = smooth01((pb->age - 2000.0) / 1000.0);
|
||||||
|
double g_thick = smooth01((pb->thick - 40.0) / 25.0);
|
||||||
|
|
||||||
|
// 加一个基线让"年轻地壳"永远保留一定权重
|
||||||
|
const double baseline_young = 0.5;
|
||||||
|
double sum_g = g_old + g_thick + baseline_young;
|
||||||
|
|
||||||
|
double w_old = g_old / sum_g;
|
||||||
|
double w_thick = g_thick / sum_g;
|
||||||
|
double w_young = baseline_young / sum_g;
|
||||||
|
|
||||||
|
// 古老组合内部:[花岗岩, 片麻岩, 片岩]
|
||||||
|
double old_w[3];
|
||||||
|
tri_weights(rock_n, 0.4, 0.7, old_w);
|
||||||
|
|
||||||
|
// 厚地壳组合内部:[花岗岩, 片岩, 片麻岩](注意和古老组合顺序不同)
|
||||||
|
double thick_raw[3];
|
||||||
|
tri_weights(rock_n, 0.5, 0.8, thick_raw);
|
||||||
|
|
||||||
|
// 年轻组合内部:[石灰岩, 砂岩, 页岩]
|
||||||
|
double young_w[3];
|
||||||
|
tri_weights(rock_n, 0.35, 0.70, young_w);
|
||||||
|
|
||||||
|
// 汇总
|
||||||
|
out_w[ROCK_GRANITE] += land * (w_old * old_w[0] +
|
||||||
|
w_thick * thick_raw[0]);
|
||||||
|
out_w[ROCK_GNEISS] += land * (w_old * old_w[1] +
|
||||||
|
w_thick * thick_raw[2]);
|
||||||
|
out_w[ROCK_SCHIST] += land * (w_old * old_w[2] +
|
||||||
|
w_thick * thick_raw[1]);
|
||||||
|
out_w[ROCK_LIMESTONE] += land * w_young * young_w[0];
|
||||||
|
out_w[ROCK_SANDSTONE] += land * w_young * young_w[1];
|
||||||
|
out_w[ROCK_SHALE] += land * w_young * young_w[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
// 每种化合物的形状参数
|
||||||
|
// scale 斑块基频尺度(米)
|
||||||
|
// octaves 倍频数
|
||||||
|
// persistence 倍频幅度衰减
|
||||||
|
// threshold 噪声阈值;低于此值权重 = 0
|
||||||
|
// abundance 基础世界丰度
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
struct Compound_Params {
|
||||||
|
double scale;
|
||||||
|
int octaves;
|
||||||
|
double persistence;
|
||||||
|
double threshold;
|
||||||
|
double abundance;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct Compound_Params CP_PARAMS[COMPOUND_COUNT] = {
|
||||||
|
// ---------- 造岩:大尺度、低阈值,几乎处处存在 ----------
|
||||||
|
[CP_QUARTZ] = { 1500.0, 3, 0.5, 0.08, 1.00 },
|
||||||
|
[CP_ORTHOCLASE] = { 1500.0, 3, 0.5, 0.10, 1.00 },
|
||||||
|
[CP_ALBITE] = { 1500.0, 3, 0.5, 0.12, 1.00 },
|
||||||
|
[CP_ANORTHITE] = { 1500.0, 3, 0.5, 0.15, 1.00 },
|
||||||
|
[CP_MUSCOVITE] = { 800.0, 3, 0.5, 0.25, 1.00 },
|
||||||
|
[CP_BIOTITE] = { 800.0, 3, 0.5, 0.25, 1.00 },
|
||||||
|
[CP_HORNBLENDE] = { 800.0, 3, 0.5, 0.28, 1.00 },
|
||||||
|
[CP_AUGITE] = { 800.0, 3, 0.5, 0.28, 1.00 },
|
||||||
|
[CP_FORSTERITE] = { 600.0, 3, 0.5, 0.55, 1.00 },
|
||||||
|
[CP_FAYALITE] = { 600.0, 3, 0.5, 0.60, 1.00 },
|
||||||
|
|
||||||
|
// ---------- 碳酸盐 / 蒸发岩 / 黏土 ----------
|
||||||
|
[CP_CALCITE] = { 1000.0, 3, 0.5, 0.20, 1.00 },
|
||||||
|
[CP_DOLOMITE] = { 900.0, 3, 0.5, 0.32, 1.00 },
|
||||||
|
[CP_SIDERITE] = { 400.0, 3, 0.5, 0.62, 1.00 },
|
||||||
|
[CP_RHODOCHROSITE] = { 400.0, 3, 0.5, 0.68, 1.00 },
|
||||||
|
[CP_MAGNESITE] = { 500.0, 3, 0.5, 0.65, 1.00 },
|
||||||
|
[CP_KAOLINITE] = { 400.0, 3, 0.5, 0.20, 1.00 },
|
||||||
|
[CP_MONTMORILLONITE]= { 400.0, 3, 0.5, 0.30, 1.00 },
|
||||||
|
[CP_ILLITE] = { 400.0, 3, 0.5, 0.30, 1.00 },
|
||||||
|
[CP_GYPSUM] = { 700.0, 3, 0.5, 0.55, 1.00 },
|
||||||
|
[CP_ANHYDRITE] = { 700.0, 3, 0.5, 0.58, 1.00 },
|
||||||
|
[CP_HALITE] = { 1000.0, 3, 0.5, 0.60, 1.00 },
|
||||||
|
[CP_SYLVITE] = { 1000.0, 3, 0.5, 0.72, 1.00 },
|
||||||
|
[CP_CARNOTITE] = { 300.0, 4, 0.5, 0.82, 1.00 },
|
||||||
|
|
||||||
|
// ---------- 铁 ----------
|
||||||
|
[CP_HEMATITE] = { 600.0, 4, 0.5, 0.45, 1.00 },
|
||||||
|
[CP_MAGNETITE] = { 500.0, 4, 0.5, 0.50, 1.00 },
|
||||||
|
[CP_GOETHITE] = { 400.0, 4, 0.5, 0.55, 1.00 },
|
||||||
|
[CP_PYRITE] = { 350.0, 4, 0.5, 0.55, 1.00 },
|
||||||
|
[CP_PYRrhOTITE] = { 300.0, 4, 0.5, 0.70, 1.00 },
|
||||||
|
[CP_ILMENITE] = { 400.0, 4, 0.5, 0.60, 1.00 },
|
||||||
|
|
||||||
|
// ---------- 铜 ----------
|
||||||
|
[CP_CHALCOPYRITE] = { 350.0, 4, 0.5, 0.58, 1.00 },
|
||||||
|
[CP_BORNITE] = { 300.0, 4, 0.5, 0.68, 1.00 },
|
||||||
|
[CP_CHALCOCITE] = { 300.0, 4, 0.5, 0.70, 1.00 },
|
||||||
|
[CP_COVELLITE] = { 250.0, 4, 0.5, 0.75, 1.00 },
|
||||||
|
[CP_CUPRITE] = { 250.0, 4, 0.5, 0.75, 1.00 },
|
||||||
|
[CP_TENORITE] = { 250.0, 4, 0.5, 0.78, 1.00 },
|
||||||
|
[CP_MALACHITE] = { 300.0, 4, 0.5, 0.65, 1.00 },
|
||||||
|
[CP_AZURITE] = { 300.0, 4, 0.5, 0.72, 1.00 },
|
||||||
|
[CP_CHRYSOCOLLA] = { 300.0, 4, 0.5, 0.72, 1.00 },
|
||||||
|
[CP_TETRAHEDRITE] = { 200.0, 4, 0.5, 0.80, 1.00 },
|
||||||
|
|
||||||
|
// ---------- 铅 / 锌 ----------
|
||||||
|
[CP_GALENA] = { 300.0, 4, 0.5, 0.60, 1.00 },
|
||||||
|
[CP_CERUSSITE] = { 300.0, 4, 0.5, 0.72, 1.00 },
|
||||||
|
[CP_ANGLESITE] = { 300.0, 4, 0.5, 0.75, 1.00 },
|
||||||
|
[CP_PYROMORPHITE] = { 250.0, 4, 0.5, 0.78, 1.00 },
|
||||||
|
[CP_SPHALERITE] = { 300.0, 4, 0.5, 0.58, 1.00 },
|
||||||
|
[CP_SMITHSONITE] = { 300.0, 4, 0.5, 0.72, 1.00 },
|
||||||
|
[CP_HEMIMORPHITE] = { 300.0, 4, 0.5, 0.75, 1.00 },
|
||||||
|
[CP_WILLEMITE] = { 300.0, 4, 0.5, 0.75, 1.00 },
|
||||||
|
|
||||||
|
// ---------- 锡 / 钨 / 钼 / 铋 / 锑 / 汞 / 砷 ----------
|
||||||
|
[CP_CASSITERITE] = { 250.0, 4, 0.5, 0.72, 1.00 },
|
||||||
|
[CP_FERBERITE] = { 200.0, 4, 0.5, 0.78, 1.00 },
|
||||||
|
[CP_HUEBNERITE] = { 200.0, 4, 0.5, 0.80, 1.00 },
|
||||||
|
[CP_SCHEELITE] = { 250.0, 4, 0.5, 0.76, 1.00 },
|
||||||
|
[CP_MOLYBDENITE] = { 250.0, 4, 0.5, 0.74, 1.00 },
|
||||||
|
[CP_WULFENITE] = { 200.0, 4, 0.5, 0.82, 1.00 },
|
||||||
|
[CP_BISMUTHINITE] = { 200.0, 4, 0.5, 0.82, 1.00 },
|
||||||
|
[CP_NATIVE_BISMUTH] = { 150.0, 4, 0.5, 0.88, 1.00 },
|
||||||
|
[CP_STIBNITE] = { 200.0, 4, 0.5, 0.80, 1.00 },
|
||||||
|
[CP_CINNABAR] = { 150.0, 4, 0.5, 0.85, 1.00 },
|
||||||
|
[CP_ARSENOPYRITE] = { 300.0, 4, 0.5, 0.72, 1.00 },
|
||||||
|
[CP_REALGAR] = { 150.0, 4, 0.5, 0.85, 1.00 },
|
||||||
|
[CP_ORPIMENT] = { 150.0, 4, 0.5, 0.85, 1.00 },
|
||||||
|
|
||||||
|
// ---------- 镍 / 钴 / 铬 / 锰 ----------
|
||||||
|
[CP_PENTLANDITE] = { 400.0, 4, 0.5, 0.70, 1.00 },
|
||||||
|
[CP_NICCOLITE] = { 250.0, 4, 0.5, 0.80, 1.00 },
|
||||||
|
[CP_MILLERITE] = { 250.0, 4, 0.5, 0.80, 1.00 },
|
||||||
|
[CP_GARNIERITE] = { 400.0, 4, 0.5, 0.68, 1.00 },
|
||||||
|
[CP_COBALTITE] = { 200.0, 4, 0.5, 0.82, 1.00 },
|
||||||
|
[CP_SKUTTERUDITE] = { 200.0, 4, 0.5, 0.84, 1.00 },
|
||||||
|
[CP_HETEROGENITE] = { 200.0, 4, 0.5, 0.85, 1.00 },
|
||||||
|
[CP_CHROMITE] = { 400.0, 4, 0.5, 0.70, 1.00 },
|
||||||
|
[CP_PYROLUSITE] = { 350.0, 4, 0.5, 0.62, 1.00 },
|
||||||
|
[CP_BRAUNITE] = { 350.0, 4, 0.5, 0.72, 1.00 },
|
||||||
|
|
||||||
|
// ---------- 铝 / 钛 / 钒 ----------
|
||||||
|
[CP_GIBBSITE] = { 800.0, 3, 0.5, 0.55, 1.00 },
|
||||||
|
[CP_BOEHMITE] = { 800.0, 3, 0.5, 0.58, 1.00 },
|
||||||
|
[CP_CORUNDUM] = { 200.0, 4, 0.5, 0.82, 1.00 },
|
||||||
|
[CP_RUTILE] = { 400.0, 4, 0.5, 0.62, 1.00 },
|
||||||
|
[CP_ANATASE] = { 400.0, 4, 0.5, 0.72, 1.00 },
|
||||||
|
[CP_VANADINITE] = { 200.0, 4, 0.5, 0.85, 1.00 },
|
||||||
|
|
||||||
|
// ---------- 贵金属 ----------
|
||||||
|
[CP_NATIVE_GOLD] = { 150.0, 4, 0.5, 0.84, 1.00 },
|
||||||
|
[CP_CALAVERITE] = { 120.0, 4, 0.5, 0.90, 1.00 },
|
||||||
|
[CP_NATIVE_SILVER] = { 150.0, 4, 0.5, 0.84, 1.00 },
|
||||||
|
[CP_ACANTHITE] = { 180.0, 4, 0.5, 0.80, 1.00 },
|
||||||
|
[CP_CHLORARGYRITE] = { 150.0, 4, 0.5, 0.86, 1.00 },
|
||||||
|
[CP_NATIVE_PLATINUM]= { 120.0, 4, 0.5, 0.90, 1.00 },
|
||||||
|
[CP_SPERRYLITE] = { 120.0, 4, 0.5, 0.92, 1.00 },
|
||||||
|
|
||||||
|
// ---------- 锂 / 铍 / 稀土 / 铀 ----------
|
||||||
|
[CP_SPODUMENE] = { 250.0, 4, 0.5, 0.80, 1.00 },
|
||||||
|
[CP_LEPIDOLITE] = { 250.0, 4, 0.5, 0.80, 1.00 },
|
||||||
|
[CP_PETALITE] = { 200.0, 4, 0.5, 0.84, 1.00 },
|
||||||
|
[CP_BERYL] = { 200.0, 4, 0.5, 0.84, 1.00 },
|
||||||
|
[CP_MONAZITE] = { 250.0, 4, 0.5, 0.78, 1.00 },
|
||||||
|
[CP_BASTNASITE] = { 250.0, 4, 0.5, 0.78, 1.00 },
|
||||||
|
[CP_XENOTIME] = { 200.0, 4, 0.5, 0.84, 1.00 },
|
||||||
|
[CP_URANINITE] = { 300.0, 4, 0.5, 0.74, 1.00 },
|
||||||
|
|
||||||
|
// ---------- 非金属 / 宝石 ----------
|
||||||
|
[CP_GRAPHITE] = { 350.0, 4, 0.5, 0.68, 1.00 },
|
||||||
|
[CP_DIAMOND] = { 120.0, 4, 0.5, 0.92, 1.00 },
|
||||||
|
[CP_COAL] = { 500.0, 3, 0.5, 0.48, 1.00 },
|
||||||
|
[CP_NATIVE_SULFUR] = { 250.0, 3, 0.5, 0.72, 1.00 },
|
||||||
|
[CP_FLUORITE] = { 200.0, 4, 0.5, 0.80, 1.00 },
|
||||||
|
[CP_BARITE] = { 250.0, 4, 0.5, 0.78, 1.00 },
|
||||||
|
[CP_APATITE] = { 400.0, 3, 0.5, 0.68, 1.00 },
|
||||||
|
[CP_TALC] = { 250.0, 4, 0.5, 0.76, 1.00 },
|
||||||
|
[CP_GEM_RUBY] = { 120.0, 4, 0.5, 0.92, 1.00 },
|
||||||
|
[CP_GEM_EMERALD] = { 120.0, 4, 0.5, 0.92, 1.00 },
|
||||||
|
[CP_GEM_TOPAZ] = { 120.0, 4, 0.5, 0.92, 1.00 },
|
||||||
|
[CP_GEM_GARNET] = { 150.0, 4, 0.5, 0.88, 1.00 },
|
||||||
|
[CP_GEM_TOURMALINE] = { 120.0, 4, 0.5, 0.92, 1.00 },
|
||||||
|
};
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
// 岩石类型亲和度
|
||||||
|
// 列顺序:GRANITE, BASALT, LIMESTONE, SANDSTONE, SHALE, SCHIST, GNEISS
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
static const double ROCK_AFFINITY[COMPOUND_COUNT][ROCK_COUNT] = {
|
||||||
|
// ---------- 造岩 ----------
|
||||||
|
/* QUARTZ */ { 2.0, 0.3, 0.1, 2.5, 0.8, 1.2, 1.5 },
|
||||||
|
/* ORTHOCLASE */ { 2.2, 0.3, 0.0, 1.2, 0.3, 0.8, 2.0 },
|
||||||
|
/* ALBITE */ { 2.0, 0.8, 0.0, 1.2, 0.3, 1.0, 1.8 },
|
||||||
|
/* ANORTHITE */ { 0.5, 2.2, 0.0, 0.5, 0.3, 1.2, 1.5 },
|
||||||
|
/* MUSCOVITE */ { 1.5, 0.3, 0.1, 0.2, 0.5, 2.0, 1.5 },
|
||||||
|
/* BIOTITE */ { 1.5, 0.8, 0.1, 0.2, 0.5, 1.8, 1.5 },
|
||||||
|
/* HORNBLENDE */ { 1.0, 1.5, 0.1, 0.1, 0.2, 2.0, 1.5 },
|
||||||
|
/* AUGITE */ { 0.3, 2.5, 0.1, 0.1, 0.2, 1.0, 0.8 },
|
||||||
|
/* FORSTERITE */ { 0.1, 2.5, 0.0, 0.0, 0.0, 0.2, 0.1 },
|
||||||
|
/* FAYALITE */ { 0.1, 2.5, 0.0, 0.0, 0.0, 0.2, 0.1 },
|
||||||
|
|
||||||
|
// ---------- 碳酸盐 / 蒸发岩 / 黏土 ----------
|
||||||
|
/* CALCITE */ { 0.1, 0.1, 3.0, 0.5, 0.3, 0.5, 0.3 },
|
||||||
|
/* DOLOMITE */ { 0.1, 0.1, 2.5, 0.3, 0.2, 0.4, 0.3 },
|
||||||
|
/* SIDERITE */ { 0.5, 0.5, 1.2, 0.8, 1.2, 1.0, 0.8 },
|
||||||
|
/* RHODOCHROSITE */ { 0.5, 0.3, 1.5, 0.5, 0.8, 0.8, 0.5 },
|
||||||
|
/* MAGNESITE */ { 0.3, 1.0, 1.2, 0.3, 0.3, 0.8, 0.5 },
|
||||||
|
/* KAOLINITE */ { 1.5, 0.3, 0.3, 0.8, 1.5, 0.5, 0.8 },
|
||||||
|
/* MONTMORILLONITE*/ { 1.0, 0.5, 0.5, 0.5, 1.5, 0.5, 0.8 },
|
||||||
|
/* ILLITE */ { 0.5, 0.3, 0.5, 0.5, 2.5, 0.8, 0.8 },
|
||||||
|
/* GYPSUM */ { 0.1, 0.1, 1.5, 0.3, 0.5, 0.1, 0.1 },
|
||||||
|
/* ANHYDRITE */ { 0.1, 0.1, 1.5, 0.3, 0.5, 0.1, 0.1 },
|
||||||
|
/* HALITE */ { 0.0, 0.0, 1.2, 0.5, 0.8, 0.1, 0.0 },
|
||||||
|
/* SYLVITE */ { 0.0, 0.0, 0.8, 0.5, 0.8, 0.1, 0.0 },
|
||||||
|
/* CARNOTITE */ { 0.0, 0.0, 0.5, 2.5, 1.5, 0.0, 0.0 },
|
||||||
|
|
||||||
|
// ---------- 铁 ----------
|
||||||
|
/* HEMATITE */ { 0.8, 1.2, 0.5, 0.8, 0.8, 1.8, 2.0 },
|
||||||
|
/* MAGNETITE */ { 0.8, 1.5, 0.3, 0.5, 0.5, 1.8, 1.8 },
|
||||||
|
/* GOETHITE */ { 0.3, 0.5, 0.5, 1.5, 1.2, 0.5, 0.5 },
|
||||||
|
/* PYRITE */ { 0.8, 1.0, 0.5, 0.8, 1.2, 1.2, 1.0 },
|
||||||
|
/* PYRRHOTITE */ { 0.3, 1.8, 0.2, 0.2, 0.3, 0.8, 0.5 },
|
||||||
|
/* ILMENITE */ { 0.5, 2.0, 0.3, 0.5, 0.5, 1.0, 0.8 },
|
||||||
|
|
||||||
|
// ---------- 铜 ----------
|
||||||
|
/* CHALCOPYRITE */ { 1.2, 1.2, 0.8, 0.8, 0.5, 1.3, 1.0 },
|
||||||
|
/* BORNITE */ { 1.0, 1.0, 0.5, 0.5, 0.5, 1.2, 1.0 },
|
||||||
|
/* CHALCOCITE */ { 0.8, 0.8, 0.8, 0.5, 0.5, 1.2, 1.0 },
|
||||||
|
/* COVELLITE */ { 0.5, 0.5, 0.5, 0.3, 0.5, 1.2, 1.0 },
|
||||||
|
/* CUPRITE */ { 0.5, 0.5, 0.8, 0.5, 0.5, 1.2, 1.0 },
|
||||||
|
/* TENORITE */ { 0.5, 0.5, 0.8, 0.5, 0.5, 1.0, 0.8 },
|
||||||
|
/* MALACHITE */ { 0.3, 0.3, 1.5, 0.5, 0.5, 0.8, 0.5 },
|
||||||
|
/* AZURITE */ { 0.3, 0.3, 1.5, 0.5, 0.5, 0.8, 0.5 },
|
||||||
|
/* CHRYSOCOLLA */ { 0.5, 0.5, 1.2, 0.5, 0.5, 0.8, 0.5 },
|
||||||
|
/* TETRAHEDRITE */ { 0.5, 0.5, 0.8, 0.5, 0.5, 1.3, 1.0 },
|
||||||
|
|
||||||
|
// ---------- 铅 / 锌 ----------
|
||||||
|
/* GALENA */ { 1.0, 0.5, 1.5, 0.5, 0.5, 1.2, 1.0 },
|
||||||
|
/* CERUSSITE */ { 0.5, 0.3, 1.8, 0.5, 0.5, 0.8, 0.5 },
|
||||||
|
/* ANGLESITE */ { 0.5, 0.3, 1.5, 0.5, 0.5, 0.8, 0.5 },
|
||||||
|
/* PYROMORPHITE */ { 0.5, 0.3, 1.2, 0.5, 0.5, 0.8, 0.5 },
|
||||||
|
/* SPHALERITE */ { 0.8, 0.5, 1.5, 0.5, 0.5, 1.2, 1.0 },
|
||||||
|
/* SMITHSONITE */ { 0.3, 0.3, 1.8, 0.5, 0.5, 0.8, 0.5 },
|
||||||
|
/* HEMIMORPHITE */ { 0.3, 0.3, 1.8, 0.5, 0.5, 0.8, 0.5 },
|
||||||
|
/* WILLEMITE */ { 0.3, 0.5, 1.5, 0.5, 0.5, 0.8, 0.5 },
|
||||||
|
|
||||||
|
// ---------- 锡 / 钨 / 钼 / 铋 / 锑 / 汞 / 砷 ----------
|
||||||
|
/* CASSITERITE */ { 1.8, 0.2, 0.1, 0.1, 0.1, 0.8, 0.8 },
|
||||||
|
/* FERBERITE */ { 1.5, 0.2, 0.3, 0.2, 0.3, 0.8, 1.0 },
|
||||||
|
/* HUEBNERITE */ { 1.5, 0.2, 0.3, 0.2, 0.3, 0.8, 1.0 },
|
||||||
|
/* SCHEELITE */ { 0.5, 0.3, 2.0, 0.3, 0.3, 1.0, 0.8 },
|
||||||
|
/* MOLYBDENITE */ { 1.5, 0.5, 0.5, 0.3, 0.5, 1.0, 1.2 },
|
||||||
|
/* WULFENITE */ { 0.5, 0.3, 1.5, 0.5, 0.5, 0.8, 0.5 },
|
||||||
|
/* BISMUTHINITE */ { 1.2, 0.2, 0.5, 0.3, 0.3, 0.8, 0.8 },
|
||||||
|
/* NATIVE_BISMUTH */ { 0.8, 0.2, 0.3, 0.2, 0.2, 0.8, 0.8 },
|
||||||
|
/* STIBNITE */ { 0.5, 0.3, 0.5, 0.3, 0.5, 1.2, 1.0 },
|
||||||
|
/* CINNABAR */ { 0.3, 0.5, 1.0, 0.3, 0.3, 1.2, 0.8 },
|
||||||
|
/* ARSENOPYRITE */ { 1.2, 0.8, 0.8, 0.5, 0.5, 1.3, 1.0 },
|
||||||
|
/* REALGAR */ { 0.2, 0.3, 0.8, 0.2, 0.3, 0.5, 0.3 },
|
||||||
|
/* ORPIMENT */ { 0.2, 0.3, 0.8, 0.2, 0.3, 0.5, 0.3 },
|
||||||
|
|
||||||
|
// ---------- 镍 / 钴 / 铬 / 锰 ----------
|
||||||
|
/* PENTLANDITE */ { 0.3, 2.5, 0.1, 0.1, 0.2, 0.8, 0.5 },
|
||||||
|
/* NICCOLITE */ { 0.2, 2.0, 0.2, 0.1, 0.2, 1.0, 0.8 },
|
||||||
|
/* MILLERITE */ { 0.3, 1.5, 0.3, 0.2, 0.3, 1.0, 0.8 },
|
||||||
|
/* GARNIERITE */ { 0.2, 2.5, 0.3, 0.3, 0.3, 0.5, 0.3 },
|
||||||
|
/* COBALTITE */ { 0.5, 1.5, 0.2, 0.3, 0.3, 1.0, 0.8 },
|
||||||
|
/* SKUTTERUDITE */ { 0.3, 1.2, 0.2, 0.2, 0.3, 1.0, 0.8 },
|
||||||
|
/* HETEROGENITE */ { 0.3, 1.0, 0.3, 0.3, 0.3, 0.8, 0.5 },
|
||||||
|
/* CHROMITE */ { 0.2, 2.0, 0.1, 0.1, 0.1, 0.5, 0.3 },
|
||||||
|
/* PYROLUSITE */ { 0.3, 0.5, 1.5, 0.5, 0.5, 0.8, 0.8 },
|
||||||
|
/* BRAUNITE */ { 0.3, 0.5, 1.5, 0.5, 0.5, 0.8, 0.8 },
|
||||||
|
|
||||||
|
// ---------- 铝 / 钛 / 钒 ----------
|
||||||
|
/* GIBBSITE */ { 0.5, 0.3, 0.3, 0.3, 0.5, 0.5, 0.5 },
|
||||||
|
/* BOEHMITE */ { 0.5, 0.3, 0.3, 0.3, 0.5, 0.5, 0.5 },
|
||||||
|
/* CORUNDUM */ { 0.8, 0.3, 0.5, 0.2, 0.2, 0.5, 0.5 },
|
||||||
|
/* RUTILE */ { 0.5, 1.5, 0.5, 0.5, 0.5, 1.2, 1.0 },
|
||||||
|
/* ANATASE */ { 0.3, 1.2, 0.5, 0.8, 0.8, 0.8, 0.5 },
|
||||||
|
/* VANADINITE */ { 0.3, 0.3, 1.0, 1.5, 0.8, 0.5, 0.3 },
|
||||||
|
|
||||||
|
// ---------- 贵金属 ----------
|
||||||
|
/* NATIVE_GOLD */ { 1.2, 0.3, 0.3, 0.5, 0.5, 1.8, 1.5 },
|
||||||
|
/* CALAVERITE */ { 0.8, 0.2, 0.3, 0.2, 0.3, 1.5, 1.2 },
|
||||||
|
/* NATIVE_SILVER */ { 0.8, 0.3, 0.5, 0.3, 0.3, 1.5, 1.2 },
|
||||||
|
/* ACANTHITE */ { 0.5, 0.3, 0.8, 0.3, 0.5, 1.5, 1.2 },
|
||||||
|
/* CHLORARGYRITE */ { 0.3, 0.2, 0.5, 0.3, 0.3, 0.5, 0.3 },
|
||||||
|
/* NATIVE_PLATINUM*/ { 0.2, 2.5, 0.1, 0.1, 0.1, 0.3, 0.2 },
|
||||||
|
/* SPERRYLITE */ { 0.2, 2.0, 0.1, 0.1, 0.1, 0.3, 0.2 },
|
||||||
|
|
||||||
|
// ---------- 锂 / 铍 / 稀土 / 铀 ----------
|
||||||
|
/* SPODUMENE */ { 1.8, 0.2, 0.3, 0.3, 0.5, 1.0, 1.0 },
|
||||||
|
/* LEPIDOLITE */ { 1.8, 0.2, 0.3, 0.3, 0.5, 1.0, 1.0 },
|
||||||
|
/* PETALITE */ { 1.5, 0.2, 0.3, 0.3, 0.3, 0.8, 0.8 },
|
||||||
|
/* BERYL */ { 1.5, 0.1, 0.3, 0.3, 0.3, 0.8, 1.0 },
|
||||||
|
/* MONAZITE */ { 1.5, 0.3, 0.3, 1.5, 0.5, 0.8, 1.2 },
|
||||||
|
/* BASTNASITE */ { 1.5, 0.3, 1.0, 0.3, 0.3, 0.8, 1.0 },
|
||||||
|
/* XENOTIME */ { 1.2, 0.2, 0.3, 1.2, 0.5, 0.8, 1.0 },
|
||||||
|
/* URANINITE */ { 1.5, 0.3, 0.5, 2.0, 1.5, 0.8, 1.0 },
|
||||||
|
|
||||||
|
// ---------- 非金属 / 宝石 ----------
|
||||||
|
/* GRAPHITE */ { 0.5, 0.3, 1.0, 0.5, 1.5, 1.5, 1.0 },
|
||||||
|
/* DIAMOND */ { 0.1, 1.5, 0.0, 0.0, 0.0, 0.3, 0.2 },
|
||||||
|
/* COAL */ { 0.0, 0.1, 0.3, 0.5, 1.5, 0.3, 0.1 },
|
||||||
|
/* NATIVE_SULFUR */ { 0.2, 1.5, 0.5, 0.3, 0.3, 0.3, 0.2 },
|
||||||
|
/* FLUORITE */ { 1.8, 0.3, 1.5, 0.3, 0.3, 0.5, 0.8 },
|
||||||
|
/* BARITE */ { 0.5, 0.3, 1.5, 0.5, 0.5, 0.8, 0.5 },
|
||||||
|
/* APATITE */ { 0.5, 0.5, 1.5, 0.5, 0.8, 0.5, 0.5 },
|
||||||
|
/* TALC */ { 0.3, 0.5, 0.5, 0.1, 0.3, 1.5, 1.0 },
|
||||||
|
/* GEM_RUBY */ { 0.3, 0.3, 1.0, 0.1, 0.1, 0.8, 0.8 },
|
||||||
|
/* GEM_EMERALD */ { 0.3, 0.3, 0.3, 0.1, 0.1, 0.8, 0.8 },
|
||||||
|
/* GEM_TOPAZ */ { 1.5, 0.2, 0.3, 0.1, 0.1, 1.2, 1.2 },
|
||||||
|
/* GEM_GARNET */ { 1.2, 0.5, 0.3, 0.3, 0.3, 1.5, 1.5 },
|
||||||
|
/* GEM_TOURMALINE */ { 1.2, 0.2, 0.3, 0.1, 0.1, 0.8, 0.8 },
|
||||||
|
};
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
// 板块 / 环境修正
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
static double plate_multiplier_blend(const struct Plate_Blend *pb, int c) {
|
||||||
|
// --- 海洋端元 ---
|
||||||
|
double ocean_a = 1.0;
|
||||||
|
switch (c) {
|
||||||
|
case CP_CHALCOPYRITE: case CP_BORNITE: case CP_CHALCOCITE:
|
||||||
|
case CP_COVELLITE: case CP_CUPRITE: case CP_TENORITE:
|
||||||
|
case CP_MALACHITE: case CP_AZURITE: case CP_CHRYSOCOLLA:
|
||||||
|
case CP_TETRAHEDRITE: ocean_a = 1.5; break;
|
||||||
|
case CP_PYROLUSITE: case CP_BRAUNITE: ocean_a = 2.0; break;
|
||||||
|
case CP_PENTLANDITE: case CP_NICCOLITE: case CP_MILLERITE:
|
||||||
|
case CP_GARNIERITE: ocean_a = 1.4; break;
|
||||||
|
case CP_COBALTITE: case CP_SKUTTERUDITE: case CP_HETEROGENITE:
|
||||||
|
ocean_a = 1.4; break;
|
||||||
|
case CP_NATIVE_PLATINUM: case CP_SPERRYLITE: ocean_a = 1.2; break;
|
||||||
|
default: ocean_a = 1.0; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 陆地端元:把硬阈值换成平滑因子 ---
|
||||||
|
double age_f = smooth01((pb->age - 2000.0) / 1000.0);
|
||||||
|
double thick_f = smooth01((pb->thick - 40.0) / 25.0);
|
||||||
|
double land_a = 1.0;
|
||||||
|
|
||||||
|
switch (c) {
|
||||||
|
case CP_HEMATITE: case CP_MAGNETITE: case CP_GOETHITE:
|
||||||
|
case CP_PYRITE: case CP_PYRrhOTITE:
|
||||||
|
land_a = 1.0 + age_f * 0.8; break;
|
||||||
|
case CP_NATIVE_GOLD: case CP_CALAVERITE:
|
||||||
|
land_a = 1.0 + age_f * 0.6; break;
|
||||||
|
case CP_URANINITE: case CP_CARNOTITE:
|
||||||
|
land_a = 1.0 + age_f * 0.4; break;
|
||||||
|
case CP_MONAZITE: case CP_BASTNASITE: case CP_XENOTIME:
|
||||||
|
land_a = 1.0 + age_f * 0.5; break;
|
||||||
|
case CP_DIAMOND:
|
||||||
|
land_a = 1.0 + age_f * 0.5; break;
|
||||||
|
|
||||||
|
case CP_CHALCOPYRITE: case CP_BORNITE:
|
||||||
|
case CP_CHALCOCITE: case CP_TETRAHEDRITE:
|
||||||
|
land_a = 1.0 + thick_f * 0.4; break;
|
||||||
|
case CP_CASSITERITE:
|
||||||
|
land_a = 1.0 + thick_f * 0.5; break;
|
||||||
|
case CP_FERBERITE: case CP_HUEBNERITE: case CP_SCHEELITE:
|
||||||
|
land_a = 1.0 + thick_f * 0.5; break;
|
||||||
|
case CP_MOLYBDENITE:
|
||||||
|
land_a = 1.0 + thick_f * 0.4; break;
|
||||||
|
case CP_SPODUMENE: case CP_LEPIDOLITE:
|
||||||
|
case CP_PETALITE: case CP_BERYL:
|
||||||
|
land_a = 1.0 + thick_f * 0.4; break;
|
||||||
|
case CP_GEM_RUBY: case CP_GEM_EMERALD:
|
||||||
|
case CP_GEM_TOPAZ: case CP_GEM_GARNET: case CP_GEM_TOURMALINE:
|
||||||
|
land_a = 1.0 + thick_f * 0.5; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 线性混合:is_ocean 是 0..1
|
||||||
|
return ocean_a * pb->is_ocean + land_a * (1.0 - pb->is_ocean);
|
||||||
|
}
|
||||||
|
|
||||||
|
static double environment_multiplier(enum Compound_Id c,
|
||||||
|
double elevation,
|
||||||
|
double temperature,
|
||||||
|
double moisture) {
|
||||||
|
double a = 1.0;
|
||||||
|
switch (c) {
|
||||||
|
// 铝土矿:热带潮湿强风化
|
||||||
|
case CP_GIBBSITE: case CP_BOEHMITE:
|
||||||
|
a *= (temperature > 20.0) ? ((temperature - 20.0) / 15.0) : 0.0;
|
||||||
|
a *= (moisture > 0.6) ? 1.0 : 0.3;
|
||||||
|
break;
|
||||||
|
// 煤:低地沉积
|
||||||
|
case CP_COAL:
|
||||||
|
a *= (elevation < 800.0) ? 1.0 : 0.1;
|
||||||
|
a *= (moisture > 0.4) ? 1.0 : 0.4;
|
||||||
|
break;
|
||||||
|
// 蒸发岩:干旱
|
||||||
|
case CP_HALITE: case CP_SYLVITE:
|
||||||
|
case CP_GYPSUM: case CP_ANHYDRITE:
|
||||||
|
a *= (moisture < 0.4) ? 1.5 : 0.3;
|
||||||
|
break;
|
||||||
|
// 砂岩型铀矿:中低地
|
||||||
|
case CP_URANINITE: case CP_CARNOTITE:
|
||||||
|
a *= (elevation < 1500.0) ? 1.2 : 0.5;
|
||||||
|
break;
|
||||||
|
// 磷块岩:浅海上升流
|
||||||
|
case CP_APATITE:
|
||||||
|
a *= (elevation < 500.0) ? 1.3 : 0.5;
|
||||||
|
break;
|
||||||
|
// 红土镍矿:热带
|
||||||
|
case CP_GARNIERITE:
|
||||||
|
a *= (temperature > 22.0) ? 1.5 : 0.4;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
// 默认世界设置:所有化合物丰度 = 1.0
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
const struct Compound_Settings COMPOUND_SETTINGS_DEFAULT = {
|
||||||
|
.abundance = {
|
||||||
|
// 造岩 10
|
||||||
|
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
|
||||||
|
// 碳酸盐/蒸发岩/黏土 13
|
||||||
|
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
|
||||||
|
// 铁 6
|
||||||
|
1.0,1.0,1.0,1.0,1.0,1.0,
|
||||||
|
// 铜 10
|
||||||
|
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
|
||||||
|
// 铅锌 8
|
||||||
|
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
|
||||||
|
// 锡钨钼铋锑汞砷 13
|
||||||
|
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
|
||||||
|
// 镍钴铬锰 10
|
||||||
|
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
|
||||||
|
// 铝钛钒 6
|
||||||
|
1.0,1.0,1.0,1.0,1.0,1.0,
|
||||||
|
// 贵金属 7
|
||||||
|
1.0,1.0,1.0,1.0,1.0,1.0,1.0,
|
||||||
|
// 锂铍稀土铀 8
|
||||||
|
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
|
||||||
|
// 非金属/宝石 13
|
||||||
|
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
// 主生成入口
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
void tile_generate_compounds(struct Tile *t,
|
||||||
|
const double rock_w[ROCK_COUNT],
|
||||||
|
const struct Plate_Blend *plate,
|
||||||
|
double wx, double wy,
|
||||||
|
uint64_t seed,
|
||||||
|
const struct Compound_Settings *settings) {
|
||||||
|
if (!settings) settings = &COMPOUND_SETTINGS_DEFAULT;
|
||||||
|
|
||||||
|
// 1. 岩石亲和度:跨 7 种岩石做加权平均
|
||||||
|
double rock_aff[COMPOUND_COUNT];
|
||||||
|
for (int c = 0; c < COMPOUND_COUNT; c++) {
|
||||||
|
double a = 0.0;
|
||||||
|
for (int r = 0; r < ROCK_COUNT; r++) {
|
||||||
|
a += rock_w[r] * ROCK_AFFINITY[c][r];
|
||||||
|
}
|
||||||
|
rock_aff[c] = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 板块乘数:所有化合物一次算好
|
||||||
|
double plate_mult[COMPOUND_COUNT];
|
||||||
|
for (int c = 0; c < COMPOUND_COUNT; c++) {
|
||||||
|
plate_mult[c] = plate_multiplier_blend(plate, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 化合物权重
|
||||||
|
double w[COMPOUND_COUNT];
|
||||||
|
double sum = 0.0;
|
||||||
|
|
||||||
|
for (int c = 0; c < COMPOUND_COUNT; c++) {
|
||||||
|
const struct Compound_Params *p = &CP_PARAMS[c];
|
||||||
|
|
||||||
|
double n = fractal_noise(seed, CHUNK_NOISE_MINERAL_BASE + c,
|
||||||
|
wx, wy, p->scale, p->octaves, p->persistence);
|
||||||
|
double v = n - p->threshold;
|
||||||
|
if (v < 0.0) v = 0.0;
|
||||||
|
|
||||||
|
v *= p->abundance * settings->abundance[c];
|
||||||
|
v *= rock_aff[c];
|
||||||
|
v *= plate_mult[c];
|
||||||
|
v *= environment_multiplier((enum Compound_Id)c,
|
||||||
|
t->elevation, t->temperature, t->moisture);
|
||||||
|
|
||||||
|
w[c] = v;
|
||||||
|
sum += v;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 归一化
|
||||||
|
if (sum < 1e-12) {
|
||||||
|
for (int c = 0; c < COMPOUND_COUNT; c++) t->compound[c] = 0.0f;
|
||||||
|
t->compound[CP_QUARTZ] = 1.0f;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int c = 0; c < COMPOUND_COUNT; c++) {
|
||||||
|
t->compound[c] = (float)(w[c] / sum);
|
||||||
|
}
|
||||||
|
}
|
||||||
+181
@@ -0,0 +1,181 @@
|
|||||||
|
#ifndef TERRAIN_COMPOUND_H
|
||||||
|
#define TERRAIN_COMPOUND_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "terrain.h"
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
// 化合物清单
|
||||||
|
// 说明:
|
||||||
|
// - 同一种元素的不同化合物(如 Fe2O3 / Fe3O4 / FeCO3 / FeS2)
|
||||||
|
// 均单独列出,因为选矿、焙烧、浸出、还原工序都不同。
|
||||||
|
// - 同质多象也分开(如 RUTILE 与 ANATASE 都是 TiO2,
|
||||||
|
// 但晶体结构、可选冶路径与用途不同)。
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
enum Compound_Id {
|
||||||
|
// ============ 造岩硅酸盐 / 氧化物 / 氢氧化物 ============
|
||||||
|
CP_QUARTZ = 0, // SiO2
|
||||||
|
CP_ORTHOCLASE, // KAlSi3O8
|
||||||
|
CP_ALBITE, // NaAlSi3O8
|
||||||
|
CP_ANORTHITE, // CaAl2Si2O8
|
||||||
|
CP_MUSCOVITE, // KAl2(AlSi3O10)(OH)2
|
||||||
|
CP_BIOTITE, // K(Mg,Fe)3AlSi3O10(OH)2
|
||||||
|
CP_HORNBLENDE, // Ca2(Mg,Fe)4Al(Si7Al)O22(OH)2
|
||||||
|
CP_AUGITE, // (Ca,Na)(Mg,Fe,Al,Ti)(Si,Al)2O6
|
||||||
|
CP_FORSTERITE, // Mg2SiO4
|
||||||
|
CP_FAYALITE, // Fe2SiO4
|
||||||
|
|
||||||
|
// ============ 碳酸盐 / 硫酸盐 / 卤化物 / 黏土 ============
|
||||||
|
CP_CALCITE, // CaCO3
|
||||||
|
CP_DOLOMITE, // CaMg(CO3)2
|
||||||
|
CP_SIDERITE, // FeCO3
|
||||||
|
CP_RHODOCHROSITE, // MnCO3
|
||||||
|
CP_MAGNESITE, // MgCO3
|
||||||
|
CP_KAOLINITE, // Al2Si2O5(OH)4
|
||||||
|
CP_MONTMORILLONITE, // (Na,Ca)0.33(Al,Mg)2Si4O10(OH)2·nH2O
|
||||||
|
CP_ILLITE, // (K,H3O)(Al,Mg,Fe)2(Si,Al)4O10[(OH)2,H2O]
|
||||||
|
CP_GYPSUM, // CaSO4·2H2O
|
||||||
|
CP_ANHYDRITE, // CaSO4
|
||||||
|
CP_HALITE, // NaCl
|
||||||
|
CP_SYLVITE, // KCl
|
||||||
|
CP_CARNOTITE, // K2(UO2)2(VO4)2·3H2O
|
||||||
|
|
||||||
|
// ============ 铁 ============
|
||||||
|
CP_HEMATITE, // Fe2O3
|
||||||
|
CP_MAGNETITE, // Fe3O4
|
||||||
|
CP_GOETHITE, // FeO(OH)
|
||||||
|
CP_PYRITE, // FeS2
|
||||||
|
CP_PYRrhOTITE, // Fe(1-x)S (磁黄铁矿)
|
||||||
|
CP_ILMENITE, // FeTiO3
|
||||||
|
|
||||||
|
// ============ 铜 ============
|
||||||
|
CP_CHALCOPYRITE, // CuFeS2
|
||||||
|
CP_BORNITE, // Cu5FeS4
|
||||||
|
CP_CHALCOCITE, // Cu2S
|
||||||
|
CP_COVELLITE, // CuS
|
||||||
|
CP_CUPRITE, // Cu2O
|
||||||
|
CP_TENORITE, // CuO
|
||||||
|
CP_MALACHITE, // Cu2CO3(OH)2
|
||||||
|
CP_AZURITE, // Cu3(CO3)2(OH)2
|
||||||
|
CP_CHRYSOCOLLA, // CuSiO3·nH2O
|
||||||
|
CP_TETRAHEDRITE, // Cu12Sb4S13(含银黝铜矿)
|
||||||
|
|
||||||
|
// ============ 铅 / 锌 ============
|
||||||
|
CP_GALENA, // PbS
|
||||||
|
CP_CERUSSITE, // PbCO3
|
||||||
|
CP_ANGLESITE, // PbSO4
|
||||||
|
CP_PYROMORPHITE, // Pb5(PO4)3Cl
|
||||||
|
CP_SPHALERITE, // ZnS
|
||||||
|
CP_SMITHSONITE, // ZnCO3
|
||||||
|
CP_HEMIMORPHITE, // Zn4Si2O7(OH)2·H2O
|
||||||
|
CP_WILLEMITE, // Zn2SiO4
|
||||||
|
|
||||||
|
// ============ 锡 / 钨 / 钼 / 铋 / 锑 / 汞 / 砷 ============
|
||||||
|
CP_CASSITERITE, // SnO2
|
||||||
|
CP_FERBERITE, // FeWO4
|
||||||
|
CP_HUEBNERITE, // MnWO4
|
||||||
|
CP_SCHEELITE, // CaWO4
|
||||||
|
CP_MOLYBDENITE, // MoS2
|
||||||
|
CP_WULFENITE, // PbMoO4
|
||||||
|
CP_BISMUTHINITE, // Bi2S3
|
||||||
|
CP_NATIVE_BISMUTH, // Bi
|
||||||
|
CP_STIBNITE, // Sb2S3
|
||||||
|
CP_CINNABAR, // HgS
|
||||||
|
CP_ARSENOPYRITE, // FeAsS
|
||||||
|
CP_REALGAR, // As4S4
|
||||||
|
CP_ORPIMENT, // As2S3
|
||||||
|
|
||||||
|
// ============ 镍 / 钴 / 铬 / 锰 ============
|
||||||
|
CP_PENTLANDITE, // (Fe,Ni)9S8
|
||||||
|
CP_NICCOLITE, // NiAs
|
||||||
|
CP_MILLERITE, // NiS
|
||||||
|
CP_GARNIERITE, // 镍蛇纹石 (Ni,Mg)3Si2O5(OH)4
|
||||||
|
CP_COBALTITE, // CoAsS
|
||||||
|
CP_SKUTTERUDITE, // CoAs3
|
||||||
|
CP_HETEROGENITE, // CoO(OH)
|
||||||
|
CP_CHROMITE, // FeCr2O4
|
||||||
|
CP_PYROLUSITE, // MnO2
|
||||||
|
CP_BRAUNITE, // Mn2O3
|
||||||
|
|
||||||
|
// ============ 铝 / 钛 / 钒 ============
|
||||||
|
CP_GIBBSITE, // Al(OH)3
|
||||||
|
CP_BOEHMITE, // AlO(OH)
|
||||||
|
CP_CORUNDUM, // Al2O3(工业刚玉)
|
||||||
|
CP_RUTILE, // TiO2(金红石)
|
||||||
|
CP_ANATASE, // TiO2(锐钛矿)
|
||||||
|
CP_VANADINITE, // Pb5(VO4)3Cl
|
||||||
|
|
||||||
|
// ============ 贵金属 ============
|
||||||
|
CP_NATIVE_GOLD, // Au
|
||||||
|
CP_CALAVERITE, // AuTe2
|
||||||
|
CP_NATIVE_SILVER, // Ag
|
||||||
|
CP_ACANTHITE, // Ag2S
|
||||||
|
CP_CHLORARGYRITE, // AgCl
|
||||||
|
CP_NATIVE_PLATINUM, // Pt
|
||||||
|
CP_SPERRYLITE, // PtAs2
|
||||||
|
|
||||||
|
// ============ 锂 / 铍 / 稀土 / 铀 ============
|
||||||
|
CP_SPODUMENE, // LiAlSi2O6
|
||||||
|
CP_LEPIDOLITE, // K(Li,Al)3(AlSi3O10)(OH)2
|
||||||
|
CP_PETALITE, // LiAlSi4O10
|
||||||
|
CP_BERYL, // Be3Al2Si6O18
|
||||||
|
CP_MONAZITE, // (Ce,La)PO4
|
||||||
|
CP_BASTNASITE, // (Ce,La)CO3F
|
||||||
|
CP_XENOTIME, // YPO4
|
||||||
|
CP_URANINITE, // UO2
|
||||||
|
|
||||||
|
// ============ 非金属 / 宝石 ============
|
||||||
|
CP_GRAPHITE, // C(石墨)
|
||||||
|
CP_DIAMOND, // C(金刚石)
|
||||||
|
CP_COAL, // C(煤,复杂有机质)
|
||||||
|
CP_NATIVE_SULFUR, // S
|
||||||
|
CP_FLUORITE, // CaF2
|
||||||
|
CP_BARITE, // BaSO4
|
||||||
|
CP_APATITE, // Ca5(PO4)3(F,Cl,OH)
|
||||||
|
CP_TALC, // Mg3Si4O10(OH)2
|
||||||
|
CP_GEM_RUBY, // Al2O3(红宝石,Cr 致色)
|
||||||
|
CP_GEM_EMERALD, // Be3Al2Si6O18(祖母绿,Cr/V 致色)
|
||||||
|
CP_GEM_TOPAZ, // Al2SiO4(F,OH)2
|
||||||
|
CP_GEM_GARNET, // X3Y2(SiO4)3
|
||||||
|
CP_GEM_TOURMALINE, // 复杂硼硅酸盐
|
||||||
|
|
||||||
|
COMPOUND_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Compound_Settings {
|
||||||
|
double abundance[COMPOUND_COUNT];
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const struct Compound_Settings COMPOUND_SETTINGS_DEFAULT;
|
||||||
|
|
||||||
|
struct Tile;
|
||||||
|
struct Plate;
|
||||||
|
|
||||||
|
// ---- 新增:连续化的板块属性 ----
|
||||||
|
struct Plate_Blend {
|
||||||
|
double is_ocean; // 0 = 全陆地,1 = 全海洋,中间是过渡
|
||||||
|
double age;
|
||||||
|
double thick;
|
||||||
|
double speed_x, speed_y;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 在 (wx, wy) 处用高斯核对附近 World_Block 的板块属性做空间混合
|
||||||
|
void plate_blend_at(struct World_Block *blocks,
|
||||||
|
struct Plate_list plates,
|
||||||
|
double wx, double wy,
|
||||||
|
struct Plate_Blend *out);
|
||||||
|
|
||||||
|
// 根据混合板块属性 + 岩石噪声,输出 7 种岩石类型的连续权重(和为 1)
|
||||||
|
void rock_weights_blend(const struct Plate_Blend *pb,
|
||||||
|
double rock_n,
|
||||||
|
double out_w[ROCK_COUNT]);
|
||||||
|
|
||||||
|
// 新签名:接受岩石权重 + 混合板块属性
|
||||||
|
void tile_generate_compounds(struct Tile *t,
|
||||||
|
const double rock_w[ROCK_COUNT],
|
||||||
|
const struct Plate_Blend *plate,
|
||||||
|
double wx, double wy,
|
||||||
|
uint64_t seed,
|
||||||
|
const struct Compound_Settings *settings);
|
||||||
|
|
||||||
|
#endif
|
||||||
+356
-19
@@ -45,18 +45,27 @@ void change_bool(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void draw_text_right(struct Font font,const char *text,struct Vector2 right_pos,float fontSize,float spacing,struct Color color){
|
||||||
|
struct Vector2 sz = MeasureTextEx(font,text,fontSize,spacing);
|
||||||
|
DrawTextEx(font,text,(struct Vector2){right_pos.x - sz.x,right_pos.y - sz.y*0.5f},fontSize,spacing,color);
|
||||||
|
}
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
|
struct World_Config world_config = {
|
||||||
|
.name = "",
|
||||||
|
.seed = 0,
|
||||||
|
.difficulty = DIFFICULTY_NORMAL,
|
||||||
|
.ore_abundance = ORE_NORMAL,
|
||||||
|
.realism = REALISM_STANDARD
|
||||||
|
};
|
||||||
|
|
||||||
struct timer half_clock_timer = init_timer(change_bool,NULL,2);
|
struct timer half_clock_timer = init_timer(change_bool,NULL,2);
|
||||||
|
|
||||||
pthread_t hct_t;
|
pthread_t hct_t;
|
||||||
|
|
||||||
start_timer(&half_clock_timer,NULL,&hct_t);
|
start_timer(&half_clock_timer,NULL,&hct_t);
|
||||||
|
|
||||||
bindtextdomain("Industrial Genesis", "locale");
|
|
||||||
textdomain("Industrial Genesis");
|
|
||||||
//区域设置
|
|
||||||
|
|
||||||
#ifdef _RELEASE_
|
#ifdef _RELEASE_
|
||||||
SetTraceLogLevel(LOG_ERROR);
|
SetTraceLogLevel(LOG_ERROR);
|
||||||
#endif
|
#endif
|
||||||
@@ -101,20 +110,59 @@ int main(){
|
|||||||
screen_scale = json_object_get_double(window_config.scale_config);
|
screen_scale = json_object_get_double(window_config.scale_config);
|
||||||
//缩放
|
//缩放
|
||||||
|
|
||||||
window_config.language_config = get_json_object_object(window_config.root,"language",json_object_new_string(setlocale(LC_MESSAGES,NULL)),"config/window.json");
|
// ---------- 读取语言配置 ----------
|
||||||
char lang[64];
|
window_config.language_config = get_json_object_object(
|
||||||
snprintf(lang,sizeof(lang),"%s",json_object_get_string(window_config.language_config));
|
window_config.root, "language",
|
||||||
if(strcmp(lang,"en_US")==0){
|
json_object_new_string(""),
|
||||||
language = ENGLISH;
|
"config/window.json");
|
||||||
}else if(strcmp(lang,"zh_CN")==0){
|
|
||||||
|
char lang[64] = {0};
|
||||||
|
snprintf(lang, sizeof(lang), "%s",
|
||||||
|
json_object_get_string(window_config.language_config));
|
||||||
|
|
||||||
|
// 配置为空或无效时,从环境变量推断系统语言
|
||||||
|
if (lang[0] == '\0' || strcmp(lang, "C") == 0 || strcmp(lang, "POSIX") == 0) {
|
||||||
|
const char *env = getenv("LC_ALL");
|
||||||
|
if (env == NULL || env[0] == '\0') env = getenv("LC_MESSAGES");
|
||||||
|
if (env == NULL || env[0] == '\0') env = getenv("LANG");
|
||||||
|
if (env == NULL || env[0] == '\0') {
|
||||||
|
snprintf(lang, sizeof(lang), "en_US");
|
||||||
|
} else {
|
||||||
|
snprintf(lang, sizeof(lang), "%s", env);
|
||||||
|
// 去掉 ".UTF-8"、".utf8" 等后缀,只保留语言代码
|
||||||
|
char *dot = strchr(lang, '.');
|
||||||
|
if (dot != NULL) *dot = '\0';
|
||||||
|
if (strcmp(lang, "C") == 0 || strcmp(lang, "POSIX") == 0) {
|
||||||
|
snprintf(lang, sizeof(lang), "en_US");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- 先设置 locale,再绑定 gettext ----------
|
||||||
|
setenv("LANGUAGE", lang, 1);
|
||||||
|
|
||||||
|
char locale_name[80];
|
||||||
|
snprintf(locale_name, sizeof(locale_name), "%s.UTF-8", lang);
|
||||||
|
if (setlocale(LC_MESSAGES, locale_name) == NULL) {
|
||||||
|
if (setlocale(LC_MESSAGES, lang) == NULL) {
|
||||||
|
setlocale(LC_MESSAGES, "en_US.UTF-8");
|
||||||
|
snprintf(lang, sizeof(lang), "en_US");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用绝对路径绑定,避免工作目录问题
|
||||||
|
char locale_path[512];
|
||||||
|
snprintf(locale_path, sizeof(locale_path), "%slocale",
|
||||||
|
GetApplicationDirectory());
|
||||||
|
bindtextdomain("Industrial Genesis", locale_path);
|
||||||
|
textdomain("Industrial Genesis");
|
||||||
|
|
||||||
|
// ---------- 记录语言状态 ----------
|
||||||
|
if (strncmp(lang, "zh", 2) == 0) {
|
||||||
language = SIMPLIFIED_CHINESE;
|
language = SIMPLIFIED_CHINESE;
|
||||||
} else {
|
} else {
|
||||||
language = ENGLISH;
|
language = ENGLISH;
|
||||||
}
|
}
|
||||||
setenv("LANGUAGE",lang,1);
|
|
||||||
strncat(lang,".UTF-8",sizeof(lang)-1);
|
|
||||||
lang[63]='\0';
|
|
||||||
setlocale(LC_MESSAGES,lang);
|
|
||||||
|
|
||||||
InitWindow(json_object_get_int(json_object_object_get(window_config.window_size_config,"x")), json_object_get_int(json_object_object_get(window_config.window_size_config,"y")), "Industrial Genesis");
|
InitWindow(json_object_get_int(json_object_object_get(window_config.window_size_config,"x")), json_object_get_int(json_object_object_get(window_config.window_size_config,"y")), "Industrial Genesis");
|
||||||
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
||||||
@@ -232,6 +280,12 @@ int main(){
|
|||||||
break;
|
break;
|
||||||
}//退出按钮按下响应
|
}//退出按钮按下响应
|
||||||
|
|
||||||
|
if(isButtonPressed(*(button_list._p))){
|
||||||
|
screen = CREATE_WORLD_SCREEN;
|
||||||
|
UninButtonList(&button_list);
|
||||||
|
break;
|
||||||
|
}//设置按钮按下响应,内存回收防止泄漏
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EXIT_SCREEN:
|
case EXIT_SCREEN:
|
||||||
if(button_list._p==NULL){
|
if(button_list._p==NULL){
|
||||||
@@ -298,7 +352,7 @@ int main(){
|
|||||||
InitAndDrawButtonEx(*(button_list._p+4),button_in_grid_pos((struct Vector2){GetScreenWidth()*0.5f,GetScreenHeight()*0.5f},(struct Vector2){2,5},(struct Vector2){1,3},normal_button_size),zoom(wide_button_size),texture_list._p[WIDE_BUTTON],texture_list._p[PRESSED_WIDE_BUTTON],_("language.en.us"),font_25px,25*screen_scale,2*screen_scale);
|
InitAndDrawButtonEx(*(button_list._p+4),button_in_grid_pos((struct Vector2){GetScreenWidth()*0.5f,GetScreenHeight()*0.5f},(struct Vector2){2,5},(struct Vector2){1,3},normal_button_size),zoom(wide_button_size),texture_list._p[WIDE_BUTTON],texture_list._p[PRESSED_WIDE_BUTTON],_("language.en.us"),font_25px,25*screen_scale,2*screen_scale);
|
||||||
break;
|
break;
|
||||||
case SIMPLIFIED_CHINESE:
|
case SIMPLIFIED_CHINESE:
|
||||||
InitAndDrawButtonEx(*(button_list._p+4),button_in_grid_pos((struct Vector2){GetScreenWidth()*0.5f,GetScreenHeight()*0.5f},(struct Vector2){2,5},(struct Vector2){1,3},normal_button_size),zoom(wide_button_size),texture_list._p[WIDE_BUTTON],texture_list._p[PRESSED_WIDE_BUTTON],_("language.en.us"),font_25px,25*screen_scale,2*screen_scale);
|
InitAndDrawButtonEx(*(button_list._p+4),button_in_grid_pos((struct Vector2){GetScreenWidth()*0.5f,GetScreenHeight()*0.5f},(struct Vector2){2,5},(struct Vector2){1,3},normal_button_size),zoom(wide_button_size),texture_list._p[WIDE_BUTTON],texture_list._p[PRESSED_WIDE_BUTTON],_("language.zh.cn"),font_25px,25*screen_scale,2*screen_scale);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
InitAndDrawButtonEx(*(button_list._p+4),button_in_grid_pos((struct Vector2){GetScreenWidth()*0.5f,GetScreenHeight()*0.5f},(struct Vector2){2,5},(struct Vector2){1,3},normal_button_size),zoom(wide_button_size),texture_list._p[WIDE_BUTTON],texture_list._p[PRESSED_WIDE_BUTTON],_("language.en.us"),font_25px,25*screen_scale,2*screen_scale);
|
InitAndDrawButtonEx(*(button_list._p+4),button_in_grid_pos((struct Vector2){GetScreenWidth()*0.5f,GetScreenHeight()*0.5f},(struct Vector2){2,5},(struct Vector2){1,3},normal_button_size),zoom(wide_button_size),texture_list._p[WIDE_BUTTON],texture_list._p[PRESSED_WIDE_BUTTON],_("language.en.us"),font_25px,25*screen_scale,2*screen_scale);
|
||||||
@@ -560,12 +614,12 @@ int main(){
|
|||||||
|
|
||||||
if(IsKeyDown(KEY_LEFT_CONTROL)&&IsKeyPressed(KEY_V)&&focus!=NULL){
|
if(IsKeyDown(KEY_LEFT_CONTROL)&&IsKeyPressed(KEY_V)&&focus!=NULL){
|
||||||
const char *clipboard = GetClipboardText();
|
const char *clipboard = GetClipboardText();
|
||||||
if(strlen(*(text_list._p+((unsigned long)(focus_p)-(unsigned long)(input_box_list._p))/sizeof(char*)))+strlen(clipboard)>=TEXT_MAX_LEN){
|
int idx = (int)(focus_p - input_box_list._p);
|
||||||
continue;
|
if(strlen(*(text_list._p+idx))+strlen(clipboard)<TEXT_MAX_LEN){
|
||||||
}
|
strcat(*(text_list._p+idx),clipboard);
|
||||||
strcat(*(text_list._p+((unsigned long)(focus_p)-(unsigned long)(input_box_list._p))/sizeof(char*)),clipboard);
|
|
||||||
DrawInputBoxEx(focus);
|
DrawInputBoxEx(focus);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(c!=0&&focus_p!=NULL){
|
if(c!=0&&focus_p!=NULL){
|
||||||
|
|
||||||
@@ -612,9 +666,292 @@ int main(){
|
|||||||
|
|
||||||
ReDrawInputBoxList(&input_box_list,focus);
|
ReDrawInputBoxList(&input_box_list,focus);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case CREATE_WORLD_SCREEN:
|
||||||
|
|
||||||
|
if(button_list._p==NULL){
|
||||||
|
InitButtonList(&button_list,6);
|
||||||
|
InitInputBoxList(&input_box_list,2);
|
||||||
|
InitTextList(&text_list,2);
|
||||||
|
if(world_config.name[0]=='\0'){
|
||||||
|
snprintf(world_config.name,WORLD_NAME_MAX,"%s",_("create_world.default_name"));
|
||||||
|
}
|
||||||
|
snprintf(*(text_list._p),TEXT_MAX_LEN,"%s",world_config.name);
|
||||||
|
if(world_config.seed==0){
|
||||||
|
(*(text_list._p+1))[0]='\0';
|
||||||
|
}else{
|
||||||
|
snprintf(*(text_list._p+1),TEXT_MAX_LEN,"%llu",(unsigned long long)world_config.seed);
|
||||||
|
}
|
||||||
|
firstFrame = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float cw = (float)GetScreenWidth();
|
||||||
|
float ch = (float)GetScreenHeight();
|
||||||
|
float cx = cw*0.5f;
|
||||||
|
float cy = ch*0.5f;
|
||||||
|
float row = 70.0f*screen_scale;
|
||||||
|
float label_right = cx - 160.0f*screen_scale;
|
||||||
|
float ctrl_center = cx + 70.0f*screen_scale;
|
||||||
|
|
||||||
|
float y_title = cy - 3.5f*row;
|
||||||
|
float y_name = cy - 2.0f*row;
|
||||||
|
float y_seed = cy - 1.0f*row;
|
||||||
|
float y_diff = cy;
|
||||||
|
float y_ore = cy + 1.0f*row;
|
||||||
|
float y_real = cy + 2.0f*row;
|
||||||
|
float y_btn = cy + 3.6f*row;
|
||||||
|
|
||||||
|
float seed_pair_w = normal_button_size.x * 2.0f + 20.0f; // 420
|
||||||
|
float seed_left = ctrl_center - seed_pair_w * 0.5f * screen_scale; // ctrl_center - 210
|
||||||
|
float seed_right = seed_left + (normal_button_size.x + 20.0f) * screen_scale; // ctrl_center + 10
|
||||||
|
|
||||||
|
const char *diff_texts[DIFFICULTY_COUNT] = {
|
||||||
|
_("difficulty.easy"), _("difficulty.normal"),
|
||||||
|
_("difficulty.hard"), _("difficulty.brutal")
|
||||||
|
};
|
||||||
|
const char *ore_texts[ORE_COUNT] = {
|
||||||
|
_("ore.scarce"), _("ore.normal"),
|
||||||
|
_("ore.abundant"), _("ore.paradise")
|
||||||
|
};
|
||||||
|
const char *real_texts[REALISM_COUNT] = {
|
||||||
|
_("realism.casual"), _("realism.standard"), _("realism.hardcore")
|
||||||
|
};
|
||||||
|
|
||||||
|
if(IsWindowResized()||firstFrame){
|
||||||
|
|
||||||
|
InitAndDrawInputBox(*(input_box_list._p),
|
||||||
|
(struct Vector2){ctrl_center - wide_button_size.x*0.5f*screen_scale, y_name - normal_button_size.y*0.5f*screen_scale},
|
||||||
|
zoom(wide_button_size),
|
||||||
|
texture_list._p[LEFT_INPUT_BOX],texture_list._p[CENTER_INPUT_BOX],texture_list._p[RIGHT_INPUT_BOX],
|
||||||
|
font_25px,25*screen_scale,2*screen_scale,*(text_list._p));
|
||||||
|
|
||||||
|
InitAndDrawInputBox(*(input_box_list._p+1),
|
||||||
|
(struct Vector2){seed_left, y_seed - normal_button_size.y*0.5f*screen_scale},
|
||||||
|
zoom(normal_button_size),
|
||||||
|
texture_list._p[LEFT_INPUT_BOX],texture_list._p[CENTER_INPUT_BOX],texture_list._p[RIGHT_INPUT_BOX],
|
||||||
|
font_25px,25*screen_scale,2*screen_scale,*(text_list._p+1));
|
||||||
|
|
||||||
|
InitAndDrawButtonEx(*(button_list._p),
|
||||||
|
(struct Vector2){ctrl_center - wide_button_size.x*0.5f*screen_scale, y_diff - normal_button_size.y*0.5f*screen_scale},
|
||||||
|
zoom(wide_button_size),
|
||||||
|
texture_list._p[WIDE_BUTTON],texture_list._p[PRESSED_WIDE_BUTTON],
|
||||||
|
(char *)diff_texts[world_config.difficulty],
|
||||||
|
font_25px,25*screen_scale,2*screen_scale);
|
||||||
|
|
||||||
|
InitAndDrawButtonEx(*(button_list._p+1),
|
||||||
|
(struct Vector2){ctrl_center - wide_button_size.x*0.5f*screen_scale, y_ore - normal_button_size.y*0.5f*screen_scale},
|
||||||
|
zoom(wide_button_size),
|
||||||
|
texture_list._p[WIDE_BUTTON],texture_list._p[PRESSED_WIDE_BUTTON],
|
||||||
|
(char *)ore_texts[world_config.ore_abundance],
|
||||||
|
font_25px,25*screen_scale,2*screen_scale);
|
||||||
|
|
||||||
|
InitAndDrawButtonEx(*(button_list._p+2),
|
||||||
|
(struct Vector2){ctrl_center - wide_button_size.x*0.5f*screen_scale, y_real - normal_button_size.y*0.5f*screen_scale},
|
||||||
|
zoom(wide_button_size),
|
||||||
|
texture_list._p[WIDE_BUTTON],texture_list._p[PRESSED_WIDE_BUTTON],
|
||||||
|
(char *)real_texts[world_config.realism],
|
||||||
|
font_25px,25*screen_scale,2*screen_scale);
|
||||||
|
|
||||||
|
InitAndDrawButtonEx(*(button_list._p+3),
|
||||||
|
(struct Vector2){seed_right, y_seed - normal_button_size.y*0.5f*screen_scale},
|
||||||
|
zoom(normal_button_size),
|
||||||
|
texture_list._p[BUTTON],texture_list._p[PRESSED_BUTTON],
|
||||||
|
_("create_world.seed.random"),
|
||||||
|
font_20px,20*screen_scale,2*screen_scale);
|
||||||
|
|
||||||
|
InitAndDrawButtonEx(*(button_list._p+4),
|
||||||
|
(struct Vector2){cx - 120.0f*screen_scale - normal_button_size.x*0.5f*screen_scale, y_btn - normal_button_size.y*0.5f*screen_scale},
|
||||||
|
zoom(normal_button_size),
|
||||||
|
texture_list._p[BUTTON],texture_list._p[PRESSED_BUTTON],
|
||||||
|
_("back"),
|
||||||
|
font_25px,25*screen_scale,2*screen_scale);
|
||||||
|
|
||||||
|
InitAndDrawButtonEx(*(button_list._p+5),
|
||||||
|
(struct Vector2){cx + 120.0f*screen_scale - normal_button_size.x*0.5f*screen_scale, y_btn - normal_button_size.y*0.5f*screen_scale},
|
||||||
|
zoom(normal_button_size),
|
||||||
|
texture_list._p[BUTTON],texture_list._p[PRESSED_BUTTON],
|
||||||
|
_("create_world.create"),
|
||||||
|
font_25px,25*screen_scale,2*screen_scale);
|
||||||
|
|
||||||
|
firstFrame = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(background_type){
|
||||||
|
case COLOR:
|
||||||
|
ClearBackground(background_color);
|
||||||
|
break;
|
||||||
|
case IMAGE:
|
||||||
|
ClearBackground(background_color);
|
||||||
|
DrawTextureEx(background_image,background_pos,0,background_scale,WHITE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ClearBackground(background_color);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
struct Vector2 title_size = MeasureTextEx(font_25px,_("create_world.title"),25*screen_scale,2*screen_scale);
|
||||||
|
DrawTextEx(font_25px,_("create_world.title"),
|
||||||
|
(struct Vector2){cx - title_size.x*0.5f, y_title},
|
||||||
|
25*screen_scale,2*screen_scale,text_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_text_right(font_25px,_("create_world.name"), (struct Vector2){label_right,y_name},25*screen_scale,2*screen_scale,text_color);
|
||||||
|
draw_text_right(font_25px,_("create_world.seed"), (struct Vector2){label_right,y_seed},25*screen_scale,2*screen_scale,text_color);
|
||||||
|
draw_text_right(font_25px,_("create_world.difficulty"),(struct Vector2){label_right,y_diff},25*screen_scale,2*screen_scale,text_color);
|
||||||
|
draw_text_right(font_25px,_("create_world.ore"), (struct Vector2){label_right,y_ore},25*screen_scale,2*screen_scale,text_color);
|
||||||
|
draw_text_right(font_25px,_("create_world.realism"),(struct Vector2){label_right,y_real},25*screen_scale,2*screen_scale,text_color);
|
||||||
|
|
||||||
|
if(isButtonPressed(*(button_list._p))){
|
||||||
|
world_config.difficulty = (world_config.difficulty+1)%DIFFICULTY_COUNT;
|
||||||
|
InitAndDrawButtonEx(*(button_list._p),
|
||||||
|
(struct Vector2){ctrl_center - wide_button_size.x*0.5f*screen_scale, y_diff - normal_button_size.y*0.5f*screen_scale},
|
||||||
|
zoom(wide_button_size),
|
||||||
|
texture_list._p[WIDE_BUTTON],texture_list._p[PRESSED_WIDE_BUTTON],
|
||||||
|
(char *)diff_texts[world_config.difficulty],
|
||||||
|
font_25px,25*screen_scale,2*screen_scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isButtonPressed(*(button_list._p+1))){
|
||||||
|
world_config.ore_abundance = (world_config.ore_abundance+1)%ORE_COUNT;
|
||||||
|
InitAndDrawButtonEx(*(button_list._p+1),
|
||||||
|
(struct Vector2){ctrl_center - wide_button_size.x*0.5f*screen_scale, y_ore - normal_button_size.y*0.5f*screen_scale},
|
||||||
|
zoom(wide_button_size),
|
||||||
|
texture_list._p[WIDE_BUTTON],texture_list._p[PRESSED_WIDE_BUTTON],
|
||||||
|
(char *)ore_texts[world_config.ore_abundance],
|
||||||
|
font_25px,25*screen_scale,2*screen_scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isButtonPressed(*(button_list._p+2))){
|
||||||
|
world_config.realism = (world_config.realism+1)%REALISM_COUNT;
|
||||||
|
InitAndDrawButtonEx(*(button_list._p+2),
|
||||||
|
(struct Vector2){ctrl_center - wide_button_size.x*0.5f*screen_scale, y_real - normal_button_size.y*0.5f*screen_scale},
|
||||||
|
zoom(wide_button_size),
|
||||||
|
texture_list._p[WIDE_BUTTON],texture_list._p[PRESSED_WIDE_BUTTON],
|
||||||
|
(char *)real_texts[world_config.realism],
|
||||||
|
font_25px,25*screen_scale,2*screen_scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isButtonPressed(*(button_list._p+3))){
|
||||||
|
uint64_t s = ((uint64_t)(uint32_t)GetRandomValue(0,INT32_MAX)<<32)|(uint64_t)(uint32_t)GetRandomValue(0,INT32_MAX);
|
||||||
|
snprintf(*(text_list._p+1),TEXT_MAX_LEN,"%llu",(unsigned long long)s);
|
||||||
|
DrawInputBoxEx(*(input_box_list._p+1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if((IsKeyPressed(KEY_ESCAPE)&&focus==NULL)||isButtonPressed(*(button_list._p+4))){
|
||||||
|
snprintf(world_config.name,WORLD_NAME_MAX,"%s",*(text_list._p));
|
||||||
|
if(strlen(*(text_list._p+1))>0){
|
||||||
|
world_config.seed = strtoull(*(text_list._p+1),NULL,10);
|
||||||
|
}
|
||||||
|
UninButtonList(&button_list);
|
||||||
|
UninInputBoxList(&input_box_list);
|
||||||
|
UninTextList(&text_list);
|
||||||
|
focus = NULL;
|
||||||
|
focus_p = NULL;
|
||||||
|
screen = START_SCREEN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isButtonPressed(*(button_list._p+5))){
|
||||||
|
snprintf(world_config.name,WORLD_NAME_MAX,"%s",*(text_list._p));
|
||||||
|
if(strlen(*(text_list._p+1))==0){
|
||||||
|
world_config.seed = ((uint64_t)(uint32_t)GetRandomValue(0,INT32_MAX)<<32)|(uint64_t)(uint32_t)GetRandomValue(0,INT32_MAX);
|
||||||
|
}else{
|
||||||
|
world_config.seed = strtoull(*(text_list._p+1),NULL,10);
|
||||||
|
}
|
||||||
|
|
||||||
|
UninButtonList(&button_list);
|
||||||
|
UninInputBoxList(&input_box_list);
|
||||||
|
UninTextList(&text_list);
|
||||||
|
focus = NULL;
|
||||||
|
focus_p = NULL;
|
||||||
|
|
||||||
|
// 接入点:world_create(&world_config); screen = GAME_SCREEN;
|
||||||
|
screen = START_SCREEN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(IsKeyPressed(KEY_ESCAPE)&&focus!=NULL){
|
||||||
|
focus = NULL;
|
||||||
|
focus_p = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int c = GetCharPressed();
|
||||||
|
|
||||||
|
if(IsKeyPressed(KEY_BACKSPACE)&&focus!=NULL){
|
||||||
|
int idx = input_box_index(focus_p,&input_box_list);
|
||||||
|
if(idx>=0){
|
||||||
|
char *_p = *(text_list._p+idx);
|
||||||
|
int tail = strlen(_p)-1;
|
||||||
|
while(tail>0&&(_p[tail]&0xC0)==0x80) tail--;
|
||||||
|
_p[tail]='\0';
|
||||||
|
DrawInputBoxEx(focus);
|
||||||
|
}
|
||||||
|
}else if(IsKeyDown(KEY_BACKSPACE)&&focus!=NULL){
|
||||||
|
float dt = GetFrameTime();
|
||||||
|
if(backspaceHeld){
|
||||||
|
backspace_timer+=dt;
|
||||||
|
if(backspace_timer>0.05f){
|
||||||
|
backspace_timer-=0.05f;
|
||||||
|
int idx = input_box_index(focus_p,&input_box_list);
|
||||||
|
if(idx>=0){
|
||||||
|
char *_p = *(text_list._p+idx);
|
||||||
|
int tail = strlen(_p)-1;
|
||||||
|
while(tail>0&&(_p[tail]&0xC0)==0x80) tail--;
|
||||||
|
_p[tail]='\0';
|
||||||
|
DrawInputBoxEx(focus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
backspace_timer+=dt;
|
||||||
|
if(backspace_timer>0.5f){
|
||||||
|
backspaceHeld = true;
|
||||||
|
backspace_timer-=0.5f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else if(IsKeyReleased(KEY_BACKSPACE)){
|
||||||
|
backspaceHeld = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(IsKeyDown(KEY_LEFT_CONTROL)&&IsKeyPressed(KEY_V)&&focus!=NULL){
|
||||||
|
const char *clipboard = GetClipboardText();
|
||||||
|
int idx = input_box_index(focus_p,&input_box_list);
|
||||||
|
if(idx>=0 && strlen(*(text_list._p+idx))+strlen(clipboard)<TEXT_MAX_LEN){
|
||||||
|
strcat(*(text_list._p+idx),clipboard);
|
||||||
|
DrawInputBoxEx(focus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(c!=0&&focus_p!=NULL){
|
||||||
|
while(c>0){
|
||||||
|
int idx = input_box_index(focus_p,&input_box_list);
|
||||||
|
if(idx>=0){
|
||||||
|
char *_p = *(text_list._p+idx);
|
||||||
|
if(c>=32){
|
||||||
|
char utf8[5] = {0};
|
||||||
|
int bytes = CodepointToUtf8(c,utf8);
|
||||||
|
if(strlen(_p)+bytes<TEXT_MAX_LEN-1){
|
||||||
|
strcat(_p,utf8);
|
||||||
|
_p[strlen(_p)]='\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c = GetCharPressed();
|
||||||
|
}
|
||||||
|
DrawInputBoxEx(focus);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(focus==NULL){
|
||||||
|
focus = WhichInputBoxIsPressed(&input_box_list,&focus_p);
|
||||||
|
}else if(IsUnFocusInputBox(focus)){
|
||||||
|
focus = WhichInputBoxIsPressed(&input_box_list,&focus_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReDrawButtonList(&button_list);
|
||||||
|
ReDrawInputBoxList(&input_box_list,focus);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsWindowResized()&&background_type==IMAGE){
|
if (IsWindowResized()&&background_type==IMAGE){
|
||||||
|
|||||||
+35
-1
@@ -50,7 +50,8 @@ enum{
|
|||||||
START_SCREEN,
|
START_SCREEN,
|
||||||
SETTING_SCREEN,
|
SETTING_SCREEN,
|
||||||
SETTING_BACKGROUND_SCREEN,
|
SETTING_BACKGROUND_SCREEN,
|
||||||
EXIT_SCREEN
|
EXIT_SCREEN,
|
||||||
|
CREATE_WORLD_SCREEN
|
||||||
}screen=START_SCREEN;
|
}screen=START_SCREEN;
|
||||||
|
|
||||||
extern const char *texture_path_list[];
|
extern const char *texture_path_list[];
|
||||||
@@ -67,6 +68,39 @@ enum {
|
|||||||
CENTER_INPUT_BOX
|
CENTER_INPUT_BOX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
DIFFICULTY_EASY,
|
||||||
|
DIFFICULTY_NORMAL,
|
||||||
|
DIFFICULTY_HARD,
|
||||||
|
DIFFICULTY_BRUTAL,
|
||||||
|
DIFFICULTY_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ORE_SCARCE,
|
||||||
|
ORE_NORMAL,
|
||||||
|
ORE_ABUNDANT,
|
||||||
|
ORE_PARADISE,
|
||||||
|
ORE_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
REALISM_CASUAL,
|
||||||
|
REALISM_STANDARD,
|
||||||
|
REALISM_HARDCORE,
|
||||||
|
REALISM_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
#define WORLD_NAME_MAX 64
|
||||||
|
|
||||||
|
struct World_Config {
|
||||||
|
char name[WORLD_NAME_MAX];
|
||||||
|
uint64_t seed;
|
||||||
|
int difficulty;
|
||||||
|
int ore_abundance;
|
||||||
|
int realism;
|
||||||
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ENGLISH,
|
ENGLISH,
|
||||||
SIMPLIFIED_CHINESE
|
SIMPLIFIED_CHINESE
|
||||||
|
|||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
#include "noise.h"
|
||||||
|
#include "random.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
static uint64_t coord_hash(uint64_t seed, int type, int x, int y) {
|
||||||
|
uint64_t sub = ((uint64_t)(uint32_t)x << 32) | (uint64_t)(uint32_t)y;
|
||||||
|
return game_hash(seed, (uint64_t)type, sub);
|
||||||
|
}
|
||||||
|
|
||||||
|
static double hash_unit(uint64_t h) {
|
||||||
|
return (double)h / (double)UINT64_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double smoothstep(double t) {
|
||||||
|
return t * t * (3.0 - 2.0 * t);
|
||||||
|
}
|
||||||
|
|
||||||
|
double value_noise(uint64_t seed, int type, double x, double y, double scale) {
|
||||||
|
double fx = x / scale;
|
||||||
|
double fy = y / scale;
|
||||||
|
int ix = (int)floor(fx);
|
||||||
|
int iy = (int)floor(fy);
|
||||||
|
double tx = smoothstep(fx - ix);
|
||||||
|
double ty = smoothstep(fy - iy);
|
||||||
|
|
||||||
|
double v00 = hash_unit(coord_hash(seed, type, ix, iy));
|
||||||
|
double v10 = hash_unit(coord_hash(seed, type, ix + 1, iy));
|
||||||
|
double v01 = hash_unit(coord_hash(seed, type, ix, iy + 1));
|
||||||
|
double v11 = hash_unit(coord_hash(seed, type, ix + 1, iy + 1));
|
||||||
|
|
||||||
|
double a = v00 * (1.0 - tx) + v10 * tx;
|
||||||
|
double b = v01 * (1.0 - tx) + v11 * tx;
|
||||||
|
return a * (1.0 - ty) + b * ty;
|
||||||
|
}
|
||||||
|
|
||||||
|
double fractal_noise(uint64_t seed, int type, double x, double y,
|
||||||
|
double scale, int octaves, double persistence) {
|
||||||
|
double total = 0.0;
|
||||||
|
double amplitude = 1.0;
|
||||||
|
double max_value = 0.0;
|
||||||
|
for (int i = 0; i < octaves; i++) {
|
||||||
|
// 关键:用 type*64 + i 作为子通道,避免不同矿物之间的倍频互相干扰
|
||||||
|
total += value_noise(seed, type * 64 + i, x, y, scale) * amplitude;
|
||||||
|
max_value += amplitude;
|
||||||
|
amplitude *= persistence;
|
||||||
|
scale *= 0.5;
|
||||||
|
}
|
||||||
|
return total / max_value;
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef TERRAIN_NOISE_H
|
||||||
|
#define TERRAIN_NOISE_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// 双线性值噪声:在整数格点取随机值,格点之间用 smoothstep 插值,输出 0–1
|
||||||
|
double value_noise(uint64_t seed, int type, double x, double y, double scale);
|
||||||
|
|
||||||
|
// 分形噪声:多个倍频叠加,输出 0–1
|
||||||
|
double fractal_noise(uint64_t seed, int type, double x, double y,
|
||||||
|
double scale, int octaves, double persistence);
|
||||||
|
|
||||||
|
#endif
|
||||||
+10
-15
@@ -1,18 +1,13 @@
|
|||||||
#include "random.h"
|
#include "random.h"
|
||||||
|
|
||||||
uint64_t game_hash(uint64_t seed,int type,int subtype){
|
uint64_t game_hash(uint64_t seed, uint64_t type, uint64_t subtype) {
|
||||||
if(type==0){
|
// 把 type 和 subtype 混合成一个 64 位的 offset
|
||||||
splitmix64_seed(seed);
|
uint64_t offset = subtype;
|
||||||
return splitmix64();
|
offset ^= type * UINT64_C(0x9E3779B97F4A7C15);
|
||||||
}else if(subtype==0){
|
offset = (offset ^ (offset >> 30)) * UINT64_C(0xBF58476D1CE4E5B9);
|
||||||
uint64_t new_seed = splitmix64_stateless(seed, type);
|
offset = (offset ^ (offset >> 27)) * UINT64_C(0x94D049BB133111EB);
|
||||||
splitmix64_seed(new_seed);
|
offset ^= offset >> 31;
|
||||||
return splitmix64();
|
|
||||||
}
|
|
||||||
uint64_t offset = ((uint64_t)type << 32) | (uint64_t)subtype;
|
|
||||||
uint64_t new_seed = splitmix64_stateless(seed, offset);
|
|
||||||
splitmix64_seed(new_seed);
|
|
||||||
return splitmix64();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// splitmix64_stateless 是纯函数,不修改全局状态
|
||||||
|
return splitmix64_stateless(seed, offset);
|
||||||
|
}
|
||||||
+14
-2
@@ -12,9 +12,21 @@ enum {
|
|||||||
PLATE_THICK,
|
PLATE_THICK,
|
||||||
PLATE_SPEED_X,
|
PLATE_SPEED_X,
|
||||||
PLATE_SPEED_Y,
|
PLATE_SPEED_Y,
|
||||||
PLATE_AGE
|
PLATE_AGE,
|
||||||
|
PLATE_HEIGHT,
|
||||||
|
CHUNK_NOISE_MED,
|
||||||
|
CHUNK_NOISE_FINE,
|
||||||
|
CHUNK_NOISE_DETAIL,
|
||||||
|
CHUNK_NOISE_MOIST,
|
||||||
|
CHUNK_NOISE_ORE_CU,
|
||||||
|
CHUNK_NOISE_ORE_SN,
|
||||||
|
CHUNK_NOISE_ORE_FE,
|
||||||
|
CHUNK_NOISE_ORE_CO,
|
||||||
|
CHUNK_NOISE_ORE_AU,
|
||||||
|
CHUNK_NOISE_ROCK,
|
||||||
|
CHUNK_NOISE_MINERAL_BASE // 每个矿物占一个通道,共 MINERAL_COUNT 个
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t game_hash(uint64_t seed,int type,int subtype);
|
uint64_t game_hash(uint64_t seed, uint64_t type, uint64_t subtype);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+118
-4
@@ -100,11 +100,11 @@ static void plate_thick(struct Plate_list _i,uint64_t seed){
|
|||||||
static void plate_speed(struct Plate_list _i,uint64_t seed){
|
static void plate_speed(struct Plate_list _i,uint64_t seed){
|
||||||
for(int i=0;i<_i.count;i++){
|
for(int i=0;i<_i.count;i++){
|
||||||
if((_i._p+i)->is_ocean){
|
if((_i._p+i)->is_ocean){
|
||||||
(_i._p+i)->speed.x=1+(double)game_hash(seed,PLATE_SPEED_X,i)/UINT64_MAX*9;
|
(_i._p+i)->speed.x=(double)game_hash(seed,PLATE_SPEED_X,i)/UINT64_MAX*20-10;
|
||||||
(_i._p+i)->speed.y=1+(double)game_hash(seed,PLATE_SPEED_Y,i)/UINT64_MAX*9;
|
(_i._p+i)->speed.y=(double)game_hash(seed,PLATE_SPEED_Y,i)/UINT64_MAX*20-10;
|
||||||
}else{
|
}else{
|
||||||
(_i._p+i)->speed.x=(double)game_hash(seed,PLATE_SPEED_X,i)/UINT64_MAX*5;
|
(_i._p+i)->speed.x=(double)game_hash(seed,PLATE_SPEED_X,i)/UINT64_MAX*10-5;
|
||||||
(_i._p+i)->speed.y=(double)game_hash(seed,PLATE_SPEED_Y,i)/UINT64_MAX*5;
|
(_i._p+i)->speed.y=(double)game_hash(seed,PLATE_SPEED_Y,i)/UINT64_MAX*10-5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,6 +119,118 @@ static void plate_age(struct Plate_list _i,uint64_t seed){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double block_dist(int i,int j) {
|
||||||
|
double ix=WORLD_BLOCK_SIZE*(i%WORLD_BLOCK_COUNT_X);
|
||||||
|
double iy=WORLD_BLOCK_SIZE*(i/WORLD_BLOCK_COUNT_X);
|
||||||
|
double jx=WORLD_BLOCK_SIZE*(j%WORLD_BLOCK_COUNT_X);
|
||||||
|
double jy=WORLD_BLOCK_SIZE*(j/WORLD_BLOCK_COUNT_X);
|
||||||
|
double dx=fabs(ix-jx);
|
||||||
|
if (dx>WORLD_W/2) dx=WORLD_W-dx;
|
||||||
|
double dy=fabs(iy-jy);
|
||||||
|
return sqrt(dx*dx+dy*dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct Vector2_double block_dir(int i,int j) {
|
||||||
|
double ix=WORLD_BLOCK_SIZE*(i%WORLD_BLOCK_COUNT_X);
|
||||||
|
double iy=WORLD_BLOCK_SIZE*(i/WORLD_BLOCK_COUNT_X);
|
||||||
|
double jx=WORLD_BLOCK_SIZE*(j%WORLD_BLOCK_COUNT_X);
|
||||||
|
double jy=WORLD_BLOCK_SIZE*(j/WORLD_BLOCK_COUNT_X);
|
||||||
|
double dx=jx-ix;
|
||||||
|
if (dx>WORLD_W/2) dx -= WORLD_W;
|
||||||
|
if (dx<-WORLD_W/2) dx+=WORLD_W;
|
||||||
|
double dy=jy-iy;
|
||||||
|
double len=sqrt(dx*dx+dy*dy);
|
||||||
|
struct Vector2_double v;
|
||||||
|
if (len<1e-9) { v.x=0;v.y=0;}
|
||||||
|
else { v.x=dx/len;v.y=dy/len;}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void plate_boundary_find(struct World_Block *_p,struct Plate_list _i) {
|
||||||
|
for (int i=0;i<WORLD_BLOCK_COUNT;i++) {
|
||||||
|
(_p+i)->boundary_dist=WORLD_W;
|
||||||
|
(_p+i)->other_plate_id=-1;
|
||||||
|
(_p+i)->boundary_normal.x=0;
|
||||||
|
(_p+i)->boundary_normal.y=0;
|
||||||
|
int ix=i%WORLD_BLOCK_COUNT_X;
|
||||||
|
int iy=i/WORLD_BLOCK_COUNT_X;
|
||||||
|
int my_plate=(_p+i)->plate_id;
|
||||||
|
double best_dist=WORLD_W;
|
||||||
|
int best_j=-1;
|
||||||
|
for (int dy=-PLATE_SEARCH_RADIUS;dy<=PLATE_SEARCH_RADIUS;dy++) {
|
||||||
|
int jy=iy+dy;
|
||||||
|
if (jy<0 || jy>=WORLD_BLOCK_COUNT_Y) continue;
|
||||||
|
for (int dx=-PLATE_SEARCH_RADIUS;dx<=PLATE_SEARCH_RADIUS;dx++) {
|
||||||
|
if (dx == 0 && dy == 0) continue;
|
||||||
|
int jx=(ix+dx+WORLD_BLOCK_COUNT_X)%WORLD_BLOCK_COUNT_X;
|
||||||
|
int j=jy*WORLD_BLOCK_COUNT_X+jx;
|
||||||
|
if ((_p+j)->plate_id == my_plate) continue;
|
||||||
|
double d=block_dist(i,j);
|
||||||
|
if (d<best_dist) {
|
||||||
|
best_dist=d;
|
||||||
|
best_j=j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (best_j>=0) {
|
||||||
|
(_p+i)->boundary_dist=best_dist;
|
||||||
|
(_p+i)->other_plate_id=(_p+best_j)->plate_id;
|
||||||
|
(_p+i)->boundary_normal=block_dir(i,best_j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static double plate_base_elev(struct Plate *p) {
|
||||||
|
if (p->is_ocean) {
|
||||||
|
return -2000.0-(p->age/200.0)*2000.0-(p->thick-5.0)*400.0;
|
||||||
|
} else {
|
||||||
|
return 200.0+(p->thick-30.0)*20.0+(p->age/4000.0)*500.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static double plate_boundary_elev(struct Plate *my,struct Plate *other,double conv,double dist) {
|
||||||
|
double decay=exp(-dist/PLATE_BOUNDARY_INFLUENCE);
|
||||||
|
double elev=0;
|
||||||
|
if (conv>0) {
|
||||||
|
if (!my->is_ocean && !other->is_ocean) {
|
||||||
|
double tf=(my->thick+other->thick)/100.0;
|
||||||
|
elev=conv*400.0*tf*decay;
|
||||||
|
} else if (!my->is_ocean && other->is_ocean) {
|
||||||
|
elev=conv*250.0*decay;
|
||||||
|
} else if (my->is_ocean && !other->is_ocean) {
|
||||||
|
elev=-conv*400.0*decay;
|
||||||
|
} else {
|
||||||
|
elev=conv*200.0*decay;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!my->is_ocean && !other->is_ocean) {
|
||||||
|
elev=conv*150.0*decay;
|
||||||
|
} else if (my->is_ocean && other->is_ocean) {
|
||||||
|
elev=-conv*250.0*decay;
|
||||||
|
} else {
|
||||||
|
elev=conv*50.0*decay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return elev;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void plate_elevation(struct World_Block *_p,struct Plate_list _i,uint64_t seed) {
|
||||||
|
for (int i=0;i<WORLD_BLOCK_COUNT;i++) {
|
||||||
|
struct Plate *my=_i._p+(_p+i)->plate_id;
|
||||||
|
double elev=plate_base_elev(my);
|
||||||
|
if ((_p+i)->other_plate_id>=0) {
|
||||||
|
struct Plate *other=_i._p+(_p+i)->other_plate_id;
|
||||||
|
double rel_x=my->speed.x-other->speed.x;
|
||||||
|
double rel_y=my->speed.y-other->speed.y;
|
||||||
|
double conv=rel_x*(_p+i)->boundary_normal.x+rel_y*(_p+i)->boundary_normal.y;
|
||||||
|
elev+=plate_boundary_elev(my,other,conv,(_p+i)->boundary_dist);
|
||||||
|
}
|
||||||
|
double noise=((double)game_hash(seed,PLATE_HEIGHT,i)/UINT64_MAX-0.5)*200.0;
|
||||||
|
elev+=noise;
|
||||||
|
(_p+i)->elevation=elev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Plate_list plate_init(uint64_t seed, struct World_Block *block){
|
struct Plate_list plate_init(uint64_t seed, struct World_Block *block){
|
||||||
int count = plate_count(seed);
|
int count = plate_count(seed);
|
||||||
struct Plate_list list;
|
struct Plate_list list;
|
||||||
@@ -131,5 +243,7 @@ struct Plate_list plate_init(uint64_t seed,struct World_Block *block){
|
|||||||
plate_thick(list,seed);
|
plate_thick(list,seed);
|
||||||
plate_speed(list,seed);
|
plate_speed(list,seed);
|
||||||
plate_age(list,seed);
|
plate_age(list,seed);
|
||||||
|
plate_boundary_find(block, list);
|
||||||
|
plate_elevation(block, list, seed);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
+17
-5
@@ -15,12 +15,25 @@
|
|||||||
#define WORLD_BLOCK_COUNT_X (WORLD_W/WORLD_BLOCK_SIZE)
|
#define WORLD_BLOCK_COUNT_X (WORLD_W/WORLD_BLOCK_SIZE)
|
||||||
#define WORLD_BLOCK_COUNT_Y (WORLD_H/WORLD_BLOCK_SIZE)
|
#define WORLD_BLOCK_COUNT_Y (WORLD_H/WORLD_BLOCK_SIZE)
|
||||||
#define WORLD_BLOCK_COUNT (WORLD_BLOCK_COUNT_X*WORLD_BLOCK_COUNT_Y)
|
#define WORLD_BLOCK_COUNT (WORLD_BLOCK_COUNT_X*WORLD_BLOCK_COUNT_Y)
|
||||||
|
#define PLATE_BOUNDARY_INFLUENCE (WORLD_BLOCK_SIZE * 4)
|
||||||
|
#define PLATE_SEARCH_RADIUS 20
|
||||||
|
|
||||||
struct Vector2_double {
|
struct Vector2_double {
|
||||||
double x;
|
double x;
|
||||||
double y;
|
double y;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum Rock_Type {
|
||||||
|
ROCK_GRANITE = 0,
|
||||||
|
ROCK_BASALT,
|
||||||
|
ROCK_LIMESTONE,
|
||||||
|
ROCK_SANDSTONE,
|
||||||
|
ROCK_SHALE,
|
||||||
|
ROCK_SCHIST,
|
||||||
|
ROCK_GNEISS,
|
||||||
|
ROCK_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
struct Vector3_double {
|
struct Vector3_double {
|
||||||
double x;
|
double x;
|
||||||
double y;
|
double y;
|
||||||
@@ -49,11 +62,10 @@ struct Plate_list {
|
|||||||
struct World_Block {
|
struct World_Block {
|
||||||
int plate_id;
|
int plate_id;
|
||||||
double nearest_plate_dist;
|
double nearest_plate_dist;
|
||||||
int north_plate_id;
|
double elevation;
|
||||||
int south_plate_id;
|
double boundary_dist;
|
||||||
int west_plate_id;
|
int other_plate_id;
|
||||||
int east_plate_id;
|
struct Vector2_double boundary_normal;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct World {
|
struct World {
|
||||||
|
|||||||
@@ -90,7 +90,12 @@ struct Vector2 zoom(struct Vector2 _i){
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct Vector2 button_in_grid_pos(struct Vector2 center,struct Vector2 size,struct Vector2 index,struct Vector2 button_size){
|
struct Vector2 button_in_grid_pos(struct Vector2 center,struct Vector2 size,struct Vector2 index,struct Vector2 button_size){
|
||||||
return (struct Vector2){((index.x-size.x)*20+(index.x-1-size.x*0.5f)*button_size.x)*screen_scale+center.x,((index.y-size.y)*20+(index.y-1-size.y*0.5f)*button_size.y)*screen_scale+center.y};
|
const float gap = 20.0f;
|
||||||
|
float total_w = size.x * button_size.x + (size.x - 1.0f) * gap;
|
||||||
|
float total_h = size.y * button_size.y + (size.y - 1.0f) * gap;
|
||||||
|
float px = center.x + (-total_w * 0.5f + (index.x - 1.0f) * (button_size.x + gap)) * screen_scale;
|
||||||
|
float py = center.y + (-total_h * 0.5f + (index.y - 1.0f) * (button_size.y + gap)) * screen_scale;
|
||||||
|
return (struct Vector2){px, py};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isButtonPressed(const struct Button *button){
|
bool isButtonPressed(const struct Button *button){
|
||||||
@@ -142,17 +147,12 @@ void DrawInputBoxEx(struct Input_Box *box){
|
|||||||
DrawTextureEx(box->right_texture,(Vector2){ box->pos.x + box->size.x - box->scale * tileWidth, box->pos.y },0.0f, box->scale, WHITE);
|
DrawTextureEx(box->right_texture,(Vector2){ box->pos.x + box->size.x - box->scale * tileWidth, box->pos.y },0.0f, box->scale, WHITE);
|
||||||
|
|
||||||
float limitWidth = box->size.x - box->size.y * 0.5f;
|
float limitWidth = box->size.x - box->size.y * 0.5f;
|
||||||
|
|
||||||
box->cuted_len = find_min_skip(box->text, limitWidth, box->font, box->fontSize, box->spacing);
|
box->cuted_len = find_min_skip(box->text, limitWidth, box->font, box->fontSize, box->spacing);
|
||||||
if(half_clock){
|
|
||||||
snprintf(box->text_show, TEXT_MAX_LEN, "%s_", box->text + box->cuted_len);
|
|
||||||
}else{
|
|
||||||
snprintf(box->text_show, TEXT_MAX_LEN, "%s ", box->text + box->cuted_len);
|
|
||||||
}
|
|
||||||
box->last_text = box->text;
|
box->last_text = box->text;
|
||||||
box->last_limit_width = limitWidth;
|
box->last_limit_width = limitWidth;
|
||||||
box->last_font_size = box->fontSize;
|
box->last_font_size = box->fontSize;
|
||||||
|
|
||||||
|
snprintf(box->text_show, TEXT_MAX_LEN, "%s ", box->text + box->cuted_len);
|
||||||
DrawTextEx(box->font, box->text_show, box->pos_text_fixed,box->fontSize, box->spacing, text_color);
|
DrawTextEx(box->font, box->text_show, box->pos_text_fixed,box->fontSize, box->spacing, text_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,6 +187,13 @@ void ReDrawInputBox(struct Input_Box *box,const struct Input_Box *focus){
|
|||||||
DrawTextureEx(box->center_texture,(Vector2){ box->pos.x + box->scale * i, box->pos.y },0.0f, box->scale, WHITE);
|
DrawTextureEx(box->center_texture,(Vector2){ box->pos.x + box->scale * i, box->pos.y },0.0f, box->scale, WHITE);
|
||||||
}
|
}
|
||||||
DrawTextureEx(box->right_texture,(Vector2){ box->pos.x + box->size.x - box->scale * tileWidth, box->pos.y },0.0f, box->scale, WHITE);
|
DrawTextureEx(box->right_texture,(Vector2){ box->pos.x + box->size.x - box->scale * tileWidth, box->pos.y },0.0f, box->scale, WHITE);
|
||||||
|
|
||||||
|
float limitWidth = box->size.x - box->size.y * 0.5f;
|
||||||
|
box->cuted_len = find_min_skip(box->text, limitWidth, box->font, box->fontSize, box->spacing);
|
||||||
|
box->last_text = box->text;
|
||||||
|
box->last_limit_width = limitWidth;
|
||||||
|
box->last_font_size = box->fontSize;
|
||||||
|
|
||||||
if(half_clock && focus == box){
|
if(half_clock && focus == box){
|
||||||
snprintf(box->text_show, TEXT_MAX_LEN, "%s_", box->text + box->cuted_len);
|
snprintf(box->text_show, TEXT_MAX_LEN, "%s_", box->text + box->cuted_len);
|
||||||
}else{
|
}else{
|
||||||
@@ -292,3 +299,8 @@ struct Input_Box *WhichInputBoxIsPressed(struct Input_Box_list *_ib,struct Input
|
|||||||
}
|
}
|
||||||
return _o;
|
return _o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int input_box_index(struct Input_Box **focus_p, struct Input_Box_list *list){
|
||||||
|
if(focus_p == NULL || list == NULL || list->_p == NULL) return -1;
|
||||||
|
return (int)(focus_p - list->_p);
|
||||||
|
}
|
||||||
@@ -82,5 +82,6 @@ void ReDrawButtonList(struct Button_list *_bl);
|
|||||||
void ReDrawInputBoxList(struct Input_Box_list *_ib,const struct Input_Box *focus);
|
void ReDrawInputBoxList(struct Input_Box_list *_ib,const struct Input_Box *focus);
|
||||||
bool IsUnFocusInputBox(const struct Input_Box *focus);
|
bool IsUnFocusInputBox(const struct Input_Box *focus);
|
||||||
struct Input_Box *WhichInputBoxIsPressed(struct Input_Box_list *_ib,struct Input_Box ***_focus);
|
struct Input_Box *WhichInputBoxIsPressed(struct Input_Box_list *_ib,struct Input_Box ***_focus);
|
||||||
|
int input_box_index(struct Input_Box **focus_p, struct Input_Box_list *list);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user