aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2025-08-19 22:41:08 -0300
committerfusion32 <marcopuzziello@gmail.com>2025-08-19 22:41:08 -0300
commitd55b9473ec498ae181b3c91583c6950e4c3bb7f2 (patch)
tree6f0b2dc1504c037f774868b549fe00fc2945b99d
parentb2a9d2cb961fabc1ca05052a645d90663d8e0a92 (diff)
downloadgame-d55b9473ec498ae181b3c91583c6950e4c3bb7f2.tar.gz
game-d55b9473ec498ae181b3c91583c6950e4c3bb7f2.zip
fix a problem with monsters freezing after failing to attack
-rw-r--r--src/cr.hh1
-rw-r--r--src/cract.cc14
-rw-r--r--src/crmain.cc2
-rw-r--r--src/crplayer.cc12
-rw-r--r--src/crskill.cc17
-rw-r--r--src/enums.hh2
-rw-r--r--src/info.cc2
-rw-r--r--src/magic.cc4
-rw-r--r--src/receiving.cc7
9 files changed, 29 insertions, 32 deletions
diff --git a/src/cr.hh b/src/cr.hh
index 0848d42..f7cbb2e 100644
--- a/src/cr.hh
+++ b/src/cr.hh
@@ -539,6 +539,7 @@ struct TCreature: TSkillBase {
void ToDoStart(void);
void ToDoYield(void);
void ToDoWait(int Delay);
+ void ToDoWaitUntil(uint32 Time);
void ToDoGo(int DestX, int DestY, int DestZ, bool MustReach, int MaxSteps);
void ToDoRotate(int Direction);
void ToDoMove(int ObjX, int ObjY, int ObjZ, ObjectType Type, uint8 RNum,
diff --git a/src/cract.cc b/src/cract.cc
index 35ca92a..7b5673e 100644
--- a/src/cract.cc
+++ b/src/cract.cc
@@ -443,8 +443,7 @@ void TCreature::Move(Object Obj, int DestX, int DestY, int DestZ, uint8 Count){
}
if(DestX == 0xFFFF){ // SPECIAL_COORDINATE ?
- // NOTE(fusion): Any inventory slot.
- if(DestY == 0){
+ if(DestY == INVENTORY_ANY){
// NOTE(fusion): `CheckInventoryDestination` will throw if it's not
// possible to place the object on the chosen container. We want to
// find a slot that doesn't make it throw while giving priority to
@@ -470,7 +469,7 @@ void TCreature::Move(Object Obj, int DestX, int DestY, int DestZ, uint8 Count){
// NOTE(fusion): No appropriate inventory slot was found so we now
// fallback to inventory containers. For whatever reason we don't
// give priority to the bag slot.
- if(DestY == 0){
+ if(DestY == INVENTORY_ANY){
for(int Position = INVENTORY_FIRST;
Position <= INVENTORY_LAST;
Position += 1){
@@ -487,7 +486,7 @@ void TCreature::Move(Object Obj, int DestX, int DestY, int DestZ, uint8 Count){
}
}
- if(DestY == 0){
+ if(DestY == INVENTORY_ANY){
throw NOROOM;
}
}
@@ -984,6 +983,13 @@ void TCreature::ToDoWait(int Delay){
this->ToDoAdd(TD);
}
+void TCreature::ToDoWaitUntil(uint32 Time){
+ TToDoEntry TD = {};
+ TD.Code = TDWait;
+ TD.Wait.Time = Time;
+ this->ToDoAdd(TD);
+}
+
void TCreature::ToDoGo(int DestX, int DestY, int DestZ, bool MustReach, int MaxSteps){
if(this->posz > DestZ){
throw UPSTAIRS;
diff --git a/src/crmain.cc b/src/crmain.cc
index 0eda5e7..586f78e 100644
--- a/src/crmain.cc
+++ b/src/crmain.cc
@@ -934,7 +934,7 @@ void TCreature::CreatureMoveStimulus(uint32 CreatureID, int Type){
SendResult(this->Connection, r);
}
this->ToDoClear();
- this->ToDoWait(this->Combat.EarliestAttackTime);
+ this->ToDoWaitUntil(this->Combat.EarliestAttackTime);
this->ToDoStart();
}
}
diff --git a/src/crplayer.cc b/src/crplayer.cc
index 621f103..16ae6bb 100644
--- a/src/crplayer.cc
+++ b/src/crplayer.cc
@@ -1011,18 +1011,18 @@ void TPlayer::ClearProfession(void){
}
void TPlayer::SetProfession(uint8 Profession){
- if(Profession == PROFESSION_PROMOTED){
+ if(Profession == PROFESSION_PROMOTION){
if(this->Profession == PROFESSION_NONE){
error("TPlayer::SetProfession: Spieler hat noch keinen Beruf für Veredelung.\n");
return;
}
- if(this->Profession >= PROFESSION_PROMOTED){
+ if(this->Profession >= PROFESSION_PROMOTION){
error("TPlayer::SetProfession: Spieler hat seinen Beruf schon veredelt.\n");
return;
}
- this->Profession += PROFESSION_PROMOTED;
+ this->Profession += PROFESSION_PROMOTION;
this->Combat.CheckCombatValues();
// TODO(fusion): This is similar to the TPlayer's constructor. It is
@@ -1107,8 +1107,8 @@ uint8 TPlayer::GetRealProfession(void){
uint8 TPlayer::GetEffectiveProfession(void){
uint8 Profession = this->Profession;
- if(Profession >= PROFESSION_PROMOTED){
- Profession -= PROFESSION_PROMOTED;
+ if(Profession >= PROFESSION_PROMOTION){
+ Profession -= PROFESSION_PROMOTION;
}
return Profession;
}
@@ -1125,7 +1125,7 @@ uint8 TPlayer::GetActiveProfession(void){
bool TPlayer::GetActivePromotion(void){
return CheckRight(this->ID, PREMIUM_ACCOUNT)
- && this->Profession >= PROFESSION_PROMOTED;
+ && this->Profession >= PROFESSION_PROMOTION;
}
bool TPlayer::SpellKnown(int SpellNr){
diff --git a/src/crskill.cc b/src/crskill.cc
index 092e701..27655a9 100644
--- a/src/crskill.cc
+++ b/src/crskill.cc
@@ -480,20 +480,13 @@ int TSkillProbe::GetExpForLevel(int Level){
return 0;
}
- // TODO(fusion): This part of the decompiled code was a bit weird. I had to
- // look into the disassembly to figure the string parameter of `error` below
- // and it is weird that we keep going even with invalid values of `FactorPercent`.
int FactorPercent = this->FactorPercent;
- if(FactorPercent < 1000){
- const char *MasterName = "---";
- if(this->Master != NULL){
- MasterName = this->Master->Name;
- }
- error("TSkillProbe::GetExpForLevel: Ungültiger FactorPercent-Wert %d bei %s.\n", FactorPercent, MasterName);
- }
-
if(FactorPercent < 1050){
- error("TSkillProbe::GetExpForLevel: Ungültiger FactorPercent-Wert %d. Rechne mit 1000 weiter.\n", FactorPercent);
+ if(FactorPercent != 1000){
+ const char *MasterName = (this->Master != NULL ? this->Master->Name : "---");
+ error("TSkillProbe::GetExpForLevel: Ungültiger FactorPercent-Wert %d bei %s."
+ " Rechne mit 1000 weiter.\n", FactorPercent, MasterName);
+ }
return (Level - this->Min) * this->Delta;
}
diff --git a/src/enums.hh b/src/enums.hh
index afec34a..6939dd0 100644
--- a/src/enums.hh
+++ b/src/enums.hh
@@ -372,7 +372,7 @@ enum PROFESSION: uint8 {
PROFESSION_PALADIN = 2,
PROFESSION_SORCERER = 3,
PROFESSION_DRUID = 4,
- PROFESSION_PROMOTED = 10,
+ PROFESSION_PROMOTION = 10,
PROFESSION_ELITE_KNIGHT = 11,
PROFESSION_ROYAL_PALADIN = 12,
PROFESSION_MASTER_SORCERER = 13,
diff --git a/src/info.cc b/src/info.cc
index e24b819..eb655c4 100644
--- a/src/info.cc
+++ b/src/info.cc
@@ -405,7 +405,7 @@ Object GetObject(uint32 CreatureID, int x, int y, int z, int RNum, ObjectType Ty
if(Con != NONE){
Obj = GetContainerObject(Con, RNum);
}
- }else if(y != 0){
+ }else if(y != INVENTORY_ANY){
error("GetObject: Ungültiger ContainerCode x=%d,y=%d,z=%d,RNum=%d,Type=%d.\n",
x, y, z, RNum, Type.TypeID);
}
diff --git a/src/magic.cc b/src/magic.cc
index a47c730..8c14634 100644
--- a/src/magic.cc
+++ b/src/magic.cc
@@ -2904,9 +2904,7 @@ void ChangeProfession(TCreature *Actor, const char *Param){
return;
}
- // NOTE(fusion): Using the value 10 with `TPlayer::SetProfession` will
- // cause the player to be promoted.
- ((TPlayer*)Actor)->SetProfession(10);
+ ((TPlayer*)Actor)->SetProfession(PROFESSION_PROMOTION);
}else{
return;
}
diff --git a/src/receiving.cc b/src/receiving.cc
index ddaee44..7546396 100644
--- a/src/receiving.cc
+++ b/src/receiving.cc
@@ -269,10 +269,9 @@ void CMoveObject(TConnection *Connection, TReadBuffer *Buffer){
return;
}
- // TODO(fusion): `RNum` usage in this context will only be used inside
- // `GetObject` for indexing containers. For some reason I thought the
- // Z coordinate was also used for that. Perhaps they're set to the same
- // value.
+ // TODO(fusion): `RNum` is only used inside `ToDoMove` > `GetObject` to index
+ // into containers. For some reason I thought the Z coordinate was also used
+ // for that. Perhaps they're set to the same value.
if(OrigX != 0xFFFF){
RNum = 1;
}