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: Misc. accesses on the nation file
29 * Known contributors to this file:
31 * Ron Koenderink, 2005
32 * Markus Armbruster, 2006-2011
49 /* must follow nation relation defines in nat.h */
50 "At War", "Hostile", "Neutral", "Friendly", "Allied"
58 if (!(np = getnatp(n)))
64 relatename(struct natstr *np, natid other)
66 return relates[getrel(np, other)];
70 rejectname(struct natstr *np, natid other)
72 static char *rejects[] = {
73 /* must follow reject flags defined in nat.h */
92 return rejects[getrejects(other, np)];
96 natstate(struct natstr *np)
98 static char *stnam[] = {
99 /* must match nat_status */
100 "FREE", "VISITOR", "VISITOR", "SANCTUARY", "ACTIVE", "DEITY"
102 return stnam[np->nat_stat];
105 /* This returns the relations that np has with them */
107 getrel(struct natstr *np, natid them)
109 return np->nat_relate[them];
113 * Return relations US has with THEM.
114 * Countries are considered allied to themselves.
117 relations_with(natid us, natid them)
119 return us == them ? ALLIED : getrel(getnatp(us), them);
123 getrejects(natid them, struct natstr *np)
125 return np->nat_rejects[them];
129 agecontact(struct natstr *np)
133 for (them = 1; them < MAXNOC; ++them) {
134 if (them != np->nat_cnum && np->nat_contact[them]) {
135 --np->nat_contact[them];
141 getcontact(struct natstr *np, natid them)
143 return np->nat_contact[them];
147 putrel(struct natstr *np, natid them, int relate)
149 np->nat_relate[them] = relate;
153 putreject(struct natstr *np, natid them, int how, int what)
156 np->nat_rejects[them] |= what;
158 np->nat_rejects[them] &= ~what;
162 putcontact(struct natstr *np, natid them, int contact)
164 if (CANT_HAPPEN(contact < 0))
166 if (CANT_HAPPEN(contact > 255))
169 if (np->nat_contact[them] < contact)
170 np->nat_contact[them] = contact;
174 influx(struct natstr *np)
178 getsect(np->nat_xcap, np->nat_ycap, §);
179 if (sect.sct_own != np->nat_cnum ||
180 (sect.sct_type != SCT_CAPIT && sect.sct_type != SCT_MOUNT &&
181 sect.sct_type != SCT_SANCT) ||
182 (np->nat_flags & NF_SACKED))
189 * Initialize NATP for country #CNUM in status STAT.
190 * STAT must be STAT_UNUSED, STAT_NEW, STAT_VIS or STAT_GOD.
191 * Also wipe realms and telegrams.
194 nat_reset(struct natstr *natp, natid cnum, char *name, char *rep,
195 enum nat_status stat)
197 struct realmstr newrealm;
201 ef_blank(EF_NATION, cnum, natp);
202 natp->nat_stat = stat;
203 strncpy(natp->nat_cnam, name, sizeof(natp->nat_cnam) - 1);
204 strncpy(natp->nat_pnam, rep, sizeof(natp->nat_pnam) - 1);
205 if (stat == STAT_GOD)
206 natp->nat_money = 123456789;
207 for (i = 0; i < MAXNOR; i++) {
208 ef_blank(EF_REALM, i + cnum * MAXNOR, &newrealm);
211 close(creat(mailbox(buf, cnum),
212 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
213 /* FIXME natp->nat_ann = #annos */
214 natp->nat_level[NAT_HLEV] = start_happiness;
215 natp->nat_level[NAT_RLEV] = start_research;
216 natp->nat_level[NAT_TLEV] = start_technology;
217 natp->nat_level[NAT_ELEV] = start_education;
218 for (i = 0; i < MAXNOC; i++)
219 natp->nat_relate[i] = NEUTRAL;
221 NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS;