Merge branch 'monsters' into develop
Conflicts: client/scenes/in_world.cpp
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
||||
*
|
||||
* 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 "monster_packet.hpp"
|
||||
|
||||
#include "serial_utility.hpp"
|
||||
|
||||
void serializeMonster(void* buffer, MonsterPacket* packet) {
|
||||
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||
|
||||
//identify the monster
|
||||
serialCopy(&buffer, &packet->monsterIndex, sizeof(int));
|
||||
serialCopy(&buffer, packet->handle, PACKET_STRING_SIZE);
|
||||
serialCopy(&buffer, packet->avatar, PACKET_STRING_SIZE);
|
||||
|
||||
//bounds
|
||||
serialCopy(&buffer, &packet->bounds.x, sizeof(int));
|
||||
serialCopy(&buffer, &packet->bounds.y, sizeof(int));
|
||||
serialCopy(&buffer, &packet->bounds.w, sizeof(int));
|
||||
serialCopy(&buffer, &packet->bounds.h, sizeof(int));
|
||||
|
||||
|
||||
//location
|
||||
serialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||
serialCopy(&buffer, &packet->origin.x, sizeof(double));
|
||||
serialCopy(&buffer, &packet->origin.y, sizeof(double));
|
||||
serialCopy(&buffer, &packet->motion.x, sizeof(double));
|
||||
serialCopy(&buffer, &packet->motion.y, sizeof(double));
|
||||
|
||||
//attack data
|
||||
//TODO
|
||||
}
|
||||
|
||||
void deserializeMonster(void* buffer, MonsterPacket* packet) {
|
||||
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||
|
||||
//identify the monster
|
||||
deserialCopy(&buffer, &packet->monsterIndex, sizeof(int));
|
||||
deserialCopy(&buffer, packet->handle, PACKET_STRING_SIZE);
|
||||
deserialCopy(&buffer, packet->avatar, PACKET_STRING_SIZE);
|
||||
|
||||
//bounds
|
||||
deserialCopy(&buffer, &packet->bounds.x, sizeof(int));
|
||||
deserialCopy(&buffer, &packet->bounds.y, sizeof(int));
|
||||
deserialCopy(&buffer, &packet->bounds.w, sizeof(int));
|
||||
deserialCopy(&buffer, &packet->bounds.h, sizeof(int));
|
||||
|
||||
|
||||
//location
|
||||
deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||
deserialCopy(&buffer, &packet->origin.x, sizeof(double));
|
||||
deserialCopy(&buffer, &packet->origin.y, sizeof(double));
|
||||
deserialCopy(&buffer, &packet->motion.x, sizeof(double));
|
||||
deserialCopy(&buffer, &packet->motion.y, sizeof(double));
|
||||
|
||||
//attack data
|
||||
//TODO
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
||||
*
|
||||
* 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 MONSTERPACKET_HPP_
|
||||
#define MONSTERPACKET_HPP_
|
||||
|
||||
#include "serial_packet_base.hpp"
|
||||
|
||||
#include "bounding_box.hpp"
|
||||
#include "vector2.hpp"
|
||||
|
||||
struct MonsterPacket : SerialPacketBase {
|
||||
//identify the monster
|
||||
int monsterIndex;
|
||||
char handle[PACKET_STRING_SIZE];
|
||||
char avatar[PACKET_STRING_SIZE];
|
||||
BoundingBox bounds;
|
||||
|
||||
//location
|
||||
int roomIndex;
|
||||
Vector2 origin;
|
||||
Vector2 motion;
|
||||
|
||||
//TODO: attack data
|
||||
};
|
||||
|
||||
void serializeMonster(void* buffer, MonsterPacket* packet);
|
||||
void deserializeMonster(void* buffer, MonsterPacket* packet);
|
||||
|
||||
#endif
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "serial_packet_base.hpp"
|
||||
#include "character_packet.hpp"
|
||||
#include "client_packet.hpp"
|
||||
#include "monster_packet.hpp"
|
||||
#include "region_packet.hpp"
|
||||
#include "server_packet.hpp"
|
||||
#include "text_packet.hpp"
|
||||
@@ -33,14 +34,15 @@
|
||||
typedef SerialPacketBase SerialPacket;
|
||||
|
||||
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients
|
||||
constexpr int NETWORK_VERSION = 20141227;
|
||||
constexpr int NETWORK_VERSION = -1;
|
||||
|
||||
union MaxPacket {
|
||||
CharacterPacket a;
|
||||
ClientPacket b;
|
||||
RegionPacket c;
|
||||
ServerPacket d;
|
||||
TextPacket e;
|
||||
MonsterPacket c;
|
||||
RegionPacket d;
|
||||
ServerPacket e;
|
||||
TextPacket f;
|
||||
};
|
||||
|
||||
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
//TODO: This needs to be smoothed out
|
||||
enum class SerialPacketType {
|
||||
//default: there is something wrong
|
||||
NONE = 0,
|
||||
NONE,
|
||||
|
||||
//-------------------------
|
||||
//ServerPacket
|
||||
@@ -38,12 +38,12 @@ enum class SerialPacketType {
|
||||
//-------------------------
|
||||
|
||||
//heartbeat
|
||||
PING = 1,
|
||||
PONG = 2,
|
||||
PING,
|
||||
PONG,
|
||||
|
||||
//Used for finding available servers
|
||||
BROADCAST_REQUEST = 3,
|
||||
BROADCAST_RESPONSE = 4,
|
||||
BROADCAST_REQUEST,
|
||||
BROADCAST_RESPONSE,
|
||||
|
||||
//-------------------------
|
||||
//ClientPacket
|
||||
@@ -51,24 +51,24 @@ enum class SerialPacketType {
|
||||
//-------------------------
|
||||
|
||||
//Connecting to a server as a client
|
||||
JOIN_REQUEST = 5,
|
||||
JOIN_RESPONSE = 6,
|
||||
JOIN_REQUEST,
|
||||
JOIN_RESPONSE,
|
||||
|
||||
//disconnect from the server
|
||||
DISCONNECT_REQUEST = 7,
|
||||
DISCONNECT_RESPONSE = 8,
|
||||
DISCONNECT_FORCED = 9,
|
||||
DISCONNECT_REQUEST,
|
||||
DISCONNECT_RESPONSE,
|
||||
DISCONNECT_FORCED,
|
||||
|
||||
//load the account
|
||||
LOGIN_REQUEST = 10,
|
||||
LOGIN_RESPONSE = 11,
|
||||
LOGIN_REQUEST,
|
||||
LOGIN_RESPONSE,
|
||||
|
||||
//unload the account
|
||||
LOGOUT_REQUEST = 12,
|
||||
LOGOUT_RESPONSE = 13,
|
||||
LOGOUT_REQUEST,
|
||||
LOGOUT_RESPONSE,
|
||||
|
||||
//shut down the server
|
||||
SHUTDOWN_REQUEST = 14,
|
||||
SHUTDOWN_REQUEST,
|
||||
|
||||
//-------------------------
|
||||
//RegionPacket
|
||||
@@ -76,8 +76,8 @@ enum class SerialPacketType {
|
||||
//-------------------------
|
||||
|
||||
//map data
|
||||
REGION_REQUEST = 15, //NOTE: technically a query
|
||||
REGION_CONTENT = 16,
|
||||
REGION_REQUEST, //NOTE: technically a query
|
||||
REGION_CONTENT,
|
||||
|
||||
//-------------------------
|
||||
//CharacterPacket
|
||||
@@ -89,22 +89,40 @@ enum class SerialPacketType {
|
||||
//-------------------------
|
||||
|
||||
//character management
|
||||
CHARACTER_CREATE = 17,
|
||||
CHARACTER_DELETE = 18,
|
||||
CHARACTER_LOAD = 19,
|
||||
CHARACTER_UNLOAD = 20,
|
||||
CHARACTER_CREATE,
|
||||
CHARACTER_DELETE,
|
||||
CHARACTER_LOAD,
|
||||
CHARACTER_UNLOAD,
|
||||
|
||||
//find out info from the server
|
||||
QUERY_CHARACTER_EXISTS = 21,
|
||||
QUERY_CHARACTER_STATS = 22,
|
||||
QUERY_CHARACTER_LOCATION = 23,
|
||||
QUERY_CHARACTER_EXISTS,
|
||||
QUERY_CHARACTER_STATS,
|
||||
QUERY_CHARACTER_LOCATION,
|
||||
|
||||
//set the info in the server
|
||||
CHARACTER_SET_ROOM = 24,
|
||||
CHARACTER_SET_ORIGIN = 25,
|
||||
CHARACTER_SET_MOTION = 26,
|
||||
CHARACTER_MOVEMENT,
|
||||
CHARACTER_ATTACK,
|
||||
|
||||
//TODO: enemy management
|
||||
//admin control
|
||||
// ADMIN_SET_CHARACTER_ORIGIN,
|
||||
|
||||
//-------------------------
|
||||
//MonsterPacket
|
||||
// monster index,
|
||||
// handle, avatar, hitbox
|
||||
// room index, origin, motion
|
||||
// TODO: attack data
|
||||
//-------------------------
|
||||
|
||||
MONSTER_CREATE,
|
||||
MONSTER_DELETE,
|
||||
|
||||
QUERY_MONSTER_EXISTS, //a list of monsters in a room
|
||||
QUERY_MONSTER_STATS, //statistics of a specific monster type or instance
|
||||
QUERY_MONSTER_LOCATION, //umm...
|
||||
|
||||
MONSTER_MOVEMENT, //monster movement
|
||||
MONSTER_ATTACK,
|
||||
|
||||
//-------------------------
|
||||
//TextPacket
|
||||
@@ -112,20 +130,21 @@ enum class SerialPacketType {
|
||||
//-------------------------
|
||||
|
||||
//general speech
|
||||
TEXT_BROADCAST = 27,
|
||||
TEXT_BROADCAST,
|
||||
|
||||
//rejection/error messages
|
||||
JOIN_REJECTION = 28,
|
||||
LOGIN_REJECTION = 29,
|
||||
REGION_REJECTION = 30,
|
||||
CHARACTER_REJECTION = 31,
|
||||
SHUTDOWN_REJECTION = 32,
|
||||
JOIN_REJECTION,
|
||||
LOGIN_REJECTION,
|
||||
REGION_REJECTION,
|
||||
CHARACTER_REJECTION,
|
||||
MONSTER_REJECTION,
|
||||
SHUTDOWN_REJECTION,
|
||||
|
||||
//-------------------------
|
||||
//not used
|
||||
//-------------------------
|
||||
|
||||
LAST = 33
|
||||
LAST
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -24,6 +24,7 @@
|
||||
//packet types
|
||||
#include "character_packet.hpp"
|
||||
#include "client_packet.hpp"
|
||||
#include "monster_packet.hpp"
|
||||
#include "region_packet.hpp"
|
||||
#include "server_packet.hpp"
|
||||
#include "text_packet.hpp"
|
||||
@@ -75,16 +76,25 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
|
||||
case SerialPacketType::QUERY_CHARACTER_EXISTS:
|
||||
case SerialPacketType::QUERY_CHARACTER_STATS:
|
||||
case SerialPacketType::QUERY_CHARACTER_LOCATION:
|
||||
case SerialPacketType::CHARACTER_SET_ROOM:
|
||||
case SerialPacketType::CHARACTER_SET_ORIGIN:
|
||||
case SerialPacketType::CHARACTER_SET_MOTION:
|
||||
case SerialPacketType::CHARACTER_MOVEMENT:
|
||||
case SerialPacketType::CHARACTER_ATTACK:
|
||||
serializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
|
||||
break;
|
||||
case SerialPacketType::MONSTER_CREATE:
|
||||
case SerialPacketType::MONSTER_DELETE:
|
||||
case SerialPacketType::QUERY_MONSTER_EXISTS:
|
||||
case SerialPacketType::QUERY_MONSTER_STATS:
|
||||
case SerialPacketType::QUERY_MONSTER_LOCATION:
|
||||
case SerialPacketType::MONSTER_MOVEMENT:
|
||||
case SerialPacketType::MONSTER_ATTACK:
|
||||
serializeMonster(buffer, static_cast<MonsterPacket*>(packet));
|
||||
break;
|
||||
case SerialPacketType::TEXT_BROADCAST:
|
||||
case SerialPacketType::JOIN_REJECTION:
|
||||
case SerialPacketType::LOGIN_REJECTION:
|
||||
case SerialPacketType::REGION_REJECTION:
|
||||
case SerialPacketType::CHARACTER_REJECTION:
|
||||
case SerialPacketType::MONSTER_REJECTION:
|
||||
case SerialPacketType::SHUTDOWN_REJECTION:
|
||||
serializeText(buffer, static_cast<TextPacket*>(packet));
|
||||
break;
|
||||
@@ -126,16 +136,25 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
||||
case SerialPacketType::QUERY_CHARACTER_EXISTS:
|
||||
case SerialPacketType::QUERY_CHARACTER_STATS:
|
||||
case SerialPacketType::QUERY_CHARACTER_LOCATION:
|
||||
case SerialPacketType::CHARACTER_SET_ROOM:
|
||||
case SerialPacketType::CHARACTER_SET_ORIGIN:
|
||||
case SerialPacketType::CHARACTER_SET_MOTION:
|
||||
case SerialPacketType::CHARACTER_MOVEMENT:
|
||||
case SerialPacketType::CHARACTER_ATTACK:
|
||||
deserializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
|
||||
break;
|
||||
case SerialPacketType::MONSTER_CREATE:
|
||||
case SerialPacketType::MONSTER_DELETE:
|
||||
case SerialPacketType::QUERY_MONSTER_EXISTS:
|
||||
case SerialPacketType::QUERY_MONSTER_STATS:
|
||||
case SerialPacketType::QUERY_MONSTER_LOCATION:
|
||||
case SerialPacketType::MONSTER_MOVEMENT:
|
||||
case SerialPacketType::MONSTER_ATTACK:
|
||||
deserializeMonster(buffer, static_cast<MonsterPacket*>(packet));
|
||||
break;
|
||||
case SerialPacketType::TEXT_BROADCAST:
|
||||
case SerialPacketType::JOIN_REJECTION:
|
||||
case SerialPacketType::LOGIN_REJECTION:
|
||||
case SerialPacketType::REGION_REJECTION:
|
||||
case SerialPacketType::CHARACTER_REJECTION:
|
||||
case SerialPacketType::MONSTER_REJECTION:
|
||||
case SerialPacketType::SHUTDOWN_REJECTION:
|
||||
deserializeText(buffer, static_cast<TextPacket*>(packet));
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user