Added the rest of the combat info to the network code

This commit is contained in:
Kayne Ruse
2014-06-01 23:07:02 +10:00
parent 2e8a474792
commit 1cfb814ee4
6 changed files with 140 additions and 51 deletions
+9
View File
@@ -40,7 +40,16 @@
#include <list>
#include <utility>
#define COMBAT_MAX_CHARACTER_COUNT 12
#define COMBAT_MAX_ENEMY_COUNT 12
struct CombatData {
enum class Terrain {
//TODO: types of terrains
NONE = 0,
GRASSLANDS,
};
typedef std::chrono::steady_clock Clock;
//combatants, point to the std::map's internal pairs
+35
View File
@@ -0,0 +1,35 @@
/* 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 ROOMDATA_HPP_
#define ROOMDATA_HPP_
struct RoomData {
enum class RoomType {
OVERWORLD,
RUINS,
TOWERS,
FORESTS,
CAVES,
};
};
#endif
+1
View File
@@ -24,6 +24,7 @@
#include "client_data.hpp"
#include "combat_data.hpp"
#include "enemy_data.hpp"
#include "room_data.hpp"
#include "statistics.hpp"
/* DOCS: Sanity check, read more
+46 -6
View File
@@ -99,7 +99,19 @@ void serializeCombat(SerialPacket* packet, char* buffer) {
//integers
SERIALIZE(buffer, &packet->combatInfo.combatIndex, sizeof(int));
SERIALIZE(buffer, &packet->combatInfo.difficulty, sizeof(int));
//TODO: more comabat info
SERIALIZE(buffer, &packet->combatInfo.terrainType, sizeof(CombatData::Terrain));
//arrays
SERIALIZE(buffer, &packet->combatInfo.characterArray, COMBAT_MAX_CHARACTER_COUNT);
SERIALIZE(buffer, &packet->combatInfo.enemyArray, COMBAT_MAX_ENEMY_COUNT);
//position
SERIALIZE(buffer, &packet->combatInfo.mapIndex, sizeof(int));
SERIALIZE(buffer, &packet->combatInfo.position.x, sizeof(double));
SERIALIZE(buffer, &packet->combatInfo.position.y, sizeof(double));
//TODO: rewards
}
void serializeStatistics(Statistics* stats, char* buffer) {
@@ -231,7 +243,19 @@ void deserializeCombat(SerialPacket* packet, char* buffer) {
//integers
DESERIALIZE(buffer, &packet->combatInfo.combatIndex, sizeof(int));
DESERIALIZE(buffer, &packet->combatInfo.difficulty, sizeof(int));
//TODO: more comabat info
DESERIALIZE(buffer, &packet->combatInfo.terrainType, sizeof(CombatData::Terrain));
//arrays
DESERIALIZE(buffer, &packet->combatInfo.characterArray, COMBAT_MAX_CHARACTER_COUNT);
DESERIALIZE(buffer, &packet->combatInfo.enemyArray, COMBAT_MAX_ENEMY_COUNT);
//position
DESERIALIZE(buffer, &packet->combatInfo.mapIndex, sizeof(int));
DESERIALIZE(buffer, &packet->combatInfo.position.x, sizeof(double));
DESERIALIZE(buffer, &packet->combatInfo.position.y, sizeof(double));
//TODO: rewards
}
@@ -337,8 +361,16 @@ void serialize(SerialPacket* packet, void* buffer) {
break;
//combat info
case SerialPacket::Type::COMBAT_ENTER:
case SerialPacket::Type::COMBAT_EXIT:
case SerialPacket::Type::COMBAT_NEW:
case SerialPacket::Type::COMBAT_DELETE:
case SerialPacket::Type::COMBAT_UPDATE:
//TODO: is this the best fit?
case SerialPacket::Type::COMBAT_ENTER_REQUEST:
case SerialPacket::Type::COMBAT_ENTER_RESPONSE:
case SerialPacket::Type::COMBAT_EXIT_REQUEST:
case SerialPacket::Type::COMBAT_EXIT_RESPONSE:
serializeCombat(packet, reinterpret_cast<char*>(buffer));
break;
@@ -407,8 +439,16 @@ void deserialize(SerialPacket* packet, void* buffer) {
break;
//combat info
case SerialPacket::Type::COMBAT_ENTER:
case SerialPacket::Type::COMBAT_EXIT:
case SerialPacket::Type::COMBAT_NEW:
case SerialPacket::Type::COMBAT_DELETE:
case SerialPacket::Type::COMBAT_UPDATE:
//TODO: is this the best fit?
case SerialPacket::Type::COMBAT_ENTER_REQUEST:
case SerialPacket::Type::COMBAT_ENTER_RESPONSE:
case SerialPacket::Type::COMBAT_EXIT_REQUEST:
case SerialPacket::Type::COMBAT_EXIT_RESPONSE:
serializeCombat(packet, reinterpret_cast<char*>(buffer));
break;
+45 -33
View File
@@ -25,10 +25,11 @@
#include "vector2.hpp"
#include "region.hpp"
#include "statistics.hpp"
#include "combat_data.hpp"
#include "SDL/SDL_net.h"
#define NETWORK_VERSION 20140528
#define NETWORK_VERSION 20140601
#define PACKET_STRING_SIZE 100
union SerialPacket {
@@ -38,60 +39,67 @@ union SerialPacket {
NONE = 0,
//keep alive
PING = 1,
PONG = 2,
PING,
PONG,
//searching for a server to join
BROADCAST_REQUEST = 3,
BROADCAST_RESPONSE = 4,
BROADCAST_REJECTION = 5,
BROADCAST_REQUEST,
BROADCAST_RESPONSE,
BROADCAST_REJECTION,
//try to join the server
JOIN_REQUEST = 6,
JOIN_RESPONSE = 7,
JOIN_REJECTION = 8,
JOIN_REQUEST,
JOIN_RESPONSE,
JOIN_REJECTION,
//mass update
SYNCHRONIZE = 9,
SYNCHRONIZE,
//disconnect from the server
DISCONNECT = 10,
DISCONNECT,
//shut down the server
SHUTDOWN = 11,
SHUTDOWN,
//map data
REGION_REQUEST = 12,
REGION_CONTENT = 13,
REGION_REJECTION = 14,
REGION_REQUEST,
REGION_CONTENT,
REGION_REJECTION,
//combat data
COMBAT_ENTER = 15,
COMBAT_EXIT = 16,
COMBAT_NEW,
COMBAT_DELETE,
COMBAT_UPDATE,
COMBAT_UPDATE = 17,
COMBAT_ENTER_REQUEST,
COMBAT_ENTER_RESPONSE,
COMBAT_REJECTION = 18,
COMBAT_EXIT_REQUEST,
COMBAT_EXIT_RESPONSE,
//TODO: COMBAT info
COMBAT_REJECTION,
//character data
CHARACTER_NEW = 19,
CHARACTER_DELETE = 20,
CHARACTER_UPDATE = 21,
CHARACTER_NEW,
CHARACTER_DELETE,
CHARACTER_UPDATE,
CHARACTER_STATS_REQUEST = 22,
CHARACTER_STATS_RESPONSE = 23,
CHARACTER_STATS_REQUEST,
CHARACTER_STATS_RESPONSE,
CHARACTER_REJECTION = 24,
CHARACTER_REJECTION,
//enemy data
ENEMY_NEW = 25,
ENEMY_DELETE = 26,
ENEMY_UPDATE = 27,
ENEMY_NEW,
ENEMY_DELETE,
ENEMY_UPDATE,
ENEMY_STATS_REQUEST = 28,
ENEMY_STATS_RESPONSE = 29,
ENEMY_STATS_REQUEST,
ENEMY_STATS_RESPONSE,
ENEMY_REJECTION = 30,
ENEMY_REJECTION,
//more packet types go here
@@ -138,8 +146,11 @@ union SerialPacket {
Metadata meta;
int combatIndex;
int difficulty;
//TODO: background image, based on terrain type
//TODO: array of combatants
CombatData::Terrain terrainType;
int characterArray[COMBAT_MAX_CHARACTER_COUNT];
int enemyArray[COMBAT_MAX_ENEMY_COUNT];
int mapIndex;
Vector2 position;
//TODO: rewards
}combatInfo;
@@ -163,6 +174,7 @@ union SerialPacket {
char handle[PACKET_STRING_SIZE];
char avatar[PACKET_STRING_SIZE];
Statistics stats;
//TODO: rewards
}enemyInfo;
//defaults
+4 -12
View File
@@ -23,18 +23,10 @@
#define ENEMYFACTORYINTERFACE_HPP_
#include "enemy_data.hpp"
#include "room_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:
@@ -44,12 +36,12 @@ public:
virtual void Generate(std::list<EnemyData>* container) = 0;
//control the difficulty of the room
RoomType SetType(RoomType t) { return type = t; }
RoomData::RoomType SetType(RoomData::RoomType t) { return type = t; }
int SetDifficulty(int d) { return difficulty = d; }
RoomType GetType() { return type; }
RoomData::RoomType GetType() { return type; }
int GetDifficulty() { return difficulty; }
protected:
RoomType type;
RoomData::RoomType type;
int difficulty;
};