]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/finish.c
Fix trailing whitespace
[empserver] / src / lib / update / finish.c
index 28aab7b967e1d0f6fd26a5cf4baf6cdccb93024c..b8c8342c1b319199a458f986b54e018a02d8b79b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, 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
@@ -26,7 +26,7 @@
  *  ---
  *
  *  finish.c: Finish the update
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Thomas Ruschak, 1993
 
 #include <config.h>
 
+#include <stdlib.h>
 #include "distribute.h"
 #include "path.h"
 #include "update.h"
-#include <stdlib.h>
 
 /* Used for building up distribution info */
 struct distinfo {
@@ -77,20 +77,15 @@ finish_sects(int etu)
     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)));
+       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 */
@@ -130,7 +125,7 @@ finish_sects(int etu)
        if (np->nat_money < 0)
            continue;
        /* Get the pointer */
-       infptr = &g_distptrs[XYOFFSET(sp->sct_x, sp->sct_y)];
+       infptr = &g_distptrs[sp->sct_uid];
        dodistribute(sp, EXPORT,
                     infptr->path, infptr->imcost, infptr->excost);
     }
@@ -140,7 +135,7 @@ finish_sects(int etu)
     logerror("importing...");
     for (n = 0; NULL != (sp = getsectid(n)); n++) {
        /* Get the pointer (we do it first so we can free if needed) */
-       infptr = &g_distptrs[XYOFFSET(sp->sct_x, sp->sct_y)];
+       infptr = &g_distptrs[sp->sct_uid];
        if (sp->sct_type == SCT_WATER || sp->sct_own == 0) {
 #ifdef SAVE_FINISH_PATHS
            if (infptr->path)
@@ -184,7 +179,7 @@ assemble_dist_paths(struct distinfo *distptrs)
        if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y))
            continue;
        /* Set the pointer */
-       infptr = &distptrs[XYOFFSET(sp->sct_x, sp->sct_y)];
+       infptr = &distptrs[sp->sct_uid];
        /* now, get the dist sector */
        dist = getsectp(sp->sct_dist_x, sp->sct_dist_y);
        if (dist == NULL) {