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  *  land.h: Definitions for land units
28  *
29  *  Known contributors to this file:
30  *     Thomas Ruschak, 1992
31  *     Ken Stevens, 1995
32  *     Steve McClure, 1998
33  *     Markus Armbruster, 2004-2020
34  */
35 
36 #ifndef LAND_H
37 #define LAND_H
38 
39 #include "file.h"
40 #include "item.h"
41 #include "retreat.h"
42 #include "types.h"
43 
44 #define LAND_MINEFF	10
45 #define LAND_MINFIREEFF 40	/* arty must be this effic to fire */
46 
47 struct lndstr {
48     /* initial part must match struct empobj */
49     signed ef_type: 8;
50     unsigned lnd_seqno: 12;
51     unsigned lnd_generation: 12;
52     int lnd_uid;		/* unit ID (land #) */
53     time_t lnd_timestamp;	/* Last time this unit was touched */
54     natid lnd_own;		/* owner's country num */
55     coord lnd_x;		/* x location in abs coords */
56     coord lnd_y;		/* y location in abs coords */
57     signed char lnd_type;	/* index in lchr[] */
58     signed char lnd_effic;	/* 0% to 100% */
59     signed char lnd_mobil;	/* mobility units */
60     unsigned char lnd_off;	/* repairs stopped? */
61     short lnd_tech;		/* tech level ship was built at */
62     char lnd_army;		/* group membership */
63     coord lnd_opx, lnd_opy;	/* Op sector coords */
64     short lnd_mission;		/* mission code */
65     short lnd_radius;		/* mission radius */
66     /* end of part matching struct empobj */
67     int lnd_ship;		/* UID of transporting ship, or -1 */
68     signed char lnd_harden;	/* fortification */
69     short lnd_retreat;		/* retreat percentage */
70     int lnd_rflags;		/* When do I retreat? */
71     char lnd_rpath[RET_LEN];	/* retreat path */
72     unsigned char lnd_scar;	/* how experienced the unit is (not used) */
73     short lnd_item[I_MAX+1];	/* amount of items on board */
74     short lnd_pstage;		/* plague stage */
75     short lnd_ptime;		/* how many ETUs remain in this stage */
76     int lnd_land;		/* UID of transporting land unit, or -1 */
77     short lnd_access;		/* Last tick mob was updated (MOB_ACCESS) */
78 };
79 
80 struct lchrstr {
81     short l_item[I_MAX+1];	/* load limit */
82     char *l_name;		/* full name of type of land unit */
83     short l_mat[I_MAX+1];	/* materials to build 100% */
84 				/* only I_LCM and I_HCM non-zero */
85     int l_bwork;		/* work to build 100% */
86     int l_tech;			/* tech required to build */
87     int l_cost;			/* how much it costs to build */
88     float l_att;		/* attack multiplier */
89     float l_def;		/* defense multiplier */
90     int l_vul;			/* vulnerability (0-100) */
91     int l_spd;			/* speed */
92     int l_vis;			/* visibility */
93     int l_spy;			/* Seeing distance */
94     int l_rad;			/* reaction radius */
95     int l_frg;			/* firing range */
96     int l_acc;			/* firing accuracy */
97     int l_dam;			/* # of guns firing */
98     int l_ammo;			/* firing ammu used per shot */
99     int l_aaf;			/* AA fire */
100     int l_flags;		/* what special things can this unit do */
101     unsigned char l_nxlight;	/* maximum number of xlight planes */
102     unsigned char l_nland;	/* maximum number of units */
103     signed char l_type;		/* index in lchr[] */
104 };
105 
106 /* Land unit ability flags */
107 #define L_ENGINEER	bit(1)	/* Do engineering things */
108 #define L_SUPPLY	bit(2)	/* supply other units/sects */
109 #define L_SECURITY	bit(3)	/* anti-terrorist troops */
110 #define L_LIGHT		bit(4)	/* can go on ships */
111 #define L_MARINE	bit(5)	/* marine units, good at assaulting */
112 #define L_RECON		bit(6)	/* recon units, good at spying */
113 #define L_RADAR		bit(7)	/* radar unit */
114 #define L_ASSAULT	bit(8)	/* can assault */
115 #define L_FLAK		bit(9)	/* flak unit */
116 #define L_SPY		bit(10)	/* spy unit - way cool */
117 #define L_TRAIN		bit(11)	/* train unit - neato */
118 #define L_HEAVY		bit(12)	/* heavy unit - can't go on trains */
119 
120 /* Chance to detect L_SPY unit (percent) */
121 #define LND_SPY_DETECT_CHANCE(eff) ((110-(eff))/100.0)
122 
123 #define getland(n, p) ef_read(EF_LAND, (n), (p))
124 #define putland(n, p) ef_write(EF_LAND, (n), (p))
125 #define getlandp(n) ((struct lndstr *)ef_ptr(EF_LAND, (n)))
126 
127 #define LCHR_SZ 128
128 extern struct lchrstr lchr[LCHR_SZ];
129 
130 enum {
131     LND_AIROPS_EFF = 50		/* min. efficiency for air ops */
132 };
133 
134 enum lnd_stuck {
135     LND_STUCK_NOT,		/* not stuck */
136     LND_STUCK_NO_RAIL,		/* land needs rail */
137     LND_STUCK_IMPASSABLE	/* sector type not marchable */
138 };
139 
140 extern float l_att(struct lchrstr *, int);
141 extern float l_def(struct lchrstr *, int);
142 extern int l_vul(struct lchrstr *, int);
143 extern int l_spd(struct lchrstr *, int);
144 extern int l_frg(struct lchrstr *, int);
145 extern int l_acc(struct lchrstr *, int);
146 extern int l_dam(struct lchrstr *, int);
147 extern int l_aaf(struct lchrstr *, int);
148 extern float lnd_att(struct lndstr *);
149 extern float lnd_def(struct lndstr *);
150 extern int lnd_vul(struct lndstr *);
151 extern int lnd_spd(struct lndstr *);
152 extern int lnd_vis(struct lndstr *);
153 extern int lnd_frg(struct lndstr *);
154 extern int lnd_acc(struct lndstr *);
155 extern int lnd_dam(struct lndstr *);
156 extern int lnd_aaf(struct lndstr *);
157 
158 /* src/lib/common/cargo.c */
159 extern void lnd_carrier_change(struct lndstr *, int, int, int);
160 extern int lnd_first_on_ship(struct shpstr *);
161 extern int lnd_first_on_land(struct lndstr *);
162 extern int lnd_next_on_unit(int);
163 extern int lnd_nxlight(struct lndstr *);
164 extern int lnd_nland(struct lndstr *);
165 
166 extern int lnd_fire(struct lndstr *);
167 extern int lnd_sabo(struct lndstr *, short *);
168 extern double lnd_fire_range(struct lndstr *);
169 
170 /* src/lib/subs/lndsub.c */
171 extern int lnd_sweep(struct emp_qelem *, int, int, natid);
172 extern int lnd_interdict(struct emp_qelem *, coord, coord, natid);
173 extern int lnd_may_mar(struct lndstr *, struct lndstr *, char *);
174 extern void lnd_sel(struct nstr_item *, struct emp_qelem *);
175 extern struct ulist *lnd_insque(struct lndstr *, struct emp_qelem *);
176 extern int lnd_check_mines(struct emp_qelem *);
177 extern enum lnd_stuck lnd_check_mar(struct lndstr *, struct sctstr *);
178 extern double lnd_pathcost(struct lndstr *, double);
179 extern int lnd_mobtype(struct lndstr *);
180 extern double lnd_mobcost(struct lndstr *, struct sctstr *);
181 
182 extern double attack_val(int, struct lndstr *);
183 extern double defense_val(struct lndstr *);
184 extern int lnd_reaction_range(struct lndstr *);
185 extern void lnd_print(natid, struct ulist *, char *);
186 extern int lnd_take_casualty(int, struct ulist *, int);
187 extern void lnd_submil(struct lndstr *, int);
188 extern void lnd_takemob(struct emp_qelem *, double);
189 extern int lnd_spyval(struct lndstr *);
190 extern void intelligence_report(natid, struct lndstr *, int, char *);
191 extern void lnd_mar_stay_behind(struct emp_qelem *, natid);
192 extern void lnd_mar_put(struct emp_qelem *, natid);
193 extern void lnd_put(struct emp_qelem *);
194 extern void lnd_put_one(struct ulist *);
195 extern int lnd_hardtarget(struct lndstr *);
196 extern int lnd_abandon_askyn(struct emp_qelem *);
197 extern int lnd_mar_dir(struct emp_qelem *, int, natid);
198 extern int lnd_mar_gauntlet(struct emp_qelem *, int, natid);
199 extern int lnd_support(natid, natid, coord, coord, int);
200 extern int lnd_can_attack(struct lndstr *);
201 extern int lnd_fortify(struct lndstr *lp, int hard_amt);
202 extern void lnd_set_tech(struct lndstr *, int);
203 
204 #endif
205