]> git.pond.sub.org Git - empserver/blobdiff - src/util/fairland.c
Drop add's obscure sector check and wipe functionality
[empserver] / src / util / fairland.c
index 5536ddc2e0ccf9f312f2132fe310ae97f26416bc..87e14e6ff8bb42e47c4fb53387c030e92bb66fbd 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, 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,
@@ -14,8 +14,7 @@
  *  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/>.
  *
  *  ---
  *
@@ -55,7 +54,7 @@ static int quiet = 0;
 #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
@@ -66,6 +65,7 @@ static int quiet = 0;
 /* lower URAN_MIN for more uranium */
 #define URAN_MIN   56
 
+#include <assert.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -102,7 +102,7 @@ static int DISTINCT_ISLANDS = 1;
 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:
 */
@@ -152,7 +152,7 @@ static const char *numletter =
 static void help(char *);
 static void usage(void);
 static void parse_args(int argc, char *argv[]);
-static int allocate_memory(void);
+static void allocate_memory(void);
 static void init(void);
 static int drift(void);
 static void grow_continents(void);
@@ -227,8 +227,7 @@ main(int argc, char *argv[])
        exit(1);
     empfile_fixup();
 
-    if (allocate_memory() == -1)
-       exit(-1);
+    allocate_memory();
     print_vars();
 
     do {
@@ -261,14 +260,12 @@ main(int argc, char *argv[])
        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())) {
-       perror("ef_open");
+    if (!ef_open(EF_SECTOR, EFF_MEM | EFF_NOTIME))
        exit(1);
-    }
     write_sects();
     qprint("writing to sectors file...\n");
     if (!ef_close(EF_SECTOR))
-       exit(-1);
+       exit(1);
 
     output();
     qprint("\n\nA script for adding all the countries can be found in \"%s\".\n",
@@ -420,10 +417,9 @@ parse_args(int argc, char *argv[])
        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);
     }
 }
 
@@ -431,7 +427,7 @@ parse_args(int argc, char *argv[])
   VARIABLE INITIALIZATION
 ****************************************************************************/
 
-static int
+static void
 allocate_memory(void)
 {
     int i;
@@ -464,7 +460,6 @@ allocate_memory(void)
        sectc[i] = calloc(is * 2, sizeof(int));
     }
 
-    return 0;
 }
 
 static void
@@ -689,12 +684,8 @@ new_try(int c)
                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;
 }
@@ -1127,7 +1118,9 @@ output(void)
        }
     }
     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
@@ -1160,19 +1153,18 @@ write_newcap_script(void)
     }
 
     for (c = 0; c < nc; ++c) {
-       fprintf(script, "add %d %d %d n i\n", c + 1, c + 1, c + 1);
+       fprintf(script, "add %d %d %d n\n", c + 1, c + 1, c + 1);
        if (AIRPORT_MARKER)
            fprintf(script, "des %d,%d -\n", capx[c], capy[c]);
        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;
+    fprintf(script, "add %d visitor visitor v\n", c + 1);
     fclose(script);
     return 0;
 }
 
 static void
-qprint(const char * const fmt, ...)
+qprint(const char *const fmt, ...)
 {
     va_list ap;