1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  sect.h: Definitions for things having to do with sectors.
28  *
29  *  Known contributors to this file:
30  *     Dave Pare
31  *     Ken Stevens, 1995
32  *     Steve McClure, 1998
33  *     Markus Armbruster, 2004-2020
34  */
35 
36 
37 #ifndef SECT_H
38 #define SECT_H
39 
40 #include "file.h"
41 #include "item.h"
42 #include "types.h"
43 
44 struct sctstr {
45     /* initial part must match struct empobj */
46     signed ef_type: 8;
47     unsigned sct_seqno: 12;
48     unsigned sct_generation: 12;
49     int sct_uid;		/* equals XYOFFSET(sct_x, sct_y) */
50     time_t sct_timestamp;	/* Last time this sector was written to */
51     natid sct_own;		/* owner's country num */
52     coord sct_x;		/* x coord of sector */
53     coord sct_y;		/* y coord of sector */
54     signed char sct_type;	/* sector type */
55     signed char sct_effic;	/* 0% to 100% */
56     signed char sct_mobil;	/* mobility units */
57     unsigned char sct_off;	/* Should this sector produce? */
58     /* end of part matching struct empobj */
59     unsigned char sct_loyal;	/* updates until civilans "converted" */
60     unsigned char sct_terr;	/* territory 0 number */
61     unsigned char sct_terr1;	/* territory 1 number */
62     unsigned char sct_terr2;	/* territory 2 number */
63     unsigned char sct_terr3;	/* territory 3 number */
64     unsigned char sct_dterr;	/* deity's territory # */
65     coord sct_dist_x;		/* Dist sector */
66     coord sct_dist_y;
67     short sct_avail;		/* available workforce for "other things" */
68     short sct_flags;		/* temporary flags */
69     short sct_elev;		/* elevation/depth */
70     unsigned char sct_work;	/* pct of civ actually working */
71     unsigned char sct_coastal;	/* is this a coastal sector? */
72     signed char sct_newtype;	/* for changing designations */
73     unsigned char sct_min;	/* ease of mining ore */
74     unsigned char sct_gmin;	/* amount of gold ore */
75     unsigned char sct_fertil;	/* fertility of soil */
76     unsigned char sct_oil;	/* oil content */
77     unsigned char sct_uran;	/* uranium ore content */
78     natid sct_oldown;		/* old owner of sector (for liberation) */
79     unsigned char sct_updated;	/* Has this sect been updated? */
80     short sct_item[I_MAX+1];	/* amount of items stored here */
81     short sct_del[I_MAX+1];	/* delivieries */
82     short sct_dist[I_MAX+1];	/* distribution thresholds */
83     short sct_mines;		/* number of mines */
84     short sct_pstage;		/* plague stage */
85     short sct_ptime;		/* how many ETUs remain in this stage */
86     unsigned char sct_che;	/* number of guerrillas */
87     natid sct_che_target;	/* nation targeted by che */
88     unsigned short sct_fallout;
89     short sct_access;		/* Last tick mob was updated (MOB_ACCESS) */
90     unsigned char sct_road;	/* Road value of a sector */
91     unsigned char sct_rail;	/* Rail value of a sector */
92     unsigned char sct_defense;	/* Defensive value of a sector */
93 };
94 
95 enum d_navigation {
96     NAV_NONE,	/* ships can't navigate */
97     NAVOK,	/* ships can always navigate */
98     NAV_02,	/* requires 2% effic to navigate */
99     NAV_CANAL,	/* requires 2% effic to navigate and M_CANAL capability */
100     NAV_60	/* requires 60% effic to navigate */
101 };
102 
103 struct dchrstr {
104     unsigned char d_uid;
105     char d_mnem;		/* map symbol */
106     unsigned char d_terrain;	/* terrain sector type */
107     int d_prd;			/* product type */
108     int d_peffic;		/* process efficiency, in percent */
109     float d_mob0, d_mob1;	/* movement cost at 0 and 100% eff */
110     enum d_navigation d_nav;	/* navigation capability */
111     enum i_packing d_pkg;	/* type of packaging in these sects */
112     float d_ostr;		/* offensive strength */
113     float d_dstr;		/* defensive strength */
114     short d_mat[I_MAX+1];	/* materials to build 100% */
115 				/* only I_LCM and I_HCM non-zero */
116     int d_bwork;		/* work to build 100% */
117     int d_cost;			/* cost to build 100% */
118     int d_maint;		/* maintenance cost per ETU */
119     int d_maxpop;		/* maximum population */
120     int d_flags;		/* capability flags */
121     char *d_name;		/* full name of sector type */
122 };
123 
124 /* Sector capability flags */
125 #define D_DEITY		bit(0)	/* Only the deity can designate this */
126 
127 /* Sector types, must match sect.config */
128 #define SCT_WATER	0	/* basics */
129 #define SCT_MOUNT	1
130 #define SCT_SANCT	2
131 #define SCT_WASTE	3
132 #define SCT_RURAL	4
133 #define SCT_CAPIT	5
134 #define SCT_URAN	6
135 #define SCT_PARK	7
136 #define SCT_ARMSF	8	/* industries */
137 #define SCT_AMMOF	9
138 #define SCT_MINE	10
139 #define SCT_GMINE	11
140 #define SCT_HARBR	12
141 #define SCT_WAREH	13
142 #define SCT_AIRPT	14
143 #define SCT_AGRI	15
144 #define SCT_OIL		16
145 #define SCT_LIGHT	17
146 #define SCT_HEAVY	18
147 #define SCT_FORTR	19	/* military/scientific */
148 #define SCT_TECH	20
149 #define SCT_RSRCH	21
150 #define SCT_NUKE	22
151 #define SCT_LIBR	23
152 #define SCT_HIWAY	24	/* communications */
153 #define SCT_RADAR	25
154 #define SCT_HEADQ	26	/* headquarters */
155 #define SCT_BHEAD	27	/* Bridge head */
156 #define SCT_BSPAN	28	/* Bridge span */
157 #define SCT_BANK	29	/* financial */
158 #define SCT_REFINE	30	/* refinery */
159 #define SCT_ENLIST	31	/* enlistment center */
160 #define SCT_PLAINS	32	/* plains sector */
161 #define SCT_BTOWER	33	/* Bridge tower */
162 
163 #define getsect(x, y, p) ef_read(EF_SECTOR, sctoff((x), (y)), (p))
164 #define putsect(p) ef_write(EF_SECTOR, (p)->sct_uid, (p))
165 #define getsectp(x, y) ((struct sctstr *)ef_ptr(EF_SECTOR, sctoff((x), (y))))
166 #define getsectid(id) ((struct sctstr *)ef_ptr(EF_SECTOR, (id)))
167 
168 #define DCHR_SZ 64
169 extern struct dchrstr dchr[DCHR_SZ];
170 
171 #define IS_BIG_CITY(type) (dchr[(type)].d_pkg == UPKG)
172 
173 /* Minimal efficiency of sectors that can be knocked down (bridges) */
174 #define SCT_MINEFF 20
175 
176 /* Work required for building */
177 #define SCT_BLD_WORK(lcm, hcm) ((lcm) + 2 * (hcm))
178 
179 /* Return SP's defense efficiency */
180 #define SCT_DEFENSE(sp) \
181     (intrchr[INT_DEF].in_enable ? (sp)->sct_defense : (sp)->sct_effic)
182 
183 #define FORTEFF 5		/* forts must be 5% efficient to fire. */
184 
185 /* Can trains enter sector SP? */
186 #define SCT_HAS_RAIL(sp)					\
187     (opt_RAILWAYS ? sct_rail_track((sp)) != 0			\
188      : intrchr[INT_RAIL].in_enable && (sp)->sct_rail != 0)
189 
190 #define SCT_MINES_ARE_SEAMINES(sp) \
191     ((sp)->sct_type == SCT_WATER || (sp)->sct_type == SCT_BSPAN)
192 #define SCT_SEAMINES(sp) \
193     (SCT_MINES_ARE_SEAMINES((sp)) ? (sp)->sct_mines : 0)
194 #define SCT_LANDMINES(sp) \
195     (SCT_MINES_ARE_SEAMINES((sp)) ? 0 : (sp)->sct_mines)
196 
197 /* Sector infrastructure types, must match infra.config */
198 #define INT_ROAD	0
199 #define INT_RAIL	1
200 #define INT_DEF		2
201 
202 /* Sector flags */
203 #define MOVE_IN_PROGRESS	bit(0)	/* move in progress */
204 
205 /* maximum item amount, must fit into sct_item[], sct_del[], sct_dist[] */
206 #define ITEM_MAX 9999
207 /* maximum number of mines, must fit into struct sctstr member sct_mines */
208 #define MINES_MAX 32767
209 /* maximum number of che, must fit into struct sctstr member sct_che */
210 #define CHE_MAX 255
211 /* maximum fallout, must fit into struct sctstr member sct_fallout */
212 #define FALLOUT_MAX 9999
213 /* maximum territory, must fit into struct sctstr members sct_terr etc */
214 #define TERR_MAX 99
215 
216 /* Each cost is per point of efficency */
217 struct sctintrins {
218     char *in_name;
219     short in_mat[I_MAX+1];	/* materials to build 100% */
220 				/* non-zero only for I_LCM and I_HCM */
221     short in_bmobil;		/* mobility to build 100% */
222     int in_cost;		/* cost to build 100% */
223     unsigned char in_enable;	/* enabled iff non-zero */
224 };
225 
226 #define INTRCHR_SZ INT_DEF + 2
227 extern struct sctintrins intrchr[INTRCHR_SZ];
228 
229 extern int fort_fire(struct sctstr *);
230 extern int sct_rail_track(struct sctstr *);
231 
232 #endif
233