From e5b8aadd493b8b5df4ed661f2491de33d634b001 Mon Sep 17 00:00:00 2001 From: fusion32 Date: Wed, 18 Jun 2025 18:57:37 -0300 Subject: finish `crplayer.cc` --- src/crskill.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/crskill.cc') 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){ -- cgit v1.2.3