Skip to content

Commit

Permalink
SHERLOCK: Move Scalpel map code to ScalpelMap
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jun 8, 2015
1 parent ae64cca commit f5a1b62
Show file tree
Hide file tree
Showing 21 changed files with 1,038 additions and 952 deletions.
529 changes: 4 additions & 525 deletions engines/sherlock/map.cpp

Large diffs are not rendered by default.

128 changes: 3 additions & 125 deletions engines/sherlock/map.h
Expand Up @@ -23,153 +23,31 @@
#ifndef SHERLOCK_MAP_H
#define SHERLOCK_MAP_H

#include "common/scummsys.h"
#include "common/array.h"
#include "common/rect.h"
#include "common/str.h"
#include "common/str-array.h"
#include "sherlock/surface.h"
#include "sherlock/objects.h"
#include "sherlock/saveload.h"

namespace Sherlock {

class SherlockEngine;

struct MapEntry : Common::Point {
int _translate;

MapEntry() : Common::Point(), _translate(-1) {}

MapEntry(int posX, int posY, int translate) : Common::Point(posX, posY), _translate(translate) {}
};

class MapPaths {
private:
int _numLocations;
Common::Array< Common::Array<byte> > _paths;

public:
MapPaths();

/**
* Load the data for the paths between locations on the map
*/
void load(int numLocations, Common::SeekableReadStream &s);

/**
* Get the path between two locations on the map
*/
const byte *getPath(int srcLocation, int destLocation);
};

class Map {
protected:
SherlockEngine *_vm;
Common::Array<MapEntry> _points; // Map locations for each scene
Common::StringArray _locationNames;
MapPaths _paths;
Common::Array<Common::Point> _pathPoints;
Common::Point _savedPos;
Common::Point _savedSize;
Surface _topLine;
ImageFile *_mapCursors;
ImageFile *_shapes;
ImageFile *_iconShapes;
WalkSequences _walkSequences;
Point32 _lDrawnPos;
int _point;
bool _placesShown;
int _cursorIndex;
bool _drawMap;
Surface _iconSave;
protected:
Map(SherlockEngine *vm);

/**
* Load data needed for the map
*/
void loadData();

/**
* Load and initialize all the sprites that are needed for the map display
*/
void setupSprites();

/**
* Free the sprites and data used by the map
*/
void freeSprites();

/**
* Draws an icon for every place that's currently known
*/
void showPlaces();

/**
* Makes a copy of the top rows of the screen that are used to display location names
*/
void saveTopLine();

/**
* Erases anything shown in the top line by restoring the previously saved original map background
*/
void eraseTopLine();

/**
* Prints the name of the specified icon
*/
void showPlaceName(int idx, bool highlighted);

/**
* Update all on-screen sprites to account for any scrolling of the map
*/
void updateMap(bool flushScreen);

/**
* Handle moving icon for player from their previous location on the map to a destination location
*/
void walkTheStreets();

/**
* Save the area under the player's icon
*/
void saveIcon(ImageFrame *src, const Common::Point &pt);

/**
* Restore the area under the player's icon
*/
void restoreIcon();

/**
* Handles highlighting map icons, showing their names
*/
void highlightIcon(const Common::Point &pt);
Map(SherlockEngine *vm);
public:
bool _active;
Point32 _overPos;
Point32 _bigPos;
int _charPoint, _oldCharPoint;
bool _active;
bool _frameChangeFlag;
public:
static Map *init(SherlockEngine *vm);

const MapEntry &operator[](int idx) { return _points[idx]; }

/**
* Loads the list of points for locations on the map for each scene
*/
void loadPoints(int count, const int *xList, const int *yList, const int *transList);

/**
* Load the sequence data for player icon animations
*/
void loadSequences(int count, const byte *seq);

/**
* Show the map
*/
int show();
virtual int show() = 0;

/**
* Synchronize the data for a savegame
Expand Down
11 changes: 7 additions & 4 deletions engines/sherlock/objects.cpp
Expand Up @@ -25,6 +25,7 @@
#include "sherlock/objects.h"
#include "sherlock/people.h"
#include "sherlock/scene.h"
#include "sherlock/scalpel/scalpel_map.h"
#include "sherlock/scalpel/scalpel_people.h"

namespace Sherlock {
Expand Down Expand Up @@ -1212,7 +1213,6 @@ void Object::setObjTalkSequence(int seq) {
}

int Object::checkNameForCodes(const Common::String &name, const char *const messages[]) {
Map &map = *_vm->_map;
People &people = *_vm->_people;
Scene &scene = *_vm->_scene;
Screen &screen = *_vm->_screen;
Expand Down Expand Up @@ -1257,9 +1257,12 @@ int Object::checkNameForCodes(const Common::String &name, const char *const mess
if (ch >= '0' && ch <= '9') {
scene._goToScene = atoi(name.c_str() + 1);

if (IS_SERRATED_SCALPEL && scene._goToScene < 97 && map[scene._goToScene].x) {
map._overPos.x = (map[scene._goToScene].x - 6) * FIXED_INT_MULTIPLIER;
map._overPos.y = (map[scene._goToScene].y + 9) * FIXED_INT_MULTIPLIER;
if (IS_SERRATED_SCALPEL && scene._goToScene < 97) {
Scalpel::ScalpelMap &map = *(Scalpel::ScalpelMap *)_vm->_map;
if (map[scene._goToScene].x) {
map._overPos.x = (map[scene._goToScene].x - 6) * FIXED_INT_MULTIPLIER;
map._overPos.y = (map[scene._goToScene].y + 9) * FIXED_INT_MULTIPLIER;
}
}

const char *p;
Expand Down
50 changes: 0 additions & 50 deletions engines/sherlock/people.cpp
Expand Up @@ -425,56 +425,6 @@ assert(_player._position.y >= 10000);/***DEBUG****/
_player._frameNumber = oldFrame;
}

void People::gotoStand(Sprite &sprite) {
Map &map = *_vm->_map;
_walkTo.clear();
sprite._walkCount = 0;

switch (sprite._sequenceNumber) {
case Scalpel::WALK_UP:
sprite._sequenceNumber = Scalpel::STOP_UP;
break;
case Scalpel::WALK_DOWN:
sprite._sequenceNumber = Scalpel::STOP_DOWN;
break;
case Scalpel::TALK_LEFT:
case Scalpel::WALK_LEFT:
sprite._sequenceNumber = Scalpel::STOP_LEFT;
break;
case Scalpel::TALK_RIGHT:
case Scalpel::WALK_RIGHT:
sprite._sequenceNumber = Scalpel::STOP_RIGHT;
break;
case Scalpel::WALK_UPRIGHT:
sprite._sequenceNumber = Scalpel::STOP_UPRIGHT;
break;
case Scalpel::WALK_UPLEFT:
sprite._sequenceNumber = Scalpel::STOP_UPLEFT;
break;
case Scalpel::WALK_DOWNRIGHT:
sprite._sequenceNumber = Scalpel::STOP_DOWNRIGHT;
break;
case Scalpel::WALK_DOWNLEFT:
sprite._sequenceNumber = Scalpel::STOP_DOWNLEFT;
break;
default:
break;
}

// Only restart frame at 0 if the sequence number has changed
if (_oldWalkSequence != -1 || sprite._sequenceNumber == Scalpel::STOP_UP)
sprite._frameNumber = 0;

if (map._active) {
sprite._sequenceNumber = 0;
_player._position.x = (map[map._charPoint].x - 6) * FIXED_INT_MULTIPLIER;
_player._position.y = (map[map._charPoint].y + 10) * FIXED_INT_MULTIPLIER;
}

_oldWalkSequence = -1;
_allowWalkAbort = true;
}

void People::walkToCoords(const Point32 &destPos, int destDir) {
Events &events = *_vm->_events;
Scene &scene = *_vm->_scene;
Expand Down
12 changes: 6 additions & 6 deletions engines/sherlock/people.h
Expand Up @@ -158,12 +158,6 @@ class People {
*/
void setWalking();

/**
* Bring a moving character to a standing position. If the Scalpel chessboard
* is being displayed, then the chraracter will always face down.
*/
void gotoStand(Sprite &sprite);

/**
* Walk to the co-ordinates passed, and then face the given direction
*/
Expand Down Expand Up @@ -195,6 +189,12 @@ class People {
* Change the sequence of the scene background object associated with the current speaker.
*/
virtual void setTalkSequence(int speaker, int sequenceNum = 1) = 0;

/**
* Bring a moving character to a standing position. If the Scalpel chessboard
* is being displayed, then the chraracter will always face down.
*/
virtual void gotoStand(Sprite &sprite) = 0;
};

} // End of namespace Sherlock
Expand Down
8 changes: 5 additions & 3 deletions engines/sherlock/scalpel/scalpel.cpp
Expand Up @@ -22,6 +22,7 @@

#include "engines/util.h"
#include "sherlock/scalpel/scalpel.h"
#include "sherlock/scalpel/scalpel_map.h"
#include "sherlock/scalpel/scalpel_people.h"
#include "sherlock/scalpel/scalpel_scene.h"
#include "sherlock/scalpel/tsage/logo.h"
Expand Down Expand Up @@ -205,9 +206,10 @@ void ScalpelEngine::initialize() {

if (!isDemo()) {
// Load the map co-ordinates for each scene and sequence data
_map->loadPoints(NUM_PLACES, &MAP_X[0], &MAP_Y[0], &MAP_TRANSLATE[0]);
_map->loadSequences(3, &MAP_SEQUENCES[0][0]);
_map->_oldCharPoint = BAKER_ST_EXTERIOR;
ScalpelMap &map = *(ScalpelMap *)_map;
map.loadPoints(NUM_PLACES, &MAP_X[0], &MAP_Y[0], &MAP_TRANSLATE[0]);
map.loadSequences(3, &MAP_SEQUENCES[0][0]);
map._oldCharPoint = BAKER_ST_EXTERIOR;
}

// Load the inventory
Expand Down

0 comments on commit f5a1b62

Please sign in to comment.