Debian Codegraph @

common/main/robot.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 * Header for robot.c
23 *
24 */
25
26 #pragma once
27
28 #include <ranges>
29 #include "fwd-robot.h"
30 #include "game.h"
31
32 #include "pack.h"
33 #include "aistruct.h"
34 #include "weapon_id.h"
35 #include "object.h"
36 #include "fwd-partial_range.h"
37 #include "d_array.h"
38 #include "digi.h"
39
40 namespace dcx {
41
42 enum class robot_animation_state : uint8_t
43 {
44 rest,
45 alert,
46 fire,
47 recoil,
48 flinch,
49 };
50
51 enum class robot_gun_animation_index : uint8_t
52 {
53 /* Valid values are [0, MAX_GUNS]. */
54 None = UINT8_MAX,
55 };
56
57 enum class robot_id : uint8_t
58 {
59 brain = 7,
60 toaster = 10,
61 baby_spider = 14,
62 /* if DXX_BUILD_DESCENT == 2 */
63 energy_bandit = 44,
64 special_reactor = 65,
65 /* endif */
66 None = UINT8_MAX,
67 };
68
69 enum class boss_robot_id : uint8_t;
70
71 //describes the position of a certain joint
72 struct jointpos : prohibit_void_ptr<jointpos>
73 {
74 uint16_t jointnum;
75 vms_angvec angles;
76 };
77
78 //describes a list of joint positions
79 struct jointlist
80 {
81 short n_joints;
82 short offset;
83 };
84
85 struct d_level_shared_robot_joint_state {
86 unsigned N_robot_joints;
87 };
88
89 }
90
91 #ifdef DXX_BUILD_DESCENT
92 constexpr auto weapon_none = weapon_id_type::unspecified;
93
94 namespace dsx {
95
96 // Robot information
97 struct robot_info : prohibit_void_ptr<robot_info>
98 {
99 polygon_model_index model_num; // which polygon model?
100 enumerated_array<vms_vector, MAX_GUNS, robot_gun_number> gun_points; // where each gun model is
101 enumerated_array<uint8_t, MAX_GUNS, robot_gun_number> gun_submodels; // which submodel is each gun in?
102 uint16_t score_value; // Score from this robot.
103 vclip_index exp1_vclip_num;
104 vclip_index exp2_vclip_num;
105 sound_effect exp1_sound_num;
106 sound_effect exp2_sound_num;
107 weapon_id_type weapon_type;
108 uint8_t n_guns; // how many different gun positions
109 sbyte contains_prob; // Probability that this instance will contain something in N/16
110 contained_object_parameters contains; // Type of thing contained, robot or powerup, in bitmaps.tbl, !0=robot, 0=powerup
111 #if DXX_BUILD_DESCENT == 1
112 #elif DXX_BUILD_DESCENT == 2
113 sbyte kamikaze; // !0 means commits suicide when hits you, strength thereof. 0 means no.
114
115 sbyte badass; // Dies with badass explosion, and strength thereof, 0 means NO.
116 sbyte energy_drain; // Points of energy drained at each collision.
117 weapon_id_type weapon_type2; // Secondary weapon number, -1 means none, otherwise gun #0 fires this weapon.
118 #endif
119 fix lighting; // should this be here or with polygon model?
120 fix strength; // Initial shields of robot
121
122 fix mass; // how heavy is this thing?
123 fix drag; // how much drag does it have?
124
125 enumerated_array<fix, NDL, Difficulty_level_type> field_of_view, // compare this value with forward_vector.dot.vector_to_player, if field_of_view <, then robot can see player
126 firing_wait, // time in seconds between shots
127 #if DXX_BUILD_DESCENT == 2
128 firing_wait2, // time in seconds between shots
129 #endif
130 turn_time, // time in seconds to rotate 360 degrees in a dimension
131 max_speed, // maximum speed attainable by this robot
132 circle_distance; // distance at which robot circles player
133
134 enumerated_array<int8_t, NDL, Difficulty_level_type> rapidfire_count, // number of shots fired rapidly
135 evade_speed; // rate at which robot can evade shots, 0=none, 4=very fast
136 sbyte cloak_type; // 0=never, 1=always, 2=except-when-firing
137 sbyte attack_type; // 0=firing, 1=charge (like green guy)
138
139 sound_effect see_sound; // sound robot makes when it first sees the player
140 sound_effect attack_sound; // sound robot makes when it attacks the player
141 sound_effect claw_sound; // sound robot makes as it claws you (attack_type should be 1)
142 boss_robot_id boss_flag; // 0 = not boss, 1 = boss. Is that surprising?
143 #if DXX_BUILD_DESCENT == 2
144 sound_effect taunt_sound; // sound robot makes after you die
145
146 sbyte companion; // Companion robot, leads you to things.
147 sbyte smart_blobs; // how many smart blobs are emitted when this guy dies!
148 sbyte energy_blobs; // how many smart blobs are emitted when this guy gets hit by energy weapon!
149
150 sbyte thief; // !0 means this guy can steal when he collides with you!
151 sbyte pursuit; // !0 means pursues player after he goes around a corner. 4 = 4/2 pursue up to 4/2 seconds after becoming invisible if up to 4 segments away
152 sbyte lightcast; // Amount of light cast. 1 is default. 10 is very large.
153 sbyte death_roll; // 0 = dies without death roll. !0 means does death roll, larger = faster and louder
154
155 //boss_flag, companion, thief, & pursuit probably should also be bits in the flags byte.
156 ubyte flags; // misc properties
157
158 sound_effect deathroll_sound; // if has deathroll, what sound?
159 ubyte glow; // apply this light to robot itself. stored as 4:4 fixed-point
160 ai_behavior behavior; // Default behavior.
161 ubyte aim; // 255 = perfect, less = more likely to miss. 0 != random, would look stupid. 0=45 degree spread. Specify in bitmaps.tbl in range 0.0..1.0
162 #endif
163 //animation info
164 enumerated_array<enumerated_array<jointlist, N_ANIM_STATES, robot_animation_state>, MAX_GUNS + 1, robot_gun_animation_index> anim_states;
165 int always_0xabcd; // debugging
166 };
167
168 #if DXX_BUILD_DESCENT == 1
169 static inline int robot_is_companion(const robot_info &)
170 {
171 return 0;
172 }
173
174 static inline int robot_is_thief(const robot_info &)
175 {
176 return 0;
177 }
178 #elif DXX_BUILD_DESCENT == 2
179 static inline int robot_is_companion(const robot_info &robptr)
180 {
181 return robptr.companion;
182 }
183
184 static inline int robot_is_thief(const robot_info &robptr)
185 {
186 return robptr.thief;
187 }
188 #endif
189
190 //the array of robots types
191 struct d_level_shared_robot_info_state
192 {
193 //how many kinds of robots
194 unsigned N_robot_types; // Number of robot types. We used to assume this was the same as N_polygon_models.
195 // Robot info for AI system, loaded from bitmaps.tbl.
196 d_robot_info_array Robot_info;
197 };
198
199 #if DXX_BUILD_DESCENT == 2
200 // returns ptr to escort robot, or NULL
201 imobjptridx_t find_escort(fvmobjptridx &vmobjptridx, const d_robot_info_array &Robot_info);
202 #endif
203
204 imobjptridx_t robot_create(const d_robot_info_array &Robot_info, robot_id id, vmsegptridx_t segnum, const vms_vector &pos, const vms_matrix *orient, fix size, ai_behavior behavior, const imsegidx_t hide_segment = segment_none);
205 void recreate_thief(const d_robot_info_array &Robot_info, robot_id thief_id);
206
207 // Drops objects contained in objp.
208 bool object_create_robot_egg(const d_robot_info_array &Robot_info, object_base &objp);
209 bool object_create_robot_egg(const d_robot_info_array &Robot_info, contained_object_type type, contained_object_id id, unsigned num, const vms_vector &init_vel, const vms_vector &pos, vmsegptridx_t segnum);
210
211 // Create a matcen robot
212 imobjptridx_t create_morph_robot(const d_robot_info_array &Robot_info, vmsegptridx_t segp, const vms_vector &object_pos, robot_id object_id);
213
214 // do whatever this thing does in a frame
215 void do_controlcen_frame(const d_robot_info_array &Robot_info, vmobjptridx_t obj);
216
217 window_event_result multi_message_input_sub(const d_robot_info_array &Robot_info, int key, control_info &Controls);
218
219 /* Robot joints can be customized by hxm files, which are per-level.
220 */
221 struct d_level_shared_robot_joint_state : ::dcx::d_level_shared_robot_joint_state
222 {
223 //Big array of joint positions. All robots index into this array
224 std::array<jointpos, MAX_ROBOT_JOINTS> Robot_joints;
225 };
226
227 // Tells joint positions for a gun to be in a specified state.
228 // A gun can have associated with it any number of joints. In order to tell whether a gun is a certain
229 // state (such as FIRE or ALERT), you should call this function and check the returned joint positions
230 // against the robot's gun's joint positions. This function should also be called to determine how to
231 // move a gun into a desired position.
232 // For now (May 30, 1994), it is assumed that guns will linearly interpolate from one joint position to another.
233 // There is no ordering of joint movement, so it's impossible to guarantee that a strange starting position won't
234 // cause a gun to move through a robot's body, for example.
235
236 // Given:
237 // jp_list_ptr pointer to list of joint angles, on exit, this is pointing at a static array
238 // robot_type type of robot for which to get joint information. A particular type, not an instance of a robot.
239 // gun_num gun number. If in 0..Robot_info[robot_type].n_guns-1, then it is a gun, else it refers to non-animating parts of robot.
240 // state state about which to get information. Legal states in range 0..N_ANIM_STATES-1, defined in robot.h, are:
241 // robot_animation_state::rest, robot_animation_state::alert, robot_animation_state::fire, robot_animation_state::recoil, robot_animation_state::flinch
242
243 // On exit:
244 // Returns number of joints in list.
245 // jp_list_ptr is stuffed with a pointer to a static array of joint positions. This pointer is valid forever.
246 std::ranges::subrange<const jointpos *> robot_get_anim_state(const d_robot_info_array &, const std::array<jointpos, MAX_ROBOT_JOINTS> &, robot_id robot_type, robot_gun_animation_index gun_num, robot_animation_state state);
247
248 /*
249 * reads n robot_info structs from a PHYSFS_File
250 */
251 }
252 #endif
253
254 #if 0
255 void jointpos_write(PHYSFS_File *fp, const jointpos &jp);
256 #endif
257 #ifdef DXX_BUILD_DESCENT
258 namespace dsx {
259
260 static inline void boss_link_see_sound(const d_robot_info_array &Robot_info, const vcobjptridx_t objp)
261 {
262 #if DXX_BUILD_DESCENT == 1
263 (void)Robot_info;
264 constexpr auto soundnum{sound_effect::SOUND_BOSS_SHARE_SEE};
265 #elif DXX_BUILD_DESCENT == 2
266 const auto soundnum{Robot_info[get_robot_id(objp)].see_sound};
267 #endif
268 digi_link_sound_to_object2(soundnum, objp, 1, F1_0, sound_stack::allow_stacking, vm_distance{F1_0*512}); // F1_0*512 means play twice as loud
269 }
270 }
271 #endif