]> git.pond.sub.org Git - empserver/blob - include/nat.h
(nxtitemp, trade_getitem, trade_desc, trade_check_item_ok, nxtitem,
[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
58 /*
59  * TODO
60  *
61  * One of (r_cnum, r_realm) and r_uid is redundant, provided MAXNOR is known.
62  *
63  * The only user of r_cnum and r_realm appears to be xdump.
64  * If we had working virtual selectors, we could remove r_cnum and r_realm.
65  */
66 struct realmstr {
67     /* initial part must match struct empobj */
68     short ef_type;
69     natid r_cnum;               /* country number */
70     /* end of part matching struct empobj */
71     short r_uid;                /* realm table index */
72     unsigned short r_realm;     /* realm number */
73     short r_xl, r_xh;           /* horizontal bounds */
74     short r_yl, r_yh;           /* vertical bounds */
75     time_t r_timestamp; /* Last time this realm was touched */
76 };
77
78 struct natstr {
79     /* initial part must match struct empobj */
80     short ef_type;
81     natid nat_cnum;             /* our country number */
82     /* end of part matching struct empobj */
83     nat_status nat_stat;
84     char nat_cnam[20];          /* country name */
85     char nat_pnam[20];          /* representative */
86     char nat_hostaddr[32];      /* host addr of last user */
87     char nat_hostname[512];     /* hostname of last user, may be empty */
88     char nat_userid[32];        /* userid of last user, may be empty */
89     coord nat_xcap, nat_ycap;   /* cap location in abs coords */
90     coord nat_xorg, nat_yorg;   /* origin location in abs coords */
91     signed char nat_dayno;      /* day of the year mod 128 */
92     signed char nat_update;     /* Want an update or not. */
93     unsigned char nat_missed;   /* How many updates missed */
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     long nat_reserve;           /* military reserves */
99     long nat_money;             /* moola */
100     time_t nat_last_login;      /* time of last login, 0 menas never */
101     time_t nat_last_logout;     /* time of last logout, 0 means never */
102     time_t nat_newstim;         /* date news last read */
103     time_t nat_annotim;         /* date annos last read */
104     float nat_level[4];         /* technology, etc */
105     unsigned char nat_relate[MAXNOC];
106     unsigned char nat_contact[MAXNOC];
107     unsigned char nat_rejects[MAXNOC];
108     long nat_flags;             /* nation flags */
109 };
110
111         /* Update fields. */
112 #define WUPD_WANT       bit(0)
113
114         /* nstat values */
115 #define VIS             bit(0)
116 #define SANCT           (bit(1) | VIS)
117 #define NORM            (bit(2) | VIS)
118 #define GOD             (bit(3) | NORM | VIS)
119 #define CAP             bit(6)
120 #define MONEY           bit(7)
121
122         /* nation relation codes */
123 #define AT_WAR          0
124 #define SITZKRIEG       1
125 #define MOBILIZATION    2
126 #define HOSTILE         3
127 #define NEUTRAL         4
128 #define FRIENDLY        5
129 #define ALLIED          6
130
131         /* nation reject codes */
132 #define REJ_TELE        bit(0)  /* dont allow telegrams to be sent */
133 #define REJ_TREA        bit(1)  /* dont allow treaties to be offered */
134 #define REJ_ANNO        bit(2)  /* don't receive announcements */
135 #define REJ_LOAN        bit(3)  /* don't allow loans to be offered */
136
137 #define NAT_TLEV        0
138 #define NAT_RLEV        1
139 #define NAT_ELEV        2
140 #define NAT_HLEV        3
141
142 /*
143  * Number of updates contact lasts for various ways of making contact.
144  * These are only useful with option LOSE_CONTACT option, which
145  * implies option HIDDEN.
146  */
147 /* Planes spotting and being spotted */
148 #define FOUND_FLY       3
149 /* Lookout */
150 #define FOUND_LOOK      5
151 /* Spies and ground combat */
152 #define FOUND_SPY       6
153 /* Communication */
154 #define FOUND_TELE      3
155 /* Coastwatch and skywatch */
156 #define FOUND_COAST     3
157
158 extern char *relates[];
159
160 /* procedures relating to nation stuff */
161
162 #define putnat(p) ef_write(EF_NATION, (p)->nat_cnum, (p))
163 #define getnatp(n) (struct natstr *)ef_ptr(EF_NATION, (n))
164
165 #define getrealm(r, n, p) ef_read(EF_REALM, ((r) + ((n) * MAXNOR)), (p))
166 #define putrealm(p) ef_write(EF_REALM, (p)->r_uid, (p))
167
168 extern double tfact(natid cn, double mult);
169 extern double techfact(int level, double mult);
170
171 extern char *cname(natid n);
172 extern char *relatename(struct natstr *np, natid other);
173 extern char *rejectname(struct natstr *np, natid other);
174 extern char *natstate(struct natstr *np);
175 extern int getrel(struct natstr *np, natid them);
176 extern int getrejects(natid them, struct natstr *np);
177 extern int getcontact(struct natstr *np, natid them);
178 extern void putrel(struct natstr *np, natid them, int relate);
179 extern void putreject(struct natstr *np, natid them, int how, int what);
180 extern void putcontact(struct natstr *np, natid them, int contact);
181 extern void agecontact(struct natstr *np);
182 extern int influx(struct natstr *np);
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