Galactic Bloodshed
prof.cc
Go to the documentation of this file.
1 // Copyright 2014 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 /* prof.c -- print out racial profile */
6 
7 #include "gb/prof.h"
8 
9 #include <cstdio>
10 #include <cstdlib>
11 
12 #include "gb/GB_server.h"
13 #include "gb/buffers.h"
14 #include "gb/races.h"
15 #include "gb/ships.h"
16 #include "gb/shlmisc.h"
17 #include "gb/shootblast.h"
18 #include "gb/tweakables.h"
19 #include "gb/vars.h"
20 
21 static int round_perc(int, Race *, int);
22 static char *Estimate_f(double, Race *, int);
23 
24 void whois(const command_t &argv, GameObj &g) {
25  player_t Playernum = g.player;
26  governor_t Governor = g.governor;
27  // TODO(jeffbailey): int APcount = 0;
28  int j;
29  int numraces;
30  racetype *Race;
31 
32  if (argv.size() <= 1) {
33  whois({"whois", std::to_string(Playernum)}, g);
34  return;
35  }
36  numraces = Num_races;
37 
38  for (size_t i = 1; i <= argv.size() - 1; i++) {
39  j = std::stoi(argv[i]);
40  if (!(j < 1 || j > numraces)) {
41  Race = races[j - 1];
42  if (j == Playernum)
43  sprintf(buf, "[%2d, %d] %s \"%s\"\n", j, Governor, Race->name,
44  Race->governor[Governor].name);
45  else
46  sprintf(buf, "[%2d] %s\n", j, Race->name);
47  } else {
48  sprintf(buf, "Identify: Invalid player number #%d. Try again.\n", j);
49  }
50  notify(Playernum, Governor, buf);
51  }
52 }
53 
54 void treasury(const command_t &, GameObj &g) {
55  player_t Playernum = g.player;
56  governor_t Governor = g.governor;
57  // TODO(jeffbailey): int APcount = 0;
58  racetype *Race;
59 
60  Race = races[Playernum - 1];
61 
62  sprintf(
63  buf, "Income last update was: %ld\t\tCosts last update was: %ld\n",
64  Race->governor[Governor].income + Race->governor[Governor].profit_market,
65  Race->governor[Governor].maintain + Race->governor[Governor].cost_tech +
66  Race->governor[Governor].cost_market);
67  notify(Playernum, Governor, buf);
68  sprintf(buf, " Market: %5ld\t\t\t Market: %5ld\n",
69  Race->governor[Governor].profit_market,
70  Race->governor[Governor].cost_market);
71  notify(Playernum, Governor, buf);
72  sprintf(buf, " Taxes: %5ld\t\t\t Tech: %5ld\n",
73  Race->governor[Governor].income, Race->governor[Governor].cost_tech);
74  notify(Playernum, Governor, buf);
75 
76  sprintf(buf, "\t\t\t\t\t Maint: %5ld\n",
77  Race->governor[Governor].maintain);
78  notify(Playernum, Governor, buf);
79  sprintf(buf, "You have: %ld\n", Race->governor[Governor].money);
80  notify(Playernum, Governor, buf);
81 }
82 
83 void profile(const command_t &argv, GameObj &g) {
84  player_t Playernum = g.player;
85  governor_t Governor = g.governor;
86  // TODO(jeffbailey): int APcount = 0;
87  int p;
88  Race *r;
89  racetype *Race;
90 
91  Race = races[Playernum - 1];
92 
93  if (argv.size() == 1) {
94  sprintf(buf, "--==** Racial profile for %s (player %d) **==--\n",
95  Race->name, Race->Playernum);
96  notify(Playernum, Governor, buf);
97  if (Race->God) {
98  sprintf(buf, "*** Diety Status ***\n");
99  notify(Playernum, Governor, buf);
100  }
101  sprintf(buf, "Personal: %s\n", Race->info);
102  notify(Playernum, Governor, buf);
103  sprintf(buf, "Default Scope: /%s/%s\n",
104  Stars[Race->governor[Governor].homesystem]->name,
105  Stars[Race->governor[Governor].homesystem]
106  ->pnames[Race->governor[Governor].homeplanetnum]);
107  notify(Playernum, Governor, buf);
108  if (Race->Gov_ship == 0)
109  sprintf(buf, "NO DESIGNATED CAPITAL!!");
110  else
111  sprintf(buf, "Designated Capital: #%-8lu", Race->Gov_ship);
112  notify(Playernum, Governor, buf);
113  sprintf(buf, "\t\tRanges: guns: %5.0f\n",
114  gun_range(Race, (Ship *)nullptr, 1));
115  notify(Playernum, Governor, buf);
116  sprintf(buf, "Morale: %5ld\t\t\t\t\t space: %5.0f\n", Race->morale,
117  tele_range(ShipType::OTYPE_STELE, Race->tech));
118  notify(Playernum, Governor, buf);
119  sprintf(buf, "Updates active: %d\t\t\t\t ground: %5.0f\n\n", Race->turn,
120  tele_range(ShipType::OTYPE_GTELE, Race->tech));
121  notify(Playernum, Governor, buf);
122  sprintf(buf, "%s Planet Conditions\t Sector Preferences\n",
123  Race->Metamorph ? "Metamorphic Race\t" : "Normal Race\t\t");
124  notify(Playernum, Governor, buf);
125  sprintf(buf, "Fert: %3d%%\t\t Temp:\t%d\n", Race->fertilize,
126  Temp(Race->conditions[TEMP]));
127  notify(Playernum, Governor, buf);
128  sprintf(buf,
129  "Rate: %3.1f\t\t methane %5d%%\t %-8.8s %c %3.0f%%\n",
130  Race->birthrate, Race->conditions[METHANE],
131  Desnames[SectorType::SEC_SEA], CHAR_SEA,
132  Race->likes[SectorType::SEC_SEA] * 100.);
133  notify(Playernum, Governor, buf);
134  sprintf(buf,
135  "Mass: %4.2f\t\t oxygen %5d%%\t %-8.8s %c %3.0f%%\n",
136  Race->mass, Race->conditions[OXYGEN], Desnames[SectorType::SEC_GAS],
137  CHAR_GAS, Race->likes[SectorType::SEC_GAS] * 100.);
138  notify(Playernum, Governor, buf);
139  sprintf(buf, "Fight: %d\t\t helium %5d%%\t %-8.8s %c %3.0f%%\n",
140  Race->fighters, Race->conditions[HELIUM],
141  Desnames[SectorType::SEC_ICE], CHAR_ICE,
142  Race->likes[SectorType::SEC_ICE] * 100.);
143  notify(Playernum, Governor, buf);
144  sprintf(buf,
145  "Metab: %4.2f\t\t nitrogen %5d%%\t %-8.8s %c %3.0f%%\n",
146  Race->metabolism, Race->conditions[NITROGEN],
147  Desnames[SectorType::SEC_MOUNT], CHAR_MOUNT,
148  Race->likes[SectorType::SEC_MOUNT] * 100.);
149  notify(Playernum, Governor, buf);
150  sprintf(buf, "Sexes: %1d\t\t CO2 %5d%%\t %-8.8s %c %3.0f%%\n",
151  Race->number_sexes, Race->conditions[CO2],
152  Desnames[SectorType::SEC_LAND], CHAR_LAND,
153  Race->likes[SectorType::SEC_LAND] * 100.);
154  notify(Playernum, Governor, buf);
155  sprintf(buf,
156  "Explore: %-3.0f%%\t\t hydrogen %5d%%\t %-8.8s %c %3.0f%%\n",
157  Race->adventurism * 100.0, Race->conditions[HYDROGEN],
158  Desnames[SectorType::SEC_DESERT], CHAR_DESERT,
159  Race->likes[SectorType::SEC_DESERT] * 100.);
160  notify(Playernum, Governor, buf);
161  sprintf(buf, "Avg Int: %3d\t\t sulfer %5d%%\t %-8.8s %c %3.0f%%\n",
162  Race->IQ, Race->conditions[SULFUR],
163  Desnames[SectorType::SEC_FOREST], CHAR_FOREST,
164  Race->likes[SectorType::SEC_FOREST] * 100.);
165  notify(Playernum, Governor, buf);
166  sprintf(
167  buf, "Tech: %-6.2f\t\t other %5d%%\t %-8.8s %c %3.0f%%\n",
168  Race->tech, Race->conditions[OTHER], Desnames[SectorType::SEC_PLATED],
169  CHAR_PLATED, Race->likes[SectorType::SEC_PLATED] * 100.);
170  notify(Playernum, Governor, buf);
171 
172  g.out << "Discoveries:";
173  if (Crystal(Race)) g.out << " Crystals";
174  if (Hyper_drive(Race)) g.out << " Hyper-drive";
175  if (Laser(Race)) g.out << " Combat Lasers";
176  if (Cew(Race)) g.out << " Confined Energy Weapons";
177  if (Vn(Race)) g.out << " Von Neumann Machines";
178  if (Tractor_beam(Race)) g.out << " Tractor Beam";
179  if (Transporter(Race)) g.out << " Transporter";
180  if (Avpm(Race)) g.out << " AVPM";
181  if (Cloak(Race)) g.out << " Cloaking";
182  if (Wormhole(Race)) g.out << " Wormhole";
183  g.out << "\n";
184  } else {
185  if (!(p = get_player(argv[1]))) {
186  sprintf(buf, "Player does not exist.\n");
187  notify(Playernum, Governor, buf);
188  return;
189  }
190  r = races[p - 1];
191  sprintf(buf, "------ Race report on %s (%d) ------\n", r->name, p);
192  notify(Playernum, Governor, buf);
193  if (Race->God) {
194  if (r->God) {
195  sprintf(buf, "*** Deity Status ***\n");
196  notify(Playernum, Governor, buf);
197  }
198  }
199  sprintf(buf, "Personal: %s\n", r->info);
200  notify(Playernum, Governor, buf);
201  sprintf(buf, "%%Know: %3d%%\n", Race->translate[p - 1]);
202  notify(Playernum, Governor, buf);
203  if (Race->translate[p - 1] > 50) {
204  sprintf(buf, "%s\t Planet Conditions\n",
205  r->Metamorph ? "Metamorphic Race" : "Normal Race\t");
206  notify(Playernum, Governor, buf);
207  sprintf(buf, "Fert: %s", Estimate_i((int)(r->fertilize), Race, p));
208  notify(Playernum, Governor, buf);
209  sprintf(buf, "\t\t Temp:\t%s\n",
210  Estimate_i((int)(r->conditions[TEMP]), Race, p));
211  notify(Playernum, Governor, buf);
212  sprintf(buf, "Rate: %s%%", Estimate_f(r->birthrate * 100.0, Race, p));
213  notify(Playernum, Governor, buf);
214  } else {
215  sprintf(buf, "Unknown Race\t\t Planet Conditions\n");
216  notify(Playernum, Governor, buf);
217  sprintf(buf, "Fert: %s", Estimate_i((int)(r->fertilize), Race, p));
218  notify(Playernum, Governor, buf);
219  sprintf(buf, "\t\t Temp:\t%s\n",
220  Estimate_i((int)(r->conditions[TEMP]), Race, p));
221  notify(Playernum, Governor, buf);
222  sprintf(buf, "Rate: %s", Estimate_f(r->birthrate, Race, p));
223  notify(Playernum, Governor, buf);
224  }
225  sprintf(buf, "\t\t methane %4s%%\t\tRanges:\n",
226  Estimate_i((int)(r->conditions[METHANE]), Race, p));
227  notify(Playernum, Governor, buf);
228  sprintf(buf, "Mass: %s", Estimate_f(r->mass, Race, p));
229  notify(Playernum, Governor, buf);
230  sprintf(buf, "\t\t oxygen %4s%%",
231  Estimate_i((int)(r->conditions[OXYGEN]), Race, p));
232  notify(Playernum, Governor, buf);
233  sprintf(buf, "\t\t guns: %6s\n",
234  Estimate_f(gun_range(r, (Ship *)nullptr, 1), Race, p));
235  notify(Playernum, Governor, buf);
236  sprintf(buf, "Fight: %s", Estimate_i((int)(r->fighters), Race, p));
237  notify(Playernum, Governor, buf);
238  sprintf(buf, "\t\t helium %4s%%",
239  Estimate_i((int)(r->conditions[HELIUM]), Race, p));
240  notify(Playernum, Governor, buf);
241  sprintf(buf, "\t\t space: %6s\n",
242  Estimate_f(tele_range(ShipType::OTYPE_STELE, r->tech), Race, p));
243  notify(Playernum, Governor, buf);
244  sprintf(buf, "Metab: %s", Estimate_f(r->metabolism, Race, p));
245  notify(Playernum, Governor, buf);
246  sprintf(buf, "\t\t nitrogen %4s%%",
247  Estimate_i((int)(r->conditions[NITROGEN]), Race, p));
248  notify(Playernum, Governor, buf);
249  sprintf(buf, "\t\t ground: %6s\n",
250  Estimate_f(tele_range(ShipType::OTYPE_GTELE, r->tech), Race, p));
251  notify(Playernum, Governor, buf);
252  sprintf(buf, "Sexes: %s", Estimate_i((int)(r->number_sexes), Race, p));
253  notify(Playernum, Governor, buf);
254  sprintf(buf, "\t\t CO2 %4s%%\n",
255  Estimate_i((int)(r->conditions[CO2]), Race, p));
256  notify(Playernum, Governor, buf);
257  sprintf(buf, "Explore: %s%%", Estimate_f(r->adventurism * 100.0, Race, p));
258  notify(Playernum, Governor, buf);
259  sprintf(buf, "\t\t hydrogen %4s%%\n",
260  Estimate_i((int)(r->conditions[HYDROGEN]), Race, p));
261  notify(Playernum, Governor, buf);
262  sprintf(buf, "Avg Int: %s", Estimate_i((int)(r->IQ), Race, p));
263  notify(Playernum, Governor, buf);
264  sprintf(buf, "\t\t sulfer %4s%%\n",
265  Estimate_i((int)(r->conditions[SULFUR]), Race, p));
266  notify(Playernum, Governor, buf);
267  sprintf(buf, "Tech: %s", Estimate_f(r->tech, Race, p));
268  notify(Playernum, Governor, buf);
269  sprintf(buf, "\t\t other %4s%%",
270  Estimate_i((int)(r->conditions[OTHER]), Race, p));
271  notify(Playernum, Governor, buf);
272  sprintf(buf, "\t\tMorale: %6s\n", Estimate_i((int)(r->morale), Race, p));
273  notify(Playernum, Governor, buf);
274  sprintf(buf, "Sector type preference : %s\n",
275  Race->translate[p - 1] > 80 ? Desnames[r->likesbest] : " ? ");
276  notify(Playernum, Governor, buf);
277  }
278 }
279 
280 static char est_buf[20];
281 
282 static char *Estimate_f(double data, Race *r, int p) {
283  int est;
284 
285  sprintf(est_buf, "?");
286 
287  if (r->translate[p - 1] > 10) {
288  est = round_perc((int)data, r, p);
289  if (est < 1000)
290  sprintf(est_buf, "%d", est);
291  else if (est < 10000)
292  sprintf(est_buf, "%.1fK", (double)est / 1000.);
293  else if (est < 1000000)
294  sprintf(est_buf, "%.0fK", (double)est / 1000.);
295  else
296  sprintf(est_buf, "%.1fM", (double)est / 1000000.);
297  }
298  return est_buf;
299 }
300 
301 char *Estimate_i(int data, Race *r, int p) {
302  int est;
303 
304  sprintf(est_buf, "?");
305 
306  if (r->translate[p - 1] > 10) {
307  est = round_perc((int)data, r, p);
308  if ((int)abs(est) < 1000)
309  sprintf(est_buf, "%d", est);
310  else if ((int)abs(est) < 10000)
311  sprintf(est_buf, "%.1fK", (double)est / 1000.);
312  else if ((int)abs(est) < 1000000)
313  sprintf(est_buf, "%.0fK", (double)est / 1000.);
314  else
315  sprintf(est_buf, "%.1fM", (double)est / 1000000.);
316  }
317  return est_buf;
318 }
319 
320 static int round_perc(int data, Race *r, int p) {
321  int k;
322 
323  k = 101 - MIN(r->translate[p - 1], 100);
324  return ((data / k) * k);
325 }
#define Wormhole(r)
Definition: races.h:121
#define Vn(r)
Definition: races.h:116
#define HELIUM
Definition: tweakables.h:37
#define SULFUR
Definition: tweakables.h:36
#define METHANE
Definition: tweakables.h:31
#define Cloak(r)
Definition: races.h:120
void treasury(const command_t &, GameObj &g)
Definition: prof.cc:54
void whois(const command_t &argv, GameObj &g)
Definition: prof.cc:24
#define Crystal(r)
Definition: races.h:122
#define OXYGEN
Definition: tweakables.h:32
static char * Estimate_f(double, Race *, int)
Definition: prof.cc:282
#define Cew(r)
Definition: races.h:115
#define Tractor_beam(r)
Definition: races.h:117
#define MIN(x, y)
Definition: tweakables.h:213
#define Temp(x)
Definition: tweakables.h:222
void profile(const command_t &argv, GameObj &g)
Definition: prof.cc:83
#define CO2
Definition: tweakables.h:33
#define TEMP
Definition: tweakables.h:30
#define Hyper_drive(r)
Definition: races.h:113
#define Transporter(r)
Definition: races.h:118
#define OTHER
Definition: tweakables.h:38
#define HYDROGEN
Definition: tweakables.h:34
#define Avpm(r)
Definition: races.h:119
#define NITROGEN
Definition: tweakables.h:35
#define Laser(r)
Definition: races.h:114
double gun_range(Race *, Ship *, int)
Definition: shootblast.cc:530
static char est_buf[20]
Definition: prof.cc:280
double tele_range(int, double)
Definition: shootblast.cc:539
static int round_perc(int, Race *, int)
Definition: prof.cc:320
char * Estimate_i(int data, Race *r, int p)
Definition: prof.cc:301