-
Notifications
You must be signed in to change notification settings - Fork 4
/
D20Ability.hpp
83 lines (66 loc) · 2.62 KB
/
D20Ability.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef __D20Ability
#define __D20Ability
#include <string>
#include "Rollable.hpp"
#include "GlobalDef.hpp"
namespace D20Rules
{
class D20Character;
namespace Rollables
{
class D20Ability : public Rollable
{
private:
Loki::StrongPtr<D20Rules::Definitions::ScoreType> iScore;
Loki::StrongPtr<D20Rules::Definitions::ModifierType, false> iModifier;
D20Rules::Definitions::ScoreType iTemp;
inline Definitions::ModifierType calculateModifier(const Definitions::ScoreType iScore) const { return (iScore - 10 - (iScore % 2)) / 2; }
/*! \author Omer Katz
\date 09/04/05
\brief This function is used to update iTotal's value.
iTotal here represents the active modifier.
For more intfo about the active modifier see getActiveModifier()'s documention.
*/
void updateTotal() { *iTotal = calculateModifier(*iScore); }
public:
D20Ability();
D20Ability(const Definitions::ScoreType iNewScore);
virtual ~D20Ability() {}
/*! \author Omer Katz
\date 2004
\brief The function returns the score of the ability.
*/
inline Definitions::ScoreType getScore() const { return *iScore - iTemp; }
/*! \author Omer Katz
\date 2004
\brief The function returns the modifier of the ability.
*/
inline Definitions::ModifierType getModifier() { updateTotal(); return *iTotal; }
/*! \author Omer Katz
\date 2004
\brief The function returns the temporary score of the ability.
*/
inline Definitions::ScoreType getTempScore() const { return *iScore; }
/*! \author Omer Katz
\date 2004
\brief The procedure sets the score of the ability.
It also sets the modifier of the score automaticly.
\param iNewScore - a constant integer
*/
inline void setScore(const Definitions::ScoreType iNewScore) { *iScore = iNewScore; updateTotal(); }
/*! \author Omer Katz
\date 2004
\brief The procedure sets the temporary score of the ability.
It also sets the temporary modifier of the score automaticly.
\param iNewTempScore - a constant integer
*/
void setTempScore(const Definitions::ScoreType iNewTempScore);
void rollAbility();
inline Definitions::ScoreType operator=(const Definitions::ScoreType iNewScore) { setScore(iNewScore); return *iScore; }
inline Definitions::ScoreType operator+=(const Definitions::ScoreType iNewScore) { setScore(*iScore + iNewScore); return *iScore; }
inline Definitions::ScoreType operator-=(const Definitions::ScoreType iNewScore) { setScore(*iScore - iNewScore); return *iScore; }
friend class D20Character;
};
}
}
#endif