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)
58 static void printdiff(int mystat, double ours, struct natstr *natp,
60 static void repo_header(void);
61 static void repo_list(struct stats *stat, natid cn, struct natstr *natp);
63 static int check(s_char *buf, double theirs, double min, double max,
64 int shift, int tolerance);
75 if (!snxtitem(&ni, EF_NATION, player->argp[1]))
78 natp = getnatp(player->cnum);
79 memset(&mystat, 0, sizeof(struct stats));
80 mystat.stat = natp->nat_stat;
81 if (mystat.stat >= STAT_ACTIVE) {
82 mystat.res = natp->nat_level[NAT_RLEV];
83 mystat.tech = natp->nat_level[NAT_TLEV];
84 mystat.edu = natp->nat_level[NAT_ELEV];
85 mystat.hap = natp->nat_level[NAT_HLEV];
93 while (nxtitem(&ni, &nat)) {
94 if (nat.nat_stat == STAT_UNUSED)
97 if (!player->god && !getcontact(getnatp(player->cnum), ni.cur))
104 repo_list(&mystat, (natid)ni.cur, &nat);
112 pr(" # name tech research education happiness ");
124 repo_list(struct stats *stat, natid cn, struct natstr *natp)
127 pr(" %-3d %-14.14s ", cn, natp->nat_cnam);
128 pr(" %7.2f %7.2f %7.2f %7.2f",
129 natp->nat_level[NAT_TLEV],
130 natp->nat_level[NAT_RLEV],
131 natp->nat_level[NAT_ELEV], natp->nat_level[NAT_HLEV]);
132 prxy(" %4d,%-4d\n", natp->nat_xcap, natp->nat_ycap, player->cnum);
135 if (natp->nat_stat == STAT_ACTIVE) {
136 pr(" %-3d %-14.14s ", cn, natp->nat_cnam);
137 printdiff(stat->stat, stat->tech, natp, NAT_TLEV);
138 printdiff(stat->stat, stat->res, natp, NAT_RLEV);
139 printdiff(stat->stat, stat->edu, natp, NAT_ELEV);
140 printdiff(stat->stat, stat->hap, natp, NAT_HLEV);
146 else if (natp->nat_money <= 0)
155 printdiff(int mystat, double ours, struct natstr *natp, int what)
162 if (natp->nat_cnum == player->cnum) {
166 if (ours && mystat >= STAT_ACTIVE && natp->nat_stat >= STAT_ACTIVE) {
167 theirs = natp->nat_level[what];
168 if ((shift = min((int)theirs, (int)ours) - 100) > 0) {
183 if (tolerance > 2 * ours)
184 tolerance = (int)(2 * ours);
185 if (check(buf, theirs, 2 * ours, -1.0, shift, tolerance))
187 else if (check(buf, theirs, 1.5 * ours, 2.0 * ours, shift, tolerance))
189 else if (check(buf, theirs, 1.2 * ours, 1.5 * ours, shift, tolerance))
191 else if (check(buf, theirs, 1.1 * ours, 1.2 * ours, shift, tolerance))
193 else if (check(buf, theirs, ours / 1.1, 1.1 * ours, shift, tolerance))
195 else if (check(buf, theirs, ours / 1.2, ours / 1.1, shift, tolerance))
197 else if (check(buf, theirs, ours / 1.5, ours / 1.2, shift, tolerance))
199 else if (check(buf, theirs, ours / 2.0, ours / 1.5, shift, tolerance))
201 else if (check(buf, theirs, -1.0, ours / 2.0, shift, tolerance)) ;
203 sprintf(buf, " n/a");
205 sprintf(buf, " n/a");
211 check(s_char *buf, double theirs, double min, double max, int shift,
220 sprintf(buf, " 0 - %d", (int)max + shift);
223 } else if (max < 0) {
225 sprintf(buf, " >= %d", (int)min + shift);
228 } else if (theirs >= min && theirs <= max) {
229 if (max - min < tolerance) {
230 shove = (tolerance - (max - min)) / 2;
231 if (min + shift - shove >= 0) {
239 sprintf(buf, "%4d - %d", (int)min + shift, (int)max + shift);