1 /*
2  * Portions of this file are copyright Rebirth contributors and licensed as
3  * described in COPYING.txt.
4  * Portions of this file are copyright Parallax Software and licensed
5  * according to the Parallax license below.
6  * See COPYING.txt for license details.
7 
8 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
10 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
16 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
18 */
19 
20 /*
21  *
22  * Protypes for weapon stuff.
23  *
24  */
25 
26 #pragma once
27 
28 #ifdef __cplusplus
29 #include "pack.h"
30 #include "pstypes.h"
31 #include "maths.h"
32 #include "dxxsconf.h"
33 #include "dsx-ns.h"
34 #include "kconfig.h"
35 #include "weapon_id.h"
36 
37 #include "fwd-object.h"
38 #include "fwd-vclip.h"
39 #include <array>
40 
41 enum powerup_type_t : uint8_t;
42 
43 #if defined(DXX_BUILD_DESCENT_II)
44 #define LASER_HELIX_MASK        7   // must match number of bits in flags
45 #define MAX_SUPER_LASER_LEVEL   laser_level::_6   // Note, laser levels are numbered from 0.
46 #endif
47 
48 #if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II)
49 
50 struct PHYSFS_File;
51 #if 0
52 void weapon_info_write(PHYSFS_File *, const weapon_info &);
53 #endif
54 
55 namespace dcx {
56 enum class laser_level : uint8_t;
57 }
58 
59 namespace dsx {
60 struct weapon_info;
61 
62 #define REARM_TIME                  (F1_0)
63 
64 #define WEAPON_DEFAULT_LIFETIME     (F1_0*12)   // Lifetime of an object if a bozo forgets to define it.
65 
66 #define WEAPON_TYPE_WEAK_LASER      0
67 #define WEAPON_TYPE_STRONG_LASER    1
68 #define WEAPON_TYPE_CANNON_BALL     2
69 #define WEAPON_TYPE_MISSILE         3
70 
71 #define WEAPON_RENDER_NONE          weapon_info::render_type::None
72 #define WEAPON_RENDER_LASER         weapon_info::render_type::laser
73 #define WEAPON_RENDER_BLOB          weapon_info::render_type::blob
74 #define WEAPON_RENDER_POLYMODEL     weapon_info::render_type::polymodel
75 #define WEAPON_RENDER_VCLIP         weapon_info::render_type::vclip
76 
77 #if defined(DXX_BUILD_DESCENT_I)
78 constexpr std::integral_constant<unsigned, 30> MAX_WEAPON_TYPES{};
79 
80 constexpr std::integral_constant<unsigned, 5> MAX_PRIMARY_WEAPONS{};
81 constexpr std::integral_constant<unsigned, 5> MAX_SECONDARY_WEAPONS{};
82 
83 #elif defined(DXX_BUILD_DESCENT_II)
84 // weapon info flags
85 #define WIF_PLACABLE        1   // can be placed by level designer
86 constexpr std::integral_constant<unsigned, 70> MAX_WEAPON_TYPES{};
87 
88 constexpr std::integral_constant<unsigned, 10> MAX_PRIMARY_WEAPONS{};
89 constexpr std::integral_constant<unsigned, 10> MAX_SECONDARY_WEAPONS{};
90 #endif
91 
92 enum primary_weapon_index_t : uint8_t;
93 enum secondary_weapon_index_t : uint8_t;
94 
95 extern const enumerated_array<weapon_id_type, MAX_PRIMARY_WEAPONS, primary_weapon_index_t> Primary_weapon_to_weapon_info;
96 //for each primary weapon, what kind of powerup gives weapon
97 extern const enumerated_array<powerup_type_t, MAX_PRIMARY_WEAPONS, primary_weapon_index_t> Primary_weapon_to_powerup;
98 extern const enumerated_array<weapon_id_type, MAX_SECONDARY_WEAPONS, secondary_weapon_index_t> Secondary_weapon_to_weapon_info;
99 //for each Secondary weapon, what kind of powerup gives weapon
100 extern const enumerated_array<powerup_type_t, MAX_SECONDARY_WEAPONS, secondary_weapon_index_t> Secondary_weapon_to_powerup;
101 extern const enumerated_array<uint8_t, MAX_SECONDARY_WEAPONS, secondary_weapon_index_t>    Secondary_ammo_max;
102 /*
103  * reads n weapon_info structs from a PHYSFS_File
104  */
105 using weapon_info_array = std::array<weapon_info, MAX_WEAPON_TYPES>;
106 extern weapon_info_array Weapon_info;
107 void weapon_info_read_n(weapon_info_array &wi, std::size_t count, PHYSFS_File *fp, int file_version, std::size_t offset = 0);
108 
109 //given a weapon index, return the flag value
110 #define  HAS_PRIMARY_FLAG(index)  (1<<(index))
111 #define  HAS_SECONDARY_FLAG(index)  (1<<(index))
112 
113 // Weapon flags, if player->weapon_flags & WEAPON_FLAG is set, then the player has this weapon
114 #define HAS_LASER_FLAG      HAS_PRIMARY_FLAG(primary_weapon_index_t::LASER_INDEX)
115 #define HAS_VULCAN_FLAG     HAS_PRIMARY_FLAG(primary_weapon_index_t::VULCAN_INDEX)
116 #define HAS_SPREADFIRE_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::SPREADFIRE_INDEX)
117 #define HAS_PLASMA_FLAG     HAS_PRIMARY_FLAG(primary_weapon_index_t::PLASMA_INDEX)
118 #define HAS_FUSION_FLAG     HAS_PRIMARY_FLAG(primary_weapon_index_t::FUSION_INDEX)
119 
120 #define NUM_SMART_CHILDREN  6   // Number of smart children created by default.
121 #if defined(DXX_BUILD_DESCENT_I)
122 #define	NUM_SHAREWARE_WEAPONS	3		//in shareware, old get first 3 of each
123 #elif defined(DXX_BUILD_DESCENT_II)
124 #define HAS_SUPER_LASER_FLAG	HAS_PRIMARY_FLAG(primary_weapon_index_t::SUPER_LASER_INDEX)
125 #define HAS_GAUSS_FLAG     HAS_PRIMARY_FLAG(primary_weapon_index_t::GAUSS_INDEX)
126 #define HAS_HELIX_FLAG     HAS_PRIMARY_FLAG(primary_weapon_index_t::HELIX_INDEX)
127 #define HAS_PHOENIX_FLAG   HAS_PRIMARY_FLAG(primary_weapon_index_t::PHOENIX_INDEX)
128 #define HAS_OMEGA_FLAG     HAS_PRIMARY_FLAG(primary_weapon_index_t::OMEGA_INDEX)
129 #define SUPER_WEAPON        5
130 //flags whether the last time we use this weapon, it was the 'super' version
131 #endif
132 //for each Secondary weapon, which gun it fires out of
133 extern const std::array<uint8_t, MAX_SECONDARY_WEAPONS> Secondary_weapon_to_gun_num;
134 }
135 
136 namespace dcx {
137 extern unsigned N_weapon_types;
138 template <typename T>
139 class player_selected_weapon : public prohibit_void_ptr<player_selected_weapon<T>>
140 {
141 	T active, delayed;
142 public:
T()143 	operator T() const
144 	{
145 		return get_active();
146 	}
get_active()147 	T get_active() const
148 	{
149 		return active;
150 	}
get_delayed()151 	T get_delayed() const
152 	{
153 		return delayed;
154 	}
155 	player_selected_weapon &operator=(T v)
156 	{
157 		active = v;
158 		set_delayed(v);
159 		return *this;
160 	}
set_delayed(T v)161 	void set_delayed(T v)
162 	{
163 		delayed = v;
164 	}
165 };
166 
167 }
168 #ifdef dsx
169 namespace dsx {
170 
171 struct player_info;
172 void do_primary_weapon_select(player_info &, primary_weapon_index_t weapon_num);
173 void do_secondary_weapon_select(player_info &, secondary_weapon_index_t weapon_num);
174 void auto_select_primary_weapon(player_info &);
175 void auto_select_secondary_weapon(player_info &);
176 void set_primary_weapon(player_info &, uint_fast32_t weapon_num);
177 void select_primary_weapon(player_info &, const char *weapon_name, uint_fast32_t weapon_num, int wait_for_rearm);
178 void set_secondary_weapon_to_concussion(player_info &);
179 void select_secondary_weapon(player_info &, const char *weapon_name, uint_fast32_t weapon_num, int wait_for_rearm);
180 
181 }
182 #endif
183 class has_weapon_result;
184 
185 //-----------------------------------------------------------------------------
186 // Return:
187 // Bits set:
188 //      HAS_WEAPON_FLAG
189 //      HAS_ENERGY_FLAG
190 //      HAS_AMMO_FLAG
191 #ifdef dsx
192 namespace dsx {
193 has_weapon_result player_has_primary_weapon(const player_info &, primary_weapon_index_t weapon_num);
194 has_weapon_result player_has_secondary_weapon(const player_info &, secondary_weapon_index_t weapon_num);
195 
196 //called when one of these weapons is picked up
197 //when you pick up a secondary, you always get the weapon & ammo for it
198 int pick_up_primary(player_info &, primary_weapon_index_t weapon_index);
199 int pick_up_secondary(player_info &, secondary_weapon_index_t weapon_index, int count, const control_info &Controls);
200 
201 //called when a primary weapon is picked up
202 //returns true if actually picked up
203 }
204 #endif
205 
206 //called when ammo (for the vulcan cannon) is picked up
207 
208 namespace dsx {
209 int pick_up_vulcan_ammo(player_info &player_info, uint_fast32_t ammo_count, bool change_weapon = true);
210 //this function is for when the player intentionally drops a powerup
211 imobjptridx_t spit_powerup(const d_vclip_array &Vclip, const object_base &spitter, unsigned id, unsigned seed);
212 
213 #if defined(DXX_BUILD_DESCENT_II)
214 int attempt_to_steal_item(vmobjptridx_t objp, vmobjptr_t playerobjp);
215 
216 #define SMEGA_ID    40
217 
218 void weapons_homing_all();
219 void weapons_homing_all_reset();
220 
221 extern void rock_the_mine_frame(void);
222 extern void smega_rock_stuff(void);
223 extern void init_smega_detonates(void);
224 #endif
225 }
226 #endif
227 
228 #ifdef dsx
229 namespace dsx {
230 void InitWeaponOrdering();
231 void CyclePrimary(player_info &);
232 void CycleSecondary(player_info &);
233 void ReorderPrimary();
234 void ReorderSecondary();
235 #if defined(DXX_BUILD_DESCENT_II)
236 void check_to_use_primary_super_laser(player_info &player_info);
237 void init_seismic_disturbances(void);
238 void process_super_mines_frame(void);
239 void do_seismic_stuff();
240 #endif
241 void DropCurrentWeapon(player_info &);
242 void DropSecondaryWeapon(player_info &);
243 }
244 #endif
245 
246 #endif
247