]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/distribute.c
Merge dodistribute() parameters dist_i_cost, dist_e_cost
[empserver] / src / lib / update / distribute.c
index 91ae6b725e3e77b42960338479768a9fb4ac1ff2..ddc88bdd5a1b3efffb8145e84979e77d97936b05 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
 #include "prototypes.h"
 #include "update.h"
 
+#ifdef DISTRIBUTE_DEBUG
+#define DPRINTF(fmt, ...) ((void)printf(fmt , ## __VA_ARGS__))
+#else
+#define DPRINTF(fmt, ...) ((void)0)
+#endif
+
 #define EXPORT_BONUS 10.0
 #define IMPORT_BONUS 10.0
 
 int
-dodistribute(struct sctstr *sp, int imex, char *path, double dist_i_cost,
-            double dist_e_cost)
-         /* import or export? */
+dodistribute(struct sctstr *sp, int imex, double path_cost)
 {
     struct ichrstr *ip;
     struct sctstr *dist;
@@ -67,7 +71,7 @@ dodistribute(struct sctstr *sp, int imex, char *path, double dist_i_cost,
     if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y))
        return 0;
 
-    if (!path) {
+    if (path_cost < 0.0) {
        if (sp->sct_own != 0) {
            if (imex == EXPORT) /* only want this once */
                wu(0, sp->sct_own, "No path to dist sector for %s\n",
@@ -80,6 +84,10 @@ dodistribute(struct sctstr *sp, int imex, char *path, double dist_i_cost,
     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;
 
+    DPRINTF("distribute: %d,%d to %d,%d pathcost %g\n",
+           sp->sct_x, sp->sct_y, sp->sct_dist_x, sp->sct_dist_y,
+           path_cost);
+
     lplague = rplague = changed = 0;
     for (item = I_NONE + 1; item <= I_MAX; item++) {
        if (sp->sct_dist[item] == 0)
@@ -118,8 +126,10 @@ dodistribute(struct sctstr *sp, int imex, char *path, double dist_i_cost,
            if (dist->sct_mobil <= 0)
                continue;
            amt = diff;
-           if (item == I_CIVIL)
-               amt_dist--;     /* Don't send your last civ */
+           /* make sure not to abandon the sector */
+           if (item == I_CIVIL ||
+               (item == I_MILIT && dist->sct_item[I_CIVIL] == 0))
+               amt_dist--;
 
            if (amt_dist < amt) {
                amt = amt_dist;
@@ -127,7 +137,7 @@ dodistribute(struct sctstr *sp, int imex, char *path, double dist_i_cost,
                    continue;
            }
            pack = ip->i_pkg[dist_packing];
-           mcost = dist_i_cost / pack * ip->i_lbs / IMPORT_BONUS;
+           mcost = path_cost / pack * ip->i_lbs / IMPORT_BONUS;
            if (dist->sct_mobil < mcost * amt)
                amt = dist->sct_mobil / mcost;
 
@@ -158,7 +168,7 @@ dodistribute(struct sctstr *sp, int imex, char *path, double dist_i_cost,
            if (amt > amt_sect)
                amt = amt_sect;
            pack = MAX(ip->i_pkg[sect_packing], ip->i_pkg[dist_packing]);
-           mcost = dist_e_cost / pack * ip->i_lbs / EXPORT_BONUS;
+           mcost = path_cost / pack * ip->i_lbs / EXPORT_BONUS;
            if (sp->sct_mobil < mcost * amt)
                amt = sp->sct_mobil / mcost;
            if (amt > ITEM_MAX - amt_dist)