int3.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef INT3_H
  2. #define INT3_H
  3. #include <map>
  4. class CCreature;
  5. class CCreatureSet //seven combined creatures
  6. {
  7. public:
  8. std::map<si32,std::pair<ui32,si32> > slots; //slots[slot_id]=> pair(creature_id,creature_quantity)
  9. bool formation; //false - wide, true - tight
  10. template <typename Handler> void serialize(Handler &h, const int version)
  11. {
  12. h & slots & formation;
  13. }
  14. };
  15. class int3
  16. {
  17. public:
  18. si32 x,y,z;
  19. inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0
  20. inline int3(const si32 & X, const si32 & Y, const si32 & Z):x(X),y(Y),z(Z){}; //c-tor
  21. inline ~int3(){} // d-tor - does nothing
  22. inline int3 operator+(const int3 & i) const
  23. {return int3(x+i.x,y+i.y,z+i.z);}
  24. inline int3 operator+(const si32 i) const //increases all components by si32
  25. {return int3(x+i,y+i,z+i);}
  26. inline int3 operator-(const int3 & i) const
  27. {return int3(x-i.x,y-i.y,z-i.z);}
  28. inline int3 operator-(const si32 i) const
  29. {return int3(x-i,y-i,z-i);}
  30. inline int3 operator-() const //increases all components by si32
  31. {return int3(-x,-y,-z);}
  32. inline void operator+=(const int3 & i)
  33. {
  34. x+=i.x;
  35. y+=i.y;
  36. z+=i.z;
  37. }
  38. inline void operator+=(const si32 & i)
  39. {
  40. x+=i;
  41. y+=i;
  42. z+=i;
  43. }
  44. inline void operator-=(const int3 & i)
  45. {
  46. x-=i.x;
  47. y-=i.y;
  48. z-=i.z;
  49. }
  50. inline void operator-=(const si32 & i)
  51. {
  52. x+=i;
  53. y+=i;
  54. z+=i;
  55. }
  56. inline bool operator==(const int3 & i) const
  57. {return (x==i.x) && (y==i.y) && (z==i.z);}
  58. inline bool operator!=(const int3 & i) const
  59. {return !(*this==i);}
  60. inline bool operator<(const int3 & i) const
  61. {
  62. if (z<i.z)
  63. return true;
  64. if (z>i.z)
  65. return false;
  66. if (y<i.y)
  67. return true;
  68. if (y>i.y)
  69. return false;
  70. if (x<i.x)
  71. return true;
  72. if (x>i.x)
  73. return false;
  74. return false;
  75. }
  76. template <typename Handler> void serialize(Handler &h, const int version)
  77. {
  78. h & x & y & z;
  79. }
  80. };
  81. inline std::istream & operator>>(std::istream & str, int3 & dest)
  82. {
  83. str>>dest.x>>dest.y>>dest.z;
  84. return str;
  85. }
  86. inline std::ostream & operator<<(std::ostream & str, const int3 & sth)
  87. {
  88. return str<<sth.x<<' '<<sth.y<<' '<<sth.z;
  89. }
  90. #endif //INT3_H