2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * repo.c: Report on various levels (tech, research) of other nations
29 * Known contributors to this file:
31 * Dave Pare, 1986 (rewrite)
40 static void repo_header(void);
41 static void repo_list(struct natstr *, struct natstr *);
42 static void printdiff(struct natstr *, struct natstr *, int what);
43 static int tryprdiff(double, double, double, int, int);
52 if (!snxtitem(&ni, EF_NATION, player->argp[1], NULL))
55 natp = getnatp(player->cnum);
57 while (nxtitem(&ni, &nat)) {
58 if (nat.nat_stat == STAT_UNUSED)
61 if (!player->god && !getcontact(natp, ni.cur))
64 if (!player->god && nat.nat_stat != STAT_ACTIVE)
66 repo_list(natp, &nat);
74 pr(" # name tech research education happiness"
76 player->god ? "capital" : " status");
80 repo_list(struct natstr *plnatp, struct natstr *natp)
82 pr(" %-3d %-14.14s ", natp->nat_cnum, natp->nat_cnam);
83 if (player->god || player->cnum == natp->nat_cnum) {
84 pr(" %7.2f %7.2f %7.2f %7.2f%s",
85 natp->nat_level[NAT_TLEV], natp->nat_level[NAT_RLEV],
86 natp->nat_level[NAT_ELEV], natp->nat_level[NAT_HLEV],
87 player->god ? "" : " ");
89 printdiff(plnatp, natp, NAT_TLEV);
90 printdiff(plnatp, natp, NAT_RLEV);
91 printdiff(plnatp, natp, NAT_ELEV);
92 printdiff(plnatp, natp, NAT_HLEV);
95 prxy(" %4d,%-4d\n", natp->nat_xcap, natp->nat_ycap);
97 if (!opt_HIDDEN && influx(natp))
99 else if (!opt_HIDDEN && natp->nat_money < 0)
107 printdiff(struct natstr *plnatp, struct natstr *natp, int what)
109 double ours = plnatp->nat_level[what];
115 && plnatp->nat_stat >= STAT_ACTIVE
116 && natp->nat_stat >= STAT_ACTIVE) {
117 theirs = natp->nat_level[what];
118 if ((shift = MIN((int)theirs, (int)ours) - 100) > 0) {
133 if (tolerance > 2 * ours)
134 tolerance = (int)(2 * ours);
135 if (tryprdiff(theirs, 2 * ours, -1.0, shift, tolerance))
137 else if (tryprdiff(theirs, 1.5 * ours, 2.0 * ours, shift, tolerance))
139 else if (tryprdiff(theirs, 1.2 * ours, 1.5 * ours, shift, tolerance))
141 else if (tryprdiff(theirs, 1.1 * ours, 1.2 * ours, shift, tolerance))
143 else if (tryprdiff(theirs, ours / 1.1, 1.1 * ours, shift, tolerance))
145 else if (tryprdiff(theirs, ours / 1.2, ours / 1.1, shift, tolerance))
147 else if (tryprdiff(theirs, ours / 1.5, ours / 1.2, shift, tolerance))
149 else if (tryprdiff(theirs, ours / 2.0, ours / 1.5, shift, tolerance))
151 else if (tryprdiff(theirs, -1.0, ours / 2.0, shift, tolerance)) ;
159 tryprdiff(double theirs, double min, double max, int shift, int tolerance)
167 pr(" 0 - %-4d ", (int)max + shift);
170 } else if (max < 0) {
172 pr(" >= %-4d ", (int)min + shift);
175 } else if (theirs >= min && theirs <= max) {
176 if (max - min < tolerance) {
177 shove = (tolerance - (max - min)) / 2;
178 if (min + shift - shove >= 0) {
186 pr("%4d - %-4d ", (int)min + shift, (int)max + shift);