Galactic Bloodshed
tech_status.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/tech_status.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 tech_report_star(int Playernum, int Governor, startype *star,
26  starnum_t snum, int *t_invest, double *t_gain,
27  double *t_max_gain) {
28  char str[200];
29  double gain;
30  double max_gain;
31 
32  if (isset(star->explored, Playernum) &&
33  (!Governor || star->governor[Playernum - 1] == Governor)) {
34  for (planetnum_t i = 0; i < star->numplanets; i++) {
35  const auto pl = getplanet(snum, i);
36  if (pl.info[Playernum - 1].explored &&
37  pl.info[Playernum - 1].numsectsowned) {
38  sprintf(str, "%s/%s%s", star->name, star->pnames[i],
39  (pl.info[Playernum - 1].autorep ? "*" : ""));
40  sprintf(buf, "%16.16s %10ld%10d%8.3lf%8.3lf\n", str,
41  pl.info[Playernum - 1].popn, pl.info[Playernum - 1].tech_invest,
42  gain = tech_prod((int)pl.info[Playernum - 1].tech_invest,
43  (int)pl.info[Playernum - 1].popn),
44  max_gain = tech_prod((int)pl.info[Playernum - 1].prod_res,
45  (int)pl.info[Playernum - 1].popn));
46  notify(Playernum, Governor, buf);
47  *t_invest += pl.info[Playernum - 1].tech_invest;
48  *t_gain += gain;
49  *t_max_gain += max_gain;
50  }
51  }
52  }
53 }
54 } // namespace
55 
56 void tech_status(const command_t &argv, GameObj &g) {
57  const player_t Playernum = g.player;
58  const governor_t Governor = g.governor;
59  int k;
60  placetype where;
61  double total_gain = 0.0;
62  double total_max_gain = 0.0;
63  int total_invest = 0;
64 
65  getsdata(&Sdata);
66 
67  sprintf(buf, " ========== Technology Report ==========\n\n");
68  notify(Playernum, Governor, buf);
69 
70  sprintf(buf, " Planet popn invest gain ^gain\n");
71  notify(Playernum, Governor, buf);
72 
73  if (argv.size() == 1) {
74  for (starnum_t star = 0; star < Sdata.numstars; star++) {
75  getstar(&(Stars[star]), star);
76  tech_report_star(Playernum, Governor, Stars[star], star, &total_invest,
77  &total_gain, &total_max_gain);
78  }
79  } else { /* Several arguments */
80  for (k = 1; k < argv.size(); k++) {
81  where = getplace(g, argv[k], 0);
82  if (where.err || where.level == ScopeLevel::LEVEL_UNIV ||
83  where.level == ScopeLevel::LEVEL_SHIP) {
84  sprintf(buf, "Bad location `%s'.\n", argv[k].c_str());
85  notify(Playernum, Governor, buf);
86  continue;
87  } /* ok, a proper location */
88  starnum_t star = where.snum;
89  getstar(&Stars[star], star);
90  tech_report_star(Playernum, Governor, Stars[star], star, &total_invest,
91  &total_gain, &total_max_gain);
92  }
93  }
94  sprintf(buf, " Total Popn: %7ld\n", Power[Playernum - 1].popn);
95  notify(Playernum, Governor, buf);
96  sprintf(buf, "Tech: %31d%8.3lf%8.3lf\n", total_invest, total_gain,
97  total_max_gain);
98  notify(Playernum, Governor, buf);
99 }
Planet getplanet(const starnum_t star, const planetnum_t pnum)
Definition: files_shl.cc:335
#define isset(a, i)
Definition: vars.h:312
void tech_status(const command_t &argv, GameObj &g)
Definition: tech_status.cc:56
double tech_prod(int investment, int popn)
Definition: tech.cc:69
void tech_report_star(int Playernum, int Governor, startype *star, starnum_t snum, int *t_invest, double *t_gain, double *t_max_gain)
Definition: tech_status.cc:25
void getsdata(struct stardata *S)
Definition: files_shl.cc:272
void getstar(startype **s, int star)
Definition: files_shl.cc:281