Permalink
Browse files

SCI32: Fix QFG4 forest pathfinding

Adds workarounds for odd detours during entry, bugs #10857, #10858
  • Loading branch information...
Vhati authored and bluegr committed Jan 3, 2019
1 parent b254618 commit aac5ed1cae3d83fb84b8179956f75f96fcc43763
Showing with 46 additions and 9 deletions.
  1. +16 −9 engines/sci/engine/kpathing.cpp
  2. +30 −0 engines/sci/engine/script_patches.cpp
@@ -1407,15 +1407,22 @@ static void AStar(PathfindingState *s) {
// This difference might lead to problems, but none are
// known at the time of writing.

// WORKAROUND: This check fails in QFG1VGA, room 81 (bug report #3568452).
// However, it is needed in other SCI1.1 games, such as LB2. Therefore, we
// add this workaround for that scene in QFG1VGA, until our algorithm matches
// better what SSCI is doing. With this workaround, QFG1VGA no longer freezes
// in that scene.
bool qfg1VgaWorkaround = (g_sci->getGameId() == GID_QFG1VGA &&
g_sci->getEngineState()->currentRoomNumber() == 81);

if (s->pointOnScreenBorder(vertex->v) && !qfg1VgaWorkaround)
// WORKAROUND: This check is needed in SCI1.1 games, such as LB2. Until our
// algorithm matches better what SSCI is doing, we exempt certain rooms where
// the check fails.
bool penaltyWorkaround =
// QFG1VGA room 81 - Hero gets stuck when walking to the SE corner (bug #6140).
(g_sci->getGameId() == GID_QFG1VGA && g_sci->getEngineState()->currentRoomNumber() == 81) ||
#ifdef ENABLE_SCI32
// QFG4 room 563 - Hero zig-zags into the room (bug #10858).
// Entering from the south (564) off-screen behind an obstacle, hero
// fails to turn at a point on the screen edge, passes the poly's corner,
// then approaches the destination from deeper in the room.
(g_sci->getGameId() == GID_QFG4 && g_sci->getEngineState()->currentRoomNumber() == 563) ||
#endif
false;

if (s->pointOnScreenBorder(vertex->v) && !penaltyWorkaround)
new_dist += 10000;

if (new_dist < vertex->costG) {
@@ -9473,6 +9473,35 @@ static const uint16 qfg4PitRopeMagePatch2[] = {
PATCH_END
};

// WORKAROUND: Script needed, because of differences in our pathfinding
// algorithm.
// When entering forest room 557 from the east (563), hero is supposed to move
// only a short distance into the room. ScummVM's pathfinding sends hero off
// course, to the middle of the room and back.
//
// There's an unwalkable stream in the SE corner, and hero's coords were within
// its polygon. We lower the top two points to keep hero on the outside.
//
// Applies to at least: English CD, English floppy, German floppy
// Responsible method: rm557::init() in script 557
// Fixes bug: #10857
static const uint16 qfg4Forest557PathfindingSignature[] = {
SIG_MAGICDWORD,
0x38, SIG_UINT16(0x0119), // pushi 281d (point 3)
0x38, SIG_UINT16(0x0087), // pushi 135d
0x38, SIG_UINT16(0x013f), // pushi 319d (point 4)
0x38, SIG_UINT16(0x0087), // pushi 135d
SIG_END
};

static const uint16 qfg4Forest557PathfindingPatch[] = {
PATCH_ADDTOOFFSET(+3),
0x38, PATCH_UINT16(0x0089), // pushi 137d
PATCH_ADDTOOFFSET(+3),
0x38, PATCH_UINT16(0x0089), // pushi 137d
PATCH_END
};

// script, description, signature patch
static const SciScriptPatcherEntry qfg4Signatures[] = {
{ true, 0, "prevent autosave from deleting save games", 1, qfg4AutosaveSignature, qfg4AutosavePatch },
@@ -9501,6 +9530,7 @@ static const SciScriptPatcherEntry qfg4Signatures[] = {
{ true, 542, "fix setLooper calls (1/2)", 5, qfg4SetLooperSignature1, qfg4SetLooperPatch1 },
{ true, 543, "fix setLooper calls (1/2)", 5, qfg4SetLooperSignature1, qfg4SetLooperPatch1 },
{ true, 545, "fix setLooper calls (1/2)", 5, qfg4SetLooperSignature1, qfg4SetLooperPatch1 },
{ true, 557, "fix forest 557 entry from east", 1, qfg4Forest557PathfindingSignature, qfg4Forest557PathfindingPatch },
{ true, 630, "fix great hall entry from barrel room", 1, qfg4GreatHallEntrySignature, qfg4GreatHallEntryPatch },
{ true, 633, "fix stairway pathfinding", 1, qfg4StairwayPathfindingSignature, qfg4StairwayPathfindingPatch },
{ true, 643, "fix iron safe's east door sending hero west", 1, qfg4SafeDoorEastSignature, qfg4SafeDoorEastPatch },

0 comments on commit aac5ed1

Please sign in to comment.