1 // ==============================================================
2 //	This file is part of Glest (www.glest.org)
3 //
4 //	Copyright (C) 2001-2008 Marti�o Figueroa
5 //
6 //	You can redistribute this code and/or modify it under
7 //	the terms of the GNU General Public License as published
8 //	by the Free Software Foundation; either version 2 of the
9 //	License, or (at your option) any later version
10 // ==============================================================
11 
12 #ifndef _GLEST_GAME_NETWORKTYPES_H_
13 #define _GLEST_GAME_NETWORKTYPES_H_
14 
15 #include <string>
16 
17 #include "types.h"
18 #include "vec.h"
19 
20 using std::string;
21 using Shared::Platform::int8;
22 using Shared::Platform::int16;
23 using Shared::Platform::int32;
24 using Shared::Graphics::Vec2i;
25 
26 namespace Glest{ namespace Game{
27 
28 // =====================================================
29 //	class NetworkString
30 // =====================================================
31 
32 template<int S>
33 class NetworkString{
34 private:
35 	char buffer[S];
36 
37 public:
NetworkString()38 	NetworkString()						{memset(buffer, 0, S);}
39 	void operator=(const string& str)	{strncpy(buffer, str.c_str(), S-1);}
getString()40 	string getString() const			{return buffer;}
41 };
42 
43 // =====================================================
44 //	class NetworkCommand
45 // =====================================================
46 
47 enum NetworkCommandType{
48 	nctGiveCommand,
49 	nctCancelCommand,
50 	nctSetMeetingPoint
51 };
52 
53 class NetworkCommand{
54 private:
55 	int16 networkCommandType;
56 	int16 unitId;
57 	int16 commandTypeId;
58 	int16 positionX;
59 	int16 positionY;
60 	int16 unitTypeId;
61 	int16 targetId;
62 
63 public:
NetworkCommand()64 	NetworkCommand(){};
65 	NetworkCommand(int networkCommandType, int unitId, int commandTypeId= -1, const Vec2i &pos= Vec2i(0), int unitTypeId= -1, int targetId= -1);
66 
getNetworkCommandType()67 	NetworkCommandType getNetworkCommandType() const	{return static_cast<NetworkCommandType>(networkCommandType);}
getUnitId()68 	int getUnitId() const								{return unitId;}
getCommandTypeId()69 	int getCommandTypeId() const						{return commandTypeId;}
getPosition()70 	Vec2i getPosition() const							{return Vec2i(positionX, positionY);}
getUnitTypeId()71 	int getUnitTypeId() const							{return unitTypeId;}
getTargetId()72 	int getTargetId() const								{return targetId;}
73 };
74 
75 }}//end namespace
76 
77 #endif
78