/*
* 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
* ---
*
* 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 {
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 */
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);
}
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)
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) {