Added creatures to the room containers
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../entities ../monsters ../rooms ../triggers ../../common/gameplay ../../common/map ../../common/network ../../common/network/packet_types ../../common/utilities
|
INCLUDES+=. .. ../creatures ../entities ../monsters ../rooms ../triggers ../../common/gameplay ../../common/map ../../common/network ../../common/network/packet_types ../../common/utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,14 @@ CreatureManager::~CreatureManager() {
|
|||||||
UnloadAll();
|
UnloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreatureManager::Update() {
|
||||||
|
for (auto& it : elementMap) {
|
||||||
|
it.second.Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int CreatureManager::Create(std::string avatar, int scriptRef) {
|
int CreatureManager::Create(std::string avatar, int scriptRef) {
|
||||||
//implicitly create the new
|
//implicitly create the new object
|
||||||
elementMap.emplace(counter, CreatureData(avatar, scriptRef));
|
elementMap.emplace(counter, CreatureData(avatar, scriptRef));
|
||||||
|
|
||||||
//TODO: do various things like saving to the database
|
//TODO: do various things like saving to the database
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ public:
|
|||||||
~CreatureManager();
|
~CreatureManager();
|
||||||
|
|
||||||
//common public methods
|
//common public methods
|
||||||
|
void Update();
|
||||||
|
|
||||||
int Create(std::string avatar, int scriptRef);
|
int Create(std::string avatar, int scriptRef);
|
||||||
void Unload(int uid);
|
void Unload(int uid);
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ static int create(lua_State* L) {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TOOD: this needs to take the userdata as a parameter too
|
//TOOD: overload this to take the userdata as a parameter
|
||||||
static int unload(lua_State* L) {
|
static int unload(lua_State* L) {
|
||||||
CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1));
|
CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1));
|
||||||
mgr->Unload(lua_tointeger(L, 2));
|
mgr->Unload(lua_tointeger(L, 2));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../characters ../entities ../monsters ../triggers ../../common/gameplay ../../common/map ../../common/utilities
|
INCLUDES+=. .. ../characters ../creatures ../entities ../monsters ../triggers ../../common/gameplay ../../common/map ../../common/utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
+12
-16
@@ -50,20 +50,18 @@ static int getTilesetName(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int getCreatureMgr(lua_State* L) {
|
||||||
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetCreatureMgr()) );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int getPager(lua_State* L) {
|
static int getPager(lua_State* L) {
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetPager()) );
|
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetPager()) );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
static int getMonsterMgr(lua_State* L) {
|
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
|
||||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetMonsterMgr()) );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int getTriggerMgr(lua_State* L) {
|
static int getTriggerMgr(lua_State* L) {
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetTriggerMgr()) );
|
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetTriggerMgr()) );
|
||||||
@@ -87,12 +85,11 @@ static int forEachCharacter(lua_State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static int forEachCreature(lua_State* L) {
|
||||||
static int forEachMonster(lua_State* L) {
|
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
MonsterManager* monsterMgr = room->GetMonsterMgr();
|
CreatureManager* creatureMgr = room->GetCreatureMgr();
|
||||||
//pass each monster to the given function
|
//pass each creature to the given function
|
||||||
for (auto& it : *monsterMgr->GetContainer()) {
|
for (auto& it : *creatureMgr->GetContainer()) {
|
||||||
lua_pushvalue(L, -1);
|
lua_pushvalue(L, -1);
|
||||||
lua_pushlightuserdata(L, static_cast<void*>(&it.second));
|
lua_pushlightuserdata(L, static_cast<void*>(&it.second));
|
||||||
//call each iteration, throwing an exception if something happened
|
//call each iteration, throwing an exception if something happened
|
||||||
@@ -105,7 +102,6 @@ static int forEachMonster(lua_State* L) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
static int setOnTick(lua_State* L) {
|
static int setOnTick(lua_State* L) {
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
@@ -139,12 +135,12 @@ static const luaL_Reg roomLib[] = {
|
|||||||
{"SetTileset", setTilesetName},
|
{"SetTileset", setTilesetName},
|
||||||
{"GetTileset", getTilesetName},
|
{"GetTileset", getTilesetName},
|
||||||
|
|
||||||
|
{"GetCreatureMgr",getCreatureMgr},
|
||||||
{"GetPager",getPager},
|
{"GetPager",getPager},
|
||||||
// {"GetMonsterMgr",getMonsterMgr},
|
|
||||||
{"GetTriggerMgr",getTriggerMgr},
|
{"GetTriggerMgr",getTriggerMgr},
|
||||||
|
|
||||||
{"ForEachCharacter", forEachCharacter},
|
{"ForEachCharacter", forEachCharacter},
|
||||||
// {"ForEachMonster", forEachMonster},
|
{"ForEachCreature", forEachCreature},
|
||||||
|
|
||||||
{"SetOnTick", setOnTick},
|
{"SetOnTick", setOnTick},
|
||||||
{"GetOnTick", getOnTick},
|
{"GetOnTick", getOnTick},
|
||||||
|
|||||||
@@ -43,10 +43,10 @@ void RoomData::RunFrame() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//update the entities in the room
|
//update the entities in the room
|
||||||
|
creatureMgr.Update();
|
||||||
for (auto& it : characterList) {
|
for (auto& it : characterList) {
|
||||||
it->Update();
|
it->Update();
|
||||||
}
|
}
|
||||||
//TODO: (3) iterate through the monster map
|
|
||||||
//TODO: (3) trigger script for monsters
|
//TODO: (3) trigger script for monsters
|
||||||
|
|
||||||
//build a list of game entities
|
//build a list of game entities
|
||||||
@@ -100,6 +100,8 @@ void RoomData::RunFrame() {
|
|||||||
//next
|
//next
|
||||||
entityStack.pop();
|
entityStack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: creature/character collisions
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string RoomData::SetName(std::string s) {
|
std::string RoomData::SetName(std::string s) {
|
||||||
@@ -118,6 +120,14 @@ std::string RoomData::GetTileset() {
|
|||||||
return tilesetName;
|
return tilesetName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::list<CharacterData*>* RoomData::GetCharacterList() {
|
||||||
|
return &characterList;
|
||||||
|
}
|
||||||
|
|
||||||
|
CreatureManager* RoomData::GetCreatureMgr() {
|
||||||
|
return &creatureMgr;
|
||||||
|
}
|
||||||
|
|
||||||
RegionPagerLua* RoomData::GetPager() {
|
RegionPagerLua* RoomData::GetPager() {
|
||||||
return &pager;
|
return &pager;
|
||||||
}
|
}
|
||||||
@@ -126,10 +136,6 @@ TriggerManager* RoomData::GetTriggerMgr() {
|
|||||||
return &triggerMgr;
|
return &triggerMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<CharacterData*>* RoomData::GetCharacterList() {
|
|
||||||
return &characterList;
|
|
||||||
}
|
|
||||||
|
|
||||||
lua_State* RoomData::SetLuaState(lua_State* L) {
|
lua_State* RoomData::SetLuaState(lua_State* L) {
|
||||||
lua = L;
|
lua = L;
|
||||||
pager.SetLuaState(lua);
|
pager.SetLuaState(lua);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "character_data.hpp"
|
#include "character_data.hpp"
|
||||||
|
#include "creature_manager.hpp"
|
||||||
#include "region_pager_lua.hpp"
|
#include "region_pager_lua.hpp"
|
||||||
#include "trigger_manager.hpp"
|
#include "trigger_manager.hpp"
|
||||||
|
|
||||||
@@ -47,9 +48,10 @@ public:
|
|||||||
std::string SetTileset(std::string);
|
std::string SetTileset(std::string);
|
||||||
std::string GetTileset();
|
std::string GetTileset();
|
||||||
|
|
||||||
|
std::list<CharacterData*>* GetCharacterList();
|
||||||
|
CreatureManager* GetCreatureMgr();
|
||||||
RegionPagerLua* GetPager();
|
RegionPagerLua* GetPager();
|
||||||
TriggerManager* GetTriggerMgr();
|
TriggerManager* GetTriggerMgr();
|
||||||
std::list<CharacterData*>* GetCharacterList();
|
|
||||||
|
|
||||||
//API interfaces
|
//API interfaces
|
||||||
lua_State* SetLuaState(lua_State* L);
|
lua_State* SetLuaState(lua_State* L);
|
||||||
@@ -68,9 +70,10 @@ private:
|
|||||||
std::string tilesetName;
|
std::string tilesetName;
|
||||||
|
|
||||||
//members
|
//members
|
||||||
|
std::list<CharacterData*> characterList;
|
||||||
|
CreatureManager creatureMgr;
|
||||||
RegionPagerLua pager;
|
RegionPagerLua pager;
|
||||||
TriggerManager triggerMgr;
|
TriggerManager triggerMgr;
|
||||||
std::list<CharacterData*> characterList;
|
|
||||||
|
|
||||||
//API
|
//API
|
||||||
lua_State* lua = nullptr;
|
lua_State* lua = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user