Skip to content

Commit

Permalink
util cleanup; unique_gear_x7 to unnamed namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
scamille committed Mar 27, 2018
1 parent fb16e18 commit 59291cc
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 78 deletions.
4 changes: 2 additions & 2 deletions engine/class_modules/priest/sc_priest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1467,12 +1467,12 @@ std::string priest_t::create_profile( save_e type )
{
if ( !options.autoUnshift )
{
profile_str += "autounshift=" + util::to_string( options.autoUnshift ) + "\n";
profile_str += fmt::format("autounshift={}\n", options.autoUnshift);
}

if ( !options.priest_fixed_time )
{
profile_str += "priest_fixed_time=" + util::to_string( options.priest_fixed_time ) + "\n";
profile_str += fmt::format("priest_fixed_time={}\n", options.priest_fixed_time);
}
}

Expand Down
5 changes: 4 additions & 1 deletion engine/interfaces/sc_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ rapidjson::Value* sc_js_t::path_value( const std::string& path_str )
if ( v -> GetType() != rapidjson::kArrayType )
v -> SetArray();

unsigned idx = util::to_unsigned( path[ i ] ), missing = 0;
int parsed_idx = std::stoi( path[ i ] );
assert( parsed_idx >= 0 );
unsigned idx = parsed_idx;
unsigned missing = 0;
if ( v -> Size() <= idx )
missing = ( idx - v -> Size() ) + 1;

Expand Down
11 changes: 7 additions & 4 deletions engine/interfaces/sc_wowhead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ bool wowhead::download_item_data( item_t& item,
for ( size_t i = 0; i < spell_links.size(); i++ )
{
int trigger_type = -1;
unsigned spell_id = 0;

std::string v;
if ( spell_links[ i ] -> get_value( v, "." ) && v != "Equip: " && v != "Use: " )
Expand All @@ -281,10 +280,14 @@ bool wowhead::download_item_data( item_t& item,
else
begin++;

spell_id = util::to_unsigned( url.substr( begin ) );
if ( spell_id > 0 && trigger_type != -1 )
int parsed_spell_id = std::stoi( url.substr( begin ) );
if ( parsed_spell_id < 0 )
{
item.parsed.data.id_spell[ spell_idx ] = spell_id;
throw std::invalid_argument(fmt::format("Invalid spell id {} < 0.", parsed_spell_id) );
}
if ( parsed_spell_id > 0 && trigger_type != -1 )
{
item.parsed.data.id_spell[ spell_idx ] = parsed_spell_id;
item.parsed.data.trigger_spell[ spell_idx ] = trigger_type;
spell_idx++;
}
Expand Down
54 changes: 30 additions & 24 deletions engine/player/sc_unique_gear_x7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

using namespace unique_gear;

namespace {
/**
* Forward declarations so we can reorganize the file a bit more sanely.
*/

namespace consumable
namespace consumables
{
void potion_of_the_old_war( special_effect_t& );
void potion_of_deadly_grace( special_effect_t& );
Expand All @@ -25,7 +26,7 @@ namespace enchants
{
void mark_of_the_hidden_satyr( special_effect_t& );
void mark_of_the_distant_army( special_effect_t& );
void mark_of_the_ancient_priestess( special_effect_t& ); // NYI
//void mark_of_the_ancient_priestess( special_effect_t& ); // NYI
}

namespace item
Expand Down Expand Up @@ -78,7 +79,7 @@ namespace item
void leyspark(special_effect_t& );

// 7.0 Raid
void bloodthirsty_instinct( special_effect_t& );
//void bloodthirsty_instinct( special_effect_t& );
void natures_call( special_effect_t& );
void ravaged_seed_pod( special_effect_t& );
void spontaneous_appendages( special_effect_t& );
Expand Down Expand Up @@ -200,8 +201,11 @@ namespace artifact_power

namespace util
{
// Return the Karazhan Chest empowerment multiplier (as 1.0 + multiplier) for trinkets, or 1.0 if
// the chest is not found on the actor.
/**
* Return the Karazhan Chest empowerment multiplier.
*
* Multiplier is in form (as 1.0 + multiplier) for trinkets, or 1.0 if the chest is not found on the actor.
*/
double composite_karazhan_empower_multiplier( const player_t* player )
{
auto it = range::find_if( player -> items, []( const item_t& item ) {
Expand Down Expand Up @@ -280,7 +284,7 @@ void set_bonus::passive_stat_aura( special_effect_t& effect )
stat = STAT_BONUS_ARMOR;
}

double amount = util::round( spell -> effectN( 1 ).average( effect.player, std::min( MAX_LEVEL, effect.player -> level() ) ) );
double amount = ::util::round( spell -> effectN( 1 ).average( effect.player, std::min( MAX_LEVEL, effect.player -> level() ) ) );

effect.player -> passive.add_stat( stat, amount );
}
Expand Down Expand Up @@ -1810,7 +1814,7 @@ struct norgannons_command_t : public dbc_proc_callback_t
range::for_each( nuke_spell_ids, [ this, &effect ]( unsigned spell_id ) {
auto spell = effect.player -> find_spell( spell_id );
std::string name = spell -> name_cstr();
util::tokenize( name );
::util::tokenize( name );

auto action = create_proc_action<norgannon_nuke_t>( name, effect, name, spell );
nukes.push_back( action );
Expand Down Expand Up @@ -4617,7 +4621,7 @@ struct darkmoon_deck_t
assert( s -> found() );

std::string n = s -> name_cstr();
util::tokenize( n );
::util::tokenize( n );

cards.push_back( stat_buff_creator_t( player, n, s, effect.item ) );
}
Expand Down Expand Up @@ -5774,7 +5778,7 @@ void set_bonus::march_of_the_legion( special_effect_t& effect ) {
const spell_data_t* spell = effect.player->find_spell( 228445 );

std::string spell_name = spell->name_cstr();
util::tokenize( spell_name );
::util::tokenize( spell_name );

struct march_t : public proc_spell_t
{
Expand Down Expand Up @@ -5918,7 +5922,7 @@ struct legion_potion_damage_t : public T

// Potion of the Old War ====================================================

void consumable::potion_of_the_old_war( special_effect_t& effect )
void consumables::potion_of_the_old_war( special_effect_t& effect )
{
// Instantiate a new action if we cannot find a suitable one already
auto action = effect.player -> find_action( effect.name() );
Expand Down Expand Up @@ -5958,10 +5962,10 @@ void consumable::potion_of_the_old_war( special_effect_t& effect )

// Potion of Deadly Grace ===================================================

void consumable::potion_of_deadly_grace( special_effect_t& effect )
void consumables::potion_of_deadly_grace( special_effect_t& effect )
{
std::string action_name = effect.driver() -> effectN( 1 ).trigger() -> name_cstr();
util::tokenize( action_name );
::util::tokenize( action_name );

// Instantiate a new action if we cannot find a suitable one already
auto action = effect.player -> find_action( action_name );
Expand Down Expand Up @@ -6010,7 +6014,7 @@ void consumable::potion_of_deadly_grace( special_effect_t& effect )

// Hearty Feast =============================================================

void consumable::hearty_feast( special_effect_t& effect )
void consumables::hearty_feast( special_effect_t& effect )
{
effect.stat = effect.player -> convert_hybrid_stat( STAT_STR_AGI_INT );
switch ( effect.stat )
Expand Down Expand Up @@ -6039,7 +6043,7 @@ void consumable::hearty_feast( special_effect_t& effect )

// Lavish Suramar Feast =====================================================

void consumable::lavish_suramar_feast( special_effect_t& effect )
void consumables::lavish_suramar_feast( special_effect_t& effect )
{
effect.stat = effect.player -> convert_hybrid_stat( STAT_STR_AGI_INT );
switch ( effect.stat )
Expand Down Expand Up @@ -6069,7 +6073,7 @@ void consumable::lavish_suramar_feast( special_effect_t& effect )

// Lemon Herb Filet =========================================================

void consumable::lemon_herb_filet( special_effect_t& effect )
void consumables::lemon_herb_filet( special_effect_t& effect )
{
double value = effect.driver() -> effectN( 1 ).percent();

Expand Down Expand Up @@ -6152,7 +6156,7 @@ struct pepper_breath_driver_t : public proc_spell_t
}
};

void consumable::pepper_breath( special_effect_t& effect )
void consumables::pepper_breath( special_effect_t& effect )
{
unsigned trigger_id = 0;
switch ( effect.driver() -> id() )
Expand Down Expand Up @@ -6749,6 +6753,8 @@ void artifact_power::infusion_of_light( special_effect_t& effect )
new dbc_proc_callback_t( effect.player, effect );
}

} // unnamed namespace

void unique_gear::register_special_effects_x7()
{
/* Legion 7.0 Dungeon */
Expand Down Expand Up @@ -6895,14 +6901,14 @@ void unique_gear::register_special_effects_x7()
register_special_effect( 236373, item::norgannons_foresight );

/* Consumables */
register_special_effect( 188028, consumable::potion_of_the_old_war );
register_special_effect( 188027, consumable::potion_of_deadly_grace );
register_special_effect( 201351, consumable::hearty_feast );
register_special_effect( 201352, consumable::lavish_suramar_feast );
register_special_effect( 225606, consumable::pepper_breath );
register_special_effect( 225601, consumable::pepper_breath );
register_special_effect( 201336, consumable::pepper_breath );
register_special_effect( 185736, consumable::lemon_herb_filet );
register_special_effect( 188028, consumables::potion_of_the_old_war );
register_special_effect( 188027, consumables::potion_of_deadly_grace );
register_special_effect( 201351, consumables::hearty_feast );
register_special_effect( 201352, consumables::lavish_suramar_feast );
register_special_effect( 225606, consumables::pepper_breath );
register_special_effect( 225601, consumables::pepper_breath );
register_special_effect( 201336, consumables::pepper_breath );
register_special_effect( 185736, consumables::lemon_herb_filet );

/* Artifact powers */
register_special_effect( 252906, artifact_power::torment_the_weak );
Expand Down
2 changes: 2 additions & 0 deletions engine/report/sc_report.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ class html_decorator_t
html_decorator_t()
{ }

virtual ~html_decorator_t() = default;

virtual std::string url_params() const
{
std::stringstream s;
Expand Down
8 changes: 5 additions & 3 deletions engine/sc_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,8 @@ std::vector<std::string> util::string_split_allow_quotes( std::string str, const
}


/* replaces all occurrences of 'from' in the string 's', with 'to'
/**
* Replaces all occurrences of 'from' in the string 's', with 'to'.
*/
void util::replace_all( std::string& s, const std::string& from, const std::string& to )
{
Expand Down Expand Up @@ -2284,10 +2285,10 @@ int util::parse_item_quality( const std::string& quality )

// string_strip_quotes ======================================================

void util::string_strip_quotes( std::string& str )
std::string util::string_strip_quotes( std::string str )
{
std::string::size_type pos = str.find( '"' );
if ( pos == std::string::npos ) return;
if ( pos == std::string::npos ) return str;

std::string::iterator dst = str.begin() + pos, src = dst;
while ( ++src != str.end() )
Expand All @@ -2297,6 +2298,7 @@ void util::string_strip_quotes( std::string& str )
}

str.resize( dst - str.begin() );
return str;
}

// to_string ================================================================
Expand Down
38 changes: 1 addition & 37 deletions engine/sc_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ double crit_multiplier( meta_gem_e gem );

std::vector<std::string> string_split( const std::string& str, const std::string& delim );
std::vector<std::string> string_split_allow_quotes( std::string str, const char* delim );
void string_strip_quotes( std::string& str );
std::string string_strip_quotes( std::string str );
void replace_all( std::string& s, const std::string&, const std::string& );
void erase_all( std::string& s, const std::string& from );

Expand Down Expand Up @@ -189,9 +189,6 @@ int numDigits( T number );

bool contains_non_ascii( const std::string& );

template<class T>
T from_string( const std::string& );

template <class T>
double duration_fp_seconds(const T& chrono_time)
{
Expand All @@ -200,39 +197,6 @@ double duration_fp_seconds(const T& chrono_time)
return std::chrono::duration<double, std::chrono::seconds::period>( now - chrono_time ).count();
}

template<>
inline int from_string( const std::string& v )
{
return strtol( v.c_str(), nullptr, 10 );
}
template<>
inline bool from_string( const std::string& v )
{
return from_string<int>( v ) != 0;
}

template<>
inline unsigned from_string( const std::string& v )
{
return strtoul( v.c_str(), nullptr, 10 );
}

template<>
inline double from_string( const std::string& v )
{
return strtod( v.c_str(), nullptr );
}
template<>
inline timespan_t from_string( const std::string& v )
{
return timespan_t::from_seconds( util::from_string<double>( v ) );
}
template<>
inline std::string from_string( const std::string& v )
{
return v;
}

// https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
inline unsigned next_power_of_two( unsigned v )
{
Expand Down
8 changes: 6 additions & 2 deletions engine/sim/sc_cooldown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ cooldown_t::cooldown_t( const std::string& n, sim_t& s ) :
action( nullptr )
{}

// Adjust a dynamic cooldown (reduction) multiplier based on the current action associated with the
// cooldown. Actions are associated by start() calls.
/**
* Adjust a dynamic cooldown.
*
* Adjust a dynamic cooldown (reduction) multiplier based on the current action associated with the cooldown.
* Actions are associated by start() calls.
*/
void cooldown_t::adjust_recharge_multiplier()
{
if ( up() )
Expand Down
6 changes: 2 additions & 4 deletions engine/sim/sc_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3460,10 +3460,8 @@ void sim_t::setup( sim_control_t* c )
}
if ( ! opts::parse(this, p->options, o.name, o.value))
{
std::stringstream s;
s << "Unable to parse option '" << o.name << "' with value '" << o.value
<< "' for player '" << p->name() << "'";
throw std::invalid_argument(s.str());
throw std::invalid_argument(fmt::format("Unable to parse option '{}' with value '{}' for player '{}'.",
o.name, o.value, p->name()));
}

}
Expand Down
2 changes: 1 addition & 1 deletion engine/simulationcraft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7923,7 +7923,7 @@ struct ground_aoe_event_t : public player_event_t
// effect_callbacks_t::register_callback =====================================

template <typename T>
static void add_callback( std::vector<T*>& callbacks, T* cb )
inline void add_callback( std::vector<T*>& callbacks, T* cb )
{
if ( range::find( callbacks, cb ) == callbacks.end() )
callbacks.push_back( cb );
Expand Down

0 comments on commit 59291cc

Please sign in to comment.