SHERLOCK: Refactored Chess class to be Map class

This commit is contained in:
Paul Gilbert 2015-04-15 08:22:40 -05:00
parent a830d77325
commit 17bf9e7f54
11 changed files with 69 additions and 51 deletions

View file

@ -20,26 +20,27 @@
* *
*/ */
#ifndef SHERLOCK_CHESS_H #include "sherlock/map.h"
#define SHERLOCK_CHESS_H
namespace Sherlock { namespace Sherlock {
namespace Scalpel { Map::Map(SherlockEngine *vm): _vm(vm) {
}
class ScalpelEngine; /**
* Loads the list of points for locations on the map for each scene
*/
void Map::loadPoints(int count, const int *xList, const int *yList) {
for (int idx = 0; idx < count; ++idx, ++xList, ++yList) {
_points.push_back(Common::Point(*xList, *yList));
}
}
class Chess { /**
private: * Show the map
ScalpelEngine *_vm; */
public: int Map::show() {
Chess(ScalpelEngine *vm) : _vm(vm) {} return 0;
}
int doChessBoard();
};
} // End of namespace Scalpel
} // End of namespace Sherlock } // End of namespace Sherlock
#endif

View file

@ -20,18 +20,33 @@
* *
*/ */
#include "sherlock/scalpel/chess.h" #ifndef SHERLOCK_MAP_H
#include "sherlock/scalpel/scalpel.h" #define SHERLOCK_MAP_H
#include "common/scummsys.h"
#include "common/array.h"
#include "common/rect.h"
#include "common/str.h"
namespace Sherlock { namespace Sherlock {
namespace Scalpel { class SherlockEngine;
int Chess::doChessBoard() { class Map {
// TODO private:
return 0; SherlockEngine *_vm;
} Common::Array<Common::Point> _points; // Map locations for each scene
public:
public:
Map(SherlockEngine *vm);
} // End of namespace Scalpel const Common::Point &operator[](int idx) { return _points[idx]; }
} // End of namespace Scalpel void loadPoints(int count, const int *xList, const int *yList);
int show();
};
} // End of namespace Sherlock
#endif

View file

@ -1,7 +1,6 @@
MODULE := engines/sherlock MODULE := engines/sherlock
MODULE_OBJS = \ MODULE_OBJS = \
scalpel/chess.o \
scalpel/darts.o \ scalpel/darts.o \
scalpel/scalpel.o \ scalpel/scalpel.o \
tattoo/tattoo.o \ tattoo/tattoo.o \
@ -13,6 +12,7 @@ MODULE_OBJS = \
graphics.o \ graphics.o \
inventory.o \ inventory.o \
journal.o \ journal.o \
map.o \
objects.o \ objects.o \
people.o \ people.o \
resources.o \ resources.o \

View file

@ -801,6 +801,7 @@ void Object::setObjSequence(int seq, bool wait) {
* @returns 0 if no codes are found, 1 if codes were found * @returns 0 if no codes are found, 1 if codes were found
*/ */
int Object::checkNameForCodes(const Common::String &name, const char *const messages[]) { int Object::checkNameForCodes(const Common::String &name, const char *const messages[]) {
Map &map = *_vm->_map;
People &people = *_vm->_people; People &people = *_vm->_people;
Scene &scene = *_vm->_scene; Scene &scene = *_vm->_scene;
Screen &screen = *_vm->_screen; Screen &screen = *_vm->_screen;
@ -847,9 +848,9 @@ int Object::checkNameForCodes(const Common::String &name, const char *const mess
if (ch >= '0' && ch <= '9') { if (ch >= '0' && ch <= '9') {
scene._goToScene = atoi(name.c_str() + 1); scene._goToScene = atoi(name.c_str() + 1);
if (scene._goToScene < 97 && _vm->_map[scene._goToScene].x) { if (scene._goToScene < 97 && map[scene._goToScene].x) {
_vm->_over.x = _vm->_map[scene._goToScene].x * 100 - 600; _vm->_over.x = map[scene._goToScene].x * 100 - 600;
_vm->_over.y = _vm->_map[scene._goToScene].y * 100 + 900; _vm->_over.y = map[scene._goToScene].y * 100 + 900;
} }
if ((p = strchr(name.c_str(), ',')) != nullptr) { if ((p = strchr(name.c_str(), ',')) != nullptr) {

View file

@ -415,6 +415,7 @@ void People::setWalking() {
* is being displayed, then the chraracter will always face down. * is being displayed, then the chraracter will always face down.
*/ */
void People::gotoStand(Sprite &sprite) { void People::gotoStand(Sprite &sprite) {
Map &map = *_vm->_map;
Scene &scene = *_vm->_scene; Scene &scene = *_vm->_scene;
_walkTo.clear(); _walkTo.clear();
sprite._walkCount = 0; sprite._walkCount = 0;
@ -448,8 +449,8 @@ void People::gotoStand(Sprite &sprite) {
if (_vm->_onChessboard) { if (_vm->_onChessboard) {
sprite._sequenceNumber = 0; sprite._sequenceNumber = 0;
_data[AL]._position.x = (_vm->_map[scene._charPoint].x - 6) * 100; _data[AL]._position.x = (map[scene._charPoint].x - 6) * 100;
_data[AL]._position.y = (_vm->_map[scene._charPoint].x + 10) * 100; _data[AL]._position.y = (map[scene._charPoint].x + 10) * 100;
} }
_oldWalkSequence = -1; _oldWalkSequence = -1;

View file

@ -183,13 +183,11 @@ byte TALK_SEQUENCES[MAX_PEOPLE][MAX_TALK_SEQUENCES] = {
ScalpelEngine::ScalpelEngine(OSystem *syst, const SherlockGameDescription *gameDesc) : ScalpelEngine::ScalpelEngine(OSystem *syst, const SherlockGameDescription *gameDesc) :
SherlockEngine(syst, gameDesc) { SherlockEngine(syst, gameDesc) {
_chess = nullptr;
_darts = nullptr; _darts = nullptr;
_chessResult = 0; _mapResult = 0;
} }
ScalpelEngine::~ScalpelEngine() { ScalpelEngine::~ScalpelEngine() {
delete _chess;
delete _darts; delete _darts;
} }
@ -199,7 +197,6 @@ ScalpelEngine::~ScalpelEngine() {
void ScalpelEngine::initialize() { void ScalpelEngine::initialize() {
SherlockEngine::initialize(); SherlockEngine::initialize();
_chess = new Chess(this);
_darts = new Darts(this); _darts = new Darts(this);
_flags.resize(100 * 8); _flags.resize(100 * 8);
@ -207,8 +204,7 @@ void ScalpelEngine::initialize() {
_flags[39] = true; // Turn on Baker Street _flags[39] = true; // Turn on Baker Street
// Load the map co-ordinates for each scene // Load the map co-ordinates for each scene
for (int idx = 0; idx < NUM_PLACES; ++idx) _map->loadPoints(NUM_PLACES, &MAP_X[0], &MAP_Y[0]);
_map.push_back(Common::Point(MAP_X[idx], MAP_Y[idx]));
// Load the inventory // Load the inventory
loadInventory(); loadInventory();
@ -393,7 +389,7 @@ void ScalpelEngine::startScene() {
} }
} }
_scene->_goToScene = _chess->doChessBoard(); _scene->_goToScene = _map->show();
_sound->freeSong(); _sound->freeSong();
_scene->_hsavedPos = Common::Point(-1, -1); _scene->_hsavedPos = Common::Point(-1, -1);
@ -533,10 +529,10 @@ void ScalpelEngine::startScene() {
if (_scene->_goToScene == 99) { if (_scene->_goToScene == 99) {
// Chess Board // Chess Board
_darts->playDarts(); _darts->playDarts();
_chessResult = _scene->_goToScene = 19; // Go back to the bar _mapResult = _scene->_goToScene = 19; // Go back to the bar
} }
_chessResult = _scene->_goToScene; _mapResult = _scene->_goToScene;
} }
/** /**

View file

@ -24,7 +24,6 @@
#define SHERLOCK_SCALPEL_H #define SHERLOCK_SCALPEL_H
#include "sherlock/sherlock.h" #include "sherlock/sherlock.h"
#include "sherlock/scalpel/chess.h"
#include "sherlock/scalpel/darts.h" #include "sherlock/scalpel/darts.h"
namespace Sherlock { namespace Sherlock {
@ -33,9 +32,8 @@ namespace Scalpel {
class ScalpelEngine : public SherlockEngine { class ScalpelEngine : public SherlockEngine {
private: private:
Chess *_chess;
Darts *_darts; Darts *_darts;
int _chessResult; int _mapResult;
bool showCityCutscene(); bool showCityCutscene();
bool showAlleyCutscene(); bool showAlleyCutscene();

View file

@ -193,6 +193,7 @@ void Scene::freeScene() {
*/ */
bool Scene::loadScene(const Common::String &filename) { bool Scene::loadScene(const Common::String &filename) {
Events &events = *_vm->_events; Events &events = *_vm->_events;
Map &map = *_vm->_map;
People &people = *_vm->_people; People &people = *_vm->_people;
Screen &screen = *_vm->_screen; Screen &screen = *_vm->_screen;
Sound &sound = *_vm->_sound; Sound &sound = *_vm->_sound;
@ -437,8 +438,8 @@ bool Scene::loadScene(const Common::String &filename) {
// Reset the position on the overland map // Reset the position on the overland map
_vm->_oldCharPoint = _currentScene; _vm->_oldCharPoint = _currentScene;
_vm->_over.x = _vm->_map[_currentScene].x * 100 - 600; _vm->_over.x = map[_currentScene].x * 100 - 600;
_vm->_over.y = _vm->_map[_currentScene].y * 100 + 900; _vm->_over.y = map[_currentScene].y * 100 + 900;
events.clearEvents(); events.clearEvents();
return flag; return flag;
@ -843,6 +844,7 @@ void Scene::checkBgShapes(ImageFrame *frame, const Common::Point &pt) {
*/ */
int Scene::startCAnim(int cAnimNum, int playRate) { int Scene::startCAnim(int cAnimNum, int playRate) {
Events &events = *_vm->_events; Events &events = *_vm->_events;
Map &map = *_vm->_map;
People &people = *_vm->_people; People &people = *_vm->_people;
Resources &res = *_vm->_res; Resources &res = *_vm->_res;
Talk &talk = *_vm->_talk; Talk &talk = *_vm->_talk;
@ -1027,8 +1029,8 @@ int Scene::startCAnim(int cAnimNum, int playRate) {
if (gotoCode > 0 && !talk._talkToAbort) { if (gotoCode > 0 && !talk._talkToAbort) {
_goToScene = gotoCode; _goToScene = gotoCode;
if (_goToScene < 97 && _vm->_map[_goToScene].x) { if (_goToScene < 97 && map[_goToScene].x) {
_overPos = _vm->_map[_goToScene]; _overPos = map[_goToScene];
} }
} }

View file

@ -35,6 +35,7 @@ SherlockEngine::SherlockEngine(OSystem *syst, const SherlockGameDescription *gam
_events = nullptr; _events = nullptr;
_inventory = nullptr; _inventory = nullptr;
_journal = nullptr; _journal = nullptr;
_map = nullptr;
_people = nullptr; _people = nullptr;
_res = nullptr; _res = nullptr;
_scene = nullptr; _scene = nullptr;
@ -55,6 +56,7 @@ SherlockEngine::~SherlockEngine() {
delete _debugger; delete _debugger;
delete _events; delete _events;
delete _journal; delete _journal;
delete _map;
delete _people; delete _people;
delete _scene; delete _scene;
delete _screen; delete _screen;
@ -78,6 +80,7 @@ void SherlockEngine::initialize() {
_debugger = new Debugger(this); _debugger = new Debugger(this);
_events = new Events(this); _events = new Events(this);
_inventory = new Inventory(this); _inventory = new Inventory(this);
_map = new Map(this);
_journal = new Journal(this); _journal = new Journal(this);
_people = new People(this); _people = new People(this);
_scene = new Scene(this); _scene = new Scene(this);

View file

@ -36,6 +36,7 @@
#include "sherlock/events.h" #include "sherlock/events.h"
#include "sherlock/inventory.h" #include "sherlock/inventory.h"
#include "sherlock/journal.h" #include "sherlock/journal.h"
#include "sherlock/map.h"
#include "sherlock/people.h" #include "sherlock/people.h"
#include "sherlock/resources.h" #include "sherlock/resources.h"
#include "sherlock/scene.h" #include "sherlock/scene.h"
@ -85,6 +86,7 @@ public:
Events *_events; Events *_events;
Inventory *_inventory; Inventory *_inventory;
Journal *_journal; Journal *_journal;
Map *_map;
People *_people; People *_people;
Resources *_res; Resources *_res;
Scene *_scene; Scene *_scene;
@ -101,7 +103,6 @@ public:
bool _loadingSavedGame; bool _loadingSavedGame;
int _oldCharPoint; // Old scene int _oldCharPoint; // Old scene
Common::Point _over; // Old map position Common::Point _over; // Old map position
Common::Array<Common::Point> _map; // Map locations for each scene
bool _onChessboard; bool _onChessboard;
bool _slowChess; bool _slowChess;
bool _joystick; bool _joystick;

View file

@ -574,7 +574,6 @@ void Talk::freeTalkVars() {
* conversation. If found, the data for that conversation is loaded * conversation. If found, the data for that conversation is loaded
*/ */
void Talk::loadTalkFile(const Common::String &filename) { void Talk::loadTalkFile(const Common::String &filename) {
People &people = *_vm->_people;
Resources &res = *_vm->_res; Resources &res = *_vm->_res;
Sound &sound = *_vm->_sound; Sound &sound = *_vm->_sound;
@ -1000,6 +999,7 @@ void Talk::doScript(const Common::String &script) {
Animation &anim = *_vm->_animation; Animation &anim = *_vm->_animation;
Events &events = *_vm->_events; Events &events = *_vm->_events;
Inventory &inv = *_vm->_inventory; Inventory &inv = *_vm->_inventory;
Map &map = *_vm->_map;
People &people = *_vm->_people; People &people = *_vm->_people;
Scene &scene = *_vm->_scene; Scene &scene = *_vm->_scene;
Screen &screen = *_vm->_screen; Screen &screen = *_vm->_screen;
@ -1351,8 +1351,8 @@ void Talk::doScript(const Common::String &script) {
if (scene._goToScene != 100) { if (scene._goToScene != 100) {
// Not going to the map overview // Not going to the map overview
scene._oldCharPoint = scene._goToScene; scene._oldCharPoint = scene._goToScene;
scene._overPos.x = _vm->_map[scene._goToScene].x * 100 - 600; scene._overPos.x = map[scene._goToScene].x * 100 - 600;
scene._overPos.y = _vm->_map[scene._goToScene].y * 100 + 900; scene._overPos.y = map[scene._goToScene].y * 100 + 900;
// Run a canimation? // Run a canimation?
if (str[2] > 100) { if (str[2] > 100) {