Skip to content

Commit

Permalink
MORTEVIELLE: Remove remaining macros, start refactoring menus, modify…
Browse files Browse the repository at this point in the history
… the way _cfiphBuffer is read/written
  • Loading branch information
Strangerke committed Jul 28, 2013
1 parent 93fe1c6 commit eb11645
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 128 deletions.
21 changes: 14 additions & 7 deletions engines/mortevielle/actions.cpp
Expand Up @@ -41,13 +41,14 @@ namespace Mortevielle {
* @remarks Originally called 'taller'
*/
void MortevielleEngine::fctMove() {
if ((_coreVar._currPlace == ROOM26) && (_currAction == _menu._moveMenu[6])) {
int oldMenu = (_menu._moveMenu[6]._menuId << 8) | _menu._moveMenu[6]._actionId;
if ((_coreVar._currPlace == ROOM26) && (_currAction == oldMenu)) {
_coreVar._currPlace = LANDING;
_caff = _coreVar._currPlace;
drawPictureWithText();
handleDescriptionText(2, _coreVar._currPlace);
}
if ((_coreVar._currPlace == LANDING) && (_currAction == _menu._moveMenu[6])) {
if ((_coreVar._currPlace == LANDING) && (_currAction == oldMenu)) {
if (!_syn)
displayTextInVerbBar(getEngineString(S_GO_TO));
displayStatusArrow();
Expand Down Expand Up @@ -85,9 +86,11 @@ void MortevielleEngine::fctMove() {
}
exitRoom();
int menuChoice = 1;

while (_menu._moveMenu[menuChoice] != _currAction)
oldMenu = (_menu._moveMenu[menuChoice]._menuId << 8) | _menu._moveMenu[menuChoice]._actionId;
while (oldMenu != _currAction) {
++menuChoice;
oldMenu = (_menu._moveMenu[menuChoice]._menuId << 8) | _menu._moveMenu[menuChoice]._actionId;
}

if (_coreVar._currPlace == MOUNTAIN) {
if (menuChoice == 1)
Expand Down Expand Up @@ -300,9 +303,11 @@ void MortevielleEngine::fctTake() {
*/
void MortevielleEngine::fctInventoryTake() {
int inventIndex = 0;
int oldMenu = 0;
do {
++inventIndex;
} while (_menu._inventoryMenu[inventIndex] != _currAction);
oldMenu = (_menu._inventoryMenu[inventIndex]._menuId << 8) | _menu._inventoryMenu[inventIndex]._actionId;
} while (oldMenu != _currAction);
int cz = 0;
int cy = 0;
do {
Expand Down Expand Up @@ -1154,7 +1159,7 @@ void MortevielleEngine::fctEnter() {
++_coreVar._faithScore;
_coreVar._currPlace = LANDING;
_currMenu = MENU_DISCUSS;
_currAction = _menu._discussMenu[charIndex];
_currAction = (_menu._discussMenu[charIndex]._menuId << 8) | _menu._discussMenu[charIndex]._actionId;
_syn = true;
if (_roomDoorId == ROOM9) {
_col = true;
Expand Down Expand Up @@ -1352,9 +1357,11 @@ void MortevielleEngine::fctDiscuss() {
displId = 128;
else {
cx = 0;
int oldMenu;
do {
++cx;
} while (_menu._discussMenu[cx] != _currAction);
oldMenu = (_menu._discussMenu[cx]._menuId << 8) | _menu._discussMenu[cx]._actionId;
} while (oldMenu != _currAction);
_caff = 69 + cx;
drawPictureWithText();
handleDescriptionText(2, _caff);
Expand Down
2 changes: 1 addition & 1 deletion engines/mortevielle/graphics.cpp
Expand Up @@ -1113,7 +1113,7 @@ void ScreenSurface::drawString(const Common::String &l, int command) {
pt.x += 1;
pt.y += 1;
for (x = 1; (x <= (int)l.size()) && (l[x - 1] != 0); ++x) {
_vm->_screenSurface.writeCharacter(Common::Point(pt.x, pt.y), ord(l[x - 1]), color);
_vm->_screenSurface.writeCharacter(Common::Point(pt.x, pt.y), l[x - 1], color);
pt.x += charWidth;
}
_vm->_mouse.showMouse();
Expand Down
112 changes: 55 additions & 57 deletions engines/mortevielle/menu.cpp
Expand Up @@ -52,32 +52,30 @@ const byte menuConstants[8][4] = {
* Setup a menu's contents
* @remarks Originally called 'menut'
*/
void Menu::setText(int menuId, Common::String name) {
byte h = hi(menuId);
byte l = lo(menuId);
void Menu::setText(int menuId, int actionId, Common::String name) {
Common::String s = name;

while (s.size() < 22)
s += ' ';

switch (h) {
switch (menuId) {
case MENU_INVENTORY:
if (l != 7) {
_inventoryStringArray[l] = s;
_inventoryStringArray[l].insertChar(' ', 0);
if (actionId != 7) {
_inventoryStringArray[actionId] = s;
_inventoryStringArray[actionId].insertChar(' ', 0);
}
break;
case MENU_MOVE:
_moveStringArray[l] = s;
_moveStringArray[actionId] = s;
break;
case MENU_ACTION:
_actionStringArray[l] = s;
_actionStringArray[actionId] = s;
break;
case MENU_SELF:
_selfStringArray[l] = s;
_selfStringArray[actionId] = s;
break;
case MENU_DISCUSS:
_discussStringArray[l] = s;
_discussStringArray[actionId] = s;
break;
default:
break;
Expand All @@ -99,40 +97,38 @@ void Menu::setDestinationText(int roomId) {
nomp = _vm->getString(_vm->_destinationArray[destinationId][roomId] + kMenuPlaceStringIndex);
while (nomp.size() < 20)
nomp += ' ';
setText(_moveMenu[destinationId + 1], nomp);
setText(_moveMenu[destinationId + 1]._menuId, _moveMenu[destinationId + 1]._actionId, nomp);
}
nomp = "* ";
for (int i = 7; i >= destinationId + 1; --i)
setText(_moveMenu[i], nomp);
setText(_moveMenu[i]._menuId, _moveMenu[i]._actionId, nomp);
}

/**
* _disable a menu item
* @param menuId Hi byte represents menu number, lo byte reprsents item index
* @param menuId Menu number
* @param actionId Item index
*/
void Menu::disableMenuItem(int menuId) {
byte h = hi(menuId);
byte l = lo(menuId);

switch (h) {
void Menu::disableMenuItem(int menuId, int actionId) {
switch (menuId) {
case MENU_INVENTORY:
if (l > 6) {
_inventoryStringArray[l].setChar('<', 0);
_inventoryStringArray[l].setChar('>', 21);
if (actionId > 6) {
_inventoryStringArray[actionId].setChar('<', 0);
_inventoryStringArray[actionId].setChar('>', 21);
} else
_inventoryStringArray[l].setChar('*', 0);
_inventoryStringArray[actionId].setChar('*', 0);
break;
case MENU_MOVE:
_moveStringArray[l].setChar('*', 0);
_moveStringArray[actionId].setChar('*', 0);
break;
case MENU_ACTION:
_actionStringArray[l].setChar('*', 0);
_actionStringArray[actionId].setChar('*', 0);
break;
case MENU_SELF:
_selfStringArray[l].setChar('*', 0);
_selfStringArray[actionId].setChar('*', 0);
break;
case MENU_DISCUSS:
_discussStringArray[l].setChar('*', 0);
_discussStringArray[actionId].setChar('*', 0);
break;
default:
break;
Expand All @@ -141,31 +137,29 @@ void Menu::disableMenuItem(int menuId) {

/**
* Enable a menu item
* @param menuId Hi byte represents menu number, lo byte reprsents item index
* @param menuId Menu number
* @param actionId Item index
* @remarks Originally called menu_enable
*/
void Menu::enableMenuItem(int menuId) {
byte h = hi(menuId);
byte l = lo(menuId);

switch (h) {
void Menu::enableMenuItem(int menuId, int actionId) {
switch (menuId) {
case MENU_INVENTORY:
_inventoryStringArray[l].setChar(' ', 0);
_inventoryStringArray[l].setChar(' ', 21);
_inventoryStringArray[actionId].setChar(' ', 0);
_inventoryStringArray[actionId].setChar(' ', 21);
break;
case MENU_MOVE:
_moveStringArray[l].setChar(' ', 0);
_moveStringArray[actionId].setChar(' ', 0);
break;
case MENU_ACTION:
_actionStringArray[l].setChar(' ', 0);
_actionStringArray[actionId].setChar(' ', 0);
break;
case MENU_SELF:
_selfStringArray[l].setChar(' ', 0);
_selfStringArray[actionId].setChar(' ', 0);
// The original sets two times the same value. Skipped
// _selfStringArray[l].setChar(' ', 0);
break;
case MENU_DISCUSS:
_discussStringArray[l].setChar(' ', 0);
_discussStringArray[actionId].setChar(' ', 0);
break;
default:
break;
Expand Down Expand Up @@ -235,7 +229,7 @@ void Menu::invert(int indx) {
if (_msg4 == OPCODE_NONE)
return;

int menuIndex = lo(_msg4);
int menuIndex = _msg4 & 0xFF;

_vm->_screenSurface.putxy(menuConstants[_msg3 - 1][0] << 3, (menuIndex + 1) << 3);

Expand Down Expand Up @@ -471,7 +465,7 @@ void Menu::updateMenu() {
// Another menu to be _displayed
_vm->setMouseClick(false);
menuUp(_msg3);
if (lo(_msg4) == 1)
if ((_msg4 & 0xFF) == 1)
_msg3 = MENU_SAVE;
else
_msg3 = MENU_LOAD;
Expand Down Expand Up @@ -531,12 +525,16 @@ void Menu::initMenu(MortevielleEngine *vm) {
++i;
} while (i != 22);
for (i = 1; i <= 8; ++i) {
_discussMenu[i] = 0x500 + i;
if (i < 8)
_moveMenu[i] = 0x200 + i;
_inventoryMenu[i] = 0x100 + i;
_discussMenu[i]._menuId = MENU_DISCUSS;
_discussMenu[i]._actionId = i;
if (i < 8) {
_moveMenu[i]._menuId = MENU_MOVE;
_moveMenu[i]._actionId = i;
}
_inventoryMenu[i]._menuId = MENU_INVENTORY;
_inventoryMenu[i]._actionId = i;
if (i > 6)
disableMenuItem(_inventoryMenu[i]);
disableMenuItem(_inventoryMenu[i]._menuId, _inventoryMenu[i]._actionId);
}
_msg3 = OPCODE_NONE;
_msg4 = OPCODE_NONE;
Expand All @@ -551,13 +549,13 @@ void Menu::initMenu(MortevielleEngine *vm) {
*/
void Menu::setSearchMenu() {
for (int i = 1; i <= 7; ++i)
disableMenuItem(_moveMenu[i]);
disableMenuItem(MENU_MOVE, _moveMenu[i]._actionId);

for (int i = 1; i <= 11; ++i)
disableMenuItem(_actionMenu[i]);
disableMenuItem(_actionMenu[i]._menuId, _actionMenu[i]._actionId);

setText(OPCODE_SOUND, _vm->getEngineString(S_SUITE));
setText(OPCODE_LIFT, _vm->getEngineString(S_STOP));
setText(OPCODE_SOUND >> 8, OPCODE_SOUND & 0xFF, _vm->getEngineString(S_SUITE));
setText(OPCODE_LIFT >> 8, OPCODE_LIFT & 0xFF, _vm->getEngineString(S_STOP));
}

/**
Expand All @@ -567,10 +565,10 @@ void Menu::setSearchMenu() {
void Menu::unsetSearchMenu() {
setDestinationText(_vm->_coreVar._currPlace);
for (int i = 1; i <= 11; ++i)
enableMenuItem(_actionMenu[i]);
enableMenuItem(_actionMenu[i]._menuId, _actionMenu[i]._actionId);

setText(OPCODE_SOUND, _vm->getEngineString(S_PROBE));
setText(OPCODE_LIFT, _vm->getEngineString(S_RAISE));
setText(OPCODE_SOUND >> 8, OPCODE_SOUND & 0xFF, _vm->getEngineString(S_PROBE));
setText(OPCODE_LIFT >> 8, OPCODE_LIFT & 0xFF, _vm->getEngineString(S_RAISE));
}

/**
Expand All @@ -586,15 +584,15 @@ void Menu::setInventoryText() {
++cy;
int r = _vm->_coreVar._inventory[i] + 400;
nomp = _vm->getString(r - 501 + kInventoryStringIndex);
setText(_inventoryMenu[cy], nomp);
enableMenuItem(_inventoryMenu[i]);
setText(_inventoryMenu[cy]._menuId, _inventoryMenu[cy]._actionId, nomp);
enableMenuItem(_inventoryMenu[i]._menuId, _inventoryMenu[i]._actionId);
}
}

if (cy < 6) {
for (int i = cy + 1; i <= 6; ++i) {
setText(_inventoryMenu[i], " ");
disableMenuItem(_inventoryMenu[i]);
setText(_inventoryMenu[i]._menuId, _inventoryMenu[i]._actionId, " ");
disableMenuItem(_inventoryMenu[i]._menuId, _inventoryMenu[i]._actionId);
}
}
}
Expand Down
39 changes: 33 additions & 6 deletions engines/mortevielle/menu.h
Expand Up @@ -40,6 +40,33 @@ enum {
MENU_LOAD = 8
};

enum verbs {OPCODE_NONE = 0, OPCODE_ATTACH = 0x301, OPCODE_WAIT = 0x302, OPCODE_FORCE = 0x303, OPCODE_SLEEP = 0x304, OPCODE_LISTEN = 0x305,
OPCODE_ENTER = 0x306, OPCODE_CLOSE = 0x307, OPCODE_SEARCH = 0x308, OPCODE_KNOCK = 0x309, OPCODE_SCRATCH = 0x30a,
OPCODE_READ = 0x30b, OPCODE_EAT = 0x30c, OPCODE_PLACE = 0x30d, OPCODE_OPEN = 0x30e, OPCODE_TAKE = 0x30f,
OPCODE_LOOK = 0x310, OPCODE_SMELL = 0x311, OPCODE_SOUND = 0x312, OPCODE_LEAVE = 0x313, OPCODE_LIFT = 0x314,
OPCODE_TURN = 0x315, OPCODE_SHIDE = 0x401, OPCODE_SSEARCH = 0x402, OPCODE_SREAD = 0x403, OPCODE_SPUT = 0x404,
OPCODE_SLOOK = 0x405};

struct menuItem {
int _menuId;
int _actionId;
};

static const menuItem _actionMenu[12] = {
{OPCODE_NONE >> 8, OPCODE_NONE & 0xFF},
{OPCODE_SHIDE >> 8, OPCODE_SHIDE & 0xFF},
{OPCODE_ATTACH >> 8, OPCODE_ATTACH & 0xFF},
{OPCODE_FORCE >> 8, OPCODE_FORCE & 0xFF},
{OPCODE_SLEEP >> 8, OPCODE_SLEEP & 0xFF},
{OPCODE_ENTER >> 8, OPCODE_ENTER & 0xFF},
{OPCODE_CLOSE >> 8, OPCODE_CLOSE & 0xFF},
{OPCODE_KNOCK >> 8, OPCODE_KNOCK & 0xFF},
{OPCODE_EAT >> 8, OPCODE_EAT & 0xFF},
{OPCODE_PLACE >> 8, OPCODE_PLACE & 0xFF},
{OPCODE_OPEN >> 8, OPCODE_OPEN & 0xFF},
{OPCODE_LEAVE >> 8, OPCODE_LEAVE & 0xFF}
};

class Menu {
private:
MortevielleEngine *_vm;
Expand All @@ -61,15 +88,15 @@ class Menu {
Common::String _actionStringArray[22];
Common::String _selfStringArray[7];
Common::String _discussStringArray[9];
int _discussMenu[9];
int _inventoryMenu[9];
int _moveMenu[8];
menuItem _discussMenu[9];
menuItem _inventoryMenu[9];
menuItem _moveMenu[8];

void setText(int menuId, Common::String name);
void setText(int menuId, int actionId, Common::String name);
void setDestinationText(int roomId);
void setInventoryText();
void disableMenuItem(int menuId);
void enableMenuItem(int menuId);
void disableMenuItem(int menuId, int actionId);
void enableMenuItem(int menuId, int actionId);
void displayMenu();
void drawMenu();
void menuUp(int msgId);
Expand Down
20 changes: 0 additions & 20 deletions engines/mortevielle/mortevielle.h
Expand Up @@ -65,12 +65,6 @@ namespace Mortevielle {
*/
const int kAdrMusic = 0x5000;

#define ord(v) ((int) v)
#define chr(v) ((unsigned char) v)
#define lo(v) ((v) & 0xff)
#define hi(v) (((v) >> 8) & 0xff)
#define swap(v) (((lo(v)) << 8) | ((hi(v)) >> 8))

// Debug channels
enum {
kMortevielleCore = 1 << 0,
Expand Down Expand Up @@ -137,20 +131,6 @@ const int kMenuSelfStringIndex = 497;
const int kMenuSayStringIndex = 502;
const int kMaxPatt = 20;

const int OPCODE_NONE = 0;
enum verbs {OPCODE_ATTACH = 0x301, OPCODE_WAIT = 0x302, OPCODE_FORCE = 0x303, OPCODE_SLEEP = 0x304, OPCODE_LISTEN = 0x305,
OPCODE_ENTER = 0x306, OPCODE_CLOSE = 0x307, OPCODE_SEARCH = 0x308, OPCODE_KNOCK = 0x309, OPCODE_SCRATCH = 0x30a,
OPCODE_READ = 0x30b, OPCODE_EAT = 0x30c, OPCODE_PLACE = 0x30d, OPCODE_OPEN = 0x30e, OPCODE_TAKE = 0x30f,
OPCODE_LOOK = 0x310, OPCODE_SMELL = 0x311, OPCODE_SOUND = 0x312, OPCODE_LEAVE = 0x313, OPCODE_LIFT = 0x314,
OPCODE_TURN = 0x315, OPCODE_SHIDE = 0x401, OPCODE_SSEARCH = 0x402, OPCODE_SREAD = 0x403, OPCODE_SPUT = 0x404,
OPCODE_SLOOK = 0x405};

static const int _actionMenu[12] = { OPCODE_NONE,
OPCODE_SHIDE, OPCODE_ATTACH, OPCODE_FORCE, OPCODE_SLEEP,
OPCODE_ENTER, OPCODE_CLOSE, OPCODE_KNOCK, OPCODE_EAT,
OPCODE_PLACE, OPCODE_OPEN, OPCODE_LEAVE
};

/*
9 "A glance at the forbidden$",
18 "It's already open$",
Expand Down

0 comments on commit eb11645

Please sign in to comment.