aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruruk2014-05-19 23:24:23 +0200
committeruruk2014-05-19 23:24:23 +0200
commitbf820481b7077ed3c6dc0599377bbbc4655ff8a7 (patch)
treef543d8a260fb6d912c19cd16a5c4710f389bfd02
parent36534403e3f49cf8eee8de17d0de9bc36ff6464b (diff)
downloadscummvm-rg350-bf820481b7077ed3c6dc0599377bbbc4655ff8a7.tar.gz
scummvm-rg350-bf820481b7077ed3c6dc0599377bbbc4655ff8a7.tar.bz2
scummvm-rg350-bf820481b7077ed3c6dc0599377bbbc4655ff8a7.zip
CGE2: Implement feedSnail().
-rw-r--r--engines/cge2/cge2.cpp9
-rw-r--r--engines/cge2/cge2.h11
-rw-r--r--engines/cge2/cge2_main.cpp40
-rw-r--r--engines/cge2/cge2_main.h1
-rw-r--r--engines/cge2/snail.cpp113
-rw-r--r--engines/cge2/snail.h2
-rw-r--r--engines/cge2/spare.cpp6
-rw-r--r--engines/cge2/vga13h.cpp10
-rw-r--r--engines/cge2/vga13h.h2
9 files changed, 186 insertions, 8 deletions
diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp
index 385fe4ea73..fe94e16387 100644
--- a/engines/cge2/cge2.cpp
+++ b/engines/cge2/cge2.cpp
@@ -36,6 +36,7 @@
#include "cge2/general.h"
#include "cge2/spare.h"
#include "cge2/events.h"
+#include "cge2/talk.h"
namespace CGE2 {
@@ -55,8 +56,10 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription)
_eyeTab[i] = nullptr;
_spare = nullptr;
_commandHandler = nullptr;
+ _commandHandlerTurbo = nullptr;
_infoLine = nullptr;
_mouse = nullptr;
+ _talk = nullptr;
_quitFlag = false;
_bitmapPalette = nullptr;
@@ -83,14 +86,15 @@ void CGE2Engine::init() {
_eyeTab[i] = new V3D();
_spare = new Spare(this);
_commandHandler = new CommandHandler(this, false);
+ _commandHandlerTurbo = new CommandHandler(this, true);
_infoLine = new InfoLine(this, kInfoW);
_mouse = new Mouse(this);
+ _talk = new Talk(this);
}
void CGE2Engine::deinit() {
delete _resman;
delete _vga;
- delete _sprite;
delete _fx;
delete _sound;
delete _midiPlayer;
@@ -105,9 +109,12 @@ void CGE2Engine::deinit() {
if (_eye != nullptr)
delete _eye;
delete _spare;
+ delete _sprite;
delete _commandHandler;
+ delete _commandHandlerTurbo;
delete _infoLine;
delete _mouse;
+ delete _talk;
}
bool CGE2Engine::hasFeature(EngineFeature f) const {
diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h
index f3a9a287c8..0a275d5c9d 100644
--- a/engines/cge2/cge2.h
+++ b/engines/cge2/cge2.h
@@ -50,6 +50,8 @@ class Spare;
class CommandHandler;
class InfoLine;
class Mouse;
+class Talk;
+class Hero;
#define kScrWidth 320
#define kScrHeight 240
@@ -67,6 +69,8 @@ enum CallbackType {
kNullCB = 0, kQGame, kMiniStep, kXScene, kSoundSetVolume
};
+enum Action { kNear, kMTake, kFTake, kActions };
+
class Font {
char _path[kPathMax];
void load();
@@ -109,6 +113,11 @@ public:
void selectPocket(int n);
void busy(bool on);
void show();
+ void feedSnail(Sprite *spr, Action snq, Hero *hero);
+ int freePockets(int sx);
+ int findActivePocket(int ref);
+ void pocFul();
+ void killText();
void setEye(V3D &e);
void setEye(const V2D& e2, int z = -kScrWidth);
@@ -146,8 +155,10 @@ public:
V3D *_eyeTab[kCaveMax];
Spare *_spare;
CommandHandler *_commandHandler;
+ CommandHandler *_commandHandlerTurbo;
InfoLine *_infoLine;
Mouse *_mouse;
+ Talk *_talk;
private:
void init();
void deinit();
diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp
index ed9f37aa41..591f28a57d 100644
--- a/engines/cge2/cge2_main.cpp
+++ b/engines/cge2/cge2_main.cpp
@@ -361,6 +361,9 @@ void CGE2Engine::caveUp(int cav) {
_sprite = _vga->_showQ->first();
if (_startupMode)
_vga->sunrise(_vga->_sysPal);
+
+ feedSnail(_vga->_showQ->locate(bakRef + 255), kNear, _heroTab[_sex]->_ptr);
+ //setDrawColors();
}
void CGE2Engine::showBak(int ref) {
@@ -518,4 +521,41 @@ bool CGE2Engine::showTitle(const char *name) {
return true;
}
+int CGE2Engine::freePockets(int sx) {
+ int n = 0;
+ for (int i = 0; i < kPocketMax; i++){
+ if (_heroTab[sx]->_pocket[i] == nullptr)
+ ++n;
+ }
+ return n;
+}
+
+int CGE2Engine::findActivePocket(int ref) {
+ for (int i = 0; i < kPocketMax; i++) {
+ Sprite *spr = _heroTab[_sex]->_pocket[i];
+ if (ref >= 0) {
+ if (spr && spr->_ref == ref)
+ return i;
+ } else if (!spr)
+ return i;
+ }
+ return -1;
+}
+
+void CGE2Engine::pocFul() {
+ Hero *h = _heroTab[_sex]->_ptr;
+ h->park();
+ _commandHandler->addCommand(kCmdWait, -1, -1, h);
+ _commandHandler->addCommand(kCmdSound, -1, 2, h);
+ _commandHandler->addCommand(kCmdSay, -1, kPocketFull + _sex, h);
+}
+
+void CGE2Engine::killText() {
+ if (!_talk)
+ return;
+
+ _commandHandlerTurbo->addCommand(kCmdKill, -1, 0, _talk);
+ _talk = NULL;
+}
+
} // End of namespace CGE2
diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h
index 9e9dca0ba2..432a6a4b10 100644
--- a/engines/cge2/cge2_main.h
+++ b/engines/cge2/cge2_main.h
@@ -35,6 +35,7 @@ namespace CGE2 {
#define kNoByte -1
#define kTabName "CGE.TAB"
#define kInfoW 140
+#define kPocketFull 170
} // End of namespace CGE2
diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp
index 52aefe2d40..c883606422 100644
--- a/engines/cge2/snail.cpp
+++ b/engines/cge2/snail.cpp
@@ -27,6 +27,7 @@
#include "cge2/snail.h"
#include "cge2/fileio.h"
+#include "cge2/hero.h"
namespace CGE2 {
@@ -90,4 +91,116 @@ int CommandHandler::com(const char *com) {
return (i < 0) ? i : i + kCmdCom0 + 1;
}
+void CGE2Engine::feedSnail(Sprite *spr, Action snq, Hero *hero) {
+ if (!spr || !spr->active())
+ return;
+
+ int cnt = spr->_actionCtrl[snq]._cnt;
+ if (cnt) {
+ byte ptr = spr->_actionCtrl[snq]._ptr;
+ CommandHandler::Command *comtab = spr->snList(snq);
+ CommandHandler::Command *c = &comtab[ptr];
+ CommandHandler::Command *p;
+ CommandHandler::Command *q = &comtab[cnt];
+
+ warning("STUB: CGE2Engine::feedSnail()");
+ // Dont bother with pockets (inventory system) for now... TODO: Implement it later!!!
+ /*
+ int pocFre = freePockets(hero->_ref & 1);
+ int pocReq = 0;
+ for (p = c; p < q && p->_commandType != kCmdNext; p++) { // scan commands
+ // drop from pocket?
+ if ((p->_commandType == kCmdSend && p->_val != _now)
+ || p->_commandType == kCmdGive) {
+ int ref = p->_ref;
+ if (ref < 0)
+ ref = spr->_ref;
+ if (findActivePocket(ref) >= 0)
+ --pocReq;
+ }
+ // make/dispose additional room?
+ if (p->_commandType == kCmdRoom) {
+ if (p->_val == 0)
+ ++pocReq;
+ else
+ --pocReq;
+ }
+ // put into pocket?
+ if (p->_commandType == kCmdKeep)
+ ++pocReq;
+ // overloaded?
+ if (pocReq > pocFre) {
+ pocFul();
+ return;
+ }
+ }*/
+
+ while (c < q) {
+ if (c->_commandType == kCmdTalk) {
+ if ((_commandHandler->_talkEnable = (c->_val != 0)) == false)
+ killText();
+ }
+ if (c->_commandType == kCmdWalk || c->_commandType == kCmdReach) {
+ if (c->_val == -1)
+ c->_val = spr->_ref;
+ }
+ if (c->_commandType == kCmdNext) {
+ Sprite *s;
+
+ switch (c->_ref) {
+ case -2:
+ s = hero;
+ break;
+ case -1:
+ s = spr;
+ break;
+ default:
+ s = _vga->_showQ->locate(c->_ref);
+ break;
+ }
+
+ if (s) {
+ if (s->_actionCtrl[snq]._cnt) {
+ int v;
+ switch (c->_val) {
+ case -1:
+ v = int(c - comtab + 1);
+ break;
+ case -2:
+ v = int(c - comtab);
+ break;
+ case -3:
+ v = -1;
+ break;
+ default:
+ v = c->_val;
+ if ((v > 255) && s)
+ v = s->labVal(snq, v >> 8);
+ break;
+ }
+ if (v >= 0)
+ s->_actionCtrl[snq]._ptr = v;
+ }
+ }
+ if (s == spr)
+ break;
+ }
+ if (c->_commandType == kCmdIf) {
+ Sprite *s = (c->_ref < 0) ? spr : _vga->_showQ->locate(c->_ref);
+ if (s) { // sprite extsts
+ if (!s->seqTest(-1)) { // not parked
+ int v = c->_val;
+ if (v > 255) if (s) v = s->labVal(snq, v >> 8);
+ c = comtab + (v - 1);
+ }
+ }
+ } else
+ _commandHandler->addCommand(c->_commandType, c->_ref, c->_val, spr);
+
+ ++c;
+ }
+ }
+
+}
+
} // End of namespace CGE2.
diff --git a/engines/cge2/snail.h b/engines/cge2/snail.h
index b364aa92d0..00e0d0912a 100644
--- a/engines/cge2/snail.h
+++ b/engines/cge2/snail.h
@@ -33,8 +33,6 @@
namespace CGE2 {
-enum Action { kNear, kMTake, kFTake, kActions };
-
enum CommandType {
kCmdCom0 = 128,
kCmdNop, // NOP :: do nothing
diff --git a/engines/cge2/spare.cpp b/engines/cge2/spare.cpp
index dbd8425eed..2f7a1381bf 100644
--- a/engines/cge2/spare.cpp
+++ b/engines/cge2/spare.cpp
@@ -34,8 +34,6 @@ void Spare::synchronize() {
}
void Spare::clear() {
- for (int i = 0; i < _container.size(); i++)
- delete _container[i];
_container.clear();
}
@@ -78,10 +76,10 @@ void Spare::dispose(Sprite *spr) {
for (int i = 0; i < _container.size(); i++) {
if (spr == _container[i]) {
_container.remove_at(i);
+ delete spr;
+ break;
}
}
-
- delete spr;
}
}
}
diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp
index 57c84e020e..d11e71f5fc 100644
--- a/engines/cge2/vga13h.cpp
+++ b/engines/cge2/vga13h.cpp
@@ -209,6 +209,16 @@ void Sprite::setName(char *newName) {
}
}
+int Sprite::labVal(Action snq, int lab) {
+ warning("STUB: Sprite::labVal()");
+ return 0;
+}
+
+CommandHandler::Command *Sprite::snList(Action type) {
+ SprExt *e = _ext;
+ return (e) ? e->_actions[type] : NULL;
+}
+
Sprite *Sprite::expand() {
if (_ext)
return this;
diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h
index 8f73f42375..6750aeebd1 100644
--- a/engines/cge2/vga13h.h
+++ b/engines/cge2/vga13h.h
@@ -127,7 +127,7 @@ public:
void setShapeList(BitmapPtr *shp, int cnt);
void moveShapesHi(void);
void moveShapesLo(void);
- int LabVal(Action snq, int lab);
+ int labVal(Action snq, int lab);
Sprite *expand();
Sprite *contract();
void backShow(void);