Replace common pattern by new LIMIT_TO()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2013-01-14 22:34:05 +01:00
parent aa870f5d91
commit 726b9380d1
11 changed files with 73 additions and 162 deletions

View file

@ -29,6 +29,7 @@
* *
* Known contributors to this file: * Known contributors to this file:
* Doug Hay, 1998 * Doug Hay, 1998
* Markus Armbruster, 2004-2013
*/ */
#ifndef MISC_H #ifndef MISC_H
@ -37,6 +38,9 @@
#define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b))
#define LIMIT_TO(val, min, max) \
((val) < (min) ? (min) : (val) > (max) ? (max) : (val))
#ifdef _WIN32 #ifdef _WIN32
#include "w32misc.h" #include "w32misc.h"
#endif /* _WIN32 */ #endif /* _WIN32 */

View file

@ -402,16 +402,6 @@ pr_ship(struct shpstr *ship)
pr("\n"); pr("\n");
} }
static int
errcheck(int num, int min, int max)
{
if (num < min)
return min;
else if (num > max)
return max;
return num;
}
static int static int
getin(char *buf, char **valp) getin(char *buf, char **valp)
{ {
@ -454,7 +444,7 @@ doland(char op, int arg, char *p, struct sctstr *sect)
case 'o': case 'o':
if (arg < 0) if (arg < 0)
return RET_SYN; return RET_SYN;
newown = (natid)errcheck(arg, 0, MAXNOC - 1); newown = (natid)LIMIT_TO(arg, 0, MAXNOC - 1);
pr("Owner of %s changed from %s (#%d) to %s (#%d).\n", pr("Owner of %s changed from %s (#%d) to %s (#%d).\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), xyas(sect->sct_x, sect->sct_y, player->cnum),
cname(sect->sct_own), sect->sct_own, cname(newown), newown); cname(sect->sct_own), sect->sct_own, cname(newown), newown);
@ -475,7 +465,7 @@ doland(char op, int arg, char *p, struct sctstr *sect)
case 'O': case 'O':
if (arg < 0) if (arg < 0)
return RET_SYN; return RET_SYN;
oldown = (natid)errcheck(arg, 0, MAXNOC - 1); oldown = (natid)LIMIT_TO(arg, 0, MAXNOC - 1);
pr("Old owner of %s changed from %s (#%d) to %s (#%d).\n", pr("Old owner of %s changed from %s (#%d) to %s (#%d).\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), xyas(sect->sct_x, sect->sct_y, player->cnum),
cname(sect->sct_oldown), cname(sect->sct_oldown),
@ -483,47 +473,47 @@ doland(char op, int arg, char *p, struct sctstr *sect)
sect->sct_oldown = oldown; sect->sct_oldown = oldown;
break; break;
case 'e': case 'e':
new = errcheck(arg, 0, 100); new = LIMIT_TO(arg, 0, 100);
noise(sect, "Efficiency", sect->sct_effic, new); noise(sect, "Efficiency", sect->sct_effic, new);
sect->sct_effic = new; sect->sct_effic = new;
break; break;
case 'm': case 'm':
new = errcheck(arg, -127, 255); new = LIMIT_TO(arg, -127, 255);
noise(sect, "Mobility", sect->sct_mobil, new); noise(sect, "Mobility", sect->sct_mobil, new);
sect->sct_mobil = new; sect->sct_mobil = new;
break; break;
case 'i': case 'i':
new = errcheck(arg, 0, 127); new = LIMIT_TO(arg, 0, 127);
noise(sect, "Iron ore content", sect->sct_min, new); noise(sect, "Iron ore content", sect->sct_min, new);
sect->sct_min = (unsigned char)new; sect->sct_min = (unsigned char)new;
break; break;
case 'g': case 'g':
new = errcheck(arg, 0, 127); new = LIMIT_TO(arg, 0, 127);
noise(sect, "Gold content", sect->sct_gmin, new); noise(sect, "Gold content", sect->sct_gmin, new);
sect->sct_gmin = (unsigned char)new; sect->sct_gmin = (unsigned char)new;
break; break;
case 'f': case 'f':
new = errcheck(arg, 0, 127); new = LIMIT_TO(arg, 0, 127);
noise(sect, "Fertility", sect->sct_fertil, new); noise(sect, "Fertility", sect->sct_fertil, new);
sect->sct_fertil = (unsigned char)new; sect->sct_fertil = (unsigned char)new;
break; break;
case 'c': case 'c':
new = errcheck(arg, 0, 127); new = LIMIT_TO(arg, 0, 127);
noise(sect, "Oil content", sect->sct_oil, new); noise(sect, "Oil content", sect->sct_oil, new);
sect->sct_oil = (unsigned char)new; sect->sct_oil = (unsigned char)new;
break; break;
case 'u': case 'u':
new = errcheck(arg, 0, 127); new = LIMIT_TO(arg, 0, 127);
noise(sect, "Uranium content", sect->sct_uran, new); noise(sect, "Uranium content", sect->sct_uran, new);
sect->sct_uran = (unsigned char)new; sect->sct_uran = (unsigned char)new;
break; break;
case 'w': case 'w':
new = errcheck(arg, 0, 100); new = LIMIT_TO(arg, 0, 100);
noise(sect, "Workforce percentage", sect->sct_work, new); noise(sect, "Workforce percentage", sect->sct_work, new);
sect->sct_work = (unsigned char)new; sect->sct_work = (unsigned char)new;
break; break;
case 'l': case 'l':
new = errcheck(arg, 0, 127); new = LIMIT_TO(arg, 0, 127);
pr("Loyalty of %s changed from %d to %d%%\n", pr("Loyalty of %s changed from %d to %d%%\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), xyas(sect->sct_x, sect->sct_y, player->cnum),
sect->sct_loyal, new); sect->sct_loyal, new);
@ -531,14 +521,14 @@ doland(char op, int arg, char *p, struct sctstr *sect)
break; break;
case 'x': case 'x':
old = sect->sct_che; old = sect->sct_che;
new = errcheck(arg, 0, CHE_MAX); new = LIMIT_TO(arg, 0, CHE_MAX);
pr("Guerillas in %s changed from %d to %d\n", pr("Guerillas in %s changed from %d to %d\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), old, new); xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
sect->sct_che = new; sect->sct_che = new;
break; break;
case 'X': case 'X':
old = sect->sct_che_target; old = sect->sct_che_target;
new = errcheck(arg, 0, MAXNOC - 1); new = LIMIT_TO(arg, 0, MAXNOC - 1);
pr("Che target of %s changed from %s (#%d) to %s (#%d).\n", pr("Che target of %s changed from %s (#%d) to %s (#%d).\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), xyas(sect->sct_x, sect->sct_y, player->cnum),
cname(old), old, cname(new), new); cname(old), old, cname(new), new);
@ -548,32 +538,32 @@ doland(char op, int arg, char *p, struct sctstr *sect)
break; break;
case 'p': case 'p':
old = sect->sct_pstage; old = sect->sct_pstage;
new = errcheck(arg, 0, PLG_EXPOSED); new = LIMIT_TO(arg, 0, PLG_EXPOSED);
pr("Plague stage of %s changed from %d to %d%%\n", pr("Plague stage of %s changed from %d to %d%%\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), old, new); xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
sect->sct_pstage = new; sect->sct_pstage = new;
break; break;
case 't': case 't':
old = sect->sct_ptime; old = sect->sct_ptime;
new = errcheck(arg, 0, 255); new = LIMIT_TO(arg, 0, 255);
pr("Plague time of %s changed from %d to %d%%\n", pr("Plague time of %s changed from %d to %d%%\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), old, new); xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
sect->sct_ptime = new; sect->sct_ptime = new;
break; break;
case 'F': case 'F':
old = sect->sct_fallout; old = sect->sct_fallout;
new = errcheck(arg, 0, FALLOUT_MAX); new = LIMIT_TO(arg, 0, FALLOUT_MAX);
pr("Fallout for sector %s changed from %d to %d\n", pr("Fallout for sector %s changed from %d to %d\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), old, new); xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
sect->sct_fallout = new; sect->sct_fallout = new;
break; break;
case 'a': case 'a':
new = errcheck(arg, 0, 9999); new = LIMIT_TO(arg, 0, 9999);
noise(sect, "Available workforce", sect->sct_avail, new); noise(sect, "Available workforce", sect->sct_avail, new);
sect->sct_avail = new; sect->sct_avail = new;
break; break;
case 'M': case 'M':
new = errcheck(arg, 0, MINES_MAX); new = LIMIT_TO(arg, 0, MINES_MAX);
sect->sct_mines = new; sect->sct_mines = new;
pr("Mines changed to %d\n", new); pr("Mines changed to %d\n", new);
break; break;
@ -614,28 +604,19 @@ doland(char op, int arg, char *p, struct sctstr *sect)
sect->sct_newtype = des; sect->sct_newtype = des;
break; break;
case 'R': case 'R':
if (arg > 100) new = LIMIT_TO(arg, 0, 100);
arg = 100; noise(sect, "Road percentage", sect->sct_road, new);
if (arg < 0) sect->sct_road = new;
arg = 0;
noise(sect, "Road percentage", sect->sct_road, arg);
sect->sct_road = arg;
break; break;
case 'r': case 'r':
if (arg > 100) new = LIMIT_TO(arg, 0, 100);
arg = 100; noise(sect, "Rail percentage", sect->sct_rail, new);
if (arg < 0) sect->sct_rail = new;
arg = 0;
noise(sect, "Rail percentage", sect->sct_rail, arg);
sect->sct_rail = arg;
break; break;
case 'd': case 'd':
if (arg > 100) new = LIMIT_TO(arg, 0, 100);
arg = 100; noise(sect, "Defense percentage", sect->sct_defense, new);
if (arg < 0) sect->sct_defense = new;
arg = 0;
noise(sect, "Defense percentage", sect->sct_defense, arg);
sect->sct_defense = arg;
break; break;
default: default:
pr("huh? (%c)\n", op); pr("huh? (%c)\n", op);
@ -668,7 +649,7 @@ docountry(char op, int arg, char *p, struct natstr *np)
np->nat_tgms = arg; np->nat_tgms = arg;
break; break;
case 'b': case 'b':
arg = errcheck(arg, 0, 1024); arg = LIMIT_TO(arg, 0, 1024);
pr("BTU's changed from %d to %d\n", np->nat_btu, arg); pr("BTU's changed from %d to %d\n", np->nat_btu, arg);
np->nat_btu = arg; np->nat_btu = arg;
break; break;
@ -700,10 +681,10 @@ docountry(char op, int arg, char *p, struct natstr *np)
np->nat_yorg = newy; np->nat_yorg = newy;
break; break;
case 's': case 's':
np->nat_stat = errcheck(arg, STAT_UNUSED, STAT_GOD); np->nat_stat = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
break; break;
case 'u': case 'u':
arg = errcheck(arg, 0, m_m_p_d * 60); arg = LIMIT_TO(arg, 0, m_m_p_d * 60);
pr("Number of seconds used changed from %d to %d.\n", pr("Number of seconds used changed from %d to %d.\n",
np->nat_timeused, arg); np->nat_timeused, arg);
np->nat_timeused = arg; np->nat_timeused = arg;
@ -784,12 +765,11 @@ doship(char op, int arg, char *p, struct shpstr *ship)
ship->shp_y = newy; ship->shp_y = newy;
break; break;
case 'T': case 'T':
shp_set_tech(ship, arg = LIMIT_TO(arg, mchr[(int)ship->shp_type].m_tech, SHRT_MAX);
errcheck(arg, shp_set_tech(ship, arg);
mchr[(int)ship->shp_type].m_tech, SHRT_MAX));
break; break;
case 'E': case 'E':
ship->shp_effic = errcheck(arg, SHIP_MINEFF, 100); ship->shp_effic = LIMIT_TO(arg, SHIP_MINEFF, 100);
break; break;
case 'M': case 'M':
ship->shp_mobil = arg; ship->shp_mobil = arg;
@ -882,15 +862,14 @@ dounit(char op, int arg, char *p, struct lndstr *land)
land->lnd_y = newy; land->lnd_y = newy;
break; break;
case 'e': case 'e':
land->lnd_effic = errcheck(arg, LAND_MINEFF, 100); land->lnd_effic = LIMIT_TO(arg, LAND_MINEFF, 100);
break; break;
case 'M': case 'M':
land->lnd_mobil = arg; land->lnd_mobil = arg;
break; break;
case 't': case 't':
lnd_set_tech(land, arg = LIMIT_TO(arg, lchr[(int)land->lnd_type].l_tech, SHRT_MAX);
errcheck(arg, lnd_set_tech(land, arg);
lchr[(int)land->lnd_type].l_tech, SHRT_MAX));
break; break;
case 'a': case 'a':
if (p[0] == '~') if (p[0] == '~')
@ -903,7 +882,7 @@ dounit(char op, int arg, char *p, struct lndstr *land)
} }
break; break;
case 'F': case 'F':
land->lnd_harden = errcheck(arg, 0, 255); land->lnd_harden = LIMIT_TO(arg, 0, 255);
break; break;
case 'S': case 'S':
land->lnd_ship = arg; land->lnd_ship = arg;
@ -992,15 +971,14 @@ doplane(char op, int arg, char *p, struct plnstr *plane)
plane->pln_effic = 0; plane->pln_effic = 0;
break; break;
case 'e': case 'e':
plane->pln_effic = errcheck(arg, PLANE_MINEFF, 100); plane->pln_effic = LIMIT_TO(arg, PLANE_MINEFF, 100);
break; break;
case 'm': case 'm':
plane->pln_mobil = errcheck(arg, -127, 255); plane->pln_mobil = LIMIT_TO(arg, -127, 255);
break; break;
case 't': case 't':
pln_set_tech(plane, arg = LIMIT_TO(arg, plchr[(int)plane->pln_type].pl_tech, SHRT_MAX);
errcheck(arg, pln_set_tech(plane, arg);
plchr[(int)plane->pln_type].pl_tech, SHRT_MAX));
break; break;
case 'w': case 'w':
if (p[0] == '~') if (p[0] == '~')

View file

@ -30,7 +30,7 @@
* David Sharnoff, 1987 * David Sharnoff, 1987
* Ken Stevens, 1995 (rewritten) * Ken Stevens, 1995 (rewritten)
* Steve McClure, 1998-2000 * Steve McClure, 1998-2000
* Markus Armbruster, 2004-2012 * Markus Armbruster, 2004-2013
*/ */
#include <config.h> #include <config.h>
@ -326,14 +326,8 @@ move_amount(int sect_amt, int unit_amt, int unit_max,
move_amt = -amount - unit_amt; move_amt = -amount - unit_amt;
else else
move_amt = load_unload == LOAD ? amount : -amount; move_amt = load_unload == LOAD ? amount : -amount;
if (move_amt > unit_max - unit_amt) move_amt = LIMIT_TO(move_amt, -unit_amt, unit_max - unit_amt);
move_amt = unit_max - unit_amt; move_amt = LIMIT_TO(move_amt, sect_amt - ITEM_MAX, sect_amt);
if (move_amt < -unit_amt)
move_amt = -unit_amt;
if (move_amt > sect_amt)
move_amt = sect_amt;
if (move_amt < sect_amt - ITEM_MAX)
move_amt = sect_amt - ITEM_MAX;
return move_amt; return move_amt;
} }

View file

@ -30,6 +30,7 @@
* David Muir Sharnoff * David Muir Sharnoff
* Karl Hagen * Karl Hagen
* Steve McClure, 1998 * Steve McClure, 1998
* Markus Armbruster, 2010-2013
*/ */
#include <config.h> #include <config.h>
@ -64,10 +65,7 @@ setres(void)
if (!p || !*p) if (!p || !*p)
return RET_SYN; return RET_SYN;
amt = atoi(p); amt = atoi(p);
if (amt > 100) amt = LIMIT_TO(amt, 0, 100);
amt = 100;
if (amt < 0)
amt = 0;
if (!check_sect_ok(&sect)) if (!check_sect_ok(&sect))
return RET_FAIL; return RET_FAIL;
switch (char0) { switch (char0) {

View file

@ -29,6 +29,7 @@
* Known contributors to this file: * Known contributors to this file:
* David Muir Sharnoff * David Muir Sharnoff
* Steve McClure, 1998 * Steve McClure, 1998
* Markus Armbruster, 2004-2013
*/ */
#include <config.h> #include <config.h>
@ -73,10 +74,7 @@ setsector(void)
case 'i': case 'i':
current = sect.sct_min; current = sect.sct_min;
current += amt; current += amt;
if (current < 0) current = LIMIT_TO(current, 0, 100);
current = 0;
if (current > 100)
current = 100;
if (sect.sct_own != 0) if (sect.sct_own != 0)
resnoise(&sect, "Iron ore content", sect.sct_min, current); resnoise(&sect, "Iron ore content", sect.sct_min, current);
sect.sct_min = (unsigned char)current; sect.sct_min = (unsigned char)current;
@ -84,10 +82,7 @@ setsector(void)
case 'g': case 'g':
current = sect.sct_gmin; current = sect.sct_gmin;
current += amt; current += amt;
if (current < 0) current = LIMIT_TO(current, 0, 100);
current = 0;
if (current > 100)
current = 100;
if (sect.sct_own != 0) if (sect.sct_own != 0)
resnoise(&sect, "Gold content", sect.sct_gmin, current); resnoise(&sect, "Gold content", sect.sct_gmin, current);
sect.sct_gmin = (unsigned char)current; sect.sct_gmin = (unsigned char)current;
@ -97,10 +92,7 @@ setsector(void)
case 'i': case 'i':
current = sect.sct_oil; current = sect.sct_oil;
current += amt; current += amt;
if (current < 0) current = LIMIT_TO(current, 0, 100);
current = 0;
if (current > 100)
current = 100;
if (sect.sct_own != 0) if (sect.sct_own != 0)
resnoise(&sect, "Oil content", sect.sct_oil, current); resnoise(&sect, "Oil content", sect.sct_oil, current);
sect.sct_oil = (unsigned char)current; sect.sct_oil = (unsigned char)current;
@ -139,10 +131,7 @@ setsector(void)
case 'e': case 'e':
current = sect.sct_effic; current = sect.sct_effic;
current += amt; current += amt;
if (current < 0) current = LIMIT_TO(current, 0, 100);
current = 0;
if (current > 100)
current = 100;
pr("Efficiency in %s changed to %d.\n", pr("Efficiency in %s changed to %d.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), current); xyas(sect.sct_x, sect.sct_y, player->cnum), current);
sect.sct_effic = current; sect.sct_effic = current;
@ -152,10 +141,7 @@ setsector(void)
case 'i': case 'i':
current = sect.sct_mines; current = sect.sct_mines;
current += amt; current += amt;
if (current < 0) current = LIMIT_TO(current, 0, MINES_MAX);
current = 0;
if (current > MINES_MAX)
current = MINES_MAX;
if (sect.sct_own != 0 && sect.sct_own == sect.sct_oldown) if (sect.sct_own != 0 && sect.sct_own == sect.sct_oldown)
resnoise(&sect, "Mines", sect.sct_mines, current); resnoise(&sect, "Mines", sect.sct_mines, current);
sect.sct_mines = current; sect.sct_mines = current;
@ -163,10 +149,7 @@ setsector(void)
case 'o': case 'o':
current = sect.sct_mobil; current = sect.sct_mobil;
current += amt; current += amt;
if (current < -127) current = LIMIT_TO(current, -127, 127);
current = -127;
if (current > 127)
current = 127;
pr("Mobility in %s changed to %d.\n", pr("Mobility in %s changed to %d.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), current); xyas(sect.sct_x, sect.sct_y, player->cnum), current);
sect.sct_mobil = current; sect.sct_mobil = current;
@ -179,10 +162,7 @@ setsector(void)
case 'a': case 'a':
current = sect.sct_avail; current = sect.sct_avail;
current += amt; current += amt;
if (current < 0) current = LIMIT_TO(current, 0, 9999);
current = 0;
if (current > 9999)
current = 9999;
pr("Available in %s changed to %d.\n", pr("Available in %s changed to %d.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), current); xyas(sect.sct_x, sect.sct_y, player->cnum), current);
sect.sct_avail = (short)current; sect.sct_avail = (short)current;
@ -190,10 +170,7 @@ setsector(void)
case 'w': case 'w':
current = sect.sct_work; current = sect.sct_work;
current += amt; current += amt;
if (current < 0) current = LIMIT_TO(current, 0, 100);
current = 0;
if (current > 100)
current = 100;
pr("Work in %s changed to %d.\n", pr("Work in %s changed to %d.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), current); xyas(sect.sct_x, sect.sct_y, player->cnum), current);
sect.sct_work = (unsigned char)current; sect.sct_work = (unsigned char)current;
@ -201,10 +178,7 @@ setsector(void)
case 'f': case 'f':
current = sect.sct_fertil; current = sect.sct_fertil;
current += amt; current += amt;
if (current < 0) current = LIMIT_TO(current, 0, 100);
current = 0;
if (current > 100)
current = 100;
if (sect.sct_own != 0) if (sect.sct_own != 0)
resnoise(&sect, "Fertility content", sect.sct_fertil, current); resnoise(&sect, "Fertility content", sect.sct_fertil, current);
sect.sct_fertil = (unsigned char)current; sect.sct_fertil = (unsigned char)current;
@ -212,10 +186,7 @@ setsector(void)
case 'u': case 'u':
current = sect.sct_uran; current = sect.sct_uran;
current += amt; current += amt;
if (current < 0) current = LIMIT_TO(current, 0, 100);
current = 0;
if (current > 100)
current = 100;
if (sect.sct_own != 0) if (sect.sct_own != 0)
resnoise(&sect, "Uranium content", sect.sct_uran, current); resnoise(&sect, "Uranium content", sect.sct_uran, current);
sect.sct_uran = (unsigned char)current; sect.sct_uran = (unsigned char)current;

View file

@ -51,11 +51,7 @@ hap_fact(struct natstr *tnat, struct natstr *vnat)
hap_fact = 2.0; hap_fact = 2.0;
else /* Target has no happy, worse fighting */ else /* Target has no happy, worse fighting */
hap_fact = 0.8; hap_fact = 0.8;
if (hap_fact > 2.0) return LIMIT_TO(hap_fact, 0.8, 2.0);
hap_fact = 2.0;
if (hap_fact < 0.8)
hap_fact = 0.8;
return hap_fact;
} }
/* Return happiness required to keep NP's citizens happy. */ /* Return happiness required to keep NP's citizens happy. */

View file

@ -29,7 +29,7 @@
* Known contributors to this file: * Known contributors to this file:
* Ken Stevens, 1995 * Ken Stevens, 1995
* Steve McClure, 1996-2000 * Steve McClure, 1996-2000
* Markus Armbruster, 2006-2012 * Markus Armbruster, 2006-2013
*/ */
#include <config.h> #include <config.h>
@ -2587,9 +2587,5 @@ sector_strength(struct sctstr *sp)
double base = sp->sct_type == SCT_MOUNT ? 2.0 : 1.0; double base = sp->sct_type == SCT_MOUNT ? 2.0 : 1.0;
double d = base + (dchr[sp->sct_type].d_dstr - base) * def; double d = base + (dchr[sp->sct_type].d_dstr - base) * def;
if (d > dchr[sp->sct_type].d_dstr) return LIMIT_TO(d, base, dchr[sp->sct_type].d_dstr);
d = dchr[sp->sct_type].d_dstr;
if (d < base)
d = base;
return d;
} }

View file

@ -29,7 +29,7 @@
* Known contributors to this file: * Known contributors to this file:
* Ken Stevens, 1995 * Ken Stevens, 1995
* Steve McClure, 1996-2000 * Steve McClure, 1996-2000
* Markus Armbruster, 2006-2012 * Markus Armbruster, 2006-2013
*/ */
#include <config.h> #include <config.h>
@ -871,10 +871,7 @@ shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget)
teff = ship.shp_tech / (ship.shp_tech + 200.0); teff = ship.shp_tech / (ship.shp_tech + 200.0);
/* raise 4.5 for better interception -KHS */ /* raise 4.5 for better interception -KHS */
hitchance = (int)(gun * eff * teff * 4.5) - hardtarget; hitchance = (int)(gun * eff * teff * 4.5) - hardtarget;
if (hitchance < 0) hitchance = LIMIT_TO(hitchance, 0, 100);
hitchance = 0;
if (hitchance > 100)
hitchance = 100;
hit = pct_chance(hitchance); hit = pct_chance(hitchance);
mpr(bombown, "%s anti-missile system activated...%s\n", mpr(bombown, "%s anti-missile system activated...%s\n",

View file

@ -27,7 +27,7 @@
* supply.c: Supply subroutines * supply.c: Supply subroutines
* *
* Known contributors to this file: * Known contributors to this file:
* Markus Armbruster, 2004-2011 * Markus Armbruster, 2004-2013
*/ */
#include <config.h> #include <config.h>
@ -201,11 +201,7 @@ s_commod(struct empobj *sink, short *vec,
/* take off mobility for delivering sect */ /* take off mobility for delivering sect */
n = roundavg(wanted * weight * move_cost); n = roundavg(wanted * weight * move_cost);
if (n < 0) sect.sct_mobil -= LIMIT_TO(n, 0, sect.sct_mobil);
n = 0;
if (n > sect.sct_mobil)
n = sect.sct_mobil;
sect.sct_mobil -= n;
if (actually_doit) { if (actually_doit) {
vec[type] += wanted; vec[type] += wanted;
putsect(&sect); putsect(&sect);
@ -219,11 +215,7 @@ s_commod(struct empobj *sink, short *vec,
/* take off mobility for delivering sect */ /* take off mobility for delivering sect */
n = roundavg(can_move * weight * move_cost); n = roundavg(can_move * weight * move_cost);
if (n < 0) sect.sct_mobil -= LIMIT_TO(n, 0, sect.sct_mobil);
n = 0;
if (n > sect.sct_mobil)
n = sect.sct_mobil;
sect.sct_mobil -= n;
if (actually_doit) { if (actually_doit) {
vec[type] += can_move; vec[type] += can_move;
putsect(&sect); putsect(&sect);
@ -271,11 +263,7 @@ s_commod(struct empobj *sink, short *vec,
ship.shp_item[type] -= wanted; ship.shp_item[type] -= wanted;
n = roundavg(wanted * weight * move_cost); n = roundavg(wanted * weight * move_cost);
if (n < 0) sect.sct_mobil -= LIMIT_TO(n, 0, sect.sct_mobil);
n = 0;
if (n > sect.sct_mobil)
n = sect.sct_mobil;
sect.sct_mobil -= n;
if (actually_doit) { if (actually_doit) {
vec[type] += can_move; vec[type] += can_move;
putship(ship.shp_uid, &ship); putship(ship.shp_uid, &ship);
@ -289,11 +277,7 @@ s_commod(struct empobj *sink, short *vec,
ship.shp_item[type] -= can_move; ship.shp_item[type] -= can_move;
n = roundavg(can_move * weight * move_cost); n = roundavg(can_move * weight * move_cost);
if (n < 0) sect.sct_mobil -= LIMIT_TO(n, 0, sect.sct_mobil);
n = 0;
if (n > sect.sct_mobil)
n = sect.sct_mobil;
sect.sct_mobil -= n;
if (actually_doit) { if (actually_doit) {
vec[type] += can_move; vec[type] += can_move;
putship(ship.shp_uid, &ship); putship(ship.shp_uid, &ship);

View file

@ -102,11 +102,7 @@ populace(struct natstr *np, struct sctstr *sp, int etu)
n -= roundavg(etu * 0.25); n -= roundavg(etu * 0.25);
else else
n += roundavg(etu * 0.125); n += roundavg(etu * 0.125);
if (n < 0) sp->sct_loyal = LIMIT_TO(n, 0, 127);
n = 0;
else if (n > 127)
n = 127;
sp->sct_loyal = n;
if (sp->sct_loyal == 0) { if (sp->sct_loyal == 0) {
if (sp->sct_oldown != sp->sct_own) { if (sp->sct_oldown != sp->sct_own) {
wu(0, sp->sct_own, wu(0, sp->sct_own,

View file

@ -378,10 +378,7 @@ parse_args(int argc, char *argv[])
sp = atoi(argv[4]); sp = atoi(argv[4]);
else else
sp = DEFAULT_SPIKE; sp = DEFAULT_SPIKE;
if (sp < 0) sp = LIMIT_TO(sp, 0, 100);
sp = 0;
if (sp > 100)
sp = 100;
if (argc > 5) if (argc > 5)
pm = atoi(argv[5]); pm = atoi(argv[5]);