Use enum class for AIB constants
This commit is contained in:
parent
f8ac14b737
commit
e883d7c872
|
@ -102,7 +102,7 @@ extern vms_vector Believed_player_pos;
|
|||
void move_towards_segment_center(vobjptr_t objp);
|
||||
extern objptridx_t gate_in_robot(int type, segnum_t segnum);
|
||||
void do_ai_frame(vobjptridx_t objp);
|
||||
void init_ai_object(vobjptr_t objp, int initial_mode, segnum_t hide_segment);
|
||||
void init_ai_object(vobjptr_t objp, ai_behavior initial_mode, segnum_t hide_segment);
|
||||
extern void do_ai_frame_all(void);
|
||||
extern void create_all_paths(void);
|
||||
void create_path_to_station(vobjptridx_t objp, int max_length);
|
||||
|
@ -120,7 +120,7 @@ static inline vms_vector make_random_vector()
|
|||
return make_random_vector(v), v;
|
||||
}
|
||||
extern void init_robots_for_level(void);
|
||||
extern int ai_behavior_to_mode(int behavior);
|
||||
int ai_behavior_to_mode(ai_behavior behavior);
|
||||
#if defined(DXX_BUILD_DESCENT_II)
|
||||
void create_path_to_segment(vobjptridx_t objp, segnum_t goalseg, int max_length, int safety_flag);
|
||||
int polish_path(vobjptridx_t objp, point_seg *psegs, int num_points);
|
||||
|
|
|
@ -29,7 +29,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
#pragma once
|
||||
|
||||
#include <physfs.h>
|
||||
#include "polyobj.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "pack.h"
|
||||
|
@ -59,7 +58,7 @@ enum class player_awareness_type_t : int8_t
|
|||
#define AI_DIR_FORWARD 1
|
||||
#define AI_DIR_BACKWARD (-AI_DIR_FORWARD)
|
||||
|
||||
enum ai_behavior : uint8_t
|
||||
enum class ai_behavior : uint8_t
|
||||
{
|
||||
// Behaviors
|
||||
AIB_STILL = 0x80,
|
||||
|
@ -76,6 +75,8 @@ enum ai_behavior : uint8_t
|
|||
#endif
|
||||
};
|
||||
|
||||
#include "polyobj.h"
|
||||
|
||||
#define MIN_BEHAVIOR 0x80
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
#define MAX_BEHAVIOR 0x85
|
||||
|
@ -206,7 +207,7 @@ struct ai_local : public prohibit_void_ptr<ai_local>
|
|||
|
||||
struct ai_static : public prohibit_void_ptr<ai_static>
|
||||
{
|
||||
ubyte behavior; //
|
||||
ai_behavior behavior; //
|
||||
array<sbyte, MAX_AI_FLAGS> flags; // various flags, meaning defined by constants
|
||||
segnum_t hide_segment; // Segment to go to for hiding.
|
||||
short hide_index; // Index in Path_seg_points
|
||||
|
|
|
@ -31,6 +31,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
|
||||
#ifdef __cplusplus
|
||||
#include "pack.h"
|
||||
#include "aistruct.h"
|
||||
#include "polyobj.h"
|
||||
|
||||
#define MAX_GUNS 8 //should be multiple of 4 for ubyte array
|
||||
|
@ -143,7 +144,7 @@ struct robot_info : prohibit_void_ptr<robot_info>
|
|||
|
||||
ubyte deathroll_sound; // if has deathroll, what sound?
|
||||
ubyte glow; // apply this light to robot itself. stored as 4:4 fixed-point
|
||||
ubyte behavior; // Default behavior.
|
||||
ai_behavior behavior; // Default behavior.
|
||||
ubyte aim; // 255 = perfect, less = more likely to miss. 0 != random, would look stupid. 0=45 degree spread. Specify in bitmaps.tbl in range 0.0..1.0
|
||||
#endif
|
||||
//animation info
|
||||
|
|
|
@ -1145,7 +1145,8 @@ void bm_read_robot(int skip)
|
|||
short weapon_type = 0, weapon_type2 = -1;
|
||||
int g,s;
|
||||
char name[ROBOT_NAME_LENGTH];
|
||||
int contains_count=0, contains_id=0, contains_prob=0, contains_type=0, behavior=ai_behavior::AIB_NORMAL;
|
||||
int contains_count=0, contains_id=0, contains_prob=0, contains_type=0;
|
||||
auto behavior = ai_behavior::AIB_NORMAL;
|
||||
int companion = 0, smart_blobs=0, energy_blobs=0, badass=0, energy_drain=0, kamikaze=0, thief=0, pursuit=0, lightcast=0, death_roll=0;
|
||||
fix glow=0, aim=F1_0;
|
||||
int deathroll_sound = SOUND_BOSS_SHARE_DIE; //default
|
||||
|
|
|
@ -112,7 +112,7 @@ static movement_type_name &get_movement_type(int num)
|
|||
}
|
||||
}
|
||||
|
||||
static ai_type_name &get_ai_behavior(int num)
|
||||
static ai_type_name &get_ai_behavior(ai_behavior num)
|
||||
{
|
||||
switch (num) {
|
||||
case ai_behavior::AIB_STILL:
|
||||
|
@ -146,7 +146,7 @@ static void info_display_object_placement(int show_all)
|
|||
static int old_type;
|
||||
static int old_movement_type;
|
||||
static int old_control_type;
|
||||
static int old_mode;
|
||||
static ai_behavior old_mode;
|
||||
if (init_info || show_all ||
|
||||
( Cur_object_index != old_Cur_object_index) ||
|
||||
( Objects[Cur_object_index].type != old_type) ||
|
||||
|
|
|
@ -80,7 +80,7 @@ struct robot_dialog
|
|||
|
||||
static int robot_dialog_handler(UI_DIALOG *dlg,const d_event &event, robot_dialog *r);
|
||||
|
||||
static void call_init_ai_object(const vobjptr_t objp, int behavior)
|
||||
static void call_init_ai_object(const vobjptr_t objp, ai_behavior behavior)
|
||||
{
|
||||
segnum_t hide_segment;
|
||||
|
||||
|
@ -568,12 +568,27 @@ int robot_dialog_handler(UI_DIALOG *dlg,const d_event &event, robot_dialog *r)
|
|||
range_for (auto &i, r->initialMode)
|
||||
ui_radio_set_value(i.get(), 0);
|
||||
if ( Cur_object_index != object_none ) {
|
||||
int behavior = Objects[Cur_object_index].ctype.ai_info.behavior;
|
||||
if ( !((behavior >= MIN_BEHAVIOR) && (behavior <= MAX_BEHAVIOR))) {
|
||||
Objects[Cur_object_index].ctype.ai_info.behavior = ai_behavior::AIB_NORMAL;
|
||||
auto &behavior = Objects[Cur_object_index].ctype.ai_info.behavior;
|
||||
switch (behavior)
|
||||
{
|
||||
case ai_behavior::AIB_STILL:
|
||||
case ai_behavior::AIB_NORMAL:
|
||||
case ai_behavior::AIB_RUN_FROM:
|
||||
case ai_behavior::AIB_STATION:
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
case ai_behavior::AIB_HIDE:
|
||||
case ai_behavior::AIB_FOLLOW_PATH:
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
case ai_behavior::AIB_BEHIND:
|
||||
case ai_behavior::AIB_SNIPE:
|
||||
case ai_behavior::AIB_FOLLOW:
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
behavior = ai_behavior::AIB_NORMAL;
|
||||
break;
|
||||
}
|
||||
ui_radio_set_value(r->initialMode[behavior - MIN_BEHAVIOR].get(), 1);
|
||||
ui_radio_set_value(r->initialMode[static_cast<std::size_t>(behavior) - MIN_BEHAVIOR].get(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -583,12 +598,15 @@ int robot_dialog_handler(UI_DIALOG *dlg,const d_event &event, robot_dialog *r)
|
|||
//------------------------------------------------------------
|
||||
for ( int i=0; i < NUM_BOXES; i++ ) {
|
||||
if (GADGET_PRESSED(r->initialMode[i].get()))
|
||||
if (Objects[Cur_object_index].ctype.ai_info.behavior != MIN_BEHAVIOR+i) {
|
||||
Objects[Cur_object_index].ctype.ai_info.behavior = MIN_BEHAVIOR+i; // Set the ai_state to the cooresponding radio button
|
||||
call_init_ai_object(&Objects[Cur_object_index], MIN_BEHAVIOR+i);
|
||||
{
|
||||
const auto b = static_cast<ai_behavior>(MIN_BEHAVIOR + i);
|
||||
if (Objects[Cur_object_index].ctype.ai_info.behavior != b) {
|
||||
Objects[Cur_object_index].ctype.ai_info.behavior = b; // Set the ai_state to the cooresponding radio button
|
||||
call_init_ai_object(&Objects[Cur_object_index], b);
|
||||
rval = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Redraw the object in the little 64x64 box
|
||||
|
|
|
@ -353,20 +353,29 @@ static int ready_to_fire_any_weapon(const robot_info *robptr, const ai_local *ai
|
|||
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
// Given a behavior, set initial mode.
|
||||
int ai_behavior_to_mode(int behavior)
|
||||
int ai_behavior_to_mode(ai_behavior behavior)
|
||||
{
|
||||
switch (behavior) {
|
||||
case ai_behavior::AIB_STILL: return AIM_STILL;
|
||||
case ai_behavior::AIB_NORMAL: return AIM_CHASE_OBJECT;
|
||||
case ai_behavior::AIB_RUN_FROM: return AIM_RUN_FROM_OBJECT;
|
||||
case ai_behavior::AIB_STATION: return AIM_STILL;
|
||||
case ai_behavior::AIB_STILL:
|
||||
return AIM_STILL;
|
||||
case ai_behavior::AIB_NORMAL:
|
||||
return AIM_CHASE_OBJECT;
|
||||
case ai_behavior::AIB_RUN_FROM:
|
||||
return AIM_RUN_FROM_OBJECT;
|
||||
case ai_behavior::AIB_STATION:
|
||||
return AIM_STILL;
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
case ai_behavior::AIB_HIDE: return AIM_HIDE;
|
||||
case ai_behavior::AIB_FOLLOW_PATH: return AIM_FOLLOW_PATH;
|
||||
case ai_behavior::AIB_HIDE:
|
||||
return AIM_HIDE;
|
||||
case ai_behavior::AIB_FOLLOW_PATH:
|
||||
return AIM_FOLLOW_PATH;
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
case ai_behavior::AIB_BEHIND: return AIM_BEHIND;
|
||||
case ai_behavior::AIB_SNIPE: return AIM_STILL; // Changed, 09/13/95, MK, snipers are still until they see you or are hit.
|
||||
case ai_behavior::AIB_FOLLOW: return AIM_FOLLOW_PATH;
|
||||
case ai_behavior::AIB_BEHIND:
|
||||
return AIM_BEHIND;
|
||||
case ai_behavior::AIB_SNIPE:
|
||||
return AIM_STILL; // Changed, 09/13/95, MK, snipers are still until they see you or are hit.
|
||||
case ai_behavior::AIB_FOLLOW:
|
||||
return AIM_FOLLOW_PATH;
|
||||
#endif
|
||||
default: Int3(); // Contact Mike: Error, illegal behavior type
|
||||
}
|
||||
|
@ -386,14 +395,14 @@ void ai_init_boss_for_ship(void)
|
|||
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
// initial_mode == -1 means leave mode unchanged.
|
||||
void init_ai_object(const vobjptr_t objp, int behavior, segnum_t hide_segment)
|
||||
void init_ai_object(const vobjptr_t objp, ai_behavior behavior, segnum_t hide_segment)
|
||||
{
|
||||
ai_static *aip = &objp->ctype.ai_info;
|
||||
ai_local *ailp = &objp->ctype.ai_info.ail;
|
||||
|
||||
*ailp = {};
|
||||
|
||||
if (behavior == 0) {
|
||||
if (static_cast<unsigned>(behavior) == 0) {
|
||||
behavior = ai_behavior::AIB_NORMAL;
|
||||
aip->behavior = behavior;
|
||||
}
|
||||
|
@ -403,11 +412,9 @@ void init_ai_object(const vobjptr_t objp, int behavior, segnum_t hide_segment)
|
|||
|
||||
ailp->previous_visibility = 0;
|
||||
|
||||
if (behavior != -1) {
|
||||
{
|
||||
aip->behavior = behavior;
|
||||
ailp->mode = ai_behavior_to_mode(aip->behavior);
|
||||
} else if (!((aip->behavior >= MIN_BEHAVIOR) && (aip->behavior <= MAX_BEHAVIOR))) {
|
||||
aip->behavior = ai_behavior::AIB_NORMAL;
|
||||
}
|
||||
|
||||
robot_info *robptr = &Robot_info[get_robot_id(objp)];
|
||||
|
@ -1578,6 +1585,7 @@ void do_ai_robot_hit(const vobjptridx_t objp, player_awareness_type_t type)
|
|||
case ai_behavior::AIB_STILL:
|
||||
objp->ctype.ai_info.ail.mode = AIM_CHASE_OBJECT;
|
||||
break;
|
||||
case ai_behavior::AIB_FOLLOW_PATH:
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
case ai_behavior::AIB_STILL:
|
||||
{
|
||||
|
@ -1600,7 +1608,14 @@ void do_ai_robot_hit(const vobjptridx_t objp, player_awareness_type_t type)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case ai_behavior::AIB_BEHIND:
|
||||
case ai_behavior::AIB_SNIPE:
|
||||
case ai_behavior::AIB_FOLLOW:
|
||||
#endif
|
||||
case ai_behavior::AIB_NORMAL:
|
||||
case ai_behavior::AIB_RUN_FROM:
|
||||
case ai_behavior::AIB_STATION:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1894,7 +1909,6 @@ static objptridx_t create_gated_robot(const vsegptridx_t segp, int object_id, co
|
|||
const robot_info *robptr = &Robot_info[object_id];
|
||||
int count=0;
|
||||
fix objsize = Polygon_models[robptr->model_num].rad;
|
||||
int default_behavior;
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
const int maximum_gated_robots = 2*Difficulty_level + 3;
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
|
@ -1948,6 +1962,7 @@ static objptridx_t create_gated_robot(const vsegptridx_t segp, int object_id, co
|
|||
objp->shields = robptr->strength;
|
||||
objp->matcen_creator = BOSS_GATE_MATCEN_NUM; // flag this robot as having been created by the boss.
|
||||
|
||||
ai_behavior default_behavior;
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
default_behavior = ai_behavior::AIB_NORMAL;
|
||||
if (object_id == 10) // This is a toaster guy!
|
||||
|
@ -2980,8 +2995,24 @@ void do_ai_frame(const vobjptridx_t obj)
|
|||
#endif
|
||||
|
||||
//Assert((aip->behavior >= MIN_BEHAVIOR) && (aip->behavior <= MAX_BEHAVIOR));
|
||||
if (!((aip->behavior >= MIN_BEHAVIOR) && (aip->behavior <= MAX_BEHAVIOR))) {
|
||||
switch (aip->behavior)
|
||||
{
|
||||
case ai_behavior::AIB_STILL:
|
||||
case ai_behavior::AIB_NORMAL:
|
||||
case ai_behavior::AIB_RUN_FROM:
|
||||
case ai_behavior::AIB_STATION:
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
case ai_behavior::AIB_HIDE:
|
||||
case ai_behavior::AIB_FOLLOW_PATH:
|
||||
#elif defined(DXX_BUILD_DESCENT_II)
|
||||
case ai_behavior::AIB_BEHIND:
|
||||
case ai_behavior::AIB_SNIPE:
|
||||
case ai_behavior::AIB_FOLLOW:
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
aip->behavior = ai_behavior::AIB_NORMAL;
|
||||
break;
|
||||
}
|
||||
|
||||
Assert(obj->segnum != segment_none);
|
||||
|
|
|
@ -298,7 +298,6 @@ Restart: ;
|
|||
|
||||
objptridx_t create_morph_robot( const vsegptridx_t segp, const vms_vector &object_pos, int object_id)
|
||||
{
|
||||
int default_behavior;
|
||||
|
||||
Players[Player_num].num_robots_level++;
|
||||
Players[Player_num].num_robots_total++;
|
||||
|
@ -325,7 +324,7 @@ objptridx_t create_morph_robot( const vsegptridx_t segp, const vms_vector &obje
|
|||
obj->mtype.phys_info.flags |= (PF_LEVELLING);
|
||||
|
||||
obj->shields = Robot_info[get_robot_id(obj)].strength;
|
||||
|
||||
ai_behavior default_behavior;
|
||||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
default_behavior = ai_behavior::AIB_NORMAL;
|
||||
if (object_id == 10) // This is a toaster guy!
|
||||
|
|
|
@ -420,7 +420,7 @@ static void read_object(const vobjptr_t obj,PHYSFS_file *f,int version)
|
|||
switch (obj->control_type) {
|
||||
|
||||
case CT_AI: {
|
||||
obj->ctype.ai_info.behavior = PHYSFSX_readByte(f);
|
||||
obj->ctype.ai_info.behavior = static_cast<ai_behavior>(PHYSFSX_readByte(f));
|
||||
|
||||
range_for (auto &i, obj->ctype.ai_info.flags)
|
||||
i = PHYSFSX_readByte(f);
|
||||
|
@ -662,7 +662,7 @@ static void write_object(const vcobjptr_t obj, short version, PHYSFS_file *f)
|
|||
switch (obj->control_type) {
|
||||
|
||||
case CT_AI: {
|
||||
PHYSFSX_writeU8(f, obj->ctype.ai_info.behavior);
|
||||
PHYSFSX_writeU8(f, static_cast<uint8_t>(obj->ctype.ai_info.behavior));
|
||||
|
||||
range_for (auto &i, obj->ctype.ai_info.flags)
|
||||
PHYSFSX_writeU8(f, i);
|
||||
|
|
|
@ -5378,7 +5378,7 @@ void multi_object_to_object_rw(const vobjptr_t obj, object_rw *obj_rw)
|
|||
case CT_AI:
|
||||
{
|
||||
int i;
|
||||
obj_rw->ctype.ai_info.behavior = obj->ctype.ai_info.behavior;
|
||||
obj_rw->ctype.ai_info.behavior = static_cast<uint8_t>(obj->ctype.ai_info.behavior);
|
||||
for (i = 0; i < MAX_AI_FLAGS; i++)
|
||||
obj_rw->ctype.ai_info.flags[i] = obj->ctype.ai_info.flags[i];
|
||||
obj_rw->ctype.ai_info.hide_segment = obj->ctype.ai_info.hide_segment;
|
||||
|
@ -5546,7 +5546,7 @@ void multi_object_rw_to_object(object_rw *obj_rw, const vobjptr_t obj)
|
|||
case CT_AI:
|
||||
{
|
||||
int i;
|
||||
obj->ctype.ai_info.behavior = obj_rw->ctype.ai_info.behavior;
|
||||
obj->ctype.ai_info.behavior = static_cast<ai_behavior>(obj_rw->ctype.ai_info.behavior);
|
||||
for (i = 0; i < MAX_AI_FLAGS; i++)
|
||||
obj->ctype.ai_info.flags[i] = obj_rw->ctype.ai_info.flags[i];
|
||||
obj->ctype.ai_info.hide_segment = obj_rw->ctype.ai_info.hide_segment;
|
||||
|
|
|
@ -288,7 +288,7 @@ void robot_info_read(PHYSFS_File *fp, robot_info &ri)
|
|||
|
||||
ri.deathroll_sound = PHYSFSX_readByte(fp);
|
||||
ri.glow = PHYSFSX_readByte(fp);
|
||||
ri.behavior = PHYSFSX_readByte(fp);
|
||||
ri.behavior = static_cast<ai_behavior>(PHYSFSX_readByte(fp));
|
||||
ri.aim = PHYSFSX_readByte(fp);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ static void state_object_to_object_rw(const vcobjptr_t obj, object_rw *obj_rw)
|
|||
case CT_AI:
|
||||
{
|
||||
int i;
|
||||
obj_rw->ctype.ai_info.behavior = obj->ctype.ai_info.behavior;
|
||||
obj_rw->ctype.ai_info.behavior = static_cast<uint8_t>(obj->ctype.ai_info.behavior);
|
||||
for (i = 0; i < MAX_AI_FLAGS; i++)
|
||||
obj_rw->ctype.ai_info.flags[i] = obj->ctype.ai_info.flags[i];
|
||||
obj_rw->ctype.ai_info.hide_segment = obj->ctype.ai_info.hide_segment;
|
||||
|
@ -383,7 +383,7 @@ static void state_object_rw_to_object(object_rw *obj_rw, const vobjptr_t obj)
|
|||
case CT_AI:
|
||||
{
|
||||
int i;
|
||||
obj->ctype.ai_info.behavior = obj_rw->ctype.ai_info.behavior;
|
||||
obj->ctype.ai_info.behavior = static_cast<ai_behavior>(obj_rw->ctype.ai_info.behavior);
|
||||
for (i = 0; i < MAX_AI_FLAGS; i++)
|
||||
obj->ctype.ai_info.flags[i] = obj_rw->ctype.ai_info.flags[i];
|
||||
obj->ctype.ai_info.hide_segment = obj_rw->ctype.ai_info.hide_segment;
|
||||
|
|
Loading…
Reference in a new issue