]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/finish.c
Update copyright notice
[empserver] / src / lib / update / finish.c
index 19c4f44b936fe9a187b6b08929650a1a55b96825..0725602131d494df344173a2311bd2b3297bc99c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
 
 #include <config.h>
 
-#include "misc.h"
-#include "sect.h"
-#include "nat.h"
-#include "file.h"
-#include "xy.h"
-#include "path.h"
 #include "distribute.h"
+#include "path.h"
 #include "update.h"
-#include "common.h"
-#include "optlist.h"
+#include <stdlib.h>
 
 /* Used for building up distribution info */
 struct distinfo {
-    s_char *path;              /* path to take */
+    char *path;                        /* path to take */
     double imcost;             /* import cost */
     double excost;             /* export cost */
 };
@@ -56,7 +50,7 @@ struct distinfo {
 /* This is our global buffer of distribution pointers.  Note that
  * We only malloc this once, and never again (until reboot time
  * of course :) ) We do clear it each and every time. */
-struct distinfo *g_distptrs = (struct distinfo *)0;
+static struct distinfo *g_distptrs;
 
 /* Note that even though we malloc and save the path, it is never
  * used.  Thus, this option.  If you want to malloc and save every
@@ -66,11 +60,11 @@ struct distinfo *g_distptrs = (struct distinfo *)0;
 /* #define SAVE_FINISH_PATHS */
 
 #ifndef SAVE_FINISH_PATHS
-static s_char *finish_path = "h";      /* Placeholder indicating path exists */
+static char *finish_path = "h";        /* Placeholder indicating path exists */
 #endif /* SAVE_FINISH_PATHS */
 
 static void assemble_dist_paths(struct distinfo *distptrs);
-static s_char *ReversePath(s_char *path);
+static char *ReversePath(char *path);
 
 void
 finish_sects(int etu)
@@ -80,23 +74,18 @@ finish_sects(int etu)
     int n;
     struct distinfo *infptr;
 
-    if (g_distptrs == (struct distinfo *)0) {
+    if (g_distptrs == NULL) {
        logerror("First update since reboot, allocating buffer\n");
        /* Allocate the information buffer */
-       g_distptrs = (struct distinfo *)(malloc((WORLD_X * WORLD_Y) *
-                                               sizeof(struct distinfo)));
-       if (g_distptrs == (struct distinfo *)0) {
+       g_distptrs = malloc(WORLD_SZ() * sizeof(*g_distptrs));
+       if (g_distptrs == NULL) {
            logerror("malloc failed in finish_sects.\n");
            return;
        }
-
-       logerror("Allocated '%lu' bytes '%d' indices\n",
-                (unsigned long)(WORLD_X * WORLD_Y * sizeof(struct distinfo)),
-                WORLD_X * WORLD_Y);
     }
 
     /* Wipe it clean */
-    memset(g_distptrs, 0, ((WORLD_X * WORLD_Y) * sizeof(struct distinfo)));
+    memset(g_distptrs, 0, WORLD_SZ() * sizeof(*g_distptrs));
 
     logerror("delivering...\n");
     /* Do deliveries */
@@ -168,6 +157,8 @@ finish_sects(int etu)
        if (infptr->path)
            free(infptr->path);
 #endif /* SAVE_FINISH_PATHS */
+
+       sp->sct_off = 0;
     }
     logerror("done importing\n");
 
@@ -176,13 +167,13 @@ finish_sects(int etu)
 static void
 assemble_dist_paths(struct distinfo *distptrs)
 {
-    s_char *path, *p;
+    char *path, *p;
     double d;
     struct sctstr *sp;
     struct sctstr *dist;
     struct distinfo *infptr;
     int n;
-    s_char buf[512];
+    char buf[512];
 
     for (n = 0; NULL != (sp = getsectid(n)); n++) {
        if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y))
@@ -191,24 +182,25 @@ assemble_dist_paths(struct distinfo *distptrs)
        infptr = &distptrs[XYOFFSET(sp->sct_x, sp->sct_y)];
        /* now, get the dist sector */
        dist = getsectp(sp->sct_dist_x, sp->sct_dist_y);
-       if (dist == (struct sctstr *)0) {
-           logerror("Bad dist sect %d,%d for %d,%d !\n", sp->sct_dist_x,
-                    sp->sct_dist_y, sp->sct_x, sp->sct_y);
+       if (dist == NULL) {
+           logerror("Bad dist sect %d,%d for %d,%d !\n",
+                    sp->sct_dist_x, sp->sct_dist_y,
+                    sp->sct_x, sp->sct_y);
            continue;
        }
        /* Now, get the best distribution path over roads */
        /* Note we go from the dist center to the sector.  This gives
           us the import path for that sector. */
-       path = BestDistPath(buf, dist, sp, &d, MOB_ROAD);
+       path = BestDistPath(buf, dist, sp, &d);
 
        /* Now, we have a path */
-       if (path != (s_char *)0) {
+       if (path != NULL) {
 #ifdef SAVE_FINISH_PATHS
            int len;
            /* Here we malloc a buffer and save it */
            len = strlen(path);
            infptr->path = malloc(len);
-           if (infptr->path == (s_char *)0) {
+           if (infptr->path == NULL) {
                logerror("malloc failed in assemble_dist_path!\n");
                return;
            }
@@ -219,7 +211,7 @@ assemble_dist_paths(struct distinfo *distptrs)
            p = ReversePath(path);
            /* And walk the path back to the dist center to get the export
               cost */
-           infptr->excost = pathcost(sp, p, MOB_ROAD);
+           infptr->excost = pathcost(sp, p, MOB_MOVE);
 #ifdef SAVE_FINISH_PATHS
            memcpy(infptr->path, p, len);
 #else
@@ -229,19 +221,19 @@ assemble_dist_paths(struct distinfo *distptrs)
     }
 }
 
-static s_char *
-ReversePath(s_char *path)
+static char *
+ReversePath(char *path)
 {
-    s_char *patharray = "aucdefjhigklmyopqrstbvwxnz";
-    static s_char new_path[512];
+    char *patharray = "aucdefjhigklmyopqrstbvwxnz";
+    static char new_path[512];
     int ind;
 
-    if (path == (s_char *)0)
-       return (s_char *)0;
+    if (path == NULL)
+       return NULL;
 
     ind = strlen(path);
     if (ind == 0)
-       return (s_char *)0;
+       return NULL;
 
     if (path[ind - 1] == 'h')
        ind--;