Skip to content

Commit

Permalink
AGI: Cleanup some Winnie string code
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Hoops committed Jul 3, 2011
1 parent c2be473 commit b4f4fd6
Showing 1 changed file with 31 additions and 35 deletions.
66 changes: 31 additions & 35 deletions engines/agi/preagi_winnie.cpp
Expand Up @@ -86,20 +86,20 @@ void Winnie::parseObjHeader(WTP_OBJ_HDR *objHdr, byte *buffer, int len) {
}

uint32 Winnie::readRoom(int iRoom, uint8 *buffer, WTP_ROOM_HDR &roomHdr) {
char szFile[256] = {0};
Common::String fileName;

if (_vm->getPlatform() == Common::kPlatformPC)
sprintf(szFile, IDS_WTP_ROOM_DOS, iRoom);
fileName = Common::String::format(IDS_WTP_ROOM_DOS, iRoom);
else if (_vm->getPlatform() == Common::kPlatformAmiga)
sprintf(szFile, IDS_WTP_ROOM_AMIGA, iRoom);
fileName = Common::String::format(IDS_WTP_ROOM_AMIGA, iRoom);
else if (_vm->getPlatform() == Common::kPlatformC64)
sprintf(szFile, IDS_WTP_ROOM_C64, iRoom);
fileName = Common::String::format(IDS_WTP_ROOM_C64, iRoom);
else if (_vm->getPlatform() == Common::kPlatformApple2GS)
sprintf(szFile, IDS_WTP_ROOM_APPLE, iRoom);
fileName = Common::String::format(IDS_WTP_ROOM_APPLE, iRoom);

Common::File file;
if (!file.open(szFile)) {
warning ("Could not open file \'%s\'", szFile);
if (!file.open(fileName)) {
warning("Could not open file \'%s\'", fileName.c_str());
return 0;
}

Expand All @@ -119,20 +119,20 @@ uint32 Winnie::readRoom(int iRoom, uint8 *buffer, WTP_ROOM_HDR &roomHdr) {
}

uint32 Winnie::readObj(int iObj, uint8 *buffer) {
char szFile[256] = {0};
Common::String fileName;

if (_vm->getPlatform() == Common::kPlatformPC)
sprintf(szFile, IDS_WTP_OBJ_DOS, iObj);
fileName = Common::String::format(IDS_WTP_OBJ_DOS, iObj);
else if (_vm->getPlatform() == Common::kPlatformAmiga)
sprintf(szFile, IDS_WTP_OBJ_AMIGA, iObj);
fileName = Common::String::format(IDS_WTP_OBJ_AMIGA, iObj);
else if (_vm->getPlatform() == Common::kPlatformC64)
sprintf(szFile, IDS_WTP_OBJ_C64, iObj);
fileName = Common::String::format(IDS_WTP_OBJ_C64, iObj);
else if (_vm->getPlatform() == Common::kPlatformApple2GS)
sprintf(szFile, IDS_WTP_OBJ_APPLE, iObj);
fileName = Common::String::format(IDS_WTP_OBJ_APPLE, iObj);

Common::File file;
if (!file.open(szFile)) {
warning ("Could not open file \'%s\'", szFile);
if (!file.open(fileName)) {
warning ("Could not open file \'%s\'", fileName.c_str());
return 0;
}

Expand Down Expand Up @@ -468,17 +468,16 @@ void Winnie::keyHelp() {
}

void Winnie::inventory() {
char szMissing[41] = {0};

if (_game.iObjHave)
printObjStr(_game.iObjHave, IDI_WTP_OBJ_TAKE);
else {
_vm->clearTextArea();
_vm->drawStr(IDI_WTP_ROW_MENU, IDI_WTP_COL_MENU, IDA_DEFAULT, IDS_WTP_INVENTORY_0);
}

sprintf(szMissing, IDS_WTP_INVENTORY_1, _game.nObjMiss);
_vm->drawStr(IDI_WTP_ROW_OPTION_4, IDI_WTP_COL_MENU, IDA_DEFAULT, szMissing);
Common::String missing = Common::String::format(IDS_WTP_INVENTORY_1, _game.nObjMiss);

_vm->drawStr(IDI_WTP_ROW_OPTION_4, IDI_WTP_COL_MENU, IDA_DEFAULT, missing.c_str());
_vm->_gfx->doUpdate();
_vm->_system->updateScreen(); //TODO: Move to game's main loop
_vm->getSelection(kSelAnyKey);
Expand Down Expand Up @@ -1049,16 +1048,15 @@ void Winnie::gameLoop() {
}

void Winnie::drawPic(const char *szName) {
char szFile[256] = {0};
Common::File file;
Common::String fileName = szName;

// construct filename
if (_vm->getPlatform() != Common::kPlatformAmiga)
sprintf(szFile, "%s.pic", szName);
else
strcpy(szFile, szName);
if (!file.open(szFile)) {
warning ("Could not open file \'%s\'", szFile);
fileName += ".pic";

Common::File file;

if (!file.open(fileName)) {
warning ("Could not open file \'%s\'", fileName.c_str());
return;
}

Expand Down Expand Up @@ -1149,12 +1147,11 @@ void Winnie::gameOver() {
}

void Winnie::saveGame() {
Common::OutSaveFile* outfile;
char szFile[256] = {0};
int i = 0;

sprintf(szFile, IDS_WTP_FILE_SAVEGAME);
if (!(outfile = _vm->getSaveFileMan()->openForSaving(szFile)))
Common::OutSaveFile *outfile = _vm->getSaveFileMan()->openForSaving(IDS_WTP_FILE_SAVEGAME);

if (!outfile)
return;

outfile->writeUint32BE(MKTAG('W','I','N','N')); // header
Expand All @@ -1178,19 +1175,18 @@ void Winnie::saveGame() {
outfile->finalize();

if (outfile->err())
warning("Can't write file '%s'. (Disk full?)", szFile);
warning("Can't write file '%s'. (Disk full?)", IDS_WTP_FILE_SAVEGAME);

delete outfile;
}

void Winnie::loadGame() {
Common::InSaveFile* infile;
char szFile[256] = {0};
int saveVersion = 0;
int i = 0;

sprintf(szFile, IDS_WTP_FILE_SAVEGAME);
if (!(infile = _vm->getSaveFileMan()->openForLoading(szFile)))
Common::InSaveFile *infile = _vm->getSaveFileMan()->openForLoading(IDS_WTP_FILE_SAVEGAME);

if (!infile)
return;

if (infile->readUint32BE() == MKTAG('W','I','N','N')) {
Expand Down

0 comments on commit b4f4fd6

Please sign in to comment.