5 #include "gb/commands/analysis.h" 11 #include "gb/GB_server.h" 12 #include "gb/buffers.h" 13 #include "gb/files_shl.h" 14 #include "gb/getplace.h" 18 #include "gb/tweakables.h" 28 static void do_analysis(GameObj &,
int,
int,
int, starnum_t, planetnum_t);
32 void analysis(
const command_t &argv, GameObj &g) {
41 where.level = g.level;
54 sector_type = SectorType::SEC_SEA;
57 sector_type = SectorType::SEC_LAND;
60 sector_type = SectorType::SEC_MOUNT;
63 sector_type = SectorType::SEC_GAS;
66 sector_type = SectorType::SEC_ICE;
69 sector_type = SectorType::SEC_FOREST;
72 sector_type = SectorType::SEC_DESERT;
75 sector_type = SectorType::SEC_PLATED;
78 sector_type = SectorType::SEC_WASTED;
81 if (sector_type != -1 && mode == 1) {
88 if (do_player > Num_races) {
89 g.out <<
"No such player #.\n";
92 where.level = g.level;
98 if (i < argv.size() && (isalpha(*p) || *p ==
'/')) {
99 where = getplace(g, argv[i], 0);
100 if (where.err)
continue;
103 switch (where.level) {
104 case ScopeLevel::LEVEL_UNIV:
105 case ScopeLevel::LEVEL_SHIP:
106 g.out <<
"You can only analyze planets.\n";
108 case ScopeLevel::LEVEL_PLAN:
111 case ScopeLevel::LEVEL_STAR:
112 for (planetnum_t pnum = 0; pnum < Stars[where.snum]->numplanets; pnum++)
119 static void do_analysis(GameObj &g,
int ThisPlayer,
int mode,
int sector_type,
120 starnum_t Starnum, planetnum_t Planetnum) {
121 player_t Playernum = g.player;
122 governor_t Governor = g.governor;
149 int PlaySect[
MAXPLAYERS + 1][SectorType::SEC_WASTED + 1];
153 int Sect[SectorType::SEC_WASTED + 1];
154 static char SectTypes[] = {CHAR_SEA, CHAR_LAND, CHAR_MOUNT,
155 CHAR_GAS, CHAR_ICE, CHAR_FOREST,
156 CHAR_DESERT, CHAR_PLATED, CHAR_WASTED};
158 for (i = 0; i <
CARE; i++)
162 TotalWasted = TotalCrys = TotalPopn = TotalMob = TotalTroops = TotalEff =
163 TotalRes = TotalSect = 0;
164 for (p = 0; p <= Num_races; p++) {
165 PlayTroops[p] = PlayPopn[p] = PlayMob[p] = PlayEff[p] = PlayCrys[p] =
166 PlayRes[p] = PlayTSect[p] = 0;
168 for (i = 0; i <= SectorType::SEC_WASTED; i++) PlaySect[p][i] = 0;
171 for (i = 0; i <= SectorType::SEC_WASTED; i++) Sect[i] = 0;
173 Race = races[Playernum - 1];
176 if (!planet.info[Playernum - 1].explored) {
183 TotalSect = planet.Maxx * planet.Maxy;
184 for (x = planet.Maxx - 1; x >= 0; x--) {
185 for (y = planet.Maxy - 1; y >= 0; y--) {
186 auto § = smap.get(x, y);
189 PlayEff[p] += sect.eff;
190 PlayMob[p] += sect.mobilization;
191 PlayRes[p] += sect.resource;
192 PlayPopn[p] += sect.popn;
193 PlayTroops[p] += sect.troops;
194 PlaySect[p][sect.condition]++;
196 TotalEff += sect.eff;
197 TotalMob += sect.mobilization;
198 TotalRes += sect.resource;
199 TotalPopn += sect.popn;
200 TotalTroops += sect.troops;
201 Sect[sect.condition]++;
203 if (sect.condition == SectorType::SEC_WASTED) {
212 if (sector_type == -1 || sector_type == sect.condition) {
213 if (ThisPlayer < 0 || ThisPlayer == p) {
216 Insert(mode
, Mob
, x
, y
, sect.condition
, (
int)sect.mobilization
);
219 Insert(mode
, Troops
, x
, y
, sect.condition
, (
int)sect.troops
);
227 sprintf(buf,
"\nAnalysis of /%s/%s:\n", Stars[Starnum]->name,
228 Stars[Starnum]->pnames[Planetnum]);
229 notify(Playernum, Governor, buf);
230 sprintf(buf,
"%s %d", (mode ?
"Highest" :
"Lowest"),
CARE);
231 switch (sector_type) {
233 sprintf(buf,
"%s of all", buf);
235 case SectorType::SEC_SEA:
236 sprintf(buf,
"%s Ocean", buf);
238 case SectorType::SEC_LAND:
239 sprintf(buf,
"%s Land", buf);
241 case SectorType::SEC_MOUNT:
242 sprintf(buf,
"%s Mountain", buf);
244 case SectorType::SEC_GAS:
245 sprintf(buf,
"%s Gas", buf);
247 case SectorType::SEC_ICE:
248 sprintf(buf,
"%s Ice", buf);
250 case SectorType::SEC_FOREST:
251 sprintf(buf,
"%s Forest", buf);
253 case SectorType::SEC_DESERT:
254 sprintf(buf,
"%s Desert", buf);
256 case SectorType::SEC_PLATED:
257 sprintf(buf,
"%s Plated", buf);
259 case SectorType::SEC_WASTED:
260 sprintf(buf,
"%s Wasted", buf);
263 notify(Playernum, Governor, buf);
265 sprintf(buf,
" sectors.\n");
266 else if (ThisPlayer == 0)
267 sprintf(buf,
" sectors that are unoccupied.\n");
269 sprintf(buf,
" sectors owned by %d.\n", ThisPlayer);
270 notify(Playernum, Governor, buf);
281 sprintf(buf,
"%2s %3s %7s %6s %5s %5s %5s %2s",
"Pl",
"sec",
"popn",
"troops",
282 "a.eff",
"a.mob",
"res",
"x");
283 notify(Playernum, Governor, buf);
285 for (i = 0; i <= SectorType::SEC_WASTED; i++) {
286 sprintf(buf,
"%4c", SectTypes[i]);
287 notify(Playernum, Governor, buf);
289 notify(Playernum, Governor,
290 "\n----------------------------------------------" 291 "---------------------------------\n");
292 for (p = 0; p <= Num_races; p++)
293 if (PlayTSect[p] != 0) {
294 sprintf(buf,
"%2d %3d %7d %6d %5.1lf %5.1lf %5d %2d", p, PlayTSect[p],
295 PlayPopn[p], PlayTroops[p], (
double)PlayEff[p] / PlayTSect[p],
296 (
double)PlayMob[p] / PlayTSect[p], PlayRes[p], PlayCrys[p]);
297 notify(Playernum, Governor, buf);
298 for (i = 0; i <= SectorType::SEC_WASTED; i++) {
299 sprintf(buf,
"%4d", PlaySect[p][i]);
300 notify(Playernum, Governor, buf);
304 notify(Playernum, Governor,
305 "------------------------------------------------" 306 "-------------------------------\n");
307 sprintf(buf,
"%2s %3d %7d %6d %5.1lf %5.1lf %5d %2d",
"Tl", TotalSect,
308 TotalPopn, TotalTroops, (
double)TotalEff / TotalSect,
309 (
double)TotalMob / TotalSect, TotalRes, TotalCrys);
310 notify(Playernum, Governor, buf);
311 for (i = 0; i <= SectorType::SEC_WASTED; i++) {
312 sprintf(buf,
"%4d", Sect[i]);
313 notify(Playernum, Governor, buf);
320 for (
int i = 0; i <
CARE; i++)
321 if ((mode && arr[i]
.value < value) ||
322 (!mode && (arr[i]
.value > value || arr[i]
.value == -1))) {
323 for (
int j =
CARE - 1; j > i; j--) arr[j] = arr[j - 1];
333 player_t Playernum = g.player;
334 governor_t Governor = g.governor;
336 sprintf(buf,
"%8s:", name);
337 notify(Playernum, Governor, buf);
338 for (
int i = 0; i <
CARE && arr[i]
.value != -1; i++) {
339 sprintf(buf,
"%5d%c(%2d,%2d)", arr[i]
.value, Dessymbols[arr[i]
.des],
341 notify(Playernum, Governor, buf);
Planet getplanet(const starnum_t star, const planetnum_t pnum)
static void do_analysis(GameObj &, int, int, int, starnum_t, planetnum_t)
static void PrintTop(GameObj &, struct anal_sect[], const char *)
double compatibility(const Planet &planet, const Race *race)
void analysis(const command_t &argv, GameObj &g)
static void Insert(int, struct anal_sect[], int, int, int, int)
SectorMap getsmap(const Planet &p)
int maxsupport(const Race *r, const Sector &s, const double c, const int toxic)