Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 93c41bb19c | |||
| bf922ec598 | |||
| de902d2d3d | |||
| 7b3bf24e5d | |||
| de7da81102 | |||
| 6428b02d85 | |||
| 519b8a1e36 | |||
| 967f0653a1 | |||
| b86d393571 | |||
| 6b38501c27 | |||
| 5893342ad8 | |||
| ac4a264f12 | |||
| 43895a462a | |||
| 1bde0ed3f7 | |||
| d903c0df30 | |||
| 9620826d65 | |||
| 0a71f43ef3 | |||
| a47e76845f | |||
| c2eb08bd5e | |||
| 7b76e07231 | |||
| 1dd8042d3d | |||
| c575ee9ce1 | |||
| 1befc76b70 | |||
| 6a6e7f7125 | |||
| bb6e248583 | |||
| f7df4fba6c | |||
| e7403be508 | |||
| 873715b28c | |||
| b1d6e5a314 | |||
| f0453375c4 |
@@ -1,9 +1,14 @@
|
|||||||
The most recent stable windows build can be found [here](https://dl.dropboxusercontent.com/u/46669050/Tortuga.rar).
|
The most recent stable build for Windows can be found [here](https://dl.dropboxusercontent.com/u/46669050/Tortuga.rar).
|
||||||
|
|
||||||
Tortuga is an open source 2D multiplayer role playing game featuring permadeath (deletion of a character upon death). The emphasis of this game is on multiplayer cooperation, competition, exploration and customization. The game runs on customizable server software that can support up to 150 simultaneous players or more.
|
Tortuga is a 2D multiplayer JRPG featuring permadeath (deletion of a character upon death). The emphasis of this game is on multiplayer cooperation, exploration and customization. The game runs on customizable server software that can support up to 150 simultaneous players or more.
|
||||||
|
|
||||||
This game is inspired by classic 2D RPGs, as well as more modern sandbox MMOs. This project is currently independently created and funded, with the goal of creating a game that will engage user's imagination and inspire a large modding community.
|
This game is inspired by classic 2D RPGs, as well as more modern sandbox MMOs. This project is currently independently created and funded, with the goal of creating a game that will engage user's imagination and inspire a large modding community.
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
## External Dependencies
|
## External Dependencies
|
||||||
|
|
||||||
* [SDL 1.2](http://www.libsdl.org/) - Simple DirectMedia Layer API
|
* [SDL 1.2](http://www.libsdl.org/) - Simple DirectMedia Layer API
|
||||||
@@ -11,13 +16,10 @@ This game is inspired by classic 2D RPGs, as well as more modern sandbox MMOs. T
|
|||||||
* [lua 5.2](http://www.lua.org/) - The lua programming language
|
* [lua 5.2](http://www.lua.org/) - The lua programming language
|
||||||
* [SQLite3](http://www.sqlite.org/) - A lightweight SQL database engine
|
* [SQLite3](http://www.sqlite.org/) - A lightweight SQL database engine
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
[Tortuga Game Design Document](https://github.com/Ratstail91/Tortuga/blob/docs/design%20doc.docx?raw=true)
|
|
||||||
[Tortuga Technical Document](https://github.com/Ratstail91/Tortuga/blob/docs/technical%20doc.docx?raw=true)
|
|
||||||
|
|
||||||
## Copyright
|
## Copyright
|
||||||
|
|
||||||
|
(Future versions (to be determined) may be released under a modified version of the [Uplink Developer's License](http://www.introversion.co.uk/uplink/developer/license.html).)
|
||||||
|
|
||||||
The current version of Tortuga is released under the [zlib license](http://en.wikipedia.org/wiki/Zlib_License).
|
The current version of Tortuga is released under the [zlib license](http://en.wikipedia.org/wiki/Zlib_License).
|
||||||
|
|
||||||
Copyright (c) 2013, 2014 Kayne Ruse
|
Copyright (c) 2013, 2014 Kayne Ruse
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,3 +1,24 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013, 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 CHANNELS_HPP_
|
#ifndef CHANNELS_HPP_
|
||||||
#define CHANNELS_HPP_
|
#define CHANNELS_HPP_
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -56,7 +56,7 @@ void ClientApplication::Init(int argc, char** argv) {
|
|||||||
if (SDLNet_Init()) {
|
if (SDLNet_Init()) {
|
||||||
throw(std::runtime_error("Failed to initialize SDL_net"));
|
throw(std::runtime_error("Failed to initialize SDL_net"));
|
||||||
}
|
}
|
||||||
network.Open(0, PACKET_BUFFER_SIZE);
|
network.Open(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientApplication::Proc() {
|
void ClientApplication::Proc() {
|
||||||
@@ -122,10 +122,10 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
|
|||||||
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex);
|
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex);
|
||||||
break;
|
break;
|
||||||
case SceneList::INWORLD:
|
case SceneList::INWORLD:
|
||||||
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex);
|
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap);
|
||||||
break;
|
break;
|
||||||
case SceneList::INCOMBAT:
|
case SceneList::INCOMBAT:
|
||||||
activeScene = new InCombat();
|
activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw(std::logic_error("Failed to recognize the scene index"));
|
throw(std::logic_error("Failed to recognize the scene index"));
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -27,6 +27,11 @@
|
|||||||
|
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
|
#include "character_data.hpp"
|
||||||
|
#include "combat_data.hpp"
|
||||||
|
#include "enemy_data.hpp"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
class ClientApplication {
|
class ClientApplication {
|
||||||
public:
|
public:
|
||||||
@@ -50,6 +55,10 @@ private:
|
|||||||
int clientIndex = -1;
|
int clientIndex = -1;
|
||||||
int accountIndex = -1;
|
int accountIndex = -1;
|
||||||
int characterIndex = -1;
|
int characterIndex = -1;
|
||||||
|
|
||||||
|
std::map<int, CombatData> combatMap;
|
||||||
|
std::map<int, CharacterData> characterMap;
|
||||||
|
std::map<int, EnemyData> enemyMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -25,7 +25,25 @@
|
|||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
InCombat::InCombat() {
|
InCombat::InCombat(
|
||||||
|
ConfigUtility* const argConfig,
|
||||||
|
UDPNetworkUtility* const argNetwork,
|
||||||
|
int* const argClientIndex,
|
||||||
|
int* const argAccountIndex,
|
||||||
|
int* const argCharacterIndex,
|
||||||
|
std::map<int, CombatData>* argCombatMap,
|
||||||
|
std::map<int, CharacterData>* argCharacterMap,
|
||||||
|
std::map<int, EnemyData>* argEnemyMap
|
||||||
|
):
|
||||||
|
config(*argConfig),
|
||||||
|
network(*argNetwork),
|
||||||
|
clientIndex(*argClientIndex),
|
||||||
|
accountIndex(*argAccountIndex),
|
||||||
|
characterIndex(*argCharacterIndex),
|
||||||
|
combatMap(*argCombatMap),
|
||||||
|
characterMap(*argCharacterMap),
|
||||||
|
enemyMap(*argEnemyMap)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +67,13 @@ void InCombat::FrameEnd() {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InCombat::RenderFrame() {
|
||||||
|
SDL_FillRect(GetScreen(), 0, 0);
|
||||||
|
Render(GetScreen());
|
||||||
|
SDL_Flip(GetScreen());
|
||||||
|
fps.Calculate();
|
||||||
|
}
|
||||||
|
|
||||||
void InCombat::Render(SDL_Surface* const screen) {
|
void InCombat::Render(SDL_Surface* const screen) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@@ -57,6 +82,12 @@ void InCombat::Render(SDL_Surface* const screen) {
|
|||||||
//Event handlers
|
//Event handlers
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
void InCombat::QuitEvent() {
|
||||||
|
//exit the game AND the server
|
||||||
|
// RequestDisconnect();
|
||||||
|
SetNextScene(SceneList::MAINMENU);
|
||||||
|
}
|
||||||
|
|
||||||
void InCombat::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
void InCombat::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@@ -80,3 +111,15 @@ void InCombat::KeyDown(SDL_KeyboardEvent const& key) {
|
|||||||
void InCombat::KeyUp(SDL_KeyboardEvent const& key) {
|
void InCombat::KeyUp(SDL_KeyboardEvent const& key) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Network handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//TODO: network handlers
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Server control
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//TODO: server control
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013, 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 INCOMBAT_HPP_
|
||||||
|
#define INCOMBAT_HPP_
|
||||||
|
|
||||||
|
//network
|
||||||
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
|
//graphics
|
||||||
|
#include "image.hpp"
|
||||||
|
#include "raster_font.hpp"
|
||||||
|
#include "button.hpp"
|
||||||
|
|
||||||
|
//common
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
#include "frame_rate.hpp"
|
||||||
|
|
||||||
|
#include "combat_data.hpp"
|
||||||
|
#include "character_data.hpp"
|
||||||
|
#include "enemy_data.hpp"
|
||||||
|
|
||||||
|
//client
|
||||||
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
|
class InCombat : public BaseScene {
|
||||||
|
public:
|
||||||
|
//Public access members
|
||||||
|
InCombat(
|
||||||
|
ConfigUtility* const argConfig,
|
||||||
|
UDPNetworkUtility* const argNetwork,
|
||||||
|
int* const argClientIndex,
|
||||||
|
int* const argAccountIndex,
|
||||||
|
int* const argCharacterIndex,
|
||||||
|
std::map<int, CombatData>* argCombatMap,
|
||||||
|
std::map<int, CharacterData>* argCharacterMap,
|
||||||
|
std::map<int, EnemyData>* argEnemyMap
|
||||||
|
);
|
||||||
|
~InCombat();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//Frame loop
|
||||||
|
void FrameStart();
|
||||||
|
void Update(double delta);
|
||||||
|
void FrameEnd();
|
||||||
|
void RenderFrame();
|
||||||
|
void Render(SDL_Surface* const);
|
||||||
|
|
||||||
|
//Event handlers
|
||||||
|
void QuitEvent();
|
||||||
|
void MouseMotion(SDL_MouseMotionEvent const&);
|
||||||
|
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||||
|
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||||
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
|
//Network handlers
|
||||||
|
void HandlePacket(SerialPacket);
|
||||||
|
void HandleDisconnect(SerialPacket);
|
||||||
|
//TODO: more
|
||||||
|
|
||||||
|
//Server control
|
||||||
|
void SendPlayerUpdate();
|
||||||
|
void RequestDisconnect();
|
||||||
|
void RequestShutdown();
|
||||||
|
//TODO: more
|
||||||
|
|
||||||
|
//shared parameters
|
||||||
|
ConfigUtility& config;
|
||||||
|
UDPNetworkUtility& network;
|
||||||
|
int& clientIndex;
|
||||||
|
int& accountIndex;
|
||||||
|
int& characterIndex;
|
||||||
|
std::map<int, CombatData>& combatMap;
|
||||||
|
std::map<int, CharacterData>& characterMap;
|
||||||
|
std::map<int, EnemyData>& enemyMap;
|
||||||
|
|
||||||
|
//graphics
|
||||||
|
//TODO: graphics
|
||||||
|
|
||||||
|
//UI
|
||||||
|
//TODO: UI
|
||||||
|
FrameRate fps;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -31,12 +31,22 @@
|
|||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex):
|
InWorld::InWorld(
|
||||||
|
ConfigUtility* const argConfig,
|
||||||
|
UDPNetworkUtility* const argNetwork,
|
||||||
|
int* const argClientIndex,
|
||||||
|
int* const argAccountIndex,
|
||||||
|
int* const argCharacterIndex,
|
||||||
|
std::map<int, CombatData>* argCombatMap,
|
||||||
|
std::map<int, CharacterData>* argCharacterMap
|
||||||
|
):
|
||||||
config(*argConfig),
|
config(*argConfig),
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex),
|
accountIndex(*argAccountIndex),
|
||||||
characterIndex(*argCharacterIndex)
|
characterIndex(*argCharacterIndex),
|
||||||
|
combatMap(*argCombatMap),
|
||||||
|
characterMap(*argCharacterMap)
|
||||||
{
|
{
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||||
@@ -63,16 +73,8 @@ InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNet
|
|||||||
//TODO: add the tilesheet to the map system?
|
//TODO: add the tilesheet to the map system?
|
||||||
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15);
|
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15);
|
||||||
|
|
||||||
//TODO: move this into it's own function
|
|
||||||
//request a sync
|
//request a sync
|
||||||
SerialPacket packet;
|
RequestSynchronize();
|
||||||
char buffer[PACKET_STRING_SIZE];
|
|
||||||
packet.meta.type = SerialPacket::Type::SYNCHRONIZE;
|
|
||||||
packet.clientInfo.clientIndex = clientIndex;
|
|
||||||
packet.clientInfo.accountIndex = accountIndex;
|
|
||||||
packet.clientInfo.characterIndex = characterIndex;
|
|
||||||
serialize(&packet, buffer);
|
|
||||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
|
||||||
|
|
||||||
//debug
|
//debug
|
||||||
// RequestRegion(0, 0);
|
// RequestRegion(0, 0);
|
||||||
@@ -94,22 +96,19 @@ void InWorld::Update(double delta) {
|
|||||||
SerialPacket packet;
|
SerialPacket packet;
|
||||||
|
|
||||||
//suck in all waiting packets
|
//suck in all waiting packets
|
||||||
while(network.Receive()) {
|
while(network.Receive(&packet)) {
|
||||||
deserialize(&packet, network.GetInData());
|
|
||||||
packet.meta.srcAddress = network.GetInPacket()->address;
|
|
||||||
HandlePacket(packet);
|
HandlePacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
//update the characters
|
//update the characters
|
||||||
for (auto& it : playerCharacters) {
|
for (auto& it : characterMap) {
|
||||||
it.second.Update(delta);
|
it.second.Update(delta);
|
||||||
}
|
}
|
||||||
//TODO: sort the players and entities by Y position
|
|
||||||
|
|
||||||
//update the camera
|
//update the camera
|
||||||
if(localCharacter) {
|
if(localCharacter) {
|
||||||
camera.x = localCharacter->GetPosition().x - camera.marginX;
|
camera.x = localCharacter->position.x - camera.marginX;
|
||||||
camera.y = localCharacter->GetPosition().y - camera.marginY;
|
camera.y = localCharacter->position.y - camera.marginY;
|
||||||
}
|
}
|
||||||
|
|
||||||
//check the map
|
//check the map
|
||||||
@@ -134,7 +133,8 @@ void InWorld::Render(SDL_Surface* const screen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//draw characters
|
//draw characters
|
||||||
for (auto& it : playerCharacters) {
|
for (auto& it : characterMap) {
|
||||||
|
//TODO: drawing order according to Y position
|
||||||
it.second.DrawTo(screen, camera.x, camera.y);
|
it.second.DrawTo(screen, camera.x, camera.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,6 +151,7 @@ void InWorld::Render(SDL_Surface* const screen) {
|
|||||||
void InWorld::QuitEvent() {
|
void InWorld::QuitEvent() {
|
||||||
//exit the game AND the server
|
//exit the game AND the server
|
||||||
RequestDisconnect();
|
RequestDisconnect();
|
||||||
|
SetNextScene(SceneList::MAINMENU);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
void InWorld::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
@@ -182,28 +183,28 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
|
|||||||
//player movement
|
//player movement
|
||||||
case SDLK_LEFT:
|
case SDLK_LEFT:
|
||||||
if (localCharacter) {
|
if (localCharacter) {
|
||||||
localCharacter->AdjustDirection(PlayerCharacter::Direction::WEST);
|
localCharacter->motion.x -= CHARACTER_WALKING_SPEED;
|
||||||
SendPlayerUpdate();
|
SendPlayerUpdate();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_RIGHT:
|
case SDLK_RIGHT:
|
||||||
if (localCharacter) {
|
if (localCharacter) {
|
||||||
localCharacter->AdjustDirection(PlayerCharacter::Direction::EAST);
|
localCharacter->motion.x += CHARACTER_WALKING_SPEED;
|
||||||
SendPlayerUpdate();
|
SendPlayerUpdate();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_UP:
|
case SDLK_UP:
|
||||||
if (localCharacter) {
|
if (localCharacter) {
|
||||||
localCharacter->AdjustDirection(PlayerCharacter::Direction::NORTH);
|
localCharacter->motion.y -= CHARACTER_WALKING_SPEED;
|
||||||
SendPlayerUpdate();
|
SendPlayerUpdate();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_DOWN:
|
case SDLK_DOWN:
|
||||||
if (localCharacter) {
|
if (localCharacter) {
|
||||||
localCharacter->AdjustDirection(PlayerCharacter::Direction::SOUTH);
|
localCharacter->motion.y += CHARACTER_WALKING_SPEED;
|
||||||
SendPlayerUpdate();
|
SendPlayerUpdate();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -215,28 +216,28 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
|
|||||||
//player movement
|
//player movement
|
||||||
case SDLK_LEFT:
|
case SDLK_LEFT:
|
||||||
if (localCharacter) {
|
if (localCharacter) {
|
||||||
localCharacter->AdjustDirection(PlayerCharacter::Direction::EAST);
|
localCharacter->motion.x += CHARACTER_WALKING_SPEED;
|
||||||
SendPlayerUpdate();
|
SendPlayerUpdate();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_RIGHT:
|
case SDLK_RIGHT:
|
||||||
if (localCharacter) {
|
if (localCharacter) {
|
||||||
localCharacter->AdjustDirection(PlayerCharacter::Direction::WEST);
|
localCharacter->motion.x -= CHARACTER_WALKING_SPEED;
|
||||||
SendPlayerUpdate();
|
SendPlayerUpdate();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_UP:
|
case SDLK_UP:
|
||||||
if (localCharacter) {
|
if (localCharacter) {
|
||||||
localCharacter->AdjustDirection(PlayerCharacter::Direction::SOUTH);
|
localCharacter->motion.y += CHARACTER_WALKING_SPEED;
|
||||||
SendPlayerUpdate();
|
SendPlayerUpdate();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_DOWN:
|
case SDLK_DOWN:
|
||||||
if (localCharacter) {
|
if (localCharacter) {
|
||||||
localCharacter->AdjustDirection(PlayerCharacter::Direction::NORTH);
|
localCharacter->motion.y -= CHARACTER_WALKING_SPEED;
|
||||||
SendPlayerUpdate();
|
SendPlayerUpdate();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -281,123 +282,134 @@ void InWorld::HandleDisconnect(SerialPacket packet) {
|
|||||||
|
|
||||||
void InWorld::HandleRegionContent(SerialPacket packet) {
|
void InWorld::HandleRegionContent(SerialPacket packet) {
|
||||||
//replace existing regions
|
//replace existing regions
|
||||||
if (regionPager.FindRegion(packet.regionInfo.x, packet.regionInfo.y)) {
|
regionPager.UnloadRegion(packet.regionInfo.x, packet.regionInfo.y);
|
||||||
regionPager.UnloadRegion(packet.regionInfo.x, packet.regionInfo.y);
|
|
||||||
}
|
|
||||||
regionPager.PushRegion(packet.regionInfo.region);
|
regionPager.PushRegion(packet.regionInfo.region);
|
||||||
packet.regionInfo.region = nullptr;
|
packet.regionInfo.region = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleCharacterUpdate(SerialPacket packet) {
|
void InWorld::HandleCharacterUpdate(SerialPacket packet) {
|
||||||
if (playerCharacters.find(packet.characterInfo.characterIndex) == playerCharacters.end()) {
|
if (characterMap.find(packet.characterInfo.characterIndex) == characterMap.end()) {
|
||||||
HandleCharacterNew(packet);
|
HandleCharacterNew(packet);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//update only if the message didn't originate from here
|
//update only if the message didn't originate from here
|
||||||
if (packet.characterInfo.clientIndex != clientIndex) {
|
if (packet.characterInfo.clientIndex != clientIndex) {
|
||||||
playerCharacters[packet.characterInfo.characterIndex].SetPosition(packet.characterInfo.position);
|
characterMap[packet.characterInfo.characterIndex].position = packet.characterInfo.position;
|
||||||
playerCharacters[packet.characterInfo.characterIndex].SetMotion(packet.characterInfo.motion);
|
characterMap[packet.characterInfo.characterIndex].motion = packet.characterInfo.motion;
|
||||||
}
|
}
|
||||||
playerCharacters[packet.characterInfo.characterIndex].ResetDirection();
|
characterMap[packet.characterInfo.characterIndex].CorrectSprite();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleCharacterNew(SerialPacket packet) {
|
void InWorld::HandleCharacterNew(SerialPacket packet) {
|
||||||
if (playerCharacters.find(packet.characterInfo.characterIndex) != playerCharacters.end()) {
|
if (characterMap.find(packet.characterInfo.characterIndex) != characterMap.end()) {
|
||||||
throw(std::runtime_error("Cannot create duplicate characters"));
|
throw(std::runtime_error("Cannot create duplicate characters"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: set the player's handle
|
//create the character object
|
||||||
playerCharacters[packet.characterInfo.characterIndex].GetSprite()->LoadSurface(config["dir.sprites"] + packet.characterInfo.avatar, 4, 4);
|
CharacterData& character = characterMap[packet.characterInfo.characterIndex];
|
||||||
playerCharacters[packet.characterInfo.characterIndex].SetPosition(packet.characterInfo.position);
|
|
||||||
playerCharacters[packet.characterInfo.characterIndex].SetMotion(packet.characterInfo.motion);
|
//set the members
|
||||||
playerCharacters[packet.characterInfo.characterIndex].ResetDirection();
|
character.handle = packet.characterInfo.handle;
|
||||||
|
character.avatar = packet.characterInfo.avatar;
|
||||||
|
character.sprite.LoadSurface(config["dir.sprites"] + character.avatar, 4, 4);
|
||||||
|
character.mapIndex = packet.characterInfo.mapIndex;
|
||||||
|
character.position = packet.characterInfo.position;
|
||||||
|
character.motion = packet.characterInfo.motion;
|
||||||
|
character.stats = packet.characterInfo.stats;
|
||||||
|
|
||||||
|
character.CorrectSprite();
|
||||||
|
|
||||||
//catch this client's player object
|
//catch this client's player object
|
||||||
if (packet.characterInfo.characterIndex == characterIndex && !localCharacter) {
|
if (packet.characterInfo.characterIndex == characterIndex && !localCharacter) {
|
||||||
localCharacter = &playerCharacters[characterIndex];
|
localCharacter = &character;
|
||||||
|
|
||||||
//setup the camera
|
//setup the camera
|
||||||
|
//TODO: can't change the screen size?
|
||||||
camera.width = GetScreen()->w;
|
camera.width = GetScreen()->w;
|
||||||
camera.height = GetScreen()->h;
|
camera.height = GetScreen()->h;
|
||||||
|
|
||||||
//center on the player's character
|
//center on the player's character
|
||||||
camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
|
camera.marginX = (GetScreen()->w / 2 - localCharacter->sprite.GetImage()->GetClipW() / 2);
|
||||||
camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2);
|
camera.marginY = (GetScreen()->h / 2 - localCharacter->sprite.GetImage()->GetClipH() / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleCharacterDelete(SerialPacket packet) {
|
void InWorld::HandleCharacterDelete(SerialPacket packet) {
|
||||||
//TODO: authenticate
|
//TODO: authenticate when own character is being deleted (linked to a TODO in the server)
|
||||||
if (playerCharacters.find(packet.characterInfo.characterIndex) == playerCharacters.end()) {
|
|
||||||
throw(std::runtime_error("Cannot delete non-existant characters"));
|
|
||||||
}
|
|
||||||
|
|
||||||
playerCharacters.erase(packet.characterInfo.characterIndex);
|
|
||||||
|
|
||||||
//catch this client's player object
|
//catch this client's player object
|
||||||
if (packet.characterInfo.characterIndex == characterIndex) {
|
if (packet.characterInfo.characterIndex == characterIndex) {
|
||||||
characterIndex = -1;
|
characterIndex = -1;
|
||||||
localCharacter = nullptr;
|
localCharacter = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
characterMap.erase(packet.characterInfo.characterIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Server control
|
//Server control
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
void InWorld::RequestSynchronize() {
|
||||||
|
SerialPacket packet;
|
||||||
|
|
||||||
|
//request a sync
|
||||||
|
packet.meta.type = SerialPacket::Type::SYNCHRONIZE;
|
||||||
|
packet.clientInfo.clientIndex = clientIndex;
|
||||||
|
packet.clientInfo.accountIndex = accountIndex;
|
||||||
|
packet.clientInfo.characterIndex = characterIndex;
|
||||||
|
|
||||||
|
network.SendTo(Channels::SERVER, &packet);
|
||||||
|
}
|
||||||
|
|
||||||
void InWorld::SendPlayerUpdate() {
|
void InWorld::SendPlayerUpdate() {
|
||||||
SerialPacket packet;
|
SerialPacket packet;
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
|
||||||
|
|
||||||
//pack the packet
|
//pack the packet
|
||||||
packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
|
packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
|
||||||
packet.characterInfo.clientIndex = clientIndex;
|
packet.characterInfo.clientIndex = clientIndex;
|
||||||
packet.characterInfo.accountIndex = accountIndex;
|
packet.characterInfo.accountIndex = accountIndex;
|
||||||
packet.characterInfo.characterIndex = characterIndex;
|
packet.characterInfo.characterIndex = characterIndex;
|
||||||
packet.characterInfo.position = localCharacter->GetPosition();
|
packet.characterInfo.position = localCharacter->position;
|
||||||
packet.characterInfo.motion = localCharacter->GetMotion();
|
packet.characterInfo.motion = localCharacter->motion;
|
||||||
|
|
||||||
serialize(&packet, buffer);
|
network.SendTo(Channels::SERVER, &packet);
|
||||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::RequestDisconnect() {
|
void InWorld::RequestDisconnect() {
|
||||||
SerialPacket packet;
|
SerialPacket packet;
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
|
||||||
|
|
||||||
//send a disconnect request
|
//send a disconnect request
|
||||||
packet.meta.type = SerialPacket::Type::DISCONNECT;
|
packet.meta.type = SerialPacket::Type::DISCONNECT;
|
||||||
packet.clientInfo.clientIndex = clientIndex;
|
packet.clientInfo.clientIndex = clientIndex;
|
||||||
packet.clientInfo.accountIndex = accountIndex;
|
packet.clientInfo.accountIndex = accountIndex;
|
||||||
packet.clientInfo.characterIndex = characterIndex;
|
packet.clientInfo.characterIndex = characterIndex;
|
||||||
serialize(&packet, buffer);
|
|
||||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
network.SendTo(Channels::SERVER, &packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::RequestShutDown() {
|
void InWorld::RequestShutDown() {
|
||||||
SerialPacket packet;
|
SerialPacket packet;
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
|
||||||
|
|
||||||
//send a shutdown request
|
//send a shutdown request
|
||||||
packet.meta.type = SerialPacket::Type::SHUTDOWN;
|
packet.meta.type = SerialPacket::Type::SHUTDOWN;
|
||||||
packet.clientInfo.clientIndex = clientIndex;
|
packet.clientInfo.clientIndex = clientIndex;
|
||||||
packet.clientInfo.accountIndex = accountIndex;
|
packet.clientInfo.accountIndex = accountIndex;
|
||||||
packet.clientInfo.characterIndex = characterIndex;
|
packet.clientInfo.characterIndex = characterIndex;
|
||||||
serialize(&packet, buffer);
|
|
||||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
network.SendTo(Channels::SERVER, &packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::RequestRegion(int mapIndex, int x, int y) {
|
void InWorld::RequestRegion(int mapIndex, int x, int y) {
|
||||||
SerialPacket packet;
|
SerialPacket packet;
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
|
||||||
|
|
||||||
//pack the region's data
|
//pack the region's data
|
||||||
packet.meta.type = SerialPacket::Type::REGION_REQUEST;
|
packet.meta.type = SerialPacket::Type::REGION_REQUEST;
|
||||||
packet.regionInfo.mapIndex = mapIndex;
|
packet.regionInfo.mapIndex = mapIndex;
|
||||||
packet.regionInfo.x = x;
|
packet.regionInfo.x = x;
|
||||||
packet.regionInfo.y = y;
|
packet.regionInfo.y = y;
|
||||||
serialize(&packet, buffer);
|
|
||||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
network.SendTo(Channels::SERVER, &packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -29,8 +29,6 @@
|
|||||||
|
|
||||||
//networking
|
//networking
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
#include "serial_packet.hpp"
|
|
||||||
#include "serial.hpp"
|
|
||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
@@ -42,9 +40,11 @@
|
|||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
#include "frame_rate.hpp"
|
#include "frame_rate.hpp"
|
||||||
|
|
||||||
|
#include "combat_data.hpp"
|
||||||
|
#include "character_data.hpp"
|
||||||
|
|
||||||
//client
|
//client
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "player_character.hpp"
|
|
||||||
|
|
||||||
//STL
|
//STL
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -52,7 +52,15 @@
|
|||||||
class InWorld : public BaseScene {
|
class InWorld : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
InWorld(ConfigUtility* const, UDPNetworkUtility* const, int* const, int* const, int* const);
|
InWorld(
|
||||||
|
ConfigUtility* const argConfig,
|
||||||
|
UDPNetworkUtility* const argNetwork,
|
||||||
|
int* const argClientIndex,
|
||||||
|
int* const argAccountIndex,
|
||||||
|
int* const argCharacterIndex,
|
||||||
|
std::map<int, CombatData>* argCombatMap,
|
||||||
|
std::map<int, CharacterData>* argCharacterMap
|
||||||
|
);
|
||||||
~InWorld();
|
~InWorld();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -80,6 +88,7 @@ protected:
|
|||||||
void HandleRegionContent(SerialPacket);
|
void HandleRegionContent(SerialPacket);
|
||||||
|
|
||||||
//Server control
|
//Server control
|
||||||
|
void RequestSynchronize();
|
||||||
void SendPlayerUpdate();
|
void SendPlayerUpdate();
|
||||||
void RequestDisconnect();
|
void RequestDisconnect();
|
||||||
void RequestShutDown();
|
void RequestShutDown();
|
||||||
@@ -94,6 +103,8 @@ protected:
|
|||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
int& characterIndex;
|
int& characterIndex;
|
||||||
|
std::map<int, CombatData>& combatMap;
|
||||||
|
std::map<int, CharacterData>& characterMap;
|
||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
Image buttonImage;
|
Image buttonImage;
|
||||||
@@ -106,7 +117,7 @@ protected:
|
|||||||
//UI
|
//UI
|
||||||
Button disconnectButton;
|
Button disconnectButton;
|
||||||
Button shutDownButton;
|
Button shutDownButton;
|
||||||
//TODO: Fix the camera
|
//TODO: Review the camera
|
||||||
struct {
|
struct {
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
int width = 0, height = 0;
|
int width = 0, height = 0;
|
||||||
@@ -115,8 +126,7 @@ protected:
|
|||||||
FrameRate fps;
|
FrameRate fps;
|
||||||
|
|
||||||
//game
|
//game
|
||||||
std::map<int, PlayerCharacter> playerCharacters;
|
CharacterData* localCharacter = nullptr;
|
||||||
PlayerCharacter* localCharacter = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -30,7 +30,13 @@
|
|||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
LobbyMenu::LobbyMenu(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex):
|
LobbyMenu::LobbyMenu(
|
||||||
|
ConfigUtility* const argConfig,
|
||||||
|
UDPNetworkUtility* const argNetwork,
|
||||||
|
int* const argClientIndex,
|
||||||
|
int* const argAccountIndex,
|
||||||
|
int* const argCharacterIndex
|
||||||
|
):
|
||||||
config(*argConfig),
|
config(*argConfig),
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
@@ -80,11 +86,9 @@ void LobbyMenu::FrameStart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::Update(double delta) {
|
void LobbyMenu::Update(double delta) {
|
||||||
//suck in all waiting packets
|
//suck in and process all waiting packets
|
||||||
SerialPacket packet;
|
SerialPacket packet;
|
||||||
while(network.Receive()) {
|
while(network.Receive(&packet)) {
|
||||||
deserialize(&packet, network.GetInData());
|
|
||||||
packet.meta.srcAddress = network.GetInPacket()->address;
|
|
||||||
HandlePacket(packet);
|
HandlePacket(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,6 +99,7 @@ void LobbyMenu::FrameEnd() {
|
|||||||
|
|
||||||
void LobbyMenu::Render(SDL_Surface* const screen) {
|
void LobbyMenu::Render(SDL_Surface* const screen) {
|
||||||
//TODO: I need a proper UI system for the entire client and the editor
|
//TODO: I need a proper UI system for the entire client and the editor
|
||||||
|
|
||||||
//UI
|
//UI
|
||||||
search.DrawTo(screen);
|
search.DrawTo(screen);
|
||||||
join.DrawTo(screen);
|
join.DrawTo(screen);
|
||||||
@@ -120,7 +125,7 @@ void LobbyMenu::Render(SDL_Surface* const screen) {
|
|||||||
font.DrawStringTo("?", screen, listBox.x - font.GetCharW(), listBox.y + i*listBox.h);
|
font.DrawStringTo("?", screen, listBox.x - font.GetCharW(), listBox.y + i*listBox.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
//ping?
|
//TODO: ping/delay?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,14 +147,10 @@ void LobbyMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
|||||||
|
|
||||||
void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
if (search.MouseButtonUp(button) == Button::State::HOVER) {
|
if (search.MouseButtonUp(button) == Button::State::HOVER) {
|
||||||
//the vars
|
|
||||||
SerialPacket packet;
|
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
|
||||||
|
|
||||||
//broadcast to the network, or a specific server
|
//broadcast to the network, or a specific server
|
||||||
|
SerialPacket packet;
|
||||||
packet.meta.type = SerialPacket::Type::BROADCAST_REQUEST;
|
packet.meta.type = SerialPacket::Type::BROADCAST_REQUEST;
|
||||||
serialize(&packet, buffer);
|
network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet);
|
||||||
network.Send(config["server.host"].c_str(), config.Int("server.port"), buffer, PACKET_BUFFER_SIZE);
|
|
||||||
|
|
||||||
//reset the server list
|
//reset the server list
|
||||||
serverInfo.clear();
|
serverInfo.clear();
|
||||||
@@ -157,19 +158,15 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (join.MouseButtonUp(button) == Button::State::HOVER && selection != nullptr && selection->compatible) {
|
else if (join.MouseButtonUp(button) == Button::State::HOVER && selection != nullptr && selection->compatible) {
|
||||||
//the vars
|
|
||||||
SerialPacket packet;
|
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
|
||||||
|
|
||||||
//pack the packet
|
//pack the packet
|
||||||
|
SerialPacket packet;
|
||||||
packet.meta.type = SerialPacket::Type::JOIN_REQUEST;
|
packet.meta.type = SerialPacket::Type::JOIN_REQUEST;
|
||||||
strncpy(packet.clientInfo.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
|
strncpy(packet.clientInfo.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
|
||||||
strncpy(packet.clientInfo.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
|
strncpy(packet.clientInfo.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
|
||||||
strncpy(packet.clientInfo.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
|
strncpy(packet.clientInfo.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
|
||||||
|
|
||||||
//join the selected server
|
//join the selected server
|
||||||
serialize(&packet, buffer);
|
network.SendTo(&selection->address, &packet);
|
||||||
network.Send(&selection->address, buffer, PACKET_BUFFER_SIZE);
|
|
||||||
selection = nullptr;
|
selection = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,6 +200,10 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Network handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
void LobbyMenu::HandlePacket(SerialPacket packet) {
|
void LobbyMenu::HandlePacket(SerialPacket packet) {
|
||||||
switch(packet.meta.type) {
|
switch(packet.meta.type) {
|
||||||
case SerialPacket::Type::BROADCAST_RESPONSE: {
|
case SerialPacket::Type::BROADCAST_RESPONSE: {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -30,8 +30,6 @@
|
|||||||
|
|
||||||
//network
|
//network
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
#include "serial_packet.hpp"
|
|
||||||
#include "serial.hpp"
|
|
||||||
|
|
||||||
//client
|
//client
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
@@ -42,7 +40,13 @@
|
|||||||
class LobbyMenu : public BaseScene {
|
class LobbyMenu : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
LobbyMenu(ConfigUtility* const, UDPNetworkUtility* const, int* const, int* const, int* const);
|
LobbyMenu(
|
||||||
|
ConfigUtility* const argConfig,
|
||||||
|
UDPNetworkUtility* const argNetwork,
|
||||||
|
int* const argClientIndex,
|
||||||
|
int* const argAccountIndex,
|
||||||
|
int* const argCharacterIndex
|
||||||
|
);
|
||||||
~LobbyMenu();
|
~LobbyMenu();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -59,6 +63,7 @@ protected:
|
|||||||
void KeyDown(SDL_KeyboardEvent const&);
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
void KeyUp(SDL_KeyboardEvent const&);
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
|
//Network handlers
|
||||||
void HandlePacket(SerialPacket);
|
void HandlePacket(SerialPacket);
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
+3
-10
@@ -1,17 +1,14 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. scenes ../common ../common/graphics ../common/map ../common/network ../common/ui
|
INCLUDES+=. ../common/gameplay ../common/graphics ../common/map ../common/network ../common/ui ../common/utilities
|
||||||
LIBS+=libclient.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS
|
||||||
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
#source
|
||||||
CXXSRC=$(wildcard *.cpp)
|
CXXSRC=$(wildcard *.cpp)
|
||||||
CSRC=$(wildcard *.c)
|
|
||||||
|
|
||||||
#objects
|
#objects
|
||||||
OBJDIR=obj
|
OBJDIR=obj
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o))
|
|
||||||
|
|
||||||
#output
|
#output
|
||||||
OUTDIR=../out
|
OUTDIR=../out
|
||||||
@@ -19,7 +16,6 @@ OUT=$(addprefix $(OUTDIR)/,client)
|
|||||||
|
|
||||||
#targets
|
#targets
|
||||||
all: $(OBJ) $(OUT)
|
all: $(OBJ) $(OUT)
|
||||||
$(MAKE) -C scenes
|
|
||||||
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
||||||
|
|
||||||
$(OBJ): | $(OBJDIR)
|
$(OBJ): | $(OBJDIR)
|
||||||
@@ -35,9 +31,6 @@ $(OUTDIR):
|
|||||||
$(OBJDIR)/%.o: %.cpp
|
$(OBJDIR)/%.o: %.cpp
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.c
|
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o *.a *.exe
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
|
||||||
*
|
|
||||||
* 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 "player_character.hpp"
|
|
||||||
|
|
||||||
#define WALKING_SPEED 140
|
|
||||||
|
|
||||||
void PlayerCharacter::Update(double delta) {
|
|
||||||
if (diagonal) {
|
|
||||||
constexpr double d = 1.0/sqrt(2);
|
|
||||||
position += motion * delta * d;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
position += motion * delta;
|
|
||||||
}
|
|
||||||
sprite.Update(delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerCharacter::AdjustDirection(Direction direction) {
|
|
||||||
//shift the movement in this direction
|
|
||||||
switch(direction) {
|
|
||||||
case Direction::NORTH:
|
|
||||||
if (motion.y >= 0) {
|
|
||||||
motion.y -= WALKING_SPEED;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Direction::SOUTH:
|
|
||||||
if (motion.y <= 0) {
|
|
||||||
motion.y += WALKING_SPEED;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Direction::WEST:
|
|
||||||
if (motion.x >= 0) {
|
|
||||||
motion.x -= WALKING_SPEED;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Direction::EAST:
|
|
||||||
if (motion.x <= 0) {
|
|
||||||
motion.x += WALKING_SPEED;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//face the correct direction
|
|
||||||
ResetDirection();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerCharacter::FaceDirection(Direction direction) {
|
|
||||||
//this function depends on the format of the sprite sheets
|
|
||||||
switch(direction) {
|
|
||||||
case Direction::NORTH:
|
|
||||||
sprite.SetYIndex(1);
|
|
||||||
break;
|
|
||||||
case Direction::SOUTH:
|
|
||||||
sprite.SetYIndex(0);
|
|
||||||
break;
|
|
||||||
case Direction::WEST:
|
|
||||||
sprite.SetYIndex(2);
|
|
||||||
break;
|
|
||||||
case Direction::EAST:
|
|
||||||
sprite.SetYIndex(3);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerCharacter::ResetDirection() {
|
|
||||||
//base the direction on the character's movement
|
|
||||||
if (motion.y > 0) {
|
|
||||||
FaceDirection(Direction::SOUTH);
|
|
||||||
}
|
|
||||||
else if (motion.y < 0) {
|
|
||||||
FaceDirection(Direction::NORTH);
|
|
||||||
}
|
|
||||||
else if (motion.x > 0) {
|
|
||||||
FaceDirection(Direction::EAST);
|
|
||||||
}
|
|
||||||
else if (motion.x < 0) {
|
|
||||||
FaceDirection(Direction::WEST);
|
|
||||||
}
|
|
||||||
ResetSpeed();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerCharacter::ResetSpeed() {
|
|
||||||
//diagonal
|
|
||||||
if (motion.x != 0 && motion.y != 0) {
|
|
||||||
sprite.SetDelay(0.1);
|
|
||||||
diagonal = true;
|
|
||||||
}
|
|
||||||
//cardinal
|
|
||||||
else if (motion != 0) {
|
|
||||||
sprite.SetDelay(0.1);
|
|
||||||
diagonal = false;
|
|
||||||
}
|
|
||||||
//not moving
|
|
||||||
else {
|
|
||||||
sprite.SetDelay(0);
|
|
||||||
sprite.SetXIndex(0);
|
|
||||||
diagonal = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
|
||||||
*
|
|
||||||
* 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 PLAYERCHARACTER_HPP_
|
|
||||||
#define PLAYERCHARACTER_HPP_
|
|
||||||
|
|
||||||
#include "vector2.hpp"
|
|
||||||
#include "sprite_sheet.hpp"
|
|
||||||
|
|
||||||
//TODO: correct the PlayerCharacter class and it's movement system
|
|
||||||
class PlayerCharacter {
|
|
||||||
public:
|
|
||||||
enum class Direction {
|
|
||||||
NORTH, SOUTH, EAST, WEST
|
|
||||||
};
|
|
||||||
|
|
||||||
PlayerCharacter() = default;
|
|
||||||
~PlayerCharacter() = default;
|
|
||||||
|
|
||||||
void Update(double delta);
|
|
||||||
|
|
||||||
void DrawTo(SDL_Surface* const dest, int camX, int camY) { sprite.DrawTo(dest, position.x - camX, position.y - camY); }
|
|
||||||
|
|
||||||
//clunky code results in smooth movement and controls
|
|
||||||
void AdjustDirection(Direction);
|
|
||||||
void FaceDirection(Direction);
|
|
||||||
void ResetDirection();
|
|
||||||
void ResetSpeed();
|
|
||||||
|
|
||||||
//accessors and mutators
|
|
||||||
Vector2 SetPosition(Vector2 v) { return position = v; }
|
|
||||||
Vector2 ShiftPosition(Vector2 v) { return position += v; }
|
|
||||||
Vector2 GetPosition() { return position; }
|
|
||||||
|
|
||||||
Vector2 SetMotion(Vector2 v) { return motion = v; }
|
|
||||||
Vector2 ShiftMotion(Vector2 v) { return motion += v; }
|
|
||||||
Vector2 GetMotion() { return motion; }
|
|
||||||
|
|
||||||
SpriteSheet* GetSprite() { return &sprite; }
|
|
||||||
private:
|
|
||||||
Vector2 position;
|
|
||||||
Vector2 motion;
|
|
||||||
SpriteSheet sprite;
|
|
||||||
|
|
||||||
//for moving diagonally
|
|
||||||
bool diagonal = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/* 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 "character_data.hpp"
|
||||||
|
|
||||||
|
void CharacterData::Update(double delta) {
|
||||||
|
if (motion.x && motion.y) {
|
||||||
|
position += motion * delta * CHARACTER_WALKING_MOD;
|
||||||
|
}
|
||||||
|
else if (motion != 0) {
|
||||||
|
position += motion * delta;
|
||||||
|
}
|
||||||
|
#ifdef GRAPHICS
|
||||||
|
sprite.Update(delta);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef GRAPHICS
|
||||||
|
|
||||||
|
void CharacterData::DrawTo(SDL_Surface* const dest, int camX, int camY) {
|
||||||
|
sprite.DrawTo(dest, position.x - camX, position.y - camY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CharacterData::CorrectSprite() {
|
||||||
|
//NOTE: These must correspond to the sprite sheet in use
|
||||||
|
if (motion.y > 0) {
|
||||||
|
sprite.SetYIndex(0);
|
||||||
|
}
|
||||||
|
else if (motion.y < 0) {
|
||||||
|
sprite.SetYIndex(1);
|
||||||
|
}
|
||||||
|
else if (motion.x > 0) {
|
||||||
|
sprite.SetYIndex(3);
|
||||||
|
}
|
||||||
|
else if (motion.x < 0) {
|
||||||
|
sprite.SetYIndex(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
//animation
|
||||||
|
if (motion != 0) {
|
||||||
|
sprite.SetDelay(0.1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sprite.SetDelay(0);
|
||||||
|
sprite.SetXIndex(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/* 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 CHARACTERDATA_HPP_
|
||||||
|
#define CHARACTERDATA_HPP_
|
||||||
|
|
||||||
|
//POD members
|
||||||
|
#include "bbox.hpp"
|
||||||
|
#include "vector2.hpp"
|
||||||
|
#include "statistics.hpp"
|
||||||
|
|
||||||
|
//graphics
|
||||||
|
#ifdef GRAPHICS
|
||||||
|
#include "sprite_sheet.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//std namespace
|
||||||
|
#include <string>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
//the speeds that the characters move
|
||||||
|
constexpr double CHARACTER_WALKING_SPEED = 140.0;
|
||||||
|
constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0);
|
||||||
|
|
||||||
|
struct CharacterData {
|
||||||
|
//metadata
|
||||||
|
int owner;
|
||||||
|
std::string handle;
|
||||||
|
std::string avatar;
|
||||||
|
|
||||||
|
//world position
|
||||||
|
int mapIndex = 0;
|
||||||
|
Vector2 position = {0.0,0.0};
|
||||||
|
Vector2 motion = {0.0,0.0};
|
||||||
|
|
||||||
|
//base statistics
|
||||||
|
Statistics stats;
|
||||||
|
|
||||||
|
//TODO: equipment
|
||||||
|
//TODO: items
|
||||||
|
//TODO: buffs
|
||||||
|
//TODO: debuffs
|
||||||
|
|
||||||
|
//methods
|
||||||
|
void Update(double delta);
|
||||||
|
#ifdef GRAPHICS
|
||||||
|
void DrawTo(SDL_Surface* const, int camX, int camY);
|
||||||
|
void CorrectSprite();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//active gameplay members
|
||||||
|
//NOTE: these are lost when unloaded
|
||||||
|
#ifdef GRAPHICS
|
||||||
|
SpriteSheet sprite;
|
||||||
|
#endif
|
||||||
|
BBox bbox = {0,0,0,0};
|
||||||
|
bool inCombat = false;
|
||||||
|
int atbGauge = 0;
|
||||||
|
//TODO: stored command
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
struct ClientData {
|
struct ClientData {
|
||||||
IPaddress address = {0,0};
|
IPaddress address = {0,0};
|
||||||
static int uidCounter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/* 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 COMBATDATA_HPP_
|
||||||
|
#define COMBATDATA_HPP_
|
||||||
|
|
||||||
|
//POD members
|
||||||
|
#include "vector2.hpp"
|
||||||
|
#include "bbox.hpp"
|
||||||
|
|
||||||
|
//gameplay members
|
||||||
|
#include "character_data.hpp"
|
||||||
|
#include "enemy_data.hpp"
|
||||||
|
|
||||||
|
//graphics
|
||||||
|
#ifdef GRAPHICS
|
||||||
|
#include "sprite_sheet.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//std namespace
|
||||||
|
#include <chrono>
|
||||||
|
#include <list>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
struct CombatData {
|
||||||
|
typedef std::chrono::steady_clock Clock;
|
||||||
|
|
||||||
|
//combatants, point to the std::map's internal pairs
|
||||||
|
std::list<std::pair<const int, CharacterData>*> characterList;
|
||||||
|
std::list<std::pair<const int, EnemyData>*> enemyList;
|
||||||
|
|
||||||
|
//world interaction
|
||||||
|
int mapIndex = 0;
|
||||||
|
Vector2 position = {0.0,0.0};
|
||||||
|
BBox bbox = {0,0,0,0};
|
||||||
|
|
||||||
|
//time interval
|
||||||
|
Clock::time_point lastTick = Clock::now();
|
||||||
|
|
||||||
|
//graphics
|
||||||
|
#ifdef GRAPHICS
|
||||||
|
SpriteSheet sprite;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/* 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 ENEMYDATA_HPP_
|
||||||
|
#define ENEMYDATA_HPP_
|
||||||
|
|
||||||
|
//gameplay
|
||||||
|
#include "statistics.hpp"
|
||||||
|
|
||||||
|
//graphics
|
||||||
|
#ifdef GRAPHICS
|
||||||
|
#include "sprite_sheet.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//std namespace
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct EnemyData {
|
||||||
|
//metadata
|
||||||
|
std::string handle;
|
||||||
|
std::string avatar;
|
||||||
|
|
||||||
|
//gameplay
|
||||||
|
Statistics stats;
|
||||||
|
|
||||||
|
//TODO: equipment
|
||||||
|
//TODO: items
|
||||||
|
//TODO: buffs
|
||||||
|
//TODO: debuffs
|
||||||
|
|
||||||
|
//active gameplay members
|
||||||
|
//NOTE: these are lost when unloaded
|
||||||
|
#ifdef GRAPHICS
|
||||||
|
SpriteSheet sprite;
|
||||||
|
#endif
|
||||||
|
int tableIndex;
|
||||||
|
int atbGauge = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,21 +1,18 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../../common ../../common/graphics ../../common/map ../../common/network ../../common/ui
|
INCLUDES+=. ../utilities ../graphics
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS
|
||||||
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
#source
|
||||||
CXXSRC=$(wildcard *.cpp)
|
CXXSRC=$(wildcard *.cpp)
|
||||||
CSRC=$(wildcard *.c)
|
|
||||||
|
|
||||||
#objects
|
#objects
|
||||||
OBJDIR=obj
|
OBJDIR=obj
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o))
|
|
||||||
|
|
||||||
#output
|
#output
|
||||||
OUTDIR=..
|
OUTDIR=../..
|
||||||
OUT=$(addprefix $(OUTDIR)/,libclient.a)
|
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
|
||||||
|
|
||||||
#targets
|
#targets
|
||||||
all: $(OBJ) $(OUT)
|
all: $(OBJ) $(OUT)
|
||||||
@@ -34,9 +31,6 @@ $(OUTDIR):
|
|||||||
$(OBJDIR)/%.o: %.cpp
|
$(OBJDIR)/%.o: %.cpp
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.c
|
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o *.a *.exe
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
@@ -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 "account_data.hpp"
|
||||||
|
#include "character_data.hpp"
|
||||||
|
#include "client_data.hpp"
|
||||||
|
#include "combat_data.hpp"
|
||||||
|
#include "enemy_data.hpp"
|
||||||
|
#include "statistics.hpp"
|
||||||
|
|
||||||
|
/* DOCS: Sanity check, read more
|
||||||
|
* Since most/all of the files in this directory are header files, I've created
|
||||||
|
* this source file as a "sanity check", to ensure that the above header files
|
||||||
|
* are written correctly via make.
|
||||||
|
*
|
||||||
|
* Oddly enough, I'm pretty sure this is the first directory compiled in a
|
||||||
|
* clean build.
|
||||||
|
*/
|
||||||
@@ -19,28 +19,10 @@
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
#ifndef CHARACTERDATA_HPP_
|
#ifndef STATISTICS_HPP_
|
||||||
#define CHARACTERDATA_HPP_
|
#define STATISTICS_HPP_
|
||||||
|
|
||||||
//POD members
|
struct Statistics {
|
||||||
#include "bbox.hpp"
|
|
||||||
#include "vector2.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
struct CharacterData {
|
|
||||||
//metadata
|
|
||||||
int owner;
|
|
||||||
std::string handle;
|
|
||||||
std::string avatar;
|
|
||||||
|
|
||||||
//world position
|
|
||||||
int mapIndex = 0;
|
|
||||||
Vector2 position = {0.0,0.0};
|
|
||||||
Vector2 motion = {0.0,0.0};
|
|
||||||
BBox bbox = {0,0,0,0};
|
|
||||||
|
|
||||||
//statistics
|
|
||||||
int level = 0;
|
int level = 0;
|
||||||
int exp = 0;
|
int exp = 0;
|
||||||
int maxHP = 0;
|
int maxHP = 0;
|
||||||
@@ -51,9 +33,10 @@ struct CharacterData {
|
|||||||
int defence = 0;
|
int defence = 0;
|
||||||
int intelligence = 0;
|
int intelligence = 0;
|
||||||
int resistance = 0;
|
int resistance = 0;
|
||||||
|
int speed = 0;
|
||||||
float accuracy = 0.0;
|
float accuracy = 0.0;
|
||||||
float evasion = 0.0;
|
float evasion = 0.0;
|
||||||
float luck = 0.0;
|
float luck = 0.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../map
|
INCLUDES+=. ../map
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
#source
|
||||||
CXXSRC=$(wildcard *.cpp)
|
CXXSRC=$(wildcard *.cpp)
|
||||||
CSRC=$(wildcard *.c)
|
|
||||||
|
|
||||||
#objects
|
#objects
|
||||||
OBJDIR=obj
|
OBJDIR=obj
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o))
|
|
||||||
|
|
||||||
#output
|
#output
|
||||||
OUTDIR=../..
|
OUTDIR=../..
|
||||||
@@ -34,9 +31,6 @@ $(OUTDIR):
|
|||||||
$(OBJDIR)/%.o: %.cpp
|
$(OBJDIR)/%.o: %.cpp
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.c
|
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o *.a *.exe
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
+4
-39
@@ -1,46 +1,11 @@
|
|||||||
#config
|
all:
|
||||||
INCLUDES+=.
|
$(MAKE) -C gameplay
|
||||||
LIBS+=
|
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
|
||||||
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
|
||||||
CXXSRC=$(wildcard *.cpp)
|
|
||||||
CSRC=$(wildcard *.c)
|
|
||||||
|
|
||||||
#objects
|
|
||||||
OBJDIR=obj
|
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o))
|
|
||||||
|
|
||||||
#output
|
|
||||||
OUTDIR=..
|
|
||||||
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
|
|
||||||
|
|
||||||
#targets
|
|
||||||
all: $(OBJ) $(OUT)
|
|
||||||
ar -crs $(OUT) $(OBJ)
|
|
||||||
$(MAKE) -C graphics
|
$(MAKE) -C graphics
|
||||||
$(MAKE) -C map
|
$(MAKE) -C map
|
||||||
$(MAKE) -C script
|
|
||||||
$(MAKE) -C network
|
$(MAKE) -C network
|
||||||
|
$(MAKE) -C script
|
||||||
$(MAKE) -C ui
|
$(MAKE) -C ui
|
||||||
|
$(MAKE) -C utilities
|
||||||
$(OBJ): | $(OBJDIR)
|
|
||||||
|
|
||||||
$(OUT): | $(OUTDIR)
|
|
||||||
|
|
||||||
$(OBJDIR):
|
|
||||||
mkdir $(OBJDIR)
|
|
||||||
|
|
||||||
$(OUTDIR):
|
|
||||||
mkdir $(OUTDIR)
|
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.cpp
|
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.c
|
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o *.a *.exe
|
$(RM) *.o *.a *.exe
|
||||||
|
|||||||
+2
-8
@@ -1,17 +1,14 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../graphics
|
INCLUDES+=. ../utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
#source
|
||||||
CXXSRC=$(wildcard *.cpp)
|
CXXSRC=$(wildcard *.cpp)
|
||||||
CSRC=$(wildcard *.c)
|
|
||||||
|
|
||||||
#objects
|
#objects
|
||||||
OBJDIR=obj
|
OBJDIR=obj
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o))
|
|
||||||
|
|
||||||
#output
|
#output
|
||||||
OUTDIR=../..
|
OUTDIR=../..
|
||||||
@@ -34,9 +31,6 @@ $(OUTDIR):
|
|||||||
$(OBJDIR)/%.o: %.cpp
|
$(OBJDIR)/%.o: %.cpp
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.c
|
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o *.a *.exe
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../map
|
INCLUDES+=. ../gameplay ../map ../utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
#source
|
||||||
CXXSRC=$(wildcard *.cpp)
|
CXXSRC=$(wildcard *.cpp)
|
||||||
CSRC=$(wildcard *.c)
|
|
||||||
|
|
||||||
#objects
|
#objects
|
||||||
OBJDIR=obj
|
OBJDIR=obj
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o))
|
|
||||||
|
|
||||||
#output
|
#output
|
||||||
OUTDIR=../..
|
OUTDIR=../..
|
||||||
@@ -34,9 +31,6 @@ $(OUTDIR):
|
|||||||
$(OBJDIR)/%.o: %.cpp
|
$(OBJDIR)/%.o: %.cpp
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.c
|
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o *.a *.exe
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
|||||||
+155
-8
@@ -22,6 +22,7 @@
|
|||||||
#include "serial.hpp"
|
#include "serial.hpp"
|
||||||
|
|
||||||
#include "map_allocator.hpp"
|
#include "map_allocator.hpp"
|
||||||
|
#include "statistics.hpp"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
@@ -59,6 +60,7 @@ void serializeClient(SerialPacket* packet, char* buffer) {
|
|||||||
|
|
||||||
//texts
|
//texts
|
||||||
SERIALIZE(buffer, packet->clientInfo.username, PACKET_STRING_SIZE);
|
SERIALIZE(buffer, packet->clientInfo.username, PACKET_STRING_SIZE);
|
||||||
|
//TODO: password
|
||||||
SERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE);
|
SERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE);
|
||||||
SERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE);
|
SERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE);
|
||||||
}
|
}
|
||||||
@@ -91,6 +93,35 @@ void serializeRegionContent(SerialPacket* packet, char* buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void serializeCombat(SerialPacket* packet, char* buffer) {
|
||||||
|
SERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type));
|
||||||
|
|
||||||
|
//integers
|
||||||
|
SERIALIZE(buffer, &packet->combatInfo.combatIndex, sizeof(int));
|
||||||
|
SERIALIZE(buffer, &packet->combatInfo.difficulty, sizeof(int));
|
||||||
|
//TODO: more comabat info
|
||||||
|
}
|
||||||
|
|
||||||
|
void serializeStatistics(Statistics* stats, char* buffer) {
|
||||||
|
//integers
|
||||||
|
SERIALIZE(buffer, &stats->level, sizeof(int));
|
||||||
|
SERIALIZE(buffer, &stats->exp, sizeof(int));
|
||||||
|
SERIALIZE(buffer, &stats->maxHP, sizeof(int));
|
||||||
|
SERIALIZE(buffer, &stats->health, sizeof(int));
|
||||||
|
SERIALIZE(buffer, &stats->maxMP, sizeof(int));
|
||||||
|
SERIALIZE(buffer, &stats->mana, sizeof(int));
|
||||||
|
SERIALIZE(buffer, &stats->attack, sizeof(int));
|
||||||
|
SERIALIZE(buffer, &stats->defence, sizeof(int));
|
||||||
|
SERIALIZE(buffer, &stats->intelligence, sizeof(int));
|
||||||
|
SERIALIZE(buffer, &stats->resistance, sizeof(int));
|
||||||
|
SERIALIZE(buffer, &stats->speed, sizeof(int));
|
||||||
|
|
||||||
|
//floats
|
||||||
|
SERIALIZE(buffer, &stats->accuracy, sizeof(float));
|
||||||
|
SERIALIZE(buffer, &stats->evasion, sizeof(float));
|
||||||
|
SERIALIZE(buffer, &stats->luck, sizeof(float));
|
||||||
|
}
|
||||||
|
|
||||||
void serializeCharacter(SerialPacket* packet, char* buffer) {
|
void serializeCharacter(SerialPacket* packet, char* buffer) {
|
||||||
SERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type));
|
SERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type));
|
||||||
|
|
||||||
@@ -108,6 +139,22 @@ void serializeCharacter(SerialPacket* packet, char* buffer) {
|
|||||||
SERIALIZE(buffer, &packet->characterInfo.position.y, sizeof(double));
|
SERIALIZE(buffer, &packet->characterInfo.position.y, sizeof(double));
|
||||||
SERIALIZE(buffer, &packet->characterInfo.motion.x, sizeof(double));
|
SERIALIZE(buffer, &packet->characterInfo.motion.x, sizeof(double));
|
||||||
SERIALIZE(buffer, &packet->characterInfo.motion.y, sizeof(double));
|
SERIALIZE(buffer, &packet->characterInfo.motion.y, sizeof(double));
|
||||||
|
|
||||||
|
//stats structure
|
||||||
|
serializeStatistics(&packet->characterInfo.stats, buffer);
|
||||||
|
buffer += sizeof(Statistics);
|
||||||
|
}
|
||||||
|
|
||||||
|
void serializeEnemy(SerialPacket* packet, char* buffer) {
|
||||||
|
SERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type));
|
||||||
|
|
||||||
|
//texts
|
||||||
|
SERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE);
|
||||||
|
SERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE);
|
||||||
|
|
||||||
|
//stats structure
|
||||||
|
serializeStatistics(&packet->characterInfo.stats, buffer);
|
||||||
|
buffer += sizeof(Statistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -137,6 +184,7 @@ void deserializeClient(SerialPacket* packet, char* buffer) {
|
|||||||
|
|
||||||
//texts
|
//texts
|
||||||
DESERIALIZE(buffer, packet->clientInfo.username, PACKET_STRING_SIZE);
|
DESERIALIZE(buffer, packet->clientInfo.username, PACKET_STRING_SIZE);
|
||||||
|
//TODO: password
|
||||||
DESERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE);
|
DESERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE);
|
||||||
DESERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE);
|
DESERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE);
|
||||||
}
|
}
|
||||||
@@ -176,6 +224,37 @@ void deserializeRegionContent(SerialPacket* packet, char* buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void deserializeCombat(SerialPacket* packet, char* buffer) {
|
||||||
|
DESERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type));
|
||||||
|
|
||||||
|
//integers
|
||||||
|
DESERIALIZE(buffer, &packet->combatInfo.combatIndex, sizeof(int));
|
||||||
|
DESERIALIZE(buffer, &packet->combatInfo.difficulty, sizeof(int));
|
||||||
|
//TODO: more comabat info
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void deserializeStatistics(Statistics* stats, char* buffer) {
|
||||||
|
//integers
|
||||||
|
DESERIALIZE(buffer, &stats->level, sizeof(int));
|
||||||
|
DESERIALIZE(buffer, &stats->exp, sizeof(int));
|
||||||
|
DESERIALIZE(buffer, &stats->maxHP, sizeof(int));
|
||||||
|
DESERIALIZE(buffer, &stats->health, sizeof(int));
|
||||||
|
DESERIALIZE(buffer, &stats->maxMP, sizeof(int));
|
||||||
|
DESERIALIZE(buffer, &stats->mana, sizeof(int));
|
||||||
|
DESERIALIZE(buffer, &stats->attack, sizeof(int));
|
||||||
|
DESERIALIZE(buffer, &stats->defence, sizeof(int));
|
||||||
|
DESERIALIZE(buffer, &stats->intelligence, sizeof(int));
|
||||||
|
DESERIALIZE(buffer, &stats->resistance, sizeof(int));
|
||||||
|
DESERIALIZE(buffer, &stats->speed, sizeof(int));
|
||||||
|
|
||||||
|
//floats
|
||||||
|
DESERIALIZE(buffer, &stats->accuracy, sizeof(float));
|
||||||
|
DESERIALIZE(buffer, &stats->evasion, sizeof(float));
|
||||||
|
DESERIALIZE(buffer, &stats->luck, sizeof(float));
|
||||||
|
}
|
||||||
|
|
||||||
void deserializeCharacter(SerialPacket* packet, char* buffer) {
|
void deserializeCharacter(SerialPacket* packet, char* buffer) {
|
||||||
DESERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type));
|
DESERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type));
|
||||||
|
|
||||||
@@ -193,6 +272,22 @@ void deserializeCharacter(SerialPacket* packet, char* buffer) {
|
|||||||
DESERIALIZE(buffer, &packet->characterInfo.position.y, sizeof(double));
|
DESERIALIZE(buffer, &packet->characterInfo.position.y, sizeof(double));
|
||||||
DESERIALIZE(buffer, &packet->characterInfo.motion.x, sizeof(double));
|
DESERIALIZE(buffer, &packet->characterInfo.motion.x, sizeof(double));
|
||||||
DESERIALIZE(buffer, &packet->characterInfo.motion.y, sizeof(double));
|
DESERIALIZE(buffer, &packet->characterInfo.motion.y, sizeof(double));
|
||||||
|
|
||||||
|
//stats structure
|
||||||
|
deserializeStatistics(&packet->characterInfo.stats, buffer);
|
||||||
|
buffer += sizeof(Statistics);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deserializeEnemy(SerialPacket* packet, char* buffer) {
|
||||||
|
DESERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type));
|
||||||
|
|
||||||
|
//texts
|
||||||
|
DESERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE);
|
||||||
|
DESERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE);
|
||||||
|
|
||||||
|
//stats structure
|
||||||
|
deserializeStatistics(&packet->characterInfo.stats, buffer);
|
||||||
|
buffer += sizeof(Statistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -201,20 +296,29 @@ void deserializeCharacter(SerialPacket* packet, char* buffer) {
|
|||||||
|
|
||||||
void serialize(SerialPacket* packet, void* buffer) {
|
void serialize(SerialPacket* packet, void* buffer) {
|
||||||
switch(packet->meta.type) {
|
switch(packet->meta.type) {
|
||||||
//No extra data
|
//no extra data
|
||||||
case SerialPacket::Type::NONE:
|
case SerialPacket::Type::NONE:
|
||||||
case SerialPacket::Type::PING:
|
case SerialPacket::Type::PING:
|
||||||
case SerialPacket::Type::PONG:
|
case SerialPacket::Type::PONG:
|
||||||
case SerialPacket::Type::BROADCAST_REQUEST:
|
case SerialPacket::Type::BROADCAST_REQUEST:
|
||||||
|
|
||||||
|
//all rejections
|
||||||
|
case SerialPacket::Type::BROADCAST_REJECTION:
|
||||||
|
case SerialPacket::Type::JOIN_REJECTION:
|
||||||
|
case SerialPacket::Type::REGION_REJECTION:
|
||||||
|
case SerialPacket::Type::CHARACTER_REJECTION:
|
||||||
|
case SerialPacket::Type::ENEMY_REJECTION:
|
||||||
|
case SerialPacket::Type::COMBAT_REJECTION:
|
||||||
|
|
||||||
serializeType(packet, reinterpret_cast<char*>(buffer));
|
serializeType(packet, reinterpret_cast<char*>(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Server info
|
//server info
|
||||||
case SerialPacket::Type::BROADCAST_RESPONSE:
|
case SerialPacket::Type::BROADCAST_RESPONSE:
|
||||||
serializeServer(packet, reinterpret_cast<char*>(buffer));
|
serializeServer(packet, reinterpret_cast<char*>(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Client info
|
//client info
|
||||||
case SerialPacket::Type::JOIN_REQUEST:
|
case SerialPacket::Type::JOIN_REQUEST:
|
||||||
case SerialPacket::Type::JOIN_RESPONSE:
|
case SerialPacket::Type::JOIN_RESPONSE:
|
||||||
case SerialPacket::Type::SYNCHRONIZE:
|
case SerialPacket::Type::SYNCHRONIZE:
|
||||||
@@ -232,12 +336,29 @@ void serialize(SerialPacket* packet, void* buffer) {
|
|||||||
serializeRegionContent(packet, reinterpret_cast<char*>(buffer));
|
serializeRegionContent(packet, reinterpret_cast<char*>(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Character info
|
//combat info
|
||||||
|
case SerialPacket::Type::COMBAT_ENTER:
|
||||||
|
case SerialPacket::Type::COMBAT_EXIT:
|
||||||
|
serializeCombat(packet, reinterpret_cast<char*>(buffer));
|
||||||
|
break;
|
||||||
|
|
||||||
|
//character info
|
||||||
case SerialPacket::Type::CHARACTER_NEW:
|
case SerialPacket::Type::CHARACTER_NEW:
|
||||||
case SerialPacket::Type::CHARACTER_DELETE:
|
case SerialPacket::Type::CHARACTER_DELETE:
|
||||||
case SerialPacket::Type::CHARACTER_UPDATE:
|
case SerialPacket::Type::CHARACTER_UPDATE:
|
||||||
|
case SerialPacket::Type::CHARACTER_STATS_REQUEST:
|
||||||
|
case SerialPacket::Type::CHARACTER_STATS_RESPONSE:
|
||||||
serializeCharacter(packet, reinterpret_cast<char*>(buffer));
|
serializeCharacter(packet, reinterpret_cast<char*>(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
//enemy info
|
||||||
|
case SerialPacket::Type::ENEMY_NEW:
|
||||||
|
case SerialPacket::Type::ENEMY_DELETE:
|
||||||
|
case SerialPacket::Type::ENEMY_UPDATE:
|
||||||
|
case SerialPacket::Type::ENEMY_STATS_REQUEST:
|
||||||
|
case SerialPacket::Type::ENEMY_STATS_RESPONSE:
|
||||||
|
serializeEnemy(packet, reinterpret_cast<char*>(buffer));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,20 +366,29 @@ void deserialize(SerialPacket* packet, void* buffer) {
|
|||||||
//find the type, so that you can actually deserialize the packet!
|
//find the type, so that you can actually deserialize the packet!
|
||||||
deserializeType(packet, reinterpret_cast<char*>(buffer));
|
deserializeType(packet, reinterpret_cast<char*>(buffer));
|
||||||
switch(packet->meta.type) {
|
switch(packet->meta.type) {
|
||||||
//No extra data
|
//no extra data
|
||||||
case SerialPacket::Type::NONE:
|
case SerialPacket::Type::NONE:
|
||||||
case SerialPacket::Type::PING:
|
case SerialPacket::Type::PING:
|
||||||
case SerialPacket::Type::PONG:
|
case SerialPacket::Type::PONG:
|
||||||
case SerialPacket::Type::BROADCAST_REQUEST:
|
case SerialPacket::Type::BROADCAST_REQUEST:
|
||||||
|
|
||||||
|
//all rejections
|
||||||
|
case SerialPacket::Type::BROADCAST_REJECTION:
|
||||||
|
case SerialPacket::Type::JOIN_REJECTION:
|
||||||
|
case SerialPacket::Type::REGION_REJECTION:
|
||||||
|
case SerialPacket::Type::CHARACTER_REJECTION:
|
||||||
|
case SerialPacket::Type::ENEMY_REJECTION:
|
||||||
|
case SerialPacket::Type::COMBAT_REJECTION:
|
||||||
|
|
||||||
//NOTHING
|
//NOTHING
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Server info
|
//server info
|
||||||
case SerialPacket::Type::BROADCAST_RESPONSE:
|
case SerialPacket::Type::BROADCAST_RESPONSE:
|
||||||
deserializeServer(packet, reinterpret_cast<char*>(buffer));
|
deserializeServer(packet, reinterpret_cast<char*>(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Client info
|
//client info
|
||||||
case SerialPacket::Type::JOIN_REQUEST:
|
case SerialPacket::Type::JOIN_REQUEST:
|
||||||
case SerialPacket::Type::JOIN_RESPONSE:
|
case SerialPacket::Type::JOIN_RESPONSE:
|
||||||
case SerialPacket::Type::SYNCHRONIZE:
|
case SerialPacket::Type::SYNCHRONIZE:
|
||||||
@@ -276,11 +406,28 @@ void deserialize(SerialPacket* packet, void* buffer) {
|
|||||||
deserializeRegionContent(packet, reinterpret_cast<char*>(buffer));
|
deserializeRegionContent(packet, reinterpret_cast<char*>(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Character info
|
//combat info
|
||||||
|
case SerialPacket::Type::COMBAT_ENTER:
|
||||||
|
case SerialPacket::Type::COMBAT_EXIT:
|
||||||
|
serializeCombat(packet, reinterpret_cast<char*>(buffer));
|
||||||
|
break;
|
||||||
|
|
||||||
|
//character info
|
||||||
case SerialPacket::Type::CHARACTER_NEW:
|
case SerialPacket::Type::CHARACTER_NEW:
|
||||||
case SerialPacket::Type::CHARACTER_DELETE:
|
case SerialPacket::Type::CHARACTER_DELETE:
|
||||||
case SerialPacket::Type::CHARACTER_UPDATE:
|
case SerialPacket::Type::CHARACTER_UPDATE:
|
||||||
|
case SerialPacket::Type::CHARACTER_STATS_REQUEST:
|
||||||
|
case SerialPacket::Type::CHARACTER_STATS_RESPONSE:
|
||||||
deserializeCharacter(packet, reinterpret_cast<char*>(buffer));
|
deserializeCharacter(packet, reinterpret_cast<char*>(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
//enemy info
|
||||||
|
case SerialPacket::Type::ENEMY_NEW:
|
||||||
|
case SerialPacket::Type::ENEMY_DELETE:
|
||||||
|
case SerialPacket::Type::ENEMY_UPDATE:
|
||||||
|
case SerialPacket::Type::ENEMY_STATS_REQUEST:
|
||||||
|
case SerialPacket::Type::ENEMY_STATS_RESPONSE:
|
||||||
|
serializeEnemy(packet, reinterpret_cast<char*>(buffer));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,11 +28,11 @@
|
|||||||
* NOTE: REGION_CONTENT is currently the largest type of packet
|
* NOTE: REGION_CONTENT is currently the largest type of packet
|
||||||
* map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t)
|
* map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t)
|
||||||
* map format: sizeof(int) * 3
|
* map format: sizeof(int) * 3
|
||||||
* metadata: sizeof(metadata)
|
* metadata: sizeof(SerialPacket::Type)
|
||||||
*/
|
*/
|
||||||
#define PACKET_BUFFER_SIZE REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 3 + sizeof(SerialPacket::Metadata)
|
#define PACKET_BUFFER_SIZE REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 3 + sizeof(SerialPacket::Type)
|
||||||
|
|
||||||
void serialize(SerialPacket* const, void*);
|
void serialize(SerialPacket* const, void* dest);
|
||||||
void deserialize(SerialPacket* const, void*);
|
void deserialize(SerialPacket* const, void* src);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -24,53 +24,79 @@
|
|||||||
|
|
||||||
#include "vector2.hpp"
|
#include "vector2.hpp"
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
|
#include "statistics.hpp"
|
||||||
|
|
||||||
#include "SDL/SDL_net.h"
|
#include "SDL/SDL_net.h"
|
||||||
|
|
||||||
#define NETWORK_VERSION 20140512
|
#define NETWORK_VERSION 20140528
|
||||||
#define PACKET_STRING_SIZE 100
|
#define PACKET_STRING_SIZE 100
|
||||||
|
|
||||||
#pragma pack(push, 0)
|
|
||||||
|
|
||||||
union SerialPacket {
|
union SerialPacket {
|
||||||
//types of packets
|
//types of packets
|
||||||
enum class Type {
|
enum class Type {
|
||||||
//default: there is something wrong
|
//default: there is something wrong
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
|
|
||||||
//not used
|
//keep alive
|
||||||
PING = 1,
|
PING = 1,
|
||||||
PONG = 2,
|
PONG = 2,
|
||||||
|
|
||||||
//TODO: rejection message
|
//searching for a server to join
|
||||||
|
|
||||||
//Searching for a server to join
|
|
||||||
BROADCAST_REQUEST = 3,
|
BROADCAST_REQUEST = 3,
|
||||||
BROADCAST_RESPONSE = 4,
|
BROADCAST_RESPONSE = 4,
|
||||||
|
BROADCAST_REJECTION = 5,
|
||||||
|
|
||||||
//try to join the server
|
//try to join the server
|
||||||
JOIN_REQUEST = 5,
|
JOIN_REQUEST = 6,
|
||||||
JOIN_RESPONSE = 6,
|
JOIN_RESPONSE = 7,
|
||||||
|
JOIN_REJECTION = 8,
|
||||||
|
|
||||||
//mass update
|
//mass update
|
||||||
SYNCHRONIZE = 7,
|
SYNCHRONIZE = 9,
|
||||||
|
|
||||||
//disconnect from the server
|
//disconnect from the server
|
||||||
DISCONNECT = 8,
|
DISCONNECT = 10,
|
||||||
|
|
||||||
//shut down the server
|
//shut down the server
|
||||||
SHUTDOWN = 9,
|
SHUTDOWN = 11,
|
||||||
|
|
||||||
//map data
|
//map data
|
||||||
REGION_REQUEST = 10,
|
REGION_REQUEST = 12,
|
||||||
REGION_CONTENT = 11,
|
REGION_CONTENT = 13,
|
||||||
|
REGION_REJECTION = 14,
|
||||||
|
|
||||||
//Character movement, etc.
|
//combat data
|
||||||
CHARACTER_NEW = 12,
|
COMBAT_ENTER = 15,
|
||||||
CHARACTER_DELETE = 13,
|
COMBAT_EXIT = 16,
|
||||||
CHARACTER_UPDATE = 14,
|
|
||||||
|
|
||||||
//TODO: combat packets
|
COMBAT_UPDATE = 17,
|
||||||
|
|
||||||
|
COMBAT_REJECTION = 18,
|
||||||
|
|
||||||
|
//character data
|
||||||
|
CHARACTER_NEW = 19,
|
||||||
|
CHARACTER_DELETE = 20,
|
||||||
|
CHARACTER_UPDATE = 21,
|
||||||
|
|
||||||
|
CHARACTER_STATS_REQUEST = 22,
|
||||||
|
CHARACTER_STATS_RESPONSE = 23,
|
||||||
|
|
||||||
|
CHARACTER_REJECTION = 24,
|
||||||
|
|
||||||
|
//enemy data
|
||||||
|
ENEMY_NEW = 25,
|
||||||
|
ENEMY_DELETE = 26,
|
||||||
|
ENEMY_UPDATE = 27,
|
||||||
|
|
||||||
|
ENEMY_STATS_REQUEST = 28,
|
||||||
|
ENEMY_STATS_RESPONSE = 29,
|
||||||
|
|
||||||
|
ENEMY_REJECTION = 30,
|
||||||
|
|
||||||
|
//more packet types go here
|
||||||
|
|
||||||
|
//not used
|
||||||
|
LAST,
|
||||||
};
|
};
|
||||||
|
|
||||||
//metadata on the packet itself
|
//metadata on the packet itself
|
||||||
@@ -79,7 +105,7 @@ union SerialPacket {
|
|||||||
IPaddress srcAddress;
|
IPaddress srcAddress;
|
||||||
}meta;
|
}meta;
|
||||||
|
|
||||||
//information about the server
|
//info about the server
|
||||||
struct ServerInformation {
|
struct ServerInformation {
|
||||||
Metadata meta;
|
Metadata meta;
|
||||||
int networkVersion;
|
int networkVersion;
|
||||||
@@ -87,18 +113,19 @@ union SerialPacket {
|
|||||||
int playerCount;
|
int playerCount;
|
||||||
}serverInfo;
|
}serverInfo;
|
||||||
|
|
||||||
//information about the client
|
//info about the client
|
||||||
struct ClientInformation {
|
struct ClientInformation {
|
||||||
Metadata meta;
|
Metadata meta;
|
||||||
int clientIndex;
|
int clientIndex;
|
||||||
int accountIndex;
|
int accountIndex;
|
||||||
int characterIndex;
|
int characterIndex;
|
||||||
char username[PACKET_STRING_SIZE];
|
char username[PACKET_STRING_SIZE];
|
||||||
|
//TODO: password
|
||||||
char handle[PACKET_STRING_SIZE];
|
char handle[PACKET_STRING_SIZE];
|
||||||
char avatar[PACKET_STRING_SIZE];
|
char avatar[PACKET_STRING_SIZE];
|
||||||
}clientInfo;
|
}clientInfo;
|
||||||
|
|
||||||
//map data
|
//info about a region
|
||||||
struct RegionInformation {
|
struct RegionInformation {
|
||||||
Metadata meta;
|
Metadata meta;
|
||||||
int mapIndex;
|
int mapIndex;
|
||||||
@@ -106,7 +133,17 @@ union SerialPacket {
|
|||||||
Region* region;
|
Region* region;
|
||||||
}regionInfo;
|
}regionInfo;
|
||||||
|
|
||||||
//information about a character
|
//info about a combat scenario
|
||||||
|
struct CombatInformation {
|
||||||
|
Metadata meta;
|
||||||
|
int combatIndex;
|
||||||
|
int difficulty;
|
||||||
|
//TODO: background image, based on terrain type
|
||||||
|
//TODO: array of combatants
|
||||||
|
//TODO: rewards
|
||||||
|
}combatInfo;
|
||||||
|
|
||||||
|
//info about a character
|
||||||
struct CharacterInformation {
|
struct CharacterInformation {
|
||||||
Metadata meta;
|
Metadata meta;
|
||||||
int clientIndex;
|
int clientIndex;
|
||||||
@@ -117,8 +154,17 @@ union SerialPacket {
|
|||||||
int mapIndex;
|
int mapIndex;
|
||||||
Vector2 position;
|
Vector2 position;
|
||||||
Vector2 motion;
|
Vector2 motion;
|
||||||
|
Statistics stats;
|
||||||
}characterInfo;
|
}characterInfo;
|
||||||
|
|
||||||
|
//info about an enemy
|
||||||
|
struct EnemyInformation {
|
||||||
|
Metadata meta;
|
||||||
|
char handle[PACKET_STRING_SIZE];
|
||||||
|
char avatar[PACKET_STRING_SIZE];
|
||||||
|
Statistics stats;
|
||||||
|
}enemyInfo;
|
||||||
|
|
||||||
//defaults
|
//defaults
|
||||||
SerialPacket() {
|
SerialPacket() {
|
||||||
meta.type = Type::NONE;
|
meta.type = Type::NONE;
|
||||||
@@ -126,6 +172,4 @@ union SerialPacket {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -21,34 +21,33 @@
|
|||||||
*/
|
*/
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
|
#include "serial.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
void UDPNetworkUtility::Open(int port, int packSize) {
|
//DOCS: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network
|
||||||
if (!(socket = SDLNet_UDP_Open(port))) {
|
//NOTE: don't confuse SerialPacket with UDPpacket
|
||||||
Close();
|
|
||||||
throw(std::runtime_error("Failed to open a UDP socket"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(packOut = SDLNet_AllocPacket(packSize))) {
|
void UDPNetworkUtility::Open(int port) {
|
||||||
|
socket = SDLNet_UDP_Open(port);
|
||||||
|
packet = SDLNet_AllocPacket(PACKET_BUFFER_SIZE);
|
||||||
|
if (!socket || !packet) {
|
||||||
Close();
|
Close();
|
||||||
throw(std::runtime_error("Failed to allocate the out packet"));
|
throw(std::runtime_error("Failed to open UDPNetworkUtility"));
|
||||||
}
|
|
||||||
|
|
||||||
if (!(packIn = SDLNet_AllocPacket(packSize))) {
|
|
||||||
Close();
|
|
||||||
throw(std::runtime_error("Failed to allocate the in packet"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPNetworkUtility::Close() {
|
void UDPNetworkUtility::Close() {
|
||||||
SDLNet_UDP_Close(socket);
|
SDLNet_UDP_Close(socket);
|
||||||
SDLNet_FreePacket(packOut);
|
SDLNet_FreePacket(packet);
|
||||||
SDLNet_FreePacket(packIn);
|
|
||||||
socket = nullptr;
|
socket = nullptr;
|
||||||
packOut = nullptr;
|
packet = nullptr;
|
||||||
packIn = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//bind to a channel
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
int UDPNetworkUtility::Bind(const char* ip, int port, int channel) {
|
int UDPNetworkUtility::Bind(const char* ip, int port, int channel) {
|
||||||
IPaddress add;
|
IPaddress add;
|
||||||
if (SDLNet_ResolveHost(&add, ip, port) == -1) {
|
if (SDLNet_ResolveHost(&add, ip, port) == -1) {
|
||||||
@@ -61,7 +60,7 @@ int UDPNetworkUtility::Bind(const char* ip, int port, int channel) {
|
|||||||
int UDPNetworkUtility::Bind(IPaddress* add, int channel) {
|
int UDPNetworkUtility::Bind(IPaddress* add, int channel) {
|
||||||
int ret = SDLNet_UDP_Bind(socket, channel, add);
|
int ret = SDLNet_UDP_Bind(socket, channel, add);
|
||||||
|
|
||||||
if (ret == -1) {
|
if (ret < 0) {
|
||||||
throw(std::runtime_error("Failed to bind to a channel"));
|
throw(std::runtime_error("Failed to bind to a channel"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,25 +71,29 @@ void UDPNetworkUtility::Unbind(int channel) {
|
|||||||
SDLNet_UDP_Unbind(socket, channel);
|
SDLNet_UDP_Unbind(socket, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
int UDPNetworkUtility::Send(const char* ip, int port, void* data, int len) {
|
//-------------------------
|
||||||
|
//send a buffer
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendTo(const char* ip, int port, void* data, int len) {
|
||||||
IPaddress add;
|
IPaddress add;
|
||||||
if (SDLNet_ResolveHost(&add, ip, port) == -1) {
|
if (SDLNet_ResolveHost(&add, ip, port) == -1) {
|
||||||
throw(std::runtime_error("Failed to resolve a host"));
|
throw(std::runtime_error("Failed to resolve a host"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Send(&add, data, len);
|
SendTo(&add, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int UDPNetworkUtility::Send(IPaddress* add, void* data, int len) {
|
int UDPNetworkUtility::SendTo(IPaddress* add, void* data, int len) {
|
||||||
if (len > packOut->maxlen) {
|
if (len > packet->maxlen) {
|
||||||
throw(std::runtime_error("Failed to copy the data into the packet"));
|
throw(std::runtime_error("The buffer is to large for the UDPpacket"));
|
||||||
}
|
}
|
||||||
memset(packOut->data, 0, packOut->maxlen);
|
memset(packet->data, 0, packet->maxlen);
|
||||||
memcpy(packOut->data, data, len);
|
memcpy(packet->data, data, len);
|
||||||
packOut->len = len;
|
packet->len = len;
|
||||||
packOut->address = *add;
|
packet->address = *add;
|
||||||
|
|
||||||
int ret = SDLNet_UDP_Send(socket, -1, packOut);
|
int ret = SDLNet_UDP_Send(socket, -1, packet);
|
||||||
|
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
throw(std::runtime_error("Failed to send a packet"));
|
throw(std::runtime_error("Failed to send a packet"));
|
||||||
@@ -99,15 +102,15 @@ int UDPNetworkUtility::Send(IPaddress* add, void* data, int len) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UDPNetworkUtility::Send(int channel, void* data, int len) {
|
int UDPNetworkUtility::SendTo(int channel, void* data, int len) {
|
||||||
if (len > packOut->maxlen) {
|
if (len > packet->maxlen) {
|
||||||
throw(std::runtime_error("Failed to copy the data into the packet"));
|
throw(std::runtime_error("The buffer is to large for the UDPpacket"));
|
||||||
}
|
}
|
||||||
memset(packOut->data, 0, packOut->maxlen);
|
memset(packet->data, 0, packet->maxlen);
|
||||||
memcpy(packOut->data, data, len);
|
memcpy(packet->data, data, len);
|
||||||
packOut->len = len;
|
packet->len = len;
|
||||||
|
|
||||||
int ret = SDLNet_UDP_Send(socket, channel, packOut);
|
int ret = SDLNet_UDP_Send(socket, channel, packet);
|
||||||
|
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
throw(std::runtime_error("Failed to send a packet"));
|
throw(std::runtime_error("Failed to send a packet"));
|
||||||
@@ -116,29 +119,30 @@ int UDPNetworkUtility::Send(int channel, void* data, int len) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UDPNetworkUtility::SendAll(void* data, int len) {
|
int UDPNetworkUtility::SendToAllChannels(void* data, int len) {
|
||||||
if (len > packOut->maxlen) {
|
if (len > packet->maxlen) {
|
||||||
throw(std::runtime_error("Failed to copy the data into the packet"));
|
throw(std::runtime_error("The buffer is to large for the UDPpacket"));
|
||||||
}
|
}
|
||||||
memset(packOut->data, 0, packOut->maxlen);
|
memset(packet->data, 0, packet->maxlen);
|
||||||
memcpy(packOut->data, data, len);
|
memcpy(packet->data, data, len);
|
||||||
packOut->len = len;
|
packet->len = len;
|
||||||
|
|
||||||
int sent = 0;
|
int sent = 0;
|
||||||
|
|
||||||
//send to all bound channels
|
//send to all bound channels
|
||||||
for (int i = 0; i < SDLNET_MAX_UDPCHANNELS; i++) {
|
for (int i = 0; i < SDLNET_MAX_UDPCHANNELS; i++) {
|
||||||
if (SDLNet_UDP_GetPeerAddress(socket, i)) {
|
if (SDLNet_UDP_GetPeerAddress(socket, i)) {
|
||||||
sent += SDLNet_UDP_Send(socket, i, packOut);
|
sent += SDLNet_UDP_Send(socket, i, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sent;
|
return sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: put a void* and int* parameter list here
|
||||||
int UDPNetworkUtility::Receive() {
|
int UDPNetworkUtility::Receive() {
|
||||||
memset(packIn->data, 0, packIn->maxlen);
|
memset(packet->data, 0, packet->maxlen);
|
||||||
int ret = SDLNet_UDP_Recv(socket, packIn);
|
int ret = SDLNet_UDP_Recv(socket, packet);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
throw(std::runtime_error("Unknown network error occured"));
|
throw(std::runtime_error("Unknown network error occured"));
|
||||||
@@ -146,3 +150,75 @@ int UDPNetworkUtility::Receive() {
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//send a SerialPacket
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendTo(const char* ip, int port, SerialPacket* serialPacket) {
|
||||||
|
IPaddress add;
|
||||||
|
if (SDLNet_ResolveHost(&add, ip, port) == -1) {
|
||||||
|
throw(std::runtime_error("Failed to resolve a host"));
|
||||||
|
}
|
||||||
|
|
||||||
|
SendTo(&add, serialPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendTo(IPaddress* add, SerialPacket* serialPacket) {
|
||||||
|
memset(packet->data, 0, packet->maxlen);
|
||||||
|
serialize(serialPacket, packet->data);
|
||||||
|
packet->len = PACKET_BUFFER_SIZE;
|
||||||
|
packet->address = *add;
|
||||||
|
|
||||||
|
int ret = SDLNet_UDP_Send(socket, -1, packet);
|
||||||
|
|
||||||
|
if (ret <= 0) {
|
||||||
|
throw(std::runtime_error("Failed to send a packet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendTo(int channel, SerialPacket* serialPacket) {
|
||||||
|
memset(packet->data, 0, packet->maxlen);
|
||||||
|
serialize(serialPacket, packet->data);
|
||||||
|
packet->len = PACKET_BUFFER_SIZE;
|
||||||
|
|
||||||
|
int ret = SDLNet_UDP_Send(socket, channel, packet);
|
||||||
|
|
||||||
|
if (ret <= 0) {
|
||||||
|
throw(std::runtime_error("Failed to send a packet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::SendToAllChannels(SerialPacket* serialPacket) {
|
||||||
|
memset(packet->data, 0, packet->maxlen);
|
||||||
|
serialize(serialPacket, packet->data);
|
||||||
|
packet->len = PACKET_BUFFER_SIZE;
|
||||||
|
|
||||||
|
int sent = 0;
|
||||||
|
|
||||||
|
//send to all bound channels
|
||||||
|
for (int i = 0; i < SDLNET_MAX_UDPCHANNELS; i++) {
|
||||||
|
if (SDLNet_UDP_GetPeerAddress(socket, i)) {
|
||||||
|
sent += SDLNet_UDP_Send(socket, i, packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sent;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPNetworkUtility::Receive(SerialPacket* serialPacket) {
|
||||||
|
memset(packet->data, 0, packet->maxlen);
|
||||||
|
int ret = SDLNet_UDP_Recv(socket, packet);
|
||||||
|
deserialize(serialPacket, packet->data);
|
||||||
|
serialPacket->meta.srcAddress = packet->address;
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
throw(std::runtime_error("Unknown network error occured"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -24,12 +24,14 @@
|
|||||||
|
|
||||||
#include "SDL/SDL_net.h"
|
#include "SDL/SDL_net.h"
|
||||||
|
|
||||||
|
#include "serial_packet.hpp"
|
||||||
|
|
||||||
class UDPNetworkUtility {
|
class UDPNetworkUtility {
|
||||||
public:
|
public:
|
||||||
UDPNetworkUtility() = default;
|
UDPNetworkUtility() = default;
|
||||||
~UDPNetworkUtility() = default;
|
~UDPNetworkUtility() = default;
|
||||||
|
|
||||||
void Open(int port, int packSize);
|
void Open(int port);
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
//bind to a channel
|
//bind to a channel
|
||||||
@@ -41,31 +43,30 @@ public:
|
|||||||
return SDLNet_UDP_GetPeerAddress(socket, channel);
|
return SDLNet_UDP_GetPeerAddress(socket, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Send(const char* ip, int port, void* data, int len);
|
//send a buffer
|
||||||
int Send(IPaddress* add, void* data, int len);
|
int SendTo(const char* ip, int port, void* data, int len);
|
||||||
int Send(int channel, void* data, int len);
|
int SendTo(IPaddress* add, void* data, int len);
|
||||||
int SendAll(void* data, int len);
|
int SendTo(int channel, void* data, int len);
|
||||||
|
int SendToAllChannels(void* data, int len);
|
||||||
int Receive();
|
int Receive();
|
||||||
|
|
||||||
void* GetOutData() const {
|
//send a SerialPacket
|
||||||
return reinterpret_cast<void*>(packOut->data);
|
int SendTo(const char* ip, int port, SerialPacket* serialPacket);
|
||||||
};
|
int SendTo(IPaddress* add, SerialPacket* serialPacket);
|
||||||
void* GetInData() const {
|
int SendTo(int channel, SerialPacket* serialPacket);
|
||||||
return reinterpret_cast<void*>(packIn->data);
|
int SendToAllChannels(SerialPacket* serialPacket);
|
||||||
};
|
int Receive(SerialPacket* serialPacket);
|
||||||
UDPpacket* GetOutPacket() const {
|
|
||||||
return packOut;
|
//accessors
|
||||||
}
|
UDPpacket* GetPacket() const {
|
||||||
UDPpacket* GetInPacket() const {
|
return packet;
|
||||||
return packIn;
|
|
||||||
}
|
}
|
||||||
UDPsocket GetSocket() const {
|
UDPsocket GetSocket() const {
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
UDPsocket socket = nullptr;
|
UDPsocket socket = nullptr;
|
||||||
UDPpacket* packOut = nullptr;
|
UDPpacket* packet = nullptr;
|
||||||
UDPpacket* packIn = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../map
|
INCLUDES+=. ../map ../utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
#source
|
||||||
CXXSRC=$(wildcard *.cpp)
|
CXXSRC=$(wildcard *.cpp)
|
||||||
CSRC=$(wildcard *.c)
|
|
||||||
|
|
||||||
#objects
|
#objects
|
||||||
OBJDIR=obj
|
OBJDIR=obj
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o))
|
|
||||||
|
|
||||||
#output
|
#output
|
||||||
OUTDIR=../..
|
OUTDIR=../..
|
||||||
@@ -34,9 +31,6 @@ $(OUTDIR):
|
|||||||
$(OBJDIR)/%.o: %.cpp
|
$(OBJDIR)/%.o: %.cpp
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.c
|
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o *.a *.exe
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
+2
-8
@@ -1,17 +1,14 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../graphics
|
INCLUDES+=. ../graphics
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
#source
|
||||||
CXXSRC=$(wildcard *.cpp)
|
CXXSRC=$(wildcard *.cpp)
|
||||||
CSRC=$(wildcard *.c)
|
|
||||||
|
|
||||||
#objects
|
#objects
|
||||||
OBJDIR=obj
|
OBJDIR=obj
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o))
|
|
||||||
|
|
||||||
#output
|
#output
|
||||||
OUTDIR=../..
|
OUTDIR=../..
|
||||||
@@ -34,9 +31,6 @@ $(OUTDIR):
|
|||||||
$(OBJDIR)/%.o: %.cpp
|
$(OBJDIR)/%.o: %.cpp
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.c
|
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o *.a *.exe
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -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)/,libcommon.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
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
#TODO: The build process needs revising
|
|
||||||
#for use on Windows:
|
#for use on Windows:
|
||||||
|
|
||||||
#MKDIR=mkdir
|
#MKDIR=mkdir
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
print("Lua script check OK (./rsc)")
|
print("Lua script check (./rsc)")
|
||||||
|
|
||||||
|
-------------------------
|
||||||
|
--Map API overrides
|
||||||
|
-------------------------
|
||||||
|
|
||||||
function map.create(region)
|
function map.create(region)
|
||||||
for i = 1, map.getregionwidth() do
|
for i = 1, map.getregionwidth() do
|
||||||
@@ -16,12 +20,17 @@ function map.unload(region)
|
|||||||
--
|
--
|
||||||
end
|
end
|
||||||
|
|
||||||
--return true if file loaded, otherwise return false
|
|
||||||
function map.load(region, dir)
|
function map.load(region, dir)
|
||||||
--
|
--return true if file loaded, otherwise return false
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function map.save(region, dir)
|
function map.save(region, dir)
|
||||||
--
|
--
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-------------------------
|
||||||
|
--Enemy API
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
--TODO
|
||||||
@@ -1,56 +1,18 @@
|
|||||||
-------------------------
|
CREATE TABLE IF NOT EXISTS Accounts (
|
||||||
--Server
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS UserAccounts (
|
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
username varchar(100) UNIQUE,
|
username varchar(100) UNIQUE,
|
||||||
--TODO: server-client security
|
--TODO: server-client security
|
||||||
-- password varchar(100),
|
-- password varchar(100),
|
||||||
blacklisted BIT DEFAULT 0,
|
blacklisted BIT DEFAULT 0,
|
||||||
whitelisted BIT DEFAULT 1
|
whitelisted BIT DEFAULT 1,
|
||||||
-- TODO: moderator
|
administrator BIT DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
||||||
-------------------------
|
CREATE TABLE IF NOT EXISTS Characters (
|
||||||
--Items
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS MundaneItems (
|
|
||||||
--metadata
|
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
itemID INTEGER,
|
|
||||||
stackSize INTEGER DEFAULT 0,
|
|
||||||
owner INTEGER REFERENCES PlayerCharacters(uid)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS Consumables (
|
|
||||||
--metadata
|
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
itemID INTEGER,
|
|
||||||
stackSize INTEGER DEFAULT 0,
|
|
||||||
owner INTEGER REFERENCES PlayerCharacters(uid)
|
|
||||||
--holds all consumable items info (food, potions, etc.)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS Equipment (
|
|
||||||
--metadata
|
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
itemID INTEGER,
|
|
||||||
owner INTEGER REFERENCES PlayerCharacters(uid)
|
|
||||||
--hold all equipment info
|
|
||||||
--stat mods, special effects, etc.
|
|
||||||
);
|
|
||||||
|
|
||||||
-------------------------
|
|
||||||
--Players
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS PlayerCharacters (
|
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
||||||
--metadata
|
--metadata
|
||||||
owner INTEGER REFERENCES UserAccounts(uid),
|
owner INTEGER REFERENCES Accounts(uid),
|
||||||
handle varchar(100) UNIQUE,
|
handle varchar(100) UNIQUE,
|
||||||
avatar varchar(100),
|
avatar varchar(100),
|
||||||
birth timestamp NOT NULL DEFAULT (datetime()),
|
birth timestamp NOT NULL DEFAULT (datetime()),
|
||||||
@@ -71,13 +33,31 @@ CREATE TABLE IF NOT EXISTS PlayerCharacters (
|
|||||||
defence INTEGER DEFAULT 0,
|
defence INTEGER DEFAULT 0,
|
||||||
intelligence INTEGER DEFAULT 0,
|
intelligence INTEGER DEFAULT 0,
|
||||||
resistance INTEGER DEFAULT 0,
|
resistance INTEGER DEFAULT 0,
|
||||||
|
speed INTEGER DEFAULT 0,
|
||||||
accuracy REAL DEFAULT 0.0,
|
accuracy REAL DEFAULT 0.0,
|
||||||
evasion REAL DEFAULT 0.0,
|
evasion REAL DEFAULT 0.0,
|
||||||
luck REAL DEFAULT 0.0,
|
luck REAL DEFAULT 0.0,
|
||||||
|
|
||||||
--equipment
|
--equipment
|
||||||
weapon INTEGER REFERENCES Equipment(uid),
|
weapon INTEGER REFERENCES WornEquipment(uid),
|
||||||
helmet INTEGER REFERENCES Equipment(uid),
|
helmet INTEGER REFERENCES WornEquipment(uid),
|
||||||
armour INTEGER REFERENCES Equipment(uid)
|
armour INTEGER REFERENCES WornEquipment(uid)
|
||||||
--etc.
|
--etc.
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS InventoryItems (
|
||||||
|
--metadata
|
||||||
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
itemID INTEGER, --type
|
||||||
|
stackSize INTEGER DEFAULT 0,
|
||||||
|
owner INTEGER REFERENCES Characters(uid)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS WornEquipment (
|
||||||
|
--metadata
|
||||||
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
itemID INTEGER, --type
|
||||||
|
owner INTEGER REFERENCES Characters(uid)
|
||||||
|
--hold all equipment info
|
||||||
|
--stat mods, special effects, etc.
|
||||||
|
);
|
||||||
@@ -29,10 +29,10 @@
|
|||||||
//Define the queries
|
//Define the queries
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
static const char* CREATE_USER_ACCOUNT = "INSERT INTO UserAccounts (username) VALUES (?);";
|
static const char* CREATE_USER_ACCOUNT = "INSERT INTO Accounts (username) VALUES (?);";
|
||||||
static const char* LOAD_USER_ACCOUNT = "SELECT * FROM UserAccounts WHERE username = ?;";
|
static const char* LOAD_USER_ACCOUNT = "SELECT * FROM Accounts WHERE username = ?;";
|
||||||
static const char* SAVE_USER_ACCOUNT = "UPDATE OR FAIL UserAccounts SET blacklisted = ?2, whitelisted = ?3 WHERE uid = ?1;";
|
static const char* SAVE_USER_ACCOUNT = "UPDATE OR FAIL Accounts SET blacklisted = ?2, whitelisted = ?3 WHERE uid = ?1;";
|
||||||
static const char* DELETE_USER_ACCOUNT = "DELETE FROM UserAccounts WHERE uid = ?;";
|
static const char* DELETE_USER_ACCOUNT = "DELETE FROM Accounts WHERE uid = ?;";
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Define the methods
|
//Define the methods
|
||||||
|
|||||||
@@ -29,15 +29,17 @@
|
|||||||
//Define the queries
|
//Define the queries
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
static const char* CREATE_CHARACTER = "INSERT INTO PlayerCharacters (owner, handle, avatar) VALUES (?, ?, ?);";
|
//TODO: save and load the statistics
|
||||||
static const char* LOAD_CHARACTER = "SELECT * FROM PlayerCharacters WHERE handle = ?;";
|
static const char* CREATE_CHARACTER = "INSERT INTO Characters (owner, handle, avatar) VALUES (?, ?, ?);";
|
||||||
static const char* SAVE_CHARACTER = "UPDATE OR FAIL PlayerCharacters SET mapIndex = ?2, positionX = ?3, positionY = ?4 WHERE uid = ?1;";
|
static const char* LOAD_CHARACTER = "SELECT * FROM Characters WHERE handle = ?;";
|
||||||
static const char* DELETE_CHARACTER = "DELETE FROM PlayerCharacters WHERE uid = ?;";
|
static const char* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET mapIndex = ?2, positionX = ?3, positionY = ?4 WHERE uid = ?1;";
|
||||||
|
static const char* DELETE_CHARACTER = "DELETE FROM Characters WHERE uid = ?;";
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Define the methods
|
//Define the methods
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
//TODO: default stats as a parameter
|
||||||
int ServerApplication::CreateCharacter(int owner, std::string handle, std::string avatar) {
|
int ServerApplication::CreateCharacter(int owner, std::string handle, std::string avatar) {
|
||||||
//Create the character, failing if it exists
|
//Create the character, failing if it exists
|
||||||
sqlite3_stmt* statement = nullptr;
|
sqlite3_stmt* statement = nullptr;
|
||||||
@@ -121,19 +123,20 @@ int ServerApplication::LoadCharacter(int owner, std::string handle, std::string
|
|||||||
newChar.position.y = (double)sqlite3_column_int(statement, 7);
|
newChar.position.y = (double)sqlite3_column_int(statement, 7);
|
||||||
|
|
||||||
//statistics
|
//statistics
|
||||||
newChar.level = sqlite3_column_int(statement, 8);
|
newChar.stats.level = sqlite3_column_int(statement, 8);
|
||||||
newChar.exp = sqlite3_column_int(statement, 9);
|
newChar.stats.exp = sqlite3_column_int(statement, 9);
|
||||||
newChar.maxHP = sqlite3_column_int(statement, 10);
|
newChar.stats.maxHP = sqlite3_column_int(statement, 10);
|
||||||
newChar.health = sqlite3_column_int(statement, 11);
|
newChar.stats.health = sqlite3_column_int(statement, 11);
|
||||||
newChar.maxMP = sqlite3_column_int(statement, 12);
|
newChar.stats.maxMP = sqlite3_column_int(statement, 12);
|
||||||
newChar.mana = sqlite3_column_int(statement, 13);
|
newChar.stats.mana = sqlite3_column_int(statement, 13);
|
||||||
newChar.attack = sqlite3_column_int(statement, 14);
|
newChar.stats.attack = sqlite3_column_int(statement, 14);
|
||||||
newChar.defence = sqlite3_column_int(statement, 15);
|
newChar.stats.defence = sqlite3_column_int(statement, 15);
|
||||||
newChar.intelligence = sqlite3_column_int(statement, 16);
|
newChar.stats.intelligence = sqlite3_column_int(statement, 16);
|
||||||
newChar.resistance = sqlite3_column_int(statement, 17);
|
newChar.stats.resistance = sqlite3_column_int(statement, 17);
|
||||||
newChar.accuracy = sqlite3_column_double(statement, 18);
|
newChar.stats.speed = sqlite3_column_int(statement, 18);
|
||||||
newChar.evasion = sqlite3_column_double(statement, 19);
|
newChar.stats.accuracy = sqlite3_column_double(statement, 19);
|
||||||
newChar.luck = sqlite3_column_double(statement, 20);
|
newChar.stats.evasion = sqlite3_column_double(statement, 20);
|
||||||
|
newChar.stats.luck = sqlite3_column_double(statement, 21);
|
||||||
|
|
||||||
//TODO: equipment
|
//TODO: equipment
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
||||||
|
*/
|
||||||
|
#include "enemy_factory_generic.hpp"
|
||||||
|
|
||||||
|
EnemyFactoryGeneric::EnemyFactoryGeneric() : EnemyFactoryInterface() {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
EnemyFactoryGeneric::~EnemyFactoryGeneric() noexcept {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnemyFactoryGeneric::Generate(std::list<EnemyData>* container) {
|
||||||
|
//TODO: fill this out
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -19,30 +19,24 @@
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
#ifndef INCOMBAT_HPP_
|
#ifndef ENEMYFACTORYGENERIC_HPP_
|
||||||
#define INCOMBAT_HPP_
|
#define ENEMYFACTORYGENERIC_HPP_
|
||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "enemy_factory_interface.hpp"
|
||||||
|
|
||||||
class InCombat : public BaseScene {
|
#include "enemy_data.hpp"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
//DOCS: Not really intended for use, but rather for copying and tweaking
|
||||||
|
class EnemyFactoryGeneric : public EnemyFactoryInterface {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
EnemyFactoryGeneric();
|
||||||
InCombat();
|
~EnemyFactoryGeneric() noexcept override;
|
||||||
~InCombat();
|
|
||||||
|
|
||||||
protected:
|
void Generate(std::list<EnemyData>* container) override;
|
||||||
//Frame loop
|
private:
|
||||||
void FrameStart();
|
//TODO: hold the parameters specified by the room
|
||||||
void Update(double delta);
|
|
||||||
void FrameEnd();
|
|
||||||
void Render(SDL_Surface* const);
|
|
||||||
|
|
||||||
//Event handlers
|
|
||||||
void MouseMotion(SDL_MouseMotionEvent const&);
|
|
||||||
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
|
||||||
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
|
||||||
void KeyDown(SDL_KeyboardEvent const&);
|
|
||||||
void KeyUp(SDL_KeyboardEvent const&);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/* 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 ENEMYFACTORYINTERFACE_HPP_
|
||||||
|
#define ENEMYFACTORYINTERFACE_HPP_
|
||||||
|
|
||||||
|
#include "enemy_data.hpp"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
//TODO: move this elsewhere
|
||||||
|
enum RoomType {
|
||||||
|
OVERWORLD,
|
||||||
|
RUINS,
|
||||||
|
TOWERS,
|
||||||
|
FORESTS,
|
||||||
|
CAVES,
|
||||||
|
};
|
||||||
|
|
||||||
|
//NOTE: Based on biome, world difficulty, etc.
|
||||||
|
class EnemyFactoryInterface {
|
||||||
|
public:
|
||||||
|
EnemyFactoryInterface() = default;
|
||||||
|
virtual ~EnemyFactoryInterface() = default;
|
||||||
|
|
||||||
|
virtual void Generate(std::list<EnemyData>* container) = 0;
|
||||||
|
|
||||||
|
//control the difficulty of the room
|
||||||
|
RoomType SetType(RoomType t) { return type = t; }
|
||||||
|
int SetDifficulty(int d) { return difficulty = d; }
|
||||||
|
RoomType GetType() { return type; }
|
||||||
|
int GetDifficulty() { return difficulty; }
|
||||||
|
protected:
|
||||||
|
RoomType type;
|
||||||
|
int difficulty;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
+2
-8
@@ -1,17 +1,14 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../common ../common/map ../common/script ../common/network
|
INCLUDES+=. ../common/gameplay ../common/map ../common/network ../common/script ../common/utilities
|
||||||
LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
#source
|
||||||
CXXSRC=$(wildcard *.cpp)
|
CXXSRC=$(wildcard *.cpp)
|
||||||
CSRC=$(wildcard *.c)
|
|
||||||
|
|
||||||
#objects
|
#objects
|
||||||
OBJDIR=obj
|
OBJDIR=obj
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o))
|
|
||||||
|
|
||||||
#output
|
#output
|
||||||
OUTDIR=../out
|
OUTDIR=../out
|
||||||
@@ -34,9 +31,6 @@ $(OUTDIR):
|
|||||||
$(OBJDIR)/%.o: %.cpp
|
$(OBJDIR)/%.o: %.cpp
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.c
|
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o *.a *.exe
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
#include "client_data.hpp"
|
#include "client_data.hpp"
|
||||||
#include "account_data.hpp"
|
#include "account_data.hpp"
|
||||||
#include "character_data.hpp"
|
#include "character_data.hpp"
|
||||||
|
#include "combat_data.hpp"
|
||||||
|
#include "enemy_factory_generic.hpp"
|
||||||
|
|
||||||
//maps
|
//maps
|
||||||
#include "map_allocator.hpp"
|
#include "map_allocator.hpp"
|
||||||
@@ -33,9 +35,7 @@
|
|||||||
#include "region_pager.hpp"
|
#include "region_pager.hpp"
|
||||||
|
|
||||||
//networking
|
//networking
|
||||||
#include "serial_packet.hpp"
|
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
#include "serial.hpp"
|
|
||||||
|
|
||||||
//common
|
//common
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
@@ -51,6 +51,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//The main application class
|
//The main application class
|
||||||
|
//TODO: modulate this god class
|
||||||
class ServerApplication {
|
class ServerApplication {
|
||||||
public:
|
public:
|
||||||
//standard functions
|
//standard functions
|
||||||
@@ -84,14 +85,14 @@ private:
|
|||||||
void UnloadUserAccount(int uid);
|
void UnloadUserAccount(int uid);
|
||||||
void DeleteUserAccount(int uid);
|
void DeleteUserAccount(int uid);
|
||||||
|
|
||||||
//TODO: character management
|
//character management
|
||||||
int CreateCharacter(int owner, std::string handle, std::string avatar);
|
int CreateCharacter(int owner, std::string handle, std::string avatar);
|
||||||
int LoadCharacter(int owner, std::string handle, std::string avatar);
|
int LoadCharacter(int owner, std::string handle, std::string avatar);
|
||||||
int SaveCharacter(int uid);
|
int SaveCharacter(int uid);
|
||||||
void UnloadCharacter(int uid);
|
void UnloadCharacter(int uid);
|
||||||
void DeleteCharacter(int uid);
|
void DeleteCharacter(int uid);
|
||||||
|
|
||||||
//TODO: combat systems
|
//TODO: combat management
|
||||||
|
|
||||||
//APIs
|
//APIs
|
||||||
UDPNetworkUtility network;
|
UDPNetworkUtility network;
|
||||||
@@ -102,15 +103,21 @@ private:
|
|||||||
std::map<int, ClientData> clientMap;
|
std::map<int, ClientData> clientMap;
|
||||||
std::map<int, AccountData> accountMap;
|
std::map<int, AccountData> accountMap;
|
||||||
std::map<int, CharacterData> characterMap;
|
std::map<int, CharacterData> characterMap;
|
||||||
|
std::map<int, CombatData> combatMap;
|
||||||
|
std::map<int, EnemyData> enemyMap;
|
||||||
|
|
||||||
//maps
|
//maps
|
||||||
//TODO: I need to handle multiple map objects
|
//TODO: I need to handle multiple map objects
|
||||||
//TODO: Unload regions that are distant from any characters
|
//TODO: Unload regions that are distant from any characters
|
||||||
RegionPager<LuaAllocator, LuaFormat> regionPager;
|
RegionPager<LuaAllocator, LuaFormat> regionPager;
|
||||||
|
EnemyFactoryGeneric enemyFactory;
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
bool running = true;
|
bool running = true;
|
||||||
ConfigUtility config;
|
ConfigUtility config;
|
||||||
|
int clientUID = 0;
|
||||||
|
int combatUID = 0;
|
||||||
|
int enemyUID = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -36,9 +36,7 @@ void ServerApplication::HandleBroadcastRequest(SerialPacket packet) {
|
|||||||
packet.serverInfo.playerCount = characterMap.size();
|
packet.serverInfo.playerCount = characterMap.size();
|
||||||
|
|
||||||
//bounce this packet
|
//bounce this packet
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
network.SendTo(&packet.meta.srcAddress, &packet);
|
||||||
serialize(&packet, buffer);
|
|
||||||
network.Send(&packet.meta.srcAddress, buffer, PACKET_BUFFER_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::HandleJoinRequest(SerialPacket packet) {
|
void ServerApplication::HandleJoinRequest(SerialPacket packet) {
|
||||||
@@ -47,7 +45,7 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) {
|
|||||||
newClient.address = packet.meta.srcAddress;
|
newClient.address = packet.meta.srcAddress;
|
||||||
|
|
||||||
//load the user account
|
//load the user account
|
||||||
int accountIndex = LoadUserAccount(packet.clientInfo.username, ClientData::uidCounter);
|
int accountIndex = LoadUserAccount(packet.clientInfo.username, clientUID);
|
||||||
if (accountIndex < 0) {
|
if (accountIndex < 0) {
|
||||||
//TODO: send rejection packet
|
//TODO: send rejection packet
|
||||||
std::cerr << "Error: Account already loaded: " << accountIndex << std::endl;
|
std::cerr << "Error: Account already loaded: " << accountIndex << std::endl;
|
||||||
@@ -65,14 +63,12 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) {
|
|||||||
|
|
||||||
//send the client their info
|
//send the client their info
|
||||||
packet.meta.type = SerialPacket::Type::JOIN_RESPONSE;
|
packet.meta.type = SerialPacket::Type::JOIN_RESPONSE;
|
||||||
packet.clientInfo.clientIndex = ClientData::uidCounter;
|
packet.clientInfo.clientIndex = clientUID;
|
||||||
packet.clientInfo.accountIndex = accountIndex;
|
packet.clientInfo.accountIndex = accountIndex;
|
||||||
packet.clientInfo.characterIndex = characterIndex;
|
packet.clientInfo.characterIndex = characterIndex;
|
||||||
|
|
||||||
//bounce this packet
|
//bounce this packet
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
network.SendTo(&newClient.address, &packet);
|
||||||
serialize(&packet, buffer);
|
|
||||||
network.Send(&newClient.address, buffer, PACKET_BUFFER_SIZE);
|
|
||||||
|
|
||||||
//send the new character to all clients
|
//send the new character to all clients
|
||||||
packet.meta.type = SerialPacket::Type::CHARACTER_NEW;
|
packet.meta.type = SerialPacket::Type::CHARACTER_NEW;
|
||||||
@@ -85,7 +81,7 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) {
|
|||||||
|
|
||||||
//TODO: don't send anything to a certain client until they send the OK (the sync packet? or ignore client side?)
|
//TODO: don't send anything to a certain client until they send the OK (the sync packet? or ignore client side?)
|
||||||
//finished this routine
|
//finished this routine
|
||||||
clientMap[ClientData::uidCounter++] = newClient;
|
clientMap[clientUID++] = newClient;
|
||||||
std::cout << "Connect, total: " << clientMap.size() << std::endl;
|
std::cout << "Connect, total: " << clientMap.size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +90,6 @@ void ServerApplication::HandleSynchronize(SerialPacket packet) {
|
|||||||
|
|
||||||
//send all the server's data to this client
|
//send all the server's data to this client
|
||||||
SerialPacket newPacket;
|
SerialPacket newPacket;
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
|
||||||
|
|
||||||
//characters
|
//characters
|
||||||
newPacket.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
|
newPacket.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
|
||||||
@@ -106,8 +101,9 @@ void ServerApplication::HandleSynchronize(SerialPacket packet) {
|
|||||||
newPacket.characterInfo.mapIndex = it.second.mapIndex;
|
newPacket.characterInfo.mapIndex = it.second.mapIndex;
|
||||||
newPacket.characterInfo.position = it.second.position;
|
newPacket.characterInfo.position = it.second.position;
|
||||||
newPacket.characterInfo.motion = it.second.motion;
|
newPacket.characterInfo.motion = it.second.motion;
|
||||||
serialize(&newPacket, buffer);
|
newPacket.characterInfo.stats = it.second.stats;
|
||||||
network.Send(&clientMap[packet.clientInfo.clientIndex].address, buffer, PACKET_BUFFER_SIZE);
|
|
||||||
|
network.SendTo(&clientMap[packet.clientInfo.clientIndex].address, &newPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,9 +111,7 @@ void ServerApplication::HandleDisconnect(SerialPacket packet) {
|
|||||||
//TODO: authenticate who is disconnecting/kicking
|
//TODO: authenticate who is disconnecting/kicking
|
||||||
|
|
||||||
//forward to the specified client
|
//forward to the specified client
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
network.SendTo(&clientMap[accountMap[packet.clientInfo.accountIndex].clientIndex].address, &packet);
|
||||||
serialize(&packet, buffer);
|
|
||||||
network.Send(&clientMap[accountMap[packet.clientInfo.accountIndex].clientIndex].address, buffer, PACKET_BUFFER_SIZE);
|
|
||||||
|
|
||||||
//unload client and server-side characters
|
//unload client and server-side characters
|
||||||
for (std::map<int, CharacterData>::iterator it = characterMap.begin(); it != characterMap.end(); /* EMPTY */ ) {
|
for (std::map<int, CharacterData>::iterator it = characterMap.begin(); it != characterMap.end(); /* EMPTY */ ) {
|
||||||
@@ -173,17 +167,13 @@ void ServerApplication::HandleRegionRequest(SerialPacket packet) {
|
|||||||
packet.regionInfo.region = regionPager.GetRegion(packet.regionInfo.x, packet.regionInfo.y);
|
packet.regionInfo.region = regionPager.GetRegion(packet.regionInfo.x, packet.regionInfo.y);
|
||||||
|
|
||||||
//send the content
|
//send the content
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
network.SendTo(&packet.meta.srcAddress, &packet);
|
||||||
serialize(&packet, buffer);
|
|
||||||
network.Send(&packet.meta.srcAddress, buffer, PACKET_BUFFER_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::PumpPacket(SerialPacket packet) {
|
void ServerApplication::PumpPacket(SerialPacket packet) {
|
||||||
//NOTE: I don't really like this, but it'll do for now
|
//NOTE: I don't really like this, but it'll do for now
|
||||||
char buffer[PACKET_BUFFER_SIZE];
|
|
||||||
serialize(&packet, buffer);
|
|
||||||
for (auto& it : clientMap) {
|
for (auto& it : clientMap) {
|
||||||
network.Send(&it.second.address, buffer, PACKET_BUFFER_SIZE);
|
network.SendTo(&it.second.address, &packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,17 +22,12 @@
|
|||||||
#include "server_application.hpp"
|
#include "server_application.hpp"
|
||||||
|
|
||||||
#include "sql_utility.hpp"
|
#include "sql_utility.hpp"
|
||||||
|
#include "serial.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//Define the various UIDs
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
int ClientData::uidCounter = 0;
|
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Define the public members
|
//Define the public members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -58,7 +53,7 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
if (SDLNet_Init()) {
|
if (SDLNet_Init()) {
|
||||||
throw(std::runtime_error("Failed to initialize SDL_net"));
|
throw(std::runtime_error("Failed to initialize SDL_net"));
|
||||||
}
|
}
|
||||||
network.Open(config.Int("server.port"), PACKET_BUFFER_SIZE);
|
network.Open(config.Int("server.port"));
|
||||||
std::cout << "Initialized SDL_net" << std::endl;
|
std::cout << "Initialized SDL_net" << std::endl;
|
||||||
|
|
||||||
//Init SQL
|
//Init SQL
|
||||||
@@ -125,12 +120,7 @@ void ServerApplication::Proc() {
|
|||||||
SerialPacket packet;
|
SerialPacket packet;
|
||||||
while(running) {
|
while(running) {
|
||||||
//suck in the waiting packets & process them
|
//suck in the waiting packets & process them
|
||||||
while(network.Receive()) {
|
while(network.Receive(&packet)) {
|
||||||
//get the packet
|
|
||||||
deserialize(&packet, network.GetInData());
|
|
||||||
//cache the source address
|
|
||||||
packet.meta.srcAddress = network.GetInPacket()->address;
|
|
||||||
//we need to go deeper
|
|
||||||
HandlePacket(packet);
|
HandlePacket(packet);
|
||||||
}
|
}
|
||||||
//update the internals
|
//update the internals
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
* I need to keep the documentation up to date. Namely, the GDD is getting out of date.
|
|
||||||
* How many lookups is the map system using?
|
|
||||||
* Add the serial packet to the network utility
|
|
||||||
|
|
||||||
--Naming conventions--
|
|
||||||
|
|
||||||
I need to define the differences between several different terms i.e. naming conventions.
|
|
||||||
I may also need to rewrite some variable names.
|
|
||||||
|
|
||||||
* User: This is the individual who is playing the game
|
|
||||||
* Player: A synonym for a user
|
|
||||||
* Character: This is the actual player character in the game
|
|
||||||
* Username: This is the name of the player; ususally kept private
|
|
||||||
* Handle: This is the name of a character
|
|
||||||
* Avatar: This is the name of the sprite used by a character
|
|
||||||
|
|
||||||
--ServerApplication's methods--
|
|
||||||
|
|
||||||
These interact with the database file, making the server a persistent system.
|
|
||||||
|
|
||||||
* CreateUserAccount
|
|
||||||
* LoadUserAccount
|
|
||||||
* SaveUserAccount
|
|
||||||
* UnloadUserAccount
|
|
||||||
* DeleteUserAccount
|
|
||||||
|
|
||||||
* CreateCharacter
|
|
||||||
* LoadCharacter
|
|
||||||
* SaveCharacter
|
|
||||||
* UnloadCharacter
|
|
||||||
* DeleteCharacter
|
|
||||||
|
|
||||||
--Battle System--
|
|
||||||
|
|
||||||
CombatPortal:
|
|
||||||
x, y
|
|
||||||
list<Character>
|
|
||||||
list<Monster>
|
|
||||||
//...
|
|
||||||
Reference in New Issue
Block a user