/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
#define FERT_MAX 56
/* raise OIL_MAX for more oil */
-#define OIL_MAX 33
+#define OIL_MAX 33
/* lower IRON_MIN for more iron */
#define IRON_MIN 22
/* lower URAN_MIN for more uranium */
#define URAN_MIN 56
+#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
static char *program_name;
#define STABLE_CYCLE 4 /* stability required for perterbed capitals */
-#define INFINITY 999 /* a number which means "BIG" */
+#define INFINITY 999 /* a number which means "BIG" */
/* these defines prevent infinite loops:
*/
#define new_y(newy) (((newy) + WORLD_Y) % WORLD_Y)
#define rnd(x) (random() % (x))
-int secs; /* number of sectors grown */
-int ctot; /* total number of continents and islands grown */
-int *isecs; /* array of how large each island is */
+static int secs; /* number of sectors grown */
+static int ctot; /* total number of continents and islands grown */
+static int *isecs; /* array of how large each island is */
-int nc, sc, di, sp, pm, ni, is, id; /* the 8 arguments to this program */
-unsigned long rnd_seed; /* optional seed can be passed as an argument */
-int *capx, *capy; /* location of the nc capitals */
-int *mc, mcc; /* array and counter used for stability
+static int nc, sc, di, sp, pm, ni, is, id; /* the 8 args to this program */
+static unsigned long rnd_seed; /* optional seed argument */
+static int *capx, *capy; /* location of the nc capitals */
+static int *mc, mcc; /* array and counter used for stability
check when perturbing */
-int spike; /* are we spiking? */
-int mind; /* the final distance between capitals that
+static int spike; /* are we spiking? */
+static int mind; /* the final distance between capitals that
we achieved */
-int dirx[] = { -2, -1, 1, 2, 1, -1 }; /* gyujnb */
-int diry[] = { 0, -1, -1, 0, 1, 1 };
-
-int **own; /* owner of the sector. -1 means water */
-int **elev; /* elevation of the sectors */
-int **sectx, **secty; /* the sectors for each continent */
-int **sectc; /* which sectors are on the coast? */
-int *vector; /* used for measuring distances */
-int *weight; /* used for placing mountains */
-int *dsea, *dmoun; /* the dist to the ocean and mountain */
-int fl_status; /* is anything wrong? */
+static int dirx[] = { -2, -1, 1, 2, 1, -1 }; /* gyujnb */
+static int diry[] = { 0, -1, -1, 0, 1, 1 };
+
+static int **own; /* owner of the sector. -1 means water */
+static int **elev; /* elevation of the sectors */
+static int **sectx, **secty; /* the sectors for each continent */
+static int **sectc; /* which sectors are on the coast? */
+static int *vector; /* used for measuring distances */
+static int *weight; /* used for placing mountains */
+static int *dsea, *dmoun; /* the dist to the ocean and mountain */
+static int fl_status; /* is anything wrong? */
#define STATUS_NO_ROOM 1 /* there was no room to grow */
#define NUMTRIES 10 /* keep trying to grow this many times */
-const char *numletter =
+static const char *numletter =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
static void help(char *);
fprintf(stderr, "Can't chdir to %s (%s)\n", gamedir, strerror(errno));
exit(EXIT_FAILURE);
}
- if (!ef_open(EF_SECTOR, EFF_MEM | EFF_NOTIME, WORLD_SZ())) {
+ if (!ef_open(EF_SECTOR, EFF_MEM | EFF_NOTIME)) {
perror("ef_open");
exit(1);
}
exit(1);
}
if (nc * sc + nc * my_sqrt(sc) * 2 * (di + 1) > WORLD_X * WORLD_Y) {
- puts("fairland: error -- world not big enough to fit continents.");
- puts("arguments must satisfy:");
+ puts("fairland: warning -- world might be too small to fit continents.");
+ puts("arguments should satisfy:");
puts("nc*sc*sc + nc*sqrt(sc)*2*(di+1) < WORLD_X * WORLD_Y");
- exit(1);
}
}
return i;
i = (i + 1) % secs;
} while (i != starti);
- if (c < nc) {
- printf("fairland: BUG -- couldn't find coast for continent %c, sector %d.\nPlease mail stevens@math.utoronto.ca.\n",
- c + 'a', secs);
- exit(1);
- } else
- return -1;
+ assert(c >= nc);
+ return -1;
}
return -1;
}
}
}
if (AIRPORT_MARKER)
- printf("\n\nEach continent is marked by a \"*\" on the map (to distinguish them from\nthe islands). You can redesignate these airfields to wilderness sectors\none at a time, each time you add a new country to the game.\n");
+ printf("\n\nEach continent is marked by a \"*\" on the map (to distinguish them from\n"
+ "the islands). You can redesignate these airfields to wilderness sectors\n"
+ "one at a time, each time you add a new country to the game.\n");
}
static int
fprintf(script, "newcap %d %d,%d\n", c + 1, capx[c], capy[c]);
}
fprintf(script, "add %d visitor visitor v i\n", c + 1);
- ++c;
fclose(script);
return 0;
}
static void
-qprint(const char * const fmt, ...)
+qprint(const char *const fmt, ...)
{
va_list ap;