]> git.pond.sub.org Git - empserver/blob - include/plane.h
(ac_flak_dam): Redesign so that code common to all its callers ends up
[empserver] / include / plane.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  *  plane.h: Definitions for planes and plane types
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1986
32  *     Ken Stevens, 1995
33  *     Steve McClure, 1998
34  */
35
36 #ifndef PLANE_H
37 #define PLANE_H
38
39 #include "queue.h"
40 #include "sect.h"
41
42 #define PLN_TYPE_MAX    46
43 #define PLANE_MINEFF    10
44
45 struct plnstr {
46     /* initial part must match struct genitem */
47     short ef_type;
48     natid pln_own;              /* owning country */
49     short pln_uid;              /* plane unit id */
50     coord pln_x;                /* plane x-y */
51     coord pln_y;
52     signed char pln_type;       /* index in plchr[] */
53     signed char pln_effic;      /* actually "training" */
54     signed char pln_mobil;      /* plane mobility */
55     unsigned char pln_off;      /* repairs stopped? */
56     short pln_tech;             /* plane's tech level */
57     char pln_wing;              /* like fleet */
58     coord pln_opx;              /* Op sector coords */
59     coord pln_opy;              /* Op sector coords */
60     short pln_mission;          /* mission code */
61     short pln_radius;           /* mission radius */
62     /* end of part matching struct genitem */
63     unsigned char pln_range;    /* total distance, not radius */
64     unsigned char pln_range_max; /* max range for this plane */
65     short pln_ship;             /* pointer to carrier */
66     short pln_land;             /* pointer to carrier */
67     int pln_att;                /* plane air-air attack/defense values */
68     int pln_def;
69     int pln_acc;
70     int pln_load;
71     int pln_fuel;               /* (unused) */
72     signed char pln_harden;     /* for missiles */
73     signed char pln_nuketype;   /* type of nuclear armament (if any) */
74     signed char pln_flags;      /* State of the plane */
75     time_t pln_access;          /* Last time mob was updated (MOB_ACCESS) */
76     time_t pln_timestamp;       /* Last time this plane was touched */
77     float pln_theta;            /* position in orbital sine wave */
78 };
79
80 #define PLN_LAUNCHED    bit(0)  /* A satellite that's in orbit */
81 #define PLN_SYNCHRONOUS bit(1)  /* A satellite in geo-synchronous orbit */
82 #define PLN_AIRBURST    bit(2)  /* Airburst the nuke we're armed with */
83
84 struct plchrstr {
85     char *pl_name;              /* full name of type of plane */
86     int pl_lcm;                 /* costs to build */
87     int pl_hcm;
88     int pl_cost;
89     int pl_tech;                /* tech needed to build */
90     int pl_acc;                 /* bombing accuracy (higher the better) */
91     int pl_load;                /* bomb load, also for carrying cargo */
92     int pl_att;                 /* air-air attack/defense strengths */
93     int pl_def;
94     int pl_range;               /* how many sectors it can fly */
95     int pl_crew;                /* number of mil to crew it */
96     int pl_fuel;                /* fuel consumption */
97     int pl_stealth;             /* how stealthy is it? */
98     int pl_flags;               /* description of capability */
99     signed char pl_type;        /* index in plchr[] */
100 };
101
102 #define P_B     bit(0)          /* bombing factor only for bombing */
103 #define P_T     bit(1)          /* tactical bombing ability */
104 #define P_F     bit(2)          /* interceptor/escort */
105 #define P_C     bit(3)          /* bombing factor for transport only */
106 #define P_V     bit(4)          /* vtol ability */
107 #define P_M     bit(5)          /* missile, used only once, can't be intercepted */
108 #define P_L     bit(6)          /* light plane, lands on carriers */
109 #define P_S     bit(7)          /* Spy ability */
110 #define P_I     bit(8)          /* Imaging ability (advanced spying) */
111 #define P_O     bit(9)          /* Orbital ability (a satellite) */
112 #define P_X     bit(10)         /* Stealth ability */
113 #define P_N     bit(11)         /* Nuclear RV interceptor (abm) */
114 #define P_H     bit(12)         /* Half stealthy */
115 #define P_E     bit(13)         /* extra light */
116 #define P_K     bit(14)         /* chopper */
117 #define P_A     bit(15)         /* ASW (Anti-Sub Warfare) */
118 #define P_P     bit(16)         /* paradropping */
119 #define P_ESC   bit(17)         /* escort */
120 #define P_MINE  bit(18)         /* can lay mines */
121 #define P_SWEEP bit(19)         /* can sweep mines */
122 #define P_MAR   bit(20)         /* missile can hit ships */
123
124 #define PM_R    bit(0)          /* Recon mission */
125 #define PM_S    bit(1)          /* Mine-sweeping mission */
126
127         /* internal to "fly" module -- really shouldn't be here */
128
129 struct plist {
130     struct emp_qelem queue;     /* list of planes */
131     int bombs;                  /* bombs carried for bombing mission */
132     int misc;                   /* amount of random item being transported */
133     struct plchrstr *pcp;       /* pointer to desc of plane */
134     struct plnstr plane;        /* struct plane */
135 };
136
137 #define getplane(n, p) ef_read(EF_PLANE, (n), (p))
138 #define putplane(n, p) ef_write(EF_PLANE, (n), (p))
139 #define getplanep(n) (struct plnstr *)ef_ptr(EF_PLANE, (n))
140
141 extern struct plchrstr plchr[PLN_TYPE_MAX + 2];
142
143 struct shiplist {
144     short uid;
145     struct shiplist *next;
146 };
147
148 #define PLN_ATTDEF(b, t) (b + ((b?1:0) * ((t/20)>10?10:(t/20))))
149 #define PLN_ACC(b, t) (b * (1.0 - (sqrt(t) / 50.)))
150 #define PLN_RAN(b, t) (t ? (b + (logx(t, 2.0))) : b)
151 #define PLN_LOAD(b, t) (t ? (b * (logx(t, 50.0) < 1.0 ? 1.0 : \
152                                   logx(t, 50.0))) : b)
153
154 /* Work required for building 100% */
155 #define PLN_BLD_WORK(lcm, hcm) (20 + (lcm) + 2 * (hcm))
156
157 /* src/lib/subs/aircombat.c */
158 extern void ac_combat_headers(natid, natid);
159 extern void ac_airtoair(struct emp_qelem *, struct emp_qelem *);
160 extern int ac_flak_dam(int, int, int);
161 extern void ac_encounter(struct emp_qelem *, struct emp_qelem *, coord,
162                          coord, char *, int, int,
163                          struct emp_qelem *, struct emp_qelem *);
164 extern int ac_isflying(struct plnstr *, struct emp_qelem *);
165 extern void sam_intercept(struct emp_qelem *, struct emp_qelem *,
166                           natid, natid, coord, coord, int);
167
168 /* src/lib/subs/aswplnsubs.c */
169 extern int on_shiplist(short, struct shiplist *);
170 extern void add_shiplist(short, struct shiplist **);
171 extern void free_shiplist(struct shiplist **);
172 extern void print_shiplist(struct shiplist *);
173
174 #endif