2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * repo.c: Report on various levels (tech, research) of other nations
30 * Known contributors to this file:
32 * Dave Pare, 1986 (rewrite)
45 static void repo_header(void);
46 static void repo_list(struct natstr *, struct natstr *);
47 static void printdiff(struct natstr *, struct natstr *, int what);
48 static int check(char *buf, double theirs, double min, double max,
49 int shift, int tolerance);
58 if (!snxtitem(&ni, EF_NATION, player->argp[1]))
61 natp = getnatp(player->cnum);
63 while (nxtitem(&ni, &nat)) {
64 if (nat.nat_stat == STAT_UNUSED)
67 if (!player->god && !getcontact(natp, ni.cur))
70 if (!player->god && nat.nat_stat != STAT_ACTIVE)
72 repo_list(natp, &nat);
80 pr(" # name tech research education happiness"
82 player->god ? "capital" : " status");
86 repo_list(struct natstr *plnatp, struct natstr *natp)
88 pr(" %-3d %-14.14s ", natp->nat_cnum, natp->nat_cnam);
89 if (player->god || player->cnum == natp->nat_cnum) {
90 pr(" %7.2f %7.2f %7.2f %7.2f%s",
91 natp->nat_level[NAT_TLEV], natp->nat_level[NAT_RLEV],
92 natp->nat_level[NAT_ELEV], natp->nat_level[NAT_HLEV],
93 player->god ? "" : " ");
95 printdiff(plnatp, natp, NAT_TLEV);
96 printdiff(plnatp, natp, NAT_RLEV);
97 printdiff(plnatp, natp, NAT_ELEV);
98 printdiff(plnatp, natp, NAT_HLEV);
101 prxy(" %4d,%-4d\n", natp->nat_xcap, natp->nat_ycap, player->cnum);
103 if (!opt_HIDDEN && influx(natp))
105 else if (!opt_HIDDEN && natp->nat_money <= 0)
113 printdiff(struct natstr *plnatp, struct natstr *natp, int what)
115 double ours = plnatp->nat_level[what];
122 && plnatp->nat_stat >= STAT_ACTIVE && natp->nat_stat >= STAT_ACTIVE) {
123 theirs = natp->nat_level[what];
124 if ((shift = min((int)theirs, (int)ours) - 100) > 0) {
139 if (tolerance > 2 * ours)
140 tolerance = (int)(2 * ours);
141 if (check(buf, theirs, 2 * ours, -1.0, shift, tolerance))
143 else if (check(buf, theirs, 1.5 * ours, 2.0 * ours, shift, tolerance))
145 else if (check(buf, theirs, 1.2 * ours, 1.5 * ours, shift, tolerance))
147 else if (check(buf, theirs, 1.1 * ours, 1.2 * ours, shift, tolerance))
149 else if (check(buf, theirs, ours / 1.1, 1.1 * ours, shift, tolerance))
151 else if (check(buf, theirs, ours / 1.2, ours / 1.1, shift, tolerance))
153 else if (check(buf, theirs, ours / 1.5, ours / 1.2, shift, tolerance))
155 else if (check(buf, theirs, ours / 2.0, ours / 1.5, shift, tolerance))
157 else if (check(buf, theirs, -1.0, ours / 2.0, shift, tolerance)) ;
159 sprintf(buf, " n/a");
161 sprintf(buf, " n/a");
167 check(char *buf, double theirs, double min, double max, int shift,
176 sprintf(buf, " 0 - %d", (int)max + shift);
179 } else if (max < 0) {
181 sprintf(buf, " >= %d", (int)min + shift);
184 } else if (theirs >= min && theirs <= max) {
185 if (max - min < tolerance) {
186 shove = (tolerance - (max - min)) / 2;
187 if (min + shift - shove >= 0) {
195 sprintf(buf, "%4d - %d", (int)min + shift, (int)max + shift);