diff options
Diffstat (limited to 'engines/sci/engine')
-rw-r--r-- | engines/sci/engine/kernel.h | 10 | ||||
-rw-r--r-- | engines/sci/engine/kernel_tables.h | 5 | ||||
-rw-r--r-- | engines/sci/engine/kgraphics.cpp | 5 | ||||
-rw-r--r-- | engines/sci/engine/kgraphics32.cpp | 16 | ||||
-rw-r--r-- | engines/sci/engine/kmath.cpp | 82 | ||||
-rw-r--r-- | engines/sci/engine/kstring.cpp | 77 | ||||
-rw-r--r-- | engines/sci/engine/script_patches.cpp | 26 | ||||
-rw-r--r-- | engines/sci/engine/workarounds.cpp | 5 |
8 files changed, 187 insertions, 39 deletions
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index f985a69ebc..e3ebce80fb 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -427,18 +427,23 @@ reg_t kUpdatePlane(EngineState *s, int argc, reg_t *argv); reg_t kSetShowStyle(EngineState *s, int argc, reg_t *argv); reg_t kGetHighPlanePri(EngineState *s, int argc, reg_t *argv); reg_t kFrameOut(EngineState *s, int argc, reg_t *argv); + reg_t kIsOnMe(EngineState *s, int argc, reg_t *argv); // kOnMe for SCI2, kIsOnMe for SCI2.1 +reg_t kInPolygon(EngineState *s, int argc, reg_t *argv); +reg_t kObjectIntersect(EngineState *s, int argc, reg_t *argv); + reg_t kListIndexOf(EngineState *s, int argc, reg_t *argv); reg_t kListEachElementDo(EngineState *s, int argc, reg_t *argv); reg_t kListFirstTrue(EngineState *s, int argc, reg_t *argv); reg_t kListAllTrue(EngineState *s, int argc, reg_t *argv); -reg_t kInPolygon(EngineState *s, int argc, reg_t *argv); -reg_t kObjectIntersect(EngineState *s, int argc, reg_t *argv); + reg_t kEditText(EngineState *s, int argc, reg_t *argv); reg_t kMakeSaveCatName(EngineState *s, int argc, reg_t *argv); reg_t kMakeSaveFileName(EngineState *s, int argc, reg_t *argv); reg_t kSetScroll(EngineState *s, int argc, reg_t *argv); reg_t kPalCycle(EngineState *s, int argc, reg_t *argv); +reg_t kPalVaryUnknown(EngineState *s, int argc, reg_t *argv); +reg_t kPalVaryUnknown2(EngineState *s, int argc, reg_t *argv); // SCI2.1 Kernel Functions reg_t kText(EngineState *s, int argc, reg_t *argv); @@ -513,7 +518,6 @@ reg_t kPalVaryDeinit(EngineState *s, int argc, reg_t *argv); reg_t kPalVaryChangeTarget(EngineState *s, int argc, reg_t *argv); reg_t kPalVaryChangeTicks(EngineState *s, int argc, reg_t *argv); reg_t kPalVaryPauseResume(EngineState *s, int argc, reg_t *argv); -reg_t kPalVaryUnknown(EngineState *s, int argc, reg_t *argv); reg_t kPaletteSetFromResource(EngineState *s, int argc, reg_t *argv); reg_t kPaletteSetFlag(EngineState *s, int argc, reg_t *argv); diff --git a/engines/sci/engine/kernel_tables.h b/engines/sci/engine/kernel_tables.h index d0c9b9b1cf..d7858180f1 100644 --- a/engines/sci/engine/kernel_tables.h +++ b/engines/sci/engine/kernel_tables.h @@ -156,7 +156,7 @@ static const SciKernelMapSubEntry kDoSound_subops[] = { // signature for SCI21 should be "o" { SIG_SOUNDSCI21, 9, MAP_CALL(DoSoundStop), NULL, NULL }, { SIG_SOUNDSCI21, 10, MAP_CALL(DoSoundPause), NULL, NULL }, - { SIG_SOUNDSCI21, 11, MAP_CALL(DoSoundFade), NULL, NULL }, + { SIG_SOUNDSCI21, 11, MAP_CALL(DoSoundFade), NULL, kDoSoundFade_workarounds }, { SIG_SOUNDSCI21, 12, MAP_CALL(DoSoundSetHold), NULL, NULL }, { SIG_SOUNDSCI21, 13, MAP_CALL(DoSoundDummy), NULL, NULL }, { SIG_SOUNDSCI21, 14, MAP_CALL(DoSoundSetVolume), NULL, NULL }, @@ -202,7 +202,10 @@ static const SciKernelMapSubEntry kPalVary_subops[] = { { SIG_SCIALL, 4, MAP_CALL(PalVaryChangeTarget), "i", NULL }, { SIG_SCIALL, 5, MAP_CALL(PalVaryChangeTicks), "i", NULL }, { SIG_SCIALL, 6, MAP_CALL(PalVaryPauseResume), "i", NULL }, +#ifdef ENABLE_SCI32 { SIG_SCI32, 8, MAP_CALL(PalVaryUnknown), "i", NULL }, + { SIG_SCI32, 9, MAP_CALL(PalVaryUnknown2), "i", NULL }, +#endif SCI_SUBOPENTRY_TERMINATOR }; diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index da377319c0..a65bcc215e 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -722,11 +722,6 @@ reg_t kPalVaryPauseResume(EngineState *s, int argc, reg_t *argv) { return NULL_REG; } -reg_t kPalVaryUnknown(EngineState *s, int argc, reg_t *argv) { - // Unknown (seems to be SCI32 exclusive) - return NULL_REG; -} - reg_t kAssertPalette(EngineState *s, int argc, reg_t *argv) { GuiResourceId paletteId = argv[0].toUint16(); diff --git a/engines/sci/engine/kgraphics32.cpp b/engines/sci/engine/kgraphics32.cpp index 1d30f709dc..cd735d1233 100644 --- a/engines/sci/engine/kgraphics32.cpp +++ b/engines/sci/engine/kgraphics32.cpp @@ -683,6 +683,22 @@ reg_t kSetScroll(EngineState *s, int argc, reg_t *argv) { return kStub(s, argc, argv); } +reg_t kPalVaryUnknown(EngineState *s, int argc, reg_t *argv) { + // TODO: Unknown (seems to be SCI32 exclusive) + return kStub(s, argc, argv); +} + +reg_t kPalVaryUnknown2(EngineState *s, int argc, reg_t *argv) { + // TODO: Unknown (seems to be SCI32 exclusive) + // It seems to be related to the day/night palette effects in QFG4, and + // accepts a palette resource ID. It is triggered right when the night + // effect is initially applied (when exiting the caves). + // In QFG4, there are two scene palettes: 790 for night, and 791 for day. + // Initially, the game starts at night time, but this is called with the + // ID of the day time palette (i.e. 791). + return kStub(s, argc, argv); +} + reg_t kPalCycle(EngineState *s, int argc, reg_t *argv) { // Examples: GK1 room 480 (Bayou ritual), LSL6 room 100 (title screen) diff --git a/engines/sci/engine/kmath.cpp b/engines/sci/engine/kmath.cpp index 4b8fadbb84..b2aaa01b45 100644 --- a/engines/sci/engine/kmath.cpp +++ b/engines/sci/engine/kmath.cpp @@ -77,18 +77,7 @@ reg_t kSqrt(EngineState *s, int argc, reg_t *argv) { return make_reg(0, (int16) sqrt((float) ABS(argv[0].toSint16()))); } -/** - * Returns the angle (in degrees) between the two points determined by (x1, y1) - * and (x2, y2). The angle ranges from 0 to 359 degrees. - * What this function does is pretty simple but apparently the original is not - * accurate. - */ -uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) { - // SCI1 games (QFG2 and newer) use a simple atan implementation. SCI0 games - // use a somewhat less accurate calculation (below). - if (getSciVersion() >= SCI_VERSION_1_EGA_ONLY) - return (int16)(360 - atan2((double)(x1 - x2), (double)(y1 - y2)) * 57.2958) % 360; - +uint16 kGetAngle_SCI0(int16 x1, int16 y1, int16 x2, int16 y2) { int16 xRel = x2 - x1; int16 yRel = y1 - y2; // y-axis is mirrored. int16 angle; @@ -118,6 +107,75 @@ uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) { return angle; } +// atan2 for first octant, x >= y >= 0. Returns [0,45] (inclusive) +int kGetAngle_SCI1_atan2_base(int y, int x) { + if (x == 0) + return 0; + + // fixed point tan(a) + int tan_fp = 10000 * y / x; + + if ( tan_fp >= 1000 ) { + // For tan(a) >= 0.1, interpolate between multiples of 5 degrees + + // 10000 * tan([5, 10, 15, 20, 25, 30, 35, 40, 45]) + const int tan_table[] = { 875, 1763, 2679, 3640, 4663, 5774, + 7002, 8391, 10000 }; + + // Look up tan(a) in our table + int i = 1; + while (tan_fp > tan_table[i]) ++i; + + // The angle a is between 5*i and 5*(i+1). We linearly interpolate. + int dist = tan_table[i] - tan_table[i-1]; + int interp = (5 * (tan_fp - tan_table[i-1]) + dist/2) / dist; + return 5*i + interp; + } else { + // for tan(a) < 0.1, tan(a) is approximately linear in a. + // tan'(0) = 1, so in degrees the slope of atan is 180/pi = 57.29... + return (57 * y + x/2) / x; + } +} + +int kGetAngle_SCI1_atan2(int y, int x) { + if (y < 0) { + int a = kGetAngle_SCI1_atan2(-y, -x); + if (a == 180) + return 0; + else + return 180 + a; + } + if (x < 0) + return 90 + kGetAngle_SCI1_atan2(-x, y); + if (y > x) + return 90 - kGetAngle_SCI1_atan2_base(x, y); + else + return kGetAngle_SCI1_atan2_base(y, x); + +} + +uint16 kGetAngle_SCI1(int16 x1, int16 y1, int16 x2, int16 y2) { + // We flip things around to get into the standard atan2 coordinate system + return kGetAngle_SCI1_atan2(x2 - x1, y1 - y2); + +} + +/** + * Returns the angle (in degrees) between the two points determined by (x1, y1) + * and (x2, y2). The angle ranges from 0 to 359 degrees. + * What this function does is pretty simple but apparently the original is not + * accurate. + */ + +uint16 kGetAngleWorker(int16 x1, int16 y1, int16 x2, int16 y2) { + if (getSciVersion() >= SCI_VERSION_1_EGA_ONLY) + return kGetAngle_SCI1(x1, y1, x2, y2); + else + return kGetAngle_SCI0(x1, y1, x2, y2); +} + + + reg_t kGetAngle(EngineState *s, int argc, reg_t *argv) { // Based on behavior observed with a test program created with // SCI Studio. diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index c4db0b891c..65e139e1ee 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -155,30 +155,47 @@ reg_t kReadNumber(EngineState *s, int argc, reg_t *argv) { source++; /* Skip whitespace */ int16 result = 0; + int16 sign = 1; + if (*source == '-') { + sign = -1; + source++; + } if (*source == '$') { // Hexadecimal input - result = (int16)strtol(source + 1, NULL, 16); + source++; + char c; + while ((c = *source++) != 0) { + int16 x = 0; + if ((c >= '0') && (c <= '9')) + x = c - '0'; + else if ((c >= 'a') && (c <= 'f')) + x = c - 'a' + 10; + else if ((c >= 'A') && (c <= 'F')) + x = c - 'A' + 10; + else + // Stop if we encounter anything other than a digit (like atoi) + break; + result *= 16; + result += x; + } } else { // Decimal input. We can not use strtol/atoi in here, because while // Sierra used atoi, it was a non standard compliant atoi, that didn't // do clipping. In SQ4 we get the door code in here and that's even // larger than uint32! - if (*source == '-') { - // FIXME: Setting result to -1 does _not_ negate the output. - result = -1; - source++; - } - while (*source) { - if ((*source < '0') || (*source > '9')) + char c; + while ((c = *source++) != 0) { + if ((c < '0') || (c > '9')) // Stop if we encounter anything other than a digit (like atoi) break; result *= 10; - result += *source - 0x30; - source++; + result += c - '0'; } } + result *= sign; + return make_reg(0, result); } @@ -489,6 +506,7 @@ reg_t kGetMessage(EngineState *s, int argc, reg_t *argv) { reg_t kMessage(EngineState *s, int argc, reg_t *argv) { uint func = argv[0].toUint16(); + uint16 module = (argc >= 2) ? argv[1].toUint16() : 0; #ifdef ENABLE_SCI32 if (getSciVersion() >= SCI_VERSION_2) { @@ -518,19 +536,44 @@ reg_t kMessage(EngineState *s, int argc, reg_t *argv) { if (argc >= 6) tuple = MessageTuple(argv[2].toUint16(), argv[3].toUint16(), argv[4].toUint16(), argv[5].toUint16()); + // WORKAROUND for a script bug in Pepper. When using objects together, + // there is code inside script 894 that shows appropriate messages. + // In the case of the jar of cabbage (noun 26), the relevant message + // shown when using any object with it is missing. This leads to the + // script code being triggered, which modifies the jar's noun and + // message selectors, and renders it useless. Thus, when using any + // object with the jar of cabbage, it's effectively corrupted, and + // can't be used on the goat to empty it, therefore the game reaches + // an unsolvable state. It's almost impossible to patch the offending + // script, as it is used in many cases. But we can prevent the + // corruption of the jar here: if the message is found, the offending + // code is never reached and the jar is never corrupted. To do this, + // we substitute all verbs on the cabbage jar with the default verb, + // which shows the "Cannot use this object with the jar" message, and + // never triggers the offending script code that corrupts the object. + // This only affects the jar of cabbage - any other object, including + // the empty jar has a different noun, thus it's unaffected. + // Fixes bug #3601090. + // NOTE: To fix a corrupted jar object, type "send Glass_Jar message 52" + // in the debugger. + if (g_sci->getGameId() == GID_PEPPER && func == 0 && argc >= 6 && module == 894 && + tuple.noun == 26 && tuple.cond == 0 && tuple.seq == 1 && + !s->_msgState->getMessage(module, tuple, NULL_REG)) + tuple.verb = 0; + switch (func) { case K_MESSAGE_GET: - return make_reg(0, s->_msgState->getMessage(argv[1].toUint16(), tuple, (argc == 7 ? argv[6] : NULL_REG))); + return make_reg(0, s->_msgState->getMessage(module, tuple, (argc == 7 ? argv[6] : NULL_REG))); case K_MESSAGE_NEXT: return make_reg(0, s->_msgState->nextMessage((argc == 2 ? argv[1] : NULL_REG))); case K_MESSAGE_SIZE: - return make_reg(0, s->_msgState->messageSize(argv[1].toUint16(), tuple)); + return make_reg(0, s->_msgState->messageSize(module, tuple)); case K_MESSAGE_REFCOND: case K_MESSAGE_REFVERB: case K_MESSAGE_REFNOUN: { MessageTuple t; - if (s->_msgState->messageRef(argv[1].toUint16(), tuple, t)) { + if (s->_msgState->messageRef(module, tuple, t)) { switch (func) { case K_MESSAGE_REFCOND: return make_reg(0, t.cond); @@ -545,9 +588,9 @@ reg_t kMessage(EngineState *s, int argc, reg_t *argv) { } case K_MESSAGE_LASTMESSAGE: { MessageTuple msg; - int module; + int lastModule; - s->_msgState->lastQuery(module, msg); + s->_msgState->lastQuery(lastModule, msg); bool ok = false; @@ -556,7 +599,7 @@ reg_t kMessage(EngineState *s, int argc, reg_t *argv) { if (buffer) { ok = true; - WRITE_LE_UINT16(buffer, module); + WRITE_LE_UINT16(buffer, lastModule); WRITE_LE_UINT16(buffer + 2, msg.noun); WRITE_LE_UINT16(buffer + 4, msg.verb); WRITE_LE_UINT16(buffer + 6, msg.cond); @@ -567,7 +610,7 @@ reg_t kMessage(EngineState *s, int argc, reg_t *argv) { if (buffer) { ok = true; - buffer[0] = make_reg(0, module); + buffer[0] = make_reg(0, lastModule); buffer[1] = make_reg(0, msg.noun); buffer[2] = make_reg(0, msg.verb); buffer[3] = make_reg(0, msg.cond); diff --git a/engines/sci/engine/script_patches.cpp b/engines/sci/engine/script_patches.cpp index 8639b6ef71..c928cf3569 100644 --- a/engines/sci/engine/script_patches.cpp +++ b/engines/sci/engine/script_patches.cpp @@ -883,12 +883,38 @@ const uint16 qfg1vgaPatchDialogHeader[] = { PATCH_END }; +// When clicking on the crusher in room 331, Ego approaches him to talk to him, +// an action that is handled by moveToCrusher::changeState in script 331. The +// scripts set Ego to move close to the crusher, but when Ego is running instead +// of walking, the target coordinates specified by script 331 are never reached, +// as Ego is making larger steps, and never reaches the required spot. This is an +// edge case that can occur when Ego is set to run. Normally, when clicking on +// the crusher, ego is supposed to move close to position 79, 165. We change it +// to 85, 165, which is not an edge case thus the freeze is avoided. +// Fixes bug #3585189. +const byte qfg1vgaSignatureMoveToCrusher[] = { + 9, + 0x51, 0x1f, // class Motion + 0x36, // push + 0x39, 0x4f, // pushi 4f (79 - x) + 0x38, 0xa5, 0x00, // pushi 00a5 (165 - y) + 0x7c, // pushSelf + 0 +}; + +const uint16 qfg1vgaPatchMoveToCrusher[] = { + PATCH_ADDTOOFFSET | +3, + 0x39, 0x55, // pushi 55 (85 - x) + PATCH_END +}; + // script, description, magic DWORD, adjust const SciScriptSignature qfg1vgaSignatures[] = { { 215, "fight event issue", 1, PATCH_MAGICDWORD(0x6d, 0x76, 0x51, 0x07), -1, qfg1vgaSignatureFightEvents, qfg1vgaPatchFightEvents }, { 216, "weapon master event issue", 1, PATCH_MAGICDWORD(0x6d, 0x76, 0x51, 0x07), -1, qfg1vgaSignatureFightEvents, qfg1vgaPatchFightEvents }, { 814, "window text temp space", 1, PATCH_MAGICDWORD(0x3f, 0xba, 0x87, 0x00), 0, qfg1vgaSignatureTempSpace, qfg1vgaPatchTempSpace }, { 814, "dialog header offset", 3, PATCH_MAGICDWORD(0x5b, 0x04, 0x80, 0x36), 0, qfg1vgaSignatureDialogHeader, qfg1vgaPatchDialogHeader }, + { 331, "moving to crusher", 1, PATCH_MAGICDWORD(0x51, 0x1f, 0x36, 0x39), 0, qfg1vgaSignatureMoveToCrusher, qfg1vgaPatchMoveToCrusher }, SCI_SIGNATUREENTRY_TERMINATOR }; diff --git a/engines/sci/engine/workarounds.cpp b/engines/sci/engine/workarounds.cpp index db510c2545..ff7e601fcb 100644 --- a/engines/sci/engine/workarounds.cpp +++ b/engines/sci/engine/workarounds.cpp @@ -140,7 +140,7 @@ const SciWorkaroundEntry uninitializedReadWorkarounds[] = { { GID_QFG2, 260, 260, 0, "jabbarS", "changeState",0x2d22, -1, { WORKAROUND_FAKE, 0 } }, // During the thief's first mission (in the house), just before Jabbar is about to enter the house (where you have to hide in the wardrobe), bug #3040469, temps 1 and 2 { GID_QFG2, 500, 500, 0, "lightNextCandleS", "changeState", -1, -1, { WORKAROUND_FAKE, 0 } }, // Inside the last room, while Ad Avis performs the ritual to summon the genie - bug #3148418 { GID_QFG2, -1, 700, 0, NULL, "showSign", -1, 10, { WORKAROUND_FAKE, 0 } }, // Occurs sometimes when reading a sign in Raseir, Shapeir et al - bugs #3272735, #3275413 - { GID_QFG3, 510, 510, 0, "awardPrize", "changeState", -1, 0, { WORKAROUND_FAKE, 0 } }, // Simbani warrior challenge, after throwing the spears and retrieving the ring - bug #3049435 + { GID_QFG3, 510, 510, 0, "awardPrize", "changeState", -1, 0, { WORKAROUND_FAKE, 1 } }, // Simbani warrior challenge, after throwing the spears and retrieving the ring - bug #3049435. Must be non-zero, otherwise the prize is awarded twice - bug #3575570. { GID_QFG3, 140, 140, 0, "rm140", "init", 0x1008, 0, { WORKAROUND_FAKE, 0 } }, // when importing a character and selecting the previous profession - bug #3040460 { GID_QFG3, 330, 330, -1, "Teller", "doChild", -1, -1, { WORKAROUND_FAKE, 0 } }, // when talking to King Rajah about "Rajah" (bug #3036390, temp 1) or "Tarna" (temp 0), or when clicking on yourself and saying "Greet" (bug #3039774, temp 1) { GID_QFG3, 700, 700, -1, "monsterIsDead", "changeState", -1, 0, { WORKAROUND_FAKE, 0 } }, // in the jungle, after winning any fight, bug #3040624 @@ -151,6 +151,8 @@ const SciWorkaroundEntry uninitializedReadWorkarounds[] = { { GID_QFG4, -1, 15, -1, "charInitScreen", "dispatchEvent", -1, 5, { WORKAROUND_FAKE, 0 } }, // floppy version, when viewing the character screen { GID_QFG4, -1, 64917, -1, "controlPlane", "setBitmap", -1, 3, { WORKAROUND_FAKE, 0 } }, // floppy version, when entering the game menu { GID_QFG4, -1, 64917, -1, "Plane", "setBitmap", -1, 3, { WORKAROUND_FAKE, 0 } }, // floppy version, happens sometimes in fight scenes + { GID_QFG4, 520, 64950, 0, "fLake2", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // CD version, at the lake, when meeting the Rusalka and attempting to leave + { GID_QFG4, 800, 64950, 0, "View", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // CD version, in the room with the spider pillar, when climbing on the pillar { GID_RAMA, 12, 64950, -1, "InterfaceFeature", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // Demo, right when it starts { GID_RAMA, 12, 64950, -1, "hiliteOptText", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // Demo, right when it starts { GID_RAMA, 12, 64950, -1, "View", "handleEvent", -1, 0, { WORKAROUND_FAKE, 0 } }, // Demo, right when it starts @@ -246,6 +248,7 @@ const SciWorkaroundEntry kDoSoundFade_workarounds[] = { { GID_KQ5, 213, 989, 0, "globalSound3", "fade", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // english floppy: when bandits leave the secret temple, parameter 4 is an object - bug #3037594 { GID_KQ6, 105, 989, 0, "globalSound", "fade", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // floppy: during intro, parameter 4 is an object { GID_KQ6, 460, 989, 0, "globalSound2", "fade", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // after pulling the black widow's web on the isle of wonder, parameter 4 is an object - bug #3034567 + { GID_QFG4, -1, 64989, 0, "longSong", "fade", -1, 0, { WORKAROUND_STILLCALL, 0 } }, // CD version: many places, parameter 4 is an object (longSong) SCI_WORKAROUNDENTRY_TERMINATOR }; |