/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
*
* ---
*
- * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- * related information and legal notices. It is expected that any future
- * projects/authors will amend these files as needed.
+ * See files README, COPYING and CREDITS in the root of the source
+ * tree for related information and legal notices. It is expected
+ * that future projects/authors will amend these files as needed.
*
* ---
*
* Dave Pare, 1986
*/
-#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 "land.h"
-#include "nsc.h"
-#include "optlist.h"
-#include "commands.h"
+#include <config.h>
#include <fcntl.h>
+#if defined(_WIN32) && !defined(__GNUC__)
+#include <io.h>
+#endif
+#if !defined(_WIN32)
+#include <unistd.h>
+#endif
+#include "commands.h"
+#include "land.h"
+#include "optlist.h"
+#include "path.h"
+#include "prototypes.h"
+#include "tel.h"
static int isok(int x, int y);
-static void ok(s_char *map, 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 };
{
struct sctstr sect;
struct natstr *natp;
- struct boundstr newrealms;
+ struct realmstr newrealm;
struct range absrealm;
natid num;
coord x, y;
int i;
- s_char *p;
- int n;
- s_char buf[1024];
+ char *p;
+ char buf[1024];
+ time_t current_time = time(NULL);
natp = getnatp(player->cnum);
if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
pr("Must be at 0,0 to add a new country\n");
- return 0;
- }
- if ((n = natarg(player->argp[1], "Country? ")) < 0) {
- pr("Bad country number\n");
- return 0;
+ return RET_FAIL;
}
- num = n;
- natp = getnatp(num);
- if ((natp->nat_stat & STAT_NEW) == 0) {
+ if (!(natp = natargp(player->argp[1], "Country? ")))
+ return RET_SYN;
+ num = natp->nat_cnum;
+ if (natp->nat_stat != STAT_NEW) {
pr("Country #%d (%s) isn't a new country!\n", num, cname(num));
return RET_SYN;
}
if (player->aborted)
return RET_FAIL;
pr("added country %d at %s\n", num, xyas(x, y, player->cnum));
+ natp->nat_btu = max_btus;
+ natp->nat_stat = STAT_SANCT;
+ natp->nat_xcap = x;
+ natp->nat_ycap = y;
+ natp->nat_xorg = x;
+ natp->nat_yorg = y;
+ xyabsrange(natp, &defrealm, &absrealm);
+ for (i = 0; i < MAXNOR; i++) {
+ getrealm(i, num, &newrealm);
+ newrealm.r_xl = absrealm.lx;
+ newrealm.r_xh = absrealm.hx;
+ newrealm.r_yl = absrealm.ly;
+ newrealm.r_yh = absrealm.hy;
+ newrealm.r_timestamp = current_time;
+ putrealm(&newrealm);
+ }
+ if (players_at_00) {
+ natp->nat_xorg = 0;
+ natp->nat_yorg = 0;
+ }
+ natp->nat_money = start_cash;
+ 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;
+ natp->nat_tgms = 0;
+ (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
+ 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.sct_own = num;
+ 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;
- 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(§);
- getsect(x + 2, y, §);
- 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;
+ sect.sct_oldown = natp->nat_cnum;
if (at_least_one_100) {
sect.sct_oil = 100;
sect.sct_fertil = 100;
sect.sct_min = 100;
sect.sct_gmin = 100;
}
- sect.sct_item[I_CIVIL] = opt_RES_POP ? 550 : 999;
+ sect.sct_item[I_CIVIL] = max_pop(start_research, §);
sect.sct_item[I_MILIT] = 55;
- sect.sct_item[I_FOOD] = 100;
+ sect.sct_item[I_FOOD] = opt_NOFOOD ? 0 : 550;
sect.sct_item[I_UW] = 75;
putsect(§);
- natp->nat_btu = max_btus;
- natp->nat_stat &= ~STAT_NEW;
- natp->nat_stat |= STAT_SANCT;
- natp->nat_xstart = x;
- natp->nat_ystart = y;
- natp->nat_xcap = x;
- natp->nat_ycap = y;
- natp->nat_xorg = x;
- natp->nat_yorg = y;
- xyabsrange(natp, &defrealm, &absrealm);
- newrealms.b_xl = absrealm.lx;
- newrealms.b_xh = absrealm.hx;
- newrealms.b_yl = absrealm.ly;
- newrealms.b_yh = absrealm.hy;
- if (players_at_00) {
- natp->nat_xorg = 0;
- natp->nat_yorg = 0;
- }
- natp->nat_money = start_cash;
- 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 < MAXNOR; i++)
- natp->nat_b[i] = newrealms;
- natp->nat_tgms = 0;
- (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
- putnat(natp);
- return 0;
}
static int nmin, ngold, noil, nur;
static int
isok(int x, int y)
{
- s_char *map;
- s_char *p;
- s_char buf[1024];
+ signed char *map;
+ char *p;
+ char buf[1024];
nmin = ngold = noil = nur = 0;
navail = nfree = nowned = 0;
}
static void
-ok(s_char *map, int x, int y)
+ok(signed char *map, int x, int y)
{
struct sctstr sect;
int dir;