]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/deliver.c
Update copyright notice
[empserver] / src / lib / update / deliver.c
index cf93745fd53c334d4228c2364cc47a0a5bdfcea7..15986f323dd50131cd31099a56494718f2a7b3c3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  deliver.c: Deliver commodities to neighboring sector
- * 
+ *
  *  Known contributors to this file:
- *  
+ *
  */
 
-#include "misc.h"
-#include "var.h"
-#include "sect.h"
+#include <config.h>
+
 #include "item.h"
 #include "path.h"
-#include "file.h"
-#include "xy.h"
+#include "plague.h"
 #include "update.h"
-#include "subs.h"
-#include "common.h"
 
-int
-deliver(register struct sctstr *from, struct ichrstr *ip, int dir,
-       int thresh, int amt_src, int plague)
+#define DELIVER_BONUS 4.0
+
+static int
+deliver(struct sctstr *from, struct ichrstr *ip, int dir,
+       int thresh, int amt_src, int plague, enum i_packing packing)
 {
-    register struct sctstr *to;
-    int vtype;                 /* item vartype */
-    int pack_src;
+    struct sctstr *to;
+    i_type vtype;                      /* item vartype */
     int amt_moved;
     int amt_dst;
     int mobility;
-    float mcost;
+    double mcost;
     struct dchrstr *dp;
     int n;
 
@@ -77,22 +74,28 @@ deliver(register struct sctstr *from, struct ichrstr *ip, int dir,
        return 0;
     }
     dp = &dchr[from->sct_type];
-    vtype = ip->i_vtype;
-    pack_src = ip->i_pkg[dp->d_pkg];
+    vtype = ip->i_uid;
     mobility = from->sct_mobil / 2;
-    if (vtype == I_CIVIL && from->sct_own != from->sct_oldown) {
-       wu(0, from->sct_own,
-          "The conquered populace in %s refuses to relocate!\n",
-          ownxy(from));
-       return 0;
+    if (vtype == I_CIVIL) {
+       if (from->sct_own != from->sct_oldown) {
+           wu(0, from->sct_own,
+              "The conquered populace in %s refuses to relocate!\n",
+              ownxy(from));
+           return 0;
+       }
+       if (to->sct_own != to->sct_oldown) {
+           wu(0, from->sct_own,
+              "Citizens in %s refuse to relocate!\n", ownxy(from));
+           return 0;
+       }
     }
     /*
      * disallow delivery into prohibited sectors.
      * calculate unit movement cost; decrease amount if
      * there isn't enough mobility.
      */
-    mcost = sector_mcost(to, MOB_ROAD) * ip->i_lbs / pack_src;
-    mcost /= 4.0;
+    mcost = sector_mcost(to, MOB_MOVE) * ip->i_lbs / ip->i_pkg[packing];
+    mcost /= DELIVER_BONUS;
 
     if (mobility < mcost * amt_moved) {
        /* XXX can mcost be == 0? */
@@ -115,3 +118,32 @@ deliver(register struct sctstr *from, struct ichrstr *ip, int dir,
     from->sct_mobil = n;
     return amt_moved;
 }
+
+void
+dodeliver(struct sctstr *sp)
+{
+    i_type i;
+    int thresh;
+    int dir;
+    int plague;
+    enum i_packing packing;
+    int n;
+
+    if (sp->sct_mobil <= 0)
+       return;
+    plague = sp->sct_pstage;
+    packing = sp->sct_effic >= 60 ? dchr[sp->sct_type].d_pkg : IPKG;
+    for (i = I_NONE + 1; i <= I_MAX; i++) {
+       if (sp->sct_del[i] == 0)
+           continue;
+       thresh = sp->sct_del[i] & ~0x7;
+       dir = sp->sct_del[i] & 0x7;
+       n = deliver(sp, &ichr[i], dir, thresh, sp->sct_item[i],
+                   plague, packing);
+       if (n > 0) {
+           sp->sct_item[i] -= n;
+           if (sp->sct_mobil <= 0)
+               break;
+       }
+    }
+}