NetPacks.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "../global.h"
  2. struct IPack
  3. {
  4. virtual ui16 getType()const = 0 ;
  5. //template<ui16 Type>
  6. //static bool isType(const IPack * ip)
  7. //{
  8. // return Type == ip->getType();
  9. //}
  10. template<ui16 Type>
  11. static bool isType(IPack * ip)
  12. {
  13. return Type == ip->getType();
  14. }
  15. //template<ui16 Type>
  16. //static bool isType(const IPack & ip)
  17. //{
  18. // return Type == ip.getType();
  19. //}
  20. };
  21. template <typename T> struct CPack
  22. :public IPack
  23. {
  24. ui16 type;
  25. ui16 getType() const{return type;}
  26. T* This(){return static_cast<T*>(this);};
  27. };
  28. struct NewTurn : public CPack<NewTurn> //101
  29. {
  30. struct Hero
  31. {
  32. ui32 id, move, mana; //id is a general serial id
  33. template <typename Handler> void serialize(Handler &h, const int version)
  34. {
  35. h & id & move & mana;
  36. }
  37. bool operator<(const Hero&h)const{return id < h.id;}
  38. };
  39. struct Resources
  40. {
  41. ui8 player;
  42. si32 resources[RESOURCE_QUANTITY];
  43. template <typename Handler> void serialize(Handler &h, const int version)
  44. {
  45. h & player & resources;
  46. }
  47. bool operator<(const Resources&h)const{return player < h.player;}
  48. };
  49. std::set<Hero> heroes; //updates movement and mana points
  50. std::set<Resources> res;//resource list
  51. ui32 day;
  52. bool resetBuilded;
  53. NewTurn(){type = 101;};
  54. template <typename Handler> void serialize(Handler &h, const int version)
  55. {
  56. h & heroes & res & day & resetBuilded;
  57. }
  58. };
  59. struct TryMoveHero : public CPack<TryMoveHero> //501
  60. {
  61. TryMoveHero(){type = 501;};
  62. ui32 id, movePoints;
  63. ui8 result;
  64. int3 start, end;
  65. std::set<int3> fowRevealed; //revealed tiles
  66. template <typename Handler> void serialize(Handler &h, const int version)
  67. {
  68. h & id & result & start & end & movePoints & fowRevealed;
  69. }
  70. };