DREAMWEB: Add a default use handler, thereby reducing code duplication

This commit is contained in:
Filippos Karapetis 2011-12-06 22:24:15 +02:00
parent 44ed4ef0df
commit e4e059b857
2 changed files with 96 additions and 167 deletions

View file

@ -405,6 +405,7 @@
void useElvDoor();
void useObject();
void useWinch();
bool defaultUseHandler(const char *id);
void openTVDoor();
void wearWatch();
void wearShades();

View file

@ -732,20 +732,29 @@ 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 {
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;
@ -759,7 +768,6 @@ void DreamGenContext::useChurchGate() {
if (data.byte(kAidedead) != 0)
turnPathOn(2); // Open church
}
}
void DreamGenContext::useFullCart() {
data.byte(kProgresspoints)++;
@ -780,19 +788,10 @@ void DreamGenContext::useFullCart() {
}
void DreamGenContext::useClearBox() {
if (data.byte(kWithobject) == 255) {
withWhat();
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 {
if (defaultUseHandler(id))
return;
// Open box
data.byte(kProgresspoints)++;
showFirstUse();
@ -803,28 +802,17 @@ void DreamGenContext::useClearBox() {
data.byte(kSpeedcount) = 1;
data.byte(kGetback) = 1;
}
}
void DreamGenContext::openTVDoor() {
if (data.byte(kWithobject) == 255) {
withWhat();
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 {
if (defaultUseHandler(id))
return;
// Key on TV
showFirstUse();
data.byte(kLockstatus) = 0;
data.byte(kGetback) = 1;
}
}
void DreamGenContext::usePlate() {
if (data.byte(kWithobject) == 255) {
@ -885,19 +873,10 @@ void DreamGenContext::usePlinth() {
}
void DreamGenContext::useElvDoor() {
if (data.byte(kWithobject) == 255) {
withWhat();
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 {
if (defaultUseHandler(id))
return;
// Axe on door
al = 15;
cx = 300;
@ -910,7 +889,6 @@ void DreamGenContext::useElvDoor() {
data.byte(kSpeedcount) = 1;
data.byte(kGetback) = 1;
}
}
void DreamGenContext::useObject() {
data.byte(kWithobject) = 255;
@ -957,19 +935,10 @@ void DreamGenContext::useWinch() {
}
void DreamGenContext::useCart() {
if (data.byte(kWithobject) == 255) {
withWhat();
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 {
if (defaultUseHandler(id))
return;
DynObject *exObject = getExAd(data.byte(kWithobject));
exObject->mapad[0] = 0;
removeSetObject(data.byte(kCommand));
@ -979,7 +948,6 @@ void DreamGenContext::useCart() {
showFirstUse();
data.byte(kGetback) = 1;
}
}
void DreamGenContext::useTrainer() {
// TODO: Use the C++ version of getAnyAd()
@ -1003,19 +971,10 @@ void DreamGenContext::chewy() {
}
void DreamGenContext::useHole() {
if (data.byte(kWithobject) == 255) {
withWhat();
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 {
if (defaultUseHandler(id))
return;
showFirstUse();
removeSetObject(86);
DynObject *exObject = getExAd(data.byte(kWithobject));
@ -1023,67 +982,36 @@ void DreamGenContext::useHole() {
data.byte(kCanmovealtar) = 1;
data.byte(kGetback) = 1;
}
}
void DreamGenContext::openHotelDoor() {
if (data.byte(kWithobject) == 255) {
withWhat();
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 {
if (defaultUseHandler(id))
return;
playChannel1(16);
showFirstUse();
data.byte(kLockstatus) = 0;
data.byte(kGetback) = 1;
}
}
void DreamGenContext::openHotelDoor2() {
if (data.byte(kWithobject) == 255) {
withWhat();
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 {
if (defaultUseHandler(id))
return;
playChannel1(16);
showFirstUse();
putBackObStuff();
}
}
void DreamGenContext::grafittiDoor() {
if (data.byte(kWithobject) == 255) {
withWhat();
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 {
if (defaultUseHandler(id))
return;
showFirstUse();
putBackObStuff();
}
}
void DreamGenContext::openTomb() {
data.byte(kProgresspoints)++;