Renamed monsters to creatures in the code
This commit is contained in:
@@ -19,40 +19,40 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "monster_api.hpp"
|
||||
#include "creature_api.hpp"
|
||||
|
||||
#include "monster_data.hpp"
|
||||
#include "creature_data.hpp"
|
||||
|
||||
#include "entity_api.hpp"
|
||||
|
||||
static int setAvatar(lua_State* L) {
|
||||
MonsterData* monster = static_cast<MonsterData*>(lua_touserdata(L, 1));
|
||||
monster->SetAvatar(lua_tostring(L, 2));
|
||||
CreatureData* creature = static_cast<CreatureData*>(lua_touserdata(L, 1));
|
||||
creature->SetAvatar(lua_tostring(L, 2));
|
||||
//TODO: (1) send an update to the clients?
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getAvatar(lua_State* L) {
|
||||
MonsterData* monster = static_cast<MonsterData*>(lua_touserdata(L, 1));
|
||||
lua_pushstring(L, monster->GetAvatar().c_str());
|
||||
CreatureData* creature = static_cast<CreatureData*>(lua_touserdata(L, 1));
|
||||
lua_pushstring(L, creature->GetAvatar().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int setScript(lua_State* L) {
|
||||
MonsterData* monster = static_cast<MonsterData*>(lua_touserdata(L, 1));
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, monster->GetScriptReference());
|
||||
monster->SetScriptReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
||||
CreatureData* creature = static_cast<CreatureData*>(lua_touserdata(L, 1));
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, creature->GetScriptReference());
|
||||
creature->SetScriptReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getScript(lua_State* L) {
|
||||
MonsterData* monster = static_cast<MonsterData*>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, monster->GetScriptReference());
|
||||
CreatureData* creature = static_cast<CreatureData*>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, creature->GetScriptReference());
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg monsterLib[] = {
|
||||
static const luaL_Reg creatureLib[] = {
|
||||
{"SetAvatar", setAvatar},
|
||||
{"GetAvatar", getAvatar},
|
||||
{"SetScript", setScript},
|
||||
@@ -60,12 +60,12 @@ static const luaL_Reg monsterLib[] = {
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
LUAMOD_API int openMonsterAPI(lua_State* L) {
|
||||
LUAMOD_API int openCreatureAPI(lua_State* L) {
|
||||
//get the parent table
|
||||
luaL_requiref(L, TORTUGA_ENTITY_API, openEntityAPI, false);
|
||||
|
||||
//the local table
|
||||
luaL_newlib(L, monsterLib);
|
||||
luaL_newlib(L, creatureLib);
|
||||
|
||||
//merge the local table into the parent table
|
||||
lua_pushnil(L); //first key
|
||||
|
||||
@@ -23,5 +23,5 @@
|
||||
|
||||
#include "lua.hpp"
|
||||
|
||||
#define TORTUGA_MONSTER_API "monster"
|
||||
LUAMOD_API int openMonsterAPI(lua_State* L);
|
||||
#define TORTUGA_CREATURE_API "creature"
|
||||
LUAMOD_API int openCreatureAPI(lua_State* L);
|
||||
|
||||
@@ -19,17 +19,17 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "monster_data.hpp"
|
||||
#include "creature_data.hpp"
|
||||
|
||||
MonsterData::MonsterData(std::string _avatar, int _scriptRef):
|
||||
Entity("monster"),
|
||||
CreatureData::CreatureData(std::string _avatar, int _scriptRef):
|
||||
Entity("creature"),
|
||||
avatar(_avatar),
|
||||
scriptRef(_scriptRef)
|
||||
{
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
void MonsterData::Update() {
|
||||
void CreatureData::Update() {
|
||||
Entity::Update();
|
||||
//TODO: (0) call the script reference
|
||||
}
|
||||
@@ -38,18 +38,18 @@ void MonsterData::Update() {
|
||||
//accessors & mutators
|
||||
//-------------------------
|
||||
|
||||
std::string MonsterData::SetAvatar(std::string s) {
|
||||
std::string CreatureData::SetAvatar(std::string s) {
|
||||
return avatar = s;
|
||||
}
|
||||
|
||||
std::string MonsterData::GetAvatar() {
|
||||
std::string CreatureData::GetAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
int MonsterData::SetScriptReference(int i) {
|
||||
int CreatureData::SetScriptReference(int i) {
|
||||
return scriptRef = i;
|
||||
}
|
||||
|
||||
int MonsterData::GetScriptReference() {
|
||||
int CreatureData::GetScriptReference() {
|
||||
return scriptRef;
|
||||
}
|
||||
@@ -27,17 +27,17 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
/* DOCS: Monster attributes, read more
|
||||
/* DOCS: Creature attributes, read more
|
||||
* species (avatar, script)
|
||||
* level
|
||||
* health/mana
|
||||
* permadeath/respawn
|
||||
*/
|
||||
|
||||
class MonsterData: public Entity {
|
||||
class CreatureData: public Entity {
|
||||
public:
|
||||
MonsterData(std::string avatar, int scriptRef);
|
||||
~MonsterData() = default;
|
||||
CreatureData(std::string avatar, int scriptRef);
|
||||
~CreatureData() = default;
|
||||
|
||||
virtual void Update();
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
int GetScriptReference();
|
||||
|
||||
private:
|
||||
friend class MonsterManager;
|
||||
friend class CreatureManager;
|
||||
|
||||
std::string avatar;
|
||||
int scriptRef = LUA_NOREF;
|
||||
|
||||
@@ -19,36 +19,36 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "monster_manager.hpp"
|
||||
#include "creature_manager.hpp"
|
||||
|
||||
MonsterManager::MonsterManager() {
|
||||
CreatureManager::CreatureManager() {
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
MonsterManager::~MonsterManager() {
|
||||
CreatureManager::~CreatureManager() {
|
||||
UnloadAll();
|
||||
}
|
||||
|
||||
int MonsterManager::Create(std::string avatar, int scriptRef) {
|
||||
int CreatureManager::Create(std::string avatar, int scriptRef) {
|
||||
//implicitly create the new
|
||||
elementMap.emplace(counter, MonsterData(avatar, scriptRef));
|
||||
elementMap.emplace(counter, CreatureData(avatar, scriptRef));
|
||||
|
||||
//TODO: do various things like saving to the database
|
||||
return counter++;
|
||||
}
|
||||
|
||||
//TODO: (1) monster load, save
|
||||
//TODO: (1) creature load, save
|
||||
|
||||
void MonsterManager::Unload(int uid) {
|
||||
void CreatureManager::Unload(int uid) {
|
||||
elementMap.erase(uid);
|
||||
}
|
||||
|
||||
void MonsterManager::UnloadAll() {
|
||||
void CreatureManager::UnloadAll() {
|
||||
elementMap.clear();
|
||||
}
|
||||
|
||||
void MonsterManager::UnloadIf(std::function<bool(std::pair<const int, MonsterData const&>)> fn) {
|
||||
std::map<int, MonsterData>::iterator it = elementMap.begin();
|
||||
void CreatureManager::UnloadIf(std::function<bool(std::pair<const int, CreatureData const&>)> fn) {
|
||||
std::map<int, CreatureData>::iterator it = elementMap.begin();
|
||||
while (it != elementMap.end()) {
|
||||
if (fn(*it)) {
|
||||
it = elementMap.erase(it);
|
||||
@@ -59,8 +59,8 @@ void MonsterManager::UnloadIf(std::function<bool(std::pair<const int, MonsterDat
|
||||
}
|
||||
}
|
||||
|
||||
MonsterData* MonsterManager::Get(int uid) {
|
||||
std::map<int, MonsterData>::iterator it = elementMap.find(uid);
|
||||
CreatureData* CreatureManager::Get(int uid) {
|
||||
std::map<int, CreatureData>::iterator it = elementMap.find(uid);
|
||||
|
||||
if (it == elementMap.end()) {
|
||||
return nullptr;
|
||||
@@ -69,26 +69,26 @@ MonsterData* MonsterManager::Get(int uid) {
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
int MonsterManager::GetLoadedCount() {
|
||||
int CreatureManager::GetLoadedCount() {
|
||||
return elementMap.size();
|
||||
}
|
||||
|
||||
std::map<int, MonsterData>* MonsterManager::GetContainer() {
|
||||
std::map<int, CreatureData>* CreatureManager::GetContainer() {
|
||||
return &elementMap;
|
||||
}
|
||||
|
||||
lua_State* MonsterManager::SetLuaState(lua_State* L) {
|
||||
lua_State* CreatureManager::SetLuaState(lua_State* L) {
|
||||
return lua = L;
|
||||
}
|
||||
|
||||
lua_State* MonsterManager::GetLuaState() {
|
||||
lua_State* CreatureManager::GetLuaState() {
|
||||
return lua;
|
||||
}
|
||||
|
||||
sqlite3* MonsterManager::SetDatabase(sqlite3* db) {
|
||||
sqlite3* CreatureManager::SetDatabase(sqlite3* db) {
|
||||
return database = db;
|
||||
}
|
||||
|
||||
sqlite3* MonsterManager::GetDatabase() {
|
||||
sqlite3* CreatureManager::GetDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "monster_data.hpp"
|
||||
#include "creature_data.hpp"
|
||||
|
||||
#include "lua.hpp"
|
||||
#include "sqlite3.h"
|
||||
@@ -30,22 +30,22 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class MonsterManager {
|
||||
class CreatureManager {
|
||||
public:
|
||||
MonsterManager();
|
||||
~MonsterManager();
|
||||
CreatureManager();
|
||||
~CreatureManager();
|
||||
|
||||
//common public methods
|
||||
int Create(std::string avatar, int scriptRef);
|
||||
void Unload(int uid);
|
||||
|
||||
void UnloadAll();
|
||||
void UnloadIf(std::function<bool(std::pair<const int, MonsterData const&>)> fn);
|
||||
void UnloadIf(std::function<bool(std::pair<const int, CreatureData const&>)> fn);
|
||||
|
||||
//accessors & mutators
|
||||
MonsterData* Get(int uid);
|
||||
CreatureData* Get(int uid);
|
||||
int GetLoadedCount();
|
||||
std::map<int, MonsterData>* GetContainer();
|
||||
std::map<int, CreatureData>* GetContainer();
|
||||
|
||||
//hooks
|
||||
lua_State* SetLuaState(lua_State* L);
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
|
||||
private:
|
||||
//members
|
||||
std::map<int, MonsterData> elementMap;
|
||||
std::map<int, CreatureData> elementMap;
|
||||
int counter = 0;
|
||||
lua_State* lua = nullptr;
|
||||
sqlite3* database = nullptr;
|
||||
|
||||
@@ -19,52 +19,52 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "monster_manager_api.hpp"
|
||||
#include "creature_manager_api.hpp"
|
||||
|
||||
#include "monster_manager.hpp"
|
||||
#include "creature_manager.hpp"
|
||||
|
||||
static int create(lua_State* L) {
|
||||
MonsterManager* mgr = static_cast<MonsterManager* const>(lua_touserdata(L, 1));
|
||||
CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1));
|
||||
int index = mgr->Create(lua_tostring(L, 2), lua_tointeger(L, 3));
|
||||
MonsterData* monster = mgr->Get(index);
|
||||
lua_pushlightuserdata(L, static_cast<void*>(monster));
|
||||
CreatureData* creature = mgr->Get(index);
|
||||
lua_pushlightuserdata(L, static_cast<void*>(creature));
|
||||
lua_pushinteger(L, index);
|
||||
return 2;
|
||||
}
|
||||
|
||||
//TOOD: this needs to take the userdata as a parameter too
|
||||
static int unload(lua_State* L) {
|
||||
MonsterManager* mgr = static_cast<MonsterManager* const>(lua_touserdata(L, 1));
|
||||
CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1));
|
||||
mgr->Unload(lua_tointeger(L, 2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unloadAll(lua_State* L) {
|
||||
MonsterManager* mgr = static_cast<MonsterManager* const>(lua_touserdata(L, 1));
|
||||
CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1));
|
||||
mgr->UnloadAll();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unloadIf(lua_State* L) {
|
||||
MonsterManager* mgr = static_cast<MonsterManager* const>(lua_touserdata(L, 1));
|
||||
CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1));
|
||||
//TODO: unloadIf
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get(lua_State* L) {
|
||||
MonsterManager* mgr = static_cast<MonsterManager* const>(lua_touserdata(L, 1));
|
||||
MonsterData* monster = mgr->Get(lua_tointeger(L, 2));
|
||||
lua_pushlightuserdata(L, static_cast<void*>(monster));
|
||||
CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1));
|
||||
CreatureData* creature = mgr->Get(lua_tointeger(L, 2));
|
||||
lua_pushlightuserdata(L, static_cast<void*>(creature));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getLoadedCount(lua_State* L) {
|
||||
MonsterManager* mgr = static_cast<MonsterManager* const>(lua_touserdata(L, 1));
|
||||
CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, mgr->GetLoadedCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg monsterManagerLib[] = {
|
||||
static const luaL_Reg creatureManagerLib[] = {
|
||||
{"Create", create},
|
||||
{"Unload", unload},
|
||||
{"UnloadAll", unloadAll},
|
||||
@@ -74,7 +74,7 @@ static const luaL_Reg monsterManagerLib[] = {
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
LUAMOD_API int openMonsterManagerAPI(lua_State* L) {
|
||||
luaL_newlib(L, monsterManagerLib);
|
||||
LUAMOD_API int openCreatureManagerAPI(lua_State* L) {
|
||||
luaL_newlib(L, creatureManagerLib);
|
||||
return 1;
|
||||
}
|
||||
@@ -23,5 +23,5 @@
|
||||
|
||||
#include "lua.hpp"
|
||||
|
||||
#define TORTUGA_MONSTER_MANAGER_API "monster_manager"
|
||||
LUAMOD_API int openMonsterManagerAPI(lua_State* L);
|
||||
#define TORTUGA_CREATURE_MANAGER_API "creature_manager"
|
||||
LUAMOD_API int openCreatureManagerAPI(lua_State* L);
|
||||
|
||||
+4
-4
@@ -41,8 +41,8 @@
|
||||
#include "character_manager_api.hpp"
|
||||
#include "region_api.hpp"
|
||||
#include "region_pager_api.hpp"
|
||||
//#include "monster_api.hpp"
|
||||
//#include "monster_manager_api.hpp"
|
||||
#include "creature_api.hpp"
|
||||
#include "creature_manager_api.hpp"
|
||||
#include "network_api.hpp"
|
||||
#include "room_api.hpp"
|
||||
#include "room_manager_api.hpp"
|
||||
@@ -70,8 +70,8 @@ static const luaL_Reg preloadedlibs[] = {
|
||||
{TORTUGA_ENTITY_API, openEntityAPI}, //required by derived classes
|
||||
{TORTUGA_CHARACTER_API, openCharacterAPI},
|
||||
{TORTUGA_CHARACTER_MANAGER_API, openCharacterManagerAPI},
|
||||
// {TORTUGA_MONSTER_API, openMonsterAPI},
|
||||
// {TORTUGA_MONSTER_MANAGER_API, openMonsterManagerAPI},
|
||||
{TORTUGA_CREATURE_API, openCreatureAPI},
|
||||
{TORTUGA_CREATURE_MANAGER_API, openCreatureManagerAPI},
|
||||
{TORTUGA_NETWORK_API, openNetworkAPI},
|
||||
{TORTUGA_REGION_API, openRegionAPI},
|
||||
{TORTUGA_REGION_PAGER_API, openRegionPagerAPI},
|
||||
|
||||
Reference in New Issue
Block a user