diff options
Diffstat (limited to 'engines/cge')
-rw-r--r-- | engines/cge/cge_main.cpp | 5 | ||||
-rw-r--r-- | engines/cge/walk.cpp | 38 | ||||
-rw-r--r-- | engines/cge/walk.h | 51 |
3 files changed, 26 insertions, 68 deletions
diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 5ccf681f96..9b1afed245 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -763,8 +763,9 @@ void System::touch(uint16 mask, int x, int y) { if (_horzLine && !_horzLine->_flags._hide) { if (y >= kMapTop && y < kMapTop + kMapHig) { - int8 x1, z1; - XZ(x, y).split(x1, z1); + Cluster tmpCluster = XZ(x, y); + int16 x1 = tmpCluster._pt.x; + int16 z1 = tmpCluster._pt.y; Cluster::_map[z1][x1] = 1; _vm->setMapBrick(x1, z1); } diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 252e068d80..bcd15768f1 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -40,14 +40,14 @@ void Cluster::init(CGEEngine *vm) { } uint8 &Cluster::cell() { - return _map[_b][_a]; + return _map[_pt.y][_pt.x]; } bool Cluster::isValid() const { - return (_a >= 0) && (_a < kMapXCnt) && (_b >= 0) && (_b < kMapZCnt); + return (_pt.x >= 0) && (_pt.x < kMapXCnt) && (_pt.y >= 0) && (_pt.y < kMapZCnt); } -Cluster XZ(int x, int y) { +Cluster XZ(int16 x, int16 y) { if (y < kMapTop) y = kMapTop; @@ -57,12 +57,6 @@ Cluster XZ(int x, int y) { return Cluster(x / kMapGridX, (y - kMapTop) / kMapGridZ); } -Cluster XZ(Couple xy) { - signed char x, y; - xy.split(x, y); - return XZ(x, y); -} - Walk::Walk(CGEEngine *vm, BitmapPtr *shpl) : Sprite(vm, shpl), _dir(kDirNone), _tracePtr(-1), _level(0), _target(-1, -1), _findLevel(-1), _vm(vm) { } @@ -90,12 +84,13 @@ void Walk::tick() { if (_flags._hold || _tracePtr < 0) { park(); } else { - if (_here == _trace[_tracePtr]) { + if (_here._pt == _trace[_tracePtr]._pt) { if (--_tracePtr < 0) park(); } else { - signed char dx, dz; - (_trace[_tracePtr] - _here).split(dx, dz); + Common::Point tmpPoint = _trace[_tracePtr]._pt - _here._pt; + int16 dx = tmpPoint.x; + int16 dz = tmpPoint.y; Dir d = (dx) ? ((dx > 0) ? kDirEast : kDirWest) : ((dz > 0) ? kDirSouth : kDirNorth); turn(d); } @@ -108,8 +103,8 @@ void Walk::tick() { (_dir == kDirSouth && _y + _w >= kWorldHeight - 2)) { park(); } else { - signed char x; // dummy var - _here.split(x, _z); // take current Z position + // take current Z position + _z = _here._pt.y; _snail_->addCom(kSnZTrim, -1, 0, this); // update Hero's pos in show queue } } @@ -154,14 +149,13 @@ void Walk::park() { } void Walk::findWay(Cluster c) { - if (c == _here) + if (c._pt == _here._pt) return; for (_findLevel = 1; _findLevel <= kMaxFindLevel; _findLevel++) { - signed char x, z; - _here.split(x, z); - _target = Couple(x, z); - c.split(x, z); + _target = _here._pt; + int16 x = c._pt.x; + int16 z = c._pt.y; if (find1Way(Cluster(x, z))) break; @@ -219,14 +213,14 @@ void Walk::noWay() { bool Cluster::chkBar() const { assert(_vm->_now <= _vm->_caveMax); - return (_a == _vm->_barriers[_vm->_now]._horz) || (_b == _vm->_barriers[_vm->_now]._vert); + return (_pt.x == _vm->_barriers[_vm->_now]._horz) || (_pt.y == _vm->_barriers[_vm->_now]._vert); } bool Walk::find1Way(Cluster c) { const Cluster tab[4] = { Cluster(-1, 0), Cluster(1, 0), Cluster(0, -1), Cluster(0, 1)}; const int tabLen = 4; - if (c == _target) + if (c._pt == _target) // Found destination return true; @@ -249,7 +243,7 @@ bool Walk::find1Way(Cluster c) { c = start; do { - c += tab[i]; + c._pt += tab[i]._pt; if (!c.isValid()) // Break to check next direction break; diff --git a/engines/cge/walk.h b/engines/cge/walk.h index a0dce1f715..9b94120bb4 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -28,6 +28,7 @@ #ifndef CGE_WALK_H #define CGE_WALK_H +#include "common/rect.h" #include "cge/vga13h.h" #include "cge/events.h" @@ -44,54 +45,17 @@ namespace CGE { enum Dir { kDirNone = -1, kDirNorth, kDirEast, kDirSouth, kDirWest }; -class Couple { -protected: - signed char _a; - signed char _b; -public: - Couple(const signed char a, const signed char b) : _a(a), _b(b) { } - Couple operator + (Couple c) { - return Couple(_a + c._a, _b + c._b); - } - - void operator += (Couple c) { - _a += c._a; - _b += c._b; - } - - Couple operator - (Couple c) { - return Couple(_a - c._a, _b - c._b); - } - - void operator -= (Couple c) { - _a -= c._a; - _b -= c._b; - } - - bool operator == (const Couple &c) { - return ((_a - c._a) | (_b - c._b)) == 0; - } - - bool operator != (Couple c) { - return !(operator == (c)); - } - - void split(signed char &a, signed char &b) { - a = _a; - b = _b; - } -}; - -class Cluster : public Couple { +class Cluster { public: static uint8 _map[kMapZCnt][kMapXCnt]; static CGEEngine *_vm; + Common::Point _pt; static void init(CGEEngine *vm); public: uint8 &cell(); - Cluster(int a, int b) : Couple(a, b) { } - Cluster() : Couple (-1, -1) { } + Cluster(int16 a, int16 b) { _pt = Common::Point(a, b); } + Cluster() { _pt = Common::Point(-1, -1); } bool chkBar() const; bool isValid() const; }; @@ -104,7 +68,7 @@ public: int _tracePtr; int _level; int _findLevel; - Couple _target; + Common::Point _target; Cluster _trace[kMaxFindLevel]; Dir _dir; @@ -122,8 +86,7 @@ public: bool find1Way(Cluster c); }; -Cluster XZ(int x, int y); -Cluster XZ(Couple xy); +Cluster XZ(int16 x, int16 y); extern Walk *_hero; |