stats.cpp
roh/src-2.44b/stats.cpp · 3.5 KB
From the archive roh-2.44b.tar.bz2
Download the archive « Back to the archive contents
/*
* stat.cpp
* Stat code.
* ____ _
* | _ \ ___ __ _| |_ __ ___ ___
* | |_) / _ \/ _` | | '_ ` _ \/ __|
* | _ < __/ (_| | | | | | | \__ \
* |_| \_\___|\__,_|_|_| |_| |_|___/
*
* Permission to use, modify and distribute is granted via the
* Creative Commons - Attribution - Non Commercial - Share Alike 3.0 License
* http://creativecommons.org/licenses/by-nc-sa/3.0/
*
* Copyright (C) 2007-2009 Jason Mitchell, Randi Mitchell
* Contributions by Tim Callahan, Jonathan Hseu
* Based on Mordor (C) Brooke Paul, Brett J. Vickers, John P. Freeman
*
*/
#include "mud.h"
Stat::Stat() {
cur = max = tmpMax = initial = 0;
}
Stat::~Stat()
{
}
int Stat::adjustMax(int amt) {
if(amt > 0)
return(increaseMax(amt));
else
return(-1 * decreaseMax(amt*-1));
}
int Stat::increaseMax(int amt) {
if(max + amt > 30000)
amt = 30000 - max;
max += amt;
return(amt);
}
int Stat::decreaseMax(int amt) {
if(max - amt < 0)
amt = 0 - max;
max -= amt;
if(cur > max)
cur = max;
return(amt);
}
int Stat::adjust(int amt, bool overMaxOk) {
if(amt > 0)
return(increase(amt, overMaxOk));
else
return(-1 * decrease(amt*-1));
}
int Stat::increase(int amt, bool overMaxOk) {
if(amt < 0)
return(0);
int increaseAmt;
// One possibility is we're a DK under blood sacrifice. Max of 1 1/2 max
if(overMaxOk)
increaseAmt = MAX(0, MIN(amt, (max*3/2) - cur));
else
increaseAmt = MAX(0, MIN(amt, max - cur));
cur += increaseAmt;
return(increaseAmt);
}
int Stat::decrease(int amt) {
if(amt < 0)
return(0);
int decreaseAmt = MIN(amt, cur);
cur -= decreaseAmt;
return(decreaseAmt);
}
short Stat::getCur() const { return(cur); }
short Stat::getMax() const { return(max); }
short Stat::getInitial() const { return(initial); }
void Stat::addCur(short a) { cur = MAX(1, cur + a); }
void Stat::addMax(short a) { max = MAX(1, max + a); }
int Stat::setMax(short newMax, bool allowZero) {
newMax = MAX(allowZero ? 0 : 1, MIN(newMax, 30000));
max = newMax;
if(cur > max)
cur = max;
return(max);
}
int Stat::setCur(short newCur) {
cur = MIN(newCur, max);
return(cur);
}
void Stat::setInitial(short i) { initial = i; }
int Stat::restore() {
if(cur < max)
cur = max;
return(cur);
}
//*********************************************************************
// statsAddUp
//*********************************************************************
bool Player::statsAddUp() const {
if(isStaff())
return(true);
int has = strength.getCur() +
dexterity.getCur() +
constitution.getCur() +
intelligence.getCur() +
piety.getCur();
int should = 560 + (level - 1) * 10;
if(flagIsSet(P_PRAYED))
should += cClass == DEATHKNIGHT ? 30 : 50;
if(flagIsSet(P_FRENZY))
should += 50;
if(flagIsSet(P_BERSERKED))
should += cClass == CLERIC && deity == ARES ? 30 : 50;
if(isEffected("enfeeblement"))
should -= 30;
if(isEffected("slow"))
should -= 30;
if(isEffected("weakness"))
should -= 30;
if(isEffected("feeblemind"))
should -= 30;
if(isEffected("damnation"))
should -= 30;
if(isEffected("strength"))
should += 30;
if(isEffected("haste"))
should += 30;
if(isEffected("fortitude"))
should += 30;
if(isEffected("insight"))
should += 30;
if(isEffected("prayer"))
should += 30;
// goblins with min intelligence should be given a little leeway
if(race == GOBLIN && (should + 10) == has)
return(true);
return(should == has);
}