Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ac1098fa86 | |||
| deba324449 | |||
| 95362286f8 | |||
| f5c58bf5ad | |||
| 316db43b0a | |||
| 46ed196bf4 | |||
| 64baa63d12 | |||
| e19b6fbc23 | |||
| a64411a567 | |||
| 3662a97475 | |||
| 97aaacbc23 | |||
| 8afd0e7c8a | |||
| 82c776df83 | |||
| 924ebc2ee9 | |||
| d3bf099a98 | |||
| a6de5f9e69 | |||
| 618666de43 | |||
| 5c74ecdd72 |
@@ -8,6 +8,7 @@ This game is inspired by classic 2D RPGs, as well as more modern sandbox MMOs. T
|
||||
|
||||
Tortuga's full documentation can be found in a separate branch, see [Tortuga/docs](https://github.com/Ratstail91/Tortuga/tree/docs).
|
||||
For Tortuga's primary documentation, please read the [Tortuga Game Design Document](https://github.com/Ratstail91/Tortuga/blob/docs/Tortuga%20Game%20Design%20Document.docx?raw=true).
|
||||
For a list of known bugs, see the [GitHub bug tracker](https://github.com/Ratstail91/Tortuga/issues).
|
||||
|
||||
## External Dependencies
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "restart.hpp"
|
||||
#include "clean_up.hpp"
|
||||
|
||||
#include "channels.hpp"
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
Restart::Restart(
|
||||
CleanUp::CleanUp(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
@@ -77,7 +77,7 @@ Restart::Restart(
|
||||
startTick = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
Restart::~Restart() {
|
||||
CleanUp::~CleanUp() {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -85,24 +85,23 @@ Restart::~Restart() {
|
||||
//Frame loop
|
||||
//-------------------------
|
||||
|
||||
void Restart::Update(double delta) {
|
||||
void CleanUp::Update(double delta) {
|
||||
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(10)) {
|
||||
QuitEvent();
|
||||
}
|
||||
|
||||
while(network.Receive()) {
|
||||
//EAT INCOMING PACKETS
|
||||
}
|
||||
//BUGFIX: Eat incoming packets
|
||||
while(network.Receive());
|
||||
}
|
||||
|
||||
void Restart::RenderFrame() {
|
||||
void CleanUp::RenderFrame() {
|
||||
SDL_FillRect(GetScreen(), 0, 0);
|
||||
Render(GetScreen());
|
||||
SDL_Flip(GetScreen());
|
||||
fps.Calculate();
|
||||
}
|
||||
|
||||
void Restart::Render(SDL_Surface* const screen) {
|
||||
void CleanUp::Render(SDL_Surface* const screen) {
|
||||
backButton.DrawTo(screen);
|
||||
font.DrawStringTo("You have been disconnected.", screen, 50, 30);
|
||||
}
|
||||
@@ -111,32 +110,28 @@ void Restart::Render(SDL_Surface* const screen) {
|
||||
//Event handlers
|
||||
//-------------------------
|
||||
|
||||
void Restart::QuitEvent() {
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
void CleanUp::QuitEvent() {
|
||||
SetNextScene(SceneList::QUIT);
|
||||
}
|
||||
|
||||
void Restart::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
void CleanUp::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
backButton.MouseMotion(motion);
|
||||
}
|
||||
|
||||
void Restart::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||
void CleanUp::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||
backButton.MouseButtonDown(button);
|
||||
}
|
||||
|
||||
void Restart::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
void CleanUp::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
if (backButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
QuitEvent();
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
}
|
||||
}
|
||||
|
||||
void Restart::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
switch(key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
QuitEvent();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Restart::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
void CleanUp::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
//
|
||||
}
|
||||
|
||||
void CleanUp::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
//
|
||||
}
|
||||
@@ -19,8 +19,8 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef RESTART_HPP_
|
||||
#define RESTART_HPP_
|
||||
#ifndef CLEANUP_HPP_
|
||||
#define CLEANUP_HPP_
|
||||
|
||||
//network
|
||||
#include "udp_network_utility.hpp"
|
||||
@@ -44,10 +44,10 @@
|
||||
//std namespace
|
||||
#include <chrono>
|
||||
|
||||
class Restart : public BaseScene {
|
||||
class CleanUp : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
Restart(
|
||||
CleanUp(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
std::map<int, CharacterData>* argCharacterMap,
|
||||
std::map<int, EnemyData>* argEnemyMap
|
||||
);
|
||||
~Restart();
|
||||
~CleanUp();
|
||||
|
||||
protected:
|
||||
//Frame loop
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "lobby_menu.hpp"
|
||||
#include "in_world.hpp"
|
||||
#include "in_combat.hpp"
|
||||
#include "restart.hpp"
|
||||
#include "clean_up.hpp"
|
||||
|
||||
//-------------------------
|
||||
//Public access members
|
||||
@@ -132,8 +132,8 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
|
||||
case SceneList::INCOMBAT:
|
||||
activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
|
||||
break;
|
||||
case SceneList::RESTART:
|
||||
activeScene = new Restart(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
|
||||
case SceneList::CLEANUP:
|
||||
activeScene = new CleanUp(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
|
||||
break;
|
||||
default:
|
||||
throw(std::logic_error("Failed to recognize the scene index"));
|
||||
|
||||
+4
-11
@@ -123,7 +123,7 @@ void InCombat::Render(SDL_Surface* const screen) {
|
||||
void InCombat::QuitEvent() {
|
||||
//exit the game AND the server
|
||||
RequestDisconnect();
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
SetNextScene(SceneList::QUIT);
|
||||
}
|
||||
|
||||
void InCombat::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
@@ -139,11 +139,7 @@ void InCombat::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
}
|
||||
|
||||
void InCombat::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
switch(key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
QuitEvent();
|
||||
break;
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
void InCombat::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
@@ -167,7 +163,7 @@ void InCombat::HandlePacket(SerialPacket* const argPacket) {
|
||||
}
|
||||
|
||||
void InCombat::HandleDisconnect(SerialPacket* const) {
|
||||
SetNextScene(SceneList::RESTART);
|
||||
SetNextScene(SceneList::CLEANUP);
|
||||
}
|
||||
|
||||
//TODO: more network handlers
|
||||
@@ -201,10 +197,7 @@ void InCombat::SendPlayerUpdate() {
|
||||
// newPacket.motion = localCharacter->motion;
|
||||
// newPacket.stats = localCharacter->stats;
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
}
|
||||
|
||||
+4
-12
@@ -135,7 +135,7 @@ void InWorld::Render(SDL_Surface* const screen) {
|
||||
|
||||
//draw characters
|
||||
for (auto& it : characterMap) {
|
||||
//TODO: drawing order according to Y origin
|
||||
//BUG: #29 drawing order according to Y origin
|
||||
it.second.DrawTo(screen, camera.x, camera.y);
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ void InWorld::Render(SDL_Surface* const screen) {
|
||||
void InWorld::QuitEvent() {
|
||||
//exit the game AND the server
|
||||
RequestDisconnect();
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
SetNextScene(SceneList::QUIT);
|
||||
}
|
||||
|
||||
void InWorld::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
@@ -176,11 +176,6 @@ void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
|
||||
void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
switch(key.keysym.sym) {
|
||||
case SDLK_ESCAPE: {
|
||||
QuitEvent();
|
||||
}
|
||||
break;
|
||||
|
||||
//player movement
|
||||
case SDLK_LEFT:
|
||||
if (localCharacter) {
|
||||
@@ -282,7 +277,7 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) {
|
||||
}
|
||||
|
||||
void InWorld::HandleDisconnect(SerialPacket* const argPacket) {
|
||||
SetNextScene(SceneList::RESTART);
|
||||
SetNextScene(SceneList::CLEANUP);
|
||||
}
|
||||
|
||||
void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
|
||||
@@ -386,10 +381,7 @@ void InWorld::SendPlayerUpdate() {
|
||||
newPacket.motion = localCharacter->motion;
|
||||
newPacket.stats = localCharacter->stats;
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,9 @@ LobbyMenu::LobbyMenu(
|
||||
|
||||
//set the server list's position
|
||||
listBox = {300, 50, 200, font.GetCharH()};
|
||||
|
||||
//BUGFIX: Eat incoming packets
|
||||
while(network.Receive());
|
||||
}
|
||||
|
||||
LobbyMenu::~LobbyMenu() {
|
||||
@@ -187,11 +190,7 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
}
|
||||
|
||||
void LobbyMenu::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
switch(key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
break;
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
@@ -225,7 +224,7 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
|
||||
server.playerCount = argPacket->playerCount;
|
||||
server.version = argPacket->version;
|
||||
|
||||
//NOTE: Check compatibility here
|
||||
//Checking compatibility
|
||||
server.compatible = server.version == NETWORK_VERSION;
|
||||
|
||||
//push
|
||||
|
||||
@@ -113,11 +113,7 @@ void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
}
|
||||
|
||||
void MainMenu::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
switch(key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
QuitEvent();
|
||||
break;
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
void MainMenu::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
|
||||
@@ -90,11 +90,7 @@ void OptionsMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
}
|
||||
|
||||
void OptionsMenu::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
switch(key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
break;
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
void OptionsMenu::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
|
||||
@@ -35,7 +35,7 @@ enum class SceneList {
|
||||
LOBBYMENU,
|
||||
INWORLD,
|
||||
INCOMBAT,
|
||||
RESTART,
|
||||
CLEANUP,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -53,10 +53,7 @@ struct CharacterData {
|
||||
//base statistics
|
||||
Statistics stats;
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
|
||||
//methods
|
||||
void Update(double delta);
|
||||
|
||||
@@ -41,12 +41,7 @@ struct EnemyData {
|
||||
//gameplay
|
||||
Statistics stats;
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
|
||||
//TODO: rewards
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
|
||||
|
||||
//active gameplay members
|
||||
//NOTE: these are lost when unloaded
|
||||
|
||||
+22
-22
@@ -64,43 +64,43 @@ static int getDepth(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int load(lua_State* L) {
|
||||
//TODO: fill this
|
||||
static int onLoad(lua_State* L) {
|
||||
//TODO: onLoad()
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int save(lua_State* L) {
|
||||
//TODO: fill this
|
||||
static int onSave(lua_State* L) {
|
||||
//TODO: onSave()
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int create(lua_State* L) {
|
||||
//TODO: fill this
|
||||
static int onCreate(lua_State* L) {
|
||||
//TODO: onCreate()
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unload(lua_State* L) {
|
||||
//TODO: fill this
|
||||
static int onUnload(lua_State* L) {
|
||||
//TODO: onUnload()
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg regionlib[] = {
|
||||
{"settile",setTile},
|
||||
{"gettile",getTile},
|
||||
{"getx",getX},
|
||||
{"gety",getY},
|
||||
{"getwidth",getWidth},
|
||||
{"getheight",getHeight},
|
||||
{"getdepth",getDepth},
|
||||
{"load",load},
|
||||
{"save",save},
|
||||
{"create",create},
|
||||
{"unload",unload},
|
||||
static const luaL_Reg regionLib[] = {
|
||||
{"SetTile",setTile},
|
||||
{"GetTile",getTile},
|
||||
{"GetX",getX},
|
||||
{"GetY",getY},
|
||||
{"GetWidth",getWidth},
|
||||
{"GetHeight",getHeight},
|
||||
{"GetDepth",getDepth},
|
||||
{"OnLoad",onLoad},
|
||||
{"OnSave",onSave},
|
||||
{"OnCreate",onCreate},
|
||||
{"OnUnload",onUnload},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
LUAMOD_API int luaopen_regionapi(lua_State* L) {
|
||||
luaL_newlib(L, regionlib);
|
||||
LUAMOD_API int openRegionAPI(lua_State* L) {
|
||||
luaL_newlib(L, regionLib);
|
||||
return 1;
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
#define LUA_REGIONLIBNAME "region"
|
||||
LUAMOD_API int luaopen_regionapi(lua_State* L);
|
||||
#define TORTUGA_REGION_NAME "Region"
|
||||
LUAMOD_API int openRegionAPI(lua_State* L);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "pager_api.hpp"
|
||||
#include "region_pager_api.hpp"
|
||||
|
||||
#include "region_pager_lua.hpp"
|
||||
#include "region.hpp"
|
||||
@@ -27,6 +27,8 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
//DOCS: These functions are just wrappers for the RegionPagerLua class
|
||||
|
||||
static int setTile(lua_State* L) {
|
||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||
int ret = pager->SetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
|
||||
@@ -63,94 +65,46 @@ static int getDirectory(lua_State* L) {
|
||||
}
|
||||
|
||||
static int loadRegion(lua_State* L) {
|
||||
//get the parameters
|
||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
std::string s = pager->GetDirectory();
|
||||
|
||||
//push the parameters
|
||||
lua_getglobal(L, "region");
|
||||
lua_getfield(L, -1, "load");
|
||||
Region* region = pager->LoadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
lua_pushlightuserdata(L, region);
|
||||
lua_pushstring(L, s.c_str());
|
||||
|
||||
//call the method
|
||||
if (lua_pcall(L, 2, 1, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int saveRegion(lua_State* L) {
|
||||
//get the parameters
|
||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
std::string s = pager->GetDirectory();
|
||||
|
||||
//push the parameters
|
||||
lua_getglobal(L, "region");
|
||||
lua_getfield(L, -1, "save");
|
||||
Region* region = pager->SaveRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
lua_pushlightuserdata(L, region);
|
||||
lua_pushstring(L, s.c_str());
|
||||
|
||||
//call the method
|
||||
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
||||
}
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int createRegion(lua_State* L) {
|
||||
//get the parameters
|
||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
|
||||
//push the parameters
|
||||
lua_getglobal(L, "region");
|
||||
lua_getfield(L, -1, "create");
|
||||
Region* region = pager->CreateRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
lua_pushlightuserdata(L, region);
|
||||
//TODO: parameters
|
||||
|
||||
//call the method
|
||||
if (lua_pcall(L, 1, 0, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
||||
}
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int unloadRegion(lua_State* L) {
|
||||
//get the parameters
|
||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
std::string s = pager->GetDirectory();
|
||||
|
||||
//push the parameters
|
||||
lua_getglobal(L, "region");
|
||||
lua_getfield(L, -1, "unload");
|
||||
lua_pushlightuserdata(L, region);
|
||||
lua_pushstring(L, s.c_str());
|
||||
|
||||
//call the method
|
||||
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
||||
}
|
||||
pager->UnloadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg pagerlib[] = {
|
||||
{"settile", setTile},
|
||||
{"gettile", getTile},
|
||||
{"getregion", getRegion},
|
||||
{"setdirectory", setDirectory},
|
||||
{"getdirectory", getDirectory},
|
||||
{"loadregion", loadRegion},
|
||||
{"saveregion", saveRegion},
|
||||
{"createregion", createRegion},
|
||||
{"unloadregion", unloadRegion},
|
||||
{"SetTile", setTile},
|
||||
{"GetTile", getTile},
|
||||
{"GetRegion", getRegion},
|
||||
{"SetDirectory", setDirectory},
|
||||
{"GetDirectory", getDirectory},
|
||||
{"LoadRegion", loadRegion},
|
||||
{"SaveRegion", saveRegion},
|
||||
{"CreateRegion", createRegion},
|
||||
{"UnloadRegion", unloadRegion},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
LUAMOD_API int luaopen_pagerapi(lua_State* L) {
|
||||
LUAMOD_API int openRegionPagerAPI(lua_State* L) {
|
||||
luaL_newlib(L, pagerlib);
|
||||
return 1;
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
#define LUA_PAGERLIBNAME "pager"
|
||||
LUAMOD_API int luaopen_pagerapi(lua_State* L);
|
||||
#define TORTUGA_REGION_PAGER_NAME "RegionPager"
|
||||
LUAMOD_API int openRegionPagerAPI(lua_State* L);
|
||||
|
||||
#endif
|
||||
@@ -29,12 +29,12 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
|
||||
//load the region if possible
|
||||
|
||||
//something to work on
|
||||
regionList.emplace_front(x, y);
|
||||
Region tmpRegion(x, y);
|
||||
|
||||
//API hook
|
||||
lua_getglobal(luaState, "region");
|
||||
lua_getfield(luaState, -1, "load");
|
||||
lua_pushlightuserdata(luaState, ®ionList.front());
|
||||
lua_getglobal(luaState, "Region");
|
||||
lua_getfield(luaState, -1, "OnLoad");
|
||||
lua_pushlightuserdata(luaState, &tmpRegion);
|
||||
lua_pushstring(luaState, directory.c_str());
|
||||
if (lua_pcall(luaState, 2, 1, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||
@@ -42,10 +42,10 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
|
||||
//success or failure
|
||||
if (!lua_toboolean(luaState, -1)) {
|
||||
lua_pop(luaState, 2);
|
||||
regionList.pop_front();
|
||||
return nullptr;
|
||||
}
|
||||
lua_pop(luaState, 2);
|
||||
regionList.push_front(tmpRegion);
|
||||
return ®ionList.front();
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ Region* RegionPagerLua::SaveRegion(int x, int y) {
|
||||
Region* ptr = FindRegion(x, y);
|
||||
if (ptr) {
|
||||
//API hook
|
||||
lua_getglobal(luaState, "region");
|
||||
lua_getfield(luaState, -1, "save");
|
||||
lua_getglobal(luaState, "Region");
|
||||
lua_getfield(luaState, -1, "OnSave");
|
||||
lua_pushlightuserdata(luaState, ptr);
|
||||
lua_pushstring(luaState, directory.c_str());
|
||||
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
||||
@@ -72,28 +72,29 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
|
||||
}
|
||||
|
||||
//something to work on
|
||||
regionList.emplace_front(x, y);
|
||||
Region tmpRegion(x, y);
|
||||
|
||||
//API hook
|
||||
lua_getglobal(luaState, "region");
|
||||
lua_getfield(luaState, -1, "create");
|
||||
lua_pushlightuserdata(luaState, ®ionList.front());
|
||||
lua_getglobal(luaState, "Region");
|
||||
lua_getfield(luaState, -1, "OnCreate");
|
||||
lua_pushlightuserdata(luaState, &tmpRegion);
|
||||
//TODO: parameters
|
||||
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||
}
|
||||
lua_pop(luaState, 1);
|
||||
return ®ionList.front();;
|
||||
regionList.push_front(tmpRegion);
|
||||
return ®ionList.front();
|
||||
}
|
||||
|
||||
void RegionPagerLua::UnloadRegion(int x, int y) {
|
||||
lua_getglobal(luaState, "region");
|
||||
lua_getglobal(luaState, "Region");
|
||||
|
||||
regionList.remove_if([&](Region& region) -> bool {
|
||||
if (region.GetX() == x && region.GetY() == y) {
|
||||
|
||||
//API hook
|
||||
lua_getfield(luaState, -1, "unload");
|
||||
lua_getfield(luaState, -1, "OnUnload");
|
||||
lua_pushlightuserdata(luaState, ®ion);
|
||||
lua_pushstring(luaState, directory.c_str());
|
||||
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
||||
@@ -109,11 +110,11 @@ void RegionPagerLua::UnloadRegion(int x, int y) {
|
||||
}
|
||||
|
||||
void RegionPagerLua::UnloadAll() {
|
||||
lua_getglobal(luaState, "region");
|
||||
lua_getglobal(luaState, "Region");
|
||||
|
||||
for (auto& it : regionList) {
|
||||
//API hook
|
||||
lua_getfield(luaState, -1, "unload");
|
||||
lua_getfield(luaState, -1, "OnUnload");
|
||||
lua_pushlightuserdata(luaState, &it);
|
||||
lua_pushstring(luaState, directory.c_str());
|
||||
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
|
||||
void UnloadAll() override;
|
||||
|
||||
//accessors & mutators
|
||||
std::string SetDirectory(std::string s) { return directory = s; }
|
||||
std::string GetDirectory() { return directory; }
|
||||
|
||||
|
||||
@@ -44,10 +44,7 @@ struct CharacterPacket : SerialPacketBase {
|
||||
//gameplay
|
||||
Statistics stats;
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -40,7 +40,7 @@ struct CombatPacket : SerialPacketBase {
|
||||
int mapIndex;
|
||||
Vector2 origin;
|
||||
|
||||
//TODO: rewards
|
||||
//TODO: gameplay components: rewards
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -33,12 +33,7 @@ struct EnemyPacket : SerialPacketBase {
|
||||
//gameplay
|
||||
Statistics stats;
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
|
||||
//TODO: rewards
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -148,7 +148,6 @@ void deserializePacket(SerialPacketBase* packet, void* buffer) {
|
||||
case SerialPacketType::COMBAT_DELETE:
|
||||
case SerialPacketType::COMBAT_UPDATE:
|
||||
|
||||
//TODO: is this the best fit?
|
||||
case SerialPacketType::COMBAT_ENTER_REQUEST:
|
||||
case SerialPacketType::COMBAT_ENTER_RESPONSE:
|
||||
case SerialPacketType::COMBAT_EXIT_REQUEST:
|
||||
|
||||
@@ -45,10 +45,7 @@ void serializeCharacter(CharacterPacket* packet, void* buffer) {
|
||||
serializeStatistics(&packet->stats, buffer);
|
||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
}
|
||||
|
||||
void deserializeCharacter(CharacterPacket* packet, void* buffer) {
|
||||
@@ -73,8 +70,5 @@ void deserializeCharacter(CharacterPacket* packet, void* buffer) {
|
||||
deserializeStatistics(&packet->stats, buffer);
|
||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ void serializeCombat(CombatPacket* packet, void* buffer) {
|
||||
SERIALIZE(buffer, &packet->origin.x, sizeof(double));
|
||||
SERIALIZE(buffer, &packet->origin.y, sizeof(double));
|
||||
|
||||
//TODO: rewards
|
||||
//TODO: gameplay components: rewards
|
||||
}
|
||||
|
||||
void deserializeCombat(CombatPacket* packet, void* buffer) {
|
||||
@@ -60,5 +60,5 @@ void deserializeCombat(CombatPacket* packet, void* buffer) {
|
||||
DESERIALIZE(buffer, &packet->origin.x, sizeof(double));
|
||||
DESERIALIZE(buffer, &packet->origin.y, sizeof(double));
|
||||
|
||||
//TODO: rewards
|
||||
//TODO: gameplay components: rewards
|
||||
}
|
||||
|
||||
@@ -37,12 +37,7 @@ void serializeEnemy(EnemyPacket* packet, void* buffer) {
|
||||
serializeStatistics(&packet->stats, buffer);
|
||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
|
||||
//TODO: rewards
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
|
||||
}
|
||||
|
||||
void deserializeEnemy(EnemyPacket* packet, void* buffer) {
|
||||
@@ -57,10 +52,5 @@ void deserializeEnemy(EnemyPacket* packet, void* buffer) {
|
||||
deserializeStatistics(&packet->stats, buffer);
|
||||
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
|
||||
//TODO: rewards
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
//DOCS: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network
|
||||
//BUGFIX: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network
|
||||
//NOTE: don't confuse SerialPacket with UDPpacket
|
||||
|
||||
void UDPNetworkUtility::Open(int port) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef SIMPLERNG_HPP_
|
||||
#define SIMPLERNG_HPP_
|
||||
|
||||
//a simple, stateless, random number generator
|
||||
class SimpleRNG {
|
||||
public:
|
||||
SimpleRNG() { SetSeed(8891.0); }
|
||||
SimpleRNG(double x) { SetSeed(x); }
|
||||
|
||||
double SetSeed(double s) { return seed = s; }
|
||||
double GetSeed() { return seed; }
|
||||
|
||||
double operator()(double x) {
|
||||
return (x + seed) * 11235.0 + 81321.0;
|
||||
};
|
||||
|
||||
private:
|
||||
double seed;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -41,6 +41,11 @@ public:
|
||||
double SquaredLength() const {
|
||||
return x*x+y*y;
|
||||
}
|
||||
void Normalize() {
|
||||
double l = Length();
|
||||
x /= l;
|
||||
y /= l;
|
||||
}
|
||||
|
||||
//Arithmetic operators
|
||||
Vector2 operator+(Vector2 v) const {
|
||||
@@ -97,15 +102,6 @@ public:
|
||||
template<typename T> bool operator!=(T t) { return (x != t || y != t); }
|
||||
};
|
||||
|
||||
//non-member templates (flip the order)
|
||||
template<typename T> Vector2 operator+(T t, Vector2 v) { return v + t; }
|
||||
template<typename T> Vector2 operator-(T t, Vector2 v) { return v - t; }
|
||||
template<typename T> Vector2 operator*(T t, Vector2 v) { return v * t; }
|
||||
template<typename T> Vector2 operator/(T t, Vector2 v) { return v / t; }
|
||||
|
||||
template<typename T> bool operator==(T t, Vector2 v) { return v == t; }
|
||||
template<typename T> bool operator!=(T t, Vector2 v) { return v != t; }
|
||||
|
||||
//This is explicitly a POD
|
||||
static_assert(std::is_pod<Vector2>::value, "Vector2 is not a POD");
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#MKDIR=mkdir
|
||||
#RM=del /y
|
||||
|
||||
#CXXFLAGS+=-static-libgcc -static-libstdc++ -g -fno-inline-functions -Wall
|
||||
CXXFLAGS+=-static-libgcc -static-libstdc++
|
||||
|
||||
export
|
||||
|
||||
@@ -1,20 +1,42 @@
|
||||
print("Lua script check (./rsc)")
|
||||
|
||||
-------------------------
|
||||
--Map API overrides
|
||||
-------------------------
|
||||
--uber lazy declarations
|
||||
function square(x) return x*x end
|
||||
function distance(x, y, i, j) return math.sqrt(square(x - i) + square(y - j)) end
|
||||
|
||||
function region.create(r)
|
||||
for i = 1, region.getwidth() do
|
||||
for j = 1, region.getheight() do
|
||||
if math.abs(region.getx(r) + i -1) == math.abs(region.gety(r) + j -1) then
|
||||
region.settile(r, i, j, 1, 50)
|
||||
--tile macros, mapped to the tilesheet
|
||||
local base = 14
|
||||
local shift = 36
|
||||
plains = base + shift * 0
|
||||
grass = base + shift * 1
|
||||
dirt = base + shift * 2
|
||||
sand = base + shift * 3
|
||||
water = base + shift * 4
|
||||
|
||||
--Overwrite the original OnCreate with my own version
|
||||
Region.hcOnCreate = Region.OnCreate
|
||||
Region.OnCreate = function(region)
|
||||
local ret = Region.hcOnCreate(region) --best practices
|
||||
for i = 1, Region.GetWidth() do
|
||||
for j = 1, Region.GetHeight() do
|
||||
if distance(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) > 10 then
|
||||
Region.SetTile(region, i, j, 1, water)
|
||||
else
|
||||
region.settile(r, i, j, 1, 14)
|
||||
Region.SetTile(region, i, j, 1, plains)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--signal
|
||||
region.settile(r, 4, 5, 2, 86)
|
||||
return ret
|
||||
end
|
||||
|
||||
--Get some regions
|
||||
newRoom = RoomMgr.CreateRoom("overworld")
|
||||
pager = Room.GetPager(newRoom)
|
||||
regionTable = {
|
||||
RegionPager.GetRegion(pager, 0, 0),
|
||||
RegionPager.GetRegion(pager, 0, -20),
|
||||
RegionPager.GetRegion(pager, -20, 0),
|
||||
RegionPager.GetRegion(pager, -20, -20)
|
||||
}
|
||||
|
||||
print("Finished the lua script")
|
||||
@@ -0,0 +1,37 @@
|
||||
#config
|
||||
INCLUDES+=.
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
#source
|
||||
CXXSRC=$(wildcard *.cpp)
|
||||
|
||||
#objects
|
||||
OBJDIR=obj
|
||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||
|
||||
#output
|
||||
OUTDIR=..
|
||||
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
ar -crs $(OUT) $(OBJ)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OUT): | $(OUTDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.a *.exe
|
||||
|
||||
rebuild: clean all
|
||||
@@ -58,7 +58,7 @@ static const char* DELETE_CHARACTER = "DELETE FROM Characters WHERE uid = ?;";
|
||||
//Define the methods
|
||||
//-------------------------
|
||||
|
||||
//TODO: default stats as a parameter? This would be good for differing beggining states or multiple classes
|
||||
//NOTE: default stats as a parameter would be good for different beggining states or multiple classes
|
||||
int CharacterManager::CreateCharacter(int owner, std::string handle, std::string avatar) {
|
||||
//Create the character, failing if it exists
|
||||
sqlite3_stmt* statement = nullptr;
|
||||
@@ -157,10 +157,7 @@ int CharacterManager::LoadCharacter(int owner, std::string handle, std::string a
|
||||
newChar.stats.evasion = sqlite3_column_double(statement, 20);
|
||||
newChar.stats.luck = sqlite3_column_double(statement, 21);
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
|
||||
//finish the routine
|
||||
sqlite3_finalize(statement);
|
||||
@@ -217,10 +214,7 @@ int CharacterManager::SaveCharacter(int uid) {
|
||||
ret |= sqlite3_bind_double(statement, 17, character.stats.evasion) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_double(statement, 18, character.stats.luck) != SQLITE_OK;
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
|
||||
//check for binding errors
|
||||
if (ret) {
|
||||
@@ -0,0 +1,37 @@
|
||||
#config
|
||||
INCLUDES+=. ../../common/gameplay ../../common/utilities
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
#source
|
||||
CXXSRC=$(wildcard *.cpp)
|
||||
|
||||
#objects
|
||||
OBJDIR=obj
|
||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||
|
||||
#output
|
||||
OUTDIR=..
|
||||
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
ar -crs $(OUT) $(OBJ)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OUT): | $(OUTDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.a *.exe
|
||||
|
||||
rebuild: clean all
|
||||
@@ -0,0 +1,37 @@
|
||||
#config
|
||||
INCLUDES+=. ../../common/gameplay ../../common/utilities
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
#source
|
||||
CXXSRC=$(wildcard *.cpp)
|
||||
|
||||
#objects
|
||||
OBJDIR=obj
|
||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||
|
||||
#output
|
||||
OUTDIR=..
|
||||
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
ar -crs $(OUT) $(OBJ)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OUT): | $(OUTDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.a *.exe
|
||||
|
||||
rebuild: clean all
|
||||
@@ -23,7 +23,7 @@
|
||||
#define ENEMYFACTORYINTERFACE_HPP_
|
||||
|
||||
#include "enemy_data.hpp"
|
||||
#include "room_data.hpp"
|
||||
#include "map_type.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
@@ -36,13 +36,14 @@ public:
|
||||
virtual void Generate(std::list<EnemyData>* container) = 0;
|
||||
|
||||
//control the difficulty of the room
|
||||
RoomData::RoomType SetType(RoomData::RoomType t) { return type = t; }
|
||||
MapType SetType(MapType t) { return type = t; }
|
||||
MapType GetType() { return type; }
|
||||
|
||||
int SetDifficulty(int d) { return difficulty = d; }
|
||||
RoomData::RoomType GetType() { return type; }
|
||||
int GetDifficulty() { return difficulty; }
|
||||
protected:
|
||||
RoomData::RoomType type;
|
||||
int difficulty;
|
||||
MapType type;
|
||||
int difficulty = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
#config
|
||||
INCLUDES+=. ../mapgen ../../common/gameplay ../../common/map ../../common/utilities
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
#source
|
||||
CXXSRC=$(wildcard *.cpp)
|
||||
|
||||
#objects
|
||||
OBJDIR=obj
|
||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||
|
||||
#output
|
||||
OUTDIR=..
|
||||
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
ar -crs $(OUT) $(OBJ)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OUT): | $(OUTDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.a *.exe
|
||||
|
||||
rebuild: clean all
|
||||
+10
-4
@@ -37,7 +37,10 @@
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
#include "region_api.hpp"
|
||||
#include "pager_api.hpp"
|
||||
#include "region_pager_api.hpp"
|
||||
#include "room_api.hpp"
|
||||
#include "room_mgr_api.hpp"
|
||||
#include "generator_api.hpp"
|
||||
|
||||
//these libs are loaded by lua.c and are readily available to any Lua program
|
||||
static const luaL_Reg loadedlibs[] = {
|
||||
@@ -53,9 +56,12 @@ static const luaL_Reg loadedlibs[] = {
|
||||
{LUA_MATHLIBNAME, luaopen_math},
|
||||
{LUA_DBLIBNAME, luaopen_debug},
|
||||
|
||||
//custom libs
|
||||
{LUA_REGIONLIBNAME, luaopen_regionapi},
|
||||
{LUA_PAGERLIBNAME, luaopen_pagerapi},
|
||||
//Tortuga's API
|
||||
{TORTUGA_REGION_NAME, openRegionAPI},
|
||||
{TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI},
|
||||
{TORTUGA_ROOM_NAME, openRoomAPI},
|
||||
{TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI},
|
||||
{TORTUGA_GENRATOR_NAME, openGeneratorAPI},
|
||||
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
+8
-2
@@ -1,6 +1,6 @@
|
||||
#config
|
||||
INCLUDES+=. ../common/gameplay ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/utilities
|
||||
LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
||||
INCLUDES+=. accounts characters combat enemies mapgen mapgen/generators rooms ../common/gameplay ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/utilities
|
||||
LIBS+=server.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
#source
|
||||
@@ -16,6 +16,12 @@ OUT=$(addprefix $(OUTDIR)/,server)
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
$(MAKE) -C accounts
|
||||
$(MAKE) -C characters
|
||||
$(MAKE) -C combat
|
||||
$(MAKE) -C enemies
|
||||
$(MAKE) -C mapgen
|
||||
$(MAKE) -C rooms
|
||||
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef CHUNKDATA_HPP_
|
||||
#define CHUNKDATA_HPP_
|
||||
|
||||
#include "terrain_type.hpp"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
struct ChunkData {
|
||||
enum class Moddable {
|
||||
LOCKED, //do not change
|
||||
HARD, //minor changes
|
||||
SOFT, //major changes
|
||||
CLEAR, //untouched
|
||||
};
|
||||
|
||||
TerrainType type;
|
||||
// int fountainCount;
|
||||
Moddable mod;
|
||||
};
|
||||
|
||||
static_assert(std::is_pod<ChunkData>::value, "ChunkData is not a POD");
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,79 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "generator_api.hpp"
|
||||
|
||||
#include "base_generator.hpp"
|
||||
|
||||
static int getMapType(lua_State* L) {
|
||||
BaseGenerator* ptr = reinterpret_cast<BaseGenerator*>(lua_touserdata(L, 1));
|
||||
switch(ptr->GetMapType()) {
|
||||
case MapType::NONE:
|
||||
lua_pushstring(L, "none");
|
||||
break;
|
||||
case MapType::OVERWORLD:
|
||||
lua_pushstring(L, "overworld");
|
||||
break;
|
||||
case MapType::RUINS:
|
||||
lua_pushstring(L, "ruins");
|
||||
break;
|
||||
case MapType::TOWERS:
|
||||
lua_pushstring(L, "towers");
|
||||
break;
|
||||
case MapType::FORESTS:
|
||||
lua_pushstring(L, "forests");
|
||||
break;
|
||||
case MapType::CAVES:
|
||||
lua_pushstring(L, "caves");
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getChunk(lua_State* L) {
|
||||
BaseGenerator* ptr = reinterpret_cast<BaseGenerator*>(lua_touserdata(L, 1));
|
||||
ChunkData* chunk = ptr->GetChunk(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(chunk));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getMapWidth(lua_State* L) {
|
||||
lua_pushinteger(L, MAP_WIDTH);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getMapHeight(lua_State* L) {
|
||||
lua_pushinteger(L, MAP_HEIGHT);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg generatorLib[] = {
|
||||
{"GetMapType", getMapType},
|
||||
{"GetChunk", getChunk},
|
||||
{"GetMapWidth", getMapWidth},
|
||||
{"GetMapHeight", getMapHeight},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
LUAMOD_API int openGeneratorAPI(lua_State* L) {
|
||||
luaL_newlib(L, generatorLib);
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef GENERATORAPI_HPP_
|
||||
#define GENERATORAPI_HPP_
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
#define TORTUGA_GENRATOR_NAME "Generator"
|
||||
LUAMOD_API int openGeneratorAPI(lua_State* L);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "base_generator.hpp"
|
||||
|
||||
BaseGenerator::BaseGenerator(MapType t) {
|
||||
mapType = t;
|
||||
for (int i = 0; i < MAP_WIDTH; i++) {
|
||||
for (int j = 0; j < MAP_HEIGHT; j++) {
|
||||
chunks[i][j].type = TerrainType::NONE;
|
||||
chunks[i][j].mod = ChunkData::Moddable::CLEAR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BaseGenerator::~BaseGenerator() {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef BASEGENERATOR_HPP_
|
||||
#define BASEGENERATOR_HPP_
|
||||
|
||||
#include "map_type.hpp"
|
||||
#include "chunk_data.hpp"
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
constexpr int MAP_WIDTH = 256;
|
||||
constexpr int MAP_HEIGHT = 256;
|
||||
|
||||
class BaseGenerator {
|
||||
public:
|
||||
virtual ~BaseGenerator();
|
||||
|
||||
//accessors and mutators
|
||||
virtual ChunkData* GetChunk(int x, int y) { return &chunks[x][y]; }
|
||||
|
||||
MapType GetMapType() { return mapType; }
|
||||
|
||||
lua_State* SetLuaState(lua_State* L) { return luaState = L; }
|
||||
lua_State* GetLuaState() { return luaState; }
|
||||
|
||||
protected:
|
||||
BaseGenerator() = delete;
|
||||
BaseGenerator(MapType t);
|
||||
|
||||
ChunkData chunks[MAP_WIDTH][MAP_HEIGHT];
|
||||
MapType mapType = MapType::NONE;
|
||||
lua_State* luaState = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "caves_generator.hpp"
|
||||
|
||||
CavesGenerator::CavesGenerator() : BaseGenerator(MapType::CAVES) {
|
||||
//
|
||||
}
|
||||
|
||||
CavesGenerator::~CavesGenerator() {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef CAVESGENERATOR_HPP_
|
||||
#define CAVESGENERATOR_HPP_
|
||||
|
||||
#include "base_generator.hpp"
|
||||
|
||||
class CavesGenerator : public BaseGenerator {
|
||||
public:
|
||||
CavesGenerator();
|
||||
~CavesGenerator();
|
||||
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "forests_generator.hpp"
|
||||
|
||||
ForestsGenerator::ForestsGenerator() : BaseGenerator(MapType::FORESTS) {
|
||||
//
|
||||
}
|
||||
|
||||
ForestsGenerator::~ForestsGenerator() {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef FORESTSGENERATOR_HPP_
|
||||
#define FORESTSGENERATOR_HPP_
|
||||
|
||||
#include "base_generator.hpp"
|
||||
|
||||
class ForestsGenerator : public BaseGenerator {
|
||||
public:
|
||||
ForestsGenerator();
|
||||
~ForestsGenerator();
|
||||
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
#config
|
||||
INCLUDES+=. ..
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
#source
|
||||
CXXSRC=$(wildcard *.cpp)
|
||||
|
||||
#objects
|
||||
OBJDIR=obj
|
||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||
|
||||
#output
|
||||
OUTDIR=../..
|
||||
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
ar -crs $(OUT) $(OBJ)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OUT): | $(OUTDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.a *.exe
|
||||
|
||||
rebuild: clean all
|
||||
@@ -0,0 +1,30 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "overworld_generator.hpp"
|
||||
|
||||
OverworldGenerator::OverworldGenerator() : BaseGenerator(MapType::OVERWORLD) {
|
||||
//
|
||||
}
|
||||
|
||||
OverworldGenerator::~OverworldGenerator() {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef OVERWORLDGENERATOR_HPP_
|
||||
#define OVERWORLDGENERATOR_HPP_
|
||||
|
||||
#include "base_generator.hpp"
|
||||
|
||||
class OverworldGenerator : public BaseGenerator {
|
||||
public:
|
||||
OverworldGenerator();
|
||||
~OverworldGenerator();
|
||||
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "ruins_generator.hpp"
|
||||
|
||||
RuinsGenerator::RuinsGenerator() : BaseGenerator(MapType::RUINS) {
|
||||
//
|
||||
}
|
||||
|
||||
RuinsGenerator::~RuinsGenerator() {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef RUINSGENERATOR_HPP_
|
||||
#define RUINSGENERATOR_HPP_
|
||||
|
||||
#include "base_generator.hpp"
|
||||
|
||||
class RuinsGenerator : public BaseGenerator {
|
||||
public:
|
||||
RuinsGenerator();
|
||||
~RuinsGenerator();
|
||||
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "towers_generator.hpp"
|
||||
|
||||
TowersGenerator::TowersGenerator() : BaseGenerator(MapType::TOWERS) {
|
||||
//
|
||||
}
|
||||
|
||||
TowersGenerator::~TowersGenerator() {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef TOWERSGENERATOR_HPP_
|
||||
#define TOWERSGENERATOR_HPP_
|
||||
|
||||
#include "base_generator.hpp"
|
||||
|
||||
class TowersGenerator : public BaseGenerator {
|
||||
public:
|
||||
TowersGenerator();
|
||||
~TowersGenerator();
|
||||
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
#config
|
||||
INCLUDES+=. generators
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
#source
|
||||
CXXSRC=$(wildcard *.cpp)
|
||||
|
||||
#objects
|
||||
OBJDIR=obj
|
||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||
|
||||
#output
|
||||
OUTDIR=..
|
||||
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
ar -crs $(OUT) $(OBJ)
|
||||
$(MAKE) -C generators
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OUT): | $(OUTDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.a *.exe
|
||||
|
||||
rebuild: clean all
|
||||
@@ -0,0 +1,34 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef MAPTYPE_HPP_
|
||||
#define MAPTYPE_HPP_
|
||||
|
||||
enum class MapType {
|
||||
NONE,
|
||||
OVERWORLD,
|
||||
RUINS,
|
||||
TOWERS,
|
||||
FORESTS,
|
||||
CAVES,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef TERRAINTYPE_HPP_
|
||||
#define TERRAINTYPE_HPP_
|
||||
|
||||
enum class TerrainType {
|
||||
//default: something's wrong
|
||||
NONE = 0,
|
||||
|
||||
//standard overworld
|
||||
PLAINS,
|
||||
GRASS,
|
||||
DIRT,
|
||||
SAND,
|
||||
WATER,
|
||||
|
||||
//not used
|
||||
LAST,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,72 +0,0 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "room_manager.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
//-------------------------
|
||||
//public access methods
|
||||
//-------------------------
|
||||
|
||||
RoomData* RoomManager::CreateRoom(int uid) {
|
||||
//don't overwrite existing rooms
|
||||
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
|
||||
if (it != roomMap.end()) {
|
||||
throw(std::runtime_error("Cannot overwrite an existing room"));
|
||||
}
|
||||
roomMap[uid] = new RoomData();
|
||||
//TODO: create room in the API
|
||||
if (luaState) {
|
||||
roomMap[uid]->pager.SetLuaState(luaState);
|
||||
}
|
||||
return roomMap[uid];
|
||||
}
|
||||
|
||||
RoomData* RoomManager::UnloadRoom(int uid) {
|
||||
//TODO: unload room in the API
|
||||
delete roomMap[uid];
|
||||
roomMap.erase(uid);
|
||||
}
|
||||
|
||||
RoomData* RoomManager::GetRoom(int uid) {
|
||||
RoomData* ptr = FindRoom(uid);
|
||||
if (ptr) return ptr;
|
||||
ptr = CreateRoom(uid);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
RoomData* RoomManager::FindRoom(int uid) {
|
||||
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
|
||||
if (it == roomMap.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
RoomData* RoomManager::PushRoom(int uid, RoomData* room) {
|
||||
//unload existing rooms with this index
|
||||
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
|
||||
if (it != roomMap.end()) {
|
||||
UnloadRoom(uid);
|
||||
}
|
||||
roomMap[uid] = room;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#config
|
||||
INCLUDES+=. ../mapgen ../mapgen/generators ../../common/map
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
#source
|
||||
CXXSRC=$(wildcard *.cpp)
|
||||
|
||||
#objects
|
||||
OBJDIR=obj
|
||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||
|
||||
#output
|
||||
OUTDIR=..
|
||||
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
ar -crs $(OUT) $(OBJ)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OUT): | $(OUTDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.a *.exe
|
||||
|
||||
rebuild: clean all
|
||||
@@ -21,43 +21,41 @@
|
||||
*/
|
||||
#include "room_api.hpp"
|
||||
|
||||
#include "room_manager.hpp"
|
||||
#include "room_data.hpp"
|
||||
|
||||
static int getType(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, static_cast<int>(room->type));
|
||||
return 1;
|
||||
}
|
||||
|
||||
//TODO: parameters
|
||||
|
||||
static int getRegionPager(lua_State* L) {
|
||||
static int getPager(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(&room->pager));
|
||||
return 1;
|
||||
}
|
||||
|
||||
//RoomManager only
|
||||
static int getRoom(lua_State* L) {
|
||||
//get the room manager
|
||||
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
|
||||
|
||||
//push the room and return it
|
||||
lua_pushlightuserdata(L, reinterpret_cast<void*>( roomMgr->GetRoom(lua_tointeger(L, -2)) ));
|
||||
static int getGenerator(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->generator));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg roomlib[] = {
|
||||
{"gettype",getType},
|
||||
{"getregionpager",getRegionPager},
|
||||
{"getroom",getRoom},
|
||||
static int onCreate(lua_State* L) {
|
||||
//TODO: onCreate()
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int onUnload(lua_State* L) {
|
||||
//TODO: onUnload()
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TODO: parameters
|
||||
|
||||
static const luaL_Reg roomLib[] = {
|
||||
{"GetPager",getPager},
|
||||
{"GetGenerator",getGenerator},
|
||||
{"OnCreate", onCreate},
|
||||
{"OnUnload", onUnload},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
LUAMOD_API int luaopen_roomapi(lua_State* L) {
|
||||
luaL_newlib(L, roomlib);
|
||||
LUAMOD_API int openRoomAPI(lua_State* L) {
|
||||
luaL_newlib(L, roomLib);
|
||||
return 1;
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
#define LUA_ROOMLIBNAME "room"
|
||||
LUAMOD_API int luaopen_roomapi(lua_State* L);
|
||||
#define TORTUGA_ROOM_NAME "Room"
|
||||
LUAMOD_API int openRoomAPI(lua_State* L);
|
||||
|
||||
#endif
|
||||
@@ -23,20 +23,14 @@
|
||||
#define ROOMDATA_HPP_
|
||||
|
||||
//map system
|
||||
#include "map_type.hpp"
|
||||
#include "region_pager_lua.hpp"
|
||||
#include "base_generator.hpp"
|
||||
|
||||
struct RoomData {
|
||||
enum class RoomType {
|
||||
OVERWORLD = 0,
|
||||
RUINS = 1,
|
||||
TOWERS = 2,
|
||||
FORESTS = 3,
|
||||
CAVE = 4,
|
||||
};
|
||||
|
||||
//members
|
||||
RegionPagerLua pager;
|
||||
RoomType type;
|
||||
BaseGenerator* generator = nullptr;
|
||||
|
||||
//TODO: collision map
|
||||
//TODO: NPCs?
|
||||
@@ -0,0 +1,132 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "room_manager.hpp"
|
||||
|
||||
//the generator types
|
||||
#include "overworld_generator.hpp"
|
||||
#include "ruins_generator.hpp"
|
||||
#include "towers_generator.hpp"
|
||||
#include "forests_generator.hpp"
|
||||
#include "caves_generator.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
//-------------------------
|
||||
//public access methods
|
||||
//-------------------------
|
||||
|
||||
RoomData* RoomManager::CreateRoom(MapType mapType) {
|
||||
//create the room
|
||||
RoomData* newRoom = new RoomData();
|
||||
|
||||
//create the generator, use a lambda because I'm lazy
|
||||
newRoom->generator = [mapType]() -> BaseGenerator* {
|
||||
switch(mapType) {
|
||||
//BUG: Not having a map type results in an overworld generator by default
|
||||
case MapType::NONE:
|
||||
case MapType::OVERWORLD: return new OverworldGenerator();
|
||||
case MapType::RUINS: return new RuinsGenerator();
|
||||
case MapType::TOWERS: return new TowersGenerator();
|
||||
case MapType::FORESTS: return new ForestsGenerator();
|
||||
case MapType::CAVES: return new CavesGenerator();
|
||||
}
|
||||
throw(std::runtime_error("Failed to set the room's generator"));
|
||||
}();
|
||||
|
||||
//set the state
|
||||
if (luaState) {
|
||||
newRoom->pager.SetLuaState(luaState);
|
||||
newRoom->generator->SetLuaState(luaState);
|
||||
}
|
||||
|
||||
//register the room
|
||||
roomMap[counter++] = newRoom;
|
||||
|
||||
//API hook
|
||||
lua_getglobal(luaState, "Room");
|
||||
lua_getfield(luaState, -1, "OnCreate");
|
||||
lua_pushlightuserdata(luaState, newRoom);
|
||||
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||
}
|
||||
lua_pop(luaState, 1);
|
||||
|
||||
//finish the routine
|
||||
return newRoom;
|
||||
}
|
||||
|
||||
void RoomManager::UnloadRoom(int uid) {
|
||||
//find the room
|
||||
RoomData* room = FindRoom(uid);
|
||||
if (!room) {
|
||||
return;
|
||||
}
|
||||
|
||||
//API hook
|
||||
lua_getglobal(luaState, "Room");
|
||||
lua_getfield(luaState, -1, "OnUnload");
|
||||
lua_pushlightuserdata(luaState, room);
|
||||
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||
}
|
||||
lua_pop(luaState, 1);
|
||||
|
||||
//free the memory
|
||||
delete room->generator;
|
||||
delete room;
|
||||
roomMap.erase(uid);
|
||||
}
|
||||
|
||||
RoomData* RoomManager::GetRoom(int uid) {
|
||||
RoomData* ptr = FindRoom(uid);
|
||||
if (ptr) return ptr;
|
||||
return CreateRoom(MapType::NONE);
|
||||
}
|
||||
|
||||
RoomData* RoomManager::FindRoom(int uid) {
|
||||
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
|
||||
if (it == roomMap.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
int RoomManager::PushRoom(RoomData* room) {
|
||||
roomMap[counter++] = room;
|
||||
return counter;
|
||||
}
|
||||
|
||||
void RoomManager::UnloadAll() {
|
||||
lua_getglobal(luaState, "Room");
|
||||
|
||||
for (auto& it : roomMap) {
|
||||
//API hook
|
||||
lua_getfield(luaState, -1, "OnUnload");
|
||||
lua_pushlightuserdata(luaState, it.second);
|
||||
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||
}
|
||||
}
|
||||
|
||||
lua_pop(luaState, 1);
|
||||
roomMap.clear();
|
||||
}
|
||||
@@ -36,12 +36,14 @@ public:
|
||||
~RoomManager() = default;
|
||||
|
||||
//public access methods
|
||||
RoomData* CreateRoom(int uid);
|
||||
RoomData* UnloadRoom(int uid);
|
||||
RoomData* CreateRoom(MapType);
|
||||
void UnloadRoom(int uid);
|
||||
|
||||
RoomData* GetRoom(int uid);
|
||||
RoomData* FindRoom(int uid);
|
||||
RoomData* PushRoom(int uid, RoomData*);
|
||||
int PushRoom(RoomData*);
|
||||
|
||||
void UnloadAll();
|
||||
|
||||
//accessors and mutators
|
||||
std::map<int, RoomData*>* GetContainer() { return &roomMap; }
|
||||
@@ -52,6 +54,7 @@ public:
|
||||
private:
|
||||
std::map<int, RoomData*> roomMap;
|
||||
lua_State* luaState = nullptr;
|
||||
int counter = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,89 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "room_mgr_api.hpp"
|
||||
|
||||
#include "room_api.hpp"
|
||||
#include "room_manager.hpp"
|
||||
#include "room_data.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
static int getRoom(lua_State* L) {
|
||||
//get the room manager
|
||||
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
|
||||
|
||||
//push the room and return it
|
||||
lua_pushlightuserdata(L, reinterpret_cast<void*>( roomMgr->GetRoom(lua_tointeger(L, -2)) ));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int createRoom(lua_State* L) {
|
||||
//TODO: check parameter count for the glue functions
|
||||
|
||||
//get the room manager
|
||||
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
|
||||
|
||||
//determine the specified room type
|
||||
MapType mapType = [L]() -> MapType {
|
||||
if (std::string("overworld") == lua_tostring(L, -2)) return MapType::OVERWORLD;
|
||||
if (std::string("ruins") == lua_tostring(L, -2)) return MapType::RUINS;
|
||||
if (std::string("towers") == lua_tostring(L, -2)) return MapType::TOWERS;
|
||||
if (std::string("forests") == lua_tostring(L, -2)) return MapType::FORESTS;
|
||||
if (std::string("caves") == lua_tostring(L, -2)) return MapType::CAVES;
|
||||
return MapType::NONE;
|
||||
}();
|
||||
|
||||
//create the room
|
||||
RoomData* newRoom = roomMgr->CreateRoom(mapType);
|
||||
|
||||
//return the new room
|
||||
lua_pushlightuserdata(L, newRoom);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int unloadRoom(lua_State* L) {
|
||||
//get the room manager
|
||||
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
|
||||
|
||||
//unload the specified room
|
||||
roomMgr->UnloadRoom(lua_tointeger(L, -2));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg roomMgrLib[] = {
|
||||
{"GetRoom",getRoom},
|
||||
{"CreateRoom",createRoom},
|
||||
{"UnloadRoom",unloadRoom},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
LUAMOD_API int openRoomMgrAPI(lua_State* L) {
|
||||
luaL_newlib(L, roomMgrLib);
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef ROOMMGRAPI_HPP_
|
||||
#define ROOMMGRAPI_HPP_
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
#define TORTUGA_ROOM_MGR_NAME "RoomMgr"
|
||||
LUAMOD_API int openRoomMgrAPI(lua_State* L);
|
||||
|
||||
#endif
|
||||
@@ -157,7 +157,7 @@ void ServerApplication::Quit() {
|
||||
characterMgr.UnloadAll();
|
||||
//TODO: unload combats
|
||||
//TODO: unload enemies
|
||||
//TODO: unload rooms
|
||||
roomMgr.UnloadAll();
|
||||
|
||||
//APIs
|
||||
lua_close(luaState);
|
||||
@@ -338,6 +338,7 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
||||
//-------------------------
|
||||
|
||||
void ServerApplication::HandleCharacterNew(CharacterPacket* const argPacket) {
|
||||
//BUG: #27 Characters can be created with an invalid account index
|
||||
//NOTE: misnomer, try to load the character first
|
||||
int characterIndex = characterMgr.LoadCharacter(argPacket->accountIndex, argPacket->handle, argPacket->avatar);
|
||||
|
||||
@@ -413,10 +414,7 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket)
|
||||
|
||||
character->stats = argPacket->stats;
|
||||
|
||||
//TODO: equipment
|
||||
//TODO: items
|
||||
//TODO: buffs
|
||||
//TODO: debuffs
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
|
||||
PumpPacket(argPacket);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
TODO: rename restart scene to cleanup scene
|
||||
TODO: encapsulate the data structures
|
||||
TODO: Get the rooms working
|
||||
|
||||
TODO: Rejection packets
|
||||
TODO: make the whole thing more fault tolerant
|
||||
TODO: Authentication
|
||||
TODO: server is slaved to the client
|
||||
|
||||
TODO: I need to keep the documentation up to date. Namely, the GDD is getting out of date.
|
||||
TODO: I completely forgot about status ailments
|
||||
TODO: Time delay for requesting region packets
|
||||
TODO: command line parameters overriding config.cfg settings
|
||||
|
||||
Reference in New Issue
Block a user