Use enum class for check_volatile_wall

This commit is contained in:
Kp 2016-01-29 04:05:47 +00:00
parent bc488a8f57
commit e283a22709
3 changed files with 38 additions and 25 deletions

View file

@ -64,7 +64,13 @@ void drop_player_eggs(vobjptridx_t playerobj);
#if defined(DXX_BUILD_DESCENT_II)
void do_final_boss_frame(void);
void do_final_boss_hacks(void);
int check_volatile_wall(vobjptridx_t obj,vcsegptr_t seg,int sidenum);
enum class volatile_wall_result : int8_t
{
none = -1,
lava,
water,
};
volatile_wall_result check_volatile_wall(vobjptridx_t obj,vcsegptr_t seg,int sidenum);
extern int Final_boss_is_dead;
#endif
#endif

View file

@ -448,7 +448,7 @@ void scrape_player_on_wall(const vobjptridx_t obj, const vsegptridx_t hitseg, sh
//see if wall is volatile or water
//if volatile, cause damage to player
//returns 1=lava, 2=water
int check_volatile_wall(const vobjptridx_t obj, const vcsegptr_t seg, int sidenum)
volatile_wall_result check_volatile_wall(const vobjptridx_t obj, const vcsegptr_t seg, int sidenum)
{
Assert(obj->type==OBJ_PLAYER);
@ -474,30 +474,28 @@ int check_volatile_wall(const vobjptridx_t obj, const vcsegptr_t seg, int sidenu
obj->mtype.phys_info.rotvel.z = (d_rand() - 16384)/2;
}
return (d>0)?1:2;
return (d > 0) ? volatile_wall_result::lava : volatile_wall_result::water;
}
else
{
return 0;
return volatile_wall_result::none;
}
}
//this gets called when an object is scraping along the wall
void scrape_player_on_wall(const vobjptridx_t obj, const vsegptridx_t hitseg, short hitside, const vms_vector &hitpt)
{
int type;
if (obj->type != OBJ_PLAYER || get_player_id(obj) != Player_num)
return;
if ((type=check_volatile_wall(obj,hitseg,hitside))!=0) {
const auto type = check_volatile_wall(obj, hitseg, hitside);
if (type != volatile_wall_result::none)
{
vms_vector hit_dir;
if ((GameTime64 > Last_volatile_scrape_sound_time + F1_0/4) || (GameTime64 < Last_volatile_scrape_sound_time)) {
int sound = (type==1)?SOUND_VOLATILE_WALL_HISS:SOUND_SHIP_IN_WATER;
Last_volatile_scrape_sound_time = GameTime64;
const auto sound = (type == volatile_wall_result::lava) ? SOUND_VOLATILE_WALL_HISS : SOUND_SHIP_IN_WATER;
multi_digi_link_sound_to_pos(sound, hitseg, 0, hitpt, 0, F1_0);
}

View file

@ -1745,30 +1745,39 @@ static void object_move_one(const vobjptridx_t obj)
}
#if defined(DXX_BUILD_DESCENT_II)
{
int sidemask,under_lavafall=0;
static int lavafall_hiss_playing[MAX_PLAYERS]={0};
bool under_lavafall = false;
static array<bool, MAX_PLAYERS> lavafall_hiss_playing;
sidemask = get_seg_masks(obj->pos, vcsegptr(obj->segnum), obj->size).sidemask;
if (sidemask) {
int sidenum,bit,wall_num;
for (sidenum=0,bit=1;sidenum<6;bit<<=1,sidenum++)
if ((sidemask & bit) && ((wall_num=Segments[obj->segnum].sides[sidenum].wall_num)!=-1) && Walls[wall_num].type==WALL_ILLUSION) {
int type;
if ((type=check_volatile_wall(obj,vsegptridx(obj->segnum),sidenum))!=0) {
int sound = (type==1)?SOUND_LAVAFALL_HISS:SOUND_SHIP_IN_WATERFALL;
auto &playing = lavafall_hiss_playing[get_player_id(obj)];
const auto &&segp = vcsegptr(obj->segnum);
if (const auto sidemask = get_seg_masks(obj->pos, segp, obj->size).sidemask)
{
for (unsigned sidenum = 0; sidenum != MAX_SIDES_PER_SEGMENT; ++sidenum)
{
if (!(sidemask & (1 << sidenum)))
continue;
const auto wall_num = segp->sides[sidenum].wall_num;
if (wall_num != wall_none && Walls[wall_num].type == WALL_ILLUSION)
{
const auto type = check_volatile_wall(obj, segp, sidenum);
if (type != volatile_wall_result::none)
{
under_lavafall = 1;
if (!lavafall_hiss_playing[get_player_id(obj)])
if (!playing)
{
lavafall_hiss_playing[get_player_id(obj)] = 1;
playing = 1;
const auto sound = (type == volatile_wall_result::lava) ? SOUND_LAVAFALL_HISS : SOUND_SHIP_IN_WATERFALL;
digi_link_sound_to_object3( sound, obj, 1, F1_0, vm_distance{i2f(256)}, -1, -1);
break;
}
}
}
}
}
if (!under_lavafall && lavafall_hiss_playing[get_player_id(obj)]) {
lavafall_hiss_playing[get_player_id(obj)] = 0;
if (!under_lavafall && playing)
{
playing = 0;
digi_kill_sound_linked_to_object( obj);
}
}