aboutsummaryrefslogtreecommitdiff
path: root/src/cract.cc
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2025-07-21 19:23:42 -0300
committerfusion32 <marcopuzziello@gmail.com>2025-07-21 22:49:41 -0300
commite4b8bf807b76f6f446d9617d9a3957dc77dd6e90 (patch)
treef974c51ca7ea111c7e96990e39453ae5dba9a6c5 /src/cract.cc
parent7b9e7dbbcf1d779419be8f22df812ff523a25450 (diff)
downloadgame-e4b8bf807b76f6f446d9617d9a3957dc77dd6e90.tar.gz
game-e4b8bf807b76f6f446d9617d9a3957dc77dd6e90.zip
multiple bug-fixes and improvements
- Make uint32 -> Object conversion explicit. This can be more verbose but will get a lot of small mistakes, especially with function overloads. - Fix problem with the path finder not including the last step when `MustReach` was false. - Fix problem with NPC conditions. - Fix problem with monster homes continuously spawning monsters. - Fix problem with creating the standard inventory. - Fix problem with creature timers (IMPORTANT). - Fix problem with `ThrowPossible` (IMPORTANT). - Fix problem with rune casting. - Fix problem with executing moveuse events. - Fix problem with `MoveRel` and `WriteName` moveuse actions. - Fix problem with eating food deleting the whole stack. - Many other bug-fixes and improvements.
Diffstat (limited to 'src/cract.cc')
-rw-r--r--src/cract.cc26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/cract.cc b/src/cract.cc
index f30415d..41bbcca 100644
--- a/src/cract.cc
+++ b/src/cract.cc
@@ -151,7 +151,7 @@ void TShortway::Expand(TShortwayPoint *Node){
// add waypoints two more times.
int NeighborWaylength = MinNeighborWaylength;
if(OffsetX != 0 && OffsetY != 0){
- NeighborWaylength += Node->Waylength * 2;
+ NeighborWaylength += Node->Waypoints * 2;
}
if(NeighborWaylength < Neighbor->Waylength){
@@ -238,15 +238,12 @@ bool TShortway::Calculate(int DestX, int DestY, bool MustReach, int MaxSteps){
}
// NOTE(fusion): Walk back from the origin to reconstruct the path.
+ int CurDistance = std::max<int>(
+ std::abs(Node->x - DestX),
+ std::abs(Node->y - DestY));
Node = Node->Predecessor;
- while(Node != NULL && MaxSteps > 0){
- int MaxDistance = std::max<int>(
- std::abs(Node->x - DestX),
- std::abs(Node->y - DestY));
- if(!MustReach && MaxDistance <= 1){
- break;
- }
-
+ while(Node != NULL && MaxSteps > 0
+ && (MustReach || CurDistance > 1)){
TToDoEntry TD = {};
TD.Code = TDGo;
TD.Go.x = this->StartX + Node->x;
@@ -254,6 +251,9 @@ bool TShortway::Calculate(int DestX, int DestY, bool MustReach, int MaxSteps){
TD.Go.z = this->StartZ;
Creature->ToDoAdd(TD);
+ CurDistance = std::max<int>(
+ std::abs(Node->x - DestX),
+ std::abs(Node->y - DestY));
Node = Node->Predecessor;
MaxSteps -= 1;
}
@@ -768,22 +768,22 @@ void TCreature::Execute(void){
}
case TDMove:{
- this->Move(TD.Move.Obj, TD.Move.x, TD.Move.y, TD.Move.z, (uint8)TD.Move.Count);
+ this->Move(Object(TD.Move.Obj), TD.Move.x, TD.Move.y, TD.Move.z, (uint8)TD.Move.Count);
break;
}
case TDTrade:{
- this->Trade(TD.Trade.Obj, TD.Trade.Partner);
+ this->Trade(Object(TD.Trade.Obj), TD.Trade.Partner);
break;
}
case TDUse:{
- this->Use(TD.Use.Obj1, TD.Use.Obj2, TD.Use.Dummy);
+ this->Use(Object(TD.Use.Obj1), Object(TD.Use.Obj2), TD.Use.Dummy);
break;
}
case TDTurn:{
- this->Turn(TD.Turn.Obj);
+ this->Turn(Object(TD.Turn.Obj));
break;
}