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 tryprdiff(double, double, double, int, int);
57 if (!snxtitem(&ni, EF_NATION, player->argp[1]))
60 natp = getnatp(player->cnum);
62 while (nxtitem(&ni, &nat)) {
63 if (nat.nat_stat == STAT_UNUSED)
66 if (!player->god && !getcontact(natp, ni.cur))
69 if (!player->god && nat.nat_stat != STAT_ACTIVE)
71 repo_list(natp, &nat);
79 pr(" # name tech research education happiness"
81 player->god ? "capital" : " status");
85 repo_list(struct natstr *plnatp, struct natstr *natp)
87 pr(" %-3d %-14.14s ", natp->nat_cnum, natp->nat_cnam);
88 if (player->god || player->cnum == natp->nat_cnum) {
89 pr(" %7.2f %7.2f %7.2f %7.2f%s",
90 natp->nat_level[NAT_TLEV], natp->nat_level[NAT_RLEV],
91 natp->nat_level[NAT_ELEV], natp->nat_level[NAT_HLEV],
92 player->god ? "" : " ");
94 printdiff(plnatp, natp, NAT_TLEV);
95 printdiff(plnatp, natp, NAT_RLEV);
96 printdiff(plnatp, natp, NAT_ELEV);
97 printdiff(plnatp, natp, NAT_HLEV);
100 prxy(" %4d,%-4d\n", natp->nat_xcap, natp->nat_ycap, player->cnum);
102 if (!opt_HIDDEN && influx(natp))
104 else if (!opt_HIDDEN && natp->nat_money <= 0)
112 printdiff(struct natstr *plnatp, struct natstr *natp, int what)
114 double ours = plnatp->nat_level[what];
120 && plnatp->nat_stat >= STAT_ACTIVE && natp->nat_stat >= STAT_ACTIVE) {
121 theirs = natp->nat_level[what];
122 if ((shift = MIN((int)theirs, (int)ours) - 100) > 0) {
137 if (tolerance > 2 * ours)
138 tolerance = (int)(2 * ours);
139 if (tryprdiff(theirs, 2 * ours, -1.0, shift, tolerance))
141 else if (tryprdiff(theirs, 1.5 * ours, 2.0 * ours, shift, tolerance))
143 else if (tryprdiff(theirs, 1.2 * ours, 1.5 * ours, shift, tolerance))
145 else if (tryprdiff(theirs, 1.1 * ours, 1.2 * ours, shift, tolerance))
147 else if (tryprdiff(theirs, ours / 1.1, 1.1 * ours, shift, tolerance))
149 else if (tryprdiff(theirs, ours / 1.2, ours / 1.1, shift, tolerance))
151 else if (tryprdiff(theirs, ours / 1.5, ours / 1.2, shift, tolerance))
153 else if (tryprdiff(theirs, ours / 2.0, ours / 1.5, shift, tolerance))
155 else if (tryprdiff(theirs, -1.0, ours / 2.0, shift, tolerance)) ;
163 tryprdiff(double theirs, double min, double max, int shift, int tolerance)
171 pr(" 0 - %-4d ", (int)max + shift);
174 } else if (max < 0) {
176 pr(" >= %-4d ", (int)min + shift);
179 } else if (theirs >= min && theirs <= max) {
180 if (max - min < tolerance) {
181 shove = (tolerance - (max - min)) / 2;
182 if (min + shift - shove >= 0) {
190 pr("%4d - %-4d ", (int)min + shift, (int)max + shift);