Skip to content

Commit

Permalink
Convert skill_exercise_type to enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
anothersimulacrum committed Apr 14, 2020
1 parent 2051f37 commit 823983b
Show file tree
Hide file tree
Showing 24 changed files with 112 additions and 99 deletions.
40 changes: 21 additions & 19 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,11 +1148,13 @@ static void butchery_drops_harvest( item *corpse_item, const mtype &mt, player &
}

if( action == DISSECT ) {
p.practice( skill_firstaid, PRACTICE, std::max( 0, practice ), std::max( mt.size - MS_MEDIUM,
0 ) + 4 );
p.practice( skill_firstaid, skill_exercise_type::PRACTICE, std::max( 0, practice ),
std::max( mt.size - MS_MEDIUM,
0 ) + 4 );
} else {
p.practice( skill_survival, PRACTICE, std::max( 0, practice ), std::max( mt.size - MS_MEDIUM,
0 ) + 4 );
p.practice( skill_survival, skill_exercise_type::PRACTICE, std::max( 0, practice ),
std::max( mt.size - MS_MEDIUM,
0 ) + 4 );
}
}

Expand Down Expand Up @@ -1900,8 +1902,8 @@ void activity_handlers::make_zlave_finish( player_activity *act, player *p )

if( success > 0 ) {

p->practice( skill_firstaid, PRACTICE, rng( 2, 5 ) );
p->practice( skill_survival, PRACTICE, rng( 2, 5 ) );
p->practice( skill_firstaid, skill_exercise_type::PRACTICE, rng( 2, 5 ) );
p->practice( skill_survival, skill_exercise_type::PRACTICE, rng( 2, 5 ) );

p->add_msg_if_player( m_good,
_( "You slice muscles and tendons, and remove body parts until you're confident the zombie won't be able to attack you when it reanimates." ) );
Expand All @@ -1914,8 +1916,8 @@ void activity_handlers::make_zlave_finish( player_activity *act, player *p )

} else if( success > -20 ) {

p->practice( skill_firstaid, PRACTICE, rng( 3, 6 ) );
p->practice( skill_survival, PRACTICE, rng( 3, 6 ) );
p->practice( skill_firstaid, skill_exercise_type::PRACTICE, rng( 3, 6 ) );
p->practice( skill_survival, skill_exercise_type::PRACTICE, rng( 3, 6 ) );

p->add_msg_if_player( m_warning,
_( "You hack into the corpse and chop off some body parts. You think the zombie won't be able to attack when it reanimates." ) );
Expand All @@ -1930,8 +1932,8 @@ void activity_handlers::make_zlave_finish( player_activity *act, player *p )

} else {

p->practice( skill_firstaid, PRACTICE, rng( 1, 8 ) );
p->practice( skill_survival, PRACTICE, rng( 1, 8 ) );
p->practice( skill_firstaid, skill_exercise_type::PRACTICE, rng( 1, 8 ) );
p->practice( skill_survival, skill_exercise_type::PRACTICE, rng( 1, 8 ) );

body->mod_damage( rng( 0, body->max_damage() - body->damage() ), DT_STAB );
if( body->damage() == body->max_damage() ) {
Expand Down Expand Up @@ -2053,7 +2055,7 @@ void activity_handlers::pulp_do_turn( player_activity *act, player *p )

if( one_in( 4 ) ) {
// Smashing may not be butchery, but it involves some zombie anatomy
p->practice( skill_survival, PRACTICE, 2, 2 );
p->practice( skill_survival, skill_exercise_type::PRACTICE, 2, 2 );
}

float stamina_ratio = static_cast<float>( p->get_stamina() ) / p->get_stamina_max();
Expand Down Expand Up @@ -2178,7 +2180,7 @@ void activity_handlers::start_fire_finish( player_activity *act, player *p )
if( it.type->can_have_charges() ) {
p->consume_charges( it, it.type->charges_to_use() );
}
p->practice( skill_survival, PRACTICE, act->index, 5 );
p->practice( skill_survival, skill_exercise_type::PRACTICE, act->index, 5 );

firestarter_actor::resolve_firestarter_use( *p, act->placement );
act->set_to_null();
Expand Down Expand Up @@ -2257,7 +2259,7 @@ void activity_handlers::train_finish( player_activity *act, player *p )
const Skill &skill = sk.obj();
std::string skill_name = skill.name();
int old_skill_level = p->get_skill_level( sk );
p->practice( sk, KNOWLEDGE, 100, old_skill_level + 2 );
p->practice( sk, skill_exercise_type::KNOWLEDGE, 100, old_skill_level + 2 );
int new_skill_level = p->get_skill_level( sk );
if( old_skill_level != new_skill_level ) {
add_msg( m_good, _( "You finish training %s to level %d." ),
Expand Down Expand Up @@ -3151,7 +3153,7 @@ void activity_handlers::fish_do_turn( player_activity *act, player *p )
rod_fish( p, fishables );
}
if( calendar::once_every( 60_minutes ) ) {
p->practice( skill_survival, PRACTICE, rng( 1, 3 ) );
p->practice( skill_survival, skill_exercise_type::PRACTICE, rng( 1, 3 ) );
}

}
Expand Down Expand Up @@ -3983,7 +3985,7 @@ void activity_handlers::pry_nails_finish( player_activity *act, player *p )
}
p->add_msg_if_player( _( "You pry the boards from the door." ) );
}
p->practice( skill_fabrication, PRACTICE, 1, 1 );
p->practice( skill_fabrication, skill_exercise_type::PRACTICE, 1, 1 );
g->m.spawn_item( p->pos(), "nail", 0, nails );
g->m.spawn_item( p->pos(), "2x4", boards );
g->m.ter_set( pnt, newter );
Expand Down Expand Up @@ -4520,7 +4522,7 @@ void activity_handlers::robot_control_finish( player_activity *act, player *p )
//damage it a little
z->apply_damage( p, bp_torso, rng( 1, 10 ) );
if( z->is_dead() ) {
p->practice( skill_id( "computer" ), PRACTICE, 10 );
p->practice( skill_id( "computer" ), skill_exercise_type::PRACTICE, 10 );
// Do not do the other effects if the robot died
return;
}
Expand All @@ -4538,7 +4540,7 @@ void activity_handlers::robot_control_finish( player_activity *act, player *p )
} else {
p->add_msg_if_player( _( "…but the robot refuses to acknowledge you as an ally!" ) );
}
p->practice( skill_computer, PRACTICE, 10 );
p->practice( skill_computer, skill_exercise_type::PRACTICE, 10 );
}

void activity_handlers::tree_communion_do_turn( player_activity *act, player *p )
Expand Down Expand Up @@ -4621,7 +4623,7 @@ static hack_result hack_attempt( player &p )
return HACK_UNABLE;
}

p.practice( skill_computer, PRACTICE, 20 );
p.practice( skill_computer, skill_exercise_type::PRACTICE, 20 );
if( using_fingerhack ) {
p.mod_power_level( -25_kJ );
} else {
Expand Down Expand Up @@ -4910,7 +4912,7 @@ void activity_handlers::study_spell_finish( player_activity *act, player *p )
p->add_msg_if_player( m_good, _( "You gained %i experience from your study session." ),
total_exp_gained );
const spell &sp = p->magic.get_spell( spell_id( act->name ) );
p->practice( sp.skill(), PRACTICE, total_exp_gained, sp.get_difficulty() );
p->practice( sp.skill(), skill_exercise_type::PRACTICE, total_exp_gained, sp.get_difficulty() );
} else if( act->get_str_value( 1 ) == "learn" && act->values[2] == 0 ) {
p->magic.learn_spell( act->name, *p );
}
Expand Down
2 changes: 1 addition & 1 deletion src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ void avatar_action::swim( map &m, avatar &you, const tripoint &p )
you.remove_effect( effect_glowing );
}
int movecost = you.swim_speed();
you.practice( skill_swimming, PRACTICE, you.is_underwater() ? 2 : 1 );
you.practice( skill_swimming, skill_exercise_type::PRACTICE, you.is_underwater() ? 2 : 1 );
if( movecost >= 500 ) {
if( !you.is_underwater() && !( you.shoe_type_count( "swim_fins" ) == 2 ||
( you.shoe_type_count( "swim_fins" ) == 1 && one_in( 2 ) ) ) ) {
Expand Down
6 changes: 3 additions & 3 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2169,11 +2169,11 @@ bool Character::install_bionics( const itype &type, player &installer, bool auto

// Practice skills only if conducting manual installation
if( !autodoc ) {
installer.practice( skill_electronics, PRACTICE,
installer.practice( skill_electronics, skill_exercise_type::PRACTICE,
static_cast<int>( ( 100 - chance_of_success ) * 1.5 ) );
installer.practice( skill_firstaid, PRACTICE,
installer.practice( skill_firstaid, skill_exercise_type::PRACTICE,
static_cast<int>( ( 100 - chance_of_success ) * 1.0 ) );
installer.practice( skill_mechanics, PRACTICE,
installer.practice( skill_mechanics, skill_exercise_type::PRACTICE,
static_cast<int>( ( 100 - chance_of_success ) * 0.5 ) );
}

Expand Down
8 changes: 4 additions & 4 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1556,12 +1556,12 @@ void Character::recalc_hp()
int exercise_total = 0;
for( const std::string &skill_str : str_boost->skills_practice() ) {
const SkillLevel &lvl = get_skill_level_object( skill_id( skill_str ) );
exercise_total += lvl.total_exercise( PRACTICE );
exercise_total += lvl.total_exercise( skill_exercise_type::PRACTICE );
}

for( const std::string &skill_str : str_boost->skills_knowledge() ) {
const SkillLevel &lvl = get_skill_level_object( skill_id( skill_str ) );
exercise_total += lvl.total_exercise( KNOWLEDGE );
exercise_total += lvl.total_exercise( skill_exercise_type::KNOWLEDGE );
}

str_boost_val = str_boost->calc_bonus( std::floor( exercise_total / 1000 ) );
Expand Down Expand Up @@ -3254,12 +3254,12 @@ void Character::apply_skill_boost()
int experience_total = 0;
for( const std::string &skill_str : boost.skills_practice() ) {
const SkillLevel &lvl = get_skill_level_object( skill_id( skill_str ) );
experience_total += lvl.total_exercise( PRACTICE );
experience_total += lvl.total_exercise( skill_exercise_type::PRACTICE );
}

for( const std::string &skill_str : boost.skills_knowledge() ) {
const SkillLevel &lvl = get_skill_level_object( skill_id( skill_str ) );
experience_total += lvl.total_exercise( KNOWLEDGE );
experience_total += lvl.total_exercise( skill_exercise_type::KNOWLEDGE );
}

mod_stat( boost.stat(), boost.calc_bonus( std::floor( experience_total / 1000 ) ) );
Expand Down
3 changes: 2 additions & 1 deletion src/computer_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ bool computer_session::hack_attempt( player &p, int Security )

///\EFFECT_COMPUTER increases chance of successful hack attempt, vs Security level
bool successful_attempt = ( dice( player_roll, 6 ) >= dice( Security, 6 ) );
p.practice( skill_computer, PRACTICE, successful_attempt ? ( 15 + Security * 3 ) : 7 );
p.practice( skill_computer, skill_exercise_type::PRACTICE,
successful_attempt ? ( 15 + Security * 3 ) : 7 );
return successful_attempt;
}

Expand Down
6 changes: 3 additions & 3 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ void complete_construction( player *p )
const construction &built = pc->id.obj();
const auto award_xp = [&]( player & c ) {
for( const auto &pr : built.required_skills ) {
c.practice( pr.first, PRACTICE,
c.practice( pr.first, skill_exercise_type::PRACTICE,
static_cast<int>( ( 10 + 15 * pr.second ) * ( 1 + built.time / 180000.0 ) ),
static_cast<int>( pr.second * 1.25 ) );
}
Expand Down Expand Up @@ -1219,12 +1219,12 @@ void construct::done_deconstruct( const tripoint &p )
}
if( t.id == "t_console_broken" ) {
if( g->u.get_skill_level( skill_electronics ) >= 1 ) {
g->u.practice( skill_electronics, PRACTICE, 20, 4 );
g->u.practice( skill_electronics, skill_exercise_type::PRACTICE, 20, 4 );
}
}
if( t.id == "t_console" ) {
if( g->u.get_skill_level( skill_electronics ) >= 1 ) {
g->u.practice( skill_electronics, PRACTICE, 40, 8 );
g->u.practice( skill_electronics, skill_exercise_type::PRACTICE, 40, 8 );
}
}
g->m.ter_set( p, t.deconstruct.ter_set );
Expand Down
10 changes: 6 additions & 4 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,13 +852,14 @@ void player::craft_skill_gain( const item &craft, const int &multiplier )
const int base_practice = roll_remainder( ( making.difficulty * 15 + 10 ) * batch_mult /
20.0 ) * multiplier;
const int skill_cap = static_cast<int>( making.difficulty * 1.25 );
practice( making.skill_used, PRACTICE, base_practice, skill_cap, true );
practice( making.skill_used, skill_exercise_type::PRACTICE, base_practice, skill_cap, true );

// NPCs assisting or watching should gain experience...
for( auto &helper : helpers ) {
//If the NPC can understand what you are doing, they gain more exp
if( helper->get_skill_level( making.skill_used ) >= making.difficulty ) {
helper->practice( making.skill_used, PRACTICE, roll_remainder( base_practice / 2.0 ),
helper->practice( making.skill_used, skill_exercise_type::PRACTICE,
roll_remainder( base_practice / 2.0 ),
skill_cap );
if( batch_size > 1 && one_in( 3 ) ) {
add_msg( m_info, _( "%s assists with crafting…" ), helper->name );
Expand All @@ -868,7 +869,8 @@ void player::craft_skill_gain( const item &craft, const int &multiplier )
}
// NPCs around you understand the skill used better
} else {
helper->practice( making.skill_used, PRACTICE, roll_remainder( base_practice / 10.0 ),
helper->practice( making.skill_used, skill_exercise_type::PRACTICE,
roll_remainder( base_practice / 10.0 ),
skill_cap );
if( one_in( 3 ) ) {
add_msg( m_info, _( "%s watches you craft…" ), helper->name );
Expand Down Expand Up @@ -2193,7 +2195,7 @@ void player::complete_disassemble( item_location &target, const recipe &dis )

// disassembly only nets a bit of practice
if( dis.skill_used ) {
practice( dis.skill_used, PRACTICE, ( dis.difficulty ) * 2, dis.difficulty );
practice( dis.skill_used, skill_exercise_type::PRACTICE, ( dis.difficulty ) * 2, dis.difficulty );
}

// If the components aren't empty, we want items exactly identical to them
Expand Down
2 changes: 1 addition & 1 deletion src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ static void smash()
( get_option<float>( "PLAYER_BASE_STAMINA_REGEN_RATE" ) ) ) * -1;
u.mod_stamina( mod_sta );
if( u.get_skill_level( skill_melee ) == 0 ) {
u.practice( skill_melee, PRACTICE, rng( 0, 1 ) * rng( 0, 1 ) );
u.practice( skill_melee, skill_exercise_type::PRACTICE, rng( 0, 1 ) * rng( 0, 1 ) );
}
const int vol = u.weapon.volume() / units::legacy_volume_factor;
if( u.weapon.made_of( material_id( "glass" ) ) &&
Expand Down
11 changes: 6 additions & 5 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ void iexamine::gunsafe_ml( player &p, const tripoint &examp )
return;
}

p.practice( skill_mechanics, PRACTICE, 1 );
p.practice( skill_mechanics, skill_exercise_type::PRACTICE, 1 );

///\EFFECT_DEX speeds up lock picking gun safe
///\EFFECT_MECHANICS speeds up lock picking gun safe
Expand All @@ -1328,7 +1328,7 @@ void iexamine::gunsafe_ml( player &p, const tripoint &examp )
p.dex_cur ) ) * pick_quality;
int door_roll = dice( 4, 30 );
if( pick_roll >= door_roll ) {
p.practice( skill_mechanics, PRACTICE, 1 );
p.practice( skill_mechanics, skill_exercise_type::PRACTICE, 1 );
add_msg( _( "You successfully unlock the gun safe." ) );
g->m.furn_set( examp, furn_str_id( "f_safe_o" ) );
} else if( door_roll > ( 3 * pick_roll ) ) {
Expand Down Expand Up @@ -2991,7 +2991,8 @@ void iexamine::fvat_full( player &p, const tripoint &examp )
}

p.moves -= to_moves<int>( 5_seconds );
p.practice( skill_cooking, PRACTICE, std::min( to_minutes<int>( brew_time ) / 10, 100 ) );
p.practice( skill_cooking, skill_exercise_type::PRACTICE,
std::min( to_minutes<int>( brew_time ) / 10, 100 ) );
}

return;
Expand Down Expand Up @@ -3253,7 +3254,7 @@ void pick_plant( player &p, const tripoint &examp,
}

const int survival = p.get_skill_level( skill_survival );
p.practice( skill_survival, PRACTICE, 6 );
p.practice( skill_survival, skill_exercise_type::PRACTICE, 6 );

int plantBase = rng( 2, 5 );
///\EFFECT_SURVIVAL increases number of plants harvested
Expand Down Expand Up @@ -5844,5 +5845,5 @@ void iexamine::practice_survival_while_foraging( player *p )
///\EFFECT_SURVIVAL decreases survival skill gain from foraging (NEGATIVE)
const int max_exp = 2 * ( max_forage_skill - p->get_skill_level( skill_survival ) );
// Award experience for foraging attempt regardless of success
p->practice( skill_survival, PRACTICE, rng( 1, max_exp ), max_forage_skill );
p->practice( skill_survival, skill_exercise_type::PRACTICE, rng( 1, max_exp ), max_forage_skill );
}
Loading

0 comments on commit 823983b

Please sign in to comment.