| 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 |
* object system definitions |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
#pragma once |
| 27 |
|
| 28 |
#include <type_traits> |
| 29 |
#include "dsx-ns.h" |
| 30 |
#ifdef DXX_BUILD_DESCENT |
| 31 |
|
| 32 |
#include "pstypes.h" |
| 33 |
#include "vecmat.h" |
| 34 |
#include "aistruct.h" |
| 35 |
#include "polyobj.h" |
| 36 |
|
| 37 |
#include <cassert> |
| 38 |
#include <cstdint> |
| 39 |
#include "dxxsconf.h" |
| 40 |
#include "valptridx.h" |
| 41 |
#include "objnum.h" |
| 42 |
#include "fwd-segment.h" |
| 43 |
#include <vector> |
| 44 |
#include <stdexcept> |
| 45 |
#include "fwd-object.h" |
| 46 |
#include "fwd-robot.h" |
| 47 |
#include "fwd-weapon.h" |
| 48 |
#include "fwd-player.h" |
| 49 |
#include "powerup.h" |
| 50 |
#include "compiler-poison.h" |
| 51 |
#include "physics_info.h" |
| 52 |
#include "player-flags.h" |
| 53 |
#if DXX_BUILD_DESCENT == 2 |
| 54 |
#include "escort.h" |
| 55 |
#endif |
| 56 |
#include <array> |
| 57 |
#include <utility> |
| 58 |
|
| 59 |
namespace dcx { |
| 60 |
|
| 61 |
// Object types |
| 62 |
enum object_type_t : uint8_t |
| 63 |
{ |
| 64 |
OBJ_NONE = 255, // unused object |
| 65 |
OBJ_WALL = 0, // A wall... not really an object, but used for collisions |
| 66 |
OBJ_FIREBALL = 1, // a fireball, part of an explosion |
| 67 |
OBJ_ROBOT = 2, // an evil enemy |
| 68 |
OBJ_HOSTAGE = 3, // a hostage you need to rescue |
| 69 |
OBJ_PLAYER = 4, // the player on the console |
| 70 |
OBJ_WEAPON = 5, // a laser, missile, etc |
| 71 |
OBJ_CAMERA = 6, // a camera to slew around with |
| 72 |
OBJ_POWERUP = 7, // a powerup you can pick up |
| 73 |
OBJ_DEBRIS = 8, // a piece of robot |
| 74 |
OBJ_CNTRLCEN = 9, // the control center |
| 75 |
OBJ_CLUTTER = 11, // misc objects |
| 76 |
OBJ_GHOST = 12, // what the player turns into when dead |
| 77 |
OBJ_LIGHT = 13, // a light source, & not much else |
| 78 |
OBJ_COOP = 14, // a cooperative player object. |
| 79 |
/* if DXX_BUILD_DESCENT == 2 */ |
| 80 |
OBJ_MARKER = 15, // a map marker |
| 81 |
/* endif */ |
| 82 |
}; |
| 83 |
|
| 84 |
enum class render_type : uint8_t |
| 85 |
{ |
| 86 |
RT_NONE = 0, // does not render |
| 87 |
RT_POLYOBJ = 1, // a polygon model |
| 88 |
RT_FIREBALL = 2, // a fireball |
| 89 |
RT_LASER = 3, // a laser |
| 90 |
RT_HOSTAGE = 4, // a hostage |
| 91 |
RT_POWERUP = 5, // a powerup |
| 92 |
RT_MORPH = 6, // a robot being morphed |
| 93 |
RT_WEAPON_VCLIP = 7, // a weapon that renders as a vclip |
| 94 |
}; |
| 95 |
|
| 96 |
enum class contained_object_type : uint8_t |
| 97 |
{ |
| 98 |
None, |
| 99 |
robot = object_type_t::OBJ_ROBOT, |
| 100 |
powerup = object_type_t::OBJ_POWERUP, |
| 101 |
}; |
| 102 |
|
| 103 |
static inline bool valid_render_type(const uint8_t r) |
| 104 |
{ |
| 105 |
switch (r) |
| 106 |
{ |
| 107 |
case static_cast<uint8_t>(render_type::RT_NONE): |
| 108 |
case static_cast<uint8_t>(render_type::RT_POLYOBJ): |
| 109 |
case static_cast<uint8_t>(render_type::RT_FIREBALL): |
| 110 |
case static_cast<uint8_t>(render_type::RT_LASER): |
| 111 |
case static_cast<uint8_t>(render_type::RT_HOSTAGE): |
| 112 |
case static_cast<uint8_t>(render_type::RT_POWERUP): |
| 113 |
case static_cast<uint8_t>(render_type::RT_MORPH): |
| 114 |
case static_cast<uint8_t>(render_type::RT_WEAPON_VCLIP): |
| 115 |
return true; |
| 116 |
default: |
| 117 |
return false; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
#ifdef DXX_BUILD_DESCENT |
| 122 |
union contained_object_id |
| 123 |
{ |
| 124 |
powerup_type_t powerup; |
| 125 |
robot_id robot; |
| 126 |
}; |
| 127 |
|
| 128 |
struct contained_object_parameters |
| 129 |
{ |
| 130 |
contained_object_type type; // Type of object this robot contains (eg, spider contains powerup) |
| 131 |
contained_object_id id; // ID of object this robot contains (eg, id = blue type = key) |
| 132 |
uint8_t count; // number of objects of type:id this robot contains |
| 133 |
}; |
| 134 |
#endif |
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
namespace dsx { |
| 139 |
|
| 140 |
/* |
| 141 |
* STRUCTURES |
| 142 |
*/ |
| 143 |
|
| 144 |
struct reactor_static { |
| 145 |
/* Location of the gun on the reactor object */ |
| 146 |
std::array<vms_vector, MAX_CONTROLCEN_GUNS> gun_pos, |
| 147 |
/* Orientation of the gun on the reactor object */ |
| 148 |
gun_dir; |
| 149 |
}; |
| 150 |
|
| 151 |
struct player_info |
| 152 |
{ |
| 153 |
fix energy; // Amount of energy remaining. |
| 154 |
fix homing_object_dist; // Distance of nearest homing object. |
| 155 |
fix Fusion_charge; |
| 156 |
#if DXX_BUILD_DESCENT == 2 |
| 157 |
fix Omega_charge; |
| 158 |
fix Omega_recharge_delay; |
| 159 |
#endif |
| 160 |
player_flags powerup_flags; |
| 161 |
objnum_t killer_objnum; // Who killed me.... (-1 if no one) |
| 162 |
uint16_t vulcan_ammo; |
| 163 |
#if DXX_BUILD_DESCENT == 1 |
| 164 |
using primary_weapon_flag_type = uint8_t; |
| 165 |
#elif DXX_BUILD_DESCENT == 2 |
| 166 |
using primary_weapon_flag_type = uint16_t; |
| 167 |
#endif |
| 168 |
primary_weapon_flag_type primary_weapon_flags; |
| 169 |
bool Player_eggs_dropped; |
| 170 |
bool FakingInvul; |
| 171 |
bool lavafall_hiss_playing; |
| 172 |
uint8_t missile_gun; |
| 173 |
player_selected_weapon<primary_weapon_index_t> Primary_weapon; |
| 174 |
player_selected_weapon<secondary_weapon_index_t> Secondary_weapon; |
| 175 |
enum laser_level laser_level; |
| 176 |
enumerated_array<uint8_t, MAX_SECONDARY_WEAPONS, secondary_weapon_index_t> secondary_ammo; // How much ammo of each type. |
| 177 |
uint8_t Spreadfire_toggle; |
| 178 |
#if DXX_BUILD_DESCENT == 2 |
| 179 |
static constexpr uint8_t max_hoard_orbs{12}; |
| 180 |
uint8_t Primary_last_was_super; |
| 181 |
uint8_t Secondary_last_was_super; |
| 182 |
uint8_t Helix_orientation; |
| 183 |
#endif |
| 184 |
int16_t net_killed_total; // Number of times killed total |
| 185 |
int16_t net_kills_total; // Number of net kills total |
| 186 |
int16_t KillGoalCount; // Num of players killed this level |
| 187 |
union { |
| 188 |
struct { |
| 189 |
int score; // Current score. |
| 190 |
int last_score; // Score at beginning of current level. |
| 191 |
uint16_t hostages_rescued_total; // Total number of hostages rescued. |
| 192 |
uint8_t hostages_on_board; |
| 193 |
} mission; |
| 194 |
struct { |
| 195 |
uint8_t orbs; |
| 196 |
} hoard; |
| 197 |
}; |
| 198 |
fix64 cloak_time; // Time cloaked |
| 199 |
fix64 invulnerable_time; // Time invulnerable |
| 200 |
fix64 Next_flare_fire_time; |
| 201 |
fix64 Next_laser_fire_time; |
| 202 |
fix64 Next_missile_fire_time; |
| 203 |
fix64 Last_bumped_local_player; |
| 204 |
fix64 Auto_fire_fusion_cannon_time; |
| 205 |
}; |
| 206 |
|
| 207 |
} |
| 208 |
|
| 209 |
namespace dcx { |
| 210 |
|
| 211 |
// A compressed form for sending crucial data |
| 212 |
struct shortpos : prohibit_void_ptr<shortpos> |
| 213 |
{ |
| 214 |
static constexpr unsigned velocity_precision_shift{12}; |
| 215 |
std::array<int8_t, 9> bytemat; |
| 216 |
int16_t xo, yo, zo; |
| 217 |
segnum_t segment; |
| 218 |
int16_t velx, vely, velz; |
| 219 |
}; |
| 220 |
|
| 221 |
// Another compressed form for object position, velocity, orientation and rotvel using quaternion |
| 222 |
struct quaternionpos |
| 223 |
{ |
| 224 |
using packed_size = std::integral_constant<std::size_t, sizeof(vms_quaternion) + sizeof(segnum_t) + (sizeof(vms_vector) * 3)>; |
| 225 |
vms_quaternion orient; |
| 226 |
vms_vector pos; |
| 227 |
segnum_t segment; |
| 228 |
vms_vector vel; |
| 229 |
vms_vector rotvel; |
| 230 |
}; |
| 231 |
|
| 232 |
// structures for different kinds of simulation |
| 233 |
|
| 234 |
struct laser_parent |
| 235 |
{ |
| 236 |
int16_t parent_type{}; // The type of the parent of this object |
| 237 |
objnum_t parent_num{}; // The object's parent's number |
| 238 |
object_signature_t parent_signature{}; // The object's parent's signature... |
| 239 |
}; |
| 240 |
|
| 241 |
struct laser_info : prohibit_void_ptr<laser_info>, laser_parent |
| 242 |
{ |
| 243 |
fix64 creation_time{0}; // Absolute time of creation. |
| 244 |
/* hitobj_pos specifies the next position to which a value should be |
| 245 |
* written. That position may have a defined value if the array has |
| 246 |
* wrapped, but should be treated as write-only in the general case. |
| 247 |
* |
| 248 |
* hitobj_count tells how many elements in hitobj_values[] are |
| 249 |
* valid. Its valid values are [0, hitobj_values.size()]. When |
| 250 |
* hitobj_count == hitobj_values.size(), hitobj_pos wraps around and |
| 251 |
* begins erasing the oldest elements first. |
| 252 |
*/ |
| 253 |
uint8_t hitobj_pos{}, hitobj_count{}; |
| 254 |
std::array<objnum_t, 83> hitobj_values{}; |
| 255 |
objnum_t track_goal{}; // Object this object is tracking. |
| 256 |
fix multiplier{}; // Power if this is a fusion bolt (or other super weapon to be added). |
| 257 |
uint_fast8_t test_set_hitobj(const vcobjidx_t o); |
| 258 |
uint_fast8_t test_hitobj(const vcobjidx_t o) const; |
| 259 |
icobjidx_t get_last_hitobj() const; |
| 260 |
void clear_hitobj() |
| 261 |
{ |
| 262 |
hitobj_pos = hitobj_count = 0; |
| 263 |
} |
| 264 |
void reset_hitobj(const icobjidx_t o) |
| 265 |
{ |
| 266 |
if (o == object_none) |
| 267 |
{ |
| 268 |
/* Adding object_none to the array is harmless, since |
| 269 |
* get_last_hitobj can return object_none for empty arrays. |
| 270 |
* However, by filtering it here (which is called only when |
| 271 |
* loading data into new objects), test_hitobj (which is |
| 272 |
* called every time the object strikes a potential target) |
| 273 |
* will not need to read a slot that is guaranteed not to |
| 274 |
* match. |
| 275 |
*/ |
| 276 |
clear_hitobj(); |
| 277 |
return; |
| 278 |
} |
| 279 |
/* Assume caller already poisoned the unused array elements */ |
| 280 |
hitobj_pos = hitobj_count = 1; |
| 281 |
hitobj_values[0] = o; |
| 282 |
} |
| 283 |
}; |
| 284 |
|
| 285 |
// Same as above but structure Savegames/Multiplayer objects expect |
| 286 |
struct laser_info_rw |
| 287 |
{ |
| 288 |
short parent_type; // The type of the parent of this object |
| 289 |
short parent_num; // The object's parent's number |
| 290 |
int parent_signature; // The object's parent's signature... |
| 291 |
fix creation_time; // Absolute time of creation. |
| 292 |
uint16_t last_hitobj; // For persistent weapons (survive object collision), object it most recently hit. |
| 293 |
short track_goal; // Object this object is tracking. |
| 294 |
fix multiplier; // Power if this is a fusion bolt (or other super weapon to be added). |
| 295 |
} __pack__; |
| 296 |
|
| 297 |
struct explosion_info : prohibit_void_ptr<explosion_info> |
| 298 |
{ |
| 299 |
fix spawn_time; // when lifeleft is < this, spawn another |
| 300 |
fix delete_time; // when to delete object |
| 301 |
objnum_t delete_objnum; // and what object to delete |
| 302 |
objnum_t attach_parent; // explosion is attached to this object |
| 303 |
objnum_t prev_attach; // previous explosion in attach list |
| 304 |
objnum_t next_attach; // next explosion in attach list |
| 305 |
}; |
| 306 |
|
| 307 |
struct explosion_info_rw |
| 308 |
{ |
| 309 |
fix spawn_time; // when lifeleft is < this, spawn another |
| 310 |
fix delete_time; // when to delete object |
| 311 |
short delete_objnum; // and what object to delete |
| 312 |
short attach_parent; // explosion is attached to this object |
| 313 |
short prev_attach; // previous explosion in attach list |
| 314 |
short next_attach; // next explosion in attach list |
| 315 |
} __pack__; |
| 316 |
|
| 317 |
struct light_info : prohibit_void_ptr<light_info> |
| 318 |
{ |
| 319 |
fix intensity; // how bright the light is |
| 320 |
}; |
| 321 |
|
| 322 |
struct light_info_rw |
| 323 |
{ |
| 324 |
fix intensity; // how bright the light is |
| 325 |
} __pack__; |
| 326 |
|
| 327 |
struct powerup_info : prohibit_void_ptr<powerup_info> |
| 328 |
{ |
| 329 |
int count; // how many/much we pick up (vulcan cannon only?) |
| 330 |
int flags; // spat by player? |
| 331 |
fix64 creation_time; // Absolute time of creation. |
| 332 |
}; |
| 333 |
|
| 334 |
} |
| 335 |
|
| 336 |
namespace dsx { |
| 337 |
|
| 338 |
struct powerup_info_rw |
| 339 |
{ |
| 340 |
int count; // how many/much we pick up (vulcan cannon only?) |
| 341 |
#if DXX_BUILD_DESCENT == 2 |
| 342 |
// Same as above but structure Savegames/Multiplayer objects expect |
| 343 |
fix creation_time; // Absolute time of creation. |
| 344 |
int flags; // spat by player? |
| 345 |
#endif |
| 346 |
} __pack__; |
| 347 |
|
| 348 |
} |
| 349 |
|
| 350 |
namespace dcx { |
| 351 |
|
| 352 |
struct vclip_info : prohibit_void_ptr<vclip_info> |
| 353 |
{ |
| 354 |
vclip_index vclip_num; |
| 355 |
fix frametime; |
| 356 |
uint8_t framenum; |
| 357 |
}; |
| 358 |
|
| 359 |
struct vclip_info_rw |
| 360 |
{ |
| 361 |
int vclip_num; |
| 362 |
fix frametime; |
| 363 |
sbyte framenum; |
| 364 |
} __pack__; |
| 365 |
|
| 366 |
// structures for different kinds of rendering |
| 367 |
|
| 368 |
struct polyobj_info : prohibit_void_ptr<polyobj_info> |
| 369 |
{ |
| 370 |
polygon_model_index model_num{};// which polygon model |
| 371 |
std::array<vms_angvec, MAX_SUBMODELS> anim_angles{}; // angles for each subobject |
| 372 |
int subobj_flags{0}; // specify which subobjs to draw |
| 373 |
int tmap_override{0}; // if this is not -1, map all face to this |
| 374 |
int alt_textures{0}; // if not -1, use these textures instead |
| 375 |
}; |
| 376 |
|
| 377 |
struct polyobj_info_rw |
| 378 |
{ |
| 379 |
int model_num; // which polygon model |
| 380 |
vms_angvec anim_angles[MAX_SUBMODELS]; // angles for each subobject |
| 381 |
int subobj_flags; // specify which subobjs to draw |
| 382 |
int tmap_override; // if this is not -1, map all face to this |
| 383 |
int alt_textures; // if not -1, use these textures instead |
| 384 |
} __pack__; |
| 385 |
|
| 386 |
struct object_base |
| 387 |
{ |
| 388 |
enum class control_type : uint8_t; |
| 389 |
enum class movement_type : uint8_t; |
| 390 |
object_signature_t signature; |
| 391 |
object_type_t type; // what type of object this is... robot, weapon, hostage, powerup, fireball |
| 392 |
ubyte id; // which form of object...which powerup, robot, etc. |
| 393 |
objnum_t next,prev; // id of next and previous connected object in Objects, -1 = no connection |
| 394 |
enum control_type control_source; // how this object is controlled |
| 395 |
enum movement_type movement_source; // how this object moves |
| 396 |
enum render_type render_type; // how this object renders |
| 397 |
ubyte flags; // misc flags |
| 398 |
segnum_t segnum; // segment number containing object |
| 399 |
objnum_t attached_obj; // number of attached fireball object |
| 400 |
vms_vector pos; // absolute x,y,z coordinate of center of object |
| 401 |
vms_matrix orient; // orientation of object in world |
| 402 |
fix size; // 3d size of object - for collision detection |
| 403 |
fix shields; // Starts at maximum, when <0, object dies.. |
| 404 |
contained_object_parameters contains; |
| 405 |
sbyte matcen_creator; // Materialization center that created this object, high bit set if matcen-created |
| 406 |
fix lifeleft; // how long until goes away, or 7fff if immortal |
| 407 |
// -- Removed, MK, 10/16/95, using lifeleft instead: int lightlevel; |
| 408 |
|
| 409 |
// movement info, determined by MOVEMENT_TYPE |
| 410 |
union movement_info { |
| 411 |
physics_info phys_info; // a physics object |
| 412 |
vms_vector spin_rate; // for spinning objects |
| 413 |
constexpr movement_info() : |
| 414 |
phys_info{} |
| 415 |
{ |
| 416 |
static_assert(sizeof(phys_info) == sizeof(*this), "insufficient initialization"); |
| 417 |
} |
| 418 |
} mtype; |
| 419 |
|
| 420 |
// render info, determined by RENDER_TYPE |
| 421 |
union render_info { |
| 422 |
struct polyobj_info pobj_info; // polygon model |
| 423 |
struct vclip_info vclip_info; // vclip |
| 424 |
constexpr render_info() : |
| 425 |
pobj_info{} |
| 426 |
{ |
| 427 |
static_assert(sizeof(pobj_info) == sizeof(*this), "insufficient initialization"); |
| 428 |
} |
| 429 |
} rtype; |
| 430 |
}; |
| 431 |
|
| 432 |
// Control types - what tells this object what do do |
| 433 |
enum class object_base::control_type : uint8_t |
| 434 |
{ |
| 435 |
None = 0, // doesn't move (or change movement) |
| 436 |
ai = 1, // driven by AI |
| 437 |
explosion = 2, // explosion sequencer |
| 438 |
flying = 4, // the player is flying |
| 439 |
slew = 5, // slewing |
| 440 |
flythrough = 6, // the flythrough system |
| 441 |
weapon = 9, // laser, etc. |
| 442 |
repaircen = 10, // under the control of the repair center |
| 443 |
morph = 11, // this object is being morphed |
| 444 |
debris = 12, // this is a piece of debris |
| 445 |
powerup = 13, // animating powerup blob |
| 446 |
light = 14, // doesn't actually do anything |
| 447 |
remote = 15, // controlled by another net player |
| 448 |
cntrlcen = 16, // the control center/main reactor |
| 449 |
}; |
| 450 |
|
| 451 |
enum class object_base::movement_type : uint8_t |
| 452 |
{ |
| 453 |
None = 0, // doesn't move |
| 454 |
physics = 1, // moves by physics |
| 455 |
spinning = 3, // this object doesn't move, just sits and spins |
| 456 |
}; |
| 457 |
|
| 458 |
} |
| 459 |
|
| 460 |
namespace dsx { |
| 461 |
|
| 462 |
#if DXX_BUILD_DESCENT == 2 |
| 463 |
struct laser_info : public ::dcx::laser_info |
| 464 |
{ |
| 465 |
fix64 last_afterburner_time{0}; // Time at which this object last created afterburner blobs. |
| 466 |
}; |
| 467 |
#endif |
| 468 |
|
| 469 |
struct object : public ::dcx::object_base |
| 470 |
{ |
| 471 |
// control info, determined by CONTROL_TYPE |
| 472 |
union control_info { |
| 473 |
constexpr control_info() : |
| 474 |
ai_info{} |
| 475 |
{ |
| 476 |
static_assert(sizeof(ai_info) == sizeof(*this), "insufficient initialization"); |
| 477 |
} |
| 478 |
struct laser_info laser_info; |
| 479 |
struct explosion_info expl_info; // NOTE: debris uses this also |
| 480 |
struct light_info light_info; // why put this here? Didn't know what else to do with it. |
| 481 |
struct powerup_info powerup_info; |
| 482 |
struct ai_static ai_info; |
| 483 |
struct reactor_static reactor_info; |
| 484 |
struct player_info player_info; |
| 485 |
} ctype; |
| 486 |
}; |
| 487 |
|
| 488 |
// Same as above but structure Savegames/Multiplayer objects expect |
| 489 |
struct object_rw |
| 490 |
{ |
| 491 |
int signature; // Every object ever has a unique signature... |
| 492 |
ubyte type; // what type of object this is... robot, weapon, hostage, powerup, fireball |
| 493 |
ubyte id; // which form of object...which powerup, robot, etc. |
| 494 |
short next,prev; // id of next and previous connected object in Objects, -1 = no connection |
| 495 |
ubyte control_source; // how this object is controlled |
| 496 |
ubyte movement_source; // how this object moves |
| 497 |
ubyte render_type; // how this object renders |
| 498 |
ubyte flags; // misc flags |
| 499 |
uint16_t segnum; // segment number containing object |
| 500 |
short attached_obj; // number of attached fireball object |
| 501 |
vms_vector pos; // absolute x,y,z coordinate of center of object |
| 502 |
vms_matrix orient; // orientation of object in world |
| 503 |
fix size; // 3d size of object - for collision detection |
| 504 |
fix shields; // Starts at maximum, when <0, object dies.. |
| 505 |
vms_vector last_pos; // where object was last frame |
| 506 |
sbyte contains_type; // Type of object this object contains (eg, spider contains powerup) |
| 507 |
sbyte contains_id; // ID of object this object contains (eg, id = blue type = key) |
| 508 |
sbyte contains_count; // number of objects of type:id this object contains |
| 509 |
sbyte matcen_creator; // Materialization center that created this object, high bit set if matcen-created |
| 510 |
fix lifeleft; // how long until goes away, or 7fff if immortal |
| 511 |
// -- Removed, MK, 10/16/95, using lifeleft instead: int lightlevel; |
| 512 |
|
| 513 |
// movement info, determined by MOVEMENT_TYPE |
| 514 |
union { |
| 515 |
physics_info_rw phys_info; // a physics object |
| 516 |
vms_vector spin_rate; // for spinning objects |
| 517 |
} __pack__ mtype ; |
| 518 |
|
| 519 |
// control info, determined by CONTROL_TYPE |
| 520 |
union { |
| 521 |
laser_info_rw laser_info; |
| 522 |
explosion_info_rw expl_info; // NOTE: debris uses this also |
| 523 |
ai_static_rw ai_info; |
| 524 |
light_info_rw light_info; // why put this here? Didn't know what else to do with it. |
| 525 |
powerup_info_rw powerup_info; |
| 526 |
} __pack__ ctype ; |
| 527 |
|
| 528 |
// render info, determined by RENDER_TYPE |
| 529 |
union { |
| 530 |
polyobj_info_rw pobj_info; // polygon model |
| 531 |
vclip_info_rw vclip_info; // vclip |
| 532 |
} __pack__ rtype; |
| 533 |
} __pack__; |
| 534 |
|
| 535 |
} |
| 536 |
|
| 537 |
static_assert(sizeof(object_rw) == 264); |
| 538 |
|
| 539 |
namespace dcx { |
| 540 |
|
| 541 |
struct obj_position |
| 542 |
{ |
| 543 |
vms_vector pos; // absolute x,y,z coordinate of center of object |
| 544 |
vms_matrix orient; // orientation of object in world |
| 545 |
segnum_t segnum; // segment number containing object |
| 546 |
}; |
| 547 |
|
| 548 |
} |
| 549 |
|
| 550 |
#define set_object_type(O,T) \ |
| 551 |
( DXX_BEGIN_COMPOUND_STATEMENT { \ |
| 552 |
object_base &dxx_object_type_ref = (O); \ |
| 553 |
const uint8_t &dxx_object_type_value = (T); \ |
| 554 |
assert( \ |
| 555 |
dxx_object_type_value == OBJ_NONE || \ |
| 556 |
dxx_object_type_value == OBJ_FIREBALL || \ |
| 557 |
dxx_object_type_value == OBJ_ROBOT || \ |
| 558 |
dxx_object_type_value == OBJ_HOSTAGE || \ |
| 559 |
dxx_object_type_value == OBJ_PLAYER || \ |
| 560 |
dxx_object_type_value == OBJ_WEAPON || \ |
| 561 |
dxx_object_type_value == OBJ_CAMERA || \ |
| 562 |
dxx_object_type_value == OBJ_POWERUP || \ |
| 563 |
dxx_object_type_value == OBJ_DEBRIS || \ |
| 564 |
dxx_object_type_value == OBJ_CNTRLCEN || \ |
| 565 |
dxx_object_type_value == OBJ_CLUTTER || \ |
| 566 |
dxx_object_type_value == OBJ_GHOST || \ |
| 567 |
dxx_object_type_value == OBJ_LIGHT || \ |
| 568 |
dxx_object_type_value == OBJ_COOP || \ |
| 569 |
dxx_object_type_value == OBJ_MARKER \ |
| 570 |
); \ |
| 571 |
dxx_object_type_ref.type = static_cast<object_type_t>(dxx_object_type_value); \ |
| 572 |
} DXX_END_COMPOUND_STATEMENT ) |
| 573 |
|
| 574 |
namespace dsx { |
| 575 |
|
| 576 |
template <typename T, std::size_t... N> |
| 577 |
constexpr std::array<T, sizeof...(N)> init_object_number_array(std::index_sequence<N...>) |
| 578 |
{ |
| 579 |
return {{((void)N, object_none)...}}; |
| 580 |
} |
| 581 |
|
| 582 |
} |
| 583 |
|
| 584 |
namespace dcx { |
| 585 |
|
| 586 |
unsigned laser_parent_is_matching_signature(const laser_parent &l, const object_base &o); |
| 587 |
|
| 588 |
struct d_level_unique_control_center_state |
| 589 |
{ |
| 590 |
uint8_t Control_center_destroyed; |
| 591 |
uint8_t Control_center_been_hit; |
| 592 |
uint8_t Control_center_present; |
| 593 |
player_visibility_state Control_center_player_been_seen; |
| 594 |
objnum_t Dead_controlcen_object_num; |
| 595 |
int Countdown_seconds_left; |
| 596 |
fix Countdown_timer; |
| 597 |
fix Frametime_until_next_fire; |
| 598 |
/* If the player is not dead, this stays 0. If the player is dead, |
| 599 |
* this accumulates FrameTime, up until it saturates. When it |
| 600 |
* saturates, the reactor stops firing. |
| 601 |
* |
| 602 |
* FIXME: The original game defined this in terms of "the player", |
| 603 |
* but reactors are present in multiplayer games. |
| 604 |
*/ |
| 605 |
fix Frametime_since_player_died; |
| 606 |
int Total_countdown_time; //in whole seconds |
| 607 |
}; |
| 608 |
|
| 609 |
struct d_level_unique_boss_state |
| 610 |
{ |
| 611 |
fix64 Last_gate_time; |
| 612 |
fix64 Boss_cloak_start_time; |
| 613 |
fix64 Last_teleport_time; |
| 614 |
fix64 Boss_dying_start_time; |
| 615 |
int8_t Boss_hit_this_frame; |
| 616 |
int8_t Boss_dying; |
| 617 |
int8_t Boss_dying_sound_playing; |
| 618 |
}; |
| 619 |
|
| 620 |
} |
| 621 |
|
| 622 |
#define Highest_object_index (Objects.get_count() - 1) |
| 623 |
|
| 624 |
namespace dsx { |
| 625 |
|
| 626 |
// initialize a new object. adds to the list for the given segment |
| 627 |
// returns the object number |
| 628 |
[[nodiscard]] |
| 629 |
imobjptridx_t obj_create(d_level_unique_object_state &LevelUniqueObjectState, const d_level_shared_segment_state &LevelSharedSegmentState, d_level_unique_segment_state &LevelUniqueSegmentState, object_type_t type, unsigned id, vmsegptridx_t segnum, const vms_vector &pos, const vms_matrix *orient, fix size, enum object::control_type ctype, enum object::movement_type mtype, render_type rtype); |
| 630 |
|
| 631 |
[[nodiscard]] |
| 632 |
imobjptridx_t obj_weapon_create(d_level_unique_object_state &LevelUniqueObjectState, const d_level_shared_segment_state &LevelSharedSegmentState, d_level_unique_segment_state &LevelUniqueSegmentState, const weapon_info_array &Weapon_info, unsigned id, vmsegptridx_t segnum, const vms_vector &pos, fix size, render_type rtype); |
| 633 |
|
| 634 |
#if DXX_BUILD_DESCENT == 2 |
| 635 |
|
| 636 |
/* game_marker_index values are assigned as the object.id field for |
| 637 |
* marker objects, and are used as an index into most marker-related |
| 638 |
* arrays. These values are scoped to a single level. Each player |
| 639 |
* marker has a unique value for game_marker_index, computed based on |
| 640 |
* the player's ID and the player_marker_index active for that player |
| 641 |
* when the marker was created. |
| 642 |
*/ |
| 643 |
enum class game_marker_index : uint8_t |
| 644 |
{ |
| 645 |
GuidebotDeathSite = 10, |
| 646 |
None = UINT8_MAX |
| 647 |
}; |
| 648 |
|
| 649 |
/* player_marker_index are per-player marker indexes. Each player has |
| 650 |
* their own private number space. Valid values range from [0, |
| 651 |
* maxdrop), where maxdrop depends on the game type (single player, |
| 652 |
* competitive multiplayer, or cooperative multiplayer). |
| 653 |
*/ |
| 654 |
enum class player_marker_index : uint8_t |
| 655 |
{ |
| 656 |
_0, |
| 657 |
None = UINT8_MAX |
| 658 |
}; |
| 659 |
|
| 660 |
static inline game_marker_index &operator++(game_marker_index &i) |
| 661 |
{ |
| 662 |
auto u = static_cast<unsigned>(i); |
| 663 |
++ u; |
| 664 |
i = static_cast<game_marker_index>(u); |
| 665 |
return i; |
| 666 |
} |
| 667 |
|
| 668 |
static inline player_marker_index &operator++(player_marker_index &i) |
| 669 |
{ |
| 670 |
auto u = static_cast<unsigned>(i); |
| 671 |
++ u; |
| 672 |
i = static_cast<player_marker_index>(u); |
| 673 |
return i; |
| 674 |
} |
| 675 |
|
| 676 |
struct d_unique_buddy_state |
| 677 |
{ |
| 678 |
enum class Escort_goal_reachability : bool |
| 679 |
{ |
| 680 |
unreachable, |
| 681 |
reachable, |
| 682 |
}; |
| 683 |
icobjidx_t Buddy_objnum = object_none; |
| 684 |
icobjidx_t Escort_goal_objidx = object_none; |
| 685 |
Escort_goal_reachability Escort_goal_reachable = Escort_goal_reachability::unreachable; |
| 686 |
uint8_t Buddy_allowed_to_talk; |
| 687 |
uint8_t Buddy_messages_suppressed; |
| 688 |
uint8_t Buddy_gave_hint_count; |
| 689 |
game_marker_index Looking_for_marker; |
| 690 |
int Last_buddy_key; |
| 691 |
int Last_buddy_polish_path_tick; |
| 692 |
escort_goal_t Escort_goal_object; |
| 693 |
escort_goal_t Escort_special_goal; |
| 694 |
fix64 Buddy_sorry_time; |
| 695 |
fix64 Buddy_last_seen_player; |
| 696 |
fix64 Buddy_last_missile_time; |
| 697 |
fix64 Last_time_buddy_gave_hint; |
| 698 |
fix64 Last_come_back_message_time; |
| 699 |
fix64 Escort_last_path_created; |
| 700 |
fix64 Buddy_last_player_path_created; |
| 701 |
fix64 Last_buddy_message_time; |
| 702 |
}; |
| 703 |
|
| 704 |
struct d_level_unique_control_center_state : |
| 705 |
::dcx::d_level_unique_control_center_state |
| 706 |
{ |
| 707 |
fix64 Last_time_cc_vis_check; |
| 708 |
}; |
| 709 |
|
| 710 |
class d_guided_missile_indices : per_player_array<imobjidx_t> |
| 711 |
{ |
| 712 |
template <typename result_type, typename object_factory> |
| 713 |
result_type get_player_active_guided_missile_tmpl(object_factory &fvcobj, playernum_t pnum) const; |
| 714 |
static bool debug_check_current_object(const object_base &); |
| 715 |
public: |
| 716 |
constexpr d_guided_missile_indices() : |
| 717 |
per_player_array<imobjidx_t>(init_object_number_array<imobjidx_t>(std::make_index_sequence<MAX_PLAYERS>())) |
| 718 |
{ |
| 719 |
} |
| 720 |
imobjidx_t get_player_active_guided_missile(playernum_t pnum) const; |
| 721 |
imobjptr_t get_player_active_guided_missile(fvmobjptr &vmobjptr, playernum_t pnum) const; |
| 722 |
imobjptridx_t get_player_active_guided_missile(fvmobjptridx &vmobjptridx, playernum_t pnum) const; |
| 723 |
void set_player_active_guided_missile(vmobjidx_t, playernum_t pnum); |
| 724 |
void clear_player_active_guided_missile(playernum_t pnum); |
| 725 |
}; |
| 726 |
|
| 727 |
struct d_level_unique_boss_state : ::dcx::d_level_unique_boss_state |
| 728 |
{ |
| 729 |
fix64 Boss_hit_time; |
| 730 |
}; |
| 731 |
|
| 732 |
const player &get_player_controlling_guidebot(const d_unique_buddy_state & /* reserved for future use */, const valptridx<player>::array_managed_type &Players); |
| 733 |
#endif |
| 734 |
|
| 735 |
// after calling init_object(), the network code has grabbed specific |
| 736 |
// object slots without allocating them. Go though the objects & |
| 737 |
// build the free list, then set the appropriate globals. |
| 738 |
// Don't call this function unless you know what you're doing. |
| 739 |
void special_reset_objects(d_level_unique_object_state &, const d_robot_info_array &Robot_info); |
| 740 |
|
| 741 |
unsigned laser_parent_is_player(fvcobjptr &, const laser_parent &, const object_base &); |
| 742 |
unsigned laser_parent_is_object(fvcobjptr &, const laser_parent &, const object_base &); |
| 743 |
unsigned laser_parent_is_object(const laser_parent &, vcobjptridx_t); |
| 744 |
unsigned laser_parent_object_exists(fvcobjptr &, const laser_parent &); |
| 745 |
|
| 746 |
static inline powerup_type_t get_powerup_id(const object_base &o) |
| 747 |
{ |
| 748 |
return static_cast<powerup_type_t>(o.id); |
| 749 |
} |
| 750 |
|
| 751 |
static inline weapon_id_type get_weapon_id(const object_base &o) |
| 752 |
{ |
| 753 |
return static_cast<weapon_id_type>(o.id); |
| 754 |
} |
| 755 |
|
| 756 |
#if DXX_BUILD_DESCENT == 2 |
| 757 |
static inline game_marker_index get_marker_id(const object_base &o) |
| 758 |
{ |
| 759 |
return game_marker_index{o.id}; |
| 760 |
} |
| 761 |
#endif |
| 762 |
|
| 763 |
void set_powerup_id(const d_powerup_info_array &Powerup_info, const d_vclip_array &Vclip, object_base &o, powerup_type_t id); |
| 764 |
|
| 765 |
static inline void set_weapon_id(object_base &o, weapon_id_type id) |
| 766 |
{ |
| 767 |
o.id = static_cast<uint8_t>(id); |
| 768 |
} |
| 769 |
|
| 770 |
window_event_result dead_player_frame(const d_robot_info_array &Robot_info); |
| 771 |
|
| 772 |
// move all objects for the current frame |
| 773 |
window_event_result game_move_all_objects(const d_level_shared_robot_info_state &LevelSharedRobotInfoState); // moves all objects |
| 774 |
window_event_result endlevel_move_all_objects(const d_level_shared_robot_info_state &LevelSharedRobotInfoState); |
| 775 |
|
| 776 |
} |
| 777 |
|
| 778 |
namespace dcx { |
| 779 |
|
| 780 |
#ifdef DXX_BUILD_DESCENT |
| 781 |
contained_object_type build_contained_object_type_from_untrusted(uint8_t untrusted); |
| 782 |
contained_object_id build_contained_object_id_from_untrusted(contained_object_type, uint8_t untrusted); |
| 783 |
contained_object_parameters build_contained_object_parameters_from_untrusted(uint8_t type, uint8_t id, uint8_t count); |
| 784 |
#endif |
| 785 |
|
| 786 |
static inline unsigned get_player_id(const object_base &o) |
| 787 |
{ |
| 788 |
return o.id; |
| 789 |
} |
| 790 |
|
| 791 |
static inline uint8_t get_reactor_id(const object_base &o) |
| 792 |
{ |
| 793 |
return o.id; |
| 794 |
} |
| 795 |
|
| 796 |
static constexpr vclip_index get_fireball_id(const object_base &o) |
| 797 |
{ |
| 798 |
return vclip_index{o.id}; |
| 799 |
} |
| 800 |
|
| 801 |
static inline robot_id get_robot_id(const object_base &o) |
| 802 |
{ |
| 803 |
return robot_id{o.id}; |
| 804 |
} |
| 805 |
|
| 806 |
static inline void set_player_id(object_base &o, const uint8_t id) |
| 807 |
{ |
| 808 |
o.id = id; |
| 809 |
} |
| 810 |
|
| 811 |
static inline void set_reactor_id(object_base &o, const uint8_t id) |
| 812 |
{ |
| 813 |
o.id = id; |
| 814 |
} |
| 815 |
|
| 816 |
static inline void set_robot_id(object_base &o, const robot_id id) |
| 817 |
{ |
| 818 |
o.id = {static_cast<std::underlying_type<robot_id>::type>(id)}; |
| 819 |
} |
| 820 |
|
| 821 |
void check_warn_object_type(const object_base &, object_type_t, const char *file, unsigned line); |
| 822 |
#define get_player_id(O) (check_warn_object_type(O, OBJ_PLAYER, __FILE__, __LINE__), get_player_id(O)) |
| 823 |
#define get_powerup_id(O) (check_warn_object_type(O, OBJ_POWERUP, __FILE__, __LINE__), get_powerup_id(O)) |
| 824 |
#define get_reactor_id(O) (check_warn_object_type(O, OBJ_CNTRLCEN, __FILE__, __LINE__), get_reactor_id(O)) |
| 825 |
#define get_ghost_id(O) (check_warn_object_type(O, OBJ_GHOST, __FILE__, __LINE__), (get_player_id)(O)) |
| 826 |
#define get_fireball_id(O) (check_warn_object_type(O, OBJ_FIREBALL, __FILE__, __LINE__), get_fireball_id(O)) |
| 827 |
#define get_robot_id(O) (check_warn_object_type(O, OBJ_ROBOT, __FILE__, __LINE__), get_robot_id(O)) |
| 828 |
#define get_weapon_id(O) (check_warn_object_type(O, OBJ_WEAPON, __FILE__, __LINE__), get_weapon_id(O)) |
| 829 |
#if DXX_BUILD_DESCENT == 2 |
| 830 |
#define get_marker_id(O) (check_warn_object_type(O, OBJ_MARKER, __FILE__, __LINE__), get_marker_id(O)) |
| 831 |
#endif |
| 832 |
#define set_player_id(O,I) (check_warn_object_type(O, OBJ_PLAYER, __FILE__, __LINE__), set_player_id(O, I)) |
| 833 |
#define set_reactor_id(O,I) (check_warn_object_type(O, OBJ_CNTRLCEN, __FILE__, __LINE__), set_reactor_id(O, I)) |
| 834 |
#define set_robot_id(O,I) (check_warn_object_type(O, OBJ_ROBOT, __FILE__, __LINE__), set_robot_id(O, I)) |
| 835 |
#define set_weapon_id(O,I) (check_warn_object_type(O, OBJ_WEAPON, __FILE__, __LINE__), set_weapon_id(O, I)) |
| 836 |
#ifdef DXX_CONSTANT_TRUE |
| 837 |
#define check_warn_object_type(O,T,F,L) \ |
| 838 |
( DXX_BEGIN_COMPOUND_STATEMENT { \ |
| 839 |
const object_base &dxx_check_warn_o = (O); \ |
| 840 |
const auto dxx_check_warn_actual_type = dxx_check_warn_o.type; \ |
| 841 |
const auto dxx_check_warn_expected_type = (T); \ |
| 842 |
/* If the type is always right, omit the runtime check. */ \ |
| 843 |
DXX_CONSTANT_TRUE(dxx_check_warn_actual_type == dxx_check_warn_expected_type) || ( \ |
| 844 |
/* If the type is always wrong, force a compile-time error. */ \ |
| 845 |
DXX_CONSTANT_TRUE(dxx_check_warn_actual_type != dxx_check_warn_expected_type) \ |
| 846 |
? DXX_ALWAYS_ERROR_FUNCTION("object type mismatch") \ |
| 847 |
: ( \ |
| 848 |
check_warn_object_type(dxx_check_warn_o, dxx_check_warn_expected_type, F, L) \ |
| 849 |
) \ |
| 850 |
, 0); \ |
| 851 |
} DXX_END_COMPOUND_STATEMENT ) |
| 852 |
#endif |
| 853 |
|
| 854 |
} |
| 855 |
|
| 856 |
#endif |