Skip to content

Commit

Permalink
Merge pull request #315 from olanti-p/misc-fixes-5
Browse files Browse the repository at this point in the history
Misc bugfixes from DDA 5
  • Loading branch information
Coolthulhu authored Jan 17, 2021
2 parents 6af574f + 306de96 commit 431e761
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 65 deletions.
5 changes: 4 additions & 1 deletion data/json/vehicleparts/rams.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@
"durability": 40,
"description": "A mattress, strapped onto the vehicle. It could serve to blunt any impact.",
"breaks_into": [ { "item": "rag", "count": [ 40, 55 ] } ],
"requirements": { "install": { "skills": [ [ "mechanics", 0 ] ], "time": "5 m", "using": [ [ "rope_natural_short", 2 ] ] } },
"requirements": {
"install": { "skills": [ [ "mechanics", 0 ] ], "time": "5 m", "using": [ [ "rope_natural_short", 2 ] ] },
"removal": { "skills": [ [ "mechanics", 0 ] ], "time": "5 m", "using": [ ] }
},
"damage_reduction": { "bash": 20 },
"flags": [ "PROTRUSION", "OBSTACLE", "OPAQUE" ]
},
Expand Down
3 changes: 2 additions & 1 deletion src/advanced_inv_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void advanced_inventory_pane::save_settings()
void advanced_inventory_pane::load_settings( int saved_area_idx,
const std::array<advanced_inv_area, NUM_AIM_LOCATIONS> &squares, bool is_re_enter )
{
const int i_location = ( get_option<bool>( "OPEN_DEFAULT_ADV_INV" ) ) ? saved_area_idx :
const int i_location = ( get_option<bool>( "OPEN_DEFAULT_ADV_INV" ) &&
!is_re_enter ) ? saved_area_idx :
save_state->area_idx;
const aim_location location = static_cast<aim_location>( i_location );
auto square = squares[location];
Expand Down
4 changes: 0 additions & 4 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,15 +1787,11 @@ int Character::bionics_pl_skill( const skill_id &most_important_skill,
// Medical residents have some idea what they're doing
if( has_trait( trait_PROF_MED ) ) {
pl_skill += 3;
add_msg_player_or_npc( m_neutral, _( "You prep to begin surgery." ),
_( "<npcname> prepares for surgery." ) );
}

// People trained in bionics gain an additional advantage towards using it
if( has_trait( trait_PROF_AUTODOC ) ) {
pl_skill += 7;
add_msg( m_neutral, _( "A lifetime of augmentation has taught %s a thing or two…" ),
disp_name() );
}
return pl_skill;
}
Expand Down
8 changes: 7 additions & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9328,7 +9328,13 @@ bool Character::has_fire( const int quantity ) const
} else if( has_item_with_flag( "FIRESTARTER" ) ) {
auto firestarters = all_items_with_flag( "FIRESTARTER" );
for( auto &i : firestarters ) {
if( has_charges( i->typeId(), quantity ) ) {
if( !i->type->can_have_charges() ) {
const use_function *usef = i->type->get_use( "firestarter" );
const firestarter_actor *actor = dynamic_cast<const firestarter_actor *>( usef->get_actor_ptr() );
if( actor->can_use( *this->as_character(), *i, false, tripoint_zero ).success() ) {
return true;
}
} else if( has_charges( i->typeId(), quantity ) ) {
return true;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8727,6 +8727,7 @@ bool item::process_extinguish( player *carrier, const tripoint &pos )
bool submerged = false;
bool precipitation = false;
bool windtoostrong = false;
bool in_veh = carrier != nullptr && carrier->in_vehicle;
w_point weatherPoint = *g->weather.weather_precise;
int windpower = g->weather.windspeed;
switch( g->weather.weather ) {
Expand All @@ -8749,11 +8750,11 @@ bool item::process_extinguish( player *carrier, const tripoint &pos )
default:
break;
}
if( in_inv && g->m.has_flag( flag_DEEP_WATER, pos ) ) {
if( in_inv && !in_veh && g->m.has_flag( flag_DEEP_WATER, pos ) ) {
extinguish = true;
submerged = true;
}
if( ( !in_inv && g->m.has_flag( flag_LIQUID, pos ) ) ||
if( ( !in_inv && g->m.has_flag( flag_LIQUID, pos ) && !g->m.veh_at( pos ) ) ||
( precipitation && !g->is_sheltered( pos ) ) ) {
extinguish = true;
}
Expand Down
6 changes: 6 additions & 0 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,9 @@ class jmapgen_liquid_item : public jmapgen_piece
amount( jsi, "amount", 0, 0 )
, liquid( jsi.get_string( "liquid" ) )
, chance( jsi, "chance", 1, 1 ) {
// Itemgroups apply migrations when being loaded, but we need to migrate
// individual items here.
liquid = item_controller->migrate_id( itype_id( liquid ) );
if( !item::type_is_defined( itype_id( liquid ) ) ) {
set_mapgen_defer( jsi, "liquid", "no such item type '" + liquid + "'" );
}
Expand Down Expand Up @@ -1389,6 +1392,9 @@ class jmapgen_spawn_item : public jmapgen_piece
type( jsi.get_string( "item" ) )
, amount( jsi, "amount", 1, 1 )
, chance( jsi, "chance", 100, 100 ) {
// Itemgroups apply migrations when being loaded, but we need to migrate
// individual items here.
type = item_controller->migrate_id( type );
if( !item::type_is_defined( type ) ) {
set_mapgen_defer( jsi, "item", "no such item" );
}
Expand Down
76 changes: 50 additions & 26 deletions src/mission_companion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ bool talk_function::display_and_choose_opts( mission_data &mission_key, const tr
base_camps::tab_mode tab_mode = base_camps::TAB_MAIN;

size_t sel = 0;
int name_offset = 0;

// The following are for managing the right pane scrollbar.
size_t info_offset = 0;
Expand Down Expand Up @@ -432,6 +433,8 @@ bool talk_function::display_and_choose_opts( mission_data &mission_key, const tr

ui_adaptor ui;
ui.on_screen_resize( [&]( ui_adaptor & ui ) {
name_offset = 0;
info_offset = 0;
part_y = TERMY > FULL_SCREEN_HEIGHT ? ( TERMY - FULL_SCREEN_HEIGHT ) / 4 : 0;
part_x = TERMX > FULL_SCREEN_WIDTH ? ( TERMX - FULL_SCREEN_WIDTH ) / 4 : 0;
maxy = part_y ? TERMY - 2 * part_y : FULL_SCREEN_HEIGHT;
Expand Down Expand Up @@ -460,51 +463,70 @@ bool talk_function::display_and_choose_opts( mission_data &mission_key, const tr
mvwprintz( w_list, point( 1, 1 ), c_white, name_mission_tabs( omt_pos, role_id, title,
tab_mode ) );

std::vector<std::vector<std::string>> folded_names;
size_t folded_names_lines = 0;
for( const auto &cur_key_entry : cur_key_list ) {
std::vector<std::string> f_name = foldstring( cur_key_entry.name_display, MAX_FAC_NAME_SIZE - 5,
' ' );
folded_names_lines += f_name.size();
folded_names.emplace_back( f_name );
}
struct disp_entry {
std::vector<std::string> lines;
nc_color col;
};

int name_offset = 0;
calcStartPos( name_offset, sel, info_height, folded_names_lines );
std::vector<disp_entry> disp_names;
size_t folded_names_lines = 0;
for( size_t i = 0; i < cur_key_list.size(); i++ ) {
const mission_entry &e = cur_key_list[i];
std::vector<std::string> lines = foldstring( e.name_display, MAX_FAC_NAME_SIZE - 5, ' ' );
nc_color col = i == sel ? h_white : c_white;

size_t list_line = 2;
for( size_t current = name_offset; list_line < info_height &&
current < cur_key_list.size(); current++ ) {
nc_color col = ( current == sel ? h_white : c_white );
//highlight important missions
for( const auto &k : mission_key.entries[0] ) {
if( cur_key_list[current].id == k.id ) {
col = ( current == sel ? h_white : c_yellow );
if( e.id == k.id ) {
col = ( i == sel ? h_white : c_yellow );
break;
}
}
//dull uncraftable items
for( const auto &k : mission_key.entries[10] ) {
if( cur_key_list[current].id == k.id ) {
col = ( current == sel ? h_white : c_dark_gray );
if( e.id == k.id ) {
col = ( i == sel ? h_white : c_dark_gray );
break;
}
}
std::vector<std::string> &name_text = folded_names[current];
for( size_t name_line = 0; name_line < name_text.size(); name_line++ ) {
print_colored_text( w_list, point( name_line ? 5 : 1, list_line ),
col, col, name_text[name_line] );
list_line += 1;

folded_names_lines += lines.size();
disp_names.push_back( { lines, col } );
}

size_t sel_pos_min = 0;
for( size_t i = 0; i < sel; i++ ) {
sel_pos_min += disp_names[i].lines.size();
}
size_t sel_pos_max = sel_pos_min + disp_names[sel].lines.size() - 1;

// Make sure the selected entry is fully visible,
// and the cursor is positioned at 1st line of the entry.
calcStartPos( name_offset, sel_pos_max, info_height, folded_names_lines );
calcStartPos( name_offset, sel_pos_min, info_height, folded_names_lines );

// Some entries may be shown only partially,
// but that's fine since it makes scrolling smoother.
int name_curr = 0;
int name_max = name_offset + static_cast<int>( info_height );
for( const disp_entry &e : disp_names ) {
for( size_t i = 0; i < e.lines.size() && name_curr < name_max; i++, name_curr++ ) {
if( name_curr < name_offset ) {
continue;
}
point p( i == 0 ? 1 : 5, name_curr - name_offset + 2 );
nc_color col = e.col;
print_colored_text( w_list, p, col, col, e.lines[i] );
}
}

if( cur_key_list.size() > info_height + 1 ) {
if( folded_names_lines > info_height ) {
scrollbar()
.offset_x( 0 )
.offset_y( 1 )
.content_size( folded_names_lines )
.viewport_pos( sel )
.viewport_size( info_height + 1 )
.viewport_pos( name_offset )
.viewport_size( info_height )
.apply( w_list );
}
wnoutrefresh( w_list );
Expand Down Expand Up @@ -569,6 +591,7 @@ bool talk_function::display_and_choose_opts( mission_data &mission_key, const tr
info_offset++;
} else if( action == "NEXT_TAB" && role_id == "FACTION_CAMP" ) {
sel = 0;
name_offset = 0;
info_offset = 0;

do {
Expand All @@ -582,6 +605,7 @@ bool talk_function::display_and_choose_opts( mission_data &mission_key, const tr
} while( cur_key_list.empty() );
} else if( action == "PREV_TAB" && role_id == "FACTION_CAMP" ) {
sel = 0;
name_offset = 0;
info_offset = 0;

do {
Expand Down
4 changes: 4 additions & 0 deletions src/monattack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ bool mattack::eat_food( monster *z )
if( g->m.has_flag( "PLANT", p ) ) {
continue;
}
// Don't snap up food RIGHT under the player's nose.
if( z->friendly && rl_dist( g->u.pos(), p ) <= 2 ) {
continue;
}
auto items = g->m.i_at( p );
for( auto &item : items ) {
//Fun limit prevents scavengers from eating feces
Expand Down
5 changes: 5 additions & 0 deletions src/sdlsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "init.h"
#include "json.h"
#include "loading_ui.h"
#include "messages.h"
#include "options.h"
#include "path_info.h"
#include "rng.h"
Expand Down Expand Up @@ -442,6 +443,8 @@ static Mix_Chunk *do_pitch_shift( Mix_Chunk *s, float pitch )

void sfx::play_variant_sound( const std::string &id, const std::string &variant, int volume )
{
add_msg( m_debug, "sound id: %s, variant: %s, volume: %d ", id, variant, volume );

if( !check_sound( volume ) ) {
return;
}
Expand All @@ -466,6 +469,8 @@ void sfx::play_variant_sound( const std::string &id, const std::string &variant,
void sfx::play_variant_sound( const std::string &id, const std::string &variant, int volume,
int angle, double pitch_min, double pitch_max )
{
add_msg( m_debug, "sound id: %s, variant: %s, volume: %d ", id, variant, volume );

if( !check_sound( volume ) ) {
return;
}
Expand Down
64 changes: 41 additions & 23 deletions src/sounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,39 +1401,55 @@ void sfx::do_footstep()
static const std::set<ter_str_id> chain_fence = {
ter_str_id( "t_chainfence" ),
};
if( !g->u.wearing_something_on( bp_foot_l ) ) {
play_variant_sound( "plmove", "walk_barefoot", heard_volume, 0, 0.8, 1.2 );

const auto play_plmove_sound_variant = [&]( const std::string & variant ) {
play_variant_sound( "plmove", variant, heard_volume, 0, 0.8, 1.2 );
start_sfx_timestamp = std::chrono::high_resolution_clock::now();
};

auto veh_displayed_part = g->m.veh_at( g->u.pos() ).part_displayed();

if( !veh_displayed_part && ( water.count( terrain ) > 0 ) ) {
play_plmove_sound_variant( "walk_water" );
return;
} else if( sfx::has_variant_sound( "plmove", terrain.str() ) ) {
play_variant_sound( "plmove", terrain.str(), heard_volume, 0, 0.8, 1.2 );
start_sfx_timestamp = std::chrono::high_resolution_clock::now();
}
if( !g->u.wearing_something_on( body_part::bp_foot_l ) ) {
play_plmove_sound_variant( "walk_barefoot" );
return;
} else if( grass.count( terrain ) > 0 ) {
play_variant_sound( "plmove", "walk_grass", heard_volume, 0, 0.8, 1.2 );
start_sfx_timestamp = std::chrono::high_resolution_clock::now();
}
if( veh_displayed_part ) {
const std::string &part_id = veh_displayed_part->part().info().get_id().str();
if( has_variant_sound( "plmove", part_id ) ) {
play_plmove_sound_variant( part_id );
} else if( veh_displayed_part->has_feature( VPFLAG_AISLE ) ) {
play_plmove_sound_variant( "walk_tarmac" );
} else {
play_plmove_sound_variant( "clear_obstacle" );
}
return;
} else if( dirt.count( terrain ) > 0 ) {
play_variant_sound( "plmove", "walk_dirt", heard_volume, 0, 0.8, 1.2 );
start_sfx_timestamp = std::chrono::high_resolution_clock::now();
}
if( sfx::has_variant_sound( "plmove", terrain.str() ) ) {
play_plmove_sound_variant( terrain.str() );
return;
} else if( metal.count( terrain ) > 0 ) {
play_variant_sound( "plmove", "walk_metal", heard_volume, 0, 0.8, 1.2 );
start_sfx_timestamp = std::chrono::high_resolution_clock::now();
}
if( grass.count( terrain ) > 0 ) {
play_plmove_sound_variant( "walk_grass" );
return;
} else if( water.count( terrain ) > 0 ) {
play_variant_sound( "plmove", "walk_water", heard_volume, 0, 0.8, 1.2 );
start_sfx_timestamp = std::chrono::high_resolution_clock::now();
}
if( dirt.count( terrain ) > 0 ) {
play_plmove_sound_variant( "walk_dirt" );
return;
} else if( chain_fence.count( terrain ) > 0 ) {
play_variant_sound( "plmove", "clear_obstacle", heard_volume, 0, 0.8, 1.2 );
start_sfx_timestamp = std::chrono::high_resolution_clock::now();
}
if( metal.count( terrain ) > 0 ) {
play_plmove_sound_variant( "walk_metal" );
return;
} else {
play_variant_sound( "plmove", "walk_tarmac", heard_volume, 0, 0.8, 1.2 );
start_sfx_timestamp = std::chrono::high_resolution_clock::now();
}
if( chain_fence.count( terrain ) > 0 ) {
play_plmove_sound_variant( "clear_obstacle" );
return;
}

play_plmove_sound_variant( "walk_tarmac" );
}
}

Expand All @@ -1458,6 +1474,8 @@ void sfx::do_obstacle( const std::string &obst )
} else {
play_variant_sound( "plmove", "clear_obstacle", heard_volume, 0, 0.8, 1.2 );
}
// prevent footsteps from triggering
start_sfx_timestamp = std::chrono::high_resolution_clock::now();
}

void sfx::play_activity_sound( const std::string &id, const std::string &variant, int volume )
Expand Down
Loading

0 comments on commit 431e761

Please sign in to comment.