]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/add.c
Update copyright notice
[empserver] / src / lib / commands / add.c
index 140a0901a159b95d5ad19578040e622d5664ac63..0a9a6337e156775b16cec51338de7baa6f7f2f3d 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-2009, 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 @@
  *  ---
  *
  *  add.c: Add a new country to the game
- * 
+ *
  *  Known contributors to this file:
  *     Steve McClure, 2000
  */
@@ -34,6 +34,9 @@
 #include <config.h>
 
 #include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
 #include "commands.h"
 #include "land.h"
 #include "optlist.h"
@@ -57,8 +60,6 @@ add(void)
     int stat;
     struct nstr_item ni;
     struct lndstr land;
-    struct realmstr realm;
-    time_t current_time = time(NULL);
 
     for (freecn = 0; NULL != (natp = getnatp(freecn)); freecn++) {
        if (natp->nat_stat == STAT_UNUSED)
@@ -83,12 +84,10 @@ add(void)
     }
     natp = getnatp(coun);
     p = getstarg(player->argp[2], "Country Name? ", buf);
-    if (p == 0 || *p == 0)
+    if (p ==0)
        return RET_SYN;
-    if (strlen(p) >= sizeof(cntryname)) {
-       pr("Country name too long\n");
+    if (!check_nat_name(p))
        return RET_FAIL;
-    }
     strcpy(cntryname, p);
     p = getstarg(player->argp[3], "Representative? ", buf);
     if (p == 0 || *p == 0)
@@ -134,7 +133,6 @@ add(void)
            putland(land.lnd_uid, &land);
        }
     }
-    natp->nat_stat = stat;
     strcpy(natp->nat_cnam, cntryname);
     strcpy(natp->nat_pnam, pname);
     if (*p != 'w' && *p != 'c') {
@@ -154,13 +152,8 @@ add(void)
                sect.sct_defense = 0;
                sect.sct_own = 0;
                sect.sct_oldown = 0;
-               if (sect.sct_type == SCT_BSPAN ||
-                   sect.sct_type == SCT_BTOWER)
-                   sect.sct_newtype = sect.sct_type = SCT_WATER;
-               else if (sect.sct_type != SCT_MOUNT &&
-                   sect.sct_type != SCT_PLAINS)
-                   sect.sct_newtype = sect.sct_type = SCT_RURAL;
-               /* No dist path */
+               sect.sct_newtype = sect.sct_type
+                   = dchr[sect.sct_type].d_terrain;
                sect.sct_dist_x = sect.sct_x;
                sect.sct_dist_y = sect.sct_y;
                memset(sect.sct_item, 0, sizeof(sect.sct_item));
@@ -180,43 +173,12 @@ add(void)
        }
     }
 
-    if (natp->nat_stat == STAT_NEW || natp->nat_stat == STAT_VIS) {
-       *natp->nat_hostaddr = '\0';
-       *natp->nat_hostname = '\0';
-       *natp->nat_userid = '\0';
-       natp->nat_btu = 0;
-       natp->nat_reserve = 0;
-       natp->nat_tgms = 0;
-       natp->nat_ycap = 0;
-       natp->nat_xcap = 0;
-       natp->nat_yorg = 0;
-       natp->nat_xorg = 0;
-       natp->nat_dayno = 0;
-       natp->nat_minused = 0;
-       for (i = 0; i < MAXNOR; i++) {
-           getrealm(i, coun, &realm);
-           realm.r_xl = realm.r_xh = realm.r_yl = realm.r_yh = 0;
-           realm.r_timestamp = current_time;
-           putrealm(&realm);
-       }
-       natp->nat_last_login = natp->nat_last_login = 0;
-       natp->nat_money = 0;
-       natp->nat_level[NAT_TLEV] = start_technology;
-       natp->nat_level[NAT_RLEV] = start_research;
-       natp->nat_level[NAT_ELEV] = start_education;
-       natp->nat_level[NAT_HLEV] = start_happiness;
-       for (i = 0; i < MAXNOC; i++)
-           natp->nat_rejects[i] = 0;
-       natp->nat_newstim = 0;
-       natp->nat_annotim = 0;
-       (void)creat(mailbox(buf, coun), 0660);
-    } else
+    if (stat == STAT_NEW || stat == STAT_VIS)
+       nat_reset(natp, stat, 0, 0);
+    else {
+       natp->nat_stat = stat;
        pr("No special initializations done...\n");
-
-    natp->nat_flags =
-       NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS;
-    for (i = 0; i < MAXNOC; i++)
-       natp->nat_relate[i] = NEUTRAL;
+    }
     putnat(natp);
     return 0;
 }