2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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, int what);
59 static void repo_header(void);
60 static void repo_list(struct stats *stat, natid cn, struct natstr *natp);
62 static int check(s_char *buf, double theirs, double min, double max, int shift, int what, int tolerance);
73 if (!snxtitem(&ni, EF_NATION, player->argp[1]))
76 natp = getnatp(player->cnum);
77 bzero((s_char *)&mystat, sizeof(struct stats));
78 mystat.stat = natp->nat_stat;
79 if (mystat.stat & STAT_NORM) {
80 mystat.res = natp->nat_level[NAT_RLEV];
81 mystat.tech = natp->nat_level[NAT_TLEV];
82 mystat.edu = natp->nat_level[NAT_ELEV];
83 mystat.hap = natp->nat_level[NAT_HLEV];
91 while (nxtitem(&ni, (s_char *) &nat)) {
92 if (!(nat.nat_stat & STAT_INUSE))
96 !getcontact(getnatp(player->cnum), ni.cur))
103 repo_list(&mystat, (natid)ni.cur, &nat);
111 pr(" # name tech research education happiness ");
123 repo_list(struct stats *stat, natid cn, struct natstr *natp)
128 pr(" %-3d %-14.14s ", cn, natp->nat_cnam);
129 pr(" %7.2f %7.2f %7.2f %7.2f",
130 natp->nat_level[NAT_TLEV],
131 natp->nat_level[NAT_RLEV],
132 natp->nat_level[NAT_ELEV],
133 natp->nat_level[NAT_HLEV]);
134 prxy(" %4d,%-4d\n", natp->nat_xcap, natp->nat_ycap,
138 switch (natp->nat_stat & (STAT_NORM|STAT_GOD|STAT_NEW|STAT_SANCT)) {
140 case (STAT_NORM|STAT_SANCT):
141 pr(" %-3d %-14.14s ", cn, natp->nat_cnam);
142 printdiff(stat->stat, stat->tech, natp, NAT_TLEV);
143 printdiff(stat->stat, stat->res, natp, NAT_RLEV);
144 printdiff(stat->stat, stat->edu, natp, NAT_ELEV);
145 printdiff(stat->stat, stat->hap, natp, NAT_HLEV);
146 getsect(natp->nat_xcap, natp->nat_ycap, &cap);
150 if ((cap.sct_own != cn) ||
151 (cap.sct_type != SCT_CAPIT &&
152 cap.sct_type != SCT_MOUNT) ||
153 (natp->nat_flags & NF_SACKED))
155 else if (natp->nat_money <= 0)
166 case STAT_SANCT|STAT_NORM|STAT_GOD:
167 case STAT_NORM|STAT_GOD:
171 pr("???? ???? ???? ????\n");
177 printdiff(int mystat, double ours, struct natstr *natp, int what)
184 if (natp->nat_cnum == player->cnum) {
188 if (ours && mystat & STAT_NORM &&
189 natp->nat_stat &STAT_NORM) {
190 theirs = natp->nat_level[what];
191 if ((shift = min((int)theirs, (int)ours) - 100) > 0) {
198 tolerance = 20; break;
200 tolerance = 10; break;
204 if (tolerance > 2 * ours)
205 tolerance = (int)(2 * ours);
206 if (check(buf, theirs, 2 * ours, -1.0, shift, what, tolerance));
207 else if (check(buf, theirs, 1.5*ours, 2.0*ours, shift, what, tolerance));
208 else if (check(buf, theirs, 1.2*ours, 1.5*ours, shift, what, tolerance));
209 else if (check(buf, theirs, 1.1*ours, 1.2*ours, shift, what, tolerance));
210 else if (check(buf, theirs, ours/1.1, 1.1*ours, shift, what, tolerance));
211 else if (check(buf, theirs, ours/1.2, ours/1.1, shift, what, tolerance));
212 else if (check(buf, theirs, ours/1.5, ours/1.2, shift, what, tolerance));
213 else if (check(buf, theirs, ours/2.0, ours/1.5, shift, what, tolerance));
214 else if (check(buf, theirs, -1.0, ours/2.0, shift, what, tolerance));
215 else sprintf(buf, " n/a");
217 sprintf(buf, " n/a");
223 check(s_char *buf, double theirs, double min, double max, int shift, int what, int tolerance)
231 sprintf(buf, " 0 - %d", (int)max + shift);
234 } else if (max < 0) {
236 sprintf(buf, " >= %d", (int)min + shift);
239 } else if (theirs >= min && theirs <= max) {
240 if (max - min < tolerance) {
241 shove = (tolerance - (max - min)) / 2;
242 if (min + shift - shove >= 0) {
250 sprintf(buf, "%4d - %d", (int)min + shift, (int)max + shift);