diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-08-20 13:30:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-20 13:30:50 +0200 |
commit | 1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3 (patch) | |
tree | 03dd0c39e323c7f0b1f06014ff30e74f429bfa01 /src/tool.cpp | |
parent | 50669cd2822a11570ae462972194eeb2d585a8c1 (diff) | |
download | minetest-1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3.tar.gz minetest-1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3.tar.bz2 minetest-1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3.zip |
Modernize source code: last part (#6285)
* Modernize source code: last par
* Use empty when needed
* Use emplace_back instead of push_back when needed
* For range-based loops
* Initializers fixes
* constructors, destructors default
* c++ C stl includes
Diffstat (limited to 'src/tool.cpp')
-rw-r--r-- | src/tool.cpp | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/src/tool.cpp b/src/tool.cpp index 1afd71630..38508c5fe 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -31,26 +31,24 @@ void ToolCapabilities::serialize(std::ostream &os, u16 protocol_version) const writeF1000(os, full_punch_interval); writeS16(os, max_drop_level); writeU32(os, groupcaps.size()); - for (ToolGCMap::const_iterator i = groupcaps.begin(); i != groupcaps.end(); ++i) { - const std::string *name = &i->first; - const ToolGroupCap *cap = &i->second; + for (const auto &groupcap : groupcaps) { + const std::string *name = &groupcap.first; + const ToolGroupCap *cap = &groupcap.second; os << serializeString(*name); writeS16(os, cap->uses); writeS16(os, cap->maxlevel); writeU32(os, cap->times.size()); - for (std::unordered_map<int, float>::const_iterator - j = cap->times.begin(); j != cap->times.end(); ++j) { - writeS16(os, j->first); - writeF1000(os, j->second); + for (const auto &time : cap->times) { + writeS16(os, time.first); + writeF1000(os, time.second); } } writeU32(os, damageGroups.size()); - for (DamageGroup::const_iterator i = damageGroups.begin(); - i != damageGroups.end(); ++i) { - os << serializeString(i->first); - writeS16(os, i->second); + for (const auto &damageGroup : damageGroups) { + os << serializeString(damageGroup.first); + writeS16(os, damageGroup.second); } } @@ -107,15 +105,14 @@ DigParams getDigParams(const ItemGroupList &groups, bool result_diggable = false; float result_time = 0.0; float result_wear = 0.0; - std::string result_main_group = ""; + std::string result_main_group; int level = itemgroup_get(groups, "level"); //infostream<<"level="<<level<<std::endl; - for (ToolGCMap::const_iterator i = tp->groupcaps.begin(); - i != tp->groupcaps.end(); ++i) { - const std::string &name = i->first; + for (const auto &groupcap : tp->groupcaps) { + const std::string &name = groupcap.first; //infostream<<"group="<<name<<std::endl; - const ToolGroupCap &cap = i->second; + const ToolGroupCap &cap = groupcap.second; int rating = itemgroup_get(groups, name); float time = 0; bool time_exists = cap.getTime(rating, &time); @@ -159,14 +156,14 @@ HitParams getHitParams(const ItemGroupList &armor_groups, s16 damage = 0; float full_punch_interval = tp->full_punch_interval; - for (DamageGroup::const_iterator i = tp->damageGroups.begin(); - i != tp->damageGroups.end(); ++i) { - s16 armor = itemgroup_get(armor_groups, i->first); - damage += i->second * rangelim(time_from_last_punch / full_punch_interval, 0.0, 1.0) + for (const auto &damageGroup : tp->damageGroups) { + s16 armor = itemgroup_get(armor_groups, damageGroup.first); + damage += damageGroup.second + * rangelim(time_from_last_punch / full_punch_interval, 0.0, 1.0) * armor / 100.0; } - return HitParams(damage, 0); + return {damage, 0}; } HitParams getHitParams(const ItemGroupList &armor_groups, @@ -183,12 +180,13 @@ PunchDamageResult getPunchDamage( ){ bool do_hit = true; { - if(do_hit && punchitem){ - if(itemgroup_get(armor_groups, "punch_operable") && - (toolcap == NULL || punchitem->name == "")) + if (do_hit && punchitem) { + if (itemgroup_get(armor_groups, "punch_operable") && + (toolcap == NULL || punchitem->name.empty())) do_hit = false; } - if(do_hit){ + + if (do_hit) { if(itemgroup_get(armor_groups, "immortal")) do_hit = false; } |