]> git.pond.sub.org Git - empserver/blobdiff - src/util/files.c
Fix trailing whitespace
[empserver] / src / util / files.c
index 01a44b151581d5f94715c404ae367328e9b107af..b68fc06b3d5b4d0e70576f9927c6d147bf71ea20 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2007, 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 @@
  *  ---
  *
  *  files.c: Create all the misc files
- * 
+ *
  *  Known contributors to this file:
  *     Thomas Ruschak
  *     Ken Stevens, 1995
 
 #include <config.h>
 
+#include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
-#include <errno.h>
-#if defined(_WIN32)
-#include <direct.h>
-#include <io.h>
-#include "../lib/gen/getopt.h"
-#else
 #include <unistd.h>
-#endif
-
 #include "file.h"
 #include "game.h"
 #include "land.h"
@@ -62,8 +55,7 @@
 #include "trade.h"
 #include "version.h"
 
-static void file_sct_init(coord, coord, struct sctstr *ptr,
-                         time_t timestamp);
+static void file_sct_init(coord, coord, struct sctstr *ptr);
 
 static void
 print_usage(char *program_name)
@@ -83,7 +75,7 @@ main(int argc, char *argv[])
     char buf[255];
     char *filename;
     int x, y;
-    struct gamestr *game;
+    struct gamestr game;
     struct natstr nat;
     struct realmstr realm;
     struct sctstr sct;
@@ -92,7 +84,6 @@ main(int argc, char *argv[])
     int opt;
     char *config_file = NULL;
     int force = 0;
-    time_t current_time = time(NULL);
 
     while ((opt = getopt(argc, argv, "e:fhv")) != EOF) {
        switch (opt) {
@@ -114,10 +105,10 @@ main(int argc, char *argv[])
        }
     }
 
+    empfile_init();
     if (emp_config(config_file) < 0)
        exit(1);
-
-    ef_init();
+    empfile_fixup();
 
     if (mkdir(gamedir, S_IRWXU | S_IRWXG) < 0 && errno != EEXIST) {
        perror(gamedir);
@@ -130,25 +121,25 @@ main(int argc, char *argv[])
     }
 
     if (!force) {
-       printf("WARNING: this blasts the existing game in %s (if any)\n",
+       printf("WARNING: this blasts the existing game in %s (if any)\n",
               gamedir);
-       printf("continue? ");
-       fgets(buf, sizeof(buf), stdin);
-       if (*buf != 'y' && *buf != 'Y')
-           exit(1);
+       printf("continue? ");
+       fgets(buf, sizeof(buf), stdin);
+       if (*buf != 'y' && *buf != 'Y')
+           exit(1);
     }
     for (i = 0; i < EF_MAX; i++) {
        if (!EF_IS_GAME_STATE(i))
            continue;
-       if (!ef_open(i, EFF_CREATE)) {
+       if (!ef_open(i, EFF_CREATE | EFF_NOTIME, -1)) {
            perror("ef_open");
            exit(1);
        }
     }
-    game = getgamep();
-    memset(game, 0, sizeof(*game));
-    game->ef_type = EF_GAME;
-    putgame();
+    memset(&game, 0, sizeof(game));
+    game.ef_type = EF_GAME;
+    game.game_turn = 1;
+    ef_write(EF_GAME, 0, &game);
     memset(&nat, 0, sizeof(nat));
     nat.ef_type = EF_NATION;
     strcpy(nat.nat_cnam, "POGO");
@@ -163,7 +154,8 @@ main(int argc, char *argv[])
     memset(&nat, 0, sizeof(nat));
     for (i = 1; i < MAXNOC; i++) {
        nat.ef_type = EF_NATION;
-       nat.nat_cnum = i;
+       nat.nat_cnum = nat.nat_uid = i;
+       nat.nat_seqno = 0;
        putnat((&nat));
     }
     memset(&realm, 0, sizeof(realm));
@@ -173,7 +165,7 @@ main(int argc, char *argv[])
        for (j = 0; j < MAXNOR; j++) {
            realm.r_realm = j;
            realm.r_uid = (i * MAXNOR) + j;
-           realm.r_timestamp = current_time;
+           realm.r_seqno = 0;
            putrealm(&realm);
        }
     }
@@ -186,18 +178,17 @@ main(int argc, char *argv[])
        filename = mailbox(buf, x);
        close(creat(filename, S_IRWUG));
     }
-    close(creat(timestampfil, S_IRWUG));
     close(creat(annfil, S_IRWUG));
 
     /* create a zero-filled sector file */
     memset(&sct, 0, sizeof(sct));
     for (y = 0; y < WORLD_Y; y++) {
        for (x = 0; x < WORLD_X / 2; x++) {
-           file_sct_init(x * 2 + (y & 1), y, &sct, current_time);
+           file_sct_init(x * 2 + (y & 1), y, &sct);
            putsect(&sct);
        }
     }
-    map = calloc(WORLD_X * WORLD_Y / 2, sizeof(*map));
+    map = calloc(WORLD_SZ(), sizeof(*map));
     for (i = 0; i < MAXNOC; i++) {
        ef_write(EF_MAP, i, map);
     }
@@ -214,16 +205,17 @@ main(int argc, char *argv[])
 }
 
 static void
-file_sct_init(coord x, coord y, struct sctstr *ptr, time_t timestamp)
+file_sct_init(coord x, coord y, struct sctstr *ptr)
 {
     struct sctstr *sp = (struct sctstr *)ptr;
 
     sp->ef_type = EF_SECTOR;
+    sp->sct_uid = XYOFFSET(x, y);
+    sp->sct_seqno = 0;
     sp->sct_x = x;
     sp->sct_y = y;
     sp->sct_dist_x = x;
     sp->sct_dist_y = y;
-    sp->sct_timestamp = timestamp;
     sp->sct_newtype = sp->sct_type = SCT_WATER;
     sp->sct_coastal = 1;
 }