]> git.pond.sub.org Git - empserver/blob - include/ship.h
Do not include var.h where no longer needed. Clean up register keywords in these...
[empserver] / include / ship.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  ship.h: Definitions for things having to do with ships
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare
32  *     Thomas Rushack, 1992
33  *     Ken Stevens, 1995
34  *     Steve McClure, 1998
35  */
36
37 #ifndef _SHIP_H_
38 #define _SHIP_H_
39
40 #include "queue.h"
41 #include "misc.h"
42 #include "retreat.h"
43
44 #define SHIP_MINEFF     20
45
46 /* bit masks for the autonav mode flags */
47
48 #define AN_SAILDIR bit(1)
49 #define AN_AUTONAV bit(2)
50 #define AN_STANDBY bit(3)
51 #define AN_LOADING bit(4)
52 #define AN_SCUTTLE bit(5)       /* Auto-scuttle of trade ships */
53
54 /* TMAX is the number of cargo holds a ship use in the autonav code. */
55 #define TMAX 6
56
57
58 #define MAXSHPPATH      28
59 #define MAXSHPNAMLEN    24
60
61 struct shpstr {
62     short ef_type;
63     natid shp_own;              /* owner's country num */
64     short shp_uid;              /* unit id (ship #) */
65     coord shp_x;                /* x location in abs coords */
66     coord shp_y;                /* y location in abs coords */
67     s_char shp_type;            /* index in mchr[] */
68     s_char shp_effic;           /* 0% to 100% */
69     s_char shp_mobil;           /* mobility units */
70     short shp_tech;             /* tech level ship was built at */
71     s_char shp_fleet;           /* group membership */
72     coord shp_opx, shp_opy;     /* Op sector coords */
73     short shp_mission;          /* mission code */
74     short shp_radius;           /* mission radius */
75     u_char shp_nplane;          /* number of planes on board */
76     u_char shp_nland;           /* number of land units on board */
77     short shp_armor;
78     short shp_speed;
79     short shp_visib;
80     short shp_frnge;
81     short shp_glim;
82     coord shp_destx[2];         /* location for ship destination */
83     coord shp_desty[2];
84     i_type shp_tstart[TMAX];    /* what goods to pick up at start point */
85     i_type shp_tend[TMAX];      /* what goods to pick up at end point   */
86     short shp_lstart[TMAX];     /* How much do we pick up at the start  */
87     short shp_lend[TMAX];       /* How much do we pick up at the end    */
88     u_char shp_autonav;         /* autonavigation flags */
89     short shp_item[I_MAX+1];    /* amount of items on board */
90     u_short shp_pstage;         /* plague stage */
91     u_short shp_ptime;          /* how many etus remain in this stage */
92     time_t shp_access;          /* Last time mob was updated (MOB_ACCESS) */
93     time_t shp_timestamp;       /* Last time this ship was touched. */
94     u_char shp_mobquota;        /* mobility quota */
95     s_char shp_path[MAXSHPPATH];
96     short shp_follow;
97     s_char shp_name[MAXSHPNAMLEN];      /* name set with the "name" command */
98     u_char shp_fuel;            /* How much fuel do we have */
99     u_char shp_nchoppers;       /* How many choppers on board? */
100     u_char shp_nxlight;         /* How many xlight planes on board? */
101     coord shp_orig_x;
102     coord shp_orig_y;           /* Where we were built */
103     natid shp_orig_own;         /* Who built us */
104     int shp_rflags;             /* When do I retreat? */
105     s_char shp_rpath[RET_LEN];  /* retreat path */
106 };
107
108 struct fltelemstr {
109     int num;
110     int own;
111     double mobil, mobcost;
112     struct fltelemstr *next;
113 };
114
115 struct fltheadstr {
116     int leader;
117     s_char real_q;
118 /* defines for the real_q member */
119 #define LEADER_VIRTUAL  0
120 #define LEADER_REAL     1
121 #define LEADER_WRONGSECT        2
122     coord x, y;
123     natid own;
124     unsigned maxmoves;
125     struct fltelemstr *head;
126     struct fltheadstr *next;
127 };
128
129 struct mchrstr {
130     u_short m_item[I_MAX+1];    /* load limit */
131     int m_lcm;                  /* units of lcm to build */
132     int m_hcm;                  /* units of hcm to build */
133     int m_armor;                /* how well armored it is */
134     int m_speed;                /* how fast it can go */
135     int m_visib;                /* how well it can be seen */
136     int m_vrnge;                /* how well it can see */
137     int m_frnge;                /* how far it can fire */
138     int m_glim;                 /* how many guns it can fire */
139     u_char m_nxlight;           /* maximum number of xlight planes */
140     u_char m_nchoppers;         /* maximum number of choppers */
141     u_char m_fuelc;             /* fuel capacity */
142     u_char m_fuelu;             /* fuel used per 10 mob */
143     char *m_name;               /* full name of type of ship */
144     int m_tech;                 /* tech required to build */
145     int m_cost;                 /* how much it costs to build */
146     long m_flags;               /* what special things can this ship do */
147     u_char m_nplanes;           /* maximum number of planes this ship holds */
148     u_char m_nland;             /* maximum number of units this ship holds */
149 };
150
151 #define M_FOOD          bit(0)  /* catch that fish! */
152 #define M_TORP          bit(1)  /* fire torpedoes */
153 #define M_DCH           bit(2)  /* drop depth charges on subs */
154 #define M_FLY           bit(3)  /* launch and recover planes */
155 /* M_MSL will be automatically set in init_global() if m_nplanes > 0
156    and M_FLY is not set */
157 #define M_MSL           bit(4)  /* launch missiles */
158 #define M_OIL           bit(5)  /* drill for oil */
159 #define M_SONAR         bit(6)  /* locate submarines */
160 #define M_MINE          bit(7)  /* drop mines */
161 #define M_SWEEP         bit(8)  /* clean up the mines */
162 #define M_SUB           bit(9)  /* a submarine */
163 #define M_SPY           bit(10) /* gather intelligence info */
164 #define M_LAND          bit(11) /* allows full landing ability */
165 #define M_SUBT          bit(12) /* allows torping of other subs */
166 #define M_TRADE         bit(13) /* is a trade ship */
167 #define M_SEMILAND      bit(14) /* can land 1/4 */
168 /* M_XLIGHT will be automatically set in init_global() if m_nxlight > 0 */
169 #define M_XLIGHT        bit(15) /* can hold xlight planes */
170 /* M_CHOPPER will be automatically set in init_global() if m_nchoppers > 0 */
171 #define M_CHOPPER       bit(16) /* can hold choppers */
172 #define M_OILER         bit(17) /* can re-fuel ships */
173 #define M_SUPPLY        bit(18) /* Can supply units/sects/ships */
174 /* M_UNIT will be automatically set in init_global() if m_nland > 0 */
175 #define M_UNIT          bit(19) /* Can carry units */
176 #define M_ANTIMISSILE   bit(20) /* Shoot down missile */
177
178 #define getship(n, p) \
179         ef_read(EF_SHIP, n, p)
180 #define putship(n, p) \
181         ef_write(EF_SHIP, n, p)
182 #define getshipp(n) \
183         (struct shpstr *) ef_ptr(EF_SHIP, n)
184
185 extern struct mchrstr mchr[];
186 extern int shp_maxno;
187
188 struct mlist {
189     struct emp_qelem queue;     /* list of ships */
190     struct mchrstr *mcp;        /* pointer to desc of ship */
191     struct shpstr ship;         /* struct ship */
192     double mobil;               /* how much mobility the ship has left */
193     int done;                   /* has this ship been interdicted yet? */
194 };
195
196 #define SHP_DEF(b, t) (t ? (b * (logx((double)t, (double)40.0) < 1.0 ? 1.0 : \
197                              logx((double)t, (double)40.0))) : b)
198 #define SHP_SPD(b, t) (t ? (b * (logx((double)t, (double)35.0) < 1.0 ? 1.0 : \
199                              logx((double)t, (double)35.0))) : b)
200 #define SHP_VIS(b, t) (b * (1 - (sqrt((double)t) / 50)))
201 #define SHP_RNG(b, t) (t ? (b * (logx((double)t, (double)35.0) < 1.0 ? 1.0 : \
202                              logx((double)t, (double)35.0))) : b)
203 #define SHP_FIR(b, t) (t ? (b * (logx((double)t, (double)60.0) < 1.0 ? 1.0 : \
204                              logx((double)t, (double)60.0))) : b)
205
206 /* Work required for building 100% */
207 #define SHP_BLD_WORK(lcm, hcm) (20 + (lcm) + 2 * (hcm))
208
209  /* return codes from shp_check_nav */
210 #define CN_NAVIGABLE    (0)
211 #define CN_LANDLOCKED   (1)
212 #define CN_CONSTRUCTION (2)
213 #define CN_ERROR        (-1)
214
215 enum {
216     SHP_AIROPS_EFF = 50,        /* min. efficiency for air ops */
217     SHP_TORP_SHELLS = 3         /* number of shells used by a torpedo */
218 };
219
220 #endif /* _SHIP_H_ */