]> git.pond.sub.org Git - empserver/blob - include/nat.h
ship: Unbreak MOB_ACCESS real-time mobility update for ships
[empserver] / include / nat.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
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.
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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
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.
24  *
25  *  ---
26  *
27  *  nat.h: Definitions for things having to do with nations
28  *
29  *  Known contributors to this file:
30  *     Thomas Ruschak
31  *     Ken Stevens, 1995
32  *     Steve McClure, 1998-2000
33  *     Ron Koenderink, 2005-2008
34  *     Markus Armbruster, 2005-2016
35  */
36
37 #ifndef NAT_H
38 #define NAT_H
39
40 #include "file.h"
41 #include "types.h"
42
43 #define NATID_BAD 255
44
45 #define MAXNOR          50      /* max # realms */
46
47 /* Nation status */
48 enum nat_status {
49     /*
50      * Don't change order without checking inequality comparisons and
51      * array initializers!
52      */
53     STAT_UNUSED,                /* not in use */
54     STAT_NEW,                   /* just initialized */
55     STAT_VIS,                   /* visitor */
56     STAT_SANCT,                 /* still in sanctuary */
57     STAT_ACTIVE,                /* active (sanctuary broken) */
58     STAT_GOD                    /* deity powers */
59 };
60
61
62 /*
63  * TODO
64  *
65  * One of (r_cnum, r_realm) and r_uid is redundant, provided MAXNOR is known.
66  *
67  * The only user of r_cnum and r_realm appears to be xdump.
68  * If we had working virtual selectors, we could remove r_cnum and r_realm.
69  */
70 struct realmstr {
71     /* initial part must match struct empobj */
72     signed ef_type: 8;
73     unsigned r_seqno: 12;
74     unsigned r_generation: 12;
75     int r_uid;                  /* realm table index */
76     time_t r_timestamp;         /* Last time this realm was touched */
77     natid r_cnum;               /* country number */
78     /* end of part matching struct empobj */
79     unsigned short r_realm;     /* realm number */
80     coord r_xl, r_xh;           /* horizontal bounds */
81     coord r_yl, r_yh;           /* vertical bounds */
82 };
83
84 struct natstr {
85     /* initial part must match struct empobj */
86     signed ef_type: 8;
87     unsigned nat_seqno: 12;
88     unsigned nat_generation: 12;
89     int nat_uid;                /* equals nat_cnum */
90     time_t nat_timestamp;
91     natid nat_cnum;             /* our country number */
92     /* end of part matching struct empobj */
93     enum nat_status nat_stat;
94     int nat_flags;              /* nation flags */
95     char nat_cnam[20];          /* country name */
96     char nat_pnam[20];          /* representative */
97     char nat_hostaddr[46];      /* host addr of last user */
98     char nat_userid[32];        /* userid of last user, may be empty */
99     coord nat_xcap, nat_ycap;   /* cap location in abs coords */
100     coord nat_xorg, nat_yorg;   /* origin location in abs coords */
101     signed char nat_update;     /* Want an update or not. */
102     unsigned short nat_tgms;    /* # of telegrams to be announced */
103     unsigned short nat_ann;     /* # of annos pending */
104     int nat_timeused;           /* number of seconds used today */
105     short nat_btu;              /* bureaucratic time units */
106     short nat_access;           /* The tick when BTUs were last updated */
107     int nat_reserve;            /* military reserves */
108     int nat_money;              /* moola */
109     time_t nat_last_login;      /* time of last login, 0 menas never */
110     time_t nat_last_logout;     /* time of last logout, 0 means never */
111     time_t nat_newstim;         /* date news last read */
112     time_t nat_annotim;         /* date annos last read */
113     float nat_level[4];         /* technology, etc */
114 };
115
116 #define NAT_TLEV        0
117 #define NAT_RLEV        1
118 #define NAT_ELEV        2
119 #define NAT_HLEV        3
120
121 /* Diplomatic relations */
122 enum relations {
123     /*
124      * Don't change order without checking inequality comparisons and
125      * array initializers!
126      */
127     AT_WAR,
128     HOSTILE,
129     NEUTRAL,
130     FRIENDLY,
131     ALLIED
132 };
133
134 struct relatstr {
135     /* initial part must match struct empobj */
136     signed ef_type: 8;
137     unsigned rel_seqno: 12;
138     unsigned rel_generation: 12;
139     int rel_uid;
140     time_t rel_timestamp;
141     /* end of part matching struct empobj */
142     unsigned char rel_relate[MAXNOC]; /* enum relations */
143 };
144
145 /*
146  * Number of updates contact lasts for various ways of making contact.
147  * These are only useful with option LOSE_CONTACT, which implies
148  * option HIDDEN.
149  */
150 /* Planes spotting and being spotted */
151 #define FOUND_FLY       3
152 /* Lookout */
153 #define FOUND_LOOK      5
154 /* Spies and ground combat */
155 #define FOUND_SPY       6
156 /* Communication */
157 #define FOUND_TELE      3
158 /* Coastwatch and skywatch */
159 #define FOUND_COAST     3
160
161 struct contactstr {
162     /* initial part must match struct empobj */
163     signed ef_type: 8;
164     unsigned con_seqno: 12;
165     unsigned con_generation: 12;
166     int con_uid;
167     time_t con_timestamp;
168     /* end of part matching struct empobj */
169     unsigned char con_contact[MAXNOC];
170 };
171
172 /* Kinds of communication players can reject */
173 enum rej_comm {
174     REJ_TELE,                   /* dont allow telegrams to be sent */
175     REJ_ANNO,                   /* don't receive announcements */
176     REJ_LOAN                    /* don't allow loans to be offered */
177 };
178
179 struct rejectstr {
180     /* initial part must match struct empobj */
181     signed ef_type: 8;
182     unsigned rej_seqno: 12;
183     unsigned rej_generation: 12;
184     int rej_uid;
185     time_t rej_timestamp;
186     /* end of part matching struct empobj */
187     unsigned char rej_rejects[MAXNOC];
188 };
189
190 /* procedures relating to nation stuff */
191
192 #define putnat(p) ef_write(EF_NATION, (p)->nat_cnum, (p))
193 #define getnatp(n) ((struct natstr *)ef_ptr(EF_NATION, (n)))
194
195 #define getrelat(n, p) ef_read(EF_RELAT, (n), (p))
196 #define putrelat(p) ef_write(EF_RELAT, (p)->rel_uid, (p))
197 #define getrelatp(n) ((struct relatstr *)ef_ptr(EF_RELAT, (n)))
198
199 #define getcontact(n, p) ef_read(EF_CONTACT, (n), (p))
200 #define putcontact(p) ef_write(EF_CONTACT, (p)->con_uid, (p))
201 #define getcontactp(n) ((struct contactstr *)ef_ptr(EF_CONTACT, (n)))
202
203 #define getreject(n, p) ef_read(EF_REJECT, (n), (p))
204 #define putreject(p) ef_write(EF_REJECT, (p)->rej_uid, (p))
205 #define getrejectp(n) ((struct rejectstr *)ef_ptr(EF_REJECT, (n)))
206
207 #define getrealm(r, n, p) ef_read(EF_REALM, ((r) + ((n) * MAXNOR)), (p))
208 #define putrealm(p) ef_write(EF_REALM, (p)->r_uid, (p))
209
210 /* src/lib/common/tfact.c */
211 extern double tfact(natid cn, double mult);
212 extern double techfact(int level, double mult);
213
214 /* src/lib/common/nat.c */
215 extern char *cname(natid n);
216 extern char *natstate(struct natstr *np);
217 extern enum relations relations_with(natid, natid);
218 extern char *relations_string(enum relations);
219 extern int nat_accepts(natid, natid, enum rej_comm);
220 extern int in_contact(natid, natid);
221 extern void agecontact(struct natstr *np);
222 extern int influx(struct natstr *np);
223 extern void nat_reset(natid, char *, char *, enum nat_status);
224
225 /* src/lib/subs/natsub.c */
226 extern int check_nat_name(char *, natid);
227 extern char *prnat(struct natstr *);
228 extern char *prnatid(natid);
229
230 /* src/lib/common/btu.c */
231 extern int grant_btus(struct natstr *, int);
232
233 /* src/lib/subs/rej.c */
234 extern void setrel(natid, natid, enum relations);
235 extern void setcont(natid, natid, int);
236 extern void setrej(natid, natid, int, enum rej_comm);
237
238 /* nation flags */
239 #define NF_INFORM       bit(0)  /* Inform me of telegrams right away */
240 #define NF_FLASH        bit(1)  /* Allow other players to flash me (sicko :) */
241 #define NF_BEEP         bit(2)  /* Make beeping sounds when appropriate */
242 #define NF_COASTWATCH   bit(3)  /* Turn auto-coastwatch on */
243 #define NF_SONAR        bit(4)  /* Turn auto-sonar on */
244 #define NF_TECHLISTS    bit(5)  /* Sort lists by tech not type */
245 #define NF_SACKED       bit(6)  /* Capital was sacked, and hasn't been reset yet */
246
247 #endif