From ff21b2d5c8f8510ea5cfc6e59385c272d9774af9 Mon Sep 17 00:00:00 2001 From: uruk Date: Mon, 2 Jun 2014 10:03:15 +0200 Subject: CGE2: Implement Hero::expand(), move Sprite::works()'s stub to hero.cpp. --- engines/cge2/bitmap.cpp | 9 ++- engines/cge2/bitmap.h | 2 + engines/cge2/hero.cpp | 195 +++++++++++++++++++++++++++++++++++++++++++++++- engines/cge2/hero.h | 4 +- engines/cge2/vga13h.cpp | 19 +---- 5 files changed, 204 insertions(+), 25 deletions(-) (limited to 'engines/cge2') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 10fd6f1163..dfc5bcadd2 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -35,7 +35,14 @@ namespace CGE2 { -Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _m(NULL), _v(NULL), _map(0), _vm(vm) { +Bitmap::Bitmap() : _w(0), _h(0), _v(NULL), _b(NULL) { +} + +void Bitmap::setVM(CGE2Engine *vm) { + _vm = vm; +} + +Bitmap::Bitmap(CGE2Engine *vm, const char *fname) : _m(NULL), _v(NULL), _b(NULL), _map(0), _vm(vm) { char pat[kMaxPath]; forceExt(pat, fname, ".VBM"); diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 82c3b07e31..102fb1c8ca 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -66,12 +66,14 @@ public: int32 _map; HideDesc *_b; + Bitmap(); Bitmap(CGE2Engine *vm, const char *fname); Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 *map); Bitmap(CGE2Engine *vm, uint16 w, uint16 h, uint8 fill); Bitmap(CGE2Engine *vm, const Bitmap &bmp); ~Bitmap(); + void setVM(CGE2Engine *vm); Bitmap *code(); Bitmap &operator=(const Bitmap &bmp); void release(); diff --git a/engines/cge2/hero.cpp b/engines/cge2/hero.cpp index 3a6d1d2920..0c28d4c7f0 100644 --- a/engines/cge2/hero.cpp +++ b/engines/cge2/hero.cpp @@ -26,15 +26,185 @@ */ #include "cge2/hero.h" +#include "cge2/text.h" +#include "cge2/cge2_main.h" namespace CGE2 { -Hero::Hero(CGE2Engine *vm) : Sprite(vm) { - warning("STUB: Hero::Hero()"); +Hero::Hero(CGE2Engine *vm) + : Sprite(vm), _contact(nullptr), _dir(kNoDir), + _curDim(0), _tracePtr(-1), _ignoreMap(false) { } -Sprite *Hero::expand(void) { - warning("STUB: Hero::expand()"); +Sprite *Hero::expand(void) { // It's very similar to Sprite's expand, but doesn't bother with "labels" for example. TODO: Try to unify the two later! + if (_ext) + return this; + + char *text = _vm->_text->getText(_ref + 100); + char fname[kMaxPath]; + _vm->mergeExt(fname, _file, kSprExt); + _ext = new SprExt(_vm); + if (_ext == nullptr) + error("No core %s", fname); + + if (*_file) { + int cnt[kActions]; + int shpcnt = 0; + int seqcnt = 0; + int maxnow = 0; + int maxnxt = 0; + Seq *seq; + int section = kIdPhase; + + for (int i = 0; i < kDimMax; i++) { + _dim[i] = new Bitmap[_shpCnt]; + for (int j = 0; j < _shpCnt; j++) + _dim[i][j].setVM(_vm); + } + + if (_seqCnt) { + seq = new Seq[_seqCnt]; + if (seq == nullptr) + error("No core %s", fname); + } else + seq = nullptr; + + for (int i = 0; i < kActions; i++) + cnt[i] = 0; + + for (int i = 0; i < kActions; i++) { + byte n = _actionCtrl[i]._cnt; + if (n) { + _ext->_actions[i] = new CommandHandler::Command[n]; + if (_ext->_actions[i] == nullptr) + error("No core %s", fname); + } else + _ext->_actions[i] = nullptr; + } + + if (_vm->_resman->exist(fname)) { // sprite description file exist + EncryptedStream sprf(_vm, fname); + if (sprf.err()) + error("Bad SPR [%s]", fname); + + ID id; + Common::String line; + char tmpStr[kLineMax + 1]; + + for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { + if (line.size() == 0) + continue; + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + + char *p = _vm->token(tmpStr); + + id = _vm->ident(p); + switch (id) { + case kIdNear: + case kIdMTake: + case kIdFTake: + case kIdPhase: + case kIdSeq: + section = id; + break; + case kIdName: + Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); + for (p = tmpStr; *p != '='; p++); // We search for the = + setName(_vm->tail(p)); + break; + default: + if (id >= kIdNear) + break; + Seq *s; + switch (section) { + case kIdNear: + case kIdMTake: + case kIdFTake: + id = (ID)_vm->_commandHandler->com(p); + if (_actionCtrl[section]._cnt) { + CommandHandler::Command *c = &_ext->_actions[section][cnt[section]++]; + c->_commandType = CommandType(id); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + c->_ref = _vm->number(p); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + c->_val = _vm->number(p); + c->_spritePtr = nullptr; + } + break; + case kIdSeq: + s = &seq[seqcnt++]; + s->_now = atoi(p); + if (s->_now > maxnow) + maxnow = s->_now; + if ((p = _vm->token(nullptr)) == NULL) + break; + s->_next = _vm->number(p); + switch (s->_next) { + case 0xFF: + s->_next = seqcnt; + break; + case 0xFE: + s->_next = seqcnt - 1; + break; + } + if (s->_next > maxnxt) + maxnxt = s->_next; + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + s->_dx = _vm->number(p); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + s->_dy = _vm->number(p); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + s->_dz = _vm->number(p); + if ((p = _vm->token(nullptr)) == NULL) + error("Unexpected end of file! %s", fname); + s->_dly = _vm->number(p); + break; + case kIdPhase: + for (int i = 0; i < kDimMax; i++) { + char *q = p; + q[1] = '0' + i; + Bitmap b(_vm, q); + if (!b.moveHi()) + error("No EMS %s", q); + _dim[i][shpcnt] = b; + if (!shpcnt) + _hig[i] = b._h; + } + ++shpcnt; + break; + } + } + } + if (seq) { + if (maxnow >= shpcnt) + error("Bad PHASE in SEQ %s", fname); + if (maxnxt >= seqcnt) + error("Bad JUMP in SEQ %s", fname); + setSeq(seq); + } else + setSeq(_stdSeq8); + + BitmapPtr *bmp = new BitmapPtr[shpcnt]; + for (int i = 0; i < shpcnt; i++) + bmp[i] = &_dim[0][i]; + setShapeList(bmp, shpcnt); + delete[] bmp; + } + } + _reachStart = atoi(_vm->token(text)); + _reachCycle = atoi(_vm->token(nullptr)); + _sayStart = atoi(_vm->token(nullptr)); + _funStart = atoi(_vm->token(nullptr)); + _funDel = _funDel0 = (72 / _ext->_seq[0]._dly) * atoi(_vm->token(nullptr)); + int i = stepSize() / 2; + _maxDist = sqrt(double(i * i * 2)); + setCurrent(); + return this; } @@ -143,4 +313,21 @@ void Hero::setCave(int c) { warning("STUB: Hero::mapCross()"); } +bool Sprite::works(Sprite *spr) { + //if (!spr || !spr->_ext) + // return false; + + //CommandHandler::Command *c = spr->_ext->_take; + //if (c != NULL) { + // c += spr->_takePtr; + // if (c->_ref == _ref) + // if (c->_commandType != kCmdLabel || (c->_val == 0 || c->_val == _vm->_now)) + // return true; + //} + + warning("STUB: Sprite::works()"); + + return false; +} + } // End of namespace CGE2 diff --git a/engines/cge2/hero.h b/engines/cge2/hero.h index 032a46d1b3..9723be8ca8 100644 --- a/engines/cge2/hero.h +++ b/engines/cge2/hero.h @@ -96,8 +96,8 @@ public: void reach(int mode); void setCurrent(void); void setCave(int c); - void operator ++ (void); - void operator -- (void); + void operator++(void); + void operator--(void); }; } // End of namespace CGE2 diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp index 8158d6da96..e4b7dbffc7 100644 --- a/engines/cge2/vga13h.cpp +++ b/engines/cge2/vga13h.cpp @@ -144,23 +144,6 @@ void Sprite::setShapeList(BitmapPtr *shp, int cnt) { } } -bool Sprite::works(Sprite *spr) { - //if (!spr || !spr->_ext) - // return false; - - //CommandHandler::Command *c = spr->_ext->_take; - //if (c != NULL) { - // c += spr->_takePtr; - // if (c->_ref == _ref) - // if (c->_commandType != kCmdLabel || (c->_val == 0 || c->_val == _vm->_now)) - // return true; - //} - - warning("STUB: Sprite::works()"); - - return false; -} - Seq *Sprite::setSeq(Seq *seq) { expand(); @@ -264,7 +247,7 @@ Sprite *Sprite::expand() { Common::String line; char tmpStr[kLineMax + 1]; - for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()){ + for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { if (line.size() == 0) continue; Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr)); -- cgit v1.2.3