15 #include "gb/GB_server.h" 16 #include "gb/buffers.h" 18 #include "gb/csp_types.h" 19 #include "gb/files_shl.h" 21 #include "gb/getplace.h" 26 #include "gb/tweakables.h" 29 #define MAX_SHIPS_PER_SECTOR 10
31 static const char *
Tox[] = {
35 "Stage 3, semi-semi mild",
36 "Stage 4, ecologically unsound",
37 "Stage 5: ecologically unsound",
38 "Stage 6: below birth threshold",
39 "Stage 7: ecologically unstable--below birth threshold",
40 "Stage 8: ecologically poisonous --below birth threshold",
41 "Stage 9: WARNING: nearing 100% toxicity",
42 "Stage 10: WARNING: COMPLETELY TOXIC!!!",
45 static void get4args(
const char *,
int *,
int *,
int *,
int *);
47 void survey(
const command_t &argv, GameObj &g) {
48 const player_t Playernum = g.player;
49 const governor_t Governor = g.governor;
79 if (argv[0] ==
"survey")
86 if (argv.size() == 1) {
87 where.level = g.level;
92 if ((isdigit(argv[1][0]) && index(argv[1].c_str(),
',') !=
nullptr) ||
93 ((argv[1][0] ==
'-') && (all = 1))) {
94 if (g.level != ScopeLevel::LEVEL_PLAN) {
95 g.out <<
"There are no sectors here.\n";
98 where.level = ScopeLevel::LEVEL_PLAN;
103 where = getplace(g, argv[1], 0);
104 if (where.err || where.level == ScopeLevel::LEVEL_SHIP)
return;
108 Race = races[Playernum - 1];
110 if (where.level == ScopeLevel::LEVEL_PLAN) {
115 if ((isdigit(argv[1][0]) && index(argv[1].c_str(),
',') !=
nullptr) ||
120 get4args(argv[1].c_str(), &x2, &hix, &lowy, &hiy);
122 x2 = std::max(0, x2);
123 hix = std::min(hix, p.Maxx - 1);
124 lowy = std::max(0, lowy);
125 hiy = std::min(hiy, p.Maxy - 1);
134 g.out <<
" x,y cond/type owner race eff mob frt res mil popn " 139 sprintf(buf,
"%c %d %d %d %s %s %lu %d %d %ld %ld %d %.2f %d\n",
141 Stars[where.snum]->name,
142 Stars[where.snum]->pnames[where.pnum],
143 p.info[Playernum - 1].resource, p.info[Playernum - 1].fuel,
144 p.info[Playernum - 1].destruct, p.popn, p.maxpopn,
146 notify(Playernum, Governor, buf);
148 bzero((
struct shipstuff *)shiplocs,
sizeof(shiplocs));
149 inhere = p.info[Playernum - 1].numsectsowned;
152 auto shipa = getship(shiplist);
153 if (shipa->owner == Playernum &&
154 (shipa->popn || (shipa->type == ShipType::OTYPE_PROBE)))
156 if (shipa->alive && landed(*shipa) &&
157 shiplocs[shipa->land_x][shipa->land_y].pos <
159 shiplocs[shipa->land_x][shipa->land_y]
160 .shipstuffs[shiplocs[shipa->land_x][shipa->land_y].pos]
162 shiplocs[shipa->land_x][shipa->land_y]
163 .shipstuffs[shiplocs[shipa->land_x][shipa->land_y].pos]
164 .owner = shipa->owner;
165 shiplocs[shipa->land_x][shipa->land_y]
166 .shipstuffs[shiplocs[shipa->land_x][shipa->land_y].pos]
167 .ltr = Shipltrs[shipa->type];
168 shiplocs[shipa->land_x][shipa->land_y].pos++;
170 shiplist = shipa->nextship;
173 for (; lowy <= hiy; lowy++)
174 for (lowx = x2; lowx <= hix; lowx++) {
175 auto &s = smap.get(lowx, lowy);
178 sprintf(buf,
"%2d,%-2d ", lowx, lowy);
179 notify(Playernum, Governor, buf);
180 if ((d =
desshow(Playernum
, Governor
, Race
, s
)) == CHAR_CLOAKED) {
181 sprintf(buf,
"? ( ? )\n");
182 notify(Playernum, Governor, buf);
185 buf,
" %c %c %6u%5u%4u%4u%4u%5lu%5lu%5lu%6d%s\n",
186 Dessymbols[s.condition], Dessymbols[s.type], s.owner, s.race,
187 s.eff, s.mobilization, s.fert, s.resource, s.troops, s.popn,
189 ((s.crystals && (Race->discoveries[
D_CRYSTAL] || Race->God))
192 notify(Playernum, Governor, buf);
195 switch (s.condition) {
196 case SectorType::SEC_SEA:
197 sect_char = CHAR_SEA;
199 case SectorType::SEC_LAND:
200 sect_char = CHAR_LAND;
202 case SectorType::SEC_MOUNT:
203 sect_char = CHAR_MOUNT;
205 case SectorType::SEC_GAS:
206 sect_char = CHAR_GAS;
208 case SectorType::SEC_PLATED:
209 sect_char = CHAR_PLATED;
211 case SectorType::SEC_ICE:
212 sect_char = CHAR_ICE;
214 case SectorType::SEC_DESERT:
215 sect_char = CHAR_DESERT;
217 case SectorType::SEC_FOREST:
218 sect_char = CHAR_FOREST;
224 sprintf(buf,
"%c %d %d %d %c %c %d %u %u %u %u %d %lu %lu %lu %d",
227 ((s.condition == SectorType::SEC_WASTED) ? 1 : 0), s.owner,
228 s.eff, s.fert, s.mobilization,
229 ((s.crystals && (Race->discoveries[
D_CRYSTAL] || Race->God))
232 s.resource, s.popn, s.troops,
234 notify(Playernum, Governor, buf);
236 if (shiplocs[lowx][lowy].pos && inhere) {
238 for (i = 0; i < shiplocs[lowx][lowy].pos; i++) {
239 sprintf(buf,
" %d %c %u;",
240 shiplocs[lowx][lowy].shipstuffs[i].shipno,
241 shiplocs[lowx][lowy].shipstuffs[i].ltr,
242 shiplocs[lowx][lowy].shipstuffs[i].owner);
243 notify(Playernum, Governor, buf);
251 notify(Playernum, Governor, buf);
255 sprintf(buf,
"%s:\n", Stars[where.snum]->pnames[where.pnum]);
256 notify(Playernum, Governor, buf);
257 sprintf(buf,
"gravity x,y absolute x,y relative to %s\n",
258 Stars[where.snum]->name);
259 notify(Playernum, Governor, buf);
260 sprintf(buf,
"%7.2f %7.1f,%7.1f %8.1f,%8.1f\n",
gravity(p
),
261 p.xpos + Stars[where.snum]->xpos,
262 p.ypos + Stars[where.snum]->ypos, p.xpos, p.ypos);
263 notify(Playernum, Governor, buf);
264 g.out <<
"======== Planetary conditions: ========\n";
265 g.out <<
"atmosphere concentrations:\n";
266 sprintf(buf,
" methane %02d%%(%02d%%) oxygen %02d%%(%02d%%)\n",
269 notify(Playernum, Governor, buf);
271 " CO2 %02d%%(%02d%%) hydrogen %02d%%(%02d%%) " 272 "temperature: %3d (%3d)\n",
275 Race->conditions[
TEMP]);
276 notify(Playernum, Governor, buf);
278 " nitrogen %02d%%(%02d%%) sulfur %02d%%(%02d%%) " 282 p.conditions[
RTEMP]);
283 notify(Playernum, Governor, buf);
284 sprintf(buf,
" helium %02d%%(%02d%%) other %02d%%(%02d%%)\n",
286 p.conditions[
OTHER], Race->conditions[
OTHER]);
287 notify(Playernum, Governor, buf);
288 if ((tindex = p.conditions[
TOXIC] / 10) < 0)
290 else if (tindex > 10)
292 sprintf(buf,
" Toxicity: %d%% (%s)\n",
294 notify(Playernum, Governor, buf);
295 sprintf(buf,
"Total planetary compatibility: %.2f%%\n",
297 notify(Playernum, Governor, buf);
301 crystal_count = avg_fert = avg_resource = 0;
302 for (lowx = 0; lowx < p.Maxx; lowx++)
303 for (lowy = 0; lowy < p.Maxy; lowy++) {
304 auto &s = smap.get(lowx, lowy);
306 avg_resource += s.resource;
307 if (Race->discoveries[
D_CRYSTAL] || Race->God)
308 crystal_count += !!s.crystals;
310 sprintf(buf,
"%29s: %d\n%29s: %d\n%29s: %d\n",
"Average fertility",
311 avg_fert / (p.Maxx * p.Maxy),
"Average resource",
312 avg_resource / (p.Maxx * p.Maxy),
"Crystal sectors",
314 notify(Playernum, Governor, buf);
316 sprintf(buf,
"%29s: %ld\n",
"Total resource deposits",
318 notify(Playernum, Governor, buf);
320 sprintf(buf,
"fuel_stock resource_stock dest_pot. %s ^%s\n",
321 Race->Metamorph ?
"biomass" :
"popltn",
322 Race->Metamorph ?
"biomass" :
"popltn");
323 notify(Playernum, Governor, buf);
324 sprintf(buf,
"%10u %14lu %9u %7lu%11lu\n", p.info[Playernum - 1].fuel,
325 p.info[Playernum - 1].resource, p.info[Playernum - 1].destruct,
327 notify(Playernum, Governor, buf);
329 sprintf(buf,
"This planet ENSLAVED to player %d!\n", p.slaved_to);
330 notify(Playernum, Governor, buf);
333 }
else if (where.level == ScopeLevel::LEVEL_STAR) {
334 sprintf(buf,
"Star %s\n", Stars[where.snum]->name);
335 notify(Playernum, Governor, buf);
336 sprintf(buf,
"locn: %f,%f\n", Stars[where.snum]->xpos,
337 Stars[where.snum]->ypos);
338 notify(Playernum, Governor, buf);
340 for (i = 0; i < Stars[where.snum]->numplanets; i++) {
341 sprintf(buf,
" \"%s\"\n", Stars[where.snum]->pnames[i]);
342 notify(Playernum, Governor, buf);
345 sprintf(buf,
"Gravity: %.2f\tInstability: ", Stars[where.snum]->gravity);
346 notify(Playernum, Governor, buf);
349 sprintf(buf,
"%d%% (%s)\n", Stars[where.snum]->stability,
350 Stars[where.snum]->stability < 20
352 : Stars[where.snum]->stability < 40
354 : Stars[where.snum]->stability < 60
356 : Stars[where.snum]->stability < 100
357 ?
"WARNING! Nova iminent!" 358 :
"undergoing nova");
359 notify(Playernum, Governor, buf);
361 sprintf(buf,
"(cannot determine)\n");
362 notify(Playernum, Governor, buf);
364 sprintf(buf,
"temperature class (1->10) %d\n",
365 Stars[where.snum]->temperature);
366 notify(Playernum, Governor, buf);
367 sprintf(buf,
"%d planets are ", Stars[where.snum]->numplanets);
368 notify(Playernum, Governor, buf);
369 for (x2 = 0; x2 < Stars[where.snum]->numplanets; x2++) {
370 sprintf(buf,
"%s ", Stars[where.snum]->pnames[x2]);
371 notify(Playernum, Governor, buf);
374 notify(Playernum, Governor, buf);
375 }
else if (where.level == ScopeLevel::LEVEL_UNIV) {
376 g.out <<
"It's just _there_, you know?\n";
378 g.out <<
"Illegal scope.\n";
382 void repair(
const command_t &argv, GameObj &g) {
383 const player_t Playernum = g.player;
384 const governor_t Governor = g.governor;
395 if (argv.size() == 1) {
396 where.level = g.level;
401 if (isdigit(argv[1][0]) && index(argv[1].c_str(),
',') !=
nullptr) {
402 if (g.level != ScopeLevel::LEVEL_PLAN) {
403 sprintf(buf,
"There are no sectors here.\n");
404 notify(Playernum, Governor, buf);
407 where.level = ScopeLevel::LEVEL_PLAN;
412 where = getplace(g, argv[1], 0);
413 if (where.err || where.level == ScopeLevel::LEVEL_SHIP)
return;
417 if (where.level == ScopeLevel::LEVEL_PLAN) {
419 if (!p.info[Playernum - 1].numsectsowned) {
420 notify(Playernum, Governor,
421 "You don't own any sectors on this planet.\n");
425 if (isdigit(argv[1][0]) && index(argv[1].c_str(),
',') !=
nullptr) {
426 get4args(argv[1].c_str(), &x2, &hix, &lowy, &hiy);
428 x2 = std::max(0, x2);
429 hix = std::min(hix, p.Maxx - 1);
430 lowy = std::max(0, lowy);
431 hiy = std::min(hiy, p.Maxy - 1);
442 for (; lowy <= hiy; lowy++)
443 for (lowx = x2; lowx <= hix; lowx++) {
445 auto &s = smap.get(lowx, lowy);
446 if (s.condition == SectorType::SEC_WASTED &&
447 (s.owner == Playernum || !s.owner)) {
448 s.condition = s.type;
449 s.fert = std::min(100U, s.fert + 20);
459 sprintf(buf,
"%d sectors repaired at a cost of %d resources.\n", sectors,
461 notify(Playernum, Governor, buf);
463 sprintf(buf,
"scope must be a planet.\n");
464 notify(Playernum, Governor, buf);
468 static void get4args(
const char *s,
int *xl,
int *xh,
int *yl,
int *yh) {
473 sscanf(p,
"%[^,]", s1);
474 while ((*p !=
':') && (*p !=
',')) p++;
476 sscanf(s1,
"%d:%d", xl, xh);
477 while (*p !=
',') p++;
478 }
else if (*p ==
',') {
479 sscanf(s1,
"%d", xl);
484 while ((*p !=
':') && (*p !=
'\0')) p++;
486 sscanf(s2,
",%d:%d", yl, yh);
488 sscanf(s2,
",%d,", yl);
#define CSP_SURVEY_SECTOR
static void get4args(const char *, int *, int *, int *, int *)
void repair(const command_t &argv, GameObj &g)
Planet getplanet(const starnum_t star, const planetnum_t pnum)
#define MAX_SHIPS_PER_SECTOR
static const char * Tox[]
void putsector(const Sector &s, const Planet &p, const int x, const int y)
#define TECH_SEE_STABILITY
double compatibility(const Planet &planet, const Race *race)
#define SECTOR_REPAIR_COST
void survey(const command_t &argv, GameObj &g)
void putplanet(const Planet &p, startype *star, const int pnum)
SectorMap getsmap(const Planet &p)
#define LIMITED_RESOURCES
double gravity(const Planet &p)
int maxsupport(const Race *r, const Sector &s, const double c, const int toxic)
char desshow(const player_t Playernum, const governor_t Governor, const Race *r, const Sector &s)