global.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. #pragma once
  2. #ifndef __GLOBAL_H__
  3. #define __GLOBAL_H__
  4. #include <iostream>
  5. #include <algorithm> //std::find
  6. #include <string> //std::find
  7. #include <boost/logic/tribool.hpp>
  8. #include <boost/unordered_set.hpp>
  9. using boost::logic::tribool;
  10. #include <boost/cstdint.hpp>
  11. #include <assert.h>
  12. //filesystem version 3 causes problems (and it's default as of boost 1.46)
  13. #define BOOST_FILESYSTEM_VERSION 2
  14. typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes)
  15. typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes)
  16. typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes)
  17. typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte)
  18. typedef boost::int64_t si64; //signed int 64 bits (8 bytes)
  19. typedef boost::int32_t si32; //signed int 32 bits (4 bytes)
  20. typedef boost::int16_t si16; //signed int 16 bits (2 bytes)
  21. typedef boost::int8_t si8; //signed int 8 bits (1 byte)
  22. typedef si64 expType;
  23. typedef ui16 spelltype;
  24. typedef std::pair<ui32, ui32> TDmgRange;
  25. typedef ui8 TBonusType;
  26. typedef si32 TBonusSubtype;
  27. #include "int3.h"
  28. #include <map>
  29. #include <vector>
  30. #define CHECKTIME 1
  31. #if CHECKTIME
  32. #include "timeHandler.h"
  33. #define THC
  34. #endif
  35. #define NAME_VER ("VCMI 0.84")
  36. extern std::string NAME; //full name
  37. extern std::string NAME_AFFIX; //client / server
  38. #define CONSOLE_LOGGING_LEVEL 5
  39. #define FILE_LOGGING_LEVEL 6
  40. /*
  41. * DATA_DIR contains the game data (Data/, MP3/, ...).
  42. * USER_DIR is where to save games (Games/) and the config.
  43. * BIN_DIR is where the vcmiclient/vcmiserver binaries reside
  44. * LIB_DIR is where the AI libraries reside (linux only)
  45. */
  46. #ifdef _WIN32
  47. #define DATA_DIR "."
  48. #define USER_DIR "."
  49. #define BIN_DIR "."
  50. #define LIB_DIR "AI"
  51. #define SERVER_NAME "VCMI_server.exe"
  52. #else
  53. #ifndef DATA_DIR
  54. #error DATA_DIR undefined.
  55. #endif
  56. #ifndef BIN_DIR
  57. #error BIN_DIR undefined.
  58. #endif
  59. #ifndef LIB_DIR
  60. #error LIB_DIR undefined.
  61. #endif
  62. #define SERVER_NAME "vcmiserver"
  63. #endif
  64. #ifdef _WIN32
  65. #define PATH_SEPARATOR "\\"
  66. #else
  67. #define PATH_SEPARATOR "/"
  68. #endif
  69. /*
  70. * global.h, part of VCMI engine
  71. *
  72. * Authors: listed in file AUTHORS in main folder
  73. *
  74. * License: GNU General Public License v2.0 or later
  75. * Full text of license available in license.txt file, in main folder
  76. *
  77. */
  78. enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK}; //player's colors
  79. enum EvictoryConditions {artifact, gatherTroop, gatherResource, buildCity, buildGrail, beatHero,
  80. captureCity, beatMonster, takeDwellings, takeMines, transportItem, winStandard=255};
  81. enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255};
  82. enum ECombatInfo{ALIVE = 180, SUMMONED, CLONED, HAD_MORALE, WAITING, MOVED, DEFENDING};
  83. class CGameInfo;
  84. extern const CGameInfo* CGI; //game info for general use
  85. class CClientState;
  86. extern CClientState * CCS;
  87. //a few typedefs for CCreatureSet
  88. typedef si32 TSlot;
  89. typedef si32 TQuantity;
  90. typedef ui32 TCreature; //creature id
  91. const int ARMY_SIZE = 7;
  92. const int HEROI_TYPE = 34,
  93. TOWNI_TYPE = 98,
  94. CREI_TYPE = 54,
  95. EVENTI_TYPE = 26;
  96. const int CREATURES_COUNT = 197;
  97. const int CRE_LEVELS = 10;
  98. const int F_NUMBER = 9; //factions (town types) quantity
  99. const int PLAYER_LIMIT = 8; //player limit per map
  100. const int ALL_PLAYERS = 255; //bitfield
  101. const int HEROES_PER_TYPE=8; //amount of heroes of each type
  102. const int SKILL_QUANTITY=28;
  103. const int SKILL_PER_HERO=8;
  104. const int ARTIFACTS_QUANTITY=171;
  105. const int HEROES_QUANTITY=156;
  106. const int SPELLS_QUANTITY=70;
  107. const int RESOURCE_QUANTITY=8;
  108. const int TERRAIN_TYPES=10;
  109. const int PRIMARY_SKILLS=4;
  110. const int NEUTRAL_PLAYER=255;
  111. const int NAMES_PER_TOWN=16;
  112. const int CREATURES_PER_TOWN = 7; //without upgrades
  113. const int MAX_BUILDING_PER_TURN = 1;
  114. const int SPELL_LEVELS = 5;
  115. //const int CREEP_SIZE = 4000; // neutral stacks won't grow beyond this number
  116. const int CREEP_SIZE = 2000000000;
  117. const int WEEKLY_GROWTH = 10; //percent
  118. const int AVAILABLE_HEROES_PER_PLAYER = 2;
  119. const bool DWELLINGS_ACCUMULATE_CREATURES = true;
  120. const bool STACK_EXP = false;
  121. const int BFIELD_WIDTH = 17;
  122. const int BFIELD_HEIGHT = 11;
  123. const int BFIELD_SIZE = BFIELD_WIDTH * BFIELD_HEIGHT;
  124. const int SPELLBOOK_GOLD_COST = 500;
  125. //for battle stacks' positions
  126. struct THex
  127. {
  128. static const si16 INVALID = -1;
  129. enum EDir{RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT, LEFT, TOP_LEFT, TOP_RIGHT};
  130. si16 hex;
  131. THex() : hex(INVALID) {}
  132. THex(si16 _hex) : hex(_hex)
  133. {
  134. //assert(isValid());
  135. }
  136. operator si16() const
  137. {
  138. return hex;
  139. }
  140. bool isValid() const
  141. {
  142. return hex >= 0 && hex < BFIELD_SIZE;
  143. }
  144. template<typename inttype>
  145. THex(inttype x, inttype y)
  146. {
  147. setXY(x, y);
  148. }
  149. template<typename inttype>
  150. THex(std::pair<inttype, inttype> xy)
  151. {
  152. setXY(xy);
  153. }
  154. template<typename inttype>
  155. void setX(inttype x)
  156. {
  157. setXY(x, getY());
  158. }
  159. template<typename inttype>
  160. void setY(inttype y)
  161. {
  162. setXY(getX(), y);
  163. }
  164. void setXY(si16 x, si16 y)
  165. {
  166. assert(x >= 0 && x < BFIELD_WIDTH && y >= 0 && y < BFIELD_HEIGHT);
  167. hex = x + y * BFIELD_WIDTH;
  168. }
  169. template<typename inttype>
  170. void setXY(std::pair<inttype, inttype> xy)
  171. {
  172. setXY(xy.first, xy.second);
  173. }
  174. si16 getY() const
  175. {
  176. return hex/BFIELD_WIDTH;
  177. }
  178. si16 getX() const
  179. {
  180. int pos = hex - getY() * BFIELD_WIDTH;
  181. return pos;
  182. }
  183. std::pair<si16, si16> getXY() const
  184. {
  185. return std::make_pair(getX(), getY());
  186. }
  187. //moving to direction
  188. void operator+=(EDir dir)
  189. {
  190. si16 x = getX(),
  191. y = getY();
  192. switch(dir)
  193. {
  194. case TOP_LEFT:
  195. setXY(y%2 ? x-1 : x, y-1);
  196. break;
  197. case TOP_RIGHT:
  198. setXY(y%2 ? x : x+1, y-1);
  199. break;
  200. case RIGHT:
  201. setXY(x+1, y);
  202. break;
  203. case BOTTOM_RIGHT:
  204. setXY(y%2 ? x : x+1, y+1);
  205. break;
  206. case BOTTOM_LEFT:
  207. setXY(y%2 ? x-1 : x, y+1);
  208. break;
  209. case LEFT:
  210. setXY(x-1, y);
  211. break;
  212. default:
  213. throw std::string("Disaster: wrong direction in THex::operator+=!\n");
  214. break;
  215. }
  216. }
  217. //generates new THex moved by given dir
  218. THex operator+(EDir dir) const
  219. {
  220. THex ret(*this);
  221. ret += dir;
  222. return ret;
  223. }
  224. std::vector<THex> neighbouringTiles() const
  225. {
  226. std::vector<THex> ret;
  227. const int WN = BFIELD_WIDTH;
  228. checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), ret);
  229. checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), ret);
  230. checkAndPush(hex - 1, ret);
  231. checkAndPush(hex + 1, ret);
  232. checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), ret);
  233. checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), ret);
  234. return ret;
  235. }
  236. //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)
  237. static signed char mutualPosition(THex hex1, THex hex2)
  238. {
  239. if(hex2 == hex1 - ( (hex1/17)%2 ? 18 : 17 )) //top left
  240. return 0;
  241. if(hex2 == hex1 - ( (hex1/17)%2 ? 17 : 16 )) //top right
  242. return 1;
  243. if(hex2 == hex1 - 1 && hex1%17 != 0) //left
  244. return 5;
  245. if(hex2 == hex1 + 1 && hex1%17 != 16) //right
  246. return 2;
  247. if(hex2 == hex1 + ( (hex1/17)%2 ? 16 : 17 )) //bottom left
  248. return 4;
  249. if(hex2 == hex1 + ( (hex1/17)%2 ? 17 : 18 )) //bottom right
  250. return 3;
  251. return -1;
  252. }
  253. //returns distance between given hexes
  254. static si8 getDistance(THex hex1, THex hex2)
  255. {
  256. int xDst = std::abs(hex1 % BFIELD_WIDTH - hex2 % BFIELD_WIDTH),
  257. yDst = std::abs(hex1 / BFIELD_WIDTH - hex2 / BFIELD_WIDTH);
  258. return std::max(xDst, yDst) + std::min(xDst, yDst) - (yDst + 1)/2;
  259. }
  260. template <typename Handler> void serialize(Handler &h, const int version)
  261. {
  262. h & hex;
  263. }
  264. private:
  265. static void checkAndPush(int tile, std::vector<THex> & ret)
  266. {
  267. if( tile>=0 && tile<BFIELD_SIZE && (tile%BFIELD_WIDTH != (BFIELD_WIDTH - 1)) && (tile%BFIELD_WIDTH != 0) )
  268. ret.push_back(THex(tile));
  269. }
  270. };
  271. enum EMarketMode
  272. {
  273. RESOURCE_RESOURCE, RESOURCE_PLAYER, CREATURE_RESOURCE, RESOURCE_ARTIFACT,
  274. ARTIFACT_RESOURCE, ARTIFACT_EXP, CREATURE_EXP, CREATURE_UNDEAD, RESOURCE_SKILL,
  275. MARTKET_AFTER_LAST_PLACEHOLDER
  276. };
  277. namespace SpellCasting
  278. {
  279. enum ESpellCastProblem
  280. {
  281. OK, NO_HERO_TO_CAST_SPELL, ALREADY_CASTED_THIS_TURN, NO_SPELLBOOK, ANOTHER_ELEMENTAL_SUMMONED,
  282. HERO_DOESNT_KNOW_SPELL, NOT_ENOUGH_MANA, ADVMAP_SPELL_INSTEAD_OF_BATTLE_SPELL,
  283. SECOND_HEROS_SPELL_IMMUNITY, SPELL_LEVEL_LIMIT_EXCEEDED, NO_SPELLS_TO_DISPEL,
  284. NO_APPROPRIATE_TARGET, STACK_IMMUNE_TO_SPELL, WRONG_SPELL_TARGET
  285. };
  286. enum ECastingMode {HERO_CASTING, AFTER_ATTACK_CASTING};
  287. }
  288. namespace Res
  289. {
  290. enum ERes
  291. {
  292. WOOD = 0, MERCURY, ORE, SULFUR, CRYSTAL, GEMS, GOLD, MITHRIL
  293. };
  294. }
  295. namespace Arts
  296. {
  297. enum EPos
  298. {
  299. PRE_FIRST = -1,
  300. HEAD, SHOULDERS, NECK, RIGHT_HAND, LEFT_HAND, TORSO, RIGHT_RING, LEFT_RING, FEET, MISC1, MISC2, MISC3, MISC4,
  301. MACH1, MACH2, MACH3, MACH4, SPELLBOOK, MISC5,
  302. AFTER_LAST
  303. };
  304. const ui16 BACKPACK_START = 19;
  305. const int ID_CATAPULT = 3, ID_LOCK = 145;
  306. }
  307. enum EAlignment
  308. {
  309. GOOD, EVIL, NEUTRAL
  310. };
  311. //uncomment to make it work
  312. //#define MARK_BLOCKED_POSITIONS
  313. //#define MARK_VISITABLE_POSITIONS
  314. #define DEFBYPASS
  315. #ifdef _WIN32
  316. #define DLL_F_EXPORT __declspec(dllexport)
  317. #else
  318. #if defined(__GNUC__) && __GNUC__ >= 4
  319. #define DLL_F_EXPORT __attribute__ ((visibility("default")))
  320. #else
  321. #define DLL_F_EXPORT
  322. #endif
  323. #endif
  324. #ifdef _WIN32
  325. #define DLL_F_IMPORT __declspec(dllimport)
  326. #else
  327. #if defined(__GNUC__) && __GNUC__ >= 4
  328. #define DLL_F_IMPORT __attribute__ ((visibility("default")))
  329. #else
  330. #define DLL_F_IMPORT
  331. #endif
  332. #endif
  333. #ifdef VCMI_DLL
  334. #define DLL_EXPORT DLL_F_EXPORT
  335. #else
  336. #define DLL_EXPORT DLL_F_IMPORT
  337. #endif
  338. template<typename T, size_t N> char (&_ArrayCountObj(const T (&)[N]))[N];
  339. #define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr)))
  340. //a normal std::map with consted operator[] for sanity
  341. template<typename KeyT, typename ValT>
  342. class bmap : public std::map<KeyT, ValT>
  343. {
  344. public:
  345. const ValT & operator[](KeyT key) const
  346. {
  347. return find(key)->second;
  348. }
  349. ValT & operator[](KeyT key)
  350. {
  351. return static_cast<std::map<KeyT, ValT> &>(*this)[key];
  352. }
  353. template <typename Handler> void serialize(Handler &h, const int version)
  354. {
  355. h & static_cast<std::map<KeyT, ValT> &>(*this);
  356. }
  357. };
  358. namespace vstd
  359. {
  360. template <typename Container, typename Item>
  361. bool contains(const Container & c, const Item &i) //returns true if container c contains item i
  362. {
  363. return std::find(c.begin(),c.end(),i) != c.end();
  364. }
  365. template <typename V, typename Item, typename Item2>
  366. bool contains(const std::map<Item,V> & c, const Item2 &i) //returns true if map c contains item i
  367. {
  368. return c.find(i)!=c.end();
  369. }
  370. template <typename V, typename Item, typename Item2>
  371. bool contains(const bmap<Item,V> & c, const Item2 &i) //returns true if bmap c contains item i
  372. {
  373. return c.find(i)!=c.end();
  374. }
  375. template <typename Item>
  376. bool contains(const boost::unordered_set<Item> & c, const Item &i) //returns true if unordered set c contains item i
  377. {
  378. return c.find(i)!=c.end();
  379. }
  380. template <typename Item, size_t N>
  381. bool contains(const Item (&c)[N], const Item &i) //returns true if given array contains item i
  382. {
  383. return std::find(c, c+N, i) != c+N; //TODO: find out why template is not resolved
  384. }
  385. template <typename Container1, typename Container2>
  386. typename Container2::iterator findFirstNot(Container1 &c1, Container2 &c2)//returns first element of c2 not present in c1
  387. {
  388. typename Container2::iterator itr = c2.begin();
  389. while(itr != c2.end())
  390. if(!contains(c1,*itr))
  391. return itr;
  392. else
  393. ++itr;
  394. return c2.end();
  395. }
  396. template <typename Container1, typename Container2>
  397. typename Container2::const_iterator findFirstNot(const Container1 &c1, const Container2 &c2)//returns const first element of c2 not present in c1
  398. {
  399. typename Container2::const_iterator itr = c2.begin();
  400. while(itr != c2.end())
  401. if(!contains(c1,*itr))
  402. return itr;
  403. else
  404. ++itr;
  405. return c2.end();
  406. }
  407. template <typename Container, typename Item>
  408. typename Container::iterator find(const Container & c, const Item &i)
  409. {
  410. return std::find(c.begin(),c.end(),i);
  411. }
  412. template <typename T1, typename T2>
  413. int findPos(const std::vector<T1> & c, const T2 &s) //returns position of first element in vector c equal to s, if there is no such element, -1 is returned
  414. {
  415. for(size_t i=0; i < c.size(); ++i)
  416. if(c[i] == s)
  417. return i;
  418. return -1;
  419. }
  420. template <typename T1, typename T2, typename Func>
  421. int findPos(const std::vector<T1> & c, const T2 &s, const Func &f) //Func(T1,T2) must say if these elements matches
  422. {
  423. for(size_t i=0; i < c.size(); ++i)
  424. if(f(c[i],s))
  425. return i;
  426. return -1;
  427. }
  428. template <typename Container, typename Item>
  429. typename Container::iterator find(Container & c, const Item &i) //returns iterator to the given element if present in container, end() if not
  430. {
  431. return std::find(c.begin(),c.end(),i);
  432. }
  433. template <typename Container, typename Item>
  434. typename Container::const_iterator find(const Container & c, const Item &i)//returns const iterator to the given element if present in container, end() if not
  435. {
  436. return std::find(c.begin(),c.end(),i);
  437. }
  438. template <typename Container, typename Item>
  439. typename Container::size_type operator-=(Container &c, const Item &i) //removes element i from container c, returns false if c does not contain i
  440. {
  441. typename Container::iterator itr = find(c,i);
  442. if(itr == c.end())
  443. return false;
  444. c.erase(itr);
  445. return true;
  446. }
  447. template <typename t1>
  448. void delObj(t1 *a1)
  449. {
  450. delete a1;
  451. }
  452. template <typename t1, typename t2>
  453. void assign(t1 &a1, const t2 &a2)
  454. {
  455. a1 = a2;
  456. }
  457. template <typename t1, typename t2>
  458. struct assigner
  459. {
  460. public:
  461. t1 &op1;
  462. t2 op2;
  463. assigner(t1 &a1, const t2 & a2)
  464. :op1(a1), op2(a2)
  465. {}
  466. void operator()()
  467. {
  468. op1 = op2;
  469. }
  470. };
  471. template <typename t1, typename t2>
  472. assigner<t1,t2> assigno(t1 &a1, const t2 &a2)
  473. {
  474. return assigner<t1,t2>(a1,a2);
  475. }
  476. template <typename t1, typename t2, typename t3>
  477. bool equal(const t1 &a1, const t3 t1::* point, const t2 &a2)
  478. {
  479. return a1.*point == a2;
  480. }
  481. template <typename t1, typename t2>
  482. bool equal(const t1 &a1, const t2 &a2)
  483. {
  484. return a1 == a2;
  485. }
  486. }
  487. using vstd::operator-=;
  488. template <typename t1, typename t2>
  489. t1 & amax(t1 &a, const t2 &b) //assigns greater of (a, b) to a and returns maximum of (a, b)
  490. {
  491. if(a >= b)
  492. return a;
  493. else
  494. {
  495. a = b;
  496. return a;
  497. }
  498. }
  499. template <typename t1, typename t2>
  500. t1 & amin(t1 &a, const t2 &b) //assigns smaller of (a, b) to a and returns minimum of (a, b)
  501. {
  502. if(a <= b)
  503. return a;
  504. else
  505. {
  506. a = b;
  507. return a;
  508. }
  509. }
  510. template <typename t1, typename t2, typename t3>
  511. t1 & abetw(t1 &a, const t2 &b, const t3 &c) //makes a to fit the range <b, c>
  512. {
  513. amax(a,b);
  514. amin(a,c);
  515. return a;
  516. }
  517. template <typename t1, typename t2, typename t3>
  518. bool isbetw(const t1 &a, const t2 &b, const t3 &c) //checks if a is between b and c
  519. {
  520. return a > b && a < c;
  521. }
  522. template <typename t1, typename t2, typename t3>
  523. bool iswith(const t1 &a, const t2 &b, const t3 &c) //checks if a is within b and c
  524. {
  525. return a >= b && a <= c;
  526. }
  527. template <typename T>
  528. void delNull(T* &ptr) //deleted pointer and sets it to NULL
  529. {
  530. delete ptr;
  531. ptr = NULL;
  532. }
  533. #include "CConsoleHandler.h"
  534. extern DLL_EXPORT std::ostream *logfile;
  535. extern DLL_EXPORT CConsoleHandler *console;
  536. class CLogger //logger, prints log info to console and saves in file
  537. {
  538. const int lvl;
  539. public:
  540. CLogger& operator<<(std::ostream& (*fun)(std::ostream&))
  541. {
  542. if(lvl < CONSOLE_LOGGING_LEVEL)
  543. std::cout << fun;
  544. if((lvl < FILE_LOGGING_LEVEL) && logfile)
  545. *logfile << fun;
  546. return *this;
  547. }
  548. template<typename T>
  549. CLogger & operator<<(const T & data)
  550. {
  551. if(lvl < CONSOLE_LOGGING_LEVEL)
  552. {
  553. if(console)
  554. console->print(data,lvl);
  555. else
  556. std::cout << data << std::flush;
  557. }
  558. if((lvl < FILE_LOGGING_LEVEL) && logfile)
  559. *logfile << data << std::flush;
  560. return *this;
  561. }
  562. CLogger(const int Lvl) : lvl(Lvl) {}
  563. };
  564. extern DLL_EXPORT CLogger tlog0; //green - standard progress info
  565. extern DLL_EXPORT CLogger tlog1; //red - big errors
  566. extern DLL_EXPORT CLogger tlog2; //magenta - major warnings
  567. extern DLL_EXPORT CLogger tlog3; //yellow - minor warnings
  568. extern DLL_EXPORT CLogger tlog4; //white - detailed log info
  569. extern DLL_EXPORT CLogger tlog5; //gray - minor log info
  570. extern DLL_EXPORT CLogger tlog6; //teal - AI info
  571. //XXX pls dont - 'debug macros' are usually more trouble than it's worth
  572. #define HANDLE_EXCEPTION \
  573. catch (const std::exception& e) { \
  574. tlog1 << e.what() << std::endl; \
  575. throw; \
  576. } \
  577. catch (const std::exception * e) \
  578. { \
  579. tlog1 << e->what()<< std::endl; \
  580. throw; \
  581. } \
  582. catch (const std::string& e) { \
  583. tlog1 << e << std::endl; \
  584. throw; \
  585. }
  586. #define HANDLE_EXCEPTIONC(COMMAND) \
  587. catch (const std::exception& e) { \
  588. COMMAND; \
  589. tlog1 << e.what() << std::endl; \
  590. throw; \
  591. } \
  592. catch (const std::string &e) \
  593. { \
  594. COMMAND; \
  595. tlog1 << e << std::endl; \
  596. throw; \
  597. }
  598. #if defined(linux) && defined(sparc)
  599. /* SPARC does not support unaligned memory access. Let gcc know when
  600. * to emit the right code. */
  601. struct unaligned_Uint16 { ui16 val __attribute__(( packed )); };
  602. struct unaligned_Uint32 { ui32 val __attribute__(( packed )); };
  603. static inline ui16 read_unaligned_u16(const void *p)
  604. {
  605. const struct unaligned_Uint16 *v = (const struct unaligned_Uint16 *)p;
  606. return v->val;
  607. }
  608. static inline ui32 read_unaligned_u32(const void *p)
  609. {
  610. const struct unaligned_Uint32 *v = (const struct unaligned_Uint32 *)p;
  611. return v->val;
  612. }
  613. #else
  614. #define read_unaligned_u16(p) (* reinterpret_cast<const Uint16 *>(p))
  615. #define read_unaligned_u32(p) (* reinterpret_cast<const Uint32 *>(p))
  616. #endif
  617. //for explicit overrides
  618. #ifdef _MSC_VER
  619. #define OVERRIDE override
  620. #else
  621. #define OVERRIDE //is there any working counterpart?
  622. #endif
  623. #define BONUS_TREE_DESERIALIZATION_FIX if(!h.saving && h.smartPointerSerialization) deserializationFix();
  624. #endif // __GLOBAL_H__