aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/fullpipe/behavior.cpp66
-rw-r--r--engines/fullpipe/behavior.h34
2 files changed, 83 insertions, 17 deletions
diff --git a/engines/fullpipe/behavior.cpp b/engines/fullpipe/behavior.cpp
index 4f9e50d96b..cf1a436c6a 100644
--- a/engines/fullpipe/behavior.cpp
+++ b/engines/fullpipe/behavior.cpp
@@ -24,6 +24,8 @@
#include "fullpipe/objects.h"
#include "fullpipe/behavior.h"
+#include "fullpipe/statics.h"
+#include "fullpipe/messages.h"
namespace Fullpipe {
@@ -37,7 +39,69 @@ void BehaviorManager::initBehavior(Scene *scene, CGameVar *var) {
}
void BehaviorManager::updateBehaviors() {
- warning("STUB: BehaviorManager::updateBehaviors()");
+ if (!_isActive)
+ return;
+
+ for (uint i = 0; i < _behaviors.size(); i++) {
+ BehaviorInfo *beh = _behaviors[i];
+
+ if (!beh->_ani) {
+ beh->_counter++;
+ if (beh->_counter >= beh->_counterMax)
+ updateBehavior(beh, beh->_bheItems[0]);
+
+ continue;
+ }
+
+ if (beh->_ani->_movement || !(beh->_ani->_flags & 4) || (beh->_ani->_flags & 2)) {
+ beh->_staticsId = 0;
+ continue;
+ }
+
+ if (beh->_ani->_statics->_staticsId == beh->_staticsId) {
+ beh->_counter++;
+ if (beh->_counter >= beh->_counterMax) {
+ if (beh->_subIndex >= 0 && !(beh->_flags & 1) && beh->_ani->_messageQueueId <= 0)
+ updateStaticAniBehavior(beh->_ani, beh->_counter, beh->_bheItems[beh->_subIndex]);
+ }
+ } else {
+ beh->_staticsId = beh->_ani->_statics->_staticsId;
+ beh->_counter = 0;
+ beh->_subIndex = -1;
+
+ for (int j = 0; j < beh->_itemsCount; j++)
+ if (beh->_bheItems[j]->_staticsId == beh->_staticsId) {
+ beh->_subIndex = j;
+ break;
+ }
+
+ }
+ }
+}
+
+void BehaviorManager::updateBehavior(BehaviorInfo *behaviorInfo, BehaviorEntry *entry) {
+ for (int i = 0; i < entry->_itemsCount; i++) {
+ BehaviorEntryInfo *bhi = entry->_items[i];
+ if (!(bhi->_flags & 1)) {
+ if (bhi->_flags & 2) {
+ MessageQueue *mq = new MessageQueue(entry->_items[i]->_messageQueue, 0, 1);
+
+ mq->sendNextCommand();
+
+ entry->_items[i]->_flags &= 0xFFFFFFFD;
+ } else if (behaviorInfo->_counter >= bhi->_delay && bhi->_percent && g_fullpipe->_rnd->getRandomNumber(32767) <= entry->_items[i]->_percent) {
+ MessageQueue *mq = new MessageQueue(entry->_items[i]->_messageQueue, 0, 1);
+
+ mq->sendNextCommand();
+
+ behaviorInfo->_counter = 0;
+ }
+ }
+ }
+}
+
+void BehaviorManager::updateStaticAniBehavior(StaticANIObject *ani, unsigned int delay, BehaviorEntry *behaviorEntry) {
+ warning("STUB: BehaviorManager::updateStaticAniBehavior()");
}
} // End of namespace Fullpipe
diff --git a/engines/fullpipe/behavior.h b/engines/fullpipe/behavior.h
index ea618fdfd6..5029b3ee17 100644
--- a/engines/fullpipe/behavior.h
+++ b/engines/fullpipe/behavior.h
@@ -25,22 +25,10 @@
namespace Fullpipe {
-class BehaviorManager : public CObject {
- CObArray _behaviors;
- Scene *_scene;
- bool _isActive;
-
- public:
- BehaviorManager();
-
- void initBehavior(Scene *scene, CGameVar *var);
- void updateBehaviors();
-};
-
struct BehaviorEntryInfo {
- int _messageQueue;
+ MessageQueue *_messageQueue;
int _delay;
- int _percent;
+ uint _percent;
int _flags;
};
@@ -48,7 +36,7 @@ struct BehaviorEntry {
int _staticsId;
int _itemsCount;
int _flags;
- BehaviorEntryInfo *_items;
+ BehaviorEntryInfo **_items;
};
struct BehaviorInfo {
@@ -59,7 +47,21 @@ struct BehaviorInfo {
int _flags;
int _subIndex;
int _itemsCount;
- BehaviorEntryInfo *_items;
+ Common::Array<BehaviorEntry *> _bheItems;
+};
+
+class BehaviorManager : public CObject {
+ Common::Array<BehaviorInfo *> _behaviors;
+ Scene *_scene;
+ bool _isActive;
+
+ public:
+ BehaviorManager();
+
+ void initBehavior(Scene *scene, CGameVar *var);
+ void updateBehaviors();
+ void updateBehavior(BehaviorInfo *behaviorInfo, BehaviorEntry *entry);
+ void updateStaticAniBehavior(StaticANIObject *ani, unsigned int delay, BehaviorEntry *behaviorEntry);
};
} // End of namespace Fullpipe