]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/new.c
Consider only wilderness for randomly placed sanctuaries
[empserver] / src / lib / commands / new.c
index 29cc0bc1740327332218afb1056b94e49f02178a..aef15eb3057bfc19de14a2ef7d27f9d0db2b2193 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, 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
 
 #include <config.h>
 
-#include "misc.h"
-#include "player.h"
-#include "nat.h"
-#include "sect.h"
-#include "path.h"
-#include "file.h"
-#include "xy.h"
-#include "tel.h"
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include "commands.h"
 #include "land.h"
-#include "nsc.h"
 #include "optlist.h"
-#include "commands.h"
-
-#include <fcntl.h>
+#include "path.h"
+#include "prototypes.h"
+#include "tel.h"
 
 static int isok(int x, int y);
 static void ok(signed char *map, int x, int y);
+static void init_sanct(struct natstr *, coord, coord);
 
 static struct range defrealm = { -8, -5, 10, 5, 0, 0 };
 
@@ -109,10 +105,10 @@ new(void)
             * another place on the map.
             */
            getsect(x, y, &sect);
-           if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
+           if (sect.sct_type != SCT_RURAL || sect.sct_own != 0)
                continue;
            getsect(x + 2, y, &sect);
-           if (sect.sct_type == SCT_WATER || sect.sct_own != 0)
+           if (sect.sct_type != SCT_RURAL || sect.sct_own != 0)
                continue;
            if (isok(x, y))
                break;
@@ -126,56 +122,6 @@ new(void)
     if (player->aborted)
        return RET_FAIL;
     pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
-    getsect(x, y, &sect);
-    sect.sct_own = num;
-    sect.sct_type = SCT_SANCT;
-    sect.sct_newtype = SCT_SANCT;
-    sect.sct_effic = 100;
-    sect.sct_road = 0;
-    sect.sct_rail = 0;
-    sect.sct_defense = 0;
-    if (!opt_DEFENSE_INFRA)
-       sect.sct_defense = sect.sct_effic;
-    sect.sct_mobil = startmob;
-    sect.sct_work = 100;
-    sect.sct_oldown = num;
-    if (at_least_one_100) {
-       sect.sct_oil = 100;
-       sect.sct_fertil = 100;
-       sect.sct_uran = 100;
-       sect.sct_min = 100;
-       sect.sct_gmin = 100;
-    }
-    sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
-    sect.sct_item[I_MILIT] = 55;
-    sect.sct_item[I_FOOD] = 1000;
-    sect.sct_item[I_UW] = 75;
-    putsect(&sect);
-    getsect(x + 2, y, &sect);
-    sect.sct_own = num;
-    sect.sct_type = SCT_SANCT;
-    sect.sct_newtype = SCT_SANCT;
-    sect.sct_effic = 100;
-    sect.sct_road = 0;
-    sect.sct_rail = 0;
-    sect.sct_defense = 0;
-    if (!opt_DEFENSE_INFRA)
-       sect.sct_defense = sect.sct_effic;
-    sect.sct_work = 100;
-    sect.sct_oldown = num;
-    sect.sct_mobil = startmob;
-    if (at_least_one_100) {
-       sect.sct_oil = 100;
-       sect.sct_fertil = 100;
-       sect.sct_uran = 100;
-       sect.sct_min = 100;
-       sect.sct_gmin = 100;
-    }
-    sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
-    sect.sct_item[I_MILIT] = 55;
-    sect.sct_item[I_FOOD] = 100;
-    sect.sct_item[I_UW] = 75;
-    putsect(&sect);
     natp->nat_btu = max_btus;
     natp->nat_stat = STAT_SANCT;
     natp->nat_xcap = x;
@@ -202,11 +148,43 @@ new(void)
     natp->nat_level[NAT_TLEV] = start_technology;
     natp->nat_level[NAT_ELEV] = start_education;
     natp->nat_tgms = 0;
-    (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
+    close(creat(mailbox(buf, num), S_IRWUG));
+    init_sanct(natp, x, y);
+    init_sanct(natp, x + 2, y);
     putnat(natp);
     return RET_OK;
 }
 
+static void
+init_sanct(struct natstr *natp, coord x, coord y)
+{
+    struct sctstr sect;
+
+    getsect(x, y, &sect);
+    sect.sct_own = natp->nat_cnum;
+    sect.sct_type = SCT_SANCT;
+    sect.sct_newtype = SCT_SANCT;
+    sect.sct_effic = 100;
+    sect.sct_road = 0;
+    sect.sct_rail = 0;
+    sect.sct_defense = 0;
+    sect.sct_mobil = startmob;
+    sect.sct_work = 100;
+    sect.sct_oldown = natp->nat_cnum;
+    if (at_least_one_100) {
+       sect.sct_oil = 100;
+       sect.sct_fertil = 100;
+       sect.sct_uran = 100;
+       sect.sct_min = 100;
+       sect.sct_gmin = 100;
+    }
+    sect.sct_item[I_CIVIL] = max_pop(start_research, &sect);
+    sect.sct_item[I_MILIT] = 55;
+    sect.sct_item[I_FOOD] = opt_NOFOOD ? 0 : 550;
+    sect.sct_item[I_UW] = 75;
+    putsect(&sect);
+}
+
 static int nmin, ngold, noil, nur;
 static int nfree, navail, nowned;
 
@@ -219,12 +197,12 @@ isok(int x, int y)
 
     nmin = ngold = noil = nur = 0;
     navail = nfree = nowned = 0;
-    if ((map = malloc((WORLD_X * WORLD_Y) / 2)) == 0) {
+    if (!(map = malloc(WORLD_SZ()))) {
        logerror("malloc failed in isok\n");
        pr("Memory error.  Tell the deity.\n");
        return 0;
     }
-    memset(map, 0, (WORLD_X * WORLD_Y) / 2);
+    memset(map, 0, WORLD_SZ());
     ok(map, x, y);
     free(map);
     if (nfree < 5)