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