12 #include "gb/creator/makestar.h" 19 #include "gb/creator/makeplanet.h" 20 #include "gb/creator/makeuniv.h" 22 #include "gb/files_shl.h" 23 #include "gb/tweakables.h" 24 #include "gb/utils/rand.h" 31 #define M_PI 3.14159265358979323846
37 static int Numtypes[PlanetType::DESERT + 2] = {
40 static int Resource[PlanetType::DESERT + 2] = {
60 static int ReadNameList(
char ss[1000][20],
int n,
int m,
const char *filename);
64 static const char *
Nametypes[] = {
"Earth",
"Asteroid",
"Airless",
65 "Iceball",
"Gaseous",
"Water",
66 "Forest",
"Desert",
" >>"};
69 return -269 + stemp * 1315 * 40 / (40 + dist);
77 printf(
"\nPlanet/Sector distribution -\n");
79 "Type NP . * ^ ~ # ( - NS Avg Res " 81 for (i = 0; i <= PlanetType::DESERT + 1; i++) {
83 if (i < PlanetType::DESERT + 1)
85 for (j = 0; j < SectorType::SEC_PLATED; j++) {
88 if (i <= PlanetType::DESERT)
91 printf(
"%6d %5.1f",
Numsects[i][SectorType::SEC_PLATED],
93 printf(
"%8d %7.1f %5.1f\n",
Resource[i],
98 printf(
"Average Sector Fertility -\n");
99 printf(
"Type NP . * ^ ~ # ( - Fert /Plan /Sect\n");
100 for (i = 0; i <= PlanetType::DESERT + 1; i++) {
103 for (j = 0; j < SectorType::SEC_PLATED; j++) {
111 printf(
"%8d %7.1f %5.1f\n", y, (1.0 * y) /
Numtypes[i],
112 (1.0 * y) /
Numsects[i][SectorType::SEC_PLATED]);
116 static int ReadNameList(
char ss[1000][20],
int n,
int m,
const char *filename) {
119 FILE *f = fopen(filename,
"r");
122 printf(
"Unable to open \"%s\".\n", filename);
125 for (i = 0; i < n; i++) {
126 for (j = 0; j < m; j++)
127 if (
'\n' == (ss[i][j] = getc(f))) {
130 }
else if (EOF == ss[i][j])
133 while (
'\n' != (j = getc(f)))
134 if (EOF == j)
goto out;
139 printf(
"%d names listed in %s\n", i, filename);
152 for (i = 0; i <= n; i++) nums[i] = 0;
153 for (j = 0; j <= n; j++) {
154 i = k = int_rand(0, n);
155 while (nums[k] != 0) k += nums[k];
175 numplist = ReadNameList(PNames, 1000, 20,
PLANETLIST);
182 const char *Numbers[] = {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
183 "9",
"10",
"11",
"12",
"13",
"14",
"15"};
191 numslist = ReadNameList(SNames, 1000, 20,
STARLIST);
204 printf(
"Next star name:");
207 scanf(
"%14[^\n]", buf);
230 Star = (startype *)malloc(
sizeof(startype));
231 bzero(Star,
sizeof(startype));
232 Star->star_id = snum;
233 Star->gravity = int_rand(0, int_rand(0, 300)) + int_rand(0, 300) +
234 int_rand(100, 400) + int_rand(0, 9) / 10.0;
235 Star->temperature = round_rand(Star->gravity / 100.0);
240 printf(
"Star %s: gravity %1.1f, temp %d\n", Star->name, Star->gravity,
241 (
int)Star->temperature);
247 for (i = 0; i < Star->numplanets; i++) {
248 distsep = (
PLANET_DIST_MAX - distmin) / (
double)(Star->numplanets - i);
249 distmax = distmin + distsep;
250 dist = distmin + double_rand() * (distmax - distmin);
254 angle = 2.0 *
M_PI * double_rand();
255 xpos = dist * sin(angle);
256 ypos = dist * cos(angle);
260 roll = int_rand(1, 100);
261 if ((int_rand(1, 100) <= 10) || (temperature > 400)) {
262 type = PlanetType::ASTEROID;
263 }
else if ((temperature > 100) && (temperature <= 400)) {
265 type = PlanetType::MARS;
267 type = PlanetType::DESERT;
268 }
else if ((temperature > 30) && (temperature <= 100)) {
270 type = PlanetType::EARTH;
272 type = PlanetType::WATER;
274 type = PlanetType::FOREST;
276 type = PlanetType::DESERT;
278 type = PlanetType::MARS;
279 }
else if ((temperature > -10) && (temperature <= 30)) {
281 type = PlanetType::EARTH;
283 type = PlanetType::WATER;
285 type = PlanetType::FOREST;
287 type = PlanetType::DESERT;
288 }
else if ((temperature > -50) && (temperature <= -10)) {
290 type = PlanetType::DESERT;
292 type = PlanetType::ICEBALL;
294 type = PlanetType::FOREST;
296 type = PlanetType::MARS;
297 }
else if ((temperature > -100) && (temperature <= -50)) {
299 type = PlanetType::GASGIANT;
301 type = PlanetType::ICEBALL;
303 type = PlanetType::MARS;
304 }
else if (temperature <= -100) {
306 type = PlanetType::ICEBALL;
308 type = PlanetType::GASGIANT;
314 planet.total_resources = 0;
317 printf(
"Planet %s: temp %d, type %s (%u)\n", Star->pnames[i],
319 printf(
"Position is (%1.0f,%1.0f) relative to %s; distance %1.0f.\n",
320 planet.xpos, planet.ypos, Star->name, dist);
321 printf(
"sect map(%dx%d):\n", planet.Maxx, planet.Maxy);
322 for (y = 0; y < planet.Maxy; y++) {
323 for (x = 0; x < planet.Maxx; x++) {
324 switch (smap.get(x, y).condition) {
325 case SectorType::SEC_LAND:
328 case SectorType::SEC_SEA:
331 case SectorType::SEC_MOUNT:
334 case SectorType::SEC_ICE:
337 case SectorType::SEC_GAS:
340 case SectorType::SEC_DESERT:
343 case SectorType::SEC_FOREST:
357 for (y = 0; y < planet.Maxy; y++)
358 for (x = 0; x < planet.Maxx; x++) {
359 uint8_t d = smap.get(x, y).condition;
360 planet.total_resources += smap.get(x, y).resource;
361 Resource[type] += smap.get(x, y).resource;
363 Fertsects[type][d] += smap.get(x, y).fert;
365 Star->planetpos[i] = 0;
static int star_list[1000]
static const char * Nametypes[]
static int Fertsects[PlanetType::DESERT+2][SectorType::SEC_PLATED+1]
Planet Makeplanet(double, short, PlanetType)
static char * NextStarName()
static char SNames[1000][20]
static int Numtypes[PlanetType::DESERT+2]
static const double PLANET_DIST_MIN
static int planet_list[1000]
static int ReadNameList(char ss[1000][20], int n, int m, const char *filename)
static int Numsects[PlanetType::DESERT+2][SectorType::SEC_PLATED+1]
static int Resource[PlanetType::DESERT+2]
void place_star(startype *)
int Temperature(double dist, int stemp)
void putplanet(const Planet &p, startype *star, const int pnum)
SectorMap getsmap(const Planet &p)
static void rand_list(int n, int *list)
static const char * NextPlanetName(int)
static const double PLANET_DIST_MAX
static char PNames[1000][20]