diff options
author | Nipun Garg | 2019-06-20 18:14:07 +0530 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-03 17:16:52 +0200 |
commit | 054a9a55301b49a657c714c155ccaea29f896d41 (patch) | |
tree | 54be96881d6a90136407ee6275e822d7539c50a0 /engines/hdb | |
parent | b2d1bbf5f50e0d8834a49df90856224b4545af24 (diff) | |
download | scummvm-rg350-054a9a55301b49a657c714c155ccaea29f896d41.tar.gz scummvm-rg350-054a9a55301b49a657c714c155ccaea29f896d41.tar.bz2 scummvm-rg350-054a9a55301b49a657c714c155ccaea29f896d41.zip |
HDB: Add setEntityGoal()
Diffstat (limited to 'engines/hdb')
-rw-r--r-- | engines/hdb/ai-funcs.cpp | 38 | ||||
-rw-r--r-- | engines/hdb/ai.h | 3 |
2 files changed, 40 insertions, 1 deletions
diff --git a/engines/hdb/ai-funcs.cpp b/engines/hdb/ai-funcs.cpp index 8df88cf11c..6ccc982761 100644 --- a/engines/hdb/ai-funcs.cpp +++ b/engines/hdb/ai-funcs.cpp @@ -499,6 +499,44 @@ void AI::removeEntity(AIEntity *e) { _ents->erase(&e); } +void AI::setEntityGoal(AIEntity *e, int x, int y) { + int xv, yv; + + e->xVel = e->yVel = 0; + + xv = x - e->tileX; + if (xv < 0) { + e->xVel = -e->moveSpeed; + e->state = STATE_MOVELEFT; + e->dir = DIR_LEFT; + } else if (xv > 0) { + e->xVel = e->moveSpeed; + e->state = STATE_MOVERIGHT; + e->dir = DIR_RIGHT; + } + + yv = y - e->tileY; + if (yv < 0) { + e->yVel = -e->moveSpeed; + e->state = STATE_MOVELEFT; + e->dir = DIR_LEFT; + } else if (yv > 0) { + e->yVel = e->moveSpeed; + e->state = STATE_MOVERIGHT; + e->dir = DIR_RIGHT; + } + + if (e->type == AI_GUY && _playerRunning) { + e->xVel = e->xVel << 1; + e->yVel = e->yVel << 1; + } + + e->goalX = x; + e->goalY = y; + e->animFrame = 0; + e->drawXOff = e->drawYOff = 0; +} + // Initializes each entity after map is loaded void AI::initAllEnts() { for (Common::Array<AIEntity *>::iterator it = _ents->begin(); it != _ents->end(); it++) { diff --git a/engines/hdb/ai.h b/engines/hdb/ai.h index 378318f3a8..d6af20d3d6 100644 --- a/engines/hdb/ai.h +++ b/engines/hdb/ai.h @@ -359,7 +359,7 @@ struct AIEntity { uint16 drawXOff, drawYOff; // might need a drawing offset uint16 onScreen; // FLAG: is this entity onscreen? uint16 moveSpeed; // movement speed of this entity - uint16 xVel, yVel; // movement values + int16 xVel, yVel; // movement values uint16 tileX, tileY; uint16 goalX, goalY; // where we're trying to go - TILE COORDS uint16 touchpX, touchpY, touchpTile, touchpWait; // ACTION index a touchplate is using, which you're on @@ -460,6 +460,7 @@ public: void stopEntity(AIEntity *e); AIEntity *locateEntity(const char *luaName); void removeEntity(AIEntity *e); + void setEntityGoal(AIEntity *e, int x, int y); void initAllEnts(); bool getTableEnt(AIType type); bool walkThroughEnt(AIType type); |