]> git.pond.sub.org Git - empserver/blob - include/ship.h
Generation numbers to catch write back of stale copies
[empserver] / include / ship.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2009, 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  *  ship.h: Definitions for things having to do with ships
29  *
30  *  Known contributors to this file:
31  *     Dave Pare
32  *     Thomas Ruschak, 1992
33  *     Ken Stevens, 1995
34  *     Steve McClure, 1998
35  *     Markus Armbruster, 2004-2009
36  */
37
38 #ifndef SHIP_H
39 #define SHIP_H
40
41 #include <time.h>
42 #include "item.h"
43 #include "queue.h"
44 #include "retreat.h"
45 #include "types.h"
46
47 #define SHP_TYPE_MAX    46
48 #define SHIP_MINEFF     20
49
50 /* bit masks for the autonav mode flags */
51
52 #define AN_AUTONAV bit(2)
53 #define AN_STANDBY bit(3)
54 #define AN_LOADING bit(4)
55 #define AN_SCUTTLE bit(5)       /* Auto-scuttle of trade ships */
56
57 /* TMAX is the number of cargo holds a ship use in the autonav code. */
58 #define TMAX 6
59
60
61 #define MAXSHPPATH      28
62 #define MAXSHPNAMLEN    24
63
64 struct shpstr {
65     /* initial part must match struct empobj */
66     signed ef_type: 8;
67     unsigned shp_seqno: 12;
68     unsigned shp_generation: 12;
69     int shp_uid;                /* unit it (ship #) */
70     time_t shp_timestamp;       /* Last time this ship was touched. */
71     natid shp_own;              /* owner's country num */
72     coord shp_x;                /* x location in abs coords */
73     coord shp_y;                /* y location in abs coords */
74     signed char shp_type;       /* index in mchr[] */
75     signed char shp_effic;      /* 0% to 100% */
76     signed char shp_mobil;      /* mobility units */
77     unsigned char shp_off;      /* repairs stopped? */
78     short shp_tech;             /* tech level ship was built at */
79     char shp_fleet;             /* group membership */
80     coord shp_opx, shp_opy;     /* Op sector coords */
81     short shp_mission;          /* mission code */
82     short shp_radius;           /* mission radius */
83     /* end of part matching struct empobj */
84     coord shp_destx[2];         /* location for ship destination */
85     coord shp_desty[2];
86     i_type shp_tstart[TMAX];    /* what goods to pick up at start point */
87     i_type shp_tend[TMAX];      /* what goods to pick up at end point   */
88     short shp_lstart[TMAX];     /* How much do we pick up at the start  */
89     short shp_lend[TMAX];       /* How much do we pick up at the end    */
90     unsigned char shp_autonav;  /* autonavigation flags */
91     short shp_item[I_MAX+1];    /* amount of items on board */
92     short shp_pstage;           /* plague stage */
93     short shp_ptime;            /* how many etus remain in this stage */
94     short shp_access;           /* Last tick mob was updated (MOB_ACCESS) */
95     unsigned char shp_mobquota; /* mobility quota */
96     char shp_path[MAXSHPPATH];
97     int shp_follow;
98     char shp_name[MAXSHPNAMLEN]; /* name set with the "name" command */
99     coord shp_orig_x;
100     coord shp_orig_y;           /* Where we were built */
101     natid shp_orig_own;         /* Who built us */
102     int shp_rflags;             /* When do I retreat? */
103     char shp_rpath[RET_LEN];    /* retreat path */
104 };
105
106 struct mchrstr {
107     short m_item[I_MAX+1];      /* load limit */
108     int m_lcm;                  /* units of lcm to build */
109     int m_hcm;                  /* units of hcm to build */
110     int m_armor;                /* how well armored it is */
111     int m_speed;                /* how fast it can go */
112     int m_visib;                /* how well it can be seen */
113     int m_vrnge;                /* how well it can see */
114     int m_frnge;                /* how far it can fire */
115     int m_glim;                 /* how many guns it can fire */
116     unsigned char m_nxlight;    /* maximum number of xlight planes */
117     unsigned char m_nchoppers;  /* maximum number of choppers */
118     char *m_name;               /* full name of type of ship */
119     int m_tech;                 /* tech required to build */
120     int m_cost;                 /* how much it costs to build */
121     long m_flags;               /* what special things can this ship do */
122     unsigned char m_nplanes;    /* maximum number of planes this ship holds */
123     unsigned char m_nland;      /* maximum number of units this ship holds */
124     signed char m_type;         /* index in mchr[] */
125 };
126
127 #define M_FOOD          bit(0)  /* catch that fish! */
128 #define M_TORP          bit(1)  /* fire torpedoes */
129 #define M_DCH           bit(2)  /* drop depth charges on subs */
130 #define M_FLY           bit(3)  /* launch and recover planes */
131 /* M_MSL will be automatically set in init_mchr() if m_nplanes > 0
132    and M_FLY is not set */
133 #define M_MSL           bit(4)  /* launch missiles */
134 #define M_OIL           bit(5)  /* drill for oil */
135 #define M_SONAR         bit(6)  /* locate submarines */
136 #define M_MINE          bit(7)  /* drop mines */
137 #define M_SWEEP         bit(8)  /* clean up the mines */
138 #define M_SUB           bit(9)  /* a submarine */
139 /* unused               bit(10) */
140 #define M_LAND          bit(11) /* allows full landing ability */
141 #define M_SUBT          bit(12) /* allows torping of other subs */
142 #define M_TRADE         bit(13) /* is a trade ship */
143 #define M_SEMILAND      bit(14) /* can land 1/4 */
144 /* unused               bit(15) */
145 /* unused               bit(16) */
146 /* unused               bit(17) */
147 #define M_SUPPLY        bit(18) /* Can supply units/sects/ships */
148 #define M_CANAL         bit(19) /* Can navigate a canal (BIG CITY) */
149 #define M_ANTIMISSILE   bit(20) /* Shoot down missile */
150
151 #define getship(n, p) ef_read(EF_SHIP, (n), (p))
152 #define putship(n, p) ef_write(EF_SHIP, (n), (p))
153 #define getshipp(n) ((struct shpstr *)ef_ptr(EF_SHIP, (n)))
154
155 extern struct mchrstr mchr[SHP_TYPE_MAX + 2];
156
157 /* Work required for building 100% */
158 #define SHP_BLD_WORK(lcm, hcm) (20 + (lcm) + 2 * (hcm))
159
160  /* return codes from shp_check_nav */
161 #define CN_NAVIGABLE    0
162 #define CN_LANDLOCKED   1
163 #define CN_CONSTRUCTION 2
164 #define CN_ERROR        -1
165
166 enum {
167     SHP_AIROPS_EFF = 50,        /* min. efficiency for air ops */
168     SHP_TORP_SHELLS = 3         /* number of shells used by a torpedo */
169 };
170
171 extern int m_armor(struct mchrstr *, int);
172 extern int m_speed(struct mchrstr *, int);
173 extern int m_visib(struct mchrstr *, int);
174 extern int m_frnge(struct mchrstr *, int);
175 extern int m_glim(struct mchrstr *, int);
176 extern int shp_armor(struct shpstr *);
177 extern int shp_speed(struct shpstr *);
178 extern int shp_visib(struct shpstr *);
179 extern int shp_frnge(struct shpstr *);
180 extern int shp_glim(struct shpstr *);
181
182 extern int shp_nplane(struct shpstr *, int *, int *, int *);
183 extern int shp_nland(struct shpstr *);
184
185 extern int shp_dchrg(struct shpstr *);
186 extern int shp_fire(struct shpstr *);
187 extern int shp_torp(struct shpstr *, int);
188 extern double shp_fire_range(struct shpstr *);
189 extern int shp_usable_guns(struct shpstr *);
190 extern double shp_torp_hitchance(struct shpstr *, int);
191
192 #endif