forked from Cubitect/cubiomes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.c
More file actions
211 lines (193 loc) · 9.6 KB
/
Copy pathserver.c
File metadata and controls
211 lines (193 loc) · 9.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include "finders.h"
#include "generator.h"
#include "math.h"
long viable_count = 0;
long passed_filter = 0;
float step = 8;
int main(int argc, char *argv[])
{
initBiomes();
int64_t s;
unsigned int range, fullrange;
BiomeFilter filter;
int minscale;
if (argc <= 1 || sscanf(argv[1], "%" PRId64, &s) != 1)
{
printf("Seed start: ");
if (!scanf("%" SCNd64, &s))
{
printf("That's not right");
exit(1);
}
}
if (argc <= 2 || sscanf(argv[2], "%u", &range) != 1)
{
printf("Filter radius: ");
if (!scanf("%i", &range))
{
printf("That's not right");
exit(1);
}
}
if (argc <= 3 || sscanf(argv[3], "%u", &fullrange) != 1)
{
printf("Full radius: ");
if (!scanf("%i", &fullrange))
{
printf("That's not right");
exit(1);
}
}
enum BiomeID biomes[] = {ice_spikes, bamboo_jungle, desert, plains, ocean, jungle, forest, mushroom_fields, mesa, flower_forest, warm_ocean, frozen_ocean, megaTaiga, roofedForest, extremeHills, swamp, savanna, icePlains};
filter = setupBiomeFilter(biomes,
sizeof(biomes) / sizeof(enum BiomeID));
minscale = 256; // terminate search at this layer scale
// TODO: simple structure filter
int ax = -range, az = -range;
int w = 2 * range, h = 2 * range;
int fw = 2 * fullrange, fh = 2 * fullrange;
LayerStack g = setupGenerator(MC_1_15);
int *cache = allocCache(&g.layers[L_VORONOI_ZOOM_1], w, h);
if (!checkForBiomes(&g, cache, s, ax, az, w, h, filter, minscale))
return 1;
passed_filter++;
applySeed(&g, s);
int x, z;
//Pos goodhuts[2];
int hut_count = 0;
Pos huts[100];
int huts_found = 0;
int r = fullrange / SWAMP_HUT_CONFIG.regionSize;
for (z = -r; z < r; z++)
{
for (x = -r; x < r; x++)
{
Pos p;
p = getStructurePos(SWAMP_HUT_CONFIG, s, x, z);
if (isViableFeaturePos(Swamp_Hut, g, cache, p.x, p.z))
{
if (abs(p.x) < fullrange && abs(p.z) < fullrange)
{
huts[hut_count] = p;
hut_count++;
//printf("%i\n", huts[0].x);
for (int i = 0; i < hut_count; i++)
{
for (int j = 0; j < hut_count; j++)
{
if (j == i)
continue;
float dx, dz;
dx = abs(huts[i].x - huts[j].x);
dz = abs(huts[i].z - huts[j].z);
if (sqrt((dx * dx) + (dz * dz)) <= 200)
{
//goodhuts[0] = huts[i];
//goodhuts[1] = huts[j];
huts_found = 1;
}
}
}
}
}
}
}
if (!huts_found)
return 1;
int monument_count = 0;
r = fullrange / MONUMENT_CONFIG.regionSize;
for (z = -r; z < r; z++)
{
for (x = -r; x < r; x++)
{
Pos p;
p = getLargeStructurePos(MONUMENT_CONFIG, s, x, z);
if (isViableOceanMonumentPos(g, cache, p.x, p.z))
if (abs(p.x) < fullrange && abs(p.z) < fullrange)
monument_count++;
}
}
if (monument_count == 0)
return 1;
int ocean_count = 0;
// biome enum defined in layers.h
enum BiomeID req_biomes[] = {ice_spikes, bamboo_jungle, desert, plains, ocean, jungle, forest, mushroom_fields, mesa, flower_forest, warm_ocean, frozen_ocean, megaTaiga, roofedForest, extremeHills, swamp, savanna, icePlains};
int biome_exists[sizeof(req_biomes) / sizeof(enum BiomeID)] = {0};
enum BiomeID biome_percent[] = {badlands, badlands_plateau, bamboo_jungle, bamboo_jungle_hills, basalt_deltas, beach, birch_forest, birch_forest_hills, cold_ocean, crimson_forest, dark_forest, dark_forest_hills, deep_cold_ocean, deep_frozen_ocean, deep_lukewarm_ocean, deep_ocean, deep_warm_ocean, desert, desert_hills, desert_lakes, end_barrens, end_highlands, end_midlands, eroded_badlands, flower_forest, forest, frozen_ocean, frozen_river, giant_spruce_taiga, giant_spruce_taiga_hills, giant_tree_taiga, giant_tree_taiga_hills, gravelly_mountains, ice_spikes, jungle, jungle_edge, jungle_hills, lukewarm_ocean, modified_badlands_plateau, modified_gravelly_mountains, modified_jungle, modified_jungle_edge, modified_wooded_badlands_plateau, mountain_edge, mountains, mushroom_fields, mushroom_field_shore, nether_wastes, ocean, plains, river, savanna, savanna_plateau, shattered_savanna, shattered_savanna_plateau, small_end_islands, snowy_beach, snowy_mountains, snowy_taiga, snowy_taiga_hills, snowy_taiga_mountains, snowy_tundra, soul_sand_valley, stone_shore, sunflower_plains, swamp, swamp_hills, taiga, taiga_hills, taiga_mountains, tall_birch_forest, tall_birch_hills, the_end, the_void, warm_ocean, warped_forest, wooded_badlands_plateau, wooded_hills, wooded_mountains};
char *biome_percent_string[sizeof(biome_percent) / sizeof(enum BiomeID)] = {"badlands", "badlands_plateau", "bamboo_jungle", "bamboo_jungle_hills", "basalt_deltas", "beach", "birch_forest", "birch_forest_hills", "cold_ocean", "crimson_forest", "dark_forest", "dark_forest_hills", "deep_cold_ocean", "deep_frozen_ocean", "deep_lukewarm_ocean", "deep_ocean", "deep_warm_ocean", "desert", "desert_hills", "desert_lakes", "end_barrens", "end_highlands", "end_midlands", "eroded_badlands", "flower_forest", "forest", "frozen_ocean", "frozen_river", "giant_spruce_taiga", "giant_spruce_taiga_hills", "giant_tree_taiga", "giant_tree_taiga_hills", "gravelly_mountains", "ice_spikes", "jungle", "jungle_edge", "jungle_hills", "lukewarm_ocean", "modified_badlands_plateau", "modified_gravelly_mountains", "modified_jungle", "modified_jungle_edge", "modified_wooded_badlands_plateau", "mountain_edge", "mountains", "mushroom_fields", "mushroom_field_shore", "nether_wastes", "ocean", "plains", "river", "savanna", "savanna_plateau", "shattered_savanna", "shattered_savanna_plateau", "small_end_islands", "snowy_beach", "snowy_mountains", "snowy_taiga", "snowy_taiga_hills", "snowy_taiga_mountains", "snowy_tundra", "soul_sand_valley", "stone_shore", "sunflower_plains", "swamp", "swamp_hills", "taiga", "taiga_hills", "taiga_mountains", "tall_birch_forest", "tall_birch_hills", "the_end", "the_void", "warm_ocean", "warped_forest", "wooded_badlands_plateau", "wooded_hills", "wooded_mountains"};
int biome_percent_counter[sizeof(biome_percent) / sizeof(enum BiomeID)] = {0};
r = fullrange;
for (z = -r; z < r; z += step)
{
for (x = -r; x < r; x += step)
{
Pos p = {x, z};
int biome = getBiomeAtPos(g, p);
if (isOceanic(biome))
ocean_count++;
if (abs(x) < range && abs(z) < range)
for (int i = 0; i < sizeof(biome_exists) / sizeof(int); i++)
if (biome == req_biomes[i])
biome_exists[i] = -1;
for (int i = 0; i < sizeof(biome_percent) / sizeof(enum BiomeID); i++)
if (biome == biome_percent[i])
biome_percent_counter[i]++;
}
}
//verify all biomes are present
int all_biomes = 1;
for (int i = 0; i < sizeof(req_biomes) / sizeof(enum BiomeID); i++)
if (biome_exists[i] != -1)
all_biomes = 0;
if (!all_biomes)
return 1;
//get spawn biome
Pos spawn = getSpawn(MC_1_15, &g, cache, s);
int spawn_biome = getBiomeAtPos(g, spawn);
char *spawn_biome_string;
for (int i = 0; i < sizeof(biome_percent) / sizeof(enum BiomeID); i++)
if (spawn_biome == biome_percent[i])
spawn_biome_string = biome_percent_string[i];
//get closest village
Pos villages[500] = {0};
int village_count = 0;
r = fullrange / VILLAGE_CONFIG.regionSize;
for (z = -r; z < r; z++)
{
for (x = -r; x < r; x++)
{
Pos p;
p = getLargeStructurePos(VILLAGE_CONFIG, s, x, z);
if (isViableVillagePos(g, cache, p.x, p.z))
if (abs(p.x) < fullrange && abs(p.z) < fullrange)
villages[village_count++] = p;
}
}
//Pos closest_village;
int closest_village_distance = -1;
for (int i = 0; i < sizeof(villages) / sizeof(villages[0]); i++)
{
if (villages[i].x == 0 && villages[i].z == 0)
break;
float dx, dz;
dx = abs(spawn.x - villages[i].x);
dz = abs(spawn.z - villages[i].z);
if (sqrt((dx * dx) + (dz * dz)) < closest_village_distance || closest_village_distance == -1)
{
//closest_village = villages[i];
closest_village_distance = sqrt((dx * dx) + (dz * dz));
}
}
char out[512];
snprintf(out, 512, "%" PRId64, s);
snprintf(out + strlen(out), 512 - strlen(out), ",%s", spawn_biome_string);
snprintf(out + strlen(out), 512 - strlen(out), ",%i", closest_village_distance);
snprintf(out + strlen(out), 512 - strlen(out), ",%i", hut_count);
snprintf(out + strlen(out), 512 - strlen(out), ",%i", monument_count);
for (int i = 0; i < sizeof(biome_percent_counter) / sizeof(int); i++)
snprintf(out + strlen(out), 512 - strlen(out), ",%.2f%%", (biome_percent_counter[i] * (step * step) / (fw * fh)) * 100);
snprintf(out + strlen(out), 512 - strlen(out), "\n");
printf("%s", out);
fflush(stdout);
return 0;
}