]> git.pond.sub.org Git - empserver/blob - src/lib/common/nat.c
(natstate): Add STAT_SANCT case so the nation report properly
[empserver] / src / lib / common / nat.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program 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 2 of the License, or
9  *  (at your option) any later version.
10  *
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.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  nat.c: Misc. accesses on the nation file
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1989
32  */
33
34 #include "prototypes.h"
35 #include "misc.h"
36 #include "nat.h"
37 #include "file.h"
38 #include "optlist.h"
39
40 s_char *relates[] = {
41     /* must follow nation relation defines in nat.h */
42     "At War", "Sitzkrieg", "Mobilizing", "Hostile", "Neutral", "Friendly",
43     "Allied"
44 };
45
46 s_char *
47 cname(natid n)
48 {
49     struct natstr *np;
50
51     if ((np = getnatp(n)) == 0)
52         return 0;
53     return np->nat_cnam;
54 }
55
56 s_char *
57 relatename(struct natstr *np, natid other)
58 {
59     return relates[getrel(np, other)];
60 }
61
62 s_char *
63 rejectname(struct natstr *np, natid other)
64 {
65     s_char *rejects[] = {
66         /* must follow reject flags defined in nat.h */
67         "  YES  YES  YES  YES",
68         "  NO   YES  YES  YES",
69         "  YES  NO   YES  YES",
70         "  NO   NO   YES  YES",
71         "  YES  YES  NO   YES",
72         "  NO   YES  NO   YES",
73         "  YES  NO   NO   YES",
74         "  NO   NO   NO   YES",
75         "  YES  YES  YES  NO ",
76         "  NO   YES  YES  NO ",
77         "  YES  NO   YES  NO ",
78         "  NO   NO   YES  NO ",
79         "  YES  YES  NO   NO ",
80         "  NO   YES  NO   NO ",
81         "  YES  NO   NO   NO ",
82         "  NO   NO   NO   NO "
83     };
84
85     return rejects[getrejects(other, np)];
86 }
87
88 s_char *
89 natstate(struct natstr *np)
90 {
91     if ((np->nat_stat & STAT_INUSE) == 0)
92         return "FREE";
93     if (np->nat_stat & STAT_GOD)
94         return "DEITY";
95     if (np->nat_stat & STAT_SANCT)
96         return "SANCTUARY";
97     if ((np->nat_stat & STAT_NORM) == 0)
98         return "VISITOR";
99     return "ACTIVE";
100 }
101
102 /* This returns the relations that np has with them */
103 int
104 getrel(struct natstr *np, natid them)
105 {
106     return np->nat_relate[them];
107 }
108
109 int
110 getrejects(natid them, struct natstr *np)
111 {
112     int ind;
113     int shift;
114     int reject;
115
116     ind = them / 4;
117     shift = 12 - ((them - ((them / 4) << 2)) * 4);
118     reject = (np->nat_rejects[ind] >> shift) & 0x0f;
119     return reject;
120 }
121
122 void
123 agecontact(struct natstr *np)
124 {
125     int them;
126
127     for (them = 1; them < MAXNOC; ++them) {
128         if (them != np->nat_cnum && np->nat_contact[them]) {
129             --np->nat_contact[them];
130         }
131     }
132 }
133
134 int
135 getcontact(struct natstr *np, natid them)
136 {
137     return np->nat_contact[them];
138 }
139
140 void
141 putrel(struct natstr *np, natid them, int relate)
142 {
143     np->nat_relate[them] = relate;
144 }
145
146 void
147 putreject(struct natstr *np, natid them, int how, int what)
148 {
149     int shift;
150     int newrej;
151     int ind;
152
153     what &= 0x0f;
154     ind = them / 4;
155     shift = 12 - ((them - ((them / 4) << 2)) * 4);
156     newrej = np->nat_rejects[ind];
157     if (how)
158         newrej |= (what << shift);
159     else
160         newrej &= ~(what << shift);
161     np->nat_rejects[ind] = newrej;
162 }
163
164 void
165 putcontact(struct natstr *np, natid them, int contact)
166 {
167     if (CANT_HAPPEN(contact < 0))
168         contact = 0;
169     if (CANT_HAPPEN(contact > 255))
170         contact = 255;
171
172     if (np->nat_contact[them] < contact)
173         np->nat_contact[them] = contact;
174 }
175
176 int
177 influx(struct natstr *np)
178 {
179     struct sctstr sect;
180
181     getsect(np->nat_xcap, np->nat_ycap, &sect);
182     if (sect.sct_own != np->nat_cnum ||
183         (sect.sct_type != SCT_CAPIT && sect.sct_type != SCT_MOUNT &&
184          sect.sct_type != SCT_SANCT) ||
185         (np->nat_flags & NF_SACKED))
186         return 1;
187     else
188         return 0;
189 }