aboutsummaryrefslogtreecommitdiff
path: root/engines/startrek
diff options
context:
space:
mode:
authorFilippos Karapetis2019-08-16 14:14:51 +0300
committerFilippos Karapetis2019-08-16 14:16:43 +0300
commit878675cbd0487b2064abdd452006fdcfb8d6896d (patch)
treed40e7acbdb63a720afba267d50806d735f525f11 /engines/startrek
parent2b6d58cbb202a01c99bc0d6c2318802591ac7492 (diff)
downloadscummvm-rg350-878675cbd0487b2064abdd452006fdcfb8d6896d.tar.gz
scummvm-rg350-878675cbd0487b2064abdd452006fdcfb8d6896d.tar.bz2
scummvm-rg350-878675cbd0487b2064abdd452006fdcfb8d6896d.zip
STARTREK: Simplify screen name code and add the "actions" debug command
- The screen name and map name code have been merged and simplified - Some usage of SharedPtr has been adapted - Duplicate code for loading the room map has been merged - The "actions" command has been imported from the tools code - Cleanup
Diffstat (limited to 'engines/startrek')
-rw-r--r--engines/startrek/awaymission.cpp20
-rw-r--r--engines/startrek/console.cpp186
-rw-r--r--engines/startrek/console.h4
-rw-r--r--engines/startrek/menu.cpp4
-rw-r--r--engines/startrek/room.cpp9
-rw-r--r--engines/startrek/room.h4
-rw-r--r--engines/startrek/rooms/demon4.cpp4
-rw-r--r--engines/startrek/rooms/demon6.cpp4
-rw-r--r--engines/startrek/saveload.cpp3
-rw-r--r--engines/startrek/startrek.cpp1
-rw-r--r--engines/startrek/startrek.h13
-rw-r--r--engines/startrek/textbox.cpp2
12 files changed, 223 insertions, 31 deletions
diff --git a/engines/startrek/awaymission.cpp b/engines/startrek/awaymission.cpp
index ca1b3f0c79..84985c3925 100644
--- a/engines/startrek/awaymission.cpp
+++ b/engines/startrek/awaymission.cpp
@@ -85,22 +85,18 @@ void StarTrekEngine::loadRoom(const Common::String &missionName, int roomIndex)
_gfx->fadeoutScreen();
_sound->stopAllVocSounds();
- _screenName = _missionName + (char)(_roomIndex + '0');
-
- _gfx->setBackgroundImage(_gfx->loadBitmap(_screenName));
- _gfx->loadPri(_screenName);
+ _gfx->setBackgroundImage(_gfx->loadBitmap(getScreenName()));
+ _gfx->loadPri(getScreenName());
_gfx->loadPalette("palette");
_gfx->copyBackgroundScreen();
- _room = SharedPtr<Room>(new Room(this, _screenName));
+ _room = new Room(this, getScreenName());
// Original sets up bytes 0-3 of rdf file as "remote function caller"
- // Load map file
+ _room->loadMapFile(getScreenName());
+
_awayMission.activeAction = ACTION_WALK;
- _mapFilename = _screenName;
- _mapFile = loadFile(_mapFilename + ".map");
- _iwFile = SharedPtr<IWFile>(new IWFile(this, _mapFilename + ".iw"));
actorFunc1();
initActors();
@@ -467,8 +463,10 @@ void StarTrekEngine::unloadRoom() {
_gfx->fadeoutScreen();
// sub_2394b(); // TODO
actorFunc1();
- _room.reset();
+ delete _room;
+ _room = nullptr;
delete _mapFile;
+ _mapFile = nullptr;
}
int StarTrekEngine::loadActorAnimWithRoomScaling(int actorIndex, const Common::String &animName, int16 x, int16 y) {
@@ -489,7 +487,7 @@ Fixed8 StarTrekEngine::getActorScaleAtPosition(int16 y) {
return Fixed8(_playerActorScale * (y - minY)) + minScale;
}
-SharedPtr<Room> StarTrekEngine::getRoom() {
+Room *StarTrekEngine::getRoom() {
return _room;
}
diff --git a/engines/startrek/console.cpp b/engines/startrek/console.cpp
index 5e6108efa6..816b5ce742 100644
--- a/engines/startrek/console.cpp
+++ b/engines/startrek/console.cpp
@@ -22,12 +22,14 @@
#include "startrek/console.h"
#include "gui/debugger.h"
+#include "startrek/room.h"
#include "startrek/startrek.h"
namespace StarTrek {
Console::Console(StarTrekEngine *vm) : GUI::Debugger(), _vm(vm) {
registerCmd("room", WRAP_METHOD(Console, Cmd_Room));
+ registerCmd("actions", WRAP_METHOD(Console, Cmd_Actions));
}
Console::~Console() {
@@ -35,9 +37,9 @@ Console::~Console() {
bool Console::Cmd_Room(int argc, const char **argv) {
if (argc < 3) {
- debugPrintf("Current room: %s%d\n", _vm->_missionToLoad.c_str(), _vm->_roomIndexToLoad);
+ debugPrintf("Current room: %s\n", _vm->getScreenName().c_str());
debugPrintf("Use room <mission> <room> to teleport\n");
- debugPrintf("Valid missions are: DEMON, TUG, LOVE, MUDD, FEATHER, TRIAL, SINS, VENG");
+ debugPrintf("Valid missions are: DEMON, TUG, LOVE, MUDD, FEATHER, TRIAL, SINS, VENG\n");
return true;
}
@@ -48,4 +50,184 @@ bool Console::Cmd_Room(int argc, const char **argv) {
return false;
}
+bool Console::Cmd_Actions(int argc, const char **argv) {
+ Common::String screenName = _vm->getScreenName();
+
+ if (argc == 3) {
+ Common::String missionName = argv[1];
+ int roomIndex = atoi(argv[2]);
+
+ screenName = missionName + (char)(roomIndex + '0');
+ }
+
+ Common::MemoryReadStreamEndian *rdfFile = _vm->loadFile(screenName + ".RDF");
+ rdfFile->seek(14);
+
+ uint16 startOffset = rdfFile->readUint16LE();
+ uint16 endOffset = rdfFile->readUint16LE();
+ uint16 offset = startOffset;
+
+ while (offset < endOffset) {
+ rdfFile->seek(offset);
+
+ uint32 action = rdfFile->readUint32LE();
+ uint16 nextOffset = rdfFile->readUint16LE();
+
+ debugPrintf("Offset %d: %s\n", offset, EventToString(action).c_str());
+ offset = nextOffset;
+ }
+
+ delete rdfFile;
+
+ return true;
+}
+
+Common::String Console::EventToString(uint32 action) {
+ const char *actions[] = {
+ "Tick",
+ "Walk",
+ "Use",
+ "Get",
+ "Look",
+ "Talk"
+ };
+
+ byte verb = action & 0xff;
+ byte subject = (action >> 8) & 0xff;
+ byte b2 = (action >> 16) & 0xff;
+ byte b3 = (action >> 24) & 0xff;
+
+ String retString;
+ switch (verb) {
+ case 0: // Tick
+ retString = Common::String::format("Tick %d", (subject | (b2 << 8)));
+ break;
+ case 2: // Use
+ retString = Common::String(actions[verb]) + " " + ItemToString(subject) + ", " + ItemToString(b2);
+ break;
+ case 1: // Walk
+ case 3: // Get
+ case 4: // Look
+ case 5: // Talk
+ retString = Common::String(actions[verb]) + " " + ItemToString(subject);
+ break;
+ case 6: // Warp touched
+ retString = Common::String::format("Touched warp %d", subject);
+ break;
+ case 7: // Hotspot touched
+ retString = Common::String::format("Touched hotspot %d", subject);
+ break;
+ case 8: // Timer expired
+ retString = Common::String::format("Timer %d expired", subject);
+ break;
+ case 10: // Animation finished
+ retString = Common::String::format("Finished animation (%d)", subject);
+ break;
+ case 12: // Walking finished
+ retString = Common::String::format("Finished walking (%d)", subject);
+ break;
+ default:
+ retString = Common::String::format("%x%x%x%x", verb, subject, b2, b3);
+ break;
+ }
+
+ // Check for actions using bytes they're not expected to use
+ if (b3 != 0)
+ debugPrintf("WARNING: b3 nonzero in action: %s\n", retString.c_str());
+ if (b2 != 0 && verb != 0 && verb != 2)
+ debugPrintf("WARNING: b2 nonzero in action: %s\n", retString.c_str());
+
+ return retString;
+}
+
+const char *itemNames[] = {
+ "IPHASERS",
+ "IPHASERK",
+ "IHAND",
+ "IROCK",
+ "ISTRICOR",
+ "IMTRICOR",
+ "IDEADGUY",
+ "ICOMM",
+ "IPBC",
+ "IRLG",
+ "IWRENCH",
+ "IINSULAT",
+ "ISAMPLE",
+ "ICURE",
+ "IDISHES",
+ "IRT",
+ "IRTWB",
+ "ICOMBBIT",
+ "IJNKMETL",
+ "IWIRING",
+ "IWIRSCRP",
+ "IPWF",
+ "IPWE",
+ "IDEADPH",
+ "IBOMB",
+ "IMETAL",
+ "ISKULL",
+ "IMINERAL",
+ "IMETEOR",
+ "ISHELLS",
+ "IDEGRIME",
+ "ILENSES",
+ "IDISKS",
+ "IANTIGRA",
+ "IN2GAS",
+ "IO2GAS",
+ "IH2GAS",
+ "IN2O",
+ "INH3",
+ "IH2O",
+ "IWROD",
+ "IIROD",
+ "IREDGEM_A",
+ "IREDGEM_B",
+ "IREDGEM_C",
+ "IGRNGEM_A",
+ "IGRNGEM_B",
+ "IGRNGEM_C",
+ "IBLUGEM_A",
+ "IBLUGEM_B",
+ "IBLUGEM_C",
+ "ICONECT",
+ "IS8ROCKS",
+ "IIDCARD",
+ "ISNAKE",
+ "IFERN",
+ "ICRYSTAL",
+ "IKNIFE",
+ "IDETOXIN",
+ "IBERRY",
+ "IDOOVER",
+ "IALIENDV",
+ "ICAPSULE",
+ "IMEDKIT",
+ "IBEAM",
+ "IDRILL",
+ "IHYPO",
+ "IFUSION",
+ "ICABLE1",
+ "ICABLE2",
+ "ILMD",
+ "IDECK",
+ "ITECH"
+};
+
+Common::String Console::ItemToString(byte index) {
+ if (index == 0)
+ return "KIRK";
+ else if (index == 1)
+ return "SPOCK";
+ else if (index == 2)
+ return "MCCOY";
+ else if (index == 3)
+ return "REDSHIRT";
+ else if (index >= 0x40 && (index - 0x40) < ARRAYSIZE(itemNames))
+ return itemNames[index - 0x40];
+ return Common::String(Common::String::format("0x%02x:", index)); // TODO
+}
+
} // End of namespace StarTrek
diff --git a/engines/startrek/console.h b/engines/startrek/console.h
index 1d1b6e72fc..8a920ef4db 100644
--- a/engines/startrek/console.h
+++ b/engines/startrek/console.h
@@ -38,6 +38,10 @@ private:
StarTrekEngine *_vm;
bool Cmd_Room(int argc, const char **argv);
+ bool Cmd_Actions(int argc, const char **argv);
+
+ Common::String EventToString(uint32 action);
+ Common::String ItemToString(byte index);
};
} // End of namespace StarTrek
diff --git a/engines/startrek/menu.cpp b/engines/startrek/menu.cpp
index 85503e3534..039bddfab9 100644
--- a/engines/startrek/menu.cpp
+++ b/engines/startrek/menu.cpp
@@ -1167,8 +1167,8 @@ lclick:
someSprite.bitmap.reset();
_gfx->popSprites();
- _gfx->loadPri(_screenName);
- _gfx->setBackgroundImage(_gfx->loadBitmap(_screenName));
+ _gfx->loadPri(getScreenName());
+ _gfx->setBackgroundImage(_gfx->loadBitmap(getScreenName()));
_gfx->copyBackgroundScreen();
_system->updateScreen();
_system->delayMillis(10);
diff --git a/engines/startrek/room.cpp b/engines/startrek/room.cpp
index 976d9f4b0a..567cbe558f 100644
--- a/engines/startrek/room.cpp
+++ b/engines/startrek/room.cpp
@@ -136,7 +136,8 @@ void Room::loadRoomMessages() {
while (*text != '#')
text++;
- loadRoomMessage(text);
+ if (text[5] == '\\')
+ loadRoomMessage(text);
while (*text != '\0')
text++;
@@ -509,11 +510,11 @@ void Room::walkCrewmanC(int actorIndex, int16 destX, int16 destY, void (Room::*f
}
void Room::loadMapFile(const Common::String &name) {
- _vm->_mapFilename = name;
- _vm->_iwFile.reset();
delete _vm->_mapFile;
- _vm->_iwFile = SharedPtr<IWFile>(new IWFile(_vm, name + ".iw"));
_vm->_mapFile = _vm->loadFile(name + ".map");
+
+ _vm->_iwFile.reset();
+ _vm->_iwFile = SharedPtr<IWFile>(new IWFile(_vm, name + ".iw"));
}
void Room::showBitmapFor5Ticks(const Common::String &bmpName, int priority) {
diff --git a/engines/startrek/room.h b/engines/startrek/room.h
index 16e994d56e..54db694951 100644
--- a/engines/startrek/room.h
+++ b/engines/startrek/room.h
@@ -212,10 +212,14 @@ private:
*/
void walkCrewman(int actorIndex, int16 destX, int16 destY, uint16 finishedAnimActionParam = 0);
void walkCrewmanC(int actorIndex, int16 destX, int16 destY, void (Room::*funcPtr)()); // Cmd 0x08
+
+public:
/**
* Cmd 0x09: Loads a pair of .map and .iw files to change the room's collisions and pathfinding.
*/
void loadMapFile(const Common::String &name);
+
+private:
/**
* Cmd 0x0a
*/
diff --git a/engines/startrek/rooms/demon4.cpp b/engines/startrek/rooms/demon4.cpp
index 515946bc0d..848500d06c 100644
--- a/engines/startrek/rooms/demon4.cpp
+++ b/engines/startrek/rooms/demon4.cpp
@@ -527,8 +527,8 @@ done:
_vm->_gfx->fadeoutScreen();
_vm->_gfx->popSprites();
- _vm->_gfx->loadPri(_vm->_screenName);
- _vm->_gfx->setBackgroundImage(_vm->_gfx->loadBitmap(_vm->_screenName));
+ _vm->_gfx->loadPri(_vm->getScreenName());
+ _vm->_gfx->setBackgroundImage(_vm->_gfx->loadBitmap(_vm->getScreenName()));
_vm->_gfx->copyBackgroundScreen();
_vm->_gfx->forceDrawAllSprites();
diff --git a/engines/startrek/rooms/demon6.cpp b/engines/startrek/rooms/demon6.cpp
index 1f6cfd6b5b..379c26fbe5 100644
--- a/engines/startrek/rooms/demon6.cpp
+++ b/engines/startrek/rooms/demon6.cpp
@@ -488,8 +488,8 @@ int Room::demon6ShowCase(int visible) {
_vm->_gfx->fadeoutScreen();
_vm->_gfx->popSprites();
- _vm->_gfx->loadPri(_vm->_screenName);
- _vm->_gfx->setBackgroundImage(_vm->_gfx->loadBitmap(_vm->_screenName));
+ _vm->_gfx->loadPri(_vm->getScreenName());
+ _vm->_gfx->setBackgroundImage(_vm->_gfx->loadBitmap(_vm->getScreenName()));
_vm->_gfx->copyBackgroundScreen();
_vm->_gfx->forceDrawAllSprites();
diff --git a/engines/startrek/saveload.cpp b/engines/startrek/saveload.cpp
index 7c4516ec0b..126551b111 100644
--- a/engines/startrek/saveload.cpp
+++ b/engines/startrek/saveload.cpp
@@ -305,7 +305,8 @@ bool StarTrekEngine::saveOrLoadGameData(Common::SeekableReadStream *in, Common::
ser.syncAsUint16LE(a->fielda6);
}
- ser.syncString(_mapFilename);
+ Common::String unused = getScreenName();
+ ser.syncString(unused);
// Away mission struct
for (int i = 0; i < 8; i++)
diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp
index 123fc74cf5..2e4a5a0a88 100644
--- a/engines/startrek/startrek.cpp
+++ b/engines/startrek/startrek.cpp
@@ -70,6 +70,7 @@ StarTrekEngine::StarTrekEngine(OSystem *syst, const StarTrekGameDescription *gam
_activeMenu = nullptr;
_sound = nullptr;
_macResFork = nullptr;
+ _room = nullptr;
memset(_actionOnWalkCompletionInUse, 0, sizeof(_actionOnWalkCompletionInUse));
diff --git a/engines/startrek/startrek.h b/engines/startrek/startrek.h
index 5f4dc61801..3e27e002af 100644
--- a/engines/startrek/startrek.h
+++ b/engines/startrek/startrek.h
@@ -322,7 +322,7 @@ public:
bool isPositionSolid(int16 x, int16 y);
void loadRoomIndex(int roomIndex, int spawnIndex);
- SharedPtr<Room> getRoom();
+ Room *getRoom();
// intro.cpp
private:
@@ -673,7 +673,11 @@ public:
Common::Platform getPlatform() const;
uint8 getGameType() const;
Common::Language getLanguage() const;
-
+
+ // _screenName = _missionName + _roomIndex
+ Common::String getScreenName() const {
+ return _missionName + (char)(_roomIndex + '0');
+ }
// Variables
public:
@@ -690,8 +694,6 @@ public:
Common::String _missionName;
int _roomIndex;
- Common::String _screenName; // _screenName = _missionName + _roomIndex
- Common::String _mapFilename; // Similar to _screenName, but used for .map files?
Common::MemoryReadStreamEndian *_mapFile;
Fixed16 _playerActorScale;
@@ -782,9 +784,8 @@ public:
private:
Common::RandomSource _randomSource;
Common::SineTable _sineTable;
-
+ Room *_room;
Common::MacResManager *_macResFork;
- SharedPtr<Room> _room;
};
// Static function
diff --git a/engines/startrek/textbox.cpp b/engines/startrek/textbox.cpp
index a503c42a81..33f2f235cf 100644
--- a/engines/startrek/textbox.cpp
+++ b/engines/startrek/textbox.cpp
@@ -159,7 +159,7 @@ void StarTrekEngine::getTextboxHeader(String *headerTextOutput, String speakerTe
}
String StarTrekEngine::readTextFromRdf(int choiceIndex, uintptr data, String *headerTextOutput) {
- SharedPtr<Room> room = getRoom();
+ Room *room = getRoom();
int rdfVar = (size_t)data;