/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
- * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- * related information and legal notices. It is expected that any future
- * projects/authors will amend these files as needed.
+ * See files README, COPYING and CREDITS in the root of the source
+ * tree for related information and legal notices. It is expected
+ * that future projects/authors will amend these files as needed.
*
* ---
*
* repo.c: Report on various levels (tech, research) of other nations
- *
+ *
* Known contributors to this file:
* Keith Muller, 1983
* Dave Pare, 1986 (rewrite)
#include <config.h>
-#include "misc.h"
-#include "player.h"
-#include "nat.h"
-#include "file.h"
#include "commands.h"
#include "optlist.h"
static void repo_header(void);
static void repo_list(struct natstr *, struct natstr *);
static void printdiff(struct natstr *, struct natstr *, int what);
-static int check(char *buf, double theirs, double min, double max,
- int shift, int tolerance);
+static int tryprdiff(double, double, double, int, int);
int
repo(void)
struct natstr nat;
struct nstr_item ni;
- if (!snxtitem(&ni, EF_NATION, player->argp[1]))
+ if (!snxtitem(&ni, EF_NATION, player->argp[1], NULL))
return RET_SYN;
prdate();
natp = getnatp(player->cnum);
printdiff(plnatp, natp, NAT_HLEV);
}
if (player->god) {
- prxy(" %4d,%-4d\n", natp->nat_xcap, natp->nat_ycap, player->cnum);
+ prxy(" %4d,%-4d\n", natp->nat_xcap, natp->nat_ycap);
} else {
if (!opt_HIDDEN && influx(natp))
pr("In flux\n");
- else if (!opt_HIDDEN && natp->nat_money <= 0)
+ else if (!opt_HIDDEN && natp->nat_money < 0)
pr("Broke\n");
else
pr("Active\n");
double theirs;
int shift;
int tolerance;
- char buf[128];
if (ours
- && plnatp->nat_stat >= STAT_ACTIVE && natp->nat_stat >= STAT_ACTIVE) {
+ && plnatp->nat_stat >= STAT_ACTIVE
+ && natp->nat_stat >= STAT_ACTIVE) {
theirs = natp->nat_level[what];
- if ((shift = min((int)theirs, (int)ours) - 100) > 0) {
+ if ((shift = MIN((int)theirs, (int)ours) - 100) > 0) {
ours -= shift;
theirs -= shift;
} else
}
if (tolerance > 2 * ours)
tolerance = (int)(2 * ours);
- if (check(buf, theirs, 2 * ours, -1.0, shift, tolerance))
+ if (tryprdiff(theirs, 2 * ours, -1.0, shift, tolerance))
;
- else if (check(buf, theirs, 1.5 * ours, 2.0 * ours, shift, tolerance))
+ else if (tryprdiff(theirs, 1.5 * ours, 2.0 * ours, shift, tolerance))
;
- else if (check(buf, theirs, 1.2 * ours, 1.5 * ours, shift, tolerance))
+ else if (tryprdiff(theirs, 1.2 * ours, 1.5 * ours, shift, tolerance))
;
- else if (check(buf, theirs, 1.1 * ours, 1.2 * ours, shift, tolerance))
+ else if (tryprdiff(theirs, 1.1 * ours, 1.2 * ours, shift, tolerance))
;
- else if (check(buf, theirs, ours / 1.1, 1.1 * ours, shift, tolerance))
+ else if (tryprdiff(theirs, ours / 1.1, 1.1 * ours, shift, tolerance))
;
- else if (check(buf, theirs, ours / 1.2, ours / 1.1, shift, tolerance))
+ else if (tryprdiff(theirs, ours / 1.2, ours / 1.1, shift, tolerance))
;
- else if (check(buf, theirs, ours / 1.5, ours / 1.2, shift, tolerance))
+ else if (tryprdiff(theirs, ours / 1.5, ours / 1.2, shift, tolerance))
;
- else if (check(buf, theirs, ours / 2.0, ours / 1.5, shift, tolerance))
+ else if (tryprdiff(theirs, ours / 2.0, ours / 1.5, shift, tolerance))
;
- else if (check(buf, theirs, -1.0, ours / 2.0, shift, tolerance)) ;
+ else if (tryprdiff(theirs, -1.0, ours / 2.0, shift, tolerance)) ;
else
- sprintf(buf, " n/a");
+ pr(" n/a ");
} else
- sprintf(buf, " n/a");
-
- pr("%-11s ", buf);
+ pr(" n/a ");
}
static int
-check(char *buf, double theirs, double min, double max, int shift,
- int tolerance)
+tryprdiff(double theirs, double min, double max, int shift, int tolerance)
{
double shove;
if (theirs <= max) {
if (max < tolerance)
max = tolerance;
- sprintf(buf, " 0 - %d", (int)max + shift);
+ pr(" 0 - %-4d ", (int)max + shift);
return 1;
}
} else if (max < 0) {
if (theirs >= min) {
- sprintf(buf, " >= %d", (int)min + shift);
+ pr(" >= %-4d ", (int)min + shift);
return 1;
}
} else if (theirs >= min && theirs <= max) {
max = tolerance;
}
}
- sprintf(buf, "%4d - %d", (int)min + shift, (int)max + shift);
+ pr("%4d - %-4d ", (int)min + shift, (int)max + shift);
return 1;
}