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