]> git.pond.sub.org Git - empserver/blob - src/lib/common/nat.c
Remove option SLOW_WAR
[empserver] / src / lib / common / nat.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2010, 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 files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future 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  *     Ron Koenderink, 2005
33  *     Markus Armbruster, 2006-2009
34  */
35
36 #include <config.h>
37
38 #include "file.h"
39 #include "misc.h"
40 #include "nat.h"
41 #include "sect.h"
42
43 char *relates[] = {
44     /* must follow nation relation defines in nat.h */
45     "At War", "Hostile", "Neutral", "Friendly", "Allied"
46 };
47
48 char *
49 cname(natid n)
50 {
51     struct natstr *np;
52
53     if (!(np = getnatp(n)))
54         return NULL;
55     return np->nat_cnam;
56 }
57
58 char *
59 relatename(struct natstr *np, natid other)
60 {
61     return relates[getrel(np, other)];
62 }
63
64 char *
65 rejectname(struct natstr *np, natid other)
66 {
67     static char *rejects[] = {
68         /* must follow reject flags defined in nat.h */
69         "  YES  YES  YES  YES",
70         "  NO   YES  YES  YES",
71         "  YES  NO   YES  YES",
72         "  NO   NO   YES  YES",
73         "  YES  YES  NO   YES",
74         "  NO   YES  NO   YES",
75         "  YES  NO   NO   YES",
76         "  NO   NO   NO   YES",
77         "  YES  YES  YES  NO ",
78         "  NO   YES  YES  NO ",
79         "  YES  NO   YES  NO ",
80         "  NO   NO   YES  NO ",
81         "  YES  YES  NO   NO ",
82         "  NO   YES  NO   NO ",
83         "  YES  NO   NO   NO ",
84         "  NO   NO   NO   NO "
85     };
86
87     return rejects[getrejects(other, np)];
88 }
89
90 char *
91 natstate(struct natstr *np)
92 {
93     static char *stnam[] = {
94         /* must match nat_status */
95         "FREE", "VISITOR", "VISITOR", "SANCTUARY", "ACTIVE", "DEITY"
96     };
97     return stnam[np->nat_stat];
98 }
99
100 /* This returns the relations that np has with them */
101 int
102 getrel(struct natstr *np, natid them)
103 {
104     return np->nat_relate[them];
105 }
106
107 int
108 getrejects(natid them, struct natstr *np)
109 {
110     return np->nat_rejects[them];
111 }
112
113 void
114 agecontact(struct natstr *np)
115 {
116     int them;
117
118     for (them = 1; them < MAXNOC; ++them) {
119         if (them != np->nat_cnum && np->nat_contact[them]) {
120             --np->nat_contact[them];
121         }
122     }
123 }
124
125 int
126 getcontact(struct natstr *np, natid them)
127 {
128     return np->nat_contact[them];
129 }
130
131 void
132 putrel(struct natstr *np, natid them, int relate)
133 {
134     np->nat_relate[them] = relate;
135 }
136
137 void
138 putreject(struct natstr *np, natid them, int how, int what)
139 {
140     if (how)
141         np->nat_rejects[them] |= what;
142     else
143         np->nat_rejects[them] &= ~what;
144 }
145
146 void
147 putcontact(struct natstr *np, natid them, int contact)
148 {
149     if (CANT_HAPPEN(contact < 0))
150         contact = 0;
151     if (CANT_HAPPEN(contact > 255))
152         contact = 255;
153
154     if (np->nat_contact[them] < contact)
155         np->nat_contact[them] = contact;
156 }
157
158 int
159 influx(struct natstr *np)
160 {
161     struct sctstr sect;
162
163     getsect(np->nat_xcap, np->nat_ycap, &sect);
164     if (sect.sct_own != np->nat_cnum ||
165         (sect.sct_type != SCT_CAPIT && sect.sct_type != SCT_MOUNT &&
166          sect.sct_type != SCT_SANCT) ||
167         (np->nat_flags & NF_SACKED))
168         return 1;
169     else
170         return 0;
171 }