Remove custom erase_if function in favor of std::remove_if

It was originally added before I understood the correct way to use remove_if

As a side-effect, remove bad status now also removes forcecage and charm.
This commit is contained in:
2017-04-14 01:16:57 -04:00
parent 936a848166
commit 5b5b2af46f
4 changed files with 25 additions and 37 deletions

View File

@@ -578,9 +578,10 @@ location end_town_mode(short switching_level,location destination) { // returns
to_return = univ.party.out_loc;
erase_if(univ.party.party_event_timers, [](const cTimer& t) {
auto& timers = univ.party.party_event_timers;
timers.erase(std::remove_if(timers.begin(), timers.end(), [](const cTimer& t) {
return t.node_type == 2;
});
}), timers.end());
}
@@ -629,16 +630,8 @@ location end_town_mode(short switching_level,location destination) { // returns
univ.party.status[ePartyStatus::STEALTH] = 0;
univ.party.status[ePartyStatus::DETECT_LIFE] = 0; // TODO: Yes? No? Maybe?
for(short i = 0; i < 6; i++)
erase_if(univ.party[i].status, [](std::pair<const eStatus, short> kv) -> bool {
if(kv.first == eStatus::POISON) return false;
if(kv.first == eStatus::DISEASE) return false;
if(kv.first == eStatus::DUMB) return false;
if(kv.first == eStatus::ACID && kv.second > 2)
return false;
return true;
});
for(cPlayer& who : univ.party)
who.clear_brief_status();
update_explored(to_return);
redraw_screen(REFRESH_TERRAIN | REFRESH_TEXT);

View File

@@ -25,16 +25,6 @@ inline void move_to_zero(T& val){
val--;
}
// Not quite mathutil... perhaps I need a more general util file.
// This is from <http://stackoverflow.com/a/16597048>.
template<typename ContainerT, typename PredicateT >
void erase_if(ContainerT& items, const PredicateT& predicate) {
for(auto it = items.begin(); it != items.end();) {
if(predicate(*it)) it = items.erase(it);
else ++it;
}
};
// Case-insensitive string comparison seems to be semi-standard, but with different names.
#if defined(__APPLE__)
#define strnicmp strncasecmp

View File

@@ -9,6 +9,7 @@
#include "living.hpp"
#include <set>
#include <algorithm>
#include "mathutil.hpp"
void iLiving::apply_status(eStatus which, int how_much) {
@@ -46,21 +47,24 @@ void iLiving::apply_status(eStatus which, int how_much) {
}
void iLiving::clear_bad_status() {
status[eStatus::POISON] = 0;
if(status[eStatus::BLESS_CURSE] < 0)
status[eStatus::BLESS_CURSE] = 0;
if(status[eStatus::HASTE_SLOW] < 0)
status[eStatus::HASTE_SLOW] = 0;
status[eStatus::WEBS] = 0;
status[eStatus::DISEASE] = 0;
if(status[eStatus::DUMB] > 0)
status[eStatus::DUMB] = 0;
if(status[eStatus::ASLEEP] > 0)
status[eStatus::ASLEEP] = 0;
status[eStatus::PARALYZED] = 0;
status[eStatus::ACID] = 0;
if(status[eStatus::MAGIC_RESISTANCE] < 0)
status[eStatus::MAGIC_RESISTANCE] = 0;
std::map<eStatus, short> old;
status.swap(old);
std::remove_copy_if(old.begin(), old.end(), std::inserter(status, status.begin()), [](std::pair<const eStatus, short> kv) {
return isStatusNegative(kv.first) ? kv.second > 0 : kv.second < 0;
});
}
void iLiving::clear_brief_status() {
std::map<eStatus, short> old;
status.swap(old);
std::remove_copy_if(old.begin(), old.end(), std::inserter(status, status.begin()), [](std::pair<const eStatus, short> kv) -> bool {
if(kv.first == eStatus::POISON) return false;
if(kv.first == eStatus::DISEASE) return false;
if(kv.first == eStatus::DUMB) return false;
if(kv.first == eStatus::ACID && kv.second > 2)
return false;
return true;
});
}
void iLiving::void_sanctuary() {

View File

@@ -30,6 +30,7 @@ public:
virtual int get_shared_dmg(int base_dmg) const = 0; // And this goes with the above.
virtual void apply_status(eStatus which, int how_much);
virtual void clear_brief_status();
virtual void clear_bad_status();
virtual void void_sanctuary();