global.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #ifndef GLOBAL_H
  2. #define GLOBAL_H
  3. #include <iostream>
  4. #include <boost/logic/tribool.hpp>
  5. #include <boost/cstdint.hpp>
  6. typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes)
  7. typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes)
  8. typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte)
  9. typedef boost::int32_t si32; //signed int 32 bits (4 bytes)
  10. typedef boost::int16_t si16; //signed int 16 bits (2 bytes)
  11. typedef boost::int8_t si8; //signed int 8 bits (1 byte)
  12. #include "int3.h"
  13. #define CHECKTIME 1
  14. #if CHECKTIME
  15. #include "timeHandler.h"
  16. #define THC
  17. #endif
  18. #define NAME_VER ("VCMI 0.62")
  19. #ifdef _WIN32
  20. #define PATHSEPARATOR "\\"
  21. #define DATA_DIR ""
  22. #define SERVER_NAME "VCMI_server.exe"
  23. #else
  24. #define PATHSEPARATOR "/"
  25. #define DATA_DIR ""
  26. #define SERVER_NAME "./vcmiserver"
  27. #endif
  28. enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK}; //player's colors
  29. enum EterrainType {border=-1, dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock};
  30. enum Eriver {noRiver=0, clearRiver, icyRiver, muddyRiver, lavaRiver};
  31. enum Eroad {dirtRoad=1, grazvelRoad, cobblestoneRoad};
  32. enum Eformat { WoG=0x33, AB=0x15, RoE=0x0e, SoD=0x1c};
  33. enum EvictoryConditions {artifact, gatherTroop, gatherResource, buildCity, buildGrail, beatHero,
  34. captureCity, beatMonster, takeDwellings, takeMines, transportItem, winStandard=255};
  35. enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255};
  36. enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HERO_ALCHEMIST, HERO_WIZARD,
  37. HERO_DEMONIAC, HERO_HERETIC, HERO_DEATHKNIGHT, HERO_NECROMANCER, HERO_WARLOCK, HERO_OVERLORD,
  38. HERO_BARBARIAN, HERO_BATTLEMAGE, HERO_BEASTMASTER, HERO_WITCH, HERO_PLANESWALKER, HERO_ELEMENTALIST};
  39. class CGameInfo;
  40. extern CGameInfo* CGI;
  41. #define HEROI_TYPE (0)
  42. #define TOWNI_TYPE (1)
  43. const int F_NUMBER = 9; //factions (town types) quantity
  44. const int PLAYER_LIMIT = 8; //player limit per map
  45. const int HEROES_PER_TYPE=8; //amount of heroes of each type
  46. const int SKILL_QUANTITY=28;
  47. const int SKILL_PER_HERO=8;
  48. const int ARTIFACTS_QUANTITY=171;
  49. const int HEROES_QUANTITY=156;
  50. const int SPELLS_QUANTITY=70;
  51. const int RESOURCE_QUANTITY=8;
  52. const int TERRAIN_TYPES=10;
  53. const int PRIMARY_SKILLS=4;
  54. const int NEUTRAL_PLAYER=255;
  55. const int NAMES_PER_TOWN=16;
  56. const int CREATURES_PER_TOWN = 7; //without upgrades
  57. const int MAX_BUILDING_PER_TURN = 1;
  58. const int SPELL_LEVELS = 5;
  59. #define MARK_BLOCKED_POSITIONS false
  60. #define MARK_VISITABLE_POSITIONS false
  61. #define DEFBYPASS
  62. #ifdef _WIN32
  63. #ifdef VCMI_DLL
  64. #define DLL_EXPORT __declspec(dllexport)
  65. #else
  66. #define DLL_EXPORT __declspec(dllimport)
  67. #endif
  68. #else
  69. #if defined(__GNUC__) && __GNUC__ >= 4
  70. #define DLL_EXPORT __attribute__ ((visibility("default")))
  71. #else
  72. #define DLL_EXPORT
  73. #endif
  74. #endif
  75. #define HANDLE_EXCEPTION \
  76. catch (const std::exception& e) { \
  77. std::cerr << e.what() << std::endl; \
  78. } \
  79. catch (const std::exception * e) \
  80. { \
  81. std::cerr << e->what()<< std::endl; \
  82. delete e; \
  83. }
  84. #define HANDLE_EXCEPTIONC(COMMAND) \
  85. catch (const std::exception& e) { \
  86. COMMAND; \
  87. std::cerr << e.what() << std::endl; \
  88. } \
  89. catch (const std::exception * e) \
  90. { \
  91. COMMAND; \
  92. std::cerr << e->what()<< std::endl; \
  93. delete e; \
  94. }
  95. namespace vstd
  96. {
  97. template <typename Container, typename Item>
  98. bool contains(const Container & c, const Item &i)
  99. {
  100. return std::find(c.begin(),c.end(),i) != c.end();
  101. }
  102. template <typename V, typename Item>
  103. bool contains(const std::map<Item,V> & c, const Item &i)
  104. {
  105. return c.find(i)!=c.end();
  106. }
  107. template <typename Container1, typename Container2>
  108. typename Container2::iterator findFirstNot(Container1 &c1, Container2 &c2)//returns first element of c2 not present in c1
  109. {
  110. typename Container2::iterator itr = c2.begin();
  111. while(itr != c2.end())
  112. if(!contains(c1,*itr))
  113. return itr;
  114. else
  115. ++itr;
  116. return c2.end();
  117. }
  118. template <typename Container, typename Item>
  119. typename Container::iterator find(const Container & c, const Item &i)
  120. {
  121. return std::find(c.begin(),c.end(),i);
  122. }
  123. template <typename Container, typename Item>
  124. typename Container::iterator find(Container & c, const Item &i)
  125. {
  126. return std::find(c.begin(),c.end(),i);
  127. }
  128. template <typename Container, typename Item>
  129. bool operator-=(Container &c, const Item &i)
  130. {
  131. typename Container::iterator itr = find(c,i);
  132. if(itr == c.end())
  133. return false;
  134. c.erase(itr);
  135. return true;
  136. }
  137. }
  138. using vstd::operator-=;
  139. #endif //GLOBAL_H