Galactic Bloodshed
production.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/production.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 production_at_star(GameObj &g, 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(
39  buf, " %c %4.4s/%-4.4s%c%3d%8.4f%8ld%3d%6d%5d%6d %6ld %3d%8.2f\n",
40  Psymbol[pl.type], Stars[star]->name, Stars[star]->pnames[i],
41  (pl.info[Playernum - 1].autorep ? '*' : ' '),
42  Stars[star]->governor[Playernum - 1],
43  pl.info[Playernum - 1].prod_tech, pl.total_resources,
44  pl.info[Playernum - 1].prod_crystals, pl.info[Playernum - 1].prod_res,
45  pl.info[Playernum - 1].prod_dest, pl.info[Playernum - 1].prod_fuel,
46  pl.info[Playernum - 1].prod_money, pl.info[Playernum - 1].tox_thresh,
47  pl.info[Playernum - 1].est_production);
48  notify(Playernum, Governor, buf);
49  }
50  }
51 }
52 } // namespace
53 
54 void production(const command_t &argv, GameObj &g) {
55  const player_t Playernum = g.player;
56  const governor_t Governor = g.governor;
57  Race *race;
58  placetype where;
59 
60  notify(Playernum, Governor,
61  " ============ Production Report ==========\n");
62  notify(Playernum, Governor,
63  " Planet gov tech deposit x res "
64  "des fuel tax tox est prod\n");
65 
66  race = races[Playernum - 1];
67  getsdata(&Sdata);
68 
69  if (argv.size() < 2)
70  for (starnum_t star = 0; star < Sdata.numstars; star++)
72  else
73  for (int i = 1; i < argv.size(); i++) {
74  where = getplace(g, argv[i], 0);
75  if (where.err || (where.level == ScopeLevel::LEVEL_UNIV) ||
76  (where.level == ScopeLevel::LEVEL_SHIP)) {
77  sprintf(buf, "Bad location `%s'.\n", argv[i].c_str());
78  notify(Playernum, Governor, buf);
79  continue;
80  } /* ok, a proper location */
81  production_at_star(g, where.snum);
82  }
83  g.out << "\n";
84 }
Planet getplanet(const starnum_t star, const planetnum_t pnum)
Definition: files_shl.cc:335
void production_at_star(GameObj &g, starnum_t star)
Definition: production.cc:25
#define isset(a, i)
Definition: vars.h:312
void production(const command_t &argv, GameObj &g)
Definition: production.cc:54
void getsdata(struct stardata *S)
Definition: files_shl.cc:272
void getstar(startype **s, int star)
Definition: files_shl.cc:281