Move N_robot_types into LevelSharedRobotInfoState

This commit is contained in:
Kp 2018-12-30 00:43:59 +00:00
parent e84a65edc6
commit 12c06e59aa
11 changed files with 71 additions and 72 deletions

View file

@ -196,6 +196,8 @@ static inline int robot_is_thief(const robot_info &robptr)
struct d_level_shared_robot_info_state struct d_level_shared_robot_info_state
{ {
using d_robot_info_array = array<robot_info, MAX_ROBOT_TYPES>; using d_robot_info_array = array<robot_info, MAX_ROBOT_TYPES>;
//how many kinds of robots
unsigned N_robot_types; // Number of robot types. We used to assume this was the same as N_polygon_models.
// Robot info for AI system, loaded from bitmaps.tbl. // Robot info for AI system, loaded from bitmaps.tbl.
d_robot_info_array Robot_info; d_robot_info_array Robot_info;
}; };
@ -215,8 +217,6 @@ extern array<jointpos, MAX_ROBOT_JOINTS> Robot_joints;
} }
namespace dcx { namespace dcx {
//how many kinds of robots
extern unsigned N_robot_types; // Number of robot types. We used to assume this was the same as N_polygon_models.
extern unsigned N_robot_joints; extern unsigned N_robot_joints;
} }

View file

@ -132,6 +132,7 @@ static window_event_result centers_dialog_created(UI_DIALOG *const w, centers_di
#elif defined(DXX_BUILD_DESCENT_II) #elif defined(DXX_BUILD_DESCENT_II)
const unsigned d = 6; const unsigned d = 6;
#endif #endif
const auto N_robot_types = LevelSharedRobotInfoState.N_robot_types;
for (i=0; i < N_robot_types; i++) for (i=0; i < N_robot_types; i++)
c->robotMatFlag[i] = ui_add_gadget_checkbox( w, 128 + (i%d)*92, 20+(i/d)*24, 16, 16, 0, Robot_names[i].data()); c->robotMatFlag[i] = ui_add_gadget_checkbox( w, 128 + (i%d)*92, 20+(i/d)*24, 16, 16, 0, Robot_names[i].data());
c->old_seg_num = -2; // Set to some dummy value so everything works ok on the first frame. c->old_seg_num = -2; // Set to some dummy value so everything works ok on the first frame.
@ -174,6 +175,8 @@ window_event_result centers_dialog_handler(UI_DIALOG *dlg,const d_event &event,
//------------------------------------------------------------ //------------------------------------------------------------
ui_button_any_drawn = 0; ui_button_any_drawn = 0;
const auto N_robot_types = LevelSharedRobotInfoState.N_robot_types;
//------------------------------------------------------------ //------------------------------------------------------------
// If we change centers, we need to reset the ui code for all // If we change centers, we need to reset the ui code for all
// of the checkboxes that control the center flags. // of the checkboxes that control the center flags.

View file

@ -114,7 +114,7 @@ static int RobotNextType()
if (obj->type == OBJ_ROBOT) if (obj->type == OBJ_ROBOT)
{ {
obj->id++; obj->id++;
if (obj->id >= N_robot_types ) if (obj->id >= LevelSharedRobotInfoState.N_robot_types)
obj->id = 0; obj->id = 0;
//Set polygon-object-specific data //Set polygon-object-specific data
@ -144,7 +144,7 @@ static int RobotPrevType()
if (obj->type == OBJ_ROBOT) if (obj->type == OBJ_ROBOT)
{ {
if (obj->id == 0 ) if (obj->id == 0 )
obj->id = N_robot_types-1; obj->id = LevelSharedRobotInfoState.N_robot_types - 1;
else else
obj->id--; obj->id--;
@ -263,7 +263,7 @@ int GoodyNextID()
{ {
Cur_goody_id++; Cur_goody_id++;
if (Cur_goody_type == OBJ_ROBOT) { if (Cur_goody_type == OBJ_ROBOT) {
if (Cur_goody_id >= N_robot_types) if (Cur_goody_id >= LevelSharedRobotInfoState.N_robot_types)
Cur_goody_id=0; Cur_goody_id=0;
} else { } else {
if (Cur_goody_id >= N_powerup_types) if (Cur_goody_id >= N_powerup_types)
@ -279,7 +279,7 @@ int GoodyPrevID()
Cur_goody_id--; Cur_goody_id--;
if (Cur_goody_type == OBJ_ROBOT) { if (Cur_goody_type == OBJ_ROBOT) {
if (Cur_goody_id < 0) if (Cur_goody_id < 0)
Cur_goody_id = N_robot_types-1; Cur_goody_id = LevelSharedRobotInfoState.N_robot_types - 1;
} else { } else {
if (Cur_goody_id < 0) if (Cur_goody_id < 0)
Cur_goody_id = N_powerup_types-1; Cur_goody_id = N_powerup_types-1;
@ -450,7 +450,7 @@ static int LocalObjectPlaceObject(void)
{ {
Cur_object_type = OBJ_ROBOT; Cur_object_type = OBJ_ROBOT;
Cur_object_id = 3; // class 1 drone Cur_object_id = 3; // class 1 drone
Num_object_subtypes = N_robot_types; Num_object_subtypes = LevelSharedRobotInfoState.N_robot_types;
} }
rval = ObjectPlaceObject(); rval = ObjectPlaceObject();

View file

@ -265,7 +265,7 @@ int objpage_goto_next_object()
case OBJ_CNTRLCEN: case OBJ_CNTRLCEN:
default: default:
Cur_object_type = OBJ_ROBOT; Cur_object_type = OBJ_ROBOT;
Num_object_subtypes = N_robot_types; Num_object_subtypes = LevelSharedRobotInfoState.N_robot_types;
break; break;
} }
@ -327,7 +327,6 @@ void objpage_init( UI_DIALOG *dlg )
//Assert (Num_total_object_types < MAX_OBJTYPE ); //Assert (Num_total_object_types < MAX_OBJTYPE );
//Assert (N_hostage_types < MAX_HOSTAGE_TYPES ); //Assert (N_hostage_types < MAX_HOSTAGE_TYPES );
//Assert (N_powerup_types < MAX_POWERUP_TYPES ); //Assert (N_powerup_types < MAX_POWERUP_TYPES );
// Assert (N_robot_types < MAX_ROBOTS);
auto &o = objpage_dialog; auto &o = objpage_dialog;
o.prev_object = ui_add_gadget_button( dlg, OBJCURBOX_X + 00, OBJCURBOX_Y - 27, 30, 20, "<<", objpage_goto_prev ); o.prev_object = ui_add_gadget_button( dlg, OBJCURBOX_X + 00, OBJCURBOX_Y - 27, 30, 20, "<<", objpage_goto_prev );

View file

@ -2023,7 +2023,7 @@ void create_buddy_bot(void)
auto &Robot_info = LevelSharedRobotInfoState.Robot_info; auto &Robot_info = LevelSharedRobotInfoState.Robot_info;
for (buddy_id=0;; buddy_id++) for (buddy_id=0;; buddy_id++)
{ {
if (!(buddy_id < N_robot_types)) if (!(buddy_id < LevelSharedRobotInfoState.N_robot_types))
return; return;
const robot_info &robptr = Robot_info[buddy_id]; const robot_info &robptr = Robot_info[buddy_id];
if (robptr.companion) if (robptr.companion)
@ -2470,7 +2470,6 @@ static void do_super_boss_stuff(fvmsegptridx &vmsegptridx, const vmobjptridx_t o
Assert(randtype < MAX_GATE_INDEX); Assert(randtype < MAX_GATE_INDEX);
randtype = Super_boss_gate_list[randtype]; randtype = Super_boss_gate_list[randtype];
Assert(randtype < N_robot_types);
const auto &&rtval = gate_in_robot(vmsegptridx, randtype); const auto &&rtval = gate_in_robot(vmsegptridx, randtype);
if (rtval != object_none && (Game_mode & GM_MULTI)) if (rtval != object_none && (Game_mode & GM_MULTI))
@ -3013,7 +3012,7 @@ void do_ai_frame(const vmobjptridx_t obj)
} }
Assert(obj->segnum != segment_none); Assert(obj->segnum != segment_none);
Assert(get_robot_id(obj) < N_robot_types); assert(get_robot_id(obj) < LevelSharedRobotInfoState.N_robot_types);
obj_ref = objnum ^ d_tick_count; obj_ref = objnum ^ d_tick_count;

View file

@ -187,7 +187,7 @@ void properties_read_cmp(d_vclip_array &Vclip, PHYSFS_File * fp)
range_for (auto &w, WallAnims) range_for (auto &w, WallAnims)
wclip_read(fp, w); wclip_read(fp, w);
N_robot_types = PHYSFSX_readInt(fp); LevelSharedRobotInfoState.N_robot_types = PHYSFSX_readInt(fp);
auto &Robot_info = LevelSharedRobotInfoState.Robot_info; auto &Robot_info = LevelSharedRobotInfoState.Robot_info;
range_for (auto &r, Robot_info) range_for (auto &r, Robot_info)
robot_info_read(fp, r); robot_info_read(fp, r);
@ -320,9 +320,9 @@ void bm_read_all(d_vclip_array &Vclip, PHYSFS_File * fp)
range_for (auto &w, partial_range(WallAnims, Num_wall_anims)) range_for (auto &w, partial_range(WallAnims, Num_wall_anims))
wclip_read(fp, w); wclip_read(fp, w);
N_robot_types = PHYSFSX_readInt(fp);
auto &Robot_info = LevelSharedRobotInfoState.Robot_info; auto &Robot_info = LevelSharedRobotInfoState.Robot_info;
range_for (auto &r, partial_range(Robot_info, N_robot_types)) LevelSharedRobotInfoState.N_robot_types = PHYSFSX_readInt(fp);
range_for (auto &r, partial_range(Robot_info, LevelSharedRobotInfoState.N_robot_types))
robot_info_read(fp, r); robot_info_read(fp, r);
N_robot_joints = PHYSFSX_readInt(fp); N_robot_joints = PHYSFSX_readInt(fp);
@ -454,7 +454,7 @@ void bm_read_extra_robots(const char *fname, Mission::descent_version_type type)
//now read robot info //now read robot info
t = PHYSFSX_readInt(fp); t = PHYSFSX_readInt(fp);
N_robot_types = N_D2_ROBOT_TYPES+t; const auto N_robot_types = LevelSharedRobotInfoState.N_robot_types = N_D2_ROBOT_TYPES + t;
if (N_robot_types >= MAX_ROBOT_TYPES) if (N_robot_types >= MAX_ROBOT_TYPES)
Error("Too many robots (%d) in <%s>. Max is %d.",t,fname,MAX_ROBOT_TYPES-N_D2_ROBOT_TYPES); Error("Too many robots (%d) in <%s>. Max is %d.",t,fname,MAX_ROBOT_TYPES-N_D2_ROBOT_TYPES);
auto &Robot_info = LevelSharedRobotInfoState.Robot_info; auto &Robot_info = LevelSharedRobotInfoState.Robot_info;
@ -522,6 +522,7 @@ void load_robot_replacements(const d_fname &level_name)
t = PHYSFSX_readInt(fp); //read number of robots t = PHYSFSX_readInt(fp); //read number of robots
auto &Robot_info = LevelSharedRobotInfoState.Robot_info; auto &Robot_info = LevelSharedRobotInfoState.Robot_info;
const auto N_robot_types = LevelSharedRobotInfoState.N_robot_types;
for (j=0;j<t;j++) { for (j=0;j<t;j++) {
i = PHYSFSX_readInt(fp); //read robot number i = PHYSFSX_readInt(fp); //read robot number
if (i<0 || i>=N_robot_types) if (i<0 || i>=N_robot_types)

View file

@ -761,7 +761,7 @@ int gamedata_read_tbl(d_vclip_array &Vclip, int pc_shareware)
Textures[NumTextures++].index = 0; //entry for bogus tmap Textures[NumTextures++].index = 0; //entry for bogus tmap
InfoFile.reset(); InfoFile.reset();
#endif #endif
Assert(N_robot_types == Num_robot_ais); //should be one ai info per robot assert(LevelSharedRobotInfoState.N_robot_types == Num_robot_ais); //should be one ai info per robot
verify_textures(); verify_textures();
@ -1414,17 +1414,16 @@ void bm_read_robot(int skip)
int attack_sound = ROBOT_ATTACK_SOUND_DEFAULT; int attack_sound = ROBOT_ATTACK_SOUND_DEFAULT;
int claw_sound = ROBOT_CLAW_SOUND_DEFAULT; int claw_sound = ROBOT_CLAW_SOUND_DEFAULT;
Assert(N_robot_types < MAX_ROBOT_TYPES); assert(LevelSharedRobotInfoState.N_robot_types < MAX_ROBOT_TYPES);
auto &Robot_info = LevelSharedRobotInfoState.Robot_info; auto &Robot_info = LevelSharedRobotInfoState.Robot_info;
if (skip) { if (skip) {
Robot_info[N_robot_types].model_num = -1; auto &ri = Robot_info[LevelSharedRobotInfoState.N_robot_types++];
N_robot_types++; ri.model_num = -1;
#if defined(DXX_BUILD_DESCENT_I) #if defined(DXX_BUILD_DESCENT_I)
Num_total_object_types++; Num_total_object_types++;
clear_to_end_of_line(arg); clear_to_end_of_line(arg);
#elif defined(DXX_BUILD_DESCENT_II) #elif defined(DXX_BUILD_DESCENT_II)
Assert(N_robot_types < MAX_ROBOT_TYPES);
clear_to_end_of_line(); clear_to_end_of_line();
#endif #endif
return; return;
@ -1551,7 +1550,7 @@ void bm_read_robot(int skip)
#endif #endif
else if (!d_stricmp( arg, "name" )) { else if (!d_stricmp( arg, "name" )) {
#if DXX_USE_EDITOR #if DXX_USE_EDITOR
auto &name = Robot_names[N_robot_types]; auto &name = Robot_names[LevelSharedRobotInfoState.N_robot_types];
const auto len = strlen(equal_ptr); const auto len = strlen(equal_ptr);
assert(len < name.size()); // Oops, name too long. assert(len < name.size()); // Oops, name too long.
memcpy(name.data(), &equal_ptr[1], len - 2); memcpy(name.data(), &equal_ptr[1], len - 2);
@ -1577,8 +1576,9 @@ void bm_read_robot(int skip)
arg = strtok( NULL, space_tab ); arg = strtok( NULL, space_tab );
} }
auto &current_robot_info = Robot_info[LevelSharedRobotInfoState.N_robot_types];
//clear out anim info //clear out anim info
range_for (auto &g, Robot_info[N_robot_types].anim_states) range_for (auto &g, current_robot_info.anim_states)
range_for (auto &s, g) range_for (auto &s, g)
s.n_joints = 0; s.n_joints = 0;
@ -1591,10 +1591,10 @@ void bm_read_robot(int skip)
n_textures = first_bitmap_num[i+1] - first_bitmap_num[i]; n_textures = first_bitmap_num[i+1] - first_bitmap_num[i];
model_num = load_polygon_model(model_name[i],n_textures,first_bitmap_num[i], (i == 0) ? &Robot_info[N_robot_types] : nullptr); model_num = load_polygon_model(model_name[i],n_textures,first_bitmap_num[i], (i == 0) ? &current_robot_info : nullptr);
if (i==0) if (i==0)
Robot_info[N_robot_types].model_num = model_num; current_robot_info.model_num = model_num;
else else
Polygon_models[last_model_num].simpler_model = model_num+1; Polygon_models[last_model_num].simpler_model = model_num+1;
@ -1603,69 +1603,66 @@ void bm_read_robot(int skip)
#if defined(DXX_BUILD_DESCENT_I) #if defined(DXX_BUILD_DESCENT_I)
ObjType[Num_total_object_types] = OL_ROBOT; ObjType[Num_total_object_types] = OL_ROBOT;
ObjId[Num_total_object_types] = N_robot_types; ObjId[Num_total_object_types] = LevelSharedRobotInfoState.N_robot_types;
#elif defined(DXX_BUILD_DESCENT_II) #elif defined(DXX_BUILD_DESCENT_II)
if ((glow > i2f(15)) || (glow < 0) || (glow != 0 && glow < 0x1000)) { if ((glow > i2f(15)) || (glow < 0) || (glow != 0 && glow < 0x1000)) {
Int3(); Int3();
} }
#endif #endif
Robot_info[N_robot_types].exp1_vclip_num = exp1_vclip_num; current_robot_info.exp1_vclip_num = exp1_vclip_num;
Robot_info[N_robot_types].exp2_vclip_num = exp2_vclip_num; current_robot_info.exp2_vclip_num = exp2_vclip_num;
Robot_info[N_robot_types].exp1_sound_num = exp1_sound_num; current_robot_info.exp1_sound_num = exp1_sound_num;
Robot_info[N_robot_types].exp2_sound_num = exp2_sound_num; current_robot_info.exp2_sound_num = exp2_sound_num;
Robot_info[N_robot_types].lighting = lighting; current_robot_info.lighting = lighting;
Robot_info[N_robot_types].weapon_type = weapon_type; current_robot_info.weapon_type = weapon_type;
#if defined(DXX_BUILD_DESCENT_II) #if defined(DXX_BUILD_DESCENT_II)
Robot_info[N_robot_types].weapon_type2 = weapon_type2; current_robot_info.weapon_type2 = weapon_type2;
#endif #endif
Robot_info[N_robot_types].strength = strength; current_robot_info.strength = strength;
Robot_info[N_robot_types].mass = mass; current_robot_info.mass = mass;
Robot_info[N_robot_types].drag = drag; current_robot_info.drag = drag;
Robot_info[N_robot_types].cloak_type = cloak_type; current_robot_info.cloak_type = cloak_type;
Robot_info[N_robot_types].attack_type = attack_type; current_robot_info.attack_type = attack_type;
Robot_info[N_robot_types].boss_flag = boss_flag; current_robot_info.boss_flag = boss_flag;
Robot_info[N_robot_types].contains_id = contains_id; current_robot_info.contains_id = contains_id;
Robot_info[N_robot_types].contains_count = contains_count; current_robot_info.contains_count = contains_count;
Robot_info[N_robot_types].contains_prob = contains_prob; current_robot_info.contains_prob = contains_prob;
#if defined(DXX_BUILD_DESCENT_II) #if defined(DXX_BUILD_DESCENT_II)
Robot_info[N_robot_types].companion = companion; current_robot_info.companion = companion;
Robot_info[N_robot_types].badass = badass; current_robot_info.badass = badass;
Robot_info[N_robot_types].lightcast = lightcast; current_robot_info.lightcast = lightcast;
Robot_info[N_robot_types].glow = (glow>>12); //convert to 4:4 current_robot_info.glow = (glow>>12); //convert to 4:4
Robot_info[N_robot_types].death_roll = death_roll; current_robot_info.death_roll = death_roll;
Robot_info[N_robot_types].deathroll_sound = deathroll_sound; current_robot_info.deathroll_sound = deathroll_sound;
Robot_info[N_robot_types].thief = thief; current_robot_info.thief = thief;
Robot_info[N_robot_types].flags = flags; current_robot_info.flags = flags;
Robot_info[N_robot_types].kamikaze = kamikaze; current_robot_info.kamikaze = kamikaze;
Robot_info[N_robot_types].pursuit = pursuit; current_robot_info.pursuit = pursuit;
Robot_info[N_robot_types].smart_blobs = smart_blobs; current_robot_info.smart_blobs = smart_blobs;
Robot_info[N_robot_types].energy_blobs = energy_blobs; current_robot_info.energy_blobs = energy_blobs;
Robot_info[N_robot_types].energy_drain = energy_drain; current_robot_info.energy_drain = energy_drain;
#endif #endif
Robot_info[N_robot_types].score_value = score_value; current_robot_info.score_value = score_value;
Robot_info[N_robot_types].see_sound = see_sound; current_robot_info.see_sound = see_sound;
Robot_info[N_robot_types].attack_sound = attack_sound; current_robot_info.attack_sound = attack_sound;
Robot_info[N_robot_types].claw_sound = claw_sound; current_robot_info.claw_sound = claw_sound;
#if defined(DXX_BUILD_DESCENT_II) #if defined(DXX_BUILD_DESCENT_II)
Robot_info[N_robot_types].taunt_sound = taunt_sound; current_robot_info.taunt_sound = taunt_sound;
Robot_info[N_robot_types].behavior = behavior; // Default behavior for this robot, if coming out of matcen. current_robot_info.behavior = behavior; // Default behavior for this robot, if coming out of matcen.
Robot_info[N_robot_types].aim = min(f2i(aim*255), 255); // how well this robot type can aim. 255=perfect current_robot_info.aim = min(f2i(aim*255), 255); // how well this robot type can aim. 255=perfect
#endif #endif
if (contains_type) if (contains_type)
Robot_info[N_robot_types].contains_type = OBJ_ROBOT; current_robot_info.contains_type = OBJ_ROBOT;
else else
Robot_info[N_robot_types].contains_type = OBJ_POWERUP; current_robot_info.contains_type = OBJ_POWERUP;
N_robot_types++; ++LevelSharedRobotInfoState.N_robot_types;
#if defined(DXX_BUILD_DESCENT_I) #if defined(DXX_BUILD_DESCENT_I)
Num_total_object_types++; Num_total_object_types++;
#elif defined(DXX_BUILD_DESCENT_II) #elif defined(DXX_BUILD_DESCENT_II)
Assert(N_robot_types < MAX_ROBOT_TYPES);
bm_flag = BM_NONE; bm_flag = BM_NONE;
#endif #endif
} }

View file

@ -1214,7 +1214,7 @@ static window_event_result HandleTestKey(fvmsegptridx &vmsegptridx, int key)
if (new_obj != object_none) if (new_obj != object_none)
morph_start( new_obj ); morph_start( new_obj );
i++; i++;
if (i >= N_robot_types) if (i >= LevelSharedRobotInfoState.N_robot_types)
i = 0; i = 0;
break; break;
} }

View file

@ -200,6 +200,7 @@ static void verify_object(const d_vclip_array &Vclip, object &obj)
Gamesave_num_org_robots++; Gamesave_num_org_robots++;
// Make sure valid id... // Make sure valid id...
const auto N_robot_types = LevelSharedRobotInfoState.N_robot_types;
if (get_robot_id(obj) >= N_robot_types ) if (get_robot_id(obj) >= N_robot_types )
set_robot_id(obj, get_robot_id(obj) % N_robot_types); set_robot_id(obj, get_robot_id(obj) % N_robot_types);

View file

@ -2147,7 +2147,7 @@ void copy_defaults_to_robot(const vmobjptr_t objp)
Assert(objp->type == OBJ_ROBOT); Assert(objp->type == OBJ_ROBOT);
objid = get_robot_id(objp); objid = get_robot_id(objp);
Assert(objid < N_robot_types); assert(objid < LevelSharedRobotInfoState.N_robot_types);
auto &Robot_info = LevelSharedRobotInfoState.Robot_info; auto &Robot_info = LevelSharedRobotInfoState.Robot_info;
auto &robptr = Robot_info[objid]; auto &robptr = Robot_info[objid];

View file

@ -35,7 +35,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "partial_range.h" #include "partial_range.h"
namespace dcx { namespace dcx {
unsigned N_robot_types;
unsigned N_robot_joints; unsigned N_robot_joints;
} }
@ -62,7 +61,7 @@ namespace dsx {
void calc_gun_point(vms_vector &gun_point, const object_base &obj, unsigned gun_num) void calc_gun_point(vms_vector &gun_point, const object_base &obj, unsigned gun_num)
{ {
Assert(obj.render_type == RT_POLYOBJ || obj.render_type == RT_MORPH); Assert(obj.render_type == RT_POLYOBJ || obj.render_type == RT_MORPH);
Assert(get_robot_id(obj) < N_robot_types); assert(get_robot_id(obj) < LevelSharedRobotInfoState.N_robot_types);
auto &Robot_info = LevelSharedRobotInfoState.Robot_info; auto &Robot_info = LevelSharedRobotInfoState.Robot_info;
const auto &r = Robot_info[get_robot_id(obj)]; const auto &r = Robot_info[get_robot_id(obj)];