]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/supply.c
Update copyright notice
[empserver] / src / lib / subs / supply.c
index 66de35267ff51b14aadb9cb9844fb32d335f394e..2e55f26c35a34508eafa9b8ebbe87bff3a7cfbf4 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2016, 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 "path.h"
-#include "player.h"
 #include "prototypes.h"
 #include "sect.h"
 #include "ship.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(&sect);
@@ -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(&sect);
@@ -271,15 +263,12 @@ 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);
-               putsect(&sect);
+               if (n)
+                   putsect(&sect);
                put_empobj(sink->ef_type, sink->uid, sink);
            }
            return 1;
@@ -289,15 +278,12 @@ 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);
-               putsect(&sect);
+               if (n)
+                   putsect(&sect);
            }
        }
     }