aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorWalter van Niftrik2016-03-06 16:43:30 +0100
committerWalter van Niftrik2016-03-09 10:03:13 +0100
commit0ec3ab142244cbaf24f0f6c97a931d0d073d4f97 (patch)
tree5e18782be888e2dd2a91b942009f3edaebb57d8a /engines
parenta73dcdf224ae88c7bcf73d754781052835af4cd0 (diff)
downloadscummvm-rg350-0ec3ab142244cbaf24f0f6c97a931d0d073d4f97.tar.gz
scummvm-rg350-0ec3ab142244cbaf24f0f6c97a931d0d073d4f97.tar.bz2
scummvm-rg350-0ec3ab142244cbaf24f0f6c97a931d0d073d4f97.zip
ADL: Fix const'ness
Diffstat (limited to 'engines')
-rw-r--r--engines/adl/adl.cpp87
-rw-r--r--engines/adl/adl.h117
-rw-r--r--engines/adl/hires1.cpp8
-rw-r--r--engines/adl/hires1.h8
4 files changed, 129 insertions, 91 deletions
diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp
index 701f902ade..e0c0b3afae 100644
--- a/engines/adl/adl.cpp
+++ b/engines/adl/adl.cpp
@@ -137,7 +137,7 @@ Common::Error AdlEngine::run() {
return Common::kNoError;
}
-Common::String AdlEngine::readString(Common::ReadStream &stream, byte until) {
+Common::String AdlEngine::readString(Common::ReadStream &stream, byte until) const {
Common::String str;
while (1) {
@@ -155,7 +155,7 @@ Common::String AdlEngine::readString(Common::ReadStream &stream, byte until) {
return str;
}
-void AdlEngine::printStrings(Common::SeekableReadStream &stream, int count) {
+void AdlEngine::printStrings(Common::SeekableReadStream &stream, int count) const {
while (1) {
Common::String str = readString(stream);
_display->printString(str);
@@ -167,11 +167,11 @@ void AdlEngine::printStrings(Common::SeekableReadStream &stream, int count) {
};
}
-Common::String AdlEngine::getEngineString(int str) {
+Common::String AdlEngine::getEngineString(int str) const {
return _strings[str];
}
-void AdlEngine::wordWrap(Common::String &str) {
+void AdlEngine::wordWrap(Common::String &str) const {
uint end = 39;
while (1) {
@@ -186,7 +186,7 @@ void AdlEngine::wordWrap(Common::String &str) {
}
}
-void AdlEngine::printMessage(uint idx, bool wait) {
+void AdlEngine::printMessage(uint idx, bool wait) const {
Common::String msg = _messages[idx - 1];
wordWrap(msg);
_display->printString(msg);
@@ -195,7 +195,7 @@ void AdlEngine::printMessage(uint idx, bool wait) {
delay(14 * 166018 / 1000);
}
-void AdlEngine::printEngineMessage(EngineMessage msg) {
+void AdlEngine::printEngineMessage(EngineMessage msg) const {
printMessage(getEngineMessage(msg));
}
@@ -423,7 +423,7 @@ void AdlEngine::doActions(const Command &command, byte noun, byte offset) {
}
}
-bool AdlEngine::matchCommand(const Command &command, byte verb, byte noun, bool run) {
+bool AdlEngine::matchCommand(const Command &command, byte verb, byte noun, uint *actions) const {
if (command.room != IDI_NONE && command.room != _state.room)
return false;
@@ -466,8 +466,7 @@ bool AdlEngine::matchCommand(const Command &command, byte verb, byte noun, bool
}
}
- if (run)
- doActions(command, noun, offset);
+ *actions = offset;
return true;
}
@@ -477,9 +476,13 @@ bool AdlEngine::matchCommand(const Command &command, byte verb, byte noun, bool
bool AdlEngine::doOneCommand(const Commands &commands, byte verb, byte noun) {
Commands::const_iterator cmd;
- for (cmd = commands.begin(); cmd != commands.end(); ++cmd)
- if (matchCommand(*cmd, verb, noun))
+ for (cmd = commands.begin(); cmd != commands.end(); ++cmd) {
+ uint offset = 0;
+ if (matchCommand(*cmd, verb, noun, &offset)) {
+ doActions(*cmd, noun, offset);
return true;
+ }
+ }
return false;
}
@@ -489,7 +492,9 @@ void AdlEngine::doAllCommands(const Commands &commands, byte verb, byte noun) {
bool oldIsRestoring = _isRestoring;
for (cmd = commands.begin(); cmd != commands.end(); ++cmd) {
- matchCommand(*cmd, verb, noun);
+ uint offset = 0;
+ if (matchCommand(*cmd, verb, noun, &offset))
+ doActions(*cmd, noun, offset);
// We assume no restarts happen in this command group. This
// simplifies enabling GMM savegame loading on the restart
@@ -499,7 +504,7 @@ void AdlEngine::doAllCommands(const Commands &commands, byte verb, byte noun) {
}
}
-bool AdlEngine::canSaveGameStateCurrently() {
+bool AdlEngine::canSaveGameStateCurrently() const {
if (!_canSaveNow)
return false;
@@ -509,7 +514,7 @@ bool AdlEngine::canSaveGameStateCurrently() {
// "SAVE GAME". This prevents saving via the GMM in situations where
// it wouldn't otherwise be possible to do so.
for (cmd = _roomCommands.begin(); cmd != _roomCommands.end(); ++cmd) {
- if (matchCommand(*cmd, _saveVerb, _saveNoun, false)) {
+ if (matchCommand(*cmd, _saveVerb, _saveNoun)) {
if (cmd->verb != _saveVerb || cmd->noun != _saveNoun)
return false;
return cmd->numCond == 0 && cmd->script[0] == IDO_ACT_SAVE;
@@ -519,16 +524,16 @@ bool AdlEngine::canSaveGameStateCurrently() {
return false;
}
-bool AdlEngine::canLoadGameStateCurrently() {
+bool AdlEngine::canLoadGameStateCurrently() const {
return _canRestoreNow;
}
-void AdlEngine::clearScreen() {
+void AdlEngine::clearScreen() const {
_display->setMode(DISPLAY_MODE_MIXED);
_display->clear(0x00);
}
-void AdlEngine::drawItems() {
+void AdlEngine::drawItems() const {
Common::Array<Item>::const_iterator item;
uint dropped = 0;
@@ -563,7 +568,7 @@ void AdlEngine::drawItems() {
}
}
-void AdlEngine::showRoom() {
+void AdlEngine::showRoom() const {
if (!_state.isDark) {
drawPic(curRoom().curPicture);
drawItems();
@@ -722,6 +727,13 @@ Common::Error AdlEngine::loadGameState(int slot) {
return Common::kNoError;
}
+const Room &AdlEngine::room(uint i) const {
+ if (i < 1 || i > _state.rooms.size())
+ error("Room %i out of range [1, %i]", i, _state.rooms.size());
+
+ return _state.rooms[i - 1];
+}
+
Room &AdlEngine::room(uint i) {
if (i < 1 || i > _state.rooms.size())
error("Room %i out of range [1, %i]", i, _state.rooms.size());
@@ -729,10 +741,21 @@ Room &AdlEngine::room(uint i) {
return _state.rooms[i - 1];
}
+const Room &AdlEngine::curRoom() const {
+ return room(_state.room);
+}
+
Room &AdlEngine::curRoom() {
return room(_state.room);
}
+const Item &AdlEngine::item(uint i) const {
+ if (i < 1 || i > _state.items.size())
+ error("Item %i out of range [1, %i]", i, _state.items.size());
+
+ return _state.items[i - 1];
+}
+
Item &AdlEngine::item(uint i) {
if (i < 1 || i > _state.items.size())
error("Item %i out of range [1, %i]", i, _state.items.size());
@@ -740,6 +763,13 @@ Item &AdlEngine::item(uint i) {
return _state.items[i - 1];
}
+const byte &AdlEngine::var(uint i) const {
+ if (i >= _state.vars.size())
+ error("Variable %i out of range [0, %i]", i, _state.vars.size() - 1);
+
+ return _state.vars[i];
+}
+
byte &AdlEngine::var(uint i) {
if (i >= _state.vars.size())
error("Variable %i out of range [0, %i]", i, _state.vars.size() - 1);
@@ -783,7 +813,7 @@ void AdlEngine::loadWords(Common::ReadStream &stream, WordMap &map) {
}
}
-Common::String AdlEngine::getLine() {
+Common::String AdlEngine::getLine() const {
// Original engine uses a global here, which isn't reset between
// calls and may not match actual mode
bool textMode = false;
@@ -806,7 +836,7 @@ Common::String AdlEngine::getLine() {
}
}
-Common::String AdlEngine::getWord(const Common::String &line, uint &index) {
+Common::String AdlEngine::getWord(const Common::String &line, uint &index) const {
Common::String str;
for (uint i = 0; i < 8; ++i)
@@ -873,7 +903,7 @@ void AdlEngine::getInput(uint &verb, uint &noun) {
}
}
-void AdlEngine::printASCIIString(const Common::String &str) {
+void AdlEngine::printASCIIString(const Common::String &str) const {
Common::String aStr;
Common::String::const_iterator it;
@@ -883,7 +913,7 @@ void AdlEngine::printASCIIString(const Common::String &str) {
_display->printString(aStr);
}
-Common::String AdlEngine::inputString(byte prompt) {
+Common::String AdlEngine::inputString(byte prompt) const {
Common::String s;
if (prompt > 0)
@@ -921,7 +951,7 @@ Common::String AdlEngine::inputString(byte prompt) {
}
}
-byte AdlEngine::convertKey(uint16 ascii) {
+byte AdlEngine::convertKey(uint16 ascii) const {
ascii = toupper(ascii);
if (ascii >= 0x80)
@@ -935,7 +965,7 @@ byte AdlEngine::convertKey(uint16 ascii) {
return 0;
}
-byte AdlEngine::inputKey() {
+byte AdlEngine::inputKey() const {
Common::EventManager *ev = g_system->getEventManager();
byte key = 0;
@@ -974,7 +1004,7 @@ byte AdlEngine::inputKey() {
return key;
}
-void AdlEngine::delay(uint32 ms) {
+void AdlEngine::delay(uint32 ms) const {
Common::EventManager *ev = g_system->getEventManager();
uint32 start = g_system->getMillis();
@@ -996,10 +1026,9 @@ void AdlEngine::delay(uint32 ms) {
}
}
-void AdlEngine::drawNextPixel(Common::Point &p, byte color, byte bits, byte quadrant) {
- if (bits & 4) {
+void AdlEngine::drawNextPixel(Common::Point &p, byte color, byte bits, byte quadrant) const {
+ if (bits & 4)
_display->putPixel(p, color);
- }
bits += quadrant;
@@ -1009,7 +1038,7 @@ void AdlEngine::drawNextPixel(Common::Point &p, byte color, byte bits, byte quad
p.y += (bits & 2 ? 1 : -1);
}
-void AdlEngine::drawLineArt(const Common::Array<byte> &lineArt, Common::Point p, byte rotation, byte scaling, byte color) {
+void AdlEngine::drawLineArt(const Common::Array<byte> &lineArt, Common::Point p, byte rotation, byte scaling, byte color) const {
const byte stepping[] = {
0xff, 0xfe, 0xfa, 0xf4, 0xec, 0xe1, 0xd4, 0xc5,
0xb4, 0xa1, 0x8d, 0x78, 0x61, 0x49, 0x31, 0x18,
diff --git a/engines/adl/adl.h b/engines/adl/adl.h
index 66a539547b..5afcb0f64d 100644
--- a/engines/adl/adl.h
+++ b/engines/adl/adl.h
@@ -161,71 +161,30 @@ struct State {
};
typedef Common::List<Command> Commands;
+typedef Common::HashMap<Common::String, uint> WordMap;
class AdlEngine : public Engine {
public:
- AdlEngine(OSystem *syst, const AdlGameDescription *gd);
virtual ~AdlEngine();
- const AdlGameDescription *_gameDescription;
- bool hasFeature(EngineFeature f) const;
- const char *getGameId() const;
-
static AdlEngine *create(GameType type, OSystem *syst, const AdlGameDescription *gd);
- Common::Error run();
- virtual Common::String getEngineString(int str);
-
protected:
- typedef Common::HashMap<Common::String, uint> WordMap;
+ AdlEngine(OSystem *syst, const AdlGameDescription *gd);
- virtual void runIntro() { }
- virtual void loadData() = 0;
- void runGame();
- virtual void initState() = 0;
- virtual void restartGame() = 0;
- virtual uint getEngineMessage(EngineMessage msg) = 0;
- bool canSaveGameStateCurrently();
- bool canLoadGameStateCurrently();
- Common::String readString(Common::ReadStream &stream, byte until = 0);
- void printStrings(Common::SeekableReadStream &stream, int count = 1);
- virtual void printMessage(uint idx, bool wait = true);
- void wordWrap(Common::String &str);
- void readCommands(Common::ReadStream &stream, Commands &commands);
- bool matchCommand(const Command &command, byte verb, byte noun, bool run = true);
- bool doOneCommand(const Commands &commands, byte verb, byte noun);
- void doAllCommands(const Commands &commands, byte verb, byte noun);
- void doActions(const Command &command, byte noun, byte offset);
- void clearScreen();
- virtual void drawPic(byte pic, Common::Point pos = Common::Point()) = 0;
- void drawItems();
- void drawNextPixel(Common::Point &p, byte color, byte bits, byte quadrant);
- void drawLineArt(const Common::Array<byte> &lineArt, Common::Point p, byte rotation = 0, byte scaling = 1, byte color = 0x7f);
- void showRoom();
- void takeItem(byte noun);
- void dropItem(byte noun);
- Room &room(uint i);
- Room &curRoom();
- Item &item(uint i);
- byte &var(uint i);
+ Common::String readString(Common::ReadStream &stream, byte until = 0) const;
+ void printStrings(Common::SeekableReadStream &stream, int count = 1) const;
+ void printMessage(uint idx, bool wait = true) const;
+ void printASCIIString(const Common::String &str) const;
void loadVerbs(Common::ReadStream &stream) { loadWords(stream, _verbs); }
void loadNouns(Common::ReadStream &stream) { loadWords(stream, _nouns); }
- void getInput(uint &verb, uint &noun);
- void loadWords(Common::ReadStream &stream, WordMap &map);
- Common::String getLine();
- Common::String getWord(const Common::String &line, uint &index);
- void printASCIIString(const Common::String &str);
- Common::String inputString(byte prompt = 0);
- void delay(uint32 ms);
- byte inputKey();
- Common::Error loadGameState(int slot);
- Common::Error saveGameState(int slot, const Common::String &desc);
+ void readCommands(Common::ReadStream &stream, Commands &commands);
+ Common::String inputString(byte prompt = 0) const;
+ void delay(uint32 ms) const;
+ byte inputKey() const;
Display *_display;
Parser *_parser;
- bool _isRestarting, _isRestoring;
- byte _saveVerb, _saveNoun, _restoreVerb, _restoreNoun;
- bool _canSaveNow, _canRestoreNow;
Common::Array<Common::String> _strings;
Common::Array<Common::String> _messages;
@@ -239,14 +198,64 @@ protected:
State _state;
private:
- void printEngineMessage(EngineMessage);
- Common::String getTargetName() { return _targetName; }
- byte convertKey(uint16 ascii);
+ virtual void runIntro() { }
+ virtual void loadData() = 0;
+ virtual void initState() = 0;
+ virtual void restartGame() = 0;
+ virtual uint getEngineMessage(EngineMessage msg) const = 0;
+ virtual void drawPic(byte pic, Common::Point pos = Common::Point()) const = 0;
+
+ // Engine
+ Common::Error run();
+ bool hasFeature(EngineFeature f) const;
+ Common::Error loadGameState(int slot);
+ bool canLoadGameStateCurrently() const;
+ Common::Error saveGameState(int slot, const Common::String &desc);
+ bool canSaveGameStateCurrently() const;
+
+ // Text output
+ Common::String getEngineString(int str) const;
+ void printEngineMessage(EngineMessage) const;
+ void wordWrap(Common::String &str) const;
+
+ // Text input
+ void loadWords(Common::ReadStream &stream, WordMap &map);
+ byte convertKey(uint16 ascii) const;
+ Common::String getLine() const;
+ Common::String getWord(const Common::String &line, uint &index) const;
+ void getInput(uint &verb, uint &noun);
+
+ // Graphics
+ void showRoom() const;
+ void clearScreen() const;
+ void drawItems() const;
+ void drawNextPixel(Common::Point &p, byte color, byte bits, byte quadrant) const;
+ void drawLineArt(const Common::Array<byte> &lineArt, Common::Point p, byte rotation = 0, byte scaling = 1, byte color = 0x7f) const;
+
+ // Game state functions
+ const Room &room(uint i) const;
+ Room &room(uint i);
+ const Room &curRoom() const;
+ Room &curRoom();
+ const Item &item(uint i) const;
+ Item &item(uint i);
+ const byte &var(uint i) const;
+ byte &var(uint i);
+ void takeItem(byte noun);
+ void dropItem(byte noun);
+ bool matchCommand(const Command &command, byte verb, byte noun, uint *actions = nullptr) const;
+ bool doOneCommand(const Commands &commands, byte verb, byte noun);
+ void doAllCommands(const Commands &commands, byte verb, byte noun);
+ void doActions(const Command &command, byte noun, byte offset);
enum {
kWordSize = 8
};
+ const AdlGameDescription *_gameDescription;
+ bool _isRestarting, _isRestoring;
+ byte _saveVerb, _saveNoun, _restoreVerb, _restoreNoun;
+ bool _canSaveNow, _canRestoreNow;
WordMap _verbs;
WordMap _nouns;
};
diff --git a/engines/adl/hires1.cpp b/engines/adl/hires1.cpp
index 11d576b217..c7b62c144f 100644
--- a/engines/adl/hires1.cpp
+++ b/engines/adl/hires1.cpp
@@ -205,7 +205,7 @@ void HiRes1Engine::runIntro() {
delay(2000);
}
-void HiRes1Engine::drawPic(Common::ReadStream &stream, const Common::Point &pos) {
+void HiRes1Engine::drawPic(Common::ReadStream &stream, const Common::Point &pos) const {
byte x, y;
bool bNewLine = false;
byte oldX = 0, oldY = 0;
@@ -242,7 +242,7 @@ void HiRes1Engine::drawPic(Common::ReadStream &stream, const Common::Point &pos)
}
}
-void HiRes1Engine::drawPic(byte pic, Common::Point pos) {
+void HiRes1Engine::drawPic(byte pic, Common::Point pos) const {
Common::File f;
Common::String name = Common::String::format("BLOCK%i", _pictures[pic].block);
@@ -406,7 +406,7 @@ void HiRes1Engine::printMessage(uint idx, bool wait) {
AdlEngine::printMessage(idx, wait);
}
-uint HiRes1Engine::getEngineMessage(EngineMessage msg) {
+uint HiRes1Engine::getEngineMessage(EngineMessage msg) const {
switch (msg) {
case IDI_MSG_CANT_GO_THERE:
return IDI_HR1_MSG_CANT_GO_THERE;
@@ -423,7 +423,7 @@ uint HiRes1Engine::getEngineMessage(EngineMessage msg) {
}
}
-void HiRes1Engine::drawLine(const Common::Point &p1, const Common::Point &p2, byte color) {
+void HiRes1Engine::drawLine(const Common::Point &p1, const Common::Point &p2, byte color) const {
// This draws a four-connected line
int16 deltaX = p2.x - p1.x;
diff --git a/engines/adl/hires1.h b/engines/adl/hires1.h
index f72093a92a..7446e10394 100644
--- a/engines/adl/hires1.h
+++ b/engines/adl/hires1.h
@@ -39,15 +39,15 @@ public:
private:
void restartGame();
void printMessage(uint idx, bool wait = true);
- uint getEngineMessage(EngineMessage msg);
+ uint getEngineMessage(EngineMessage msg) const;
void initState();
void runIntro();
void loadData();
- void drawPic(Common::ReadStream &stream, const Common::Point &pos);
+ void drawPic(Common::ReadStream &stream, const Common::Point &pos) const;
void drawItems();
- void drawLine(const Common::Point &p1, const Common::Point &p2, byte color);
- void drawPic(byte pic, Common::Point pos);
+ void drawLine(const Common::Point &p1, const Common::Point &p2, byte color) const;
+ void drawPic(byte pic, Common::Point pos) const;
};
} // End of namespace Adl