Implemented EnemyFactory, still empty
This commit is contained in:
@@ -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<int>(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;
|
||||
}
|
||||
}
|
||||
|
||||
void ServerApplication::PopCharacterFromCombat() {
|
||||
//TODO
|
||||
combat.characterList.push_back(&character);
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -22,13 +22,13 @@
|
||||
#include "enemy_factory_generic.hpp"
|
||||
|
||||
EnemyFactoryGeneric::EnemyFactoryGeneric() : EnemyFactoryInterface() {
|
||||
//
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
EnemyFactoryGeneric::~EnemyFactoryGeneric() noexcept {
|
||||
//
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
void EnemyFactoryGeneric::Generate(std::list<EnemyData>* container) {
|
||||
//TODO: fill out
|
||||
//TODO: fill this out
|
||||
}
|
||||
@@ -26,6 +26,15 @@
|
||||
|
||||
#include <list>
|
||||
|
||||
//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<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
|
||||
|
||||
@@ -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<LuaAllocator, LuaFormat> regionPager;
|
||||
EnemyFactoryGeneric enemyFactory;
|
||||
|
||||
//misc
|
||||
bool running = true;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user