2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, 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
45 /* must follow nation relation defines in nat.h */
46 "At War", "Hostile", "Neutral", "Friendly", "Allied"
54 if (!(np = getnatp(n)))
60 relatename(struct natstr *np, natid other)
62 return relates[getrel(np, other)];
66 natstate(struct natstr *np)
68 static char *stnam[] = {
69 /* must match nat_status */
70 "FREE", "VISITOR", "VISITOR", "SANCTUARY", "ACTIVE", "DEITY"
72 return stnam[np->nat_stat];
75 /* This returns the relations that np has with them */
77 getrel(struct natstr *np, natid them)
79 return np->nat_relate[them];
83 * Return relations @us has with @them.
84 * Countries are considered allied to themselves.
87 relations_with(natid us, natid them)
89 return us == them ? ALLIED : getrel(getnatp(us), them);
93 getrejects(natid them, struct natstr *np)
95 return np->nat_rejects[them];
99 agecontact(struct natstr *np)
103 for (them = 1; them < MAXNOC; ++them) {
104 if (them != np->nat_cnum && np->nat_contact[them]) {
105 --np->nat_contact[them];
111 in_contact(struct natstr *np, natid them)
113 return np->nat_contact[them];
117 putrel(struct natstr *np, natid them, int relate)
119 np->nat_relate[them] = relate;
123 putreject(struct natstr *np, natid them, int how, int what)
126 np->nat_rejects[them] |= what;
128 np->nat_rejects[them] &= ~what;
132 influx(struct natstr *np)
136 getsect(np->nat_xcap, np->nat_ycap, §);
137 if (sect.sct_own != np->nat_cnum ||
138 (sect.sct_type != SCT_CAPIT && sect.sct_type != SCT_MOUNT &&
139 sect.sct_type != SCT_SANCT) ||
140 (np->nat_flags & NF_SACKED))
147 * Initialize @natp for country #@cnum in status @stat.
148 * @stat must be STAT_UNUSED, STAT_NEW, STAT_VIS or STAT_GOD.
149 * Also wipe realms and telegrams.
152 nat_reset(struct natstr *natp, natid cnum, char *name, char *rep,
153 enum nat_status stat)
155 struct realmstr newrealm;
159 ef_blank(EF_NATION, cnum, natp);
160 natp->nat_stat = stat;
161 strncpy(natp->nat_cnam, name, sizeof(natp->nat_cnam) - 1);
162 strncpy(natp->nat_pnam, rep, sizeof(natp->nat_pnam) - 1);
163 if (stat == STAT_GOD)
164 natp->nat_money = 123456789;
165 for (i = 0; i < MAXNOR; i++) {
166 ef_blank(EF_REALM, i + cnum * MAXNOR, &newrealm);
169 mailbox_create(mailbox(buf, cnum));
170 /* FIXME natp->nat_ann = #annos */
171 natp->nat_level[NAT_HLEV] = start_happiness;
172 natp->nat_level[NAT_RLEV] = start_research;
173 natp->nat_level[NAT_TLEV] = start_technology;
174 natp->nat_level[NAT_ELEV] = start_education;
175 for (i = 0; i < MAXNOC; i++)
176 natp->nat_relate[i] = NEUTRAL;
178 NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS;