diff --git a/server/creatures/creature_manager.cpp b/server/creatures/creature_manager.cpp index 4b82eb3..dba777d 100644 --- a/server/creatures/creature_manager.cpp +++ b/server/creatures/creature_manager.cpp @@ -32,12 +32,39 @@ CreatureManager::~CreatureManager() { } //arg: a list of creatures to be updated in the clients -void CreatureManager::Update(std::list>* creatureList) { - int ret; +void CreatureManager::Update( + std::list>* creatureList, + std::list* characterList + ) +{ + //for each creature + int ret; //0 = no action, ret&1 = update clients, ret&2 = unload during cleanup step for (auto& it : elementMap) { - ret = it.second.Update(lua); + //normal update + ret = it.second.Update(lua) ? 1 : 0; + + //check for collision with a character + BoundingBox creatureBox = it.second.GetRealBounds(); + for (auto& it : *characterList) { + if (creatureBox.CheckOverlap(it->GetRealBounds())) { + //this will need updating + ret += 2; + break; + } + } + if (ret) { - creatureList->push_back(std::pair(it.first, &it.second)); + //push to the return list + creatureList->push_back(std::make_tuple(it.first, &it.second, ret)); + } + } +} + +void CreatureManager::Cleanup(std::list>* creatureList) { + //unload the given creature objects + for (auto& it : *creatureList) { + if (std::get<2>(it) & 2) { +// Unload(std::get<0>(it)); } } } diff --git a/server/creatures/creature_manager.hpp b/server/creatures/creature_manager.hpp index 353abc1..ca3c9ae 100644 --- a/server/creatures/creature_manager.hpp +++ b/server/creatures/creature_manager.hpp @@ -21,6 +21,7 @@ */ #pragma once +#include "character_data.hpp" #include "creature_data.hpp" #include "lua.hpp" @@ -30,6 +31,7 @@ #include #include #include +#include class CreatureManager { public: @@ -37,7 +39,11 @@ public: ~CreatureManager(); //common public methods - void Update(std::list>* creatureList); + void Update( + std::list>* creatureList, + std::list* characterList + ); + void Cleanup(std::list>* creatureList); int Create(std::string avatar, int scriptRef); void Unload(int uid); diff --git a/server/creatures/makefile b/server/creatures/makefile index 338a917..8d77aa0 100644 --- a/server/creatures/makefile +++ b/server/creatures/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../entities ../../common/gameplay ../../common/utilities +INCLUDES+=. .. ../characters ../entities ../../common/gameplay ../../common/utilities LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/server/entities/entity.cpp b/server/entities/entity.cpp index b55d85c..a328cc3 100644 --- a/server/entities/entity.cpp +++ b/server/entities/entity.cpp @@ -63,6 +63,10 @@ BoundingBox Entity::GetBounds() const { return bounds; } +BoundingBox Entity::GetRealBounds() const { + return bounds + origin; +} + const char* Entity::GetType() const { return type; } \ No newline at end of file diff --git a/server/entities/entity.hpp b/server/entities/entity.hpp index f5fca84..765ca30 100644 --- a/server/entities/entity.hpp +++ b/server/entities/entity.hpp @@ -41,6 +41,7 @@ public: Vector2 GetOrigin() const; Vector2 GetMotion() const; BoundingBox GetBounds() const; + BoundingBox GetRealBounds() const; const char* GetType() const;