diff options
author | Filippos Karapetis | 2011-12-06 22:24:15 +0200 |
---|---|---|
committer | Filippos Karapetis | 2011-12-06 22:24:46 +0200 |
commit | e4e059b85722cdd5938fb39f56276ff7863e00cc (patch) | |
tree | 3b2a9716cf0bbe7602a9feaffbd33ebf0ace5337 | |
parent | 44ed4ef0dfef85d5505109b46a4ce7d0f9bb60d5 (diff) | |
download | scummvm-rg350-e4e059b85722cdd5938fb39f56276ff7863e00cc.tar.gz scummvm-rg350-e4e059b85722cdd5938fb39f56276ff7863e00cc.tar.bz2 scummvm-rg350-e4e059b85722cdd5938fb39f56276ff7863e00cc.zip |
DREAMWEB: Add a default use handler, thereby reducing code duplication
-rw-r--r-- | engines/dreamweb/stubs.h | 1 | ||||
-rw-r--r-- | engines/dreamweb/use.cpp | 246 |
2 files changed, 88 insertions, 159 deletions
diff --git a/engines/dreamweb/stubs.h b/engines/dreamweb/stubs.h index 4724ae2f81..fd734b20cc 100644 --- a/engines/dreamweb/stubs.h +++ b/engines/dreamweb/stubs.h @@ -405,6 +405,7 @@ void useElvDoor(); void useObject(); void useWinch(); + bool defaultUseHandler(const char *id); void openTVDoor(); void wearWatch(); void wearShades(); diff --git a/engines/dreamweb/use.cpp b/engines/dreamweb/use.cpp index fa23f1dc32..a2b5e7f568 100644 --- a/engines/dreamweb/use.cpp +++ b/engines/dreamweb/use.cpp @@ -732,33 +732,41 @@ void DreamGenContext::sLabDoorF() { } } -void DreamGenContext::useChurchGate() { +bool DreamGenContext::defaultUseHandler(const char *id) { if (data.byte(kWithobject) == 255) { withWhat(); - return; + return true; // event handled } - char id[4] = { 'C', 'U', 'T', 'T' }; // TODO: convert to string with trailing zero if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) { // Wrong item cx = 300; al = 14; showPuzText(); putBackObStuff(); - } else { - // Cut gate - showFirstUse(); - data.word(kWatchingtime) = 64 * 2; - data.word(kReeltowatch) = 4; - data.word(kEndwatchreel) = 70; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; - data.byte(kProgresspoints)++; - turnPathOn(3); - if (data.byte(kAidedead) != 0) - turnPathOn(2); // Open church + return true; // event handled } + + return false; // continue with the original event +} + +void DreamGenContext::useChurchGate() { + char id[4] = { 'C', 'U', 'T', 'T' }; // TODO: convert to string with trailing zero + if (defaultUseHandler(id)) + return; + + // Cut gate + showFirstUse(); + data.word(kWatchingtime) = 64 * 2; + data.word(kReeltowatch) = 4; + data.word(kEndwatchreel) = 70; + data.byte(kWatchspeed) = 1; + data.byte(kSpeedcount) = 1; + data.byte(kGetback) = 1; + data.byte(kProgresspoints)++; + turnPathOn(3); + if (data.byte(kAidedead) != 0) + turnPathOn(2); // Open church } void DreamGenContext::useFullCart() { @@ -780,50 +788,30 @@ void DreamGenContext::useFullCart() { } void DreamGenContext::useClearBox() { - if (data.byte(kWithobject) == 255) { - withWhat(); + char id[4] = { 'R', 'A', 'I', 'L' }; // TODO: convert to string with trailing zero + if (defaultUseHandler(id)) return; - } - char id[4] = { 'R', 'A', 'I', 'L' }; // TODO: convert to string with trailing zero - if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) { - // Wrong item - cx = 300; - al = 14; - showPuzText(); - putBackObStuff(); - } else { - // Open box - data.byte(kProgresspoints)++; - showFirstUse(); - data.word(kWatchingtime) = 80; - data.word(kReeltowatch) = 67; - data.word(kEndwatchreel) = 105; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; - } + // Open box + data.byte(kProgresspoints)++; + showFirstUse(); + data.word(kWatchingtime) = 80; + data.word(kReeltowatch) = 67; + data.word(kEndwatchreel) = 105; + data.byte(kWatchspeed) = 1; + data.byte(kSpeedcount) = 1; + data.byte(kGetback) = 1; } void DreamGenContext::openTVDoor() { - if (data.byte(kWithobject) == 255) { - withWhat(); + char id[4] = { 'U', 'L', 'O', 'K' }; // TODO: convert to string with trailing zero + if (defaultUseHandler(id)) return; - } - char id[4] = { 'U', 'L', 'O', 'K' }; // TODO: convert to string with trailing zero - if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) { - // Wrong item - cx = 300; - al = 14; - showPuzText(); - putBackObStuff(); - } else { - // Key on TV - showFirstUse(); - data.byte(kLockstatus) = 0; - data.byte(kGetback) = 1; - } + // Key on TV + showFirstUse(); + data.byte(kLockstatus) = 0; + data.byte(kGetback) = 1; } void DreamGenContext::usePlate() { @@ -885,31 +873,21 @@ void DreamGenContext::usePlinth() { } void DreamGenContext::useElvDoor() { - if (data.byte(kWithobject) == 255) { - withWhat(); + char id[4] = { 'A', 'X', 'E', 'D' }; // TODO: convert to string with trailing zero + if (defaultUseHandler(id)) return; - } - char id[4] = { 'A', 'X', 'E', 'D' }; // TODO: convert to string with trailing zero - if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) { - // Wrong item - cx = 300; - al = 14; - showPuzText(); - putBackObStuff(); - } else { - // Axe on door - al = 15; - cx = 300; - showPuzText(); - _inc(data.byte(kProgresspoints)); - data.word(kWatchingtime) = 46 * 2; - data.word(kReeltowatch) = 31; - data.word(kEndwatchreel) = 77; - data.byte(kWatchspeed) = 1; - data.byte(kSpeedcount) = 1; - data.byte(kGetback) = 1; - } + // Axe on door + al = 15; + cx = 300; + showPuzText(); + _inc(data.byte(kProgresspoints)); + data.word(kWatchingtime) = 46 * 2; + data.word(kReeltowatch) = 31; + data.word(kEndwatchreel) = 77; + data.byte(kWatchspeed) = 1; + data.byte(kSpeedcount) = 1; + data.byte(kGetback) = 1; } void DreamGenContext::useObject() { @@ -957,28 +935,18 @@ void DreamGenContext::useWinch() { } void DreamGenContext::useCart() { - if (data.byte(kWithobject) == 255) { - withWhat(); + char id[4] = { 'R', 'O', 'C', 'K' }; // TODO: convert to string with trailing zero + if (defaultUseHandler(id)) return; - } - char id[4] = { 'R', 'O', 'C', 'K' }; // TODO: convert to string with trailing zero - if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) { - // Wrong item - cx = 300; - al = 14; - showPuzText(); - putBackObStuff(); - } else { - DynObject *exObject = getExAd(data.byte(kWithobject)); - exObject->mapad[0] = 0; - removeSetObject(data.byte(kCommand)); - placeSetObject(data.byte(kCommand) + 1); - data.byte(kProgresspoints)++; - playChannel1(17); - showFirstUse(); - data.byte(kGetback) = 1; - } + DynObject *exObject = getExAd(data.byte(kWithobject)); + exObject->mapad[0] = 0; + removeSetObject(data.byte(kCommand)); + placeSetObject(data.byte(kCommand) + 1); + data.byte(kProgresspoints)++; + playChannel1(17); + showFirstUse(); + data.byte(kGetback) = 1; } void DreamGenContext::useTrainer() { @@ -1003,86 +971,46 @@ void DreamGenContext::chewy() { } void DreamGenContext::useHole() { - if (data.byte(kWithobject) == 255) { - withWhat(); + char id[4] = { 'H', 'N', 'D', 'A' }; // TODO: convert to string with trailing zero + if (defaultUseHandler(id)) return; - } - char id[4] = { 'H', 'N', 'D', 'A' }; // TODO: convert to string with trailing zero - if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) { - // Wrong item - cx = 300; - al = 14; - showPuzText(); - putBackObStuff(); - } else { - showFirstUse(); - removeSetObject(86); - DynObject *exObject = getExAd(data.byte(kWithobject)); - exObject->mapad[0] = 255; - data.byte(kCanmovealtar) = 1; - data.byte(kGetback) = 1; - } + showFirstUse(); + removeSetObject(86); + DynObject *exObject = getExAd(data.byte(kWithobject)); + exObject->mapad[0] = 255; + data.byte(kCanmovealtar) = 1; + data.byte(kGetback) = 1; } void DreamGenContext::openHotelDoor() { - if (data.byte(kWithobject) == 255) { - withWhat(); + char id[4] = { 'K', 'E', 'Y', 'A' }; // TODO: convert to string with trailing zero + if (defaultUseHandler(id)) return; - } - char id[4] = { 'K', 'E', 'Y', 'A' }; // TODO: convert to string with trailing zero - if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) { - // Wrong item - cx = 300; - al = 14; - showPuzText(); - putBackObStuff(); - } else { - playChannel1(16); - showFirstUse(); - data.byte(kLockstatus) = 0; - data.byte(kGetback) = 1; - } + playChannel1(16); + showFirstUse(); + data.byte(kLockstatus) = 0; + data.byte(kGetback) = 1; } void DreamGenContext::openHotelDoor2() { - if (data.byte(kWithobject) == 255) { - withWhat(); + char id[4] = { 'K', 'E', 'Y', 'A' }; // TODO: convert to string with trailing zero + if (defaultUseHandler(id)) return; - } - char id[4] = { 'K', 'E', 'Y', 'A' }; // TODO: convert to string with trailing zero - if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) { - // Wrong item - cx = 300; - al = 14; - showPuzText(); - putBackObStuff(); - } else { - playChannel1(16); - showFirstUse(); - putBackObStuff(); - } + playChannel1(16); + showFirstUse(); + putBackObStuff(); } void DreamGenContext::grafittiDoor() { - if (data.byte(kWithobject) == 255) { - withWhat(); + char id[4] = { 'A', 'P', 'E', 'N' }; // TODO: convert to string with trailing zero + if (defaultUseHandler(id)) return; - } - char id[4] = { 'A', 'P', 'E', 'N' }; // TODO: convert to string with trailing zero - if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) { - // Wrong item - cx = 300; - al = 14; - showPuzText(); - putBackObStuff(); - } else { - showFirstUse(); - putBackObStuff(); - } + showFirstUse(); + putBackObStuff(); } void DreamGenContext::openTomb() { |