Host.h
上传用户:royluo
上传日期:2007-01-05
资源大小:1584k
文件大小:7k
源码类别:

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   Host.h
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Module description: Implements the communication module that handles 
  11. *                       messages send to the game host.
  12. *                       
  13. *                                                                             
  14. *   Authors: Eran Yariv - 28484475                                           
  15. *            Moshe Zur  - 24070856                                           
  16. *                                                                            
  17. *                                                                            
  18. *   Date: 23/09/98                                                           
  19. *                                                                            
  20. ******************************************************************************/
  21. #ifndef _HOST_H_
  22. #define _HOST_H_
  23. #include "CommManager.h"
  24. class CHost
  25. {
  26. public:
  27.     CHost(CCommManager &CommManager);
  28.     ~CHost();
  29.     void HandleMessage(DPID idFrom, BOOL bFromJudge);
  30.     void RemovePlayerFromArray(DPID idPlayer);
  31.     int  LookupTankID (DPID);   // Returns 0..MAX_TANKS-1 or -1 (no found) or -2 (host)
  32.     BOOL GetPlayerInfo (UINT ind, DWORD &Duration, DWORD &RTT);
  33.     DPID GetDirectPlayID (UINT uPlayerID);
  34.     void ChkForZombies();       // Check if there are tanks that we didn't hear from
  35.                                 // for a long time
  36. private:
  37.     void HandleRequestTank (BYTE bReqTankID);
  38.     void HandleCheckSum (CMessage &, BOOL bJudgeReporting);
  39.     void SendBonusStatus();
  40.     void SendAddTank(int iTankID);
  41.     void SendTankPos(int iTankID, int nXPos, int nYPos);
  42.     void SendTankStatus(int iTankID);
  43.     void SendRemoveTank(int iTankID);
  44.     void SendTankZombie(int iTankID, BOOL bZombie, BOOL bToAll);
  45.     void SendMinesStatus(int iSector);
  46.     void LocateNewTankPos(int &XPos, int &YPos, int &Dir);
  47.     BYTE MapAndGetAvailTankID(BYTE bReqTankID);
  48.     BOOL ValueCloseEnough (int val1, int val2, int MinTolerance);
  49.     void SendToAllButSender();          // Send the message stored in m_Message to all tanks but the sender
  50.     void SendToAll ();                  // Send the message stored in m_Message to all tanks.
  51.     void ReplyToSender();               // Send the message stored in m_Message to the sender
  52.     typedef struct JudgeViewOfTankTag
  53.     {
  54.         BOOL    Exists;         // Does tank exist?
  55.         BOOL    Zombie;         // Zombie flag
  56.         BOOL    FastFire;
  57.         BOOL    LastRTTWasGood;
  58.         DWORD   Shells;
  59.         DWORD   Bullets;
  60.         DWORD   Mines;
  61.         int     BadRTTCount;
  62.     } JudgeViewOfTank;
  63.     JudgeViewOfTank m_JudgeViewOfTanks[MAX_TANKS];          // Judge's view on tanks states
  64.     BYTE            m_JudgeViewOfMines[MAX_SECTOR + 1];     // Judge's view of mines
  65.     BonusType       m_JudgeViewOfBonus;                     // Judge's view of current bonus
  66.     CCommManager&   m_CommManager;                          // Alias to the comm. manager
  67.     CGameManager&   m_GameManager;                          // Alias to the game  manager
  68.     CCommMessage&   m_Message;                              // Alias to the comm. manager's message buffer
  69.     TIMER_CLASS    &m_Timer;                                // Alias to global timer
  70.     DPID            m_aPlayersID[MAX_TANKS];                // Map TankID to player DPID
  71.     DPID            m_idFrom;                               // Sender of currently handled message 
  72.     WORD            m_wSeed;                                // Game random seed
  73.     BYTE            m_bComplexity;                          // Stored game complexity
  74.     typedef struct _PlayerRTT
  75.     {
  76. #ifdef GATHER_SYNC_STATS
  77.         DWORD dwPlayerMaxRTT;           // Maximal time RTT witnessed with this player
  78.         DWORD dwPlayerMinRTT;           // Minimal time RTT witnessed with this player
  79.         DWORD dwPlayerTotalRTTs;        // Sum of all RTTS (for average statistics)
  80.         DWORD adwPlayerRTTCounts[8];    // For histogram of RTTs
  81.         DWORD adwPlayerRTTTotals[8];    // For histogram of RTTs
  82.         DWORD dwTotMsgs;                // Total number of messages RTTs are calculated for
  83. #endif // GATHER_SYNC_STATS
  84.         DWORD dwPlayerCurRTT;           // Last time RTT witnessed with this player
  85.         DWORD dwPlayerJoinTime;         // The local host time of joining the game
  86.         DWORD dwLastMsgTime;            // The local host time of last msg from player
  87.     } PlayerRTT;
  88.     PlayerRTT   m_PlayersRTT [MAX_TANKS];
  89.     void PlayerJoinsGame (UINT uID);
  90.     void UpdatePlayerRTT (DWORD dwGameTime);
  91. #ifdef GATHER_SYNC_STATS
  92.     typedef struct _TankSyncStats
  93.     {
  94.         DWORD dwStartTime;                  // Session start time for the player
  95.         DWORD dwSyncMsgsArrived;            // Number of sync messages arriving from tank
  96.         DWORD dwTotSyncMsgSize;             // Total size of all sync messages
  97.         DWORD dwZombieIn;                   // Number of times tank turned zombie
  98.         DWORD dwZombieOut;                  // Number of times tank turned un-zombie
  99.         DWORD dwBonusMismatch;              // Number of bonus mismatches
  100.         DWORD dwMinesMismatch;              // Mines checksum mismatch
  101.         DWORD dwZombieMismatch;             // Zombie state mismatch
  102.         DWORD dwOtherTankStatusMismatch;    // Mismatch in tank status (not reporting tank)
  103.         DWORD dwMissingTanks;               // Number of tanks missing (yielding SendAddTank)
  104.         DWORD dwExtraTanks;                 // Number of tanks still alive (yielding SendRemoveTank)
  105.         DWORD dwSmallestTimeGap;            // Smallest time gap between two sync reports
  106.         DWORD dwBiggestTimeGap;             // Biggest time gap between two sync reports
  107.         DWORD dwTotalGaps, dwTotalGapsCnt;
  108.         DWORD dwLastReportTime;             // Arrival time of last sync message
  109.     } TankSyncStats;
  110.     TankSyncStats   m_TanksSyncStats[MAX_TANKS];
  111.     void ZeroTankSyncStats (UINT uTankID);
  112.     void PrintTankSyncStats (UINT uTankID);
  113.     void UpdateSyncMsgTime (UINT uTankID);
  114. #endif // GATHER_SYNC_STATS
  115. };
  116. #include <host.inl>
  117. #endif