refactor function to get the bounds of a status
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "damage.hpp"
|
||||
|
||||
#include <set>
|
||||
|
||||
static status_info_t status_info[int(eStatus::CHARM) + 1] = {
|
||||
{false, 4}, // POISONED_WEAPON
|
||||
{false, 2, 3}, // BLESS_CURSE
|
||||
@@ -46,3 +48,29 @@ const status_info_t& operator* (eStatus status) {
|
||||
const status_info_t& operator* (ePartyStatus status) {
|
||||
return party_status_info[int(status)];
|
||||
}
|
||||
|
||||
std::pair<int, int> status_bounds(eStatus which) {
|
||||
static const std::set<eStatus> allow_negative = {
|
||||
// The obvious ones:
|
||||
eStatus::BLESS_CURSE, eStatus::HASTE_SLOW,
|
||||
// The ones that BoE previously allowed:
|
||||
eStatus::POISONED_WEAPON, eStatus::POISON, eStatus::ASLEEP,
|
||||
// (Note: Negative levels of sleep can be obtained from the Hyperactivity spell. The other two never go negative.)
|
||||
// The additional ones that make sense in the negative:
|
||||
eStatus::MAGIC_RESISTANCE, eStatus::DUMB,
|
||||
};
|
||||
|
||||
int lo = 0, hi = 8;
|
||||
|
||||
if(which == eStatus::MARTYRS_SHIELD)
|
||||
hi = 10;
|
||||
else if(which == eStatus::PARALYZED)
|
||||
hi = 5000;
|
||||
else if(which == eStatus::FORCECAGE)
|
||||
hi = 1000;
|
||||
|
||||
if(allow_negative.count(which))
|
||||
lo = -hi;
|
||||
|
||||
return std::make_pair(lo, hi);
|
||||
}
|
@@ -110,6 +110,8 @@ inline bool isDead(eMainStatus stat) {
|
||||
return code > 1 && code < 5;
|
||||
}
|
||||
|
||||
std::pair<int, int> status_bounds(eStatus which);
|
||||
|
||||
std::ostream& operator << (std::ostream& out, eStatus e);
|
||||
std::istream& operator >> (std::istream& in, eStatus& e);
|
||||
std::istream& operator >> (std::istream& in, ePartyStatus& type);
|
||||
|
@@ -8,34 +8,14 @@
|
||||
|
||||
#include "living.hpp"
|
||||
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include "mathutil.hpp"
|
||||
|
||||
void iLiving::apply_status(eStatus which, int how_much) {
|
||||
if(!is_alive()) return;
|
||||
|
||||
static const std::set<eStatus> allow_negative = {
|
||||
// The obvious ones:
|
||||
eStatus::BLESS_CURSE, eStatus::HASTE_SLOW,
|
||||
// The ones that BoE previously allowed:
|
||||
eStatus::POISONED_WEAPON, eStatus::POISON, eStatus::ASLEEP,
|
||||
// (Note: Negative levels of sleep can be obtained from the Hyperactivity spell. The other two never go negative.)
|
||||
// The additional ones that make sense in the negative:
|
||||
eStatus::MAGIC_RESISTANCE, eStatus::DUMB,
|
||||
};
|
||||
|
||||
int lo = 0, hi = 8;
|
||||
|
||||
if(which == eStatus::MARTYRS_SHIELD)
|
||||
hi = 10;
|
||||
else if(which == eStatus::PARALYZED)
|
||||
hi = 5000;
|
||||
else if(which == eStatus::FORCECAGE)
|
||||
hi = 1000;
|
||||
|
||||
if(allow_negative.count(which))
|
||||
lo = -hi;
|
||||
std::pair<int, int> bounds = status_bounds(which);
|
||||
int lo = bounds.first, hi = bounds.second;
|
||||
|
||||
if(which == eStatus::ASLEEP || which == eStatus::DUMB) {
|
||||
// No "wrapping" allowed for these effects.
|
||||
|
Reference in New Issue
Block a user