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