diff options
author | Nipun Garg | 2019-07-01 08:58:12 +0530 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-03 17:17:06 +0200 |
commit | f2150cd89a07e0607976a2fe580ffec8367bfd45 (patch) | |
tree | 98f03859cb76165a83b00d4a1ab19471dbb8104f /engines | |
parent | c3be6f7f2b025886489e08d74c8248f883c609bf (diff) | |
download | scummvm-rg350-f2150cd89a07e0607976a2fe580ffec8367bfd45.tar.gz scummvm-rg350-f2150cd89a07e0607976a2fe580ffec8367bfd45.tar.bz2 scummvm-rg350-f2150cd89a07e0607976a2fe580ffec8367bfd45.zip |
HDB: Add functions for Lua Entities
Diffstat (limited to 'engines')
-rw-r--r-- | engines/hdb/ai-funcs.cpp | 65 | ||||
-rw-r--r-- | engines/hdb/ai.h | 5 |
2 files changed, 69 insertions, 1 deletions
diff --git a/engines/hdb/ai-funcs.cpp b/engines/hdb/ai-funcs.cpp index f3686ef2bb..ff336bc6bf 100644 --- a/engines/hdb/ai-funcs.cpp +++ b/engines/hdb/ai-funcs.cpp @@ -596,6 +596,71 @@ void AI::getEntityXY(const char *entName, int *x, int *y) { } } +bool AI::useLuaEntity(const char *initName) { + AIEntity *e; + + for (Common::Array<AIEntity *>::iterator it = _ents->begin(); it != _ents->end(); it++) { + e = *it; + if (e->entityName && !scumm_stricmp(initName, e->entityName)) { + e->aiUse(e); + checkActionList(e, e->tileX, e->tileY, true); + if (e->luaFuncUse) + g_hdb->_lua->callFunction(e->luaFuncUse, 0); + return true; + } + } + + // Check _actions list for activation as well + for (int i = 0; i < kMaxActions; i++) { + if (_actions[i].entityName && !scumm_stricmp(initName, _actions[i].entityName)) { + checkActionList(&_dummyPlayer, _actions[i].x1, _actions[i].y1, false); + checkActionList(&_dummyPlayer, _actions[i].x2, _actions[i].y2, false); + } + } + + return false; +} + +void AI::removeLuaEntity(const char *initName) { + AIEntity *e; + + for (uint i = 0; i < _ents->size(); i++) { + e = *(_ents->begin() + i); + if (e->entityName && !scumm_stricmp(initName, e->entityName)) { + removeEntity(*(_ents->begin() + i)); + i--; + } + } +} + +void AI::animLuaEntity(const char *initName, AIState st) { + AIEntity *e; + + for (Common::Array<AIEntity *>::iterator it = _ents->begin(); it != _ents->end(); it++) { + e = *it; + if (e->entityName && !scumm_stricmp(initName, e->entityName)) { + e->state = st; + e->animFrame = 0; + e->animDelay = e->animCycle; + } + } +} + +void AI::setLuaAnimFrame(const char *initName, AIState st, int frame) { + AIEntity *e; + + for (Common::Array<AIEntity *>::iterator it = _ents->begin(); it != _ents->end(); it++) { + e = *it; + if (e->entityName && !scumm_stricmp(initName, e->entityName)) { + e->state = st; + e->animFrame = frame; + e->animDelay = e->animCycle; + animEntFrames(e); + e->state = STATE_NONE; + } + } +} + void AI::removeEntity(AIEntity *e) { _ents->erase(&e); } diff --git a/engines/hdb/ai.h b/engines/hdb/ai.h index 27fcddfe50..ccd9aed42d 100644 --- a/engines/hdb/ai.h +++ b/engines/hdb/ai.h @@ -742,6 +742,10 @@ public: AIEntity *findEntityIgnore(int x, int y, AIEntity *ignore); AIEntity *findEntityType(AIType type, int x, int y); void getEntityXY(const char *entName, int *x, int *y); + bool useLuaEntity(const char *initName); + void removeLuaEntity(const char *initName); + void animLuaEntity(const char *initName, AIState st); + void setLuaAnimFrame(const char *initName, AIState st, int frame); void removeEntity(AIEntity *e); void setEntityGoal(AIEntity *e, int x, int y); void initAllEnts(); @@ -753,7 +757,6 @@ public: void animateEntity(AIEntity *e); void animEntFrames(AIEntity *e); - void animLuaEntity(const char *initName, AIState st); void drawEnts(int x, int y, int w, int h); void drawLevel2Ents(); void animGrabbing(); |