2014-11-23 04:36:58 +00:00
/*
* Portions of this file are copyright Rebirth contributors and licensed as
* described in COPYING . txt .
* Portions of this file are copyright Parallax Software and licensed
* according to the Parallax license .
* See COPYING . txt for license details .
*/
# pragma once
2016-12-24 18:12:17 +00:00
# include <type_traits>
2016-03-19 19:08:10 +00:00
# include "dsx-ns.h"
2014-11-23 04:36:58 +00:00
# include "objnum.h"
2022-06-05 17:44:52 +00:00
# include "fwd-piggy.h"
2015-12-05 22:57:24 +00:00
# include "fwd-vecmat.h"
2015-10-10 03:44:14 +00:00
# include "fwd-segment.h"
2016-12-24 08:50:29 +00:00
# include "fwd-window.h"
2017-08-11 23:43:53 +00:00
# include "fwd-valptridx.h"
2022-06-05 17:44:52 +00:00
# include "polyobj.h"
2020-05-02 21:18:42 +00:00
# include <array>
2014-11-23 04:36:58 +00:00
struct bitmap_index ;
2016-11-20 23:12:00 +00:00
namespace dcx {
// Movement types
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < std : : size_t , 350 > MAX_OBJECTS { } ;
2016-12-24 18:12:17 +00:00
constexpr std : : integral_constant < std : : size_t , MAX_OBJECTS - 20 > MAX_USED_OBJECTS { } ;
2020-04-19 20:47:07 +00:00
struct d_level_unique_control_center_state ;
2016-11-20 23:12:00 +00:00
2020-05-02 21:18:43 +00:00
// Render types
enum render_type_t : uint8_t ;
2016-11-20 23:12:00 +00:00
}
2016-01-09 16:38:15 +00:00
# ifdef dsx
2015-12-13 18:00:49 +00:00
namespace dsx {
2015-12-05 22:57:25 +00:00
struct object ;
2018-12-30 00:43:57 +00:00
struct d_level_unique_object_state ;
2016-12-24 18:12:17 +00:00
}
2017-08-11 23:43:52 +00:00
DXX_VALPTRIDX_DECLARE_SUBTYPE ( dsx : : , object , objnum_t , MAX_OBJECTS ) ;
2016-12-24 18:12:17 +00:00
namespace dsx {
2017-06-10 03:31:03 +00:00
DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS ( object , obj ) ;
2015-08-22 20:43:04 +00:00
2015-07-21 02:57:27 +00:00
static constexpr valptridx < object > : : magic_constant < 0xffff > object_none { } ;
static constexpr valptridx < object > : : magic_constant < 0 > object_first { } ;
2014-11-23 04:36:58 +00:00
# if defined(DXX_BUILD_DESCENT_I)
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < unsigned , 15 > MAX_OBJECT_TYPES { } ;
2014-11-23 04:36:58 +00:00
# elif defined(DXX_BUILD_DESCENT_II)
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < unsigned , 16 > MAX_OBJECT_TYPES { } ;
2020-04-19 20:47:07 +00:00
struct d_level_unique_control_center_state ;
2014-11-23 04:36:58 +00:00
# endif
2016-12-24 18:12:17 +00:00
}
# endif
2014-11-23 04:36:58 +00:00
// misc object flags
typedef unsigned object_flag_t ;
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < object_flag_t , 1 > OF_EXPLODING { } ; // this object is exploding
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.
constexpr std : : integral_constant < object_flag_t , 4 > OF_DESTROYED { } ; // this has been killed, and is showing the dead version
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!
constexpr std : : integral_constant < object_flag_t , 16 > OF_ATTACHED { } ; // this object is a fireball attached to another object
2014-11-23 04:36:58 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < object_flag_t , 64 > OF_PLAYER_DROPPED { } ; // this object was dropped by the player...
2014-11-23 04:36:58 +00:00
# endif
// physics flags
typedef unsigned physics_flag_t ;
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < physics_flag_t , 0x01 > PF_TURNROLL { } ; // roll when turning
constexpr std : : integral_constant < physics_flag_t , 0x02 > PF_LEVELLING { } ; // level object with closest side
constexpr std : : integral_constant < physics_flag_t , 0x04 > PF_BOUNCE { } ; // bounce (not slide) when hit will
constexpr std : : integral_constant < physics_flag_t , 0x08 > PF_WIGGLE { } ; // wiggle while flying
constexpr std : : integral_constant < physics_flag_t , 0x10 > PF_STICK { } ; // object sticks (stops moving) when hits wall
constexpr std : : integral_constant < physics_flag_t , 0x20 > PF_PERSISTENT { } ; // object keeps going even after it hits another object (eg, fusion cannon)
constexpr std : : integral_constant < physics_flag_t , 0x40 > PF_USES_THRUST { } ; // this object uses its thrust
2014-11-23 04:36:58 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < physics_flag_t , 0x80 > PF_BOUNCED_ONCE { } ; // Weapon has bounced once.
constexpr std : : integral_constant < physics_flag_t , 0x100 > PF_FREE_SPINNING { } ; // Drag does not apply to rotation of this object
constexpr std : : integral_constant < physics_flag_t , 0x200 > PF_BOUNCES_TWICE { } ; // This weapon bounces twice, then dies
2015-07-02 02:37:55 +00:00
# endif
2014-11-23 04:36:58 +00:00
2015-12-13 18:00:49 +00:00
namespace dcx {
2016-11-20 23:12:00 +00:00
enum object_type_t : uint8_t ;
2016-04-06 03:34:13 +00:00
struct object_base ;
2015-12-05 22:57:25 +00:00
2014-11-23 04:36:58 +00:00
typedef unsigned powerup_flag_t ;
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < powerup_flag_t , 1 > PF_SPAT_BY_PLAYER { } ; //this powerup was spat by the player
2014-11-23 04:36:58 +00:00
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < unsigned , 0x3fffffff > IMMORTAL_TIME { } ; // Time assigned to immortal objects, about 32768 seconds, or about 9 hours.
2014-11-23 04:36:58 +00:00
struct shortpos ;
struct quaternionpos ;
// This is specific to the shortpos extraction routines in gameseg.c.
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < unsigned , 10 > RELPOS_PRECISION { } ;
constexpr std : : integral_constant < unsigned , 9 > MATRIX_PRECISION { } ;
2014-11-23 04:36:58 +00:00
struct physics_info ;
struct physics_info_rw ;
2015-12-05 22:57:25 +00:00
struct laser_parent ;
2014-11-23 04:36:58 +00:00
struct laser_info_rw ;
struct explosion_info ;
struct explosion_info_rw ;
struct light_info ;
struct light_info_rw ;
struct powerup_info ;
struct vclip_info ;
struct vclip_info_rw ;
struct polyobj_info ;
struct polyobj_info_rw ;
struct obj_position ;
2015-12-05 22:57:25 +00:00
2020-08-06 03:47:56 +00:00
enum class collision_result : uint8_t
{
ignore = 0 , // Ignore this collision
check = 1 , // Check for this collision
} ;
2015-12-05 22:57:25 +00:00
}
2014-11-23 04:36:58 +00:00
2016-01-09 16:38:15 +00:00
# ifdef dsx
namespace dsx {
2014-11-23 04:36:58 +00:00
# if defined(DXX_BUILD_DESCENT_I)
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < unsigned , 4 > MAX_CONTROLCEN_GUNS { } ;
2014-11-23 04:36:58 +00:00
# elif defined(DXX_BUILD_DESCENT_II)
2017-10-14 17:10:30 +00:00
constexpr std : : integral_constant < unsigned , 8 > MAX_CONTROLCEN_GUNS { } ;
2019-03-03 00:31:08 +00:00
struct d_unique_buddy_state ;
2014-11-23 04:36:58 +00:00
# endif
2022-01-09 15:25:42 +00:00
struct object_rw ;
2015-12-05 22:57:25 +00:00
struct powerup_info_rw ;
2014-11-23 04:36:58 +00:00
struct window_rendered_data ;
2015-12-05 22:57:25 +00:00
struct reactor_static ;
2014-11-23 04:36:58 +00:00
2020-08-06 03:47:56 +00:00
using collision_inner_array_t = std : : array < collision_result , MAX_OBJECT_TYPES > ;
2020-05-02 21:18:42 +00:00
using collision_outer_array_t = std : : array < collision_inner_array_t , MAX_OBJECT_TYPES > ;
2014-11-23 04:36:58 +00:00
extern const collision_outer_array_t CollisionResult ;
2015-12-05 22:57:25 +00:00
}
2014-11-23 04:36:58 +00:00
# endif
2015-12-22 04:18:50 +00:00
namespace dcx {
2014-11-23 04:36:58 +00:00
extern int Num_robot_types ;
2015-12-22 04:18:50 +00:00
}
2014-11-23 04:36:58 +00:00
2016-01-09 16:38:15 +00:00
# ifdef dsx
2015-12-22 04:18:50 +00:00
namespace dsx {
2014-11-23 04:36:58 +00:00
extern object * ConsoleObject ; // pointer to the object that is the player
2018-09-25 03:44:09 +00:00
extern const object * Viewer ; // which object we are seeing from
2014-11-23 04:36:58 +00:00
extern object * Dead_player_camera ;
2015-12-22 04:18:50 +00:00
}
2015-11-26 02:56:55 +00:00
# endif
2014-11-23 04:36:58 +00:00
2015-12-15 04:09:35 +00:00
enum class player_dead_state : uint8_t
{
no ,
yes ,
2016-01-09 16:38:10 +00:00
exploded ,
2015-12-15 04:09:35 +00:00
} ;
2015-12-22 04:18:50 +00:00
namespace dcx {
2015-12-15 04:09:35 +00:00
extern player_dead_state Player_dead_state ; // !0 means player is dead!
2014-11-23 04:36:58 +00:00
extern objnum_t Player_fired_laser_this_frame ;
2015-12-22 04:18:50 +00:00
}
2014-11-23 04:36:58 +00:00
2016-01-09 16:38:15 +00:00
# ifdef dsx
2015-12-22 04:18:50 +00:00
namespace dsx {
2022-06-05 17:44:52 +00:00
// Draw a blob-type object, like a fireball
void draw_object_blob ( GameBitmaps_array & GameBitmaps , const object_base & Viewer , grs_canvas & , const object_base & obj , bitmap_index bitmap ) ;
2014-11-23 04:36:58 +00:00
// do whatever setup needs to be done
void init_objects ( ) ;
// when an object has moved into a new segment, this function unlinks it
// from its old segment, and links it into the new segment
2018-03-12 03:43:46 +00:00
void obj_relink ( fvmobjptr & vmobjptr , fvmsegptr & vmsegptr , vmobjptridx_t objnum , vmsegptridx_t newsegnum ) ;
2014-11-23 04:36:58 +00:00
// for getting out of messed up linking situations (i.e. caused by demo playback)
void obj_relink_all ( ) ;
2016-11-06 17:12:03 +00:00
/* Link an object without checking whether the object is currently
* unlinked . This should be used only in cases where the caller is
* intentionally overriding the normal linking rules ( such as loading
* objects from demos or from the network ) .
*/
2018-03-12 03:43:46 +00:00
void obj_link_unchecked ( fvmobjptr & vmobjptr , vmobjptridx_t obj , vmsegptridx_t segnum ) ;
2014-11-23 04:36:58 +00:00
// unlinks an object from a segment's list of objects
2018-03-12 03:43:46 +00:00
void obj_unlink ( fvmobjptr & vmobjptr , fvmsegptr & vmsegptr , object_base & obj ) ;
2014-11-23 04:36:58 +00:00
// make a copy of an object. returs num of new object
2018-12-03 04:25:11 +00:00
imobjptridx_t obj_create_copy ( const object & srcobj , vmsegptridx_t newsegnum ) ;
2014-11-23 04:36:58 +00:00
// remove object from the world
2018-12-30 00:43:57 +00:00
void obj_delete ( d_level_unique_object_state & LevelUniqueObjectState , segment_array & Segments , vmobjptridx_t objnum ) ;
2014-11-23 04:36:58 +00:00
// called after load. Takes number of objects, and objects should be
// compressed
2018-12-30 00:43:57 +00:00
void reset_objects ( d_level_unique_object_state & , unsigned n_objs ) ;
2014-11-23 04:36:58 +00:00
// make object array non-sparse
void compress_objects ( ) ;
// move all objects for the current frame
2019-12-22 05:34:08 +00:00
window_event_result game_move_all_objects ( ) ; // moves all objects
window_event_result endlevel_move_all_objects ( ) ;
2014-11-23 04:36:58 +00:00
// set viewer object to next object in array
2022-06-05 17:44:53 +00:00
void object_goto_next_viewer ( const object_array & Objects , const object * & viewer ) ;
2014-11-23 04:36:58 +00:00
// make object0 the player, setting all relevant fields
2022-06-05 17:44:52 +00:00
void init_player_object ( const d_level_shared_polygon_model_state & LevelSharedPolygonModelState , object_base & console ) ;
2014-11-23 04:36:58 +00:00
// check if object is in object->segnum. if not, check the adjacent
// segs. if not any of these, returns false, else sets obj->segnum &
// returns true callers should really use find_vector_intersection()
// Note: this function is in gameseg.c
2018-10-08 03:58:48 +00:00
int update_object_seg ( fvmobjptr & vmobjptr , const d_level_shared_segment_state & LevelSharedSegmentState , d_level_unique_segment_state & LevelUniqueSegmentState , vmobjptridx_t obj ) ;
2014-11-23 04:36:58 +00:00
// Finds what segment *obj is in, returns segment number. If not in
// any segment, returns -1. Note: This function is defined in
// gameseg.h, but object.h depends on gameseg.h, and object.h is where
// object is defined...get it?
2018-09-19 02:13:30 +00:00
imsegptridx_t find_object_seg ( const d_level_shared_segment_state & , d_level_unique_segment_state & , const object_base & obj ) ;
2014-11-23 04:36:58 +00:00
// go through all objects and make sure they have the correct segment
// numbers used when debugging is on
void fix_object_segs ( ) ;
// Drops objects contained in objp.
2022-02-06 16:12:31 +00:00
bool object_create_robot_egg ( object_base & objp ) ;
bool object_create_robot_egg ( int type , int id , int num , const vms_vector & init_vel , const vms_vector & pos , vmsegptridx_t segnum ) ;
2014-11-23 04:36:58 +00:00
// Interface to object_create_egg, puts count objects of type type, id
// = id in objp and then drops them.
2022-02-06 16:12:31 +00:00
void call_object_create_egg ( const object_base & objp , unsigned count , int id ) ;
imobjptridx_t call_object_create_egg ( const object_base & objp , int id ) ;
2014-11-23 04:36:58 +00:00
void dead_player_end ( ) ;
// Extract information from an object (objp->orient, objp->pos,
// objp->segnum), stuff in a shortpos structure. See typedef
// shortpos.
2018-09-19 02:13:30 +00:00
void create_shortpos_little ( const d_level_shared_segment_state & , shortpos & spp , const object_base & objp ) ;
void create_shortpos_native ( const d_level_shared_segment_state & , shortpos & spp , const object_base & objp ) ;
2014-11-23 04:36:58 +00:00
// Extract information from a shortpos, stuff in objp->orient
// (matrix), objp->pos, objp->segnum
2017-06-10 03:31:02 +00:00
void extract_shortpos_little ( vmobjptridx_t objp , const shortpos * spp ) ;
2014-11-23 04:36:58 +00:00
// create and extract quaternion structure from object data which greatly saves bytes by using quaternion instead or orientation matrix
2018-03-31 21:53:01 +00:00
void create_quaternionpos ( quaternionpos & qpp , const object_base & objp ) ;
void extract_quaternionpos ( vmobjptridx_t objp , quaternionpos & qpp ) ;
2014-11-23 04:36:58 +00:00
// delete objects, such as weapons & explosions, that shouldn't stay
// between levels if clear_all is set, clear even proximity bombs
void clear_transient_objects ( int clear_all ) ;
// returns the number of a free object, updating Highest_object_index.
// Generally, obj_create() should be called to get an object, since it
// fills in important fields and does the linking. returns -1 if no
// free objects
2018-12-30 00:43:57 +00:00
imobjptridx_t obj_allocate ( d_level_unique_object_state & ) ;
2014-11-23 04:36:58 +00:00
// after calling init_object(), the network code has grabbed specific
// object slots without allocating them. Go though the objects &
// build the free list, then set the apporpriate globals Don't call
// this function if you don't know what you're doing.
2018-12-30 00:43:57 +00:00
void special_reset_objects ( d_level_unique_object_state & ) ;
2014-11-23 04:36:58 +00:00
// attaches an object, such as a fireball, to another object, such as
// a robot
2018-03-12 03:43:46 +00:00
void obj_attach ( object_array & Objects , vmobjptridx_t parent , vmobjptridx_t sub ) ;
2014-11-23 04:36:58 +00:00
2017-06-10 03:31:02 +00:00
void create_small_fireball_on_object ( vmobjptridx_t objp , fix size_scale , int sound_flag ) ;
2016-12-24 08:50:29 +00:00
window_event_result dead_player_frame ( ) ;
2014-11-23 04:36:58 +00:00
# if defined(DXX_BUILD_DESCENT_II)
2015-12-22 04:18:50 +00:00
extern int Drop_afterburner_blob_flag ; //ugly hack
2020-07-22 03:11:18 +00:00
enum class game_marker_index : uint8_t ;
enum class player_marker_index : uint8_t ;
2014-11-23 04:36:58 +00:00
// returns object number
2020-07-22 03:11:18 +00:00
imobjptridx_t drop_marker_object ( const vms_vector & pos , vmsegptridx_t segnum , const vms_matrix & orient , game_marker_index marker_num ) ;
2014-11-23 04:36:58 +00:00
2018-09-25 03:44:09 +00:00
void wake_up_rendered_objects ( const object & gmissp , window_rendered_data & window ) ;
2014-11-23 04:36:58 +00:00
2018-12-30 00:43:57 +00:00
void fuelcen_check_for_goal ( object & plrobj , const shared_segment & segp ) ;
2014-11-23 04:36:58 +00:00
# endif
2019-08-15 01:34:22 +00:00
imobjptridx_t obj_find_first_of_type ( fvmobjptridx & , object_type_t type ) ;
2014-11-23 04:36:58 +00:00
void object_rw_swap ( struct object_rw * obj_rw , int swap ) ;
2022-06-05 17:44:52 +00:00
void reset_player_object ( object_base & ) ;
2015-11-26 02:56:55 +00:00
2015-12-22 04:18:50 +00:00
}
2015-11-26 02:56:55 +00:00
# endif