better managed ownership (two new functions in level.h)
This commit is contained in:
@ -29,12 +29,12 @@ void character::set_pos(const position &npos) {
|
||||
pos = npos;
|
||||
}
|
||||
|
||||
void character::apply_effect(potion *effect) {
|
||||
insert_effect(effect);
|
||||
void character::apply_effect(std::unique_ptr<potion> effect) {
|
||||
insert_effect(std::move(effect));
|
||||
}
|
||||
|
||||
void character::insert_effect(potion *effect) {
|
||||
effects.push_back(effect);
|
||||
void character::insert_effect(std::unique_ptr<potion> effect) {
|
||||
effects.push_back(std::move(effect));
|
||||
|
||||
for (int i = effects.size() - 1; i > 0 &&
|
||||
effect->get_priority() < effects[i - 1]->get_priority(); --i)
|
||||
@ -42,17 +42,17 @@ void character::insert_effect(potion *effect) {
|
||||
}
|
||||
|
||||
result character::calc_effects() {
|
||||
potion_list tmp;
|
||||
potion_own_list tmp;
|
||||
tmp.reserve(effects.size());
|
||||
|
||||
for (auto p : effects) {
|
||||
p->apply(this->race, HP, ATK, DEF, base_hit_rate);
|
||||
for (size_t i = 0; i < effects.size(); ++i) {
|
||||
effects[i]->apply(this->race, HP, ATK, DEF, base_hit_rate);
|
||||
|
||||
if (HP <= 0)
|
||||
return result::died;
|
||||
|
||||
if (p->get_duration() != 0)
|
||||
tmp.push_back(p);
|
||||
if (effects[i]->get_duration() != 0)
|
||||
tmp.push_back(std::move(effects[i]));
|
||||
}
|
||||
|
||||
tmp.shrink_to_fit();
|
||||
@ -63,12 +63,12 @@ result character::calc_effects() {
|
||||
}
|
||||
|
||||
void character::discard_level_effects() {
|
||||
potion_list tmp;
|
||||
potion_own_list tmp;
|
||||
tmp.reserve(effects.size());
|
||||
|
||||
for (auto p : effects)
|
||||
if (p->get_duration() > 0)
|
||||
tmp.push_back(p);
|
||||
for (size_t i = 0; i < effects.size(); ++i)
|
||||
if (effects[i]->get_duration() > 0)
|
||||
tmp.push_back(std::move(effects[i]));
|
||||
|
||||
tmp.shrink_to_fit();
|
||||
|
||||
|
Reference in New Issue
Block a user