]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/distribute.c
Update copyright notice
[empserver] / src / lib / update / distribute.c
index ddc88bdd5a1b3efffb8145e84979e77d97936b05..81d946570f156d9ff93a607b262919aa0f403dce 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
@@ -30,6 +29,7 @@
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Steve McClure, 1998
+ *     Markus Armbruster, 2004-2011
  */
 
 #include <config.h>
@@ -51,8 +51,9 @@
 #define IMPORT_BONUS 10.0
 
 int
-dodistribute(struct sctstr *sp, int imex, double path_cost)
+dodistribute(struct sctstr *sp, int imex, double import_cost)
 {
+    double path_cost, dcc;
     struct ichrstr *ip;
     struct sctstr *dist;
     int amt;
@@ -68,19 +69,23 @@ dodistribute(struct sctstr *sp, int imex, double path_cost)
     int rplague;
     int lplague;
 
-    if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y))
+    if (imex == IMPORT && import_cost < 0.0)
        return 0;
 
-    if (path_cost < 0.0) {
-       if (sp->sct_own != 0) {
-           if (imex == EXPORT) /* only want this once */
+    dist = getsectp(sp->sct_dist_x, sp->sct_dist_y);
+    if (imex == IMPORT)
+       path_cost = import_cost;
+    else {
+       dcc = sector_mcost(dist, MOB_MOVE);
+       if (import_cost < 0.0 || dcc < 0.0) {
+           if (sp->sct_own && sp->sct_uid != dist->sct_uid)
                wu(0, sp->sct_own, "No path to dist sector for %s\n",
                   ownxy(sp));
+           return 0;
        }
-       return 0;
+       path_cost = import_cost - sector_mcost(sp, MOB_MOVE) + dcc;
     }
 
-    dist = getsectp(sp->sct_dist_x, sp->sct_dist_y);
     dist_packing = dist->sct_effic >= 60 ? dchr[dist->sct_type].d_pkg : IPKG;
     sect_packing = sp->sct_effic   >= 60 ? dchr[sp->sct_type].d_pkg : IPKG;