2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * nat.c: Nation subroutines
29 * Known contributors to this file:
30 * Markus Armbruster, 2009
31 * Ron Koenderink, 2008-2009
45 #include "prototypes.h"
50 * Reset NATP for status STAT with origin/capital at X,Y.
51 * Wipes everything but nat_cnum, nat_cnam and nat_pnam.
52 * Also wipes realms and telegrams.
55 nat_reset(struct natstr *natp, enum nat_status stat, coord x, coord y)
57 static struct range defrealm = { -8, -5, 10, 5, 0, 0 };
58 struct realmstr newrealm;
59 struct range absrealm;
63 natp->nat_stat = stat;
64 *natp->nat_hostaddr = '\0';
65 *natp->nat_hostname = '\0';
66 *natp->nat_userid = '\0';
68 natp->nat_xcap = natp->nat_xorg = x;
69 natp->nat_ycap = natp->nat_yorg = y;
70 if (stat == STAT_SANCT)
71 xyabsrange(natp, &defrealm, &absrealm);
73 memset(&absrealm, 0, sizeof(absrealm));
74 for (i = 0; i < MAXNOR; i++) {
75 ef_blank(EF_REALM, i + natp->nat_cnum * MAXNOR, &newrealm);
76 newrealm.r_cnum = natp->nat_cnum;
78 newrealm.r_xl = absrealm.lx;
79 newrealm.r_xh = absrealm.hx;
80 newrealm.r_yl = absrealm.ly;
81 newrealm.r_yh = absrealm.hy;
89 natp->nat_timeused = 0;
93 close(creat(mailbox(buf, natp->nat_cnum),
94 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
95 natp->nat_ann = 0; /* FIXME number of annos */
97 natp->nat_btu = stat == STAT_SANCT ? max_btus : 0;
99 game_tick_to_now(&natp->nat_access);
100 natp->nat_reserve = 0;
101 natp->nat_money = stat == STAT_SANCT ? start_cash : 0;
102 natp->nat_last_login = natp->nat_last_logout = 0;
103 natp->nat_newstim = 0;
104 natp->nat_annotim = 0;
105 natp->nat_level[NAT_HLEV] = start_happiness;
106 natp->nat_level[NAT_RLEV] = start_research;
107 natp->nat_level[NAT_TLEV] = start_technology;
108 natp->nat_level[NAT_ELEV] = start_education;
109 for (i = 0; i < MAXNOC; i++)
110 natp->nat_relate[i] = NEUTRAL;
111 memset(natp->nat_contact, 0, sizeof(natp->nat_rejects));
112 memset(natp->nat_rejects, 0, sizeof(natp->nat_rejects));
114 NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS;
120 check_nat_name(char *cname)
127 if (strlen(cname) >= sizeof(natp->nat_cnam)) {
128 pr("Country name too long\n");
133 for (p = cname; *p != '\0'; p++) {
135 pr("No control characters allowed in country names!\n");
137 } else if (!isspace(*p))
141 pr("Country name can't be all blank\n");
145 for (cn = 0; NULL != (natp = getnatp(cn)); cn++) {
146 if (!strcmp(cname, natp->nat_cnam)) {
147 pr("Country #%d is already called `%s'\n", cn, cname);