]> git.pond.sub.org Git - empserver/blob - include/nat.h
Coding style fixes, mostly indentation and whitespace
[empserver] / include / nat.h
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.h: Definitions for things having to do with nations
29  *
30  *  Known contributors to this file:
31  *     Thomas Ruschak
32  *     Ken Stevens, 1995
33  *     Steve McClure, 1998-2000
34  *     Ron Koenderink, 2005-2008
35  *     Markus Armbruster, 2005-2008
36  */
37
38 #ifndef NAT_H
39 #define NAT_H
40
41 #include <time.h>
42 #include "types.h"
43
44 #define NATID_BAD 255
45
46 #define MAXNOR          50      /* max # realms */
47
48 /* Nation status */
49 enum nat_status {
50     /*
51      * Don't change order without checking inequality comparisons and
52      * array initializers!
53      */
54     STAT_UNUSED,                /* not in use */
55     STAT_NEW,                   /* just initialized */
56     STAT_VIS,                   /* visitor */
57     STAT_SANCT,                 /* still in sanctuary */
58     STAT_ACTIVE,                /* active (sanctuary broken) */
59     STAT_GOD                    /* deity powers */
60 };
61
62
63 /*
64  * TODO
65  *
66  * One of (r_cnum, r_realm) and r_uid is redundant, provided MAXNOR is known.
67  *
68  * The only user of r_cnum and r_realm appears to be xdump.
69  * If we had working virtual selectors, we could remove r_cnum and r_realm.
70  */
71 struct realmstr {
72     /* initial part must match struct empobj */
73     signed ef_type: 8;
74     unsigned r_seqno: 12;
75     unsigned r_generation: 12;
76     int r_uid;                  /* realm table index */
77     time_t r_timestamp;         /* Last time this realm was touched */
78     natid r_cnum;               /* country number */
79     /* end of part matching struct empobj */
80     unsigned short r_realm;     /* realm number */
81     coord r_xl, r_xh;           /* horizontal bounds */
82     coord r_yl, r_yh;           /* vertical bounds */
83 };
84
85 struct natstr {
86     /* initial part must match struct empobj */
87     signed ef_type: 8;
88     unsigned nat_seqno: 12;
89     unsigned nat_generation: 12;
90     int nat_uid;                /* equals nat_cnum */
91     time_t nat_timestamp;
92     natid nat_cnum;             /* our country number */
93     /* end of part matching struct empobj */
94     enum nat_status nat_stat;
95     char nat_cnam[20];          /* country name */
96     char nat_pnam[20];          /* representative */
97     char nat_hostaddr[32];      /* host addr of last user */
98     char nat_hostname[512];     /* hostname of last user, may be empty */
99     char nat_userid[32];        /* userid of last user, may be empty */
100     coord nat_xcap, nat_ycap;   /* cap location in abs coords */
101     coord nat_xorg, nat_yorg;   /* origin location in abs coords */
102     signed char nat_update;     /* Want an update or not. */
103     unsigned short nat_tgms;    /* # of telegrams to be announced */
104     unsigned short nat_ann;     /* # of annos pending */
105     int nat_timeused;           /* number of seconds used today */
106     short nat_btu;              /* bureaucratic time units */
107     short nat_access;           /* The tick when BTUs were last updated */
108     long nat_reserve;           /* military reserves */
109     long nat_money;             /* moola */
110     time_t nat_last_login;      /* time of last login, 0 menas never */
111     time_t nat_last_logout;     /* time of last logout, 0 means never */
112     time_t nat_newstim;         /* date news last read */
113     time_t nat_annotim;         /* date annos last read */
114     float nat_level[4];         /* technology, etc */
115     unsigned char nat_relate[MAXNOC];
116     unsigned char nat_contact[MAXNOC];
117     unsigned char nat_rejects[MAXNOC];
118     long nat_flags;             /* nation flags */
119 };
120
121         /* nation relation codes */
122 #define AT_WAR          0
123 #define SITZKRIEG       1
124 #define MOBILIZATION    2
125 #define HOSTILE         3
126 #define NEUTRAL         4
127 #define FRIENDLY        5
128 #define ALLIED          6
129
130         /* nation reject codes */
131 #define REJ_TELE        bit(0)  /* dont allow telegrams to be sent */
132 #define REJ_TREA        bit(1)  /* dont allow treaties to be offered */
133 #define REJ_ANNO        bit(2)  /* don't receive announcements */
134 #define REJ_LOAN        bit(3)  /* don't allow loans to be offered */
135
136 #define NAT_TLEV        0
137 #define NAT_RLEV        1
138 #define NAT_ELEV        2
139 #define NAT_HLEV        3
140
141 /*
142  * Number of updates contact lasts for various ways of making contact.
143  * These are only useful with option LOSE_CONTACT option, which
144  * implies option HIDDEN.
145  */
146 /* Planes spotting and being spotted */
147 #define FOUND_FLY       3
148 /* Lookout */
149 #define FOUND_LOOK      5
150 /* Spies and ground combat */
151 #define FOUND_SPY       6
152 /* Communication */
153 #define FOUND_TELE      3
154 /* Coastwatch and skywatch */
155 #define FOUND_COAST     3
156
157 extern char *relates[];
158
159 /* procedures relating to nation stuff */
160
161 #define putnat(p) ef_write(EF_NATION, (p)->nat_cnum, (p))
162 #define getnatp(n) ((struct natstr *)ef_ptr(EF_NATION, (n)))
163
164 #define getrealm(r, n, p) ef_read(EF_REALM, ((r) + ((n) * MAXNOR)), (p))
165 #define putrealm(p) ef_write(EF_REALM, (p)->r_uid, (p))
166
167 extern double tfact(natid cn, double mult);
168 extern double techfact(int level, double mult);
169
170 extern char *cname(natid n);
171 extern char *relatename(struct natstr *np, natid other);
172 extern char *rejectname(struct natstr *np, natid other);
173 extern char *natstate(struct natstr *np);
174 extern int getrel(struct natstr *np, natid them);
175 extern int getrejects(natid them, struct natstr *np);
176 extern int getcontact(struct natstr *np, natid them);
177 extern void putrel(struct natstr *np, natid them, int relate);
178 extern void putreject(struct natstr *np, natid them, int how, int what);
179 extern void putcontact(struct natstr *np, natid them, int contact);
180 extern void agecontact(struct natstr *np);
181 extern int influx(struct natstr *np);
182
183 extern struct natstr *nat_reset(struct natstr *, enum nat_status, coord, coord);
184 extern int check_nat_name(char *cname);
185
186 extern int grant_btus(struct natstr *, int);
187
188 /* nation flags */
189 #define NF_INFORM       bit(0)  /* Inform me of telegrams right away */
190 #define NF_FLASH        bit(1)  /* Allow other players to flash me (sicko :) */
191 #define NF_BEEP         bit(2)  /* Make beeping sounds when appropriate */
192 #define NF_COASTWATCH   bit(3)  /* Turn auto-coastwatch on */
193 #define NF_SONAR        bit(4)  /* Turn auto-sonar on */
194 #define NF_TECHLISTS    bit(5)  /* Sort lists by tech not type */
195 #define NF_SACKED       bit(6)  /* Capital was sacked, and hasn't been reset yet */
196
197 #endif