Replace common pattern by new LIMIT_TO()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
aa870f5d91
commit
726b9380d1
11 changed files with 73 additions and 162 deletions
|
@ -29,7 +29,7 @@
|
|||
* Known contributors to this file:
|
||||
* Ken Stevens, 1995
|
||||
* Steve McClure, 1996-2000
|
||||
* Markus Armbruster, 2006-2012
|
||||
* Markus Armbruster, 2006-2013
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -2587,9 +2587,5 @@ sector_strength(struct sctstr *sp)
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
* Known contributors to this file:
|
||||
* Ken Stevens, 1995
|
||||
* Steve McClure, 1996-2000
|
||||
* Markus Armbruster, 2006-2012
|
||||
* Markus Armbruster, 2006-2013
|
||||
*/
|
||||
|
||||
#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);
|
||||
/* 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",
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
* supply.c: Supply subroutines
|
||||
*
|
||||
* Known contributors to this file:
|
||||
* Markus Armbruster, 2004-2011
|
||||
* Markus Armbruster, 2004-2013
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -201,11 +201,7 @@ s_commod(struct empobj *sink, short *vec,
|
|||
|
||||
/* 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(§);
|
||||
|
@ -219,11 +215,7 @@ s_commod(struct empobj *sink, short *vec,
|
|||
|
||||
/* 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(§);
|
||||
|
@ -271,11 +263,7 @@ s_commod(struct empobj *sink, short *vec,
|
|||
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);
|
||||
|
@ -289,11 +277,7 @@ s_commod(struct empobj *sink, short *vec,
|
|||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue