/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2017, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
* supply.c: Supply subroutines
*
* Known contributors to this file:
- * Markus Armbruster, 2004-2011
+ * Markus Armbruster, 2004-2013
*/
#include <config.h>
#include <math.h>
+#include "chance.h"
#include "empobj.h"
-#include "file.h"
#include "land.h"
#include "nat.h"
#include "optlist.h"
#include "prototypes.h"
#include "sect.h"
#include "ship.h"
+#include "update.h"
static int s_commod(struct empobj *, short *, i_type, int, int, int);
static int get_minimum(struct lndstr *, i_type);
/* 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(§);
/* 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(§);
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);
- putsect(§);
+ if (n)
+ putsect(§);
put_empobj(sink->ef_type, sink->uid, sink);
}
return 1;
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);
- putsect(§);
+ if (n)
+ putsect(§);
}
}
}