diff options
Diffstat (limited to 'src/crskill.cc')
| -rw-r--r-- | src/crskill.cc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/crskill.cc b/src/crskill.cc index 235f277..923c0ab 100644 --- a/src/crskill.cc +++ b/src/crskill.cc @@ -29,7 +29,11 @@ int TSkill::Get(void){ int TSkill::GetProgress(void){ int Result = 0; if(this->NextLevel > this->LastLevel){ - Result = (this->Exp - this->LastLevel) * 100 / (this->NextLevel - this->LastLevel); + // NOTE(fusion): Use 64-bit integers to avoid overflows. + int64 Result64 = (int64)(this->Exp - this->LastLevel) * 100 + / (int64)(this->NextLevel - this->LastLevel); + + Result = (int)Result64; // TODO(fusion): This feels too much for reporting a mostly *impossible* error. if(Result < 0 || Result > 100){ @@ -64,6 +68,16 @@ void TSkill::Change(int Amount){ } } +void TSkill::SetMax(void){ + this->Set(this->Max); +} + +void TSkill::DecreasePercent(int Percent){ + // NOTE(fusion): Use 64-bit integers to avoid overflows. + int64 Amount64 = ((int64)this->Exp * (int64)Percent) / 100; + this->Decrease((int)Amount64); +} + void TSkill::SetMDAct(int MDAct){ this->MDAct = MDAct; if(this->SkNr == SKILL_GO_STRENGTH && this->Master && this->Master->Type == PLAYER){ |
