]> git.pond.sub.org Git - empserver/commitdiff
Use nat_reset() for POGO in files.c
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Nov 2011 12:30:14 +0000 (13:30 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 29 Dec 2011 10:47:06 +0000 (11:47 +0100)
Requires moving it from subs/natsub.c to common/nat.c.

include/nat.h
src/lib/common/nat.c
src/lib/subs/natsub.c
src/util/files.c

index 2ca457d8c6ba0b4bfec2592fca4d73d9ae66933b..dd13f2321f64bacd2e0dbcb274186ef806e2d322 100644 (file)
@@ -177,8 +177,8 @@ extern void putreject(struct natstr *np, natid them, int how, int what);
 extern void putcontact(struct natstr *np, natid them, int contact);
 extern void agecontact(struct natstr *np);
 extern int influx(struct natstr *np);
-
 extern struct natstr *nat_reset(struct natstr *, natid, enum nat_status);
+
 extern int check_nat_name(char *, natid);
 
 extern int grant_btus(struct natstr *, int);
index 90953b411dce645715ff5853e9f6527dd9ee556e..f539b2d26cca41bb5771e3b0fd86b5c4d9651119 100644 (file)
 
 #include <config.h>
 
+#include <fcntl.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include "file.h"
 #include "misc.h"
 #include "nat.h"
+#include "optlist.h"
 #include "sect.h"
+#include "tel.h"
 
 char *relates[] = {
     /* must follow nation relation defines in nat.h */
@@ -178,3 +184,35 @@ influx(struct natstr *np)
     else
        return 0;
 }
+
+/*
+ * Initialize NATP for country #CNUM in status STAT.
+ * STAT must be STAT_UNUSED, STAT_NEW, STAT_VIS or STAT_GOD.
+ * Also wipe realms and telegrams.
+ */
+struct natstr *
+nat_reset(struct natstr *natp, natid cnum, enum nat_status stat)
+{
+    struct realmstr newrealm;
+    char buf[1024];
+    int i;
+
+    ef_blank(EF_NATION, cnum, natp);
+    natp->nat_stat = stat;
+    for (i = 0; i < MAXNOR; i++) {
+       ef_blank(EF_REALM, i + cnum * MAXNOR, &newrealm);
+       putrealm(&newrealm);
+    }
+    close(creat(mailbox(buf, cnum),
+               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
+    /* FIXME natp->nat_ann = #annos */
+    natp->nat_level[NAT_HLEV] = start_happiness;
+    natp->nat_level[NAT_RLEV] = start_research;
+    natp->nat_level[NAT_TLEV] = start_technology;
+    natp->nat_level[NAT_ELEV] = start_education;
+    for (i = 0; i < MAXNOC; i++)
+       natp->nat_relate[i] = NEUTRAL;
+    natp->nat_flags =
+       NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS;
+    return natp;
+}
index 1a365a9c83fe49c159c606e9008b6d08427a18f7..6379a64c1cd7f5b1537f0ade7896b97673413ee9 100644 (file)
 
 #include <config.h>
 
-#include <string.h>
 #include <ctype.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <unistd.h>
 #include "file.h"
 #include "nat.h"
-#include "optlist.h"
 #include "prototypes.h"
-#include "tel.h"
-
-/*
- * Initialize NATP for country #CNUM in status STAT.
- * STAT must be STAT_UNUSED, STAT_NEW, STAT_VIS or STAT_GOD.
- * Also wipe realms and telegrams.
- */
-struct natstr *
-nat_reset(struct natstr *natp, natid cnum, enum nat_status stat)
-{
-    struct realmstr newrealm;
-    char buf[1024];
-    int i;
-
-    ef_blank(EF_NATION, cnum, natp);
-    natp->nat_stat = stat;
-    for (i = 0; i < MAXNOR; i++) {
-       ef_blank(EF_REALM, i + cnum * MAXNOR, &newrealm);
-       putrealm(&newrealm);
-    }
-    close(creat(mailbox(buf, cnum),
-               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
-    /* FIXME natp->nat_ann = #annos */
-    natp->nat_level[NAT_HLEV] = start_happiness;
-    natp->nat_level[NAT_RLEV] = start_research;
-    natp->nat_level[NAT_TLEV] = start_technology;
-    natp->nat_level[NAT_ELEV] = start_education;
-    for (i = 0; i < MAXNOC; i++)
-       natp->nat_relate[i] = NEUTRAL;
-    natp->nat_flags =
-       NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS;
-    return natp;
-}
 
 int
 check_nat_name(char *cname, natid cnum)
index 35805235fecaf9f9e3f0e1324e83cc17b080e0ac..cd48915addabdb77c17dae0acc1ad4ecf1c5fa29 100644 (file)
@@ -135,16 +135,6 @@ main(int argc, char *argv[])
            exit(1);
     }
 
-    ef_read(EF_NATION, 0, &nat);
-    strcpy(nat.nat_cnam, "POGO");
-    strcpy(nat.nat_pnam, "peter");
-    nat.nat_stat = STAT_GOD;
-    nat.nat_btu = 255;
-    nat.nat_money = 123456789;
-    nat.nat_flags =
-       NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS;
-    ef_write(EF_NATION, 0, &nat);
-    printf("All praise to %s!\n", nat.nat_cnam);
     if (mkdir(teldir, S_IRWXU | S_IRWXG) < 0 && errno != EEXIST) {
        fprintf(stderr, "Can't make telegram directory %s (%s)\n",
                teldir, strerror(errno));
@@ -156,6 +146,14 @@ main(int argc, char *argv[])
     }
     close(creat(annfil, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
 
+    nat_reset(&nat, 0, STAT_GOD);
+    strcpy(nat.nat_cnam, "POGO");
+    strcpy(nat.nat_pnam, "peter");
+    nat.nat_btu = 255;
+    nat.nat_money = 123456789;
+    putnat(&nat);
+    printf("All praise to %s!\n", nat.nat_cnam);
+
     for (i = 0; i < EF_MAX; i++) {
        if (!EF_IS_GAME_STATE(i))
            continue;