Skip to content

Commit

Permalink
Replace all occurences of 'all_ref()'
Browse files Browse the repository at this point in the history
Things became a bit cleaner semantically (no mess with pairs and pointers).
  • Loading branch information
codemime committed Apr 24, 2016
1 parent be7deb4 commit a9a5db3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 59 deletions.
31 changes: 15 additions & 16 deletions src/martialarts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ bool string_id<martialart>::is_valid() const
std::vector<matype_id> all_martialart_types()
{
std::vector<matype_id> result;
for( auto & e : martialarts.all_ref() ) {
result.push_back( e.first );
for( const auto &ma : martialarts.get_all() ) {
result.push_back( ma.id );
}
return result;
}
Expand All @@ -225,28 +225,27 @@ void check( const ma_requirements & req, const std::string &display_text )

void check_martialarts()
{
for( auto &e : martialarts.all_ref() ) {
const auto style = &e;
for( auto technique = style->second.techniques.cbegin();
technique != style->second.techniques.cend(); ++technique ) {
for( const auto &ma : martialarts.get_all() ) {
for( auto technique = ma.techniques.cbegin();
technique != ma.techniques.cend(); ++technique ) {
if( !technique->is_valid() ) {
debugmsg( "Technique with id %s in style %s doesn't exist.",
technique->c_str(), style->second.name.c_str() );
technique->c_str(), ma.name.c_str() );
}
}
for( auto weapon = style->second.weapons.cbegin();
weapon != style->second.weapons.cend(); ++weapon ) {
for( auto weapon = ma.weapons.cbegin();
weapon != ma.weapons.cend(); ++weapon ) {
if( !item::type_is_defined( *weapon ) ) {
debugmsg( "Weapon %s in style %s doesn't exist.",
weapon->c_str(), style->second.name.c_str() );
weapon->c_str(), ma.name.c_str() );
}
}
}
for( auto & t : ma_techniques.all_ref() ) {
::check( t.second.reqs, string_format( "technique %s", t.first.c_str() ) );
for( const auto &t : ma_techniques.get_all() ) {
::check( t.reqs, string_format( "technique %s", t.id.c_str() ) );
}
for( auto & b : ma_buffs.all_ref() ) {
::check( b.second.reqs, string_format( "buff %s", b.first.c_str() ) );
for( const auto &b : ma_buffs.get_all() ) {
::check( b.reqs, string_format( "buff %s", b.id.c_str() ) );
}
}

Expand Down Expand Up @@ -301,8 +300,8 @@ void finialize_martial_arts()
{
// This adds an effect type for each ma_buff, so we can later refer to it and don't need a
// redundant definition of those effects in json.
for( auto &buff : ma_buffs.all_ref() ) {
const ma_buff_effect_type new_eff( buff.second );
for( const auto &buff : ma_buffs.get_all() ) {
const ma_buff_effect_type new_eff( buff );
// Note the slicing here: new_eff is converted to a plain effect_type, but this doesn't
// bother us because ma_buff_effect_type does not have any members that can be sliced.
effect_type::register_ma_buff_effect( new_eff );
Expand Down
60 changes: 29 additions & 31 deletions src/monstergenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ void MonsterGenerator::reset()

void MonsterGenerator::finalize_mtypes()
{
for( auto &elem : mon_templates->all_ref() ) {
mtype &mon = const_cast<mtype&>( elem.second );
for( const auto &elem : mon_templates->get_all() ) {
mtype &mon = const_cast<mtype&>( elem );
apply_species_attributes( mon );
set_mtype_flags( mon );
set_species_ids( mon );
Expand Down Expand Up @@ -584,8 +584,7 @@ const std::vector<mtype> &MonsterGenerator::get_all_mtypes() const
mtype_id MonsterGenerator::get_valid_hallucination() const
{
std::vector<mtype_id> potentials;
for( auto &elem : mon_templates->all_ref() ) {
const mtype &mon = elem.second;
for( const auto &mon : mon_templates->get_all() ) {
if( mon.id != NULL_ID && mon.id != mon_generator ) {
potentials.push_back( mon.id );
}
Expand Down Expand Up @@ -669,53 +668,52 @@ void mtype::remove_special_attacks( JsonObject &jo, const std::string &member_na

void MonsterGenerator::check_monster_definitions() const
{
for( const auto &elem : mon_templates->all_ref() ) {
const mtype *mon = &elem.second;
for( auto &spec : mon->species ) {
for( const auto &mon : mon_templates->get_all() ) {
for( auto &spec : mon.species ) {
if( !spec.is_valid() ) {
debugmsg("monster %s has invalid species %s", mon->id.c_str(), spec.c_str());
debugmsg("monster %s has invalid species %s", mon.id.c_str(), spec.c_str());
}
}
if (!mon->death_drops.empty() && !item_group::group_is_defined(mon->death_drops)) {
debugmsg("monster %s has unknown death drop item group: %s", mon->id.c_str(),
mon->death_drops.c_str());
if (!mon.death_drops.empty() && !item_group::group_is_defined(mon.death_drops)) {
debugmsg("monster %s has unknown death drop item group: %s", mon.id.c_str(),
mon.death_drops.c_str());
}
for( auto &m : mon->mat ) {
for( auto &m : mon.mat ) {
if( m.str() == "null" || !m.is_valid() ) {
debugmsg( "monster %s has unknown material: %s", mon->id.c_str(), m.c_str() );
debugmsg( "monster %s has unknown material: %s", mon.id.c_str(), m.c_str() );
}
}
if( !mon->revert_to_itype.empty() && !item::type_is_defined( mon->revert_to_itype ) ) {
debugmsg("monster %s has unknown revert_to_itype: %s", mon->id.c_str(),
mon->revert_to_itype.c_str());
if( !mon.revert_to_itype.empty() && !item::type_is_defined( mon.revert_to_itype ) ) {
debugmsg("monster %s has unknown revert_to_itype: %s", mon.id.c_str(),
mon.revert_to_itype.c_str());
}
for( auto & s : mon->starting_ammo ) {
for( auto & s : mon.starting_ammo ) {
if( !item::type_is_defined( s.first ) ) {
debugmsg( "starting ammo %s of monster %s is unknown", s.first.c_str(), mon->id.c_str() );
debugmsg( "starting ammo %s of monster %s is unknown", s.first.c_str(), mon.id.c_str() );
}
}
for( auto & e : mon->atk_effs ) {
for( auto & e : mon.atk_effs ) {
if( !e.id.is_valid() ) {
debugmsg( "attack effect %s of monster %s is unknown", e.id.c_str(), mon->id.c_str() );
debugmsg( "attack effect %s of monster %s is unknown", e.id.c_str(), mon.id.c_str() );
}
}
if( mon->upgrades ) {
if( mon->half_life <= 0 ) {
debugmsg( "half_life %d (<= 0) of monster %s is invalid", mon->half_life, mon->id.c_str() );
if( mon.upgrades ) {
if( mon.half_life <= 0 ) {
debugmsg( "half_life %d (<= 0) of monster %s is invalid", mon.half_life, mon.id.c_str() );
}
if( !mon->upgrade_into && !mon->upgrade_group ) {
debugmsg( "no into nor into_group defined for monster %s", mon->id.c_str() );
if( !mon.upgrade_into && !mon.upgrade_group ) {
debugmsg( "no into nor into_group defined for monster %s", mon.id.c_str() );
}
if( mon->upgrade_into && mon->upgrade_group ) {
debugmsg( "both into and into_group defined for monster %s", mon->id.c_str() );
if( mon.upgrade_into && mon.upgrade_group ) {
debugmsg( "both into and into_group defined for monster %s", mon.id.c_str() );
}
if( !mon->upgrade_into.is_valid() ) {
if( !mon.upgrade_into.is_valid() ) {
debugmsg( "upgrade_into %s of monster %s is not a valid monster id",
mon->upgrade_into.c_str(), mon->id.c_str() );
mon.upgrade_into.c_str(), mon.id.c_str() );
}
if( !mon->upgrade_group.is_valid() ) {
if( !mon.upgrade_group.is_valid() ) {
debugmsg( "upgrade_group %s of monster %s is not a valid monster group id",
mon->upgrade_group.c_str(), mon->id.c_str() );
mon.upgrade_group.c_str(), mon.id.c_str() );
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/profession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ const profession *profession::weighted_random()
return generic();
}

const auto &map = all_profs.all_ref();
const auto &list = all_profs.get_all();
while( true ) {
auto iter = map.begin();
std::advance( iter, rng( 0, map.size() - 1 ) );
const profession &prof = iter->second;
auto iter = list.begin();
std::advance( iter, rng( 0, list.size() - 1 ) );
const profession &prof = *iter;

if( x_in_y( 2, abs( prof.point_cost() ) + 2 ) && !prof.has_flag( "SCEN_ONLY" ) ) {
return &prof;
Expand All @@ -183,8 +183,8 @@ void profession::reset()

void profession::check_definitions()
{
for( auto &pair : all_profs.all_ref() ) {
pair.second.check_definition();
for( const auto &prof : all_profs.get_all() ) {
prof.check_definition();
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ const scenario *scenario::weighted_random()
return generic();
}

const auto &map = all_scenarios.all_ref();
const auto &list = all_scenarios.get_all();
while( true ) {
auto iter = map.begin();
std::advance( iter, rng( 0, map.size() - 1 ) );
const scenario &scen = iter->second;
auto iter = list.begin();
std::advance( iter, rng( 0, list.size() - 1 ) );
const scenario &scen = *iter;

if( x_in_y( 2, abs( scen.point_cost() ) + 2 ) ) {
return &scen;
Expand All @@ -141,8 +141,8 @@ void scenario::reset()

void scenario::check_definitions()
{
for( auto &pair : all_scenarios.all_ref() ) {
pair.second.check_definition();
for( const auto &scen : all_scenarios.get_all() ) {
scen.check_definition();
}
}

Expand Down

0 comments on commit a9a5db3

Please sign in to comment.