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