1 /*
2  * XPilot NG, a multiplayer space war game.
3  *
4  * Copyright (C) 1991-2001 by
5  *
6  *      Bj�rn Stabell        <bjoern@xpilot.org>
7  *      Ken Ronny Schouten   <ken@xpilot.org>
8  *      Bert Gijsbers        <bert@xpilot.org>
9  *      Dick Balaska         <dick@xpilot.org>
10  *      Kimiko Koopman       <kimiko@xpilot.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25  */
26 
27 #ifndef CANNON_H
28 #define CANNON_H
29 
30 #ifndef MAP_H
31 # include "map.h"
32 #endif
33 
34 #ifndef WALLS_H
35 # include "walls.h"
36 #endif
37 
38 extern long CANNON_USE_ITEM;
39 
40 /* the different weapons a cannon can use.
41    used in communication between parts of firing code */
42 /* plain old bullet. more if wideangles or rearshots are available.
43    always available */
44 #define CW_SHOT		0
45 /* dropped or thrown. uses one mine */
46 #define CW_MINE		1
47 /* torpedo, heatseeker or smartmissile. uses one missile */
48 #define CW_MISSILE	2
49 /* blinding, stun or normal laser. needs a laser */
50 #define CW_LASER	3
51 /* uses one ECM */
52 #define CW_ECM		4
53 /* tractor or pressor beam. needs a tractorbeam */
54 #define CW_TRACTORBEAM	5
55 /* uses one transporter */
56 #define CW_TRANSPORTER	6
57 /* a big stream of exhaust particles (OBJ_SPARK). needs an afterburner and
58    uses one fuel pack. even bigger with emergency thrust. more afterburners
59    only increase probability of use */
60 #define CW_GASJET	7
61 
62 /* the different defenses a cannon can use.
63    used in communication between parts of defending code */
64 /* for four seconds, absorbs any shot. uses one emergency shield */
65 #define CD_EM_SHIELD	0
66 /* for four seconds, lets any shot pass through. uses one phasing device */
67 #define CD_PHASING	1
68 
69 /* base visibility distance (modified by sensors) */
70 #define CANNON_DISTANCE		(VISIBILITY_DISTANCE * 0.5)
71 
72 /* chance of throwing an item upon death (multiplied by options.dropItemOnKillProb) */
73 #define CANNON_DROP_ITEM_PROB	0.7
74 
75 #define CANNON_MINE_MASS	(MINE_MASS * 0.6)
76 #define CANNON_SHOT_MASS	0.4
77 /* lifetime in ticks (frames) of shots, missiles and mines */
78 /* #define CANNON_SHOT_LIFE	(8 + (randomMT() % 24)) */
79 /* maximum lifetime (only used in aiming) */
80 /* #define CANNON_SHOT_LIFE_MAX	(8 + 24) */
81 /* number of laser pulses used in calculation of pulse lifetime */
82 #define CANNON_PULSES		1
83 
84 /* sector in which cannonfire is possible */
85 #define CANNON_SPREAD		(RES / 3)
86 
87 /* cannon smartness is 0 to this value */
88 #define CANNON_SMARTNESS_MAX	3
89 
90 void Cannon_update(bool tick);
91 void Cannon_init(cannon_t *cannon);
92 void Cannon_init_items(cannon_t *cannon);
93 void Cannon_add_item(cannon_t *cannon, int type, int amount);
94 void Cannon_throw_items(cannon_t *cannon);
95 void Cannon_check_defense(cannon_t *cannon);
96 void Cannon_check_fire(cannon_t *cannon);
97 void Object_hits_cannon(object_t *obj, cannon_t *c);
98 void Cannon_dies(cannon_t *cannon, player_t *pl);
99 hitmask_t Cannon_hitmask(cannon_t *cannon);
100 void Cannon_set_hitmask(int group, cannon_t *cannon);
101 bool Cannon_hitfunc(group_t *groupptr, const move_t *move);
102 void World_restore_cannon(cannon_t *cannon);
103 void World_remove_cannon(cannon_t *cannon);
104 void Cannon_set_option(cannon_t *cannon, const char *name, const char *value);
105 
Cannon_get_smartness(cannon_t * c)106 static inline int Cannon_get_smartness(cannon_t *c)
107 {
108     if (c->smartness != -1)
109 	return c->smartness;
110     return options.cannonSmartness;
111 }
112 
Cannon_get_min_shot_life(cannon_t * c)113 static inline double Cannon_get_min_shot_life(cannon_t *c)
114 {
115     return options.minCannonShotLife;
116 }
117 
Cannon_get_max_shot_life(cannon_t * c)118 static inline double Cannon_get_max_shot_life(cannon_t *c)
119 {
120     return options.maxCannonShotLife;
121 }
122 
Cannon_get_shot_life(cannon_t * cannon)123 static inline double Cannon_get_shot_life(cannon_t *cannon)
124 {
125     double minlife, maxlife, d;
126 
127     minlife = Cannon_get_min_shot_life(cannon);
128     maxlife = Cannon_get_max_shot_life(cannon);
129     d = maxlife - minlife;
130 
131     return minlife + rfrac() * d;
132 }
133 
Cannon_get_shot_speed(cannon_t * cannon)134 static inline double Cannon_get_shot_speed(cannon_t *cannon)
135 {
136     if (cannon->shot_speed > 0)
137 	return cannon->shot_speed;
138     return options.cannonShotSpeed;
139 }
140 
Cannon_by_id(int id)141 static inline cannon_t *Cannon_by_id(int id)
142 {
143     int ind;
144 
145     if (id < MIN_CANNON_ID || id > MAX_CANNON_ID)
146 	return NULL;
147     ind = id - MIN_CANNON_ID;
148     return Cannon_by_index(ind);
149 }
150 
151 #endif
152