Implemented EnemyFactory, still empty

This commit is contained in:
Kayne Ruse
2014-05-18 03:45:36 +10:00
parent f7df4fba6c
commit bb6e248583
5 changed files with 62 additions and 11 deletions
+35 -4
View File
@@ -30,6 +30,8 @@ int ServerApplication::CreateCombatInstance(int mapIndex, int x, int y) {
combat.position.x = x; combat.position.x = x;
combat.position.y = y; combat.position.y = y;
enemyFactory.Generate(&combat.enemyList);
//explicitly postfix //explicitly postfix
return CombatData::uidCounter++; return CombatData::uidCounter++;
} }
@@ -49,6 +51,10 @@ void ServerApplication::UpdateCombat() {
}); });
//TODO: prune dead enemies //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 //update the instance once per second
if (CombatData::Clock::now() - combat.second.lastTick > std::chrono::duration<int>(1)) { if (CombatData::Clock::now() - combat.second.lastTick > std::chrono::duration<int>(1)) {
@@ -92,10 +98,35 @@ void ServerApplication::UpdateCombat() {
//TODO: reset instances with no players? //TODO: reset instances with no players?
} }
void ServerApplication::PushCharacterToCombat() { int ServerApplication::PushCharacterToCombat(int characterIndex, int combatIndex) {
//TODO CombatData& combat = combatMap[combatIndex];
CharacterData& character = characterMap[characterIndex];
//prevent duplicate entries
for (auto& it : combat.characterList) {
if (it == &character) {
//skip out
return -1;
}
} }
void ServerApplication::PopCharacterFromCombat() { combat.characterList.push_back(&character);
//TODO
return 0;
}
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;
} }
+3 -3
View File
@@ -22,13 +22,13 @@
#include "enemy_factory_generic.hpp" #include "enemy_factory_generic.hpp"
EnemyFactoryGeneric::EnemyFactoryGeneric() : EnemyFactoryInterface() { EnemyFactoryGeneric::EnemyFactoryGeneric() : EnemyFactoryInterface() {
// //EMPTY
} }
EnemyFactoryGeneric::~EnemyFactoryGeneric() noexcept { EnemyFactoryGeneric::~EnemyFactoryGeneric() noexcept {
// //EMPTY
} }
void EnemyFactoryGeneric::Generate(std::list<EnemyData>* container) { void EnemyFactoryGeneric::Generate(std::list<EnemyData>* container) {
//TODO: fill out //TODO: fill this out
} }
+18 -2
View File
@@ -26,6 +26,15 @@
#include <list> #include <list>
//TODO: move this elsewhere
enum RoomType {
OVERWORLD,
RUINS,
TOWERS,
FORESTS,
CAVES,
};
//NOTE: Based on biome, world difficulty, etc. //NOTE: Based on biome, world difficulty, etc.
class EnemyFactoryInterface { class EnemyFactoryInterface {
public: public:
@@ -33,8 +42,15 @@ public:
virtual ~EnemyFactoryInterface() = default; virtual ~EnemyFactoryInterface() = default;
virtual void Generate(std::list<EnemyData>* container) = 0; virtual void Generate(std::list<EnemyData>* 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 #endif
+4 -2
View File
@@ -27,6 +27,7 @@
#include "account_data.hpp" #include "account_data.hpp"
#include "character_data.hpp" #include "character_data.hpp"
#include "combat_data.hpp" #include "combat_data.hpp"
#include "enemy_factory_generic.hpp"
//maps //maps
#include "map_allocator.hpp" #include "map_allocator.hpp"
@@ -97,8 +98,8 @@ private:
int CreateCombatInstance(int mapIndex, int x, int y); int CreateCombatInstance(int mapIndex, int x, int y);
void UnloadCombatInstance(int uid); void UnloadCombatInstance(int uid);
void UpdateCombat(); void UpdateCombat();
void PushCharacterToCombat(); int PushCharacterToCombat(int characterIndex, int combatIndex);
void PopCharacterFromCombat(); int PopCharacterFromCombat(int characterIndex, int combatIndex);
//APIs //APIs
UDPNetworkUtility network; UDPNetworkUtility network;
@@ -115,6 +116,7 @@ private:
//TODO: I need to handle multiple map objects //TODO: I need to handle multiple map objects
//TODO: Unload regions that are distant from any characters //TODO: Unload regions that are distant from any characters
RegionPager<LuaAllocator, LuaFormat> regionPager; RegionPager<LuaAllocator, LuaFormat> regionPager;
EnemyFactoryGeneric enemyFactory;
//misc //misc
bool running = true; bool running = true;
+2
View File
@@ -136,6 +136,8 @@ void ServerApplication::Proc() {
} }
//update the internals //update the internals
//TODO: update the internals i.e. player positions //TODO: update the internals i.e. player positions
UpdateCombat();
//give the computer a break //give the computer a break
SDL_Delay(10); SDL_Delay(10);
} }