home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 15 / Example 15.2 / network_messages.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-30  |  2.5 KB  |  130 lines

  1.  
  2. #include <windows.h>
  3. #include <dplay8.h>     // directplay
  4. #include "debug.h"
  5. #include "terrain.h"
  6. #include "intpoint.h"
  7.  
  8. #define GAME_MSG_TEXT 0
  9. #define GAME_MSG_COMMAND 1
  10. #define GAME_MSG_PLAYER 2
  11. #define GAME_MSG_TERRAIN 3
  12. #define GAME_MSG_OBJECT 4
  13. #define GAME_MSG_ORDER 5
  14.  
  15. struct SESSION
  16. {
  17.     SESSION(char _name[], DPN_APPLICATION_DESC _desc, IDirectPlay8Address *_address)
  18.     {
  19.         name = _name;
  20.         desc = _desc;
  21.         if(_address != NULL)_address->Duplicate(&address);
  22.     }
  23.  
  24.     std::string name;
  25.     DPN_APPLICATION_DESC desc;
  26.     IDirectPlay8Address *address;
  27. };
  28.  
  29. struct DP_PLAYER
  30. {
  31.     DP_PLAYER(){}
  32.     DP_PLAYER(DPNID _id, char _name[])
  33.     {
  34.         id = _id;
  35.         strcpy(name, _name);
  36.         done = false;
  37.     }
  38.  
  39.     DPNID id;
  40.     char name[64];
  41.     bool done;
  42. };
  43.  
  44. struct RTS_MSG
  45. {
  46.     DWORD type;
  47. };
  48.  
  49. struct MSG_COMMAND : public RTS_MSG        //Game command
  50. {
  51.     MSG_COMMAND(DWORD cmd, DWORD att){command = cmd; attribute = att; type = GAME_MSG_COMMAND;}
  52.     DWORD command;        //0 = Ask for Name, 1 = Send Terrain Piece, 2 = Send Object, 3 = Add Players, 4 = Start Game
  53.     DWORD attribute;
  54. };
  55.  
  56. struct MSG_TEXT : public RTS_MSG        //Text Message
  57. {
  58.     MSG_TEXT(char txt[])
  59.     {
  60.         strcpy(text, txt);
  61.         type = GAME_MSG_TEXT;
  62.     }
  63.  
  64.     char text[100];
  65. };
  66.  
  67. struct MSG_PLAYER : public RTS_MSG                //Player Message
  68. {
  69.     MSG_PLAYER(DP_PLAYER dpp, BYTE _operation)
  70.     {
  71.         player = dpp;
  72.         operation = _operation;            //0 = Add Player, 1 = Remove Player, 2 = Get Name
  73.         type = GAME_MSG_PLAYER;
  74.     }
  75.  
  76.     DP_PLAYER player;
  77.     BYTE operation;
  78. };
  79.  
  80. struct MSG_TERRAIN : public RTS_MSG
  81. {
  82.     MSG_TERRAIN(TERRAIN &terrain, DWORD packNo)
  83.     {
  84.         packageNo = packNo;
  85.         type = GAME_MSG_TERRAIN;
  86.         size = terrain.m_size;
  87.  
  88.         memset(hm, 0, sizeof(float) * 100);
  89.  
  90.         for(int i=packageNo * 100, i2=0;i2<100 && i < size.x * size.y;i++, i2++)
  91.             hm[i2] = terrain.m_pMapTiles[i].m_height;
  92.     }
  93.  
  94.     DWORD packageNo;
  95.     INTPOINT size;
  96.     float hm[100];
  97. };
  98.  
  99. struct MSG_OBJECT : public RTS_MSG
  100. {
  101.     MSG_OBJECT(OBJECT &obj, DWORD packNo)
  102.     {
  103.         type = GAME_MSG_OBJECT;
  104.         objType = obj.m_type;
  105.         mp = obj.m_mappos;
  106.         pos = obj.m_meshInstance.m_pos;
  107.         rot = obj.m_meshInstance.m_rot;
  108.         sca = obj.m_meshInstance.m_sca;
  109.         packageNo = packNo;
  110.     }
  111.  
  112.     int objType;
  113.     DWORD packageNo;
  114.     INTPOINT mp;
  115.     D3DXVECTOR3 pos, rot, sca;
  116. };
  117.  
  118. struct MSG_ORDER : public RTS_MSG
  119. {
  120.     MSG_ORDER(int _player, int _unitID, INTPOINT _dest)
  121.     {
  122.         type = GAME_MSG_ORDER;
  123.         unitID = _unitID;
  124.         dest = _dest;
  125.         player = _player;
  126.     }
  127.  
  128.     int unitID, player;
  129.     INTPOINT dest;
  130. };