aboutsummaryrefslogtreecommitdiff
path: root/src/crskill.cc
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2025-06-18 18:57:37 -0300
committerfusion32 <marcopuzziello@gmail.com>2025-06-18 18:57:37 -0300
commite5b8aadd493b8b5df4ed661f2491de33d634b001 (patch)
tree694e90810ca82d621573f8d26f64481f7001d183 /src/crskill.cc
parentb912ba995c2175b00393f95388ae2ec1afd0494b (diff)
downloadgame-e5b8aadd493b8b5df4ed661f2491de33d634b001.tar.gz
game-e5b8aadd493b8b5df4ed661f2491de33d634b001.zip
finish `crplayer.cc`
Diffstat (limited to 'src/crskill.cc')
-rw-r--r--src/crskill.cc16
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){