]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/nat.c
Use nat_reset() for POGO in files.c
[empserver] / src / lib / common / nat.c
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;
+}