2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future 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)
41 static void repo_header(void);
42 static void repo_list(struct natstr *, struct natstr *);
43 static void printdiff(struct natstr *, struct natstr *, int what);
44 static int tryprdiff(double, double, double, int, int);
53 if (!snxtitem(&ni, EF_NATION, player->argp[1]))
56 natp = getnatp(player->cnum);
58 while (nxtitem(&ni, &nat)) {
59 if (nat.nat_stat == STAT_UNUSED)
62 if (!player->god && !getcontact(natp, ni.cur))
65 if (!player->god && nat.nat_stat != STAT_ACTIVE)
67 repo_list(natp, &nat);
75 pr(" # name tech research education happiness"
77 player->god ? "capital" : " status");
81 repo_list(struct natstr *plnatp, struct natstr *natp)
83 pr(" %-3d %-14.14s ", natp->nat_cnum, natp->nat_cnam);
84 if (player->god || player->cnum == natp->nat_cnum) {
85 pr(" %7.2f %7.2f %7.2f %7.2f%s",
86 natp->nat_level[NAT_TLEV], natp->nat_level[NAT_RLEV],
87 natp->nat_level[NAT_ELEV], natp->nat_level[NAT_HLEV],
88 player->god ? "" : " ");
90 printdiff(plnatp, natp, NAT_TLEV);
91 printdiff(plnatp, natp, NAT_RLEV);
92 printdiff(plnatp, natp, NAT_ELEV);
93 printdiff(plnatp, natp, NAT_HLEV);
96 prxy(" %4d,%-4d\n", natp->nat_xcap, natp->nat_ycap, player->cnum);
98 if (!opt_HIDDEN && influx(natp))
100 else if (!opt_HIDDEN && natp->nat_money <= 0)
108 printdiff(struct natstr *plnatp, struct natstr *natp, int what)
110 double ours = plnatp->nat_level[what];
116 && plnatp->nat_stat >= STAT_ACTIVE
117 && natp->nat_stat >= STAT_ACTIVE) {
118 theirs = natp->nat_level[what];
119 if ((shift = MIN((int)theirs, (int)ours) - 100) > 0) {
134 if (tolerance > 2 * ours)
135 tolerance = (int)(2 * ours);
136 if (tryprdiff(theirs, 2 * ours, -1.0, shift, tolerance))
138 else if (tryprdiff(theirs, 1.5 * ours, 2.0 * ours, shift, tolerance))
140 else if (tryprdiff(theirs, 1.2 * ours, 1.5 * ours, shift, tolerance))
142 else if (tryprdiff(theirs, 1.1 * ours, 1.2 * ours, shift, tolerance))
144 else if (tryprdiff(theirs, ours / 1.1, 1.1 * ours, shift, tolerance))
146 else if (tryprdiff(theirs, ours / 1.2, ours / 1.1, shift, tolerance))
148 else if (tryprdiff(theirs, ours / 1.5, ours / 1.2, shift, tolerance))
150 else if (tryprdiff(theirs, ours / 2.0, ours / 1.5, shift, tolerance))
152 else if (tryprdiff(theirs, -1.0, ours / 2.0, shift, tolerance)) ;
160 tryprdiff(double theirs, double min, double max, int shift, int tolerance)
168 pr(" 0 - %-4d ", (int)max + shift);
171 } else if (max < 0) {
173 pr(" >= %-4d ", (int)min + shift);
176 } else if (theirs >= min && theirs <= max) {
177 if (max - min < tolerance) {
178 shove = (tolerance - (max - min)) / 2;
179 if (min + shift - shove >= 0) {
187 pr("%4d - %-4d ", (int)min + shift, (int)max + shift);