From d7befe3a14be8f01d6d7288a6970358a4749368d Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Fri, 5 Oct 2012 22:48:02 +0200 Subject: [PATCH] begun monster vicinity checking --- src/map/Entity.h | 4 ++++ src/map/MapState.cpp | 33 +++++++++++++++++++++++++++------ src/map/MapState.h | 2 ++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/map/Entity.h b/src/map/Entity.h index 92b1b7c..872ad0c 100644 --- a/src/map/Entity.h +++ b/src/map/Entity.h @@ -56,6 +56,10 @@ public: void SetFlags(int f) { flags = f; } bool Blocking() const { return !(flags & FLAG_NONBLOCKING); } + bool Hostile() const { + // NOTE: this is a stub for testing! + return Blocking(); + } Entity *Follower() { return follower; } const Entity *Follower() const { return follower; } diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index 98e9b28..62e4802 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -179,12 +179,8 @@ bool MapState::CheckBlocking() const { void MapState::OnGridLock() { LockEntities(); - Trigger *trigger(map->TriggerAt(Vector(controlled->Position()))); - if (trigger) { - // TODO: run trigger - } - // TODO: check for adjacent monsters - // TODO: force all entities into their grid positions? + CheckMonster(); + CheckTrigger(); } void MapState::LockEntities() { @@ -197,6 +193,31 @@ void MapState::LockEntities() { } } +void MapState::CheckMonster() { + Vector coords(map->TileCoordinates(controlled->Position())); + Vector neighbor[4]; + neighbor[0] = Vector(coords.X() - 1, coords.Y()); // W + neighbor[1] = Vector(coords.X(), coords.Y() + 1); // S + neighbor[2] = Vector(coords.X() + 1, coords.Y()); // E + neighbor[3] = Vector(coords.X(), coords.Y() - 1); // N + + for (int i(0); i < 4; ++i) { + for (std::vector::iterator e(entities.begin()), end(entities.end()); e != end; ++e) { + if ((*e)->Hostile() && map->TileCoordinates((*e)->Position()) == neighbor[i]) { + // remove entity, push battle state and transition and halt all other activity + } + } + } +} + +void MapState::CheckTrigger() { + Trigger *trigger(map->TriggerAt(Vector(controlled->Position()))); + if (trigger) { + // TODO: run trigger + } + +} + void MapState::OnMove(bool realMove) { // TODO: evaluate monster movements if (realMove) { diff --git a/src/map/MapState.h b/src/map/MapState.h index 371a881..e7a75b6 100644 --- a/src/map/MapState.h +++ b/src/map/MapState.h @@ -55,6 +55,8 @@ private: void StopFollowers(Entity &); void LockEntities(); + void CheckMonster(); + void CheckTrigger(); private: Map *map; -- 2.39.2