2007-06-06 19:12:12 +03:00
|
|
|
#ifndef GLOBAL_H
|
|
|
|
#define GLOBAL_H
|
2008-07-09 20:22:28 +03:00
|
|
|
#include <iostream>
|
|
|
|
#include <boost/logic/tribool.hpp>
|
|
|
|
#include <boost/cstdint.hpp>
|
|
|
|
typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes)
|
|
|
|
typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes)
|
|
|
|
typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte)
|
|
|
|
typedef boost::int32_t si32; //signed int 32 bits (4 bytes)
|
|
|
|
typedef boost::int16_t si16; //signed int 16 bits (2 bytes)
|
|
|
|
typedef boost::int8_t si8; //signed int 8 bits (1 byte)
|
|
|
|
#include "int3.h"
|
2007-06-07 16:43:30 +03:00
|
|
|
#define CHECKTIME 1
|
|
|
|
#if CHECKTIME
|
|
|
|
#include "timeHandler.h"
|
|
|
|
#define THC
|
|
|
|
#endif
|
2008-07-03 18:03:32 +03:00
|
|
|
|
2008-09-23 13:58:54 +03:00
|
|
|
#define NAME_VER ("VCMI 0.62c")
|
2008-09-17 13:18:22 +03:00
|
|
|
#define CONSOLE_LOGGING_LEVEL 5
|
|
|
|
#define FILE_LOGGING_LEVEL 6
|
2008-08-02 18:08:03 +03:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define PATHSEPARATOR "\\"
|
|
|
|
#define DATA_DIR ""
|
2008-08-17 22:15:31 +03:00
|
|
|
#define SERVER_NAME "VCMI_server.exe"
|
2008-08-02 18:08:03 +03:00
|
|
|
#else
|
|
|
|
#define PATHSEPARATOR "/"
|
2008-08-17 22:15:31 +03:00
|
|
|
#define DATA_DIR ""
|
|
|
|
#define SERVER_NAME "./vcmiserver"
|
2008-08-02 18:08:03 +03:00
|
|
|
#endif
|
|
|
|
|
2007-08-06 16:09:41 +03:00
|
|
|
enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK}; //player's colors
|
2007-08-08 22:28:56 +03:00
|
|
|
enum EterrainType {border=-1, dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock};
|
2007-07-31 16:09:34 +03:00
|
|
|
enum Eriver {noRiver=0, clearRiver, icyRiver, muddyRiver, lavaRiver};
|
2007-06-18 23:05:42 +03:00
|
|
|
enum Eroad {dirtRoad=1, grazvelRoad, cobblestoneRoad};
|
2007-06-06 19:12:12 +03:00
|
|
|
enum Eformat { WoG=0x33, AB=0x15, RoE=0x0e, SoD=0x1c};
|
2008-08-02 18:08:03 +03:00
|
|
|
enum EvictoryConditions {artifact, gatherTroop, gatherResource, buildCity, buildGrail, beatHero,
|
2007-07-29 02:01:25 +03:00
|
|
|
captureCity, beatMonster, takeDwellings, takeMines, transportItem, winStandard=255};
|
2007-06-06 19:12:12 +03:00
|
|
|
enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255};
|
2008-08-02 18:08:03 +03:00
|
|
|
enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HERO_ALCHEMIST, HERO_WIZARD,
|
|
|
|
HERO_DEMONIAC, HERO_HERETIC, HERO_DEATHKNIGHT, HERO_NECROMANCER, HERO_WARLOCK, HERO_OVERLORD,
|
2007-07-29 02:01:25 +03:00
|
|
|
HERO_BARBARIAN, HERO_BATTLEMAGE, HERO_BEASTMASTER, HERO_WITCH, HERO_PLANESWALKER, HERO_ELEMENTALIST};
|
2008-09-12 11:51:46 +03:00
|
|
|
enum EAbilities {DOUBLE_WIDE, FLYING, SHOOTER, TWO_HEX_ATTACK, SIEGE_ABILITY, SIEGE_WEAPON,
|
|
|
|
KING1, KING2, KING3, MIND_IMMUNITY, NO_OBSTACLE_PENALTY, NO_CLOSE_COMBAT_PENALTY,
|
|
|
|
JOUSTING, FIRE_IMMUNITY, TWICE_ATTACK, NO_ENEMY_RETALIATION, NO_MORAL_PENALTY,
|
|
|
|
UNDEAD, MULTI_HEAD_ATTACK, EXTENDED_RADIOUS_SHOOTER, GHOST, RAISES_MORALE,
|
|
|
|
LOWERS_MORALE, DRAGON, STRIKE_AND_RETURN, FEARLESS, REBIRTH}; //some flags are used only for battles
|
|
|
|
enum ECombatInfo{ALIVE = REBIRTH+1, SUMMONED, CLONED, HAD_MORALE, WAITING, MOVED, DEFENDING};
|
2008-02-10 11:35:52 +02:00
|
|
|
class CGameInfo;
|
|
|
|
extern CGameInfo* CGI;
|
2007-08-06 07:03:34 +03:00
|
|
|
|
2008-08-28 20:36:34 +03:00
|
|
|
#define HEROI_TYPE (34)
|
|
|
|
#define TOWNI_TYPE (98)
|
2007-09-14 16:11:10 +03:00
|
|
|
|
2007-08-06 16:09:41 +03:00
|
|
|
const int F_NUMBER = 9; //factions (town types) quantity
|
2007-07-17 23:51:49 +03:00
|
|
|
const int PLAYER_LIMIT = 8; //player limit per map
|
2007-07-24 03:25:46 +03:00
|
|
|
const int HEROES_PER_TYPE=8; //amount of heroes of each type
|
2007-08-04 22:01:22 +03:00
|
|
|
const int SKILL_QUANTITY=28;
|
2008-05-03 18:30:11 +03:00
|
|
|
const int SKILL_PER_HERO=8;
|
2007-08-04 22:01:22 +03:00
|
|
|
const int ARTIFACTS_QUANTITY=171;
|
|
|
|
const int HEROES_QUANTITY=156;
|
2008-06-08 03:58:29 +03:00
|
|
|
const int SPELLS_QUANTITY=70;
|
2007-09-16 20:21:23 +03:00
|
|
|
const int RESOURCE_QUANTITY=8;
|
2007-08-20 00:12:55 +03:00
|
|
|
const int TERRAIN_TYPES=10;
|
2007-09-14 16:11:10 +03:00
|
|
|
const int PRIMARY_SKILLS=4;
|
2007-11-24 16:17:57 +02:00
|
|
|
const int NEUTRAL_PLAYER=255;
|
2007-09-16 20:21:23 +03:00
|
|
|
const int NAMES_PER_TOWN=16;
|
2008-01-09 21:59:23 +02:00
|
|
|
const int CREATURES_PER_TOWN = 7; //without upgrades
|
2008-01-12 13:32:40 +02:00
|
|
|
const int MAX_BUILDING_PER_TURN = 1;
|
2008-08-20 09:57:53 +03:00
|
|
|
const int SPELL_LEVELS = 5;
|
2007-09-16 20:21:23 +03:00
|
|
|
|
2007-08-11 17:58:07 +03:00
|
|
|
#define MARK_BLOCKED_POSITIONS false
|
|
|
|
#define MARK_VISITABLE_POSITIONS false
|
|
|
|
|
2007-06-06 19:12:12 +03:00
|
|
|
#define DEFBYPASS
|
2007-08-20 00:12:55 +03:00
|
|
|
|
2008-06-12 09:45:51 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
#ifdef VCMI_DLL
|
|
|
|
#define DLL_EXPORT __declspec(dllexport)
|
|
|
|
#else
|
|
|
|
#define DLL_EXPORT __declspec(dllimport)
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if defined(__GNUC__) && __GNUC__ >= 4
|
|
|
|
#define DLL_EXPORT __attribute__ ((visibility("default")))
|
|
|
|
#else
|
|
|
|
#define DLL_EXPORT
|
|
|
|
#endif
|
|
|
|
#endif
|
2008-02-10 11:35:52 +02:00
|
|
|
|
2008-08-09 02:02:32 +03:00
|
|
|
namespace vstd
|
|
|
|
{
|
|
|
|
template <typename Container, typename Item>
|
|
|
|
bool contains(const Container & c, const Item &i)
|
|
|
|
{
|
|
|
|
return std::find(c.begin(),c.end(),i) != c.end();
|
|
|
|
}
|
2008-09-12 11:51:46 +03:00
|
|
|
template <typename V, typename Item, typename Item2>
|
|
|
|
bool contains(const std::map<Item,V> & c, const Item2 &i)
|
2008-08-13 03:44:31 +03:00
|
|
|
{
|
|
|
|
return c.find(i)!=c.end();
|
|
|
|
}
|
2008-08-26 00:14:00 +03:00
|
|
|
template <typename Container1, typename Container2>
|
|
|
|
typename Container2::iterator findFirstNot(Container1 &c1, Container2 &c2)//returns first element of c2 not present in c1
|
|
|
|
{
|
|
|
|
typename Container2::iterator itr = c2.begin();
|
|
|
|
while(itr != c2.end())
|
|
|
|
if(!contains(c1,*itr))
|
|
|
|
return itr;
|
|
|
|
else
|
|
|
|
++itr;
|
|
|
|
return c2.end();
|
|
|
|
}
|
2008-08-09 02:02:32 +03:00
|
|
|
template <typename Container, typename Item>
|
|
|
|
typename Container::iterator find(const Container & c, const Item &i)
|
|
|
|
{
|
|
|
|
return std::find(c.begin(),c.end(),i);
|
|
|
|
}
|
2008-08-28 20:36:34 +03:00
|
|
|
template <typename T1, typename T2>
|
|
|
|
int findPos(const std::vector<T1> & c, const T2 &s)
|
|
|
|
{
|
|
|
|
for(int i=0;i<c.size();i++)
|
|
|
|
if(c[i] == s)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
template <typename T1, typename T2, typename Func>
|
2008-09-07 06:38:37 +03:00
|
|
|
int findPos(const std::vector<T1> & c, const T2 &s, const Func &f) //Func(T1,T2) must say if these elements matches
|
2008-08-28 20:36:34 +03:00
|
|
|
{
|
|
|
|
for(int i=0;i<c.size();i++)
|
|
|
|
if(f(c[i],s))
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
2008-08-13 07:41:11 +03:00
|
|
|
template <typename Container, typename Item>
|
|
|
|
typename Container::iterator find(Container & c, const Item &i)
|
|
|
|
{
|
|
|
|
return std::find(c.begin(),c.end(),i);
|
|
|
|
}
|
|
|
|
template <typename Container, typename Item>
|
|
|
|
bool operator-=(Container &c, const Item &i)
|
|
|
|
{
|
2008-08-17 17:09:30 +03:00
|
|
|
typename Container::iterator itr = find(c,i);
|
2008-08-13 07:41:11 +03:00
|
|
|
if(itr == c.end())
|
|
|
|
return false;
|
|
|
|
c.erase(itr);
|
|
|
|
return true;
|
|
|
|
}
|
2008-09-07 06:38:37 +03:00
|
|
|
template <typename t1>
|
|
|
|
void delObj(t1 *a1)
|
|
|
|
{
|
|
|
|
delete a1;
|
|
|
|
}
|
2008-08-28 20:36:34 +03:00
|
|
|
template <typename t1, typename t2>
|
|
|
|
void assign(t1 &a1, const t2 &a2)
|
|
|
|
{
|
|
|
|
a1 = a2;
|
|
|
|
}
|
2008-09-18 16:54:54 +03:00
|
|
|
template <typename t1, typename t2>
|
|
|
|
struct assigner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
t1 &op1;
|
|
|
|
t2 op2;
|
|
|
|
assigner(t1 &a1, t2 a2)
|
|
|
|
:op1(a1), op2(a2)
|
|
|
|
{}
|
|
|
|
void operator()()
|
|
|
|
{
|
|
|
|
op1 = op2;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <typename t1, typename t2>
|
|
|
|
assigner<t1,t2> assigno(t1 &a1, const t2 &a2)
|
|
|
|
{
|
|
|
|
return assigner<t1,t2>(a1,a2);
|
|
|
|
}
|
2008-08-28 20:36:34 +03:00
|
|
|
template <typename t1, typename t2, typename t3>
|
|
|
|
bool equal(const t1 &a1, const t3 t1::* point, const t2 &a2)
|
|
|
|
{
|
|
|
|
return a1.*point == a2;
|
|
|
|
}
|
|
|
|
template <typename t1, typename t2>
|
|
|
|
bool equal(const t1 &a1, const t2 &a2)
|
|
|
|
{
|
|
|
|
return a1 == a2;
|
|
|
|
}
|
2008-08-09 02:02:32 +03:00
|
|
|
}
|
2008-08-13 07:41:11 +03:00
|
|
|
using vstd::operator-=;
|
2008-09-17 13:18:22 +03:00
|
|
|
|
|
|
|
#include "CConsoleHandler.h"
|
2008-09-19 11:16:19 +03:00
|
|
|
extern DLL_EXPORT std::ostream *logfile;
|
|
|
|
extern DLL_EXPORT CConsoleHandler *console;
|
2008-09-17 13:18:22 +03:00
|
|
|
template <int lvl> class CLogger
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CLogger<lvl>& operator<<(std::ostream& (*fun)(std::ostream&))
|
|
|
|
{
|
|
|
|
if(lvl < CONSOLE_LOGGING_LEVEL)
|
|
|
|
std::cout << fun;
|
|
|
|
if((lvl < FILE_LOGGING_LEVEL) && logfile)
|
|
|
|
*logfile << fun;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
CLogger<lvl> & operator<<(const T & data)
|
|
|
|
{
|
|
|
|
if(lvl < CONSOLE_LOGGING_LEVEL)
|
|
|
|
if(console)
|
|
|
|
console->print(data,lvl);
|
|
|
|
else
|
|
|
|
std::cout << data << std::flush;
|
|
|
|
if((lvl < FILE_LOGGING_LEVEL) && logfile)
|
|
|
|
*logfile << data << std::flush;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-09-19 11:16:19 +03:00
|
|
|
extern DLL_EXPORT CLogger<0> tlog0; //green - standard progress info
|
|
|
|
extern DLL_EXPORT CLogger<1> tlog1; //red - big errors
|
|
|
|
extern DLL_EXPORT CLogger<2> tlog2; //magenta - major warnings
|
|
|
|
extern DLL_EXPORT CLogger<3> tlog3; //yellow - minor warnings
|
|
|
|
extern DLL_EXPORT CLogger<4> tlog4; //white - detailed log info
|
|
|
|
extern DLL_EXPORT CLogger<5> tlog5; //gray - minor log info
|
2008-09-17 13:18:22 +03:00
|
|
|
|
|
|
|
#define HANDLE_EXCEPTION \
|
|
|
|
catch (const std::exception& e) { \
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog1 << e.what() << std::endl; \
|
2008-09-17 13:18:22 +03:00
|
|
|
} \
|
|
|
|
catch (const std::exception * e) \
|
|
|
|
{ \
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog1 << e->what()<< std::endl; \
|
2008-09-17 13:18:22 +03:00
|
|
|
delete e; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define HANDLE_EXCEPTIONC(COMMAND) \
|
|
|
|
catch (const std::exception& e) { \
|
|
|
|
COMMAND; \
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog1 << e.what() << std::endl; \
|
2008-09-17 13:18:22 +03:00
|
|
|
} \
|
|
|
|
catch (const std::exception * e) \
|
|
|
|
{ \
|
|
|
|
COMMAND; \
|
2008-09-19 11:16:19 +03:00
|
|
|
tlog1 << e->what()<< std::endl; \
|
2008-09-17 13:18:22 +03:00
|
|
|
delete e; \
|
|
|
|
}
|
|
|
|
|
2008-08-02 18:08:03 +03:00
|
|
|
#endif //GLOBAL_H
|