Debian Codegraph @

common/main/fwd-weapon.h

raw
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 #include "pack.h"
29 #include "pstypes.h"
30 #include "maths.h"
31 #include "dxxsconf.h"
32 #include "dsx-ns.h"
33 #include "kconfig.h"
34 #include "weapon_id.h"
35
36 #include "fwd-player.h"
37 #include "fwd-powerup.h"
38
39 #ifdef DXX_BUILD_DESCENT
40 #if DXX_BUILD_DESCENT == 2
41 #define MAX_SUPER_LASER_LEVEL laser_level::_6 // Note, laser levels are numbered from 0.
42 #endif
43
44 struct PHYSFS_File;
45 #if 0
46 void weapon_info_write(PHYSFS_File *, const weapon_info &);
47 #endif
48
49 namespace dcx {
50 enum class laser_level : uint8_t;
51 enum class has_primary_weapon_result : uint8_t;
52 enum class has_secondary_weapon_result : bool;
53 }
54
55 namespace dsx {
56 struct weapon_info;
57
58 #define REARM_TIME (F1_0)
59
60 #define WEAPON_DEFAULT_LIFETIME (F1_0*12) // Lifetime of an object if a bozo forgets to define it.
61
62 #define WEAPON_RENDER_NONE weapon_info::render_type::None
63 #define WEAPON_RENDER_LASER weapon_info::render_type::laser
64 #define WEAPON_RENDER_BLOB weapon_info::render_type::blob
65 #define WEAPON_RENDER_POLYMODEL weapon_info::render_type::polymodel
66 #define WEAPON_RENDER_VCLIP weapon_info::render_type::vclip
67
68 #if DXX_BUILD_DESCENT == 1
69 constexpr std::integral_constant<unsigned, 30> MAX_WEAPON_TYPES{};
70
71 constexpr std::integral_constant<unsigned, 5> MAX_PRIMARY_WEAPONS{};
72 constexpr std::integral_constant<unsigned, 5> MAX_SECONDARY_WEAPONS{};
73
74 #elif DXX_BUILD_DESCENT == 2
75 // weapon info flags
76 #define WIF_PLACABLE 1 // can be placed by level designer
77 constexpr std::integral_constant<unsigned, 70> MAX_WEAPON_TYPES{};
78
79 constexpr std::integral_constant<unsigned, 10> MAX_PRIMARY_WEAPONS{};
80 constexpr std::integral_constant<unsigned, 10> MAX_SECONDARY_WEAPONS{};
81
82 enum class pig_hamfile_version : uint8_t;
83 extern pig_hamfile_version Piggy_hamfile_version;
84 #endif
85
86 enum class primary_weapon_index_t : uint8_t;
87 enum class secondary_weapon_index_t : uint8_t;
88
89 extern const enumerated_array<weapon_id_type, MAX_PRIMARY_WEAPONS, primary_weapon_index_t> Primary_weapon_to_weapon_info;
90 //for each primary weapon, what kind of powerup gives weapon
91 extern const enumerated_array<powerup_type_t, MAX_PRIMARY_WEAPONS, primary_weapon_index_t> Primary_weapon_to_powerup;
92 extern const enumerated_array<weapon_id_type, MAX_SECONDARY_WEAPONS, secondary_weapon_index_t> Secondary_weapon_to_weapon_info;
93 //for each Secondary weapon, what kind of powerup gives weapon
94 extern const enumerated_array<powerup_type_t, MAX_SECONDARY_WEAPONS, secondary_weapon_index_t> Secondary_weapon_to_powerup;
95 extern const enumerated_array<uint8_t, MAX_SECONDARY_WEAPONS, secondary_weapon_index_t> Secondary_ammo_max;
96 /*
97 * reads n weapon_info structs from a PHYSFS_File
98 */
99 using weapon_info_array = std::array<weapon_info, MAX_WEAPON_TYPES>;
100 extern weapon_info_array Weapon_info;
101 void weapon_info_read_n(weapon_info_array &wi, std::size_t count, NamedPHYSFS_File fp,
102 #if DXX_BUILD_DESCENT == 2
103 pig_hamfile_version file_version,
104 #endif
105 std::size_t offset);
106
107 // Weapon flags, if player->weapon_flags & WEAPON_FLAG is set, then the player has this weapon
108 #define HAS_LASER_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::LASER_INDEX)
109 #define HAS_VULCAN_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::VULCAN_INDEX)
110 #define HAS_SPREADFIRE_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::SPREADFIRE_INDEX)
111 #define HAS_PLASMA_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::PLASMA_INDEX)
112 #define HAS_FUSION_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::FUSION_INDEX)
113
114 #define NUM_SMART_CHILDREN 6 // Number of smart children created by default.
115 #if DXX_BUILD_DESCENT == 1
116 #define NUM_SHAREWARE_WEAPONS 3 //in shareware, old get first 3 of each
117 #elif DXX_BUILD_DESCENT == 2
118 #define HAS_SUPER_LASER_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::SUPER_LASER_INDEX)
119 #define HAS_GAUSS_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::GAUSS_INDEX)
120 #define HAS_HELIX_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::HELIX_INDEX)
121 #define HAS_PHOENIX_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::PHOENIX_INDEX)
122 #define HAS_OMEGA_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::OMEGA_INDEX)
123 #define SUPER_WEAPON 5
124
125 static constexpr bool is_super_weapon(const primary_weapon_index_t i)
126 {
127 return static_cast<unsigned>(i) >= SUPER_WEAPON;
128 }
129
130 static constexpr bool is_super_weapon(const secondary_weapon_index_t i)
131 {
132 return static_cast<unsigned>(i) >= SUPER_WEAPON;
133 }
134
135 //flags whether the last time we use this weapon, it was the 'super' version
136 #endif
137 //for each Secondary weapon, which gun it fires out of
138 extern const enumerated_array<player_gun_number, MAX_SECONDARY_WEAPONS, secondary_weapon_index_t> Secondary_weapon_to_gun_num;
139 }
140
141 namespace dcx {
142 extern unsigned N_weapon_types;
143 template <typename T>
144 class player_selected_weapon : public prohibit_void_ptr<player_selected_weapon<T>>
145 {
146 T active, delayed;
147 public:
148 operator T() const
149 {
150 return get_active();
151 }
152 T get_active() const
153 {
154 return active;
155 }
156 T get_delayed() const
157 {
158 return delayed;
159 }
160 player_selected_weapon &operator=(T v)
161 {
162 active = v;
163 set_delayed(v);
164 return *this;
165 }
166 void set_delayed(T v)
167 {
168 delayed = v;
169 }
170 };
171
172 }
173 #ifdef DXX_BUILD_DESCENT
174 namespace dsx {
175
176 struct player_info;
177 void do_primary_weapon_select(player_info &, primary_weapon_index_t weapon_num);
178 void do_secondary_weapon_select(player_info &, secondary_weapon_index_t weapon_num);
179 void auto_select_primary_weapon(player_info &);
180 void auto_select_secondary_weapon(player_info &);
181 void set_primary_weapon(player_info &, primary_weapon_index_t weapon_num);
182 void select_primary_weapon(player_info &, const char *weapon_name, primary_weapon_index_t weapon_num, int wait_for_rearm);
183 void set_secondary_weapon_to_concussion(player_info &);
184 void select_secondary_weapon(player_info &, const char *weapon_name, secondary_weapon_index_t weapon_num, int wait_for_rearm);
185
186 }
187 #endif
188
189 //-----------------------------------------------------------------------------
190 // Return:
191 // Bits set:
192 // HAS_WEAPON_FLAG
193 // HAS_ENERGY_FLAG
194 // HAS_AMMO_FLAG
195 #ifdef DXX_BUILD_DESCENT
196 namespace dsx {
197 has_primary_weapon_result player_has_primary_weapon(const player_info &, primary_weapon_index_t weapon_num);
198 has_secondary_weapon_result player_has_secondary_weapon(const player_info &, secondary_weapon_index_t weapon_num);
199
200 //called when one of these weapons is picked up
201 //when you pick up a secondary, you always get the weapon & ammo for it
202 int pick_up_primary(player_info &, primary_weapon_index_t weapon_index);
203 int pick_up_secondary(player_info &, secondary_weapon_index_t weapon_index, int count, const control_info &Controls);
204
205 //called when a primary weapon is picked up
206 //returns true if actually picked up
207 }
208 #endif
209
210 //called when ammo (for the vulcan cannon) is picked up
211
212 namespace dsx {
213 int pick_up_vulcan_ammo(player_info &player_info, uint_fast32_t ammo_count, bool change_weapon = true);
214 //this function is for when the player intentionally drops a powerup
215 imobjptridx_t spit_powerup(d_level_unique_object_state &LevelUniqueObjectState, const d_level_shared_segment_state &LevelSharedSegmentState, d_level_unique_segment_state &LevelUniqueSegmentState, const d_vclip_array &Vclip, const object_base &spitter, powerup_type_t id, unsigned seed);
216
217 #if DXX_BUILD_DESCENT == 2
218 void attempt_to_steal_item(vmobjptridx_t objp, const robot_info &, object &playerobjp);
219
220 #define SMEGA_ID 40
221
222 void weapons_homing_all();
223 void weapons_homing_all_reset();
224
225 extern void rock_the_mine_frame(void);
226 extern void smega_rock_stuff(void);
227 extern void init_smega_detonates(void);
228 #endif
229 }
230
231 namespace dsx {
232 void InitWeaponOrdering();
233 void CyclePrimary(player_info &);
234 void CycleSecondary(player_info &);
235 void ReorderPrimary();
236 void ReorderSecondary();
237 #if DXX_BUILD_DESCENT == 2
238 void check_to_use_primary_super_laser(player_info &player_info);
239 void init_seismic_disturbances(void);
240 void process_super_mines_frame(void);
241 void do_seismic_stuff();
242 #endif
243 void DropCurrentWeapon(player_info &);
244 void DropSecondaryWeapon(player_info &);
245 }
246 #endif