LAB: Move inventory to LabEngine class

This commit is contained in:
Eugene Sandulenko 2015-12-03 19:49:55 +01:00 committed by Willem Jan Palenstijn
parent 58e16e2cd7
commit c320e6d0ae
8 changed files with 40 additions and 39 deletions

View file

@ -45,7 +45,6 @@ extern bool stopsound, DoNotDrawMessage;
/* Global parser data */ /* Global parser data */
extern RoomData *_rooms; extern RoomData *_rooms;
extern InventoryData *Inventory;
extern uint16 NumInv, ManyRooms, HighestCondition, Direction; extern uint16 NumInv, ManyRooms, HighestCondition, Direction;
bool ispal = false, noupdatediff = false, MainDisplay = true, QuitLab = false; bool ispal = false, noupdatediff = false, MainDisplay = true, QuitLab = false;
@ -159,14 +158,14 @@ void LabEngine::drawRoomMessage(uint16 curInv, CloseDataPtr closePtr) {
} }
if (_alternate) { if (_alternate) {
if ((curInv <= NumInv) && _conditions->in(curInv) && Inventory[curInv].BInvName) { if ((curInv <= NumInv) && _conditions->in(curInv) && _inventory[curInv].BInvName) {
if ((curInv == LAMPNUM) && _conditions->in(LAMPON)) /* LAB: Labyrinth specific */ if ((curInv == LAMPNUM) && _conditions->in(LAMPON)) /* LAB: Labyrinth specific */
drawStaticMessage(kTextLampOn); drawStaticMessage(kTextLampOn);
else if (Inventory[curInv].Many > 1) { else if (_inventory[curInv].Many > 1) {
Common::String roomMessage = Common::String(Inventory[curInv].name) + " (" + Common::String::format("%d", Inventory[curInv].Many) + ")"; Common::String roomMessage = Common::String(_inventory[curInv].name) + " (" + Common::String::format("%d", _inventory[curInv].Many) + ")";
drawMessage(roomMessage.c_str()); drawMessage(roomMessage.c_str());
} else } else
drawMessage(Inventory[curInv].name); drawMessage(_inventory[curInv].name);
} }
} else } else
drawDirection(closePtr); drawDirection(closePtr);
@ -390,7 +389,7 @@ bool LabEngine::doCloseUp(CloseDataPtr closePtr) {
/******************************************************************************/ /******************************************************************************/
const char *LabEngine::getInvName(uint16 CurInv) { const char *LabEngine::getInvName(uint16 CurInv) {
if (MainDisplay) if (MainDisplay)
return Inventory[CurInv].BInvName; return _inventory[CurInv].BInvName;
if ((CurInv == LAMPNUM) && _conditions->in(LAMPON)) if ((CurInv == LAMPNUM) && _conditions->in(LAMPON))
return "P:Mines/120"; return "P:Mines/120";
@ -399,20 +398,20 @@ const char *LabEngine::getInvName(uint16 CurInv) {
return "P:Future/BeltGlow"; return "P:Future/BeltGlow";
if (CurInv == WESTPAPERNUM) { if (CurInv == WESTPAPERNUM) {
g_lab->_curFileName = Inventory[CurInv].BInvName; g_lab->_curFileName = _inventory[CurInv].BInvName;
g_lab->_anim->_noPalChange = true; g_lab->_anim->_noPalChange = true;
readPict(g_lab->_curFileName, false); readPict(g_lab->_curFileName, false);
g_lab->_anim->_noPalChange = false; g_lab->_anim->_noPalChange = false;
doWestPaper(); doWestPaper();
} else if (CurInv == NOTESNUM) { } else if (CurInv == NOTESNUM) {
g_lab->_curFileName = Inventory[CurInv].BInvName; g_lab->_curFileName = _inventory[CurInv].BInvName;
g_lab->_anim->_noPalChange = true; g_lab->_anim->_noPalChange = true;
readPict(g_lab->_curFileName, false); readPict(g_lab->_curFileName, false);
g_lab->_anim->_noPalChange = false; g_lab->_anim->_noPalChange = false;
doNotes(); doNotes();
} }
return Inventory[CurInv].BInvName; return _inventory[CurInv].BInvName;
} }
/******************************************************************************/ /******************************************************************************/
@ -517,7 +516,7 @@ void LabEngine::decIncInv(uint16 *CurInv, bool dec) {
(*CurInv)++; (*CurInv)++;
while (*CurInv && (*CurInv <= NumInv)) { while (*CurInv && (*CurInv <= NumInv)) {
if (_conditions->in(*CurInv) && Inventory[*CurInv].BInvName) { if (_conditions->in(*CurInv) && _inventory[*CurInv].BInvName) {
_nextFileName = getInvName(*CurInv); _nextFileName = getInvName(*CurInv);
break; break;
} }
@ -535,7 +534,7 @@ void LabEngine::decIncInv(uint16 *CurInv, bool dec) {
*CurInv = 1; *CurInv = 1;
while (*CurInv && (*CurInv <= NumInv)) { while (*CurInv && (*CurInv <= NumInv)) {
if (_conditions->in(*CurInv) && Inventory[*CurInv].BInvName) { if (_conditions->in(*CurInv) && _inventory[*CurInv].BInvName) {
_nextFileName = getInvName(*CurInv); _nextFileName = getInvName(*CurInv);
break; break;
} }
@ -565,7 +564,8 @@ void LabEngine::mainGameLoop() {
Direction = NORTH; Direction = NORTH;
_resource->readRoomData("LAB:Doors"); _resource->readRoomData("LAB:Doors");
_resource->readInventory("LAB:Inventor"); if (!(_inventory = _resource->readInventory("LAB:Inventor")))
return;
if (!(_conditions = new LargeSet(HighestCondition + 1, this))) if (!(_conditions = new LargeSet(HighestCondition + 1, this)))
return; return;
@ -698,16 +698,16 @@ void LabEngine::mainGameLoop() {
_rooms = nullptr; _rooms = nullptr;
} }
if (Inventory) { if (_inventory) {
for (int i = 1; i <= NumInv; i++) { for (int i = 1; i <= NumInv; i++) {
if (Inventory[i].name) if (_inventory[i].name)
free(Inventory[i].name); free(_inventory[i].name);
if (Inventory[i].BInvName) if (_inventory[i].BInvName)
free(Inventory[i].BInvName); free(_inventory[i].BInvName);
} }
free(Inventory); free(_inventory);
} }
} }
@ -1041,7 +1041,7 @@ bool LabEngine::from_crumbs(uint32 tmpClass, uint16 code, uint16 Qualifier, Comm
} }
if ((curInv <= NumInv) && _conditions->in(curInv) && if ((curInv <= NumInv) && _conditions->in(curInv) &&
Inventory[curInv].BInvName) _inventory[curInv].BInvName)
_nextFileName = getInvName(curInv); _nextFileName = getInvName(curInv);
screenUpdate(); screenUpdate();

View file

@ -112,6 +112,8 @@ LabEngine::LabEngine(OSystem *syst, const ADGameDescription *gameDesc)
_longWinInFront = false; _longWinInFront = false;
_msgFont = 0; _msgFont = 0;
_inventory = 0;
//const Common::FSNode gameDataDir(ConfMan.get("path")); //const Common::FSNode gameDataDir(ConfMan.get("path"));
//SearchMan.addSubDirectoryMatching(gameDataDir, "game"); //SearchMan.addSubDirectoryMatching(gameDataDir, "game");
//SearchMan.addSubDirectoryMatching(gameDataDir, "game/pict"); //SearchMan.addSubDirectoryMatching(gameDataDir, "game/pict");

View file

@ -125,7 +125,6 @@ public:
const char *_newFileName; /* When ProcessRoom.c decides to change the filename const char *_newFileName; /* When ProcessRoom.c decides to change the filename
of the current picture. */ of the current picture. */
private: private:
int _lastWaitTOFTicks; int _lastWaitTOFTicks;
bool _lastMessageLong; bool _lastMessageLong;
@ -133,6 +132,7 @@ private:
TextFont *_msgFont; TextFont *_msgFont;
bool _longWinInFront; bool _longWinInFront;
CloseDataPtr _cptr; CloseDataPtr _cptr;
InventoryData *_inventory;
private: private:
bool createScreen(bool HiRes); bool createScreen(bool HiRes);
@ -194,6 +194,8 @@ private:
void mayShowCrumbIndicatorOff(); void mayShowCrumbIndicatorOff();
const char *getInvName(uint16 curInv); const char *getInvName(uint16 curInv);
bool saveRestoreGame();
public: public:
void doActions(Action *aPtr, CloseDataPtr *lcptr); void doActions(Action *aPtr, CloseDataPtr *lcptr);

View file

@ -193,7 +193,6 @@ void doJournal();
void doNotes(); void doNotes();
void doWestPaper(); void doWestPaper();
void doMonitor(char *background, char *textfile, bool isinteractive, uint16 x1, uint16 y1, uint16 x2, uint16 y2); void doMonitor(char *background, char *textfile, bool isinteractive, uint16 x1, uint16 y1, uint16 x2, uint16 y2);
bool saveRestoreGame();
/*--------------------------*/ /*--------------------------*/
/*----- From saveGame.c ----*/ /*----- From saveGame.c ----*/

View file

@ -45,7 +45,6 @@ namespace Lab {
#define NOFILE "no file" #define NOFILE "no file"
RoomData *_rooms; RoomData *_rooms;
InventoryData *Inventory;
uint16 NumInv, ManyRooms, HighestCondition, Direction; uint16 NumInv, ManyRooms, HighestCondition, Direction;
extern bool DoNotDrawMessage, noupdatediff, QuitLab, MusicOn; extern bool DoNotDrawMessage, noupdatediff, QuitLab, MusicOn;
@ -434,16 +433,16 @@ void LabEngine::doActions(Action *aptr, CloseDataPtr *lcptr) {
break; break;
case SUBINV: case SUBINV:
if (Inventory[aptr->Param1].Many) if (_inventory[aptr->Param1].Many)
(Inventory[aptr->Param1].Many)--; (_inventory[aptr->Param1].Many)--;
if (Inventory[aptr->Param1].Many == 0) if (_inventory[aptr->Param1].Many == 0)
_conditions->exclElement(aptr->Param1); _conditions->exclElement(aptr->Param1);
break; break;
case ADDINV: case ADDINV:
(Inventory[aptr->Param1].Many) += aptr->Param2; (_inventory[aptr->Param1].Many) += aptr->Param2;
_conditions->inclElement(aptr->Param1); _conditions->inclElement(aptr->Param1);
break; break;

View file

@ -36,7 +36,6 @@ namespace Lab {
static uint16 allocroom; static uint16 allocroom;
extern RoomData *_rooms; extern RoomData *_rooms;
extern InventoryData *Inventory;
extern uint16 NumInv, ManyRooms, HighestCondition; extern uint16 NumInv, ManyRooms, HighestCondition;
Resource::Resource(LabEngine *vm) : _vm(vm) { Resource::Resource(LabEngine *vm) : _vm(vm) {
@ -127,22 +126,23 @@ bool Resource::readRoomData(const char *fileName) {
return true; return true;
} }
bool Resource::readInventory(const char *fileName) { InventoryData *Resource::readInventory(const char *fileName) {
Common::File *dataFile; Common::File *dataFile;
if (!(dataFile = openDataFile(fileName, MKTAG('I', 'N', 'V', '1')))) if (!(dataFile = openDataFile(fileName, MKTAG('I', 'N', 'V', '1'))))
return false; return nullptr;
NumInv = dataFile->readUint16LE(); NumInv = dataFile->readUint16LE();
Inventory = (InventoryData *)malloc((NumInv + 1) * sizeof(InventoryData)); InventoryData *inventory = (InventoryData *)malloc((NumInv + 1) * sizeof(InventoryData));
for (uint16 i = 1; i <= NumInv; i++) { for (uint16 i = 1; i <= NumInv; i++) {
Inventory[i].Many = dataFile->readUint16LE(); inventory[i].Many = dataFile->readUint16LE();
Inventory[i].name = readString(dataFile); inventory[i].name = readString(dataFile);
Inventory[i].BInvName = readString(dataFile); inventory[i].BInvName = readString(dataFile);
} }
delete dataFile; delete dataFile;
return true;
return inventory;
} }
bool Resource::readViews(uint16 roomNum) { bool Resource::readViews(uint16 roomNum) {

View file

@ -100,7 +100,7 @@ public:
Common::File *openDataFile(const char * fileName, uint32 fileHeader = 0); Common::File *openDataFile(const char * fileName, uint32 fileHeader = 0);
bool readRoomData(const char *fileName); bool readRoomData(const char *fileName);
bool readInventory(const char *fileName); InventoryData *readInventory(const char *fileName);
bool readViews(uint16 roomNum); bool readViews(uint16 roomNum);
TextFont *getFont(const char *fileName); TextFont *getFont(const char *fileName);
char *getText(const char *fileName); char *getText(const char *fileName);

View file

@ -83,7 +83,6 @@ uint16 CurTile[4][4] = {
extern uint16 *FadePalette; extern uint16 *FadePalette;
extern BitMap *DispBitMap, *DrawBitMap; extern BitMap *DispBitMap, *DrawBitMap;
extern InventoryData *Inventory;
extern uint16 Direction; extern uint16 Direction;
#define COMBINATIONUNLOCKED 130 #define COMBINATIONUNLOCKED 130
@ -753,7 +752,7 @@ void LabEngine::doJournal() {
freeAllStolenMem(); freeAllStolenMem();
} }
bool saveRestoreGame() { bool LabEngine::saveRestoreGame() {
bool isOK = false; bool isOK = false;
//g_lab->showMainMenu(); //g_lab->showMainMenu();
@ -775,14 +774,14 @@ bool saveRestoreGame() {
desc = dialog->createDefaultSaveDescription(slot); desc = dialog->createDefaultSaveDescription(slot);
} }
isOK = saveGame(Direction, Inventory[QUARTERNUM].Many, slot, desc); isOK = saveGame(Direction, _inventory[QUARTERNUM].Many, slot, desc);
} }
} else { } else {
// Restore // Restore
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false); GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
int slot = dialog->runModalWithCurrentTarget(); int slot = dialog->runModalWithCurrentTarget();
if (slot >= 0) { if (slot >= 0) {
isOK = loadGame(&Direction, &(Inventory[QUARTERNUM].Many), slot); isOK = loadGame(&Direction, &(_inventory[QUARTERNUM].Many), slot);
if (isOK) if (isOK)
g_lab->_music->resetMusic(); g_lab->_music->resetMusic();
} }