From bb6e248583a9d57cb0617afbd05318bacdc93614 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 18 May 2014 03:45:36 +1000 Subject: [PATCH] Implemented EnemyFactory, still empty --- server/combat_management.cpp | 39 +++++++++++++++++++++++++++--- server/enemy_factory_generic.cpp | 6 ++--- server/enemy_factory_interface.hpp | 20 +++++++++++++-- server/server_application.hpp | 6 +++-- server/server_internals.cpp | 2 ++ 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/server/combat_management.cpp b/server/combat_management.cpp index 7376f5a..43a87bd 100644 --- a/server/combat_management.cpp +++ b/server/combat_management.cpp @@ -30,6 +30,8 @@ int ServerApplication::CreateCombatInstance(int mapIndex, int x, int y) { combat.position.x = x; combat.position.y = y; + enemyFactory.Generate(&combat.enemyList); + //explicitly postfix return CombatData::uidCounter++; } @@ -49,6 +51,10 @@ void ServerApplication::UpdateCombat() { }); //TODO: prune dead enemies + //NOTE: This needs to invoke some sort of on death script +// erase_if(combat.second.enemyList, [](EnemyData* it) -> bool { +// return it.health <= 0; +// }); //update the instance once per second if (CombatData::Clock::now() - combat.second.lastTick > std::chrono::duration(1)) { @@ -92,10 +98,35 @@ void ServerApplication::UpdateCombat() { //TODO: reset instances with no players? } -void ServerApplication::PushCharacterToCombat() { - //TODO +int ServerApplication::PushCharacterToCombat(int characterIndex, int combatIndex) { + CombatData& combat = combatMap[combatIndex]; + CharacterData& character = characterMap[characterIndex]; + + //prevent duplicate entries + for (auto& it : combat.characterList) { + if (it == &character) { + //skip out + return -1; + } + } + + combat.characterList.push_back(&character); + + return 0; } -void ServerApplication::PopCharacterFromCombat() { - //TODO +int ServerApplication::PopCharacterFromCombat(int characterIndex, int combatIndex) { + CombatData& combat = combatMap[combatIndex]; + CharacterData& character = characterMap[characterIndex]; + + //derpy + //TODO: should the list point to the std::pair? + for (auto it = combat.characterList.begin(); it != combat.characterList.end(); it++) { + if (*it == &character) { + combat.characterList.erase(it); + return 0; + } + } + + return -1; } \ No newline at end of file diff --git a/server/enemy_factory_generic.cpp b/server/enemy_factory_generic.cpp index 4c83281..e8dd647 100644 --- a/server/enemy_factory_generic.cpp +++ b/server/enemy_factory_generic.cpp @@ -22,13 +22,13 @@ #include "enemy_factory_generic.hpp" EnemyFactoryGeneric::EnemyFactoryGeneric() : EnemyFactoryInterface() { - // + //EMPTY } EnemyFactoryGeneric::~EnemyFactoryGeneric() noexcept { - // + //EMPTY } void EnemyFactoryGeneric::Generate(std::list* container) { - //TODO: fill out + //TODO: fill this out } \ No newline at end of file diff --git a/server/enemy_factory_interface.hpp b/server/enemy_factory_interface.hpp index 6582145..a1c141b 100644 --- a/server/enemy_factory_interface.hpp +++ b/server/enemy_factory_interface.hpp @@ -26,6 +26,15 @@ #include +//TODO: move this elsewhere +enum RoomType { + OVERWORLD, + RUINS, + TOWERS, + FORESTS, + CAVES, +}; + //NOTE: Based on biome, world difficulty, etc. class EnemyFactoryInterface { public: @@ -33,8 +42,15 @@ public: virtual ~EnemyFactoryInterface() = default; virtual void Generate(std::list* container) = 0; -private: - //TODO: hold the parameters here? + + //control the difficulty of the room + RoomType SetType(RoomType t) { return type = t; } + int SetDifficulty(int d) { return difficulty = d; } + RoomType GetType() { return type; } + int GetDifficulty() { return difficulty; } +protected: + RoomType type = RoomType::OVERWORLD; + int difficulty = 0; }; #endif diff --git a/server/server_application.hpp b/server/server_application.hpp index 4dd50ea..a05ab9b 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -27,6 +27,7 @@ #include "account_data.hpp" #include "character_data.hpp" #include "combat_data.hpp" +#include "enemy_factory_generic.hpp" //maps #include "map_allocator.hpp" @@ -97,8 +98,8 @@ private: int CreateCombatInstance(int mapIndex, int x, int y); void UnloadCombatInstance(int uid); void UpdateCombat(); - void PushCharacterToCombat(); - void PopCharacterFromCombat(); + int PushCharacterToCombat(int characterIndex, int combatIndex); + int PopCharacterFromCombat(int characterIndex, int combatIndex); //APIs UDPNetworkUtility network; @@ -115,6 +116,7 @@ private: //TODO: I need to handle multiple map objects //TODO: Unload regions that are distant from any characters RegionPager regionPager; + EnemyFactoryGeneric enemyFactory; //misc bool running = true; diff --git a/server/server_internals.cpp b/server/server_internals.cpp index abd16e8..7fed732 100644 --- a/server/server_internals.cpp +++ b/server/server_internals.cpp @@ -136,6 +136,8 @@ void ServerApplication::Proc() { } //update the internals //TODO: update the internals i.e. player positions + + UpdateCombat(); //give the computer a break SDL_Delay(10); }