]> git.pond.sub.org Git - empserver/blob - include/nat.h
Doc fix.
[empserver] / include / nat.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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  */
35
36 #ifndef NAT_H
37 #define NAT_H
38
39 #include "sect.h"
40
41 #define MAXNOR          50      /* max # realms */
42
43 /* Nation status */
44 typedef enum {
45     /*
46      * Don't change order without checking inequality comparisons and
47      * array initializers!
48      */
49     STAT_UNUSED,                /* not in use */
50     STAT_NEW,                   /* just initialized */
51     STAT_VIS,                   /* visitor */
52     STAT_SANCT,                 /* still in sanctuary */
53     STAT_ACTIVE,                /* active (sanctuary broken) */
54     STAT_GOD                    /* deity powers */
55 } nat_status;
56
57 enum {                          /* Priorities */
58     /* sector types are also priorities */
59     PRI_SMAINT = SCT_MAXDEF+1,  /* ship maintenance */
60     PRI_PMAINT,                 /* plane maintenance */
61     PRI_LMAINT,                 /* land unit maintenance */
62     PRI_SBUILD,                 /* ship building */
63     PRI_PBUILD,                 /* plane building */
64     PRI_LBUILD,                 /* land building */
65     PRI_MAX = PRI_LBUILD
66 };
67
68
69 /*
70  * TODO
71  *
72  * One of (r_cnum, r_realm) and r_uid is redundant, provided MAXNOR is known.
73  *
74  * The only user of r_cnum and r_realm appears to be xdump.
75  * If we had working virtual selectors, we could remove r_cnum and r_realm.
76  *
77  */
78 struct realmstr {
79     /* initial part must match struct genitem */
80     short ef_type;
81     natid r_cnum;               /* country number */
82     /* end of part matching struct genitem */
83     short r_uid;                /* realm table index */
84     unsigned short r_realm;     /* realm number */
85     short r_xl, r_xh;           /* horizontal bounds */
86     short r_yl, r_yh;           /* vertical bounds */
87     time_t r_timestamp; /* Last time this realm was touched */
88 };
89
90 struct natstr {
91     /* initial part must match struct genitem */
92     short ef_type;
93     natid nat_cnum;             /* our country number */
94     /* end of part matching struct genitem */
95     nat_status nat_stat;
96     char nat_cnam[20];          /* country name */
97     char nat_pnam[20];          /* representative */
98     char nat_hostaddr[32];      /* host addr of last user */
99     char nat_hostname[512];     /* hostname of last user, may be empty */
100     char nat_userid[32];        /* userid of last user, may be empty */
101     coord nat_xcap, nat_ycap;   /* cap location in abs coords */
102     coord nat_xorg, nat_yorg;   /* origin location in abs coords */
103     signed char nat_dayno;      /* day of the year mod 128 */
104     signed char nat_update;     /* Want an update or not. */
105     unsigned char nat_missed;   /* How many updates missed */
106     unsigned short nat_tgms;    /* # of telegrams to be announced */
107     unsigned short nat_ann;     /* # of annos pending */
108     unsigned short nat_minused; /* number of minutes used today */
109     short nat_btu;              /* bureaucratic time units */
110     long nat_reserve;           /* military reserves */
111     long nat_money;             /* moola */
112     time_t nat_last_login;      /* time of last login, 0 menas never */
113     time_t nat_last_logout;     /* time of last logout, 0 means never */
114     time_t nat_newstim;         /* date news last read */
115     time_t nat_annotim;         /* date annos last read */
116     float nat_level[4];         /* technology, etc */
117     short nat_relate[MAXNOC];
118     unsigned char nat_contact[MAXNOC];
119     short nat_rejects[(MAXNOC + 3) / 4]; /* four bits for each country */
120     signed char nat_priorities[PRI_MAX+1]; /* budget priority */
121     long nat_flags;             /* nation flags */
122     char nat_spare[15];
123 };
124
125         /* Update fields. */
126 #define WUPD_WANT       bit(0)
127
128         /* nstat values */
129 #define VIS             bit(0)
130 #define SANCT           (bit(1) | VIS)
131 #define NORM            (bit(2) | VIS)
132 #define GOD             (bit(3) | NORM | VIS)
133 #define CAP             bit(6)
134 #define MONEY           bit(7)
135
136         /* nation relation codes */
137 #define AT_WAR          0
138 #define SITZKRIEG       1
139 #define MOBILIZATION    2
140 #define HOSTILE         3
141 #define NEUTRAL         4
142 #define FRIENDLY        5
143 #define ALLIED          6
144
145         /* nation reject codes */
146 #define REJ_TELE        bit(0)  /* dont allow telegrams to be sent */
147 #define REJ_TREA        bit(1)  /* dont allow treaties to be offered */
148 #define REJ_ANNO        bit(2)  /* don't receive announcements */
149 #define REJ_LOAN        bit(3)  /* don't allow loans to be offered */
150
151 #define NAT_TLEV        0
152 #define NAT_RLEV        1
153 #define NAT_ELEV        2
154 #define NAT_HLEV        3
155
156 /*
157  * Number of updates contact lasts for various ways of making contact.
158  * These are only useful with option LOSE_CONTACT option, which
159  * implies option HIDDEN.
160  */
161 /* Planes spotting and being spotted */
162 #define FOUND_FLY       3
163 /* Lookout */
164 #define FOUND_LOOK      5
165 /* Spies and ground combat */
166 #define FOUND_SPY       6
167 /* Communication */
168 #define FOUND_TELE      3
169 /* Coastwatch and skywatch */
170 #define FOUND_COAST     3
171
172 extern char *relates[];
173
174 /* procedures relating to nation stuff */
175
176 #define putnat(n) \
177         ef_write(EF_NATION, n->nat_cnum, n)
178 #define getnatp(n) \
179         (struct natstr *) ef_ptr(EF_NATION, (int)n)
180
181 #define putrealm(p) \
182         ef_write(EF_REALM, (int)(p)->r_uid, p)
183 #define getrealm(r, n, p) \
184         ef_read(EF_REALM, (int)(r + (n * MAXNOR)), p)
185
186 extern double tfact(natid cn, double mult);
187 extern double tfactfire(natid cn, double mult);
188 extern double techfact(int level, double mult);
189
190 extern char *cname(natid n);
191 extern char *relatename(struct natstr *np, natid other);
192 extern char *rejectname(struct natstr *np, natid other);
193 extern char *natstate(struct natstr *np);
194 extern int getrel(struct natstr *np, natid them);
195 extern int getrejects(natid them, struct natstr *np);
196 extern int getcontact(struct natstr *np, natid them);
197 extern void putrel(struct natstr *np, natid them, int relate);
198 extern void putreject(struct natstr *np, natid them, int how, int what);
199 extern void putcontact(struct natstr *np, natid them, int contact);
200 extern void agecontact(struct natstr *np);
201 extern int influx(struct natstr *np);
202
203 /* nation flags */
204 #define NF_INFORM       bit(0)  /* Inform me of telegrams right away */
205 #define NF_FLASH        bit(1)  /* Allow other players to flash me (sicko :) */
206 #define NF_BEEP         bit(2)  /* Make beeping sounds when appropriate */
207 #define NF_COASTWATCH   bit(3)  /* Turn auto-coastwatch on */
208 #define NF_SONAR        bit(4)  /* Turn auto-sonar on */
209 #define NF_TECHLISTS    bit(5)  /* Sort lists by tech not type */
210 #define NF_SACKED       bit(6)  /* Capital was sacked, and hasn't been reset yet */
211
212 #endif