aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorNicola Mettifogo2009-02-26 09:42:08 +0000
committerNicola Mettifogo2009-02-26 09:42:08 +0000
commit76283e3f736ba7c93ed703b960821e22439cfcef (patch)
tree717fae36e5ff3cb0bef6509d7b925715183308c6 /engines
parent3efffe511b2c9282f79ecfdb937e6b8fc1d330c1 (diff)
downloadscummvm-rg350-76283e3f736ba7c93ed703b960821e22439cfcef.tar.gz
scummvm-rg350-76283e3f736ba7c93ed703b960821e22439cfcef.tar.bz2
scummvm-rg350-76283e3f736ba7c93ed703b960821e22439cfcef.zip
Merged walk code for NS, and simplified handling.
svn-id: r38894
Diffstat (limited to 'engines')
-rw-r--r--engines/parallaction/parallaction.cpp75
-rw-r--r--engines/parallaction/parallaction.h13
-rw-r--r--engines/parallaction/parallaction_ns.cpp8
-rw-r--r--engines/parallaction/walk.cpp99
-rw-r--r--engines/parallaction/walk.h43
5 files changed, 89 insertions, 149 deletions
diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp
index 315da333d1..fa0ceb8576 100644
--- a/engines/parallaction/parallaction.cpp
+++ b/engines/parallaction/parallaction.cpp
@@ -167,7 +167,7 @@ void Parallaction::updateView() {
scrollX = _gfx->getScrollPos();
Common::Point foot;
- _char.getFoot(foot);
+ _char._ani->getFoot(foot);
foot.x -= scrollX;
//foot.y -= ...
@@ -829,43 +829,11 @@ void Location::freeZones(bool removeAll) {
}
-enum {
- WALK_LEFT = 0,
- WALK_RIGHT = 1,
- WALK_DOWN = 2,
- WALK_UP = 3
-};
-
-struct WalkFrames {
- int16 stillFrame[4];
- int16 firstWalkFrame[4];
- int16 numWalkFrames[4];
- int16 frameRepeat[4];
-};
-
-WalkFrames _char20WalkFrames = {
- { 0, 7, 14, 17 },
- { 1, 8, 15, 18 },
- { 6, 6, 2, 2 },
- { 2, 2, 4, 4 }
-};
-
-WalkFrames _char24WalkFrames = {
- { 0, 9, 18, 21 },
- { 1, 10, 19, 22 },
- { 8, 8, 2, 2 },
- { 2, 2, 4, 4 }
-};
-
-
Character::Character(Parallaction *vm) : _vm(vm), _ani(new Animation) {
_talk = NULL;
_head = NULL;
- _direction = WALK_DOWN;
- _step = 0;
-
_ani->setX(150);
_ani->setY(100);
_ani->setZ(10);
@@ -875,26 +843,6 @@ Character::Character(Parallaction *vm) : _vm(vm), _ani(new Animation) {
strncpy(_ani->_name, "yourself", ZONENAME_LENGTH);
}
-Character::~Character() {
-
-}
-
-void Character::getFoot(Common::Point &foot) {
- Common::Rect rect;
- _ani->gfxobj->getRect(_ani->getF(), rect);
-
- foot.x = _ani->getX() + (rect.left + rect.width() / 2);
- foot.y = _ani->getY() + (rect.top + rect.height());
-}
-
-void Character::setFoot(const Common::Point &foot) {
- Common::Rect rect;
- _ani->gfxobj->getRect(_ani->getF(), rect);
-
- _ani->setX(foot.x - (rect.left + rect.width() / 2));
- _ani->setY(foot.y - (rect.top + rect.height()));
-}
-
void Character::setName(const char *name) {
_name.bind(name);
@@ -916,27 +864,6 @@ bool Character::dummy() const {
return _name.dummy();
}
-void Character::updateDirection(const Common::Point& pos, const Common::Point& to) {
-
- Common::Point dist(to.x - pos.x, to.y - pos.y);
- WalkFrames *frames = (_ani->getFrameNum() == 20) ? &_char20WalkFrames : &_char24WalkFrames;
-
- _step++;
-
- if (dist.x == 0 && dist.y == 0) {
- _ani->setF(frames->stillFrame[_direction]);
- return;
- }
-
- if (dist.x < 0)
- dist.x = -dist.x;
- if (dist.y < 0)
- dist.y = -dist.y;
-
- _direction = (dist.x > dist.y) ? ((to.x > pos.x) ? WALK_LEFT : WALK_RIGHT) : ((to.y > pos.y) ? WALK_DOWN : WALK_UP);
- _ani->setF(frames->firstWalkFrame[_direction] + (_step / frames->frameRepeat[_direction]) % frames->numWalkFrames[_direction]);
-}
-
// Various ways of detecting character modes used to exist
diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h
index bbe08d3069..b7bf8af72c 100644
--- a/engines/parallaction/parallaction.h
+++ b/engines/parallaction/parallaction.h
@@ -120,7 +120,6 @@ class SoundMan;
class Input;
class DialogueManager;
class MenuInputHelper;
-class PathBuilder_NS;
class PathWalker_NS;
class PathWalker_BR;
class CommandExec;
@@ -199,32 +198,21 @@ public:
struct Character {
Parallaction *_vm;
-
AnimationPtr _ani;
GfxObj *_head;
GfxObj *_talk;
- PointList _walkPath;
Character(Parallaction *vm);
- ~Character();
-
- void getFoot(Common::Point &foot);
- void setFoot(const Common::Point &foot);
protected:
CharacterName _name;
- int16 _direction, _step;
-
public:
void setName(const char *name);
const char *getName() const;
const char *getBaseName() const;
const char *getFullName() const;
bool dummy() const;
-
- void updateDirection(const Common::Point& pos, const Common::Point& to);
-
};
@@ -435,7 +423,6 @@ private:
static const Callable _dosCallables[25];
static const Callable _amigaCallables[25];
- PathBuilder_NS *_builder;
PathWalker_NS *_walker;
// common callables
diff --git a/engines/parallaction/parallaction_ns.cpp b/engines/parallaction/parallaction_ns.cpp
index 26d2fe7b5e..27b1ef8b50 100644
--- a/engines/parallaction/parallaction_ns.cpp
+++ b/engines/parallaction/parallaction_ns.cpp
@@ -146,7 +146,7 @@ void LocationName::bind(const char *s) {
}
Parallaction_ns::Parallaction_ns(OSystem* syst, const PARALLACTIONGameDescription *gameDesc) : Parallaction(syst, gameDesc),
- _locationParser(0), _programParser(0), _builder(0), _walker(0) {
+ _locationParser(0), _programParser(0), _walker(0) {
}
Common::Error Parallaction_ns::init() {
@@ -184,8 +184,7 @@ Common::Error Parallaction_ns::init() {
_cmdExec = new CommandExec_ns(this);
_programExec = new ProgramExec_ns(this);
- _builder = new PathBuilder_NS(&_char);
- _walker = new PathWalker_NS(&_char);
+ _walker = new PathWalker_NS;
_sarcophagusDeltaX = 0;
_movingSarcophagus = false;
@@ -215,7 +214,6 @@ Parallaction_ns::~Parallaction_ns() {
_location._animations.remove(_char._ani);
- delete _builder;
delete _walker;
}
@@ -503,7 +501,7 @@ void Parallaction_ns::scheduleWalk(int16 x, int16 y, bool fromUser) {
return;
}
- _builder->buildPath(x, y);
+ _walker->buildPath(a, x, y);
_engineFlags |= kEngineWalking;
}
diff --git a/engines/parallaction/walk.cpp b/engines/parallaction/walk.cpp
index 4357f19474..2ccbedff44 100644
--- a/engines/parallaction/walk.cpp
+++ b/engines/parallaction/walk.cpp
@@ -31,9 +31,38 @@ namespace Parallaction {
#define IS_PATH_CLEAR(x,y) _vm->_gfx->_backgroundInfo->_path->getValue((x), (y))
+enum {
+ WALK_LEFT = 0,
+ WALK_RIGHT = 1,
+ WALK_DOWN = 2,
+ WALK_UP = 3
+};
+
+struct WalkFrames {
+ int16 stillFrame[4];
+ int16 firstWalkFrame[4];
+ int16 numWalkFrames[4];
+ int16 frameRepeat[4];
+};
+
+WalkFrames _char20WalkFrames_NS = {
+ { 0, 7, 14, 17 },
+ { 1, 8, 15, 18 },
+ { 6, 6, 2, 2 },
+ { 2, 2, 4, 4 }
+};
+
+WalkFrames _char24WalkFrames_NS = {
+ { 0, 9, 18, 21 },
+ { 1, 10, 19, 22 },
+ { 8, 8, 2, 2 },
+ { 2, 2, 4, 4 }
+};
+
+
// adjusts position towards nearest walkable point
//
-void PathBuilder_NS::correctPathPoint(Common::Point &to) {
+void PathWalker_NS::correctPathPoint(Common::Point &to) {
if (IS_PATH_CLEAR(to.x, to.y)) return;
@@ -84,7 +113,7 @@ void PathBuilder_NS::correctPathPoint(Common::Point &to) {
}
-uint32 PathBuilder_NS::buildSubPath(const Common::Point& pos, const Common::Point& stop) {
+uint32 PathWalker_NS::buildSubPath(const Common::Point& pos, const Common::Point& stop) {
uint32 v28 = 0;
uint32 v2C = 0;
@@ -132,10 +161,12 @@ uint32 PathBuilder_NS::buildSubPath(const Common::Point& pos, const Common::Poin
//
// x, y: mouse click (foot) coordinates
//
-void PathBuilder_NS::buildPath(uint16 x, uint16 y) {
+void PathWalker_NS::buildPath(AnimationPtr a, uint16 x, uint16 y) {
debugC(1, kDebugWalk, "PathBuilder::buildPath to (%i, %i)", x, y);
- _ch->_walkPath.clear();
+ _a = a;
+
+ _walkPath.clear();
Common::Point to(x, y);
correctPathPoint(to);
@@ -148,26 +179,26 @@ void PathBuilder_NS::buildPath(uint16 x, uint16 y) {
if (v38 == 1) {
// destination directly reachable
debugC(1, kDebugWalk, "direct move to (%i, %i)", to.x, to.y);
- _ch->_walkPath.push_back(v48);
+ _walkPath.push_back(v48);
return;
}
// path is obstructed: look for alternative
- _ch->_walkPath.push_back(v48);
+ _walkPath.push_back(v48);
Common::Point pos;
- _ch->getFoot(pos);
+ _a->getFoot(pos);
uint32 v34 = buildSubPath(pos, v48);
if (v38 != 0 && v34 > v38) {
// no alternative path (gap?)
- _ch->_walkPath.clear();
- _ch->_walkPath.push_back(v44);
+ _walkPath.clear();
+ _walkPath.push_back(v44);
return;
}
- _ch->_walkPath.insert(_ch->_walkPath.begin(), _subPath.begin(), _subPath.end());
+ _walkPath.insert(_walkPath.begin(), _subPath.begin(), _subPath.end());
- buildSubPath(pos, *_ch->_walkPath.begin());
- _ch->_walkPath.insert(_ch->_walkPath.begin(), _subPath.begin(), _subPath.end());
+ buildSubPath(pos, *_walkPath.begin());
+ _walkPath.insert(_walkPath.begin(), _subPath.begin(), _subPath.end());
return;
}
@@ -180,14 +211,14 @@ void PathBuilder_NS::buildPath(uint16 x, uint16 y) {
// 1 : Point reachable in a straight line
// other values: square distance to target (point not reachable in a straight line)
//
-uint16 PathBuilder_NS::walkFunc1(const Common::Point &to, Common::Point& node) {
+uint16 PathWalker_NS::walkFunc1(const Common::Point &to, Common::Point& node) {
Common::Point arg(to);
Common::Point v4;
Common::Point foot;
- _ch->getFoot(foot);
+ _a->getFoot(foot);
Common::Point v8(foot);
@@ -286,10 +317,10 @@ void PathWalker_NS::finalizeWalk() {
_engineFlags &= ~kEngineWalking;
Common::Point foot;
- _ch->getFoot(foot);
+ _a->getFoot(foot);
checkDoor(foot);
- _ch->_walkPath.clear();
+ _walkPath.clear();
}
void PathWalker_NS::walk() {
@@ -298,20 +329,20 @@ void PathWalker_NS::walk() {
}
Common::Point curPos;
- _ch->getFoot(curPos);
+ _a->getFoot(curPos);
// update target, if previous was reached
- PointList::iterator it = _ch->_walkPath.begin();
- if (it != _ch->_walkPath.end()) {
+ PointList::iterator it = _walkPath.begin();
+ if (it != _walkPath.end()) {
if (*it == curPos) {
debugC(1, kDebugWalk, "walk reached node (%i, %i)", (*it).x, (*it).y);
- it = _ch->_walkPath.erase(it);
+ it = _walkPath.erase(it);
}
}
// advance character towards the target
Common::Point targetPos;
- if (it == _ch->_walkPath.end()) {
+ if (it == _walkPath.end()) {
debugC(1, kDebugWalk, "walk reached last node");
finalizeWalk();
targetPos = curPos;
@@ -321,7 +352,7 @@ void PathWalker_NS::walk() {
Common::Point newPos(curPos);
clipMove(newPos, targetPos);
- _ch->setFoot(newPos);
+ _a->setFoot(newPos);
if (newPos == curPos) {
debugC(1, kDebugWalk, "walk was blocked by an unforeseen obstacle");
@@ -336,12 +367,32 @@ void PathWalker_NS::walk() {
// from curPos to newPos is prone to abrutply change in direction, thus making the
// code select 'too different' frames when walking diagonally against obstacles,
// and yielding an annoying shaking effect in the character.
- _ch->updateDirection(curPos, targetPos);
+ updateDirection(curPos, targetPos);
}
+void PathWalker_NS::updateDirection(const Common::Point& pos, const Common::Point& to) {
+
+ Common::Point dist(to.x - pos.x, to.y - pos.y);
+ WalkFrames *frames = (_a->getFrameNum() == 20) ? &_char20WalkFrames_NS : &_char24WalkFrames_NS;
+
+ _step++;
+
+ if (dist.x == 0 && dist.y == 0) {
+ _a->setF(frames->stillFrame[_direction]);
+ return;
+ }
+
+ if (dist.x < 0)
+ dist.x = -dist.x;
+ if (dist.y < 0)
+ dist.y = -dist.y;
+
+ _direction = (dist.x > dist.y) ? ((to.x > pos.x) ? WALK_LEFT : WALK_RIGHT) : ((to.y > pos.y) ? WALK_DOWN : WALK_UP);
+ _a->setF(frames->firstWalkFrame[_direction] + (_step / frames->frameRepeat[_direction]) % frames->numWalkFrames[_direction]);
+}
-PathBuilder_NS::PathBuilder_NS(Character *ch) : PathBuilder(ch) {
+PathWalker_NS::PathWalker_NS() : _direction(WALK_DOWN), _step(0) {
}
diff --git a/engines/parallaction/walk.h b/engines/parallaction/walk.h
index d746fdec54..65ebdb8e97 100644
--- a/engines/parallaction/walk.h
+++ b/engines/parallaction/walk.h
@@ -36,51 +36,28 @@ namespace Parallaction {
struct Character;
-class PathBuilder {
-protected:
- Character *_ch;
-
-public:
- PathBuilder(Character *ch) : _ch(ch) { }
- virtual ~PathBuilder() { }
-
- virtual void buildPath(uint16 x, uint16 y) = 0;
-};
-
-class PathWalker {
-protected:
- Character *_ch;
-public:
- PathWalker(Character *ch) : _ch(ch) { }
- virtual ~PathWalker() { }
- virtual void walk() = 0;
-};
-
-
-
-class PathBuilder_NS : public PathBuilder {
+class PathWalker_NS {
+ AnimationPtr _a;
+ PointList _walkPath;
+ int16 _direction, _step;
+ // builder routines
PointList _subPath;
-
void correctPathPoint(Common::Point &to);
uint32 buildSubPath(const Common::Point& pos, const Common::Point& stop);
uint16 walkFunc1(const Common::Point &to, Common::Point& node);
-public:
- PathBuilder_NS(Character *ch);
- void buildPath(uint16 x, uint16 y);
-};
-
-class PathWalker_NS : public PathWalker {
-
-
+ // walker routines
void finalizeWalk();
void clipMove(Common::Point& pos, const Common::Point& to);
void checkDoor(const Common::Point &foot);
+ void updateDirection(const Common::Point& pos, const Common::Point& to);
public:
- PathWalker_NS(Character *ch) : PathWalker(ch) { }
+ PathWalker_NS();
+
+ void buildPath(AnimationPtr a, uint16 x, uint16 y);
void walk();
};