]> git.pond.sub.org Git - empserver/blob - include/land.h
Break inclusion cycle: prototypes.h and commands.h included each
[empserver] / include / land.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  *  land.h: Definitions for land units
29  * 
30  *  Known contributors to this file:
31  *     Thomas Ruschak, 1992
32  *     Ken Stevens, 1995
33  *     Steve McClure, 1998
34  */
35
36 #ifndef LAND_H
37 #define LAND_H
38
39 #include "item.h"
40 #include "queue.h"
41 #include "retreat.h"
42 #include "types.h"
43
44 #define LND_TYPE_MAX    30
45 #define LAND_MINEFF     10
46 #define LAND_MINFIREEFF 40      /* arty must be this effic to fire */
47
48 struct lndstr {
49     /* initial part must match struct empobj */
50     short ef_type;
51     natid lnd_own;              /* owner's country num */
52     short lnd_uid;              /* unit id (land unit) */
53     coord lnd_x;                /* x location in abs coords */
54     coord lnd_y;                /* y location in abs coords */
55     signed char lnd_type;       /* index in lchr[] */
56     signed char lnd_effic;      /* 0% to 100% */
57     signed char lnd_mobil;      /* mobility units */
58     unsigned char lnd_off;      /* repairs stopped? */
59     short lnd_tech;             /* tech level ship was built at */
60     char lnd_army;              /* group membership */
61     coord lnd_opx, lnd_opy;     /* Op sector coords */
62     short lnd_mission;          /* mission code */
63     short lnd_radius;           /* mission radius */
64     /* end of part matching struct empobj */
65     signed char lnd_flags;      /* unit flags (unused) */
66     short lnd_ship;             /* pointer to transporting ship */
67     signed char lnd_harden;     /* fortification */
68     short lnd_retreat;          /* retreat percentage */
69     unsigned char lnd_fuel;     /* How much fuel do we have */
70     unsigned char lnd_nxlight;  /* How many xlight planes on board? */
71     int lnd_rflags;             /* When do I retreat? */
72     char lnd_rpath[RET_LEN];    /* retreat path */
73     unsigned char lnd_rad_max;  /* max radius for this unit */
74     unsigned char lnd_scar;     /* how experienced the unit is (not used) */
75     short lnd_item[I_MAX+1];    /* amount of items on board */
76     short lnd_pstage;           /* plague stage */
77     short lnd_ptime;            /* how many etus remain in this stage */
78     short lnd_land;             /* pointer to transporting unit */
79     unsigned char lnd_nland;
80     time_t lnd_access;          /* Last time mob was updated (MOB_ACCESS) */
81     float lnd_att;              /* attack multiplier */
82     float lnd_def;              /* defense multiplier */
83     int lnd_vul;                /* vulnerability (0-100) */
84     int lnd_spd;                /* speed */
85     int lnd_vis;                /* visibility */
86     int lnd_spy;                /* Seeing distance */
87     int lnd_rad;                /* reaction radius */
88     int lnd_frg;                /* firing range */
89     int lnd_acc;                /* firing accuracy */
90     int lnd_dam;                /* # of guns firing */
91     int lnd_ammo;               /* firing ammu used per shot */
92     int lnd_aaf;                /* aa fire */
93     unsigned char lnd_fuelc;    /* fuel capacity */
94     unsigned char lnd_fuelu;    /* fuel used per 10 mob */
95     unsigned char lnd_maxlight; /* maximum number of xlight planes */
96     unsigned char lnd_maxland;  /* maximum number of units */
97     time_t lnd_timestamp;       /* Last time this unit was touched */
98 };
99
100 struct lchrstr {
101     short l_item[I_MAX+1];      /* load limit */
102     char *l_name;               /* full name of type of land unit */
103     int l_lcm;                  /* units of lcm to build */
104     int l_hcm;                  /* units of hcm to build */
105     int l_mil;                  /* how many mil it takes to build */
106     int l_gun;                  /* how many guns it takes to build (unused) */
107     int l_shell;                /* #shells it takes to build (unused) */
108     int l_tech;                 /* tech required to build */
109     int l_cost;                 /* how much it costs to build */
110     float l_att;                /* attack multiplier */
111     float l_def;                /* defense multiplier */
112     int l_vul;                  /* vulnerability (0-100) */
113     int l_spd;                  /* speed */
114     int l_vis;                  /* visibility */
115     int l_spy;                  /* Seeing distance */
116     int l_rad;                  /* reaction radius */
117     int l_frg;                  /* firing range */
118     int l_acc;                  /* firing accuracy */
119     int l_dam;                  /* # of guns firing */
120     int l_ammo;                 /* firing ammu used per shot */
121     int l_aaf;                  /* aa fire */
122     unsigned char l_fuelc;      /* fuel capacity */
123     unsigned char l_fuelu;      /* fuel used per 10 mob */
124     unsigned char l_nxlight;    /* maximum number of xlight planes */
125     unsigned char l_nland;      /* maximum number of units */
126     signed char l_type;         /* index in lchr[] */
127     long l_flags;               /* what special things can this unit do */
128 };
129
130 /* Land unit ability flags */
131 #define L_ENGINEER      bit(1)  /* Do engineering things */
132 #define L_SUPPLY        bit(2)  /* supply other units/sects */
133 #define L_SECURITY      bit(3)  /* anti-terrorist troops */
134 #define L_LIGHT         bit(4)  /* can go on ships */
135 #define L_MARINE        bit(5)  /* marine units, good at assaulting */
136 #define L_RECON         bit(6)  /* recon units, good at spying */
137 #define L_RADAR         bit(7)  /* radar unit */
138 #define L_ASSAULT       bit(8)  /* can assault */
139 #define L_FLAK          bit(9)  /* flak unit */
140 #define L_SPY           bit(10) /* spy unit - way cool */
141 #define L_TRAIN         bit(11) /* train unit - neato */
142 #define L_HEAVY         bit(12) /* heavy unit - can't go on trains */
143
144 #define LND_ATTDEF(b, t) (((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0)))   \
145                           > 127 ? 127 :                                 \
146                           ((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0))))
147 #define LND_SPD(b, t) ((b * (1.0 + ((sqrt(t) / 100.0) * 2.1))) > 127    \
148                        ? 127 : (b * (1.0 + ((sqrt(t) / 100.0) * 2.1))))
149 #define LND_VUL(b, t) ((b * (1.0 - ((sqrt(t) / 100.0) * 1.1))) < 0      \
150                        ? 0 : (b * (1.0 - ((sqrt(t) / 100.0) * 1.1))))
151 #define LND_VIS(b, t) (b)
152 #define LND_SPY(b, t) (b)
153 #define LND_RAD(b, t) (b)
154 #define LND_FRG(b, t) ((t) ?                                 \
155                        ((b) * (logx((t), 35.0) < 1.0 ? 1.0 : \
156                                logx((t), 35.0))) : (b))
157 #define LND_DAM(b, t) ((t) ?                                 \
158                        ((b) * (logx((t), 60.0) < 1.0 ? 1.0 : \
159                                logx((t), 60.0))) : (b))
160 #define LND_ACC(b, t) ((b * (1.0 - ((sqrt(t) / 100.0) * 1.1))) < 0      \
161                        ? 0 : (b * (1.0 - ((sqrt(t) / 100.0) * 1.1))))
162 #define LND_AMM(b, t) (b)
163 #define LND_AAF(b, t) ((b * (1.0 + ((sqrt(t) / 100.0) * 3.0))) > 127    \
164                        ? 127 : (b * (1.0 + ((sqrt(t) / 100.0) * 3.0))))
165 #define LND_FC(b, t)  (b)
166 #define LND_FU(b, t)  (b)
167 #define LND_XPL(b, t) (b)
168 #define LND_MXL(b, t) (b)
169
170 /* Work required for building 100% */
171 #define LND_BLD_WORK(lcm, hcm) (20 + (lcm) + 2 * (hcm))
172
173 /* Chance to detect L_SPY unit (percent) */
174 #define LND_SPY_DETECT_CHANCE(eff) ((110-(eff))/100.0)
175
176 #define getland(n, p) ef_read(EF_LAND, (n), (p))
177 #define putland(n, p) ef_write(EF_LAND, (n), (p))
178 #define getlandp(n) (struct lndstr *)ef_ptr(EF_LAND, (n))
179
180 extern struct lchrstr lchr[LND_TYPE_MAX + 2];
181
182 struct llist {
183     struct emp_qelem queue;     /* list of units */
184     coord x, y;                 /* x,y it came from */
185     struct lchrstr *lcp;        /* pointer to desc of land unit */
186     struct lndstr land;         /* struct land unit */
187     int eff;
188     double mobil;
189     int supplied;
190 };
191
192 enum {
193     LND_AIROPS_EFF = 50         /* min. efficiency for air ops */
194 };
195
196 /* src/lib/subs/lndsub.c */
197 extern void lnd_sweep(struct emp_qelem *, int, int, natid);
198 extern int lnd_interdict(struct emp_qelem *, coord, coord, natid);
199 extern void lnd_sel(struct nstr_item *, struct emp_qelem *);
200 extern int lnd_check_mines(struct emp_qelem *);
201 extern double lnd_pathcost(struct lndstr *, double);
202 extern int lnd_mobtype(struct lndstr *);
203 extern double lnd_mobcost(struct lndstr *, struct sctstr *);
204 extern char *lnd_path(int, struct lndstr *, char *);
205
206 extern double attack_val(int, struct lndstr *);
207 extern double defense_val(struct lndstr *);
208 extern void lnd_print(struct llist *, char *);
209 extern void lnd_delete(struct llist *, char *);
210 extern int lnd_take_casualty(int, struct llist *, int);
211 extern void lnd_submil(struct lndstr *, int);
212 extern void lnd_takemob(struct emp_qelem *, double);
213 extern int lnd_spyval(struct lndstr *);
214 extern double intelligence_report(int, struct lndstr *, int, char *);
215 extern int count_sect_units(struct sctstr *);
216 extern void count_units(struct shpstr *);
217 extern void lnd_count_units(struct lndstr *);
218 extern void lnd_mar(struct emp_qelem *, double *, double *, int *, natid);
219 extern void lnd_put(struct emp_qelem *, natid);
220 extern void lnd_list(struct emp_qelem *);
221 extern int lnd_hardtarget(struct lndstr *);
222 extern int lnd_mar_one_sector(struct emp_qelem *, int, natid, int);
223 extern int lnd_support(natid, natid, coord, coord, int);
224 extern int lnd_can_attack(struct lndstr *);
225 extern int lnd_fortify (struct lndstr *lp, int hard_amt);
226 extern void lnd_set_tech(struct lndstr *, int);
227
228 #endif