Skip to content

Commit

Permalink
MORTEVIELLE: Replace some big if statements by switch statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke committed Aug 21, 2013
1 parent a710bb5 commit 3ef4222
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 45 deletions.
72 changes: 46 additions & 26 deletions engines/mortevielle/actions.cpp
Expand Up @@ -91,31 +91,41 @@ void MortevielleEngine::fctMove() {
oldMenu = (_menu._moveMenu[menuChoice]._menuId << 8) | _menu._moveMenu[menuChoice]._actionId;
}

if (_coreVar._currPlace == MOUNTAIN) {
switch (_coreVar._currPlace) {
case MOUNTAIN:
if (menuChoice == 1)
gotoManorFront();
else if (menuChoice == 2)
checkManorDistance();
_menu.setDestinationText(_coreVar._currPlace);
return;
} else if (_coreVar._currPlace == INSIDE_WELL) {
case INSIDE_WELL:
if (menuChoice == 1)
floodedInWell();
else if (menuChoice == 2)
gotoManorBack();
_menu.setDestinationText(_coreVar._currPlace);
return;
} else if ((_coreVar._currPlace == BUREAU) && (menuChoice == 1))
menuChoice = 6;
else if (_coreVar._currPlace == KITCHEN) {
case BUREAU:
if (menuChoice == 1)
menuChoice = 6;
break;
case KITCHEN:
if (menuChoice == 2)
menuChoice = 6;
else if (menuChoice == 5)
menuChoice = 16;
} else if ((_coreVar._currPlace == CELLAR) && (menuChoice == 3))
menuChoice = 6;
else if (((_coreVar._currPlace == LANDING) || (_coreVar._currPlace == ROOM26)) && (menuChoice == 4))
menuChoice = 6;
break;
case CELLAR:
if (menuChoice == 3)
menuChoice = 6;
break;
case LANDING:
case ROOM26:
if (menuChoice == 4)
menuChoice = 6;
break;
}

if ((_coreVar._currPlace > MOUNTAIN) && (_coreVar._currPlace != ROOM26))
menuChoice += 10;
Expand All @@ -132,32 +142,40 @@ void MortevielleEngine::fctMove() {
else if ((_coreVar._currPlace == WELL) && (menuChoice > 13) && (menuChoice != 17))
menuChoice = 15;

if (menuChoice == 1)
switch (menuChoice) {
case 1:
_coreVar._currPlace = BUREAU;
else if (menuChoice == 2)
break;
case 2:
_coreVar._currPlace = KITCHEN;
else if (menuChoice == 3)
break;
case 3:
_coreVar._currPlace = CELLAR;
else if (menuChoice == 4)
break;
case 4:
_coreVar._currPlace = LANDING;
else if (menuChoice == 5)
menuChoice = 12;
else if (menuChoice == 6)
menuChoice = 11;

if (menuChoice == 11)
gotoDiningRoom();
else if (menuChoice == 12)
break;
case 5:
case 12:
gotoManorFront();
else if (menuChoice == 13)
break;
case 6:
case 11:
gotoDiningRoom();
break;
case 13:
_coreVar._currPlace = CHAPEL;
else if (menuChoice == 14)
break;
case 14:
_coreVar._currPlace = WELL;
else if (menuChoice == 15)
break;
case 15:
checkManorDistance();
else if (menuChoice == 16)
break;
case 16:
gotoManorBack();
else if (menuChoice == 17) {
break;
case 17:
if ((_coreVar._wellObjectId != 120) && (_coreVar._wellObjectId != 140))
_crep = 997;
else if (_coreVar._wellObjectId == 120)
Expand All @@ -169,7 +187,9 @@ void MortevielleEngine::fctMove() {
_coreVar._currPlace = INSIDE_WELL;
prepareDisplayText();
}
break;
}

if ((menuChoice < 5) || (menuChoice == 13) || (menuChoice == 14))
prepareDisplayText();
resetRoomVariables(_coreVar._currPlace);
Expand Down
67 changes: 48 additions & 19 deletions engines/mortevielle/utils.cpp
Expand Up @@ -2498,7 +2498,7 @@ void MortevielleEngine::handleDescriptionText(int f, int mesgId) {
displayTextInDescriptionBar(8, 182, 103, mesgId);
if ((mesgId == 68) || (mesgId == 69))
_coreVar._availableQuestion[40] = '*';
if ((mesgId == 104) && (_caff == CELLAR)) {
else if ((mesgId == 104) && (_caff == CELLAR)) {
_coreVar._availableQuestion[36] = '*';
if (_coreVar._availableQuestion[39] == '*') {
_coreVar._pctHintFound[3] = '*';
Expand Down Expand Up @@ -2775,34 +2775,54 @@ int MortevielleEngine::getPresence(int roomId) {
displayAloneText();
else {
int h = 0;
if (roomId == DINING_ROOM)
switch (roomId) {
case DINING_ROOM:
pres = getPresenceStatsDiningRoom(h);
else if (roomId == BUREAU)
break;
case BUREAU:
pres = getPresenceStatsBureau(h);
else if (roomId == KITCHEN)
break;
case KITCHEN:
pres = getPresenceStatsKitchen();
else if ((roomId == ATTIC) || (roomId == CELLAR))
break;
case ATTIC:
case CELLAR:
pres = getPresenceStatsAttic();
else if ((roomId == LANDING) || (roomId == ROOM26))
break;
case LANDING:
case ROOM26:
pres = getPresenceStatsLanding();
else if (roomId == CHAPEL)
break;
case CHAPEL:
pres = getPresenceStatsChapel(h);
break;
}
pres += _coreVar._faithScore;
rand = getRandomNumber(1, 100);
if (rand > pres) {
displayAloneText();
retVal = 0;
} else {
if (roomId == DINING_ROOM)
switch (roomId) {
case DINING_ROOM:
pres = setPresenceDiningRoom(h);
else if (roomId == BUREAU)
break;
case BUREAU:
pres = setPresenceBureau(h);
else if ((roomId == KITCHEN) || (roomId == ATTIC) || (roomId == CELLAR))
break;
case KITCHEN:
case ATTIC:
case CELLAR:
pres = setPresenceKitchen();
else if ((roomId == LANDING) || (roomId == ROOM26))
break;
case LANDING:
case ROOM26:
pres = setPresenceLanding();
else if (roomId == CHAPEL)
break;
case CHAPEL:
pres = setPresenceChapel(h);
break;
}
retVal = pres;
}
}
Expand Down Expand Up @@ -2866,18 +2886,27 @@ void MortevielleEngine::drawPicture() {
displayAnimFrame(1, _openObjects[i]);
}

if (_caff == ATTIC) {
switch (_caff) {
case ATTIC:
if (_coreVar._atticBallHoleObjectId == 141)
displayAnimFrame(1, 7);

if (_coreVar._atticRodHoleObjectId == 159)
displayAnimFrame(1, 6);
} else if ((_caff == CELLAR) && (_coreVar._cellarObjectId == 151))
displayAnimFrame(1, 2);
else if ((_caff == SECRET_PASSAGE) && (_coreVar._secretPassageObjectId == 143))
displayAnimFrame(1, 1);
else if ((_caff == WELL) && (_coreVar._wellObjectId != 0))
displayAnimFrame(1, 1);
break;
case CELLAR:
if (_coreVar._cellarObjectId == 151)
displayAnimFrame(1, 2);
break;
case SECRET_PASSAGE:
if (_coreVar._secretPassageObjectId == 143)
displayAnimFrame(1, 1);
break;
case WELL:
if (_coreVar._wellObjectId != 0)
displayAnimFrame(1, 1);
break;
}
}

if (_caff < ROOM26)
Expand Down

0 comments on commit 3ef4222

Please sign in to comment.