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