From fce8c0f5952533b592de21205274f5cf9347a3b1 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 14 Aug 2013 12:52:59 +0300 Subject: [PATCH] FULLPIPE: Implement BehaviorEntry --- engines/fullpipe/behavior.cpp | 53 +++++++++++++++++++++++++++++++++-- engines/fullpipe/behavior.h | 4 ++- engines/fullpipe/gfx.cpp | 1 + engines/fullpipe/scene.cpp | 12 ++++++-- engines/fullpipe/scene.h | 1 + engines/fullpipe/statics.cpp | 8 ++++++ engines/fullpipe/statics.h | 1 + 7 files changed, 75 insertions(+), 5 deletions(-) diff --git a/engines/fullpipe/behavior.cpp b/engines/fullpipe/behavior.cpp index f2d0d5594d5..5f26efabe41 100644 --- a/engines/fullpipe/behavior.cpp +++ b/engines/fullpipe/behavior.cpp @@ -194,8 +194,57 @@ void BehaviorInfo::initObjectBehavior(CGameVar *var, Scene *sc, StaticANIObject } } -BehaviorEntry::BehaviorEntry(CGameVar *var, Scene *sc, StaticANIObject *ani, int *maxDelay) { - warning("STUB: BehaviorEntry::BehaviorEntry()"); +BehaviorEntry::BehaviorEntry(CGameVar *var, Scene *sc, StaticANIObject *ani, int *minDelay) { + _staticsId = 0; + _itemsCount = 0; + + *minDelay = -1; + + int totalPercent = 0; + _flags = 0; + _items = 0; + + Statics *st = ani->getStaticsByName(var->_varName); + if (st) + _staticsId = st->_staticsId; + + _itemsCount = var->getSubVarsCount(); + if (_itemsCount) { + _items = (BehaviorEntryInfo**)calloc(_itemsCount, sizeof(BehaviorEntryInfo *)); + + for (int i = 0; i < _itemsCount; i++) { + CGameVar *subvar = var->getSubVarByIndex(i); + + _items[i] = new BehaviorEntryInfo(subvar, sc); + totalPercent += _items[i]->_percent; + + if (_items[i]->_delay < *minDelay) + *minDelay = _items[i]->_delay; + } + + if (!*minDelay && totalPercent == 1000) + _flags |= 1; + } +} + +BehaviorEntryInfo::BehaviorEntryInfo(CGameVar *subvar, Scene *sc) { + _messageQueue = 0; + _delay = 0; + _percent = 0; + _flags = 0; + _messageQueue = sc->getMessageQueueByName(subvar->_varName); + + CGameVar *vart = subvar->getSubVarByName("dwDelay"); + if (vart) + _delay = vart->_value.intValue; + + vart = subvar->getSubVarByName("dwPercent"); + if (vart) + _percent = 0x7FFF * vart->_value.intValue / 1000; + + vart = subvar->getSubVarByName("dwFlags"); + if (vart && vart->_varType == 2 && strstr(vart->_value.stringValue, "QDESC_AUTOSTART")) + _flags |= 2; } } // End of namespace Fullpipe diff --git a/engines/fullpipe/behavior.h b/engines/fullpipe/behavior.h index ecb7d3a4283..210426ebc69 100644 --- a/engines/fullpipe/behavior.h +++ b/engines/fullpipe/behavior.h @@ -30,6 +30,8 @@ struct BehaviorEntryInfo { int _delay; uint _percent; int _flags; + + BehaviorEntryInfo(CGameVar *subvar, Scene *sc); }; struct BehaviorEntry { @@ -38,7 +40,7 @@ struct BehaviorEntry { int _flags; BehaviorEntryInfo **_items; - BehaviorEntry(CGameVar *var, Scene *sc, StaticANIObject *ani, int *maxDelay); + BehaviorEntry(CGameVar *var, Scene *sc, StaticANIObject *ani, int *minDelay); }; struct BehaviorInfo { diff --git a/engines/fullpipe/gfx.cpp b/engines/fullpipe/gfx.cpp index d294267a66a..63674078383 100644 --- a/engines/fullpipe/gfx.cpp +++ b/engines/fullpipe/gfx.cpp @@ -200,6 +200,7 @@ GameObject::GameObject() { _priority = 0; _field_20 = 0; _field_8 = 0; + _objectName = 0; } GameObject::GameObject(GameObject *src) { diff --git a/engines/fullpipe/scene.cpp b/engines/fullpipe/scene.cpp index 0bb44e4143e..7f1aeaa02c8 100644 --- a/engines/fullpipe/scene.cpp +++ b/engines/fullpipe/scene.cpp @@ -280,8 +280,8 @@ StaticANIObject *Scene::getStaticANIObject1ById(int obj, int a3) { } StaticANIObject *Scene::getStaticANIObject1ByName(char *name, int a3) { - for (CPtrList::iterator s = _staticANIObjectList1.begin(); s != _staticANIObjectList1.end(); ++s) { - StaticANIObject *o = (StaticANIObject *)*s; + for (uint n = 0; n < _staticANIObjectList1.size(); n++) { + StaticANIObject *o = (StaticANIObject *)_staticANIObjectList1[n]; if (!strcmp(o->_objectName, name) && (a3 == -1 || o->_okeyCode == a3)) return o; } @@ -340,6 +340,14 @@ MessageQueue *Scene::getMessageQueueById(int messageId) { return 0; } +MessageQueue *Scene::getMessageQueueByName(char *name) { + for (uint i = 0; i < _messageQueueList.size(); i++) + if (!strcmp(((MessageQueue *)_messageQueueList[i])->_queueName, name)) + return (MessageQueue *)_messageQueueList[i]; + + return 0; +} + void Scene::preloadMovements(CGameVar *var) { CGameVar *preload = var->getSubVarByName("PRELOAD"); if (!preload) diff --git a/engines/fullpipe/scene.h b/engines/fullpipe/scene.h index 1b052348537..1292bedf59b 100644 --- a/engines/fullpipe/scene.h +++ b/engines/fullpipe/scene.h @@ -60,6 +60,7 @@ class Scene : public Background { StaticANIObject *getStaticANIObject1ById(int obj, int a3); StaticANIObject *getStaticANIObject1ByName(char *name, int a3); MessageQueue *getMessageQueueById(int messageId); + MessageQueue *getMessageQueueByName(char *name); void deleteStaticANIObject(StaticANIObject *obj); void addStaticANIObject(StaticANIObject *obj, bool addList2); diff --git a/engines/fullpipe/statics.cpp b/engines/fullpipe/statics.cpp index bef18293b9b..de5d68983f4 100644 --- a/engines/fullpipe/statics.cpp +++ b/engines/fullpipe/statics.cpp @@ -273,6 +273,14 @@ Statics *StaticANIObject::getStaticsById(int itemId) { return 0; } +Statics *StaticANIObject::getStaticsByName(char *name) { + for (uint i = 0; i < _staticsList.size(); i++) + if (!strcmp(((Statics *)_staticsList[i])->_staticsName, name)) + return (Statics *)_staticsList[i]; + + return 0; +} + Movement *StaticANIObject::getMovementById(int itemId) { for (uint i = 0; i < _movements.size(); i++) if (((Movement *)_movements[i])->_id == itemId) diff --git a/engines/fullpipe/statics.h b/engines/fullpipe/statics.h index 97a044f95fa..40fc91dc067 100644 --- a/engines/fullpipe/statics.h +++ b/engines/fullpipe/statics.h @@ -187,6 +187,7 @@ class StaticANIObject : public GameObject { void setOXY(int x, int y); Statics *getStaticsById(int id); + Statics *getStaticsByName(char *name); Movement *getMovementById(int id); int getMovementIdById(int itemId); Movement *getMovementByName(char *name);