From d7e85e0cff0a42044fc5bc026b7161b9d317726c Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 2 Feb 2019 18:36:39 +0000 Subject: [PATCH] Move Boss_gate_segs, Boss_teleport_segs to d_level_shared_boss_state --- common/main/ai.h | 18 ++++++++++++------ d2x-rebirth/main/escort.cpp | 1 + similar/main/ai.cpp | 22 ++++++++++++++++------ similar/main/mglobal.cpp | 1 + 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/common/main/ai.h b/common/main/ai.h index 7fafa450e..00f2adcd7 100644 --- a/common/main/ai.h +++ b/common/main/ai.h @@ -41,6 +41,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II) #include "countarray.h" #include "aistruct.h" +#include "valptridx.h" #endif namespace dcx { @@ -90,12 +91,6 @@ extern const object *Ai_last_missile_camera; } #endif -namespace dcx { -struct boss_special_segment_array_t : public count_array_t {}; -struct boss_teleport_segment_array_t : public boss_special_segment_array_t {}; -struct boss_gate_segment_array_t : public boss_special_segment_array_t {}; -extern boss_teleport_segment_array_t Boss_teleport_segs; -} namespace dsx { void create_awareness_event(vmobjptr_t objp, player_awareness_type_t type); // object *objp can create awareness of player, amount based on "type" ai_mode ai_behavior_to_mode(ai_behavior behavior); @@ -104,6 +99,17 @@ void init_ai_object(vmobjptridx_t objp, ai_behavior initial_mode, imsegidx_t hid } namespace dcx { + +struct d_level_shared_boss_state +{ + struct special_segment_array_t : public count_array_t {}; + struct gate_segment_array_t : public special_segment_array_t {}; + struct teleport_segment_array_t : public special_segment_array_t {}; + gate_segment_array_t Gate_segs; + teleport_segment_array_t Teleport_segs; +}; + +extern d_level_shared_boss_state LevelSharedBossState; extern fix64 Boss_cloak_start_time; extern fix64 Last_teleport_time; constexpr fix Boss_cloak_duration = F1_0*7; diff --git a/d2x-rebirth/main/escort.cpp b/d2x-rebirth/main/escort.cpp index 450f2d31a..2d5d8731e 100644 --- a/d2x-rebirth/main/escort.cpp +++ b/d2x-rebirth/main/escort.cpp @@ -871,6 +871,7 @@ static void escort_create_path_to_goal(const vmobjptridx_t objp, const player_in // Returns goal object. static escort_goal_t escort_set_goal_object(const player_flags pl_flags) { + auto &Boss_teleport_segs = LevelSharedBossState.Teleport_segs; if (Escort_special_goal != ESCORT_GOAL_UNSPECIFIED) return ESCORT_GOAL_UNSPECIFIED; if (!(pl_flags & PLAYER_FLAGS_BLUE_KEY) && exists_in_mine(ConsoleObject->segnum, OBJ_POWERUP, POW_KEY_BLUE, -1, pl_flags) != object_none) diff --git a/similar/main/ai.cpp b/similar/main/ai.cpp index 9964386bf..1d46db00c 100644 --- a/similar/main/ai.cpp +++ b/similar/main/ai.cpp @@ -89,7 +89,7 @@ using std::min; #define BABY_SPIDER_ID 14 namespace dsx { -static void init_boss_segments(const segment_array &segments, const object &boss_objnum, boss_special_segment_array_t &imsegptr, int size_check, int one_wall_hack); +static void init_boss_segments(const segment_array &segments, const object &boss_objnum, d_level_shared_boss_state::special_segment_array_t &a, int size_check, int one_wall_hack); static void ai_multi_send_robot_position(object &objnum, int force); #if defined(DXX_BUILD_DESCENT_I) @@ -145,10 +145,6 @@ constexpr array Mike_to_matt_xlate{{ // Amount of time since the current robot was last processed for things such as movement. // It is not valid to use FrameTime because robots do not get moved every frame. -boss_teleport_segment_array_t Boss_teleport_segs; - -static boss_gate_segment_array_t Boss_gate_segs; - // ---------- John: These variables must be saved as part of gamesave. -------- static int Overall_agitation; point_seg_array_t Point_segs; @@ -477,6 +473,8 @@ void ai_init_boss_for_ship(void) static void boss_init_all_segments(const segment_array &Segments, const object &boss_objnum) { + auto &Boss_gate_segs = LevelSharedBossState.Gate_segs; + auto &Boss_teleport_segs = LevelSharedBossState.Teleport_segs; if (!Boss_teleport_segs.empty()) return; // already have boss segs @@ -580,6 +578,8 @@ void init_ai_object(vmobjptridx_t objp, ai_behavior behavior, const imsegidx_t h // --------------------------------------------------------------------------------------------------------------------- void init_ai_objects(void) { + auto &Boss_gate_segs = LevelSharedBossState.Gate_segs; + auto &Boss_teleport_segs = LevelSharedBossState.Teleport_segs; Point_segs_free_ptr = Point_segs.begin(); Boss_gate_segs.clear(); Boss_teleport_segs.clear(); @@ -1991,6 +1991,7 @@ imobjptridx_t gate_in_robot(int type, const vmsegptridx_t segnum) static imobjptridx_t gate_in_robot(fvmsegptridx &vmsegptridx, int type) { + auto &Boss_gate_segs = LevelSharedBossState.Gate_segs; auto segnum = Boss_gate_segs[(d_rand() * Boss_gate_segs.size()) >> 15]; return gate_in_robot(type, vmsegptridx(segnum)); } @@ -2045,7 +2046,7 @@ void create_buddy_bot(void) // he can reach from his initial position (calls find_connected_distance). // If size_check is set, then only add segment if boss can fit in it, else any segment is legal. // one_wall_hack added by MK, 10/13/95: A mega-hack! Set to !0 to ignore the -static void init_boss_segments(const segment_array &segments, const object &boss_objp, boss_special_segment_array_t &a, const int size_check, int one_wall_hack) +static void init_boss_segments(const segment_array &segments, const object &boss_objp, d_level_shared_boss_state::special_segment_array_t &a, const int size_check, int one_wall_hack) { constexpr unsigned QUEUE_SIZE = 256; auto &vcsegptridx = segments.vcptridx; @@ -2142,6 +2143,7 @@ static void init_boss_segments(const segment_array &segments, const object &boss // -------------------------------------------------------------------------------------------------------------------- static void teleport_boss(const d_vclip_array &Vclip, fvmsegptridx &vmsegptridx, const vmobjptridx_t objp, const vms_vector &target_pos) { + auto &Boss_teleport_segs = LevelSharedBossState.Teleport_segs; segnum_t rand_segnum; int rand_index; assert(!Boss_teleport_segs.empty()); @@ -4489,6 +4491,10 @@ namespace dsx { int ai_save_state(PHYSFS_File *fp) { +#if defined(DXX_BUILD_DESCENT_II) + auto &Boss_gate_segs = LevelSharedBossState.Gate_segs; + auto &Boss_teleport_segs = LevelSharedBossState.Teleport_segs; +#endif fix tmptime32 = 0; const int Ai_initialized = 0; @@ -4695,6 +4701,10 @@ static void ai_cloak_info_read_n_swap(ai_cloak_info *ci, int n, int swap, PHYSFS int ai_restore_state(PHYSFS_File *fp, int version, int swap) { +#if defined(DXX_BUILD_DESCENT_II) + auto &Boss_gate_segs = LevelSharedBossState.Gate_segs; + auto &Boss_teleport_segs = LevelSharedBossState.Teleport_segs; +#endif fix tmptime32 = 0; PHYSFSX_readSXE32(fp, swap); diff --git a/similar/main/mglobal.cpp b/similar/main/mglobal.cpp index ab17fbf20..9b9441733 100644 --- a/similar/main/mglobal.cpp +++ b/similar/main/mglobal.cpp @@ -41,6 +41,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "wall.h" namespace dcx { +d_level_shared_boss_state LevelSharedBossState; d_level_shared_vertex_state LevelSharedVertexState; d_level_unique_fuelcenter_state LevelUniqueFuelcenterState; d_level_unique_light_state LevelUniqueLightState;