2010-03-18 22:26:40 +01:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2010-05-15 20:59:17 +02:00
|
|
|
// Copyright (C) 2001-2008 Martio Figueroa
|
2010-03-18 22:26:40 +01:00
|
|
|
//
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#ifndef _GLEST_GAME_NETWORKTYPES_H_
|
|
|
|
#define _GLEST_GAME_NETWORKTYPES_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "vec.h"
|
|
|
|
|
|
|
|
using std::string;
|
2010-08-07 08:35:52 +02:00
|
|
|
using std::min;
|
2010-03-18 22:26:40 +01:00
|
|
|
using Shared::Platform::int8;
|
2010-06-08 09:40:32 +02:00
|
|
|
using Shared::Platform::uint8;
|
2010-03-18 22:26:40 +01:00
|
|
|
using Shared::Platform::int16;
|
2010-06-08 09:40:32 +02:00
|
|
|
using Shared::Platform::uint16;
|
2010-03-18 22:26:40 +01:00
|
|
|
using Shared::Platform::int32;
|
|
|
|
using Shared::Graphics::Vec2i;
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
2010-03-22 05:47:16 +01:00
|
|
|
class World;
|
|
|
|
|
2010-03-18 22:26:40 +01:00
|
|
|
// =====================================================
|
|
|
|
// class NetworkString
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
template<int S>
|
|
|
|
class NetworkString{
|
|
|
|
private:
|
|
|
|
char buffer[S];
|
|
|
|
|
|
|
|
public:
|
2010-08-07 05:26:38 +02:00
|
|
|
NetworkString() {memset(buffer, 0, S);}
|
|
|
|
void operator=(const string& str) {
|
|
|
|
// ensure we don't have a buffer overflow
|
|
|
|
int maxBufferSize = sizeof(buffer) / sizeof(buffer[0]);
|
2010-08-07 08:35:52 +02:00
|
|
|
strncpy(buffer, str.c_str(), min(S-1,maxBufferSize-1));
|
2010-08-07 05:26:38 +02:00
|
|
|
}
|
|
|
|
string getString() const {return buffer;}
|
2010-03-18 22:26:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class NetworkCommand
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
enum NetworkCommandType {
|
|
|
|
nctGiveCommand,
|
|
|
|
nctCancelCommand,
|
2010-03-22 05:47:16 +01:00
|
|
|
nctSetMeetingPoint
|
|
|
|
//nctNetworkCommand
|
2010-03-18 22:26:40 +01:00
|
|
|
};
|
|
|
|
|
2010-03-22 05:47:16 +01:00
|
|
|
//enum NetworkCommandSubType {
|
|
|
|
// ncstRotateUnit
|
|
|
|
//};
|
2010-03-18 22:26:40 +01:00
|
|
|
|
2010-06-08 09:40:32 +02:00
|
|
|
#pragma pack(push, 1)
|
2010-03-18 22:26:40 +01:00
|
|
|
class NetworkCommand{
|
|
|
|
private:
|
|
|
|
int16 networkCommandType;
|
2010-05-31 11:45:54 +02:00
|
|
|
int32 unitId;
|
2010-03-18 22:26:40 +01:00
|
|
|
int16 commandTypeId;
|
|
|
|
int16 positionX;
|
|
|
|
int16 positionY;
|
|
|
|
int16 unitTypeId;
|
2010-05-31 11:45:54 +02:00
|
|
|
int32 targetId;
|
2010-06-08 09:40:32 +02:00
|
|
|
int8 wantQueue;
|
|
|
|
int8 fromFactionIndex;
|
|
|
|
uint16 unitFactionUnitCount;
|
|
|
|
int8 unitFactionIndex;
|
2010-03-18 22:26:40 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
NetworkCommand(){};
|
2010-03-25 13:15:10 +01:00
|
|
|
NetworkCommand(
|
|
|
|
World *world,
|
|
|
|
int networkCommandType,
|
|
|
|
int unitId,
|
|
|
|
int commandTypeId= -1,
|
|
|
|
const Vec2i &pos= Vec2i(0),
|
|
|
|
int unitTypeId= -1,
|
|
|
|
int targetId= -1,
|
2010-04-18 09:35:48 +02:00
|
|
|
int facing= -1,
|
|
|
|
bool wantQueue = false);
|
2010-03-25 13:15:10 +01:00
|
|
|
|
2010-03-22 05:47:16 +01:00
|
|
|
//NetworkCommand(int networkCommandType, NetworkCommandSubType ncstType, int unitId, int value1, int value2=-1);
|
2010-03-18 22:26:40 +01:00
|
|
|
|
|
|
|
NetworkCommandType getNetworkCommandType() const {return static_cast<NetworkCommandType>(networkCommandType);}
|
|
|
|
int getUnitId() const {return unitId;}
|
|
|
|
int getCommandTypeId() const {return commandTypeId;}
|
|
|
|
Vec2i getPosition() const {return Vec2i(positionX, positionY);}
|
|
|
|
int getUnitTypeId() const {return unitTypeId;}
|
|
|
|
int getTargetId() const {return targetId;}
|
2010-04-18 09:35:48 +02:00
|
|
|
int getWantQueue() const {return wantQueue;}
|
2010-05-15 20:59:17 +02:00
|
|
|
int getFromFactionIndex() const {return fromFactionIndex;}
|
2010-05-29 10:23:52 +02:00
|
|
|
int getUnitFactionUnitCount() const {return unitFactionUnitCount;}
|
|
|
|
int getUnitFactionIndex() const {return unitFactionIndex;}
|
2010-03-22 05:47:16 +01:00
|
|
|
|
|
|
|
void preprocessNetworkCommand(World *world);
|
|
|
|
string toString() const;
|
2010-03-18 22:26:40 +01:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
#endif
|