| 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. |
| 6 |
* See COPYING.txt for license details. |
| 7 |
*/ |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include <type_traits> |
| 12 |
#include "dsx-ns.h" |
| 13 |
#include "objnum.h" |
| 14 |
#include "fwd-piggy.h" |
| 15 |
#include "fwd-vecmat.h" |
| 16 |
#include "fwd-segment.h" |
| 17 |
#include "fwd-window.h" |
| 18 |
#include "fwd-valptridx.h" |
| 19 |
#include "polyobj.h" |
| 20 |
#include <array> |
| 21 |
|
| 22 |
namespace dcx { |
| 23 |
|
| 24 |
// Movement types |
| 25 |
constexpr std::integral_constant<std::size_t, 350> MAX_OBJECTS{}; |
| 26 |
constexpr std::integral_constant<std::size_t, MAX_OBJECTS - 20> MAX_USED_OBJECTS{}; |
| 27 |
struct d_level_unique_control_center_state; |
| 28 |
|
| 29 |
// Render types |
| 30 |
enum class render_type : uint8_t; |
| 31 |
|
| 32 |
} |
| 33 |
|
| 34 |
#ifdef DXX_BUILD_DESCENT |
| 35 |
namespace dsx { |
| 36 |
struct object; |
| 37 |
struct d_level_unique_object_state; |
| 38 |
} |
| 39 |
DXX_VALPTRIDX_DECLARE_SUBTYPE(dsx::, object, objnum_t, MAX_OBJECTS); |
| 40 |
|
| 41 |
namespace dsx { |
| 42 |
DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS(object, obj); |
| 43 |
|
| 44 |
static constexpr valptridx<object>::magic_constant<objnum_t{0xffff}> object_none{}; |
| 45 |
static constexpr valptridx<object>::magic_constant<objnum_t{0}> object_first{}; |
| 46 |
|
| 47 |
#if DXX_BUILD_DESCENT == 1 |
| 48 |
constexpr std::integral_constant<unsigned, 15> MAX_OBJECT_TYPES{}; |
| 49 |
#elif DXX_BUILD_DESCENT == 2 |
| 50 |
constexpr std::integral_constant<unsigned, 16> MAX_OBJECT_TYPES{}; |
| 51 |
struct d_level_unique_control_center_state; |
| 52 |
#endif |
| 53 |
|
| 54 |
} |
| 55 |
#endif |
| 56 |
|
| 57 |
// misc object flags |
| 58 |
typedef unsigned object_flag_t; |
| 59 |
constexpr std::integral_constant<object_flag_t, 1> OF_EXPLODING{}; // this object is exploding |
| 60 |
constexpr std::integral_constant<object_flag_t, 2> OF_SHOULD_BE_DEAD{}; // this object should be dead, so next time we can, we should delete this object. |
| 61 |
constexpr std::integral_constant<object_flag_t, 4> OF_DESTROYED{}; // this has been killed, and is showing the dead version |
| 62 |
constexpr std::integral_constant<object_flag_t, 8> OF_SILENT{}; // this makes no sound when it hits a wall. Added by MK for weapons, if you extend it to other types, do it completely! |
| 63 |
constexpr std::integral_constant<object_flag_t, 16> OF_ATTACHED{}; // this object is a fireball attached to another object |
| 64 |
#ifdef DXX_BUILD_DESCENT |
| 65 |
#if DXX_BUILD_DESCENT == 2 |
| 66 |
constexpr std::integral_constant<object_flag_t, 64> OF_PLAYER_DROPPED{}; // this object was dropped by the player... |
| 67 |
#endif |
| 68 |
#endif |
| 69 |
|
| 70 |
// physics flags |
| 71 |
typedef unsigned physics_flag_t; |
| 72 |
constexpr std::integral_constant<physics_flag_t, 0x01> PF_TURNROLL{}; // roll when turning |
| 73 |
constexpr std::integral_constant<physics_flag_t, 0x02> PF_LEVELLING{}; // level object with closest side |
| 74 |
constexpr std::integral_constant<physics_flag_t, 0x04> PF_BOUNCE{}; // bounce (not slide) when hit will |
| 75 |
constexpr std::integral_constant<physics_flag_t, 0x08> PF_WIGGLE{}; // wiggle while flying |
| 76 |
constexpr std::integral_constant<physics_flag_t, 0x10> PF_STICK{}; // object sticks (stops moving) when hits wall |
| 77 |
constexpr std::integral_constant<physics_flag_t, 0x20> PF_PERSISTENT{}; // object keeps going even after it hits another object (eg, fusion cannon) |
| 78 |
constexpr std::integral_constant<physics_flag_t, 0x40> PF_USES_THRUST{}; // this object uses its thrust |
| 79 |
#ifdef DXX_BUILD_DESCENT |
| 80 |
#if DXX_BUILD_DESCENT == 2 |
| 81 |
constexpr std::integral_constant<physics_flag_t, 0x80> PF_BOUNCED_ONCE{}; // Weapon has bounced once. |
| 82 |
constexpr std::integral_constant<physics_flag_t, 0x100> PF_FREE_SPINNING{}; // Drag does not apply to rotation of this object |
| 83 |
constexpr std::integral_constant<physics_flag_t, 0x200> PF_BOUNCES_TWICE{}; // This weapon bounces twice, then dies |
| 84 |
#endif |
| 85 |
#endif |
| 86 |
|
| 87 |
namespace dcx { |
| 88 |
enum object_type_t : uint8_t; |
| 89 |
struct object_base; |
| 90 |
|
| 91 |
typedef unsigned powerup_flag_t; |
| 92 |
constexpr std::integral_constant<powerup_flag_t, 1> PF_SPAT_BY_PLAYER{}; //this powerup was spat by the player |
| 93 |
|
| 94 |
constexpr std::integral_constant<unsigned, 0x3fffffff> IMMORTAL_TIME{}; // Time assigned to immortal objects, about 32768 seconds, or about 9 hours. |
| 95 |
|
| 96 |
struct shortpos; |
| 97 |
struct quaternionpos; |
| 98 |
|
| 99 |
// This is specific to the shortpos extraction routines in gameseg.c. |
| 100 |
constexpr std::integral_constant<unsigned, 10> RELPOS_PRECISION{}; |
| 101 |
constexpr std::integral_constant<unsigned, 9> MATRIX_PRECISION{}; |
| 102 |
|
| 103 |
struct physics_info; |
| 104 |
struct physics_info_rw; |
| 105 |
|
| 106 |
struct laser_parent; |
| 107 |
struct laser_info_rw; |
| 108 |
|
| 109 |
struct explosion_info; |
| 110 |
struct explosion_info_rw; |
| 111 |
|
| 112 |
struct light_info; |
| 113 |
struct light_info_rw; |
| 114 |
|
| 115 |
struct powerup_info; |
| 116 |
|
| 117 |
struct vclip_info; |
| 118 |
struct vclip_info_rw; |
| 119 |
|
| 120 |
struct polyobj_info; |
| 121 |
struct polyobj_info_rw; |
| 122 |
|
| 123 |
struct obj_position; |
| 124 |
|
| 125 |
enum class collision_result : bool |
| 126 |
{ |
| 127 |
ignore = 0, // Ignore this collision |
| 128 |
check = 1, // Check for this collision |
| 129 |
}; |
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
#ifdef DXX_BUILD_DESCENT |
| 134 |
namespace dsx { |
| 135 |
|
| 136 |
#if DXX_BUILD_DESCENT == 1 |
| 137 |
constexpr std::size_t MAX_CONTROLCEN_GUNS{4}; |
| 138 |
#elif DXX_BUILD_DESCENT == 2 |
| 139 |
constexpr std::size_t MAX_CONTROLCEN_GUNS{8}; |
| 140 |
struct d_unique_buddy_state; |
| 141 |
#endif |
| 142 |
|
| 143 |
struct object_rw; |
| 144 |
struct powerup_info_rw; |
| 145 |
struct window_rendered_data; |
| 146 |
struct reactor_static; |
| 147 |
|
| 148 |
using collision_inner_array_t = std::array<collision_result, MAX_OBJECT_TYPES>; |
| 149 |
using collision_outer_array_t = std::array<collision_inner_array_t, MAX_OBJECT_TYPES>; |
| 150 |
extern const collision_outer_array_t CollisionResult; |
| 151 |
|
| 152 |
} |
| 153 |
#endif |
| 154 |
|
| 155 |
namespace dcx { |
| 156 |
extern int Num_robot_types; |
| 157 |
} |
| 158 |
|
| 159 |
#ifdef DXX_BUILD_DESCENT |
| 160 |
namespace dsx { |
| 161 |
extern object *ConsoleObject; // pointer to the object that is the player |
| 162 |
extern const object *Viewer; // which object we are seeing from |
| 163 |
extern object *Dead_player_camera; |
| 164 |
} |
| 165 |
#endif |
| 166 |
|
| 167 |
enum class player_dead_state : uint8_t |
| 168 |
{ |
| 169 |
no, |
| 170 |
yes, |
| 171 |
exploded, |
| 172 |
}; |
| 173 |
|
| 174 |
namespace dcx { |
| 175 |
|
| 176 |
extern player_dead_state Player_dead_state; // !0 means player is dead! |
| 177 |
extern objnum_t Player_fired_laser_this_frame; |
| 178 |
|
| 179 |
// create quaternion structure from object data which greatly saves bytes by using quaternion instead or orientation matrix |
| 180 |
[[nodiscard]] |
| 181 |
quaternionpos build_quaternionpos(const object_base &objp); |
| 182 |
|
| 183 |
// Extract information from an object (objp->orient, objp->pos, |
| 184 |
// objp->segnum), stuff in a shortpos structure. See typedef |
| 185 |
// shortpos. |
| 186 |
[[nodiscard]] |
| 187 |
shortpos create_shortpos_native(const d_level_shared_segment_state &, const object_base &objp); |
| 188 |
|
| 189 |
} |
| 190 |
|
| 191 |
#ifdef DXX_BUILD_DESCENT |
| 192 |
namespace dsx { |
| 193 |
// Draw a blob-type object, like a fireball |
| 194 |
void draw_object_blob(GameBitmaps_array &GameBitmaps, const object_base &Viewer, grs_canvas &, const object_base &obj, bitmap_index bitmap); |
| 195 |
|
| 196 |
// do whatever setup needs to be done |
| 197 |
void init_objects(); |
| 198 |
|
| 199 |
// when an object has moved into a new segment, this function unlinks it |
| 200 |
// from its old segment, and links it into the new segment |
| 201 |
void obj_relink(fvmobjptr &vmobjptr, fvmsegptr &vmsegptr, vmobjptridx_t objnum, vmsegptridx_t newsegnum); |
| 202 |
|
| 203 |
// for getting out of messed up linking situations (i.e. caused by demo playback) |
| 204 |
void obj_relink_all(); |
| 205 |
|
| 206 |
/* Link an object without checking whether the object is currently |
| 207 |
* unlinked. This should be used only in cases where the caller is |
| 208 |
* intentionally overriding the normal linking rules (such as loading |
| 209 |
* objects from demos or from the network). |
| 210 |
*/ |
| 211 |
void obj_link_unchecked(fvmobjptr &vmobjptr, vmobjptridx_t obj, vmsegptridx_t segnum); |
| 212 |
|
| 213 |
// unlinks an object from a segment's list of objects |
| 214 |
void obj_unlink(fvmobjptr &vmobjptr, fvmsegptr &vmsegptr, object_base &obj); |
| 215 |
|
| 216 |
// make a copy of an object. returs num of new object |
| 217 |
imobjptridx_t obj_create_copy(const object &srcobj, vmsegptridx_t newsegnum); |
| 218 |
|
| 219 |
// remove object from the world |
| 220 |
void obj_delete(d_level_unique_object_state &LevelUniqueObjectState, segment_array &Segments, vmobjptridx_t objnum); |
| 221 |
|
| 222 |
// called after load. Takes number of objects, and objects should be |
| 223 |
// compressed |
| 224 |
void reset_objects(d_level_unique_object_state &, unsigned n_objs); |
| 225 |
|
| 226 |
#if DXX_USE_EDITOR |
| 227 |
// make object array non-sparse |
| 228 |
void compress_objects(); |
| 229 |
#endif |
| 230 |
|
| 231 |
// set viewer object to next object in array |
| 232 |
void object_goto_next_viewer(const object_array &Objects, const object *&viewer); |
| 233 |
|
| 234 |
// make object0 the player, setting all relevant fields |
| 235 |
void init_player_object(const d_level_shared_polygon_model_state &LevelSharedPolygonModelState, object_base &console); |
| 236 |
|
| 237 |
// check if object is in object->segnum. if not, check the adjacent |
| 238 |
// segs. if not any of these, returns false, else sets obj->segnum & |
| 239 |
// returns true callers should really use find_vector_intersection() |
| 240 |
// Note: this function is in gameseg.c |
| 241 |
int update_object_seg(fvmobjptr &vmobjptr, const d_level_shared_segment_state &LevelSharedSegmentState, d_level_unique_segment_state &LevelUniqueSegmentState, vmobjptridx_t obj); |
| 242 |
|
| 243 |
// Finds what segment *obj is in, returns segment number. If not in |
| 244 |
// any segment, returns -1. Note: This function is defined in |
| 245 |
// gameseg.h, but object.h depends on gameseg.h, and object.h is where |
| 246 |
// object is defined...get it? |
| 247 |
imsegptridx_t find_object_seg(const d_level_shared_segment_state &, d_level_unique_segment_state &, const object_base &obj); |
| 248 |
|
| 249 |
// go through all objects and make sure they have the correct segment |
| 250 |
// numbers used when debugging is on |
| 251 |
void fix_object_segs(); |
| 252 |
|
| 253 |
void dead_player_end(); |
| 254 |
|
| 255 |
#if DXX_USE_MULTIPLAYER |
| 256 |
#if DXX_BUILD_DESCENT == 2 |
| 257 |
// Extract information from a shortpos, stuff in objp->orient |
| 258 |
// (matrix), objp->pos, objp->segnum |
| 259 |
void multi_object_warp_to_shortpos(vmobjptridx_t objp, const shortpos &spp); |
| 260 |
#endif |
| 261 |
|
| 262 |
// reset object position from quaternion structure |
| 263 |
void extract_quaternionpos(fvmobjptr &vmobjptr, fvmsegptr &vmsegptr, vmobjptridx_t objp, quaternionpos &qpp); |
| 264 |
#endif |
| 265 |
|
| 266 |
// delete objects, such as weapons & explosions, that shouldn't stay |
| 267 |
// between levels if clear_all is set, clear even proximity bombs |
| 268 |
void clear_transient_objects(int clear_all); |
| 269 |
|
| 270 |
// returns the number of a free object, updating Highest_object_index. |
| 271 |
// Generally, obj_create() should be called to get an object, since it |
| 272 |
// fills in important fields and does the linking. returns -1 if no |
| 273 |
// free objects |
| 274 |
[[nodiscard]] |
| 275 |
imobjptridx_t obj_allocate(d_level_unique_object_state &); |
| 276 |
|
| 277 |
// attaches an object, such as a fireball, to another object, such as |
| 278 |
// a robot |
| 279 |
void obj_attach(object_array &Objects, vmobjptridx_t parent, vmobjptridx_t sub); |
| 280 |
|
| 281 |
void create_small_fireball_on_object(vmobjptridx_t objp, fix size_scale, int sound_flag); |
| 282 |
|
| 283 |
#if DXX_BUILD_DESCENT == 2 |
| 284 |
extern int Drop_afterburner_blob_flag; //ugly hack |
| 285 |
enum class game_marker_index : uint8_t; |
| 286 |
enum class player_marker_index : uint8_t; |
| 287 |
// returns object number |
| 288 |
imobjptridx_t drop_marker_object(const vms_vector &pos, vmsegptridx_t segnum, const vms_matrix &orient, game_marker_index marker_num); |
| 289 |
|
| 290 |
void wake_up_rendered_objects(const object &gmissp, window_rendered_data &window); |
| 291 |
|
| 292 |
void fuelcen_check_for_goal(object &plrobj, const shared_segment &segp); |
| 293 |
#endif |
| 294 |
imobjptridx_t obj_find_first_of_type(fvmobjptridx &, object_type_t type); |
| 295 |
|
| 296 |
void object_rw_swap(struct object_rw *obj_rw, physfsx_endian swap); |
| 297 |
void reset_player_object(object_base &); |
| 298 |
|
| 299 |
} |
| 300 |
#endif |