#include <string.h>
#include <sys/types.h>
+#define MAX(a,b) (a > b ? a : b)
+#define MIN(a,b) (a < b ? a : b)
+
#if defined(_WIN32)
typedef unsigned char u_char;
typedef unsigned short u_short;
/* integral mismatch, due to misuse of sector short */
#ifndef __GNUC__
#pragma warning (disable : 4761 )
-#else
-#define max(a,b) ((a)>(b)?(a):(b))
-#define min(a,b) ((a)<(b)?(a):(b))
#endif
#include <io.h>
#define RET_SYN 2 /* syntax error in command */
#define RET_SYS 3 /* system error (missing file, etc) */
-double dmax(double n1, double n2);
-double dmin(double n1, double n2);
-
extern char *getstarg(char *input, char *prompt, char buf[]);
extern char *getstring(char *prompt, char buf[]);
extern char *ugetstring(char *prompt, char buf[]);
extern int deltax(int, int);
extern int deltay(int, int);
extern int mapdist(int, int, int, int);
-#if !defined(_WIN32)
-extern int max(int, int);
-extern int min(int, int);
-#endif
extern s_char *effadv(int);
extern int onearg(s_char *, s_char *);
extern int parse(char *, char **, char **, char *, char **);
continue;
shell = gun = 0;
- gun = min(ship.shp_item[I_GUN], ship.shp_glim);
+ gun = MIN(ship.shp_item[I_GUN], ship.shp_glim);
if (gun > 0) {
shell = ship.shp_item[I_SHELL];
if (shell <= 0)
if (!check_sect_ok(§))
continue;
- thresh = min(thresh, ITEM_MAX) & ~7;
+ thresh = MIN(thresh, ITEM_MAX) & ~7;
del = thresh | dir;
sect.sct_del[ich->i_vtype] = del;
putsect(§);
if (sect.sct_own != sect.sct_oldown)
continue;
civ = sect.sct_item[I_CIVIL];
- deltamil = number < 0 ? mil + number : min(mil, number);
+ deltamil = number < 0 ? mil + number : MIN(mil, number);
if (deltamil <= 0)
continue;
if (deltamil > ITEM_MAX - civ)
xyas(sect.sct_x, sect.sct_y, player->cnum));
continue;
}
- move_amt = min(tot_fuel, fuel_amt);
- move_amt = min(move_amt, max_amt);
+ move_amt = MIN(tot_fuel, fuel_amt);
+ move_amt = MIN(move_amt, max_amt);
if (move_amt == 0)
continue;
extra = ((float)move_amt / 5.0) - (move_amt / 5);
if (extra > 0.0)
sect.sct_item[I_PETROL]
- = max((pet_amt - move_amt / 5) - 1, 0);
+ = MAX((pet_amt - move_amt / 5) - 1, 0);
else
sect.sct_item[I_PETROL]
- = max((pet_amt - move_amt / 5), 0);
+ = MAX((pet_amt - move_amt / 5), 0);
} else {
sect.sct_item[I_PETROL] = 0;
move_amt -= pet_amt * 5;
extra = ((float)move_amt / 50.0) - (move_amt / 50);
- sect.sct_item[I_OIL] = max(oil_amt - move_amt / 50, 0);
+ sect.sct_item[I_OIL] = MAX(oil_amt - move_amt / 50, 0);
if (extra > 0.0)
sect.sct_item[I_OIL]
- = max((oil_amt - move_amt / 50) - 1, 0);
+ = MAX((oil_amt - move_amt / 50) - 1, 0);
else
sect.sct_item[I_OIL]
- = max((oil_amt - move_amt / 50), 0);
+ = MAX((oil_amt - move_amt / 50), 0);
}
/* load plague */
continue;
}
tot_fuel = oil_amt * 50 + pet_amt * 5;
- move_amt = min(tot_fuel, fuel_amt);
- move_amt = min(move_amt, max_amt);
+ move_amt = MIN(tot_fuel, fuel_amt);
+ move_amt = MIN(move_amt, max_amt);
if (move_amt == 0)
continue;
extra = ((float)move_amt / 5.0) - (move_amt / 5);
if (extra > 0.0)
item2.ship.shp_item[I_PETROL]
- = max((pet_amt - move_amt / 5) - 1, 0);
+ = MAX((pet_amt - move_amt / 5) - 1, 0);
else
item2.ship.shp_item[I_PETROL]
- = max((pet_amt - move_amt / 5), 0);
+ = MAX((pet_amt - move_amt / 5), 0);
} else {
item2.ship.shp_item[I_PETROL] = 0;
move_amt -= pet_amt * 5;
extra = ((float)move_amt / 50.0) - (move_amt / 50);
item2.ship.shp_item[I_OIL]
- = max(oil_amt - (move_amt / 50), 0);
+ = MAX(oil_amt - (move_amt / 50), 0);
if (extra > 0.0)
item2.ship.shp_item[I_OIL]
- = max((oil_amt - move_amt / 50) - 1, 0);
+ = MAX((oil_amt - move_amt / 50) - 1, 0);
else
item2.ship.shp_item[I_OIL]
- = max((oil_amt - move_amt / 50), 0);
+ = MAX((oil_amt - move_amt / 50), 0);
}
/* load plague */
xyas(sect.sct_x, sect.sct_y, player->cnum));
continue;
}
- move_amt = min(tot_fuel, fuel_amt);
- move_amt = min(move_amt, max_amt);
+ move_amt = MIN(tot_fuel, fuel_amt);
+ move_amt = MIN(move_amt, max_amt);
if (move_amt == 0)
continue;
extra = ((float)move_amt / 5.0) - (move_amt / 5);
if (extra > 0.0)
sect.sct_item[I_PETROL]
- = max((pet_amt - move_amt / 5) - 1, 0);
+ = MAX((pet_amt - move_amt / 5) - 1, 0);
else
sect.sct_item[I_PETROL]
- = max((pet_amt - move_amt / 5), 0);
+ = MAX((pet_amt - move_amt / 5), 0);
} else {
sect.sct_item[I_PETROL] = 0;
move_amt -= pet_amt * 5;
extra = ((float)move_amt / 50.0) - (move_amt / 50);
- sect.sct_item[I_OIL] = max(oil_amt - move_amt / 50, 0);
+ sect.sct_item[I_OIL] = MAX(oil_amt - move_amt / 50, 0);
if (extra > 0.0)
sect.sct_item[I_OIL]
- = max((oil_amt - move_amt / 50) - 1, 0);
+ = MAX((oil_amt - move_amt / 50) - 1, 0);
else
sect.sct_item[I_OIL]
- = max((oil_amt - move_amt / 50), 0);
+ = MAX((oil_amt - move_amt / 50), 0);
}
/* load plague */
continue;
}
tot_fuel = oil_amt * 50 + pet_amt * 5;
- move_amt = min(tot_fuel, fuel_amt);
- move_amt = min(move_amt, max_amt);
+ move_amt = MIN(tot_fuel, fuel_amt);
+ move_amt = MIN(move_amt, max_amt);
if (move_amt == 0)
continue;
extra = ((float)move_amt / 5.0) - (move_amt / 5);
if (extra > 0.0)
item2.land.lnd_item[I_PETROL]
- = max((pet_amt - move_amt / 5) - 1, 0);
+ = MAX((pet_amt - move_amt / 5) - 1, 0);
else
item2.land.lnd_item[I_PETROL]
- = max((pet_amt - move_amt / 5), 0);
+ = MAX((pet_amt - move_amt / 5), 0);
} else {
item2.land.lnd_item[I_PETROL] = 0;
move_amt -= pet_amt * 5;
extra = ((float)move_amt / 50.0) - (move_amt / 50);
item2.land.lnd_item[I_OIL]
- = max(oil_amt - move_amt / 50, 0);
+ = MAX(oil_amt - move_amt / 50, 0);
if (extra > 0.0)
item2.land.lnd_item[I_OIL]
- = max((oil_amt - move_amt / 50) - 1, 0);
+ = MAX((oil_amt - move_amt / 50) - 1, 0);
else
item2.land.lnd_item[I_OIL]
- = max((oil_amt - move_amt / 50), 0);
+ = MAX((oil_amt - move_amt / 50), 0);
}
/* load plague */
if (CANT_HAPPEN(pchr[P_BAR].p_ctype[i] <= I_NONE ||
pchr[P_BAR].p_ctype[i] > I_MAX))
continue;
- n = min(n,
+ n = MIN(n,
(double)(ITEM_MAX - sect.sct_item[pchr[P_BAR].p_ctype[i]])
/ (pchr[P_BAR].p_camt[i] * grind_eff));
}
range = range * (lookship->shp_effic / 100.0);
smcp = &mchr[(int)lookship->shp_type];
if (smcp->m_flags & M_SUB)
- range = min(range, 1);
+ range = MIN(range, 1);
for (i = 0; NULL != (sp = getshipp(i)); i++) {
if (sp->shp_own == player->cnum || sp->shp_own == 0)
continue;
vrange = (int)(sp->shp_visib * range / 20.0);
getsect(sp->shp_x, sp->shp_y, §);
if (sect.sct_type != SCT_WATER)
- vrange = max(1, vrange);
+ vrange = MAX(1, vrange);
if (dist > vrange)
continue;
if (smcp->m_flags & M_SUB) {
amt = 0;
/* take from target and give to tender */
- transfer = min(ontarget, -amt);
- transfer = min(maxtender - ontender, transfer);
+ transfer = MIN(ontarget, -amt);
+ transfer = MIN(maxtender - ontender, transfer);
if (transfer == 0)
continue;
target.lnd_item[ip->i_vtype] = ontarget - transfer;
total += transfer;
} else {
/* give to target from tender */
- transfer = min(ontender, amt);
- transfer = min(transfer, maxtarget - ontarget);
+ transfer = MIN(ontender, amt);
+ transfer = MIN(transfer, maxtarget - ontarget);
if (transfer == 0)
continue;
target.lnd_item[ip->i_vtype] = ontarget + transfer;
continue;
}
gun = item.ship.shp_item[I_GUN];
- gun = min(gun, item.ship.shp_glim);
+ gun = MIN(gun, item.ship.shp_glim);
if (item.ship.shp_frnge == 0) {
pr("Ships %d cannot fire guns!\n", item.ship.shp_uid);
continue;
continue;
}
gun = fship.shp_item[I_GUN];
- gun = min(gun, fship.shp_glim);
+ gun = MIN(gun, fship.shp_glim);
if (fship.shp_frnge == 0 || gun == 0) {
pr("Insufficient arms.\n");
continue;
continue;
}
}
- gun = min(gun, shell * 2);
- gun = min(gun, mil / 2);
- gun = max(gun, 1);
+ gun = MIN(gun, shell * 2);
+ gun = MIN(gun, mil / 2);
+ gun = MAX(gun, 1);
shots = gun;
guneff = seagun(fship.shp_effic, shots);
dam = (int)guneff;
shell -= ldround(((double)shots) / 2.0, 1);
fship.shp_item[I_SHELL] = shell;
if (opt_NOMOBCOST == 0)
- fship.shp_mobil = max(fship.shp_mobil - 15, -100);
+ fship.shp_mobil = MAX(fship.shp_mobil - 15, -100);
putship(fship.shp_uid, &fship);
} else if (attacker == targ_unit) {
if (fland.lnd_own != player->cnum) {
/* only need 1 shell, so don't check that */
if (shell < 1)
continue;
- nshot = min(gun, ship.shp_item[I_MILIT]);
- nshot = min(nshot, ship.shp_glim);
+ nshot = MIN(gun, ship.shp_item[I_MILIT]);
+ nshot = MIN(nshot, ship.shp_glim);
if (nshot == 0)
continue;
(*nfiring)++;
continue;
if ((shells = ship.shp_item[I_SHELL]) == 0)
continue;
- mines_avail = min(shells, mines);
+ mines_avail = MIN(shells, mines);
if (getsect(ship.shp_x, ship.shp_y, §) == 0 ||
(sect.sct_type != SCT_WATER && sect.sct_type != SCT_BSPAN)) {
pr("You can't lay mines there!!\n");
continue;
}
- sect.sct_mines = min(sect.sct_mines + mines_avail, MINES_MAX);
+ sect.sct_mines = MIN(sect.sct_mines + mines_avail, MINES_MAX);
ship.shp_item[I_SHELL] = shells - mines_avail;
putsect(§);
ship.shp_mission = 0;
putland(land.lnd_uid, &land);
if (!(shells = land.lnd_item[I_SHELL]))
continue;
- shells = min(shells, land.lnd_mobil);
+ shells = MIN(shells, land.lnd_mobil);
if (!getsect(land.lnd_x, land.lnd_y, §) ||
sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN) {
pr("You can't lay mines there!!\n");
land.lnd_mission = 0;
total_mines_laid = 0;
while (shells > 0 && total_mines_laid < mines_wanted) {
- mines_laid = min(shells, mines_wanted - total_mines_laid);
+ mines_laid = MIN(shells, mines_wanted - total_mines_laid);
land.lnd_item[I_SHELL] = shells - mines_laid;
land.lnd_mobil -= mines_laid;
putland(land.lnd_uid, &land);
putland(land.lnd_uid, &land);
total_mines_laid += mines_laid;
shells = land.lnd_item[I_SHELL];
- shells = min(shells, land.lnd_mobil);
+ shells = MIN(shells, land.lnd_mobil);
}
getsect(sect.sct_x, sect.sct_y, §);
- sect.sct_mines = min(sect.sct_mines + total_mines_laid, MINES_MAX);
+ sect.sct_mines = MIN(sect.sct_mines + total_mines_laid, MINES_MAX);
putsect(§);
if (total_mines_laid == mines_wanted) {
pr("%s laid a total of %d mines in %s",
desired_radius = 9999;
}
- size = max(sizeof(struct lndstr), sizeof(struct plnstr));
- size = max(size, sizeof(struct shpstr));
+ size = MAX(sizeof(struct lndstr), sizeof(struct plnstr));
+ size = MAX(size, sizeof(struct shpstr));
block = malloc(size);
switch (type) {
case EF_SHIP:
loan.l_loner = player->cnum;
loan.l_lonee = recipient;
loan.l_status = LS_PROPOSED;
- loan.l_irate = min(irate, 127);
- loan.l_ldur = min(dur, 127);
+ loan.l_irate = MIN(irate, 127);
+ loan.l_ldur = MIN(dur, 127);
loan.l_amtpaid = 0;
loan.l_amtdue = amt;
(void)time(&loan.l_lastpay);
total_work(sect.sct_work, etu_per_update,
civs, sect.sct_item[I_MILIT],
uws, maxpop));
- bwork = min(work / 2, bwork);
+ bwork = MIN(work / 2, bwork);
}
twork = 100 - eff;
if (twork > bwork) {
continue;
if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
continue;
- used = min(used, sect.sct_item[it] / pp->p_camt[j]);
+ used = MIN(used, sect.sct_item[it] / pp->p_camt[j]);
unit_work += pp->p_camt[j];
}
if (unit_work == 0)
if (*resource * 100 < pp->p_nrdep * max)
max = *resource * 100 / pp->p_nrdep;
}
- act = min(used, max);
+ act = MIN(used, max);
- real = dmin(999.0, (double)act * prodeff);
- maxr = dmin(999.0, (double)max * prodeff);
+ real = MIN(999.0, (double)act * prodeff);
+ maxr = MIN(999.0, (double)max * prodeff);
if (vtype != I_NONE) {
if (real < 0.0)
real = 0.0;
/* production backlog? */
- there = min(ITEM_MAX, sect.sct_item[vtype]);
- real = dmin(real, ITEM_MAX - there);
+ there = MIN(ITEM_MAX, sect.sct_item[vtype]);
+ real = MIN(real, ITEM_MAX - there);
}
if (prodeff != 0) {
civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
natp = getnatp(sect.sct_own);
maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
- civs = min(civs, maxpop);
+ civs = MIN(civs, maxpop);
/* This isn't quite right, since research might
rise/fall during the update, but it's the best
we can really do */
}
if (vtype != I_NONE || pp->p_level == NAT_ELEV
|| pp->p_level == NAT_HLEV)
- pr(" %5d\n", min(999, (int)(max * prodeff + 0.5)));
+ pr(" %5d\n", MIN(999, (int)(max * prodeff + 0.5)));
else
pr(" %5.2f\n", maxr);
}
if (ours
&& 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
return RET_FAIL;
}
if (number_set >= 0)
- com = min(number_set, amt);
+ com = MIN(number_set, amt);
else
com = amt + number_set;
if (com <= 0)
if (sect.sct_type != SCT_WATER)
continue;
range = (int)techfact(ship.shp_tech, (double)mcp->m_vrnge);
- srange = min(7, 7 * range * ship.shp_effic / 200);
+ srange = MIN(7, 7 * range * ship.shp_effic / 200);
pr("%s at %s efficiency %d%%, max range %d\n",
prship(&ship),
xyas(ship.shp_x, ship.shp_y, player->cnum),
if (targ.shp_own == player->cnum || targ.shp_own == 0)
continue;
tmcp = &mchr[(int)targ.shp_type];
- pingrange = min(7, max(targ.shp_visib, 10) * range / 10);
+ pingrange = MIN(7, MAX(targ.shp_visib, 10) * range / 10);
vrange = pingrange * ship.shp_effic / 200;
dist = mapdist(targ.shp_x, targ.shp_y, ship.shp_x, ship.shp_y);
- pingrange = (max(pingrange, 2) * targ.shp_effic) / 100;
+ pingrange = (MAX(pingrange, 2) * targ.shp_effic) / 100;
if (dist > pingrange)
continue;
if (tmcp->m_flags & M_SONAR && targ.shp_own) {
if (roll(100) >
pln_identchance(pp, shp_hardtarget(targ), EF_SHIP))
continue;
- pingrange = max(targ->shp_visib, 10) * range / 10;
+ pingrange = MAX(targ->shp_visib, 10) * range / 10;
vrange = ((float)pingrange) * ((float)pp->pln_effic / 200.0);
dist = mapdist(targ->shp_x, targ->shp_y, x, y);
- pingrange = (max(pingrange, 2) * targ->shp_effic);
+ pingrange = (MAX(pingrange, 2) * targ->shp_effic);
pingrange = roundavg(pingrange / 100.0);
if (dist > pingrange)
continue;
pr("%7d", sect.sct_mines);
else
pr("%7s", "");
- eff *= (1.0 + min(sect.sct_mines, 20) * 0.02);
+ eff *= (1.0 + MIN(sect.sct_mines, 20) * 0.02);
} else {
pr("%7s", "?");
}
amt = 0;
/* take from target and give to tender */
- transfer = min(ontarget, -amt);
- transfer = min(maxtender - ontender, transfer);
+ transfer = MIN(ontarget, -amt);
+ transfer = MIN(maxtender - ontender, transfer);
if (transfer == 0)
continue;
target.shp_item[ip->i_vtype] = ontarget - transfer;
total += transfer;
} else {
/* give to target from tender */
- transfer = min(ontender, amt);
- transfer = min(transfer, maxtarget - ontarget);
+ transfer = MIN(ontender, amt);
+ transfer = MIN(transfer, maxtarget - ontarget);
if (transfer == 0)
continue;
target.shp_item[ip->i_vtype] = ontarget + transfer;
shells = sp->shp_item[I_SHELL];
gun = sp->shp_item[I_GUN];
- gun = min(gun, sp->shp_glim);
- gun = min(gun, sp->shp_item[I_MILIT] / 2);
+ gun = MIN(gun, sp->shp_glim);
+ gun = MIN(gun, sp->shp_item[I_MILIT] / 2);
shells +=
supply_commod(sp->shp_own, sp->shp_x, sp->shp_y, I_SHELL,
(gun + 1) / 2 - shells);
- gun = min(gun, shells * 2);
+ gun = MIN(gun, shells * 2);
if (gun == 0)
return;
(int)(plane_mob_scale * (float)etu_per_update),
(int)(land_mob_scale * (float)etu_per_update));
pr("Max eff gain per update\t\t--\t%d\t%d\t%d\n",
- min((int)(ship_grow_scale * (float)etu_per_update), 100),
- min((int)(plane_grow_scale * (float)etu_per_update), 100),
- min((int)(land_grow_scale * (float)etu_per_update), 100));
+ MIN((int)(ship_grow_scale * (float)etu_per_update), 100),
+ MIN((int)(plane_grow_scale * (float)etu_per_update), 100),
+ MIN((int)(land_grow_scale * (float)etu_per_update), 100));
pr("\n");
pr("Ships on autonavigation may use %i cargo holds per ship.\n", TMAX);
if (opt_TRADESHIPS) {
doney = sect.sct_y;
continue;
}
- eff_amt = min(land.lnd_mobil, work_amt);
+ eff_amt = MIN(land.lnd_mobil, work_amt);
w = ldround(((double)eff_amt * land.lnd_effic / 600.0), 1);
if (w < 1) {
pr("%s doesn't work enough to change efficiency (try increasing amount)\n", prland(&land));
if (how & EFF_MEM)
ep->csize = ep->fids;
else
- ep->csize = max(1, blksize(fd) / ep->size);
+ ep->csize = MAX(1, blksize(fd) / ep->size);
size = ep->csize * ep->size;
if (CANT_HAPPEN(ep->cache))
free(ep->cache);
+++ /dev/null
-/*
- * Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
- *
- * This program 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
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * 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
- *
- * ---
- *
- * 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.
- *
- * ---
- *
- * minmax.c: Misc min and max routines
- *
- * Known contributors to this file:
- * Doug Hay, 1998
- * Steve McClure, 1998
- */
-
-#include <config.h>
-
-#include "gen.h"
-
-double
-dmax(double n1, double n2)
-{
- if (n1 > n2)
- return n1;
- return n2;
-}
-
-double
-dmin(double n1, double n2)
-{
- if (n1 < n2)
- return n1;
- return n2;
-}
-
-#if !defined(_WIN32)
-int
-max(int n1, int n2)
-{
- if (n1 > n2)
- return n1;
- return n2;
-}
-
-
-int
-min(int n1, int n2)
-{
- if (n1 < n2)
- return n1;
- return n2;
-}
-
-#endif
#endif /* RESOLVE_IPADDRESS */
/* XXX may not be big enough */
stacksize = 100000
-/* budget */ + max(WORLD_X * WORLD_Y / 2 * sizeof(int) * 7,
+/* budget */ + MAX(WORLD_X * WORLD_Y / 2 * sizeof(int) * 7,
/* power */ MAXNOC * sizeof(struct powstr));
sprintf(buf, "Player (fd #%d)", ns);
empth_create(PP_PLAYER, player_login, stacksize,
* charging at least 15 seconds.
*/
time(&natp->nat_last_logout);
- secs = max(natp->nat_last_logout - player->lasttime, 15);
+ secs = MAX(natp->nat_last_logout - player->lasttime, 15);
natp->nat_minused += secs / 60;
secs = secs % 60;
if (chance(secs / 60.0))
}
pp->pln_effic = eff;
- pp->pln_mobil -= min(32 + pp->pln_mobil, dam / 2);
+ pp->pln_mobil -= MIN(32 + pp->pln_mobil, dam / 2);
if (disp == 1) {
if (from != 0 && (plp->pcp->pl_flags & P_M) == 0)
nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
if (rel > HOSTILE)
continue;
shell = gun = 0;
- gun = min(ship.shp_item[I_GUN], ship.shp_glim);
+ gun = MIN(ship.shp_item[I_GUN], ship.shp_glim);
if (gun) {
shell = ship.shp_item[I_SHELL];
if (shell <= 0) {
else if (mil == 1)
pr("Only 1 mil %s\n", prcom(1, com));
/* don't abandon attacking sectors or ships */
- com->troops = max(0, mil - 1);
+ com->troops = MAX(0, mil - 1);
}
com->plague = pstage == PLG_INFECT;
} else { /* not first time */
}
if (com->troops && com->troops + 1 > mil) {
if (com->own == owner && player->cnum == owner) /* not a takeover */
- pr("WARNING: Your mil %s has been reduced from %d to %d!\n", prcom(1, com), com->troops, max(0, mil - 1));
- com->troops = max(0, mil - 1);
+ pr("WARNING: Your mil %s has been reduced from %d to %d!\n", prcom(1, com), com->troops, MAX(0, mil - 1));
+ com->troops = MAX(0, mil - 1);
}
}
}
switch (combat_mode) {
case A_ATTACK:
off->mobcost +=
- max(1,
+ MAX(1,
(int)(attacking_mil *
sector_mcost(getsectp(def->x, def->y), MOB_ROAD)));
break;
case A_LBOARD:
- off->mobcost += max(1, attacking_mil / 5);
+ off->mobcost += MAX(1, attacking_mil / 5);
break;
case A_BOARD:
switch (off->type) {
case EF_SECTOR:
- off->mobcost += max(1, attacking_mil / 5);
+ off->mobcost += MAX(1, attacking_mil / 5);
break;
case EF_SHIP:
/* the 2 in the formula below is a fudge factor */
if (att_get_combat(off, 0) <= 0)
return 0;
if ((attacking_mil =
- min(attacking_mil, min(mob_support, off->troops))) <= 0)
+ MIN(attacking_mil, MIN(mob_support, off->troops))) <= 0)
return 0;
calc_mobcost(combat_mode, off, def, attacking_mil);
getsect(def->x, def->y, §);
if (sect.sct_oldown != player->cnum) {
- mines = min(sect.sct_mines, 20);
+ mines = MIN(sect.sct_mines, 20);
if (a_engineer)
mines = ldround(((double)mines / 2.0), 1);
if (mines > 0) {
/* Make sure we use a positive mobility here */
tmob = ((def->mob < 0) ? -(def->mob) : (def->mob));
def->mobcost =
- min(20, min(1, tmob - damage(tmob, 100 * d_cas / d_mil)));
+ MIN(20, MIN(1, tmob - damage(tmob, 100 * d_cas / d_mil)));
}
def->mil = def->troops;
}
if (off[n].type != EF_BAD && off[n].troops < a_troops[n]) {
if (off[n].type == EF_SECTOR && off[n].mil)
off[n].mobcost +=
- min(20,
+ MIN(20,
off[n].mob - damage(off[n].mob,
100 * (a_troops[n] - off[n].troops)
/ off[n].mil));
if (off->own != player->cnum)
return;
d = sector_mcost(getsectp(def->x, def->y), MOB_ROAD);
- if ((mob_support = min(off->troops, (int)(off->mob / d))) <= 0)
+ if ((mob_support = MIN(off->troops, (int)(off->mob / d))) <= 0)
return;
sprintf(prompt, "How many mil to move in from %s (%d max)? ",
xyas(off->x, off->y, player->cnum), mob_support);
return;
if (att_get_combat(def, 0) < 0)
return;
- if ((num_mil = min(off->troops, num_mil)) <= 0) {
+ if ((num_mil = MIN(off->troops, num_mil)) <= 0) {
pr("No mil moved in from %s\n",
xyas(off->x, off->y, player->cnum));
return;
}
- mob_support = max(1, (int)(num_mil * d));
- off->mob -= min(off->mob, mob_support);
+ mob_support = MAX(1, (int)(num_mil * d));
+ off->mob -= MIN(off->mob, mob_support);
off->mil -= num_mil;
off->troops -= num_mil;
put_combat(off);
fallout += damage * 30;
else
fallout += damage * 3;
- sect.sct_fallout = min(fallout, FALLOUT_MAX);
+ sect.sct_fallout = MIN(fallout, FALLOUT_MAX);
}
if (damage > 100) {
makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
if (shell < ship.shp_glim)
shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
I_SHELL, shell - ship.shp_glim);
- nshot = min(min(ship.shp_item[I_GUN], shell), ship.shp_item[I_MILIT]);
- nshot = min(nshot, ship.shp_glim);
+ nshot = MIN(MIN(ship.shp_item[I_GUN], shell), ship.shp_item[I_MILIT]);
+ nshot = MIN(nshot, ship.shp_glim);
if (nshot <= 0)
continue;
ship.shp_item[I_SHELL] = shell - nshot;
landgun(int effic, int guns)
{
double d;
- double g = (double)min(guns, 7);
+ double g = (double)MIN(guns, 7);
d = ((double)(random() % 30) + 20.0) * ((double)g / 7.0);
d *= (double)effic;
{
double d = 0.0;
- shots = min(shots, guns);
+ shots = MIN(shots, guns);
while (shots-- > 0)
d += 5.0 + (double)(random() % 6);
d *= (double)effic * 0.01;
if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
int t;
t = lp->lnd_tech - 20 + roll(40);
- t = max(t, 0);
+ t = MAX(t, 0);
if (destination == player->cnum)
pr(", tech %d)\n", t);
else
gun = fsect.sct_item[I_GUN];
if (gun < 1)
continue;
- range = tfactfire(fsect.sct_own, (double)min(gun, 7));
+ range = tfactfire(fsect.sct_own, (double)MIN(gun, 7));
if (fsect.sct_effic > 59)
range++;
range2 = roundrange(range);
if ((lp->lnd_ship >= 0) || lp->lnd_land >= 0)
return 0;
- hard_amt = min(lp->lnd_mobil, hard_amt);
+ hard_amt = MIN(lp->lnd_mobil, hard_amt);
if ((lp->lnd_harden + hard_amt) > land_mob_max)
hard_amt = land_mob_max - lp->lnd_harden;
lp->lnd_mobil = 0;
lp->lnd_harden += hard_amt;
- lp->lnd_harden = min(lp->lnd_harden, land_mob_max);
+ lp->lnd_harden = MIN(lp->lnd_harden, land_mob_max);
return hard_amt;
}
struct sctstr sect;
/*
- size = max(sizeof(struct shpstr),sizeof(struct lndstr));
- size = max(size,sizeof(struct plnstr));
+ size = MAX(sizeof(struct shpstr),sizeof(struct lndstr));
+ size = MAX(size,sizeof(struct plnstr));
block = malloc(size);
*/
size = sizeof(u_block);
if (md > range2)
continue;
gun = sp->shp_item[I_GUN];
- gun = min(gun, sp->shp_glim);
+ gun = MIN(gun, sp->shp_glim);
shell = sp->shp_item[I_SHELL];
if (shell < gun)
shell += supply_commod(sp->shp_own,
sp->shp_x, sp->shp_y, I_SHELL,
gun - shell);
- gun = min(gun, shell);
- gun = min(gun, sp->shp_item[I_MILIT] / 2.0);
+ gun = MIN(gun, shell);
+ gun = MIN(gun, sp->shp_item[I_MILIT] / 2.0);
if (gun == 0)
continue;
- gun = max(gun, 1);
+ gun = MAX(gun, 1);
dam2 = seagun(sp->shp_effic, gun);
if (range2 == 0.0)
prb = 1.0;
s_char *block;
struct genitem *gp;
- size = max(sizeof(struct lndstr), sizeof(struct plnstr));
- size = max(size, sizeof(struct shpstr));
+ size = MAX(sizeof(struct lndstr), sizeof(struct plnstr));
+ size = MAX(size, sizeof(struct shpstr));
block = malloc(size);
while (nxtitem(np, block)) {
pr("Your seamines have no effect here.\n");
return;
}
- sectp->sct_mines = min(sectp->sct_mines + amt, MINES_MAX);
+ sectp->sct_mines = MIN(sectp->sct_mines + amt, MINES_MAX);
pr("%d mines laid in %s.\n", amt,
xyas(sectp->sct_x, sectp->sct_y, player->cnum));
if (map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
cost = ldround((double)cost * dist / pp->pln_range_max, 1);
- return min(32 + pp->pln_mobil, cost + 5);
+ return MIN(32 + pp->pln_mobil, cost + 5);
}
/*
for (m = 0; mines > 0 && m < 5; m++) {
if (chance(0.66)) {
mines--;
- shells = min(max, shells + 1);
+ shells = MIN(max, shells + 1);
changed |= map_set(sp->shp_own, sp->shp_x, sp->shp_y,
'X', 0);
}
for (m = 0; mines > 0 && m < 5; m++) {
if (chance(0.66)) {
mines--;
- shells = min(max, shells + 1);
+ shells = MIN(max, shells + 1);
}
}
sect.sct_mines = mines;
if (chance(0.66)) {
mpr(actor, "Sweep...\n");
mines--;
- shells = min(max, shells + 1);
+ shells = MIN(max, shells + 1);
changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0);
}
}
gun = fsect.sct_item[I_GUN];
if (gun < 1)
continue;
- range = tfactfire(fsect.sct_own, (double)min(gun, 7));
+ range = tfactfire(fsect.sct_own, (double)MIN(gun, 7));
if (fsect.sct_effic > 59)
range++;
range2 = roundrange(range);
continue;
/* now calculate the odds */
- gun = min(ship.shp_item[I_GUN], ship.shp_glim);
+ gun = MIN(ship.shp_item[I_GUN], ship.shp_glim);
eff = (double)ship.shp_effic / 100.0;
teff =
(((double)ship.shp_tech) / (((double)ship.shp_tech) + 200.0));
lp->lnd_item[I_SHELL] = shells;
}
- lp->lnd_item[I_SHELL] = max(lp->lnd_item[I_SHELL] - shells_needed, 0);
+ lp->lnd_item[I_SHELL] = MAX(lp->lnd_item[I_SHELL] - shells_needed, 0);
if (lp->lnd_frg) /* artillery */
goto done;
lp->lnd_item[I_FOOD] = food;
}
- lp->lnd_item[I_FOOD] = max(lp->lnd_item[I_FOOD] - food_needed, 0);
+ lp->lnd_item[I_FOOD] = MAX(lp->lnd_item[I_FOOD] - food_needed, 0);
if (opt_FUEL) {
fuel_needed = lp->lnd_fuelu;
if (petrol_needed) {
if (petrol >= petrol_needed) {
lp->lnd_item[I_PETROL]
- = max(lp->lnd_item[I_PETROL] - petrol_needed, 0);
+ = MAX(lp->lnd_item[I_PETROL] - petrol_needed, 0);
lp->lnd_fuel += petrol_needed * 10;
} else {
lp->lnd_fuel += lp->lnd_item[I_PETROL] * 10;
}
}
- lp->lnd_fuel = max(lp->lnd_fuel - fuel_needed, 0);
+ lp->lnd_fuel = MAX(lp->lnd_fuel - fuel_needed, 0);
}
/* end opt_FUEL */
done:
new_work(struct sctstr *sp, int delta)
{
if (sp->sct_type == sp->sct_newtype)
- return min(rollover_avail_max, sp->sct_avail) + delta;
+ return MIN(rollover_avail_max, sp->sct_avail) + delta;
return delta;
}
food_workers = work * fcrate;
food_fertil = etu * sp->sct_fertil * fgrate;
- food = min(food_workers, food_fertil);
+ food = MIN(food_workers, food_fertil);
if (food > ITEM_MAX - vec[I_FOOD])
food = ITEM_MAX - vec[I_FOOD];
/*
int mil_dbl_pay;
-#ifndef MIN
-#define MIN(x,y) ((x) > (y) ? (y) : (x))
-#endif
-
static int landrepair(struct lndstr *, struct natstr *,
int *, int);
static void upd_land(struct lndstr *lp, int etus,
mult = 2;
if (lcp->l_flags & L_ENGINEER)
mult *= 3;
-/* cost = -(mult * etus * dmin(0.0, money_land * LND_COST(lcp->l_cost, lp->lnd_tech - lcp->l_tech)));*/
- cost = -(mult * etus * dmin(0.0, money_land * lcp->l_cost));
+/* cost = -(mult * etus * MIN(0.0, money_land * LND_COST(lcp->l_cost, lp->lnd_tech - lcp->l_tech)));*/
+ cost = -(mult * etus * MIN(0.0, money_land * lcp->l_cost));
if ((np->nat_priorities[PRI_LMAINT] == 0 || np->nat_money < cost)
&& !player->simulation) {
if ((eff = lp->lnd_effic - etus / 5) < LAND_MINEFF) {
#include "common.h"
#include "subs.h"
-#ifndef MIN
-#define MIN(x,y) ((x) > (y) ? (y) : (x))
-#endif
-
void
get_materials(struct sctstr *sp, int *bp, int *mvec, int check)
/* only check if found=0, remove them=1 */
d *= (double)mchr[(int)sp->shp_type].m_fuelu;
d /= (double)fuel_mult;
sp->shp_fuel -= (u_char)ldround(d, 1);
- sp->shp_fuel = (u_char)min(sp->shp_fuel,
+ sp->shp_fuel = (u_char)MIN(sp->shp_fuel,
mchr[(int)sp->shp_type].m_fuelc);
sp->shp_mobil += (s_char)total_add;
}
d *= (double)lp->lnd_fuelu;
d /= (double)fuel_mult;
lp->lnd_fuel -= (u_char)ldround(d, 1);
- lp->lnd_fuel = (u_char)min(lp->lnd_fuel, lp->lnd_fuelc);
+ lp->lnd_fuel = (u_char)MIN(lp->lnd_fuel, lp->lnd_fuelc);
if (total_add + lp->lnd_mobil > land_mob_max) {
total_add = land_mob_max - lp->lnd_mobil;
}
if (!abs_max)
return 0; /* can't load the ship, skip to the end. */
- max_amt = min(sect_amt, max_amt - ship_amt);
+ max_amt = MIN(sect_amt, max_amt - ship_amt);
if (max_amt <= 0 && (ship_amt != abs_max)) {
sp->shp_autonav |= AN_LOADING;
return 0;
if (comm == I_CIVIL)
ship_amt--; /* This leaves 1 civs on board the ship */
- max_amt = min(ship_amt, ITEM_MAX - sect_amt);
+ max_amt = MIN(ship_amt, ITEM_MAX - sect_amt);
if (max_amt <= 0)
continue;
#include "common.h"
#include "gen.h"
-#ifndef MIN
-#define MIN(x,y) ((x) > (y) ? (y) : (x))
-#endif
-
int
prod_plane(int etus, int natnum, int *bp, int buildem)
if (buildem == 0) {
/* flight pay is 5x the pay received by other military */
start_money = np->nat_money;
- cost = -(mult * etus * dmin(0.0, desc->pl_cost * money_plane));
+ cost = -(mult * etus * MIN(0.0, desc->pl_cost * money_plane));
if ((np->nat_priorities[PRI_PMAINT] == 0 ||
np->nat_money < cost) && !player->simulation) {
if ((eff = pp->pln_effic - etus / 5) < PLANE_MINEFF) {
}
}
- /* The min() here is to take care of integer rounding errors */
+ /* The MIN() here is to take care of integer rounding errors */
if (p_e > 0.0) {
- return min(work, (int)(unit_work * material_consume / p_e));
+ return MIN(work, (int)(unit_work * material_consume / p_e));
}
return 0;
}
logerror("%d Che targeted at country %d retiring", che, target);
sp->sct_che = 0;
sp->sct_che_target = 0;
- sp->sct_item[I_CIVIL] = min(civ + che, ITEM_MAX);
+ sp->sct_item[I_CIVIL] = MIN(civ + che, ITEM_MAX);
return;
}
+ (vec[I_MILIT] * 2 / 5.0) + vec[I_UW];
*workp = roundavg((etu * (*workp)) / 100.0);
- buildeff_work = min((int)(*workp / 2), buildeff_work);
+ buildeff_work = MIN((int)(*workp / 2), buildeff_work);
}
}
if (np->nat_priorities[*desig]) {
inc = roundavg(etus * fallout_spread * (sp->sct_fallout)) - 1;
if (inc < 0)
inc = 0;
- ap->sct_fallout = min(ap->sct_fallout + inc, FALLOUT_MAX);
+ ap->sct_fallout = MIN(ap->sct_fallout + inc, FALLOUT_MAX);
}
}
#include "lost.h"
#include "budg.h"
-#ifndef MIN
-#define MIN(x,y) ((x) > (y) ? (y) : (x))
-#endif
-
static int shiprepair(struct shpstr *, struct natstr *,
int *, int);
static void upd_ship(struct shpstr *, int,
mult = 1;
if (np->nat_level[NAT_TLEV] < sp->shp_tech * 0.85)
mult = 2;
- cost = -(mult * etus * dmin(0.0, money_ship * mp->m_cost));
+ cost = -(mult * etus * MIN(0.0, money_ship * mp->m_cost));
if ((np->nat_priorities[PRI_SMAINT] == 0 || np->nat_money < cost)
&& !player->simulation) {
if ((eff = sp->shp_effic - etus / 5) < SHIP_MINEFF) {
#define new_x(newx) (((newx) + WORLD_X) % WORLD_X)
#define new_y(newy) (((newy) + WORLD_Y) % WORLD_Y)
-#if !defined(_WIN32)
-#define max(a,b) (a>b?a:b)
-#endif
#define rnd(x) (random() % (x))
int secs; /* number of sectors grown */
secty = calloc(nc + ni, sizeof(int *));
sectc = calloc(nc + ni, sizeof(int *));
isecs = calloc(nc + ni, sizeof(int));
- weight = calloc(max(sc, is * 2), sizeof(int));
- dsea = calloc(max(sc, is * 2), sizeof(int));
- dmoun = calloc(max(sc, is * 2), sizeof(int));
+ weight = calloc(MAX(sc, is * 2), sizeof(int));
+ dsea = calloc(MAX(sc, is * 2), sizeof(int));
+ dmoun = calloc(MAX(sc, is * 2), sizeof(int));
for (i = 0; i < nc; ++i) {
sectx[i] = calloc(sc, sizeof(int));
secty[i] = calloc(sc, sizeof(int));