Galactic Bloodshed
colonies.cc
Go to the documentation of this file.
1 // Copyright 2019 The Galactic Bloodshed Authors. All rights reserved.
2 // Use of this source code is governed by a license that can be
3 // found in the COPYING file.
4 
5 #include "gb/commands/colonies.h"
6 
7 #include <cmath>
8 #include <cstdio>
9 #include <cstdlib>
10 
11 #include "gb/GB_server.h"
12 #include "gb/buffers.h"
13 #include "gb/files_shl.h"
14 #include "gb/getplace.h"
15 #include "gb/map.h"
16 #include "gb/max.h"
17 #include "gb/power.h"
18 #include "gb/races.h"
19 #include "gb/ships.h"
20 #include "gb/tech.h"
21 #include "gb/tweakables.h"
22 #include "gb/vars.h"
23 
24 namespace {
25 void colonies_at_star(GameObj &g, Race *race, starnum_t star) {
26  player_t Playernum = g.player;
27  governor_t Governor = g.governor;
28 
29  getstar(&(Stars[star]), star);
30  if (!isset(Stars[star]->explored, Playernum)) return;
31 
32  for (auto i = 0; i < Stars[star]->numplanets; i++) {
33  const auto pl = getplanet(star, i);
34 
35  if (pl.info[Playernum - 1].explored &&
36  pl.info[Playernum - 1].numsectsowned &&
37  (!Governor || Stars[star]->governor[Playernum - 1] == Governor)) {
38  sprintf(buf,
39  " %c %4.4s/%-4.4s%c%4d%3d%5d%8ld%3d%6lu%5d%6d "
40  "%3d/%-3d%3.0f/%-3d%3d/%-3d",
41  Psymbol[pl.type], Stars[star]->name, Stars[star]->pnames[i],
42  (pl.info[Playernum - 1].autorep ? '*' : ' '),
43  Stars[star]->governor[Playernum - 1],
44  pl.info[Playernum - 1].numsectsowned,
45  pl.info[Playernum - 1].tech_invest, pl.info[Playernum - 1].popn,
46  pl.info[Playernum - 1].crystals, pl.info[Playernum - 1].resource,
47  pl.info[Playernum - 1].destruct, pl.info[Playernum - 1].fuel,
48  pl.info[Playernum - 1].tax, pl.info[Playernum - 1].newtax,
49  compatibility(pl, race), pl.conditions[TOXIC],
50  pl.info[Playernum - 1].comread, pl.info[Playernum - 1].mob_set);
51  notify(Playernum, Governor, buf);
52  for (auto j = 1; j <= Num_races; j++)
53  if ((j != Playernum) && (pl.info[j - 1].numsectsowned > 0)) {
54  sprintf(buf, " %d", j);
55  notify(Playernum, Governor, buf);
56  }
57  g.out << "\n";
58  }
59  }
60 }
61 } // namespace
62 
63 void colonies(const command_t &argv, GameObj &g) {
64  const player_t Playernum = g.player;
65  const governor_t Governor = g.governor;
66  Race *race;
67  placetype where;
68 
69  notify(Playernum, Governor,
70  " ========== Colonization Report ==========\n");
71  notify(Playernum, Governor,
72  " Planet gov sec tech popn x res "
73  "des fuel tax cmpt/tox mob Aliens\n");
74 
75  race = races[Playernum - 1];
76  getsdata(&Sdata);
77 
78  if (argv.size() < 2)
79  for (starnum_t star = 0; star < Sdata.numstars; star++)
80  colonies_at_star(g, race, star);
81  else
82  for (int i = 1; i < argv.size(); i++) {
83  where = getplace(g, argv[i], 0);
84  if (where.err || (where.level == ScopeLevel::LEVEL_UNIV) ||
85  (where.level == ScopeLevel::LEVEL_SHIP)) {
86  sprintf(buf, "Bad location `%s'.\n", argv[i].c_str());
87  notify(Playernum, Governor, buf);
88  continue;
89  } /* ok, a proper location */
90  colonies_at_star(g, race, where.snum);
91  }
92  g.out << "\n";
93 }
Planet getplanet(const starnum_t star, const planetnum_t pnum)
Definition: files_shl.cc:335
#define isset(a, i)
Definition: vars.h:312
#define TOXIC
Definition: tweakables.h:39
double compatibility(const Planet &planet, const Race *race)
Definition: max.cc:37
void getsdata(struct stardata *S)
Definition: files_shl.cc:272
void getstar(startype **s, int star)
Definition: files_shl.cc:281
void colonies(const command_t &argv, GameObj &g)
Definition: colonies.cc:63
void colonies_at_star(GameObj &g, Race *race, starnum_t star)
Definition: colonies.cc:25