int3.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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<int,std::pair<CCreature*,int> > slots;
  9. bool formation; //false - wide, true - tight
  10. };
  11. class int3
  12. {
  13. public:
  14. int x,y,z;
  15. inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0
  16. inline int3(const int & X, const int & Y, const int & Z):x(X),y(Y),z(Z){}; //c-tor
  17. inline ~int3(){} // d-tor - does nothing
  18. inline int3 operator+(const int3 & i) const
  19. {return int3(x+i.x,y+i.y,z+i.z);}
  20. inline int3 operator+(const int i) const //increases all components by int
  21. {return int3(x+i,y+i,z+i);}
  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 int i) const
  25. {return int3(x-i,y-i,z-i);}
  26. inline int3 operator-() const //increases all components by int
  27. {return int3(-x,-y,-z);}
  28. inline void operator+=(const int3 & i)
  29. {
  30. x+=i.x;
  31. y+=i.y;
  32. z+=i.z;
  33. }
  34. inline void operator+=(const int & i)
  35. {
  36. x+=i;
  37. y+=i;
  38. z+=i;
  39. }
  40. inline void operator-=(const int3 & i)
  41. {
  42. x-=i.x;
  43. y-=i.y;
  44. z-=i.z;
  45. }
  46. inline void operator-=(const int & i)
  47. {
  48. x+=i;
  49. y+=i;
  50. z+=i;
  51. }
  52. inline bool operator==(const int3 & i) const
  53. {return (x==i.x) && (y==i.y) && (z==i.z);}
  54. inline bool operator!=(const int3 & i) const
  55. {return !(*this==i);}
  56. inline bool operator<(const int3 & i) const
  57. {
  58. if (z<i.z)
  59. return true;
  60. if (z>i.z)
  61. return false;
  62. if (y<i.y)
  63. return true;
  64. if (y>i.y)
  65. return false;
  66. if (x<i.x)
  67. return true;
  68. if (x>i.x)
  69. return false;
  70. return false;
  71. }
  72. };
  73. inline std::istream & operator>>(std::istream & str, int3 & dest)
  74. {
  75. str>>dest.x>>dest.y>>dest.z;
  76. return str;
  77. }
  78. inline std::ostream & operator<<(std::ostream & str, int3 & sth)
  79. {
  80. return str<<sth.x<<' '<<sth.y<<' '<<sth.z;
  81. }
  82. #endif //INT3_H