Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
*
* Known contributors to this file:
* Doug Hay, 1998
*
* Known contributors to this file:
* Doug Hay, 1998
+ * Markus Armbruster, 2004-2013
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(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
#include "w32misc.h"
#endif /* _WIN32 */
#ifdef _WIN32
#include "w32misc.h"
#endif /* _WIN32 */
-static int
-errcheck(int num, int min, int max)
-{
- if (num < min)
- return min;
- else if (num > max)
- return max;
- return num;
-}
-
static int
getin(char *buf, char **valp)
{
static int
getin(char *buf, char **valp)
{
case 'o':
if (arg < 0)
return RET_SYN;
case 'o':
if (arg < 0)
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",
xyas(sect->sct_x, sect->sct_y, player->cnum),
cname(sect->sct_own), sect->sct_own, cname(newown), newown);
pr("Owner of %s changed from %s (#%d) to %s (#%d).\n",
xyas(sect->sct_x, sect->sct_y, player->cnum),
cname(sect->sct_own), sect->sct_own, cname(newown), newown);
case 'O':
if (arg < 0)
return RET_SYN;
case 'O':
if (arg < 0)
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",
xyas(sect->sct_x, sect->sct_y, player->cnum),
cname(sect->sct_oldown),
pr("Old owner of %s changed from %s (#%d) to %s (#%d).\n",
xyas(sect->sct_x, sect->sct_y, player->cnum),
cname(sect->sct_oldown),
sect->sct_oldown = oldown;
break;
case 'e':
sect->sct_oldown = oldown;
break;
case 'e':
- new = errcheck(arg, 0, 100);
+ new = LIMIT_TO(arg, 0, 100);
noise(sect, "Efficiency", sect->sct_effic, new);
sect->sct_effic = new;
break;
case 'm':
noise(sect, "Efficiency", sect->sct_effic, new);
sect->sct_effic = new;
break;
case 'm':
- new = errcheck(arg, -127, 255);
+ new = LIMIT_TO(arg, -127, 255);
noise(sect, "Mobility", sect->sct_mobil, new);
sect->sct_mobil = new;
break;
case 'i':
noise(sect, "Mobility", sect->sct_mobil, new);
sect->sct_mobil = new;
break;
case 'i':
- new = errcheck(arg, 0, 127);
+ new = LIMIT_TO(arg, 0, 127);
noise(sect, "Iron ore content", sect->sct_min, new);
sect->sct_min = (unsigned char)new;
break;
case 'g':
noise(sect, "Iron ore content", sect->sct_min, new);
sect->sct_min = (unsigned char)new;
break;
case 'g':
- new = errcheck(arg, 0, 127);
+ new = LIMIT_TO(arg, 0, 127);
noise(sect, "Gold content", sect->sct_gmin, new);
sect->sct_gmin = (unsigned char)new;
break;
case 'f':
noise(sect, "Gold content", sect->sct_gmin, new);
sect->sct_gmin = (unsigned char)new;
break;
case 'f':
- new = errcheck(arg, 0, 127);
+ new = LIMIT_TO(arg, 0, 127);
noise(sect, "Fertility", sect->sct_fertil, new);
sect->sct_fertil = (unsigned char)new;
break;
case 'c':
noise(sect, "Fertility", sect->sct_fertil, new);
sect->sct_fertil = (unsigned char)new;
break;
case 'c':
- new = errcheck(arg, 0, 127);
+ new = LIMIT_TO(arg, 0, 127);
noise(sect, "Oil content", sect->sct_oil, new);
sect->sct_oil = (unsigned char)new;
break;
case 'u':
noise(sect, "Oil content", sect->sct_oil, new);
sect->sct_oil = (unsigned char)new;
break;
case 'u':
- new = errcheck(arg, 0, 127);
+ new = LIMIT_TO(arg, 0, 127);
noise(sect, "Uranium content", sect->sct_uran, new);
sect->sct_uran = (unsigned char)new;
break;
case 'w':
noise(sect, "Uranium content", sect->sct_uran, new);
sect->sct_uran = (unsigned char)new;
break;
case 'w':
- new = errcheck(arg, 0, 100);
+ new = LIMIT_TO(arg, 0, 100);
noise(sect, "Workforce percentage", sect->sct_work, new);
sect->sct_work = (unsigned char)new;
break;
case 'l':
noise(sect, "Workforce percentage", sect->sct_work, new);
sect->sct_work = (unsigned char)new;
break;
case 'l':
- new = errcheck(arg, 0, 127);
+ new = LIMIT_TO(arg, 0, 127);
pr("Loyalty of %s changed from %d to %d%%\n",
xyas(sect->sct_x, sect->sct_y, player->cnum),
sect->sct_loyal, new);
pr("Loyalty of %s changed from %d to %d%%\n",
xyas(sect->sct_x, sect->sct_y, player->cnum),
sect->sct_loyal, new);
break;
case 'x':
old = sect->sct_che;
break;
case 'x':
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",
xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
sect->sct_che = new;
break;
case 'X':
old = sect->sct_che_target;
pr("Guerillas in %s changed from %d to %d\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
sect->sct_che = new;
break;
case 'X':
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",
xyas(sect->sct_x, sect->sct_y, player->cnum),
cname(old), old, cname(new), new);
pr("Che target of %s changed from %s (#%d) to %s (#%d).\n",
xyas(sect->sct_x, sect->sct_y, player->cnum),
cname(old), old, cname(new), new);
break;
case 'p':
old = sect->sct_pstage;
break;
case 'p':
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",
xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
sect->sct_pstage = new;
break;
case 't':
old = sect->sct_ptime;
pr("Plague stage of %s changed from %d to %d%%\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
sect->sct_pstage = new;
break;
case 't':
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",
xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
sect->sct_ptime = new;
break;
case 'F':
old = sect->sct_fallout;
pr("Plague time of %s changed from %d to %d%%\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
sect->sct_ptime = new;
break;
case 'F':
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",
xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
sect->sct_fallout = new;
break;
case 'a':
pr("Fallout for sector %s changed from %d to %d\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
sect->sct_fallout = new;
break;
case 'a':
- new = errcheck(arg, 0, 9999);
+ new = LIMIT_TO(arg, 0, 9999);
noise(sect, "Available workforce", sect->sct_avail, new);
sect->sct_avail = new;
break;
case 'M':
noise(sect, "Available workforce", sect->sct_avail, new);
sect->sct_avail = new;
break;
case 'M':
- new = errcheck(arg, 0, MINES_MAX);
+ new = LIMIT_TO(arg, 0, MINES_MAX);
sect->sct_mines = new;
pr("Mines changed to %d\n", new);
break;
sect->sct_mines = new;
pr("Mines changed to %d\n", new);
break;
sect->sct_newtype = des;
break;
case 'R':
sect->sct_newtype = des;
break;
case 'R':
- if (arg > 100)
- arg = 100;
- if (arg < 0)
- arg = 0;
- noise(sect, "Road percentage", sect->sct_road, arg);
- sect->sct_road = arg;
+ new = LIMIT_TO(arg, 0, 100);
+ noise(sect, "Road percentage", sect->sct_road, new);
+ sect->sct_road = new;
- if (arg > 100)
- arg = 100;
- if (arg < 0)
- arg = 0;
- noise(sect, "Rail percentage", sect->sct_rail, arg);
- sect->sct_rail = arg;
+ new = LIMIT_TO(arg, 0, 100);
+ noise(sect, "Rail percentage", sect->sct_rail, new);
+ sect->sct_rail = new;
- if (arg > 100)
- arg = 100;
- if (arg < 0)
- arg = 0;
- noise(sect, "Defense percentage", sect->sct_defense, arg);
- sect->sct_defense = arg;
+ new = LIMIT_TO(arg, 0, 100);
+ noise(sect, "Defense percentage", sect->sct_defense, new);
+ sect->sct_defense = new;
break;
default:
pr("huh? (%c)\n", op);
break;
default:
pr("huh? (%c)\n", op);
np->nat_tgms = arg;
break;
case 'b':
np->nat_tgms = arg;
break;
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);
np->nat_btu = arg;
break;
pr("BTU's changed from %d to %d\n", np->nat_btu, arg);
np->nat_btu = arg;
break;
np->nat_yorg = newy;
break;
case 's':
np->nat_yorg = newy;
break;
case 's':
- np->nat_stat = errcheck(arg, STAT_UNUSED, STAT_GOD);
+ np->nat_stat = LIMIT_TO(arg, STAT_UNUSED, STAT_GOD);
- 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",
np->nat_timeused, arg);
np->nat_timeused = arg;
pr("Number of seconds used changed from %d to %d.\n",
np->nat_timeused, arg);
np->nat_timeused = arg;
ship->shp_y = newy;
break;
case 'T':
ship->shp_y = newy;
break;
case 'T':
- shp_set_tech(ship,
- errcheck(arg,
- mchr[(int)ship->shp_type].m_tech, SHRT_MAX));
+ arg = LIMIT_TO(arg, mchr[(int)ship->shp_type].m_tech, SHRT_MAX);
+ shp_set_tech(ship, arg);
- ship->shp_effic = errcheck(arg, SHIP_MINEFF, 100);
+ ship->shp_effic = LIMIT_TO(arg, SHIP_MINEFF, 100);
break;
case 'M':
ship->shp_mobil = arg;
break;
case 'M':
ship->shp_mobil = arg;
land->lnd_y = newy;
break;
case 'e':
land->lnd_y = newy;
break;
case 'e':
- land->lnd_effic = errcheck(arg, LAND_MINEFF, 100);
+ land->lnd_effic = LIMIT_TO(arg, LAND_MINEFF, 100);
break;
case 'M':
land->lnd_mobil = arg;
break;
case 't':
break;
case 'M':
land->lnd_mobil = arg;
break;
case 't':
- lnd_set_tech(land,
- errcheck(arg,
- lchr[(int)land->lnd_type].l_tech, SHRT_MAX));
+ arg = LIMIT_TO(arg, lchr[(int)land->lnd_type].l_tech, SHRT_MAX);
+ lnd_set_tech(land, arg);
break;
case 'a':
if (p[0] == '~')
break;
case 'a':
if (p[0] == '~')
- land->lnd_harden = errcheck(arg, 0, 255);
+ land->lnd_harden = LIMIT_TO(arg, 0, 255);
break;
case 'S':
land->lnd_ship = arg;
break;
case 'S':
land->lnd_ship = arg;
plane->pln_effic = 0;
break;
case 'e':
plane->pln_effic = 0;
break;
case 'e':
- plane->pln_effic = errcheck(arg, PLANE_MINEFF, 100);
+ plane->pln_effic = LIMIT_TO(arg, PLANE_MINEFF, 100);
- plane->pln_mobil = errcheck(arg, -127, 255);
+ plane->pln_mobil = LIMIT_TO(arg, -127, 255);
- pln_set_tech(plane,
- errcheck(arg,
- plchr[(int)plane->pln_type].pl_tech, SHRT_MAX));
+ arg = LIMIT_TO(arg, plchr[(int)plane->pln_type].pl_tech, SHRT_MAX);
+ pln_set_tech(plane, arg);
break;
case 'w':
if (p[0] == '~')
break;
case 'w':
if (p[0] == '~')
* David Sharnoff, 1987
* Ken Stevens, 1995 (rewritten)
* Steve McClure, 1998-2000
* David Sharnoff, 1987
* Ken Stevens, 1995 (rewritten)
* Steve McClure, 1998-2000
- * Markus Armbruster, 2004-2012
+ * Markus Armbruster, 2004-2013
move_amt = -amount - unit_amt;
else
move_amt = load_unload == LOAD ? amount : -amount;
move_amt = -amount - unit_amt;
else
move_amt = load_unload == LOAD ? amount : -amount;
- if (move_amt > unit_max - unit_amt)
- move_amt = unit_max - unit_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;
+ move_amt = LIMIT_TO(move_amt, -unit_amt, unit_max - unit_amt);
+ move_amt = LIMIT_TO(move_amt, sect_amt - ITEM_MAX, sect_amt);
* David Muir Sharnoff
* Karl Hagen
* Steve McClure, 1998
* David Muir Sharnoff
* Karl Hagen
* Steve McClure, 1998
+ * Markus Armbruster, 2010-2013
if (!p || !*p)
return RET_SYN;
amt = atoi(p);
if (!p || !*p)
return RET_SYN;
amt = atoi(p);
- if (amt > 100)
- amt = 100;
- if (amt < 0)
- amt = 0;
+ amt = LIMIT_TO(amt, 0, 100);
if (!check_sect_ok(§))
return RET_FAIL;
switch (char0) {
if (!check_sect_ok(§))
return RET_FAIL;
switch (char0) {
* Known contributors to this file:
* David Muir Sharnoff
* Steve McClure, 1998
* Known contributors to this file:
* David Muir Sharnoff
* Steve McClure, 1998
+ * Markus Armbruster, 2004-2013
case 'i':
current = sect.sct_min;
current += amt;
case 'i':
current = sect.sct_min;
current += amt;
- if (current < 0)
- current = 0;
- if (current > 100)
- current = 100;
+ current = LIMIT_TO(current, 0, 100);
if (sect.sct_own != 0)
resnoise(§, "Iron ore content", sect.sct_min, current);
sect.sct_min = (unsigned char)current;
if (sect.sct_own != 0)
resnoise(§, "Iron ore content", sect.sct_min, current);
sect.sct_min = (unsigned char)current;
case 'g':
current = sect.sct_gmin;
current += amt;
case 'g':
current = sect.sct_gmin;
current += amt;
- if (current < 0)
- current = 0;
- if (current > 100)
- current = 100;
+ current = LIMIT_TO(current, 0, 100);
if (sect.sct_own != 0)
resnoise(§, "Gold content", sect.sct_gmin, current);
sect.sct_gmin = (unsigned char)current;
if (sect.sct_own != 0)
resnoise(§, "Gold content", sect.sct_gmin, current);
sect.sct_gmin = (unsigned char)current;
case 'i':
current = sect.sct_oil;
current += amt;
case 'i':
current = sect.sct_oil;
current += amt;
- if (current < 0)
- current = 0;
- if (current > 100)
- current = 100;
+ current = LIMIT_TO(current, 0, 100);
if (sect.sct_own != 0)
resnoise(§, "Oil content", sect.sct_oil, current);
sect.sct_oil = (unsigned char)current;
if (sect.sct_own != 0)
resnoise(§, "Oil content", sect.sct_oil, current);
sect.sct_oil = (unsigned char)current;
case 'e':
current = sect.sct_effic;
current += amt;
case 'e':
current = sect.sct_effic;
current += amt;
- if (current < 0)
- current = 0;
- if (current > 100)
- current = 100;
+ current = LIMIT_TO(current, 0, 100);
pr("Efficiency in %s changed to %d.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), current);
sect.sct_effic = current;
pr("Efficiency in %s changed to %d.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), current);
sect.sct_effic = current;
case 'i':
current = sect.sct_mines;
current += amt;
case 'i':
current = sect.sct_mines;
current += amt;
- if (current < 0)
- current = 0;
- if (current > MINES_MAX)
- current = MINES_MAX;
+ current = LIMIT_TO(current, 0, MINES_MAX);
if (sect.sct_own != 0 && sect.sct_own == sect.sct_oldown)
resnoise(§, "Mines", sect.sct_mines, current);
sect.sct_mines = current;
if (sect.sct_own != 0 && sect.sct_own == sect.sct_oldown)
resnoise(§, "Mines", sect.sct_mines, current);
sect.sct_mines = current;
case 'o':
current = sect.sct_mobil;
current += amt;
case 'o':
current = sect.sct_mobil;
current += amt;
- if (current < -127)
- current = -127;
- if (current > 127)
- current = 127;
+ current = LIMIT_TO(current, -127, 127);
pr("Mobility in %s changed to %d.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), current);
sect.sct_mobil = current;
pr("Mobility in %s changed to %d.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), current);
sect.sct_mobil = current;
case 'a':
current = sect.sct_avail;
current += amt;
case 'a':
current = sect.sct_avail;
current += amt;
- if (current < 0)
- current = 0;
- if (current > 9999)
- current = 9999;
+ current = LIMIT_TO(current, 0, 9999);
pr("Available in %s changed to %d.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), current);
sect.sct_avail = (short)current;
pr("Available in %s changed to %d.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), current);
sect.sct_avail = (short)current;
case 'w':
current = sect.sct_work;
current += amt;
case 'w':
current = sect.sct_work;
current += amt;
- if (current < 0)
- current = 0;
- if (current > 100)
- current = 100;
+ current = LIMIT_TO(current, 0, 100);
pr("Work in %s changed to %d.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), current);
sect.sct_work = (unsigned char)current;
pr("Work in %s changed to %d.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum), current);
sect.sct_work = (unsigned char)current;
case 'f':
current = sect.sct_fertil;
current += amt;
case 'f':
current = sect.sct_fertil;
current += amt;
- if (current < 0)
- current = 0;
- if (current > 100)
- current = 100;
+ current = LIMIT_TO(current, 0, 100);
if (sect.sct_own != 0)
resnoise(§, "Fertility content", sect.sct_fertil, current);
sect.sct_fertil = (unsigned char)current;
if (sect.sct_own != 0)
resnoise(§, "Fertility content", sect.sct_fertil, current);
sect.sct_fertil = (unsigned char)current;
case 'u':
current = sect.sct_uran;
current += amt;
case 'u':
current = sect.sct_uran;
current += amt;
- if (current < 0)
- current = 0;
- if (current > 100)
- current = 100;
+ current = LIMIT_TO(current, 0, 100);
if (sect.sct_own != 0)
resnoise(§, "Uranium content", sect.sct_uran, current);
sect.sct_uran = (unsigned char)current;
if (sect.sct_own != 0)
resnoise(§, "Uranium content", sect.sct_uran, current);
sect.sct_uran = (unsigned char)current;
hap_fact = 2.0;
else /* Target has no happy, worse fighting */
hap_fact = 0.8;
hap_fact = 2.0;
else /* Target has no happy, worse fighting */
hap_fact = 0.8;
- if (hap_fact > 2.0)
- hap_fact = 2.0;
- if (hap_fact < 0.8)
- hap_fact = 0.8;
- return hap_fact;
+ return LIMIT_TO(hap_fact, 0.8, 2.0);
}
/* Return happiness required to keep NP's citizens happy. */
}
/* Return happiness required to keep NP's citizens happy. */
* Known contributors to this file:
* Ken Stevens, 1995
* Steve McClure, 1996-2000
* Known contributors to this file:
* Ken Stevens, 1995
* Steve McClure, 1996-2000
- * Markus Armbruster, 2006-2012
+ * Markus Armbruster, 2006-2013
double base = sp->sct_type == SCT_MOUNT ? 2.0 : 1.0;
double d = base + (dchr[sp->sct_type].d_dstr - base) * def;
double base = sp->sct_type == SCT_MOUNT ? 2.0 : 1.0;
double d = base + (dchr[sp->sct_type].d_dstr - base) * def;
- if (d > dchr[sp->sct_type].d_dstr)
- d = dchr[sp->sct_type].d_dstr;
- if (d < base)
- d = base;
- return d;
+ return LIMIT_TO(d, base, dchr[sp->sct_type].d_dstr);
* Known contributors to this file:
* Ken Stevens, 1995
* Steve McClure, 1996-2000
* Known contributors to this file:
* Ken Stevens, 1995
* Steve McClure, 1996-2000
- * Markus Armbruster, 2006-2012
+ * Markus Armbruster, 2006-2013
teff = ship.shp_tech / (ship.shp_tech + 200.0);
/* raise 4.5 for better interception -KHS */
hitchance = (int)(gun * eff * teff * 4.5) - hardtarget;
teff = ship.shp_tech / (ship.shp_tech + 200.0);
/* raise 4.5 for better interception -KHS */
hitchance = (int)(gun * eff * teff * 4.5) - hardtarget;
- if (hitchance < 0)
- hitchance = 0;
- if (hitchance > 100)
- hitchance = 100;
+ hitchance = LIMIT_TO(hitchance, 0, 100);
hit = pct_chance(hitchance);
mpr(bombown, "%s anti-missile system activated...%s\n",
hit = pct_chance(hitchance);
mpr(bombown, "%s anti-missile system activated...%s\n",
* supply.c: Supply subroutines
*
* Known contributors to this file:
* supply.c: Supply subroutines
*
* Known contributors to this file:
- * Markus Armbruster, 2004-2011
+ * Markus Armbruster, 2004-2013
/* take off mobility for delivering sect */
n = roundavg(wanted * weight * move_cost);
/* take off mobility for delivering sect */
n = roundavg(wanted * weight * move_cost);
- if (n < 0)
- n = 0;
- if (n > sect.sct_mobil)
- n = sect.sct_mobil;
- sect.sct_mobil -= n;
+ sect.sct_mobil -= LIMIT_TO(n, 0, sect.sct_mobil);
if (actually_doit) {
vec[type] += wanted;
putsect(§);
if (actually_doit) {
vec[type] += wanted;
putsect(§);
/* take off mobility for delivering sect */
n = roundavg(can_move * weight * move_cost);
/* take off mobility for delivering sect */
n = roundavg(can_move * weight * move_cost);
- if (n < 0)
- n = 0;
- if (n > sect.sct_mobil)
- n = sect.sct_mobil;
- sect.sct_mobil -= n;
+ sect.sct_mobil -= LIMIT_TO(n, 0, sect.sct_mobil);
if (actually_doit) {
vec[type] += can_move;
putsect(§);
if (actually_doit) {
vec[type] += can_move;
putsect(§);
ship.shp_item[type] -= wanted;
n = roundavg(wanted * weight * move_cost);
ship.shp_item[type] -= wanted;
n = roundavg(wanted * weight * move_cost);
- if (n < 0)
- n = 0;
- if (n > sect.sct_mobil)
- n = sect.sct_mobil;
- sect.sct_mobil -= n;
+ sect.sct_mobil -= LIMIT_TO(n, 0, sect.sct_mobil);
if (actually_doit) {
vec[type] += can_move;
putship(ship.shp_uid, &ship);
if (actually_doit) {
vec[type] += can_move;
putship(ship.shp_uid, &ship);
ship.shp_item[type] -= can_move;
n = roundavg(can_move * weight * move_cost);
ship.shp_item[type] -= can_move;
n = roundavg(can_move * weight * move_cost);
- if (n < 0)
- n = 0;
- if (n > sect.sct_mobil)
- n = sect.sct_mobil;
- sect.sct_mobil -= n;
+ sect.sct_mobil -= LIMIT_TO(n, 0, sect.sct_mobil);
if (actually_doit) {
vec[type] += can_move;
putship(ship.shp_uid, &ship);
if (actually_doit) {
vec[type] += can_move;
putship(ship.shp_uid, &ship);
n -= roundavg(etu * 0.25);
else
n += roundavg(etu * 0.125);
n -= roundavg(etu * 0.25);
else
n += roundavg(etu * 0.125);
- if (n < 0)
- n = 0;
- else if (n > 127)
- n = 127;
- sp->sct_loyal = n;
+ sp->sct_loyal = LIMIT_TO(n, 0, 127);
if (sp->sct_loyal == 0) {
if (sp->sct_oldown != sp->sct_own) {
wu(0, sp->sct_own,
if (sp->sct_loyal == 0) {
if (sp->sct_oldown != sp->sct_own) {
wu(0, sp->sct_own,
sp = atoi(argv[4]);
else
sp = DEFAULT_SPIKE;
sp = atoi(argv[4]);
else
sp = DEFAULT_SPIKE;
- if (sp < 0)
- sp = 0;
- if (sp > 100)
- sp = 100;
+ sp = LIMIT_TO(sp, 0, 100);
if (argc > 5)
pm = atoi(argv[5]);
if (argc > 5)
pm = atoi(argv[5]);