]> git.localhorst.tv Git - l2e.git/commitdiff
begun monster vicinity checking
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 5 Oct 2012 20:48:02 +0000 (22:48 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 5 Oct 2012 20:48:02 +0000 (22:48 +0200)
src/map/Entity.h
src/map/MapState.cpp
src/map/MapState.h

index 92b1b7cf1a4ccf6cff5d3b8776ab35cd6594ba84..872ad0c92ed739ea1e714da24b132d1870223e3d 100644 (file)
@@ -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; }
index 98e9b2848b5a947f2643d1257ade0a17375ee732..62e480267ca092f31a178f2ffe2274f8792fc229 100644 (file)
@@ -179,12 +179,8 @@ bool MapState::CheckBlocking() const {
 
 void MapState::OnGridLock() {
        LockEntities();
-       Trigger *trigger(map->TriggerAt(Vector<int>(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<int> coords(map->TileCoordinates(controlled->Position()));
+       Vector<int> neighbor[4];
+       neighbor[0] = Vector<int>(coords.X() - 1, coords.Y()); // W
+       neighbor[1] = Vector<int>(coords.X(), coords.Y() + 1); // S
+       neighbor[2] = Vector<int>(coords.X() + 1, coords.Y()); // E
+       neighbor[3] = Vector<int>(coords.X(), coords.Y() - 1); // N
+
+       for (int i(0); i < 4; ++i) {
+               for (std::vector<Entity *>::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<int>(controlled->Position())));
+       if (trigger) {
+               // TODO: run trigger
+       }
+
+}
+
 void MapState::OnMove(bool realMove) {
        // TODO: evaluate monster movements
        if (realMove) {
index 371a881e5c54cc1b363ce2269dfa58e71c16b622..e7a75b6fca784f5dfb04c9a2b64154938a36dfbf 100644 (file)
@@ -55,6 +55,8 @@ private:
        void StopFollowers(Entity &);
 
        void LockEntities();
+       void CheckMonster();
+       void CheckTrigger();
 
 private:
        Map *map;