1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

[PLATFORM] MinGW support added

* disabled features unsupported by MinGW
* fixed issues with DLL_LINKAGE
! BOOST_THREAD_VERSION in now 3 workaround for existing code added, consider refactoring.
* some small tweaks ("-fpedantic" warnings)
This commit is contained in:
alexvins 2012-09-15 19:16:16 +00:00
parent 7087be1f02
commit 369f0ae9c6
19 changed files with 259 additions and 236 deletions

View File

@ -51,6 +51,9 @@
//The only available version is 3, as of Boost 1.50 //The only available version is 3, as of Boost 1.50
#define BOOST_FILESYSTEM_VERSION 3 #define BOOST_FILESYSTEM_VERSION 3
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_DONT_PROVIDE_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE 1
//#define BOOST_SYSTEM_NO_DEPRECATED 1
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -97,7 +100,11 @@ typedef boost::int8_t si8; //signed int 8 bits (1 byte)
// Import + Export macro declarations // Import + Export macro declarations
#ifdef _WIN32 #ifdef _WIN32
#ifdef __GNUC__
#define DLL_EXPORT __attribute__((dllexport))
#else
#define DLL_EXPORT __declspec(dllexport) #define DLL_EXPORT __declspec(dllexport)
#endif
#else #else
#if defined(__GNUC__) && GCC_VERSION >= 400 #if defined(__GNUC__) && GCC_VERSION >= 400
#define DLL_EXPORT __attribute__ ((visibility("default"))) #define DLL_EXPORT __attribute__ ((visibility("default")))
@ -107,7 +114,11 @@ typedef boost::int8_t si8; //signed int 8 bits (1 byte)
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef __GNUC__
#define DLL_IMPORT __attribute__((dllimport))
#else
#define DLL_IMPORT __declspec(dllimport) #define DLL_IMPORT __declspec(dllimport)
#endif
#else #else
#if defined(__GNUC__) && GCC_VERSION >= 400 #if defined(__GNUC__) && GCC_VERSION >= 400
#define DLL_IMPORT __attribute__ ((visibility("default"))) #define DLL_IMPORT __attribute__ ((visibility("default")))

View File

@ -29,7 +29,7 @@ struct BattleResult;
struct BattleSpellCast; struct BattleSpellCast;
struct CObstacleInstance; struct CObstacleInstance;
template <typename T> struct CondSh; template <typename T> struct CondSh;
struct SetStackEffect;; struct SetStackEffect;
struct BattleAction; struct BattleAction;
class CGTownInstance; class CGTownInstance;
struct CatapultAttack; struct CatapultAttack;

View File

@ -27,4 +27,4 @@ namespace BitmapHandler
SDL_Surface * loadBitmapFromDir(std::string path, std::string fname, bool setKey=true); SDL_Surface * loadBitmapFromDir(std::string path, std::string fname, bool setKey=true);
//Load file from any LODs //Load file from any LODs
SDL_Surface * loadBitmap(std::string fname, bool setKey=true); SDL_Surface * loadBitmap(std::string fname, bool setKey=true);
}; }

View File

@ -351,7 +351,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const BMPPal
Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.unused); Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.unused);
SDL_SetColorKey(ret, SDL_SRCCOLORKEY, keycol); SDL_SetColorKey(ret, SDL_SRCCOLORKEY, keycol);
return ret; return ret;
}; }
CDefEssential * CDefHandler::essentialize() CDefEssential * CDefHandler::essentialize()
{ {

View File

@ -7,7 +7,7 @@
#include "UIFramework/CIntObject.h" #include "UIFramework/CIntObject.h"
#ifdef __GNUC__ #ifdef __GNUC__
#define sprintf_s snprintf #define sprintf_s snprintf
#endif #endif
#ifdef max #ifdef max
@ -69,9 +69,9 @@ namespace boost
{ {
class mutex; class mutex;
class recursive_mutex; class recursive_mutex;
}; }
enum enum
{ {
/*CHANGE_SCREEN_RESOLUTION = 1,*/ /*CHANGE_SCREEN_RESOLUTION = 1,*/
RETURN_TO_MAIN_MENU = 2, RETURN_TO_MAIN_MENU = 2,
@ -100,7 +100,7 @@ public:
CCastleInterface * castleInt; //NULL if castle window isn't opened CCastleInterface * castleInt; //NULL if castle window isn't opened
static CBattleInterface * battleInt; //NULL if no battle static CBattleInterface * battleInt; //NULL if no battle
CInGameConsole * cingconsole; CInGameConsole * cingconsole;
CCallback * cb; //to communicate with engine CCallback * cb; //to communicate with engine
const BattleAction *curAction; //during the battle - action currently performed by active stack (or NULL) const BattleAction *curAction; //during the battle - action currently performed by active stack (or NULL)
@ -155,7 +155,7 @@ public:
void receivedResource(int type, int val) OVERRIDE; void receivedResource(int type, int val) OVERRIDE;
void showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID) OVERRIDE; void showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID) OVERRIDE;
void showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level) OVERRIDE; void showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level) OVERRIDE;
void showShipyardDialog(const IShipyard *obj) OVERRIDE; //obj may be town or shipyard; void showShipyardDialog(const IShipyard *obj) OVERRIDE; //obj may be town or shipyard;
void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel) OVERRIDE; //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID. void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel) OVERRIDE; //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, int queryID) OVERRIDE; void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, int queryID) OVERRIDE;
void showPuzzleMap() OVERRIDE; void showPuzzleMap() OVERRIDE;
@ -234,7 +234,7 @@ public:
CGPath *getAndVerifyPath( const CGHeroInstance * h ); CGPath *getAndVerifyPath( const CGHeroInstance * h );
void acceptTurn(); //used during hot seat after your turn message is close void acceptTurn(); //used during hot seat after your turn message is close
void tryDiggging(const CGHeroInstance *h); void tryDiggging(const CGHeroInstance *h);
void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard; void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard;
void requestReturningToMainMenu(); void requestReturningToMainMenu();
void requestStoppingClient(); void requestStoppingClient();
void sendCustomEvent(int code); void sendCustomEvent(int code);

View File

@ -124,7 +124,7 @@ public:
CPicture *playerListBg; CPicture *playerListBg;
CHighlightableButtonsGroup *difficulty; CHighlightableButtonsGroup *difficulty;
CDefHandler *sizes, *sFlags;; CDefHandler *sizes, *sFlags;
void changeSelection(const CMapInfo *to); void changeSelection(const CMapInfo *to);
void showAll(SDL_Surface * to); void showAll(SDL_Surface * to);

View File

@ -47,7 +47,7 @@ void checkForError(bool throwing = true)
void blitBuffer(char *buffer, int x, int y, int w, int h, SDL_Surface *dst) void blitBuffer(char *buffer, int x, int y, int w, int h, SDL_Surface *dst)
{ {
const int bpp = dst->format->BytesPerPixel; const int bpp = dst->format->BytesPerPixel;
char *dest; char *dest;
for(int i = h; i > 0; i--) for(int i = h; i > 0; i--)
{ {
@ -142,10 +142,13 @@ bool CBIKHandler::open(std::string name)
tlog1 << "BIK handler: failed to open " << name << std::endl; tlog1 << "BIK handler: failed to open " << name << std::endl;
goto checkErrorAndClean; goto checkErrorAndClean;
} }
//GCC wants scope of waveout to dont cross labels/swith/goto
{
void *waveout = GetProcAddress(dll,"_BinkOpenWaveOut@4");
if(waveout)
binkSetSoundSystem(waveout,NULL);
void *waveout = GetProcAddress(dll,"_BinkOpenWaveOut@4"); }
if(waveout)
binkSetSoundSystem(waveout,NULL);
hBink = binkOpen(hBinkFile, 0x8a800000); hBink = binkOpen(hBinkFile, 0x8a800000);
if(!hBink) if(!hBink)
@ -166,8 +169,8 @@ checkErrorAndClean:
void CBIKHandler::show( int x, int y, SDL_Surface *dst, bool update ) void CBIKHandler::show( int x, int y, SDL_Surface *dst, bool update )
{ {
const int w = hBink->width, const int w = hBink->width,
h = hBink->height, h = hBink->height,
Bpp = dst->format->BytesPerPixel; Bpp = dst->format->BytesPerPixel;
int mode = -1; int mode = -1;
@ -298,7 +301,7 @@ bool CSmackPlayer::open( std::string name )
Uint32 flags[2] = {0xff400, 0xfe400}; Uint32 flags[2] = {0xff400, 0xfe400};
data = ptrSmackOpen( (void*)name.c_str(), flags[1], -1); data = ptrSmackOpen( (void*)name.c_str(), flags[1], -1);
if (!data) if (!data)
{ {
tlog1 << "Smack cannot open " << name << std::endl; tlog1 << "Smack cannot open " << name << std::endl;
checkForError(); checkForError();
@ -337,9 +340,9 @@ void CSmackPlayer::redraw( int x, int y, SDL_Surface *dst, bool update )
{ {
int w = std::min<int>(data->width, dst->w - x), h = std::min<int>(data->height, dst->h - y); int w = std::min<int>(data->width, dst->w - x), h = std::min<int>(data->height, dst->h - y);
/* Lock the screen for direct access to the pixels */ /* Lock the screen for direct access to the pixels */
if ( SDL_MUSTLOCK(dst) ) if ( SDL_MUSTLOCK(dst) )
{ {
if ( SDL_LockSurface(dst) < 0 ) if ( SDL_LockSurface(dst) < 0 )
{ {
fprintf(stderr, "Can't lock screen: %s\n", SDL_GetError()); fprintf(stderr, "Can't lock screen: %s\n", SDL_GetError());
return; return;
@ -374,7 +377,7 @@ void CSmackPlayer::redraw( int x, int y, SDL_Surface *dst, bool update )
//convert rgb 555 to 565 //convert rgb 555 to 565
Uint16 pixel = *addr; Uint16 pixel = *addr;
Uint16 *p = (Uint16 *)((Uint8 *)dst->pixels + (j+y) * dst->pitch + (i + x) * dst->format->BytesPerPixel); Uint16 *p = (Uint16 *)((Uint8 *)dst->pixels + (j+y) * dst->pitch + (i + x) * dst->format->BytesPerPixel);
*p = (pixel & 0x1F) *p = (pixel & 0x1F)
+ ((pixel & 0x3e0) << 1) + ((pixel & 0x3e0) << 1)
+ ((pixel & 0x7c00) << 1); + ((pixel & 0x7c00) << 1);
@ -383,7 +386,7 @@ void CSmackPlayer::redraw( int x, int y, SDL_Surface *dst, bool update )
} }
} }
if ( SDL_MUSTLOCK(dst) ) if ( SDL_MUSTLOCK(dst) )
{ {
SDL_UnlockSurface(dst); SDL_UnlockSurface(dst);
} }
@ -425,7 +428,7 @@ bool CVideoPlayer::open(std::string name)
out.exceptions(std::ifstream::failbit | std::ifstream::badbit); out.exceptions(std::ifstream::failbit | std::ifstream::badbit);
out.write(data.get(), myVideo->getSize()); out.write(data.get(), myVideo->getSize());
} }
current->open(name); current->open(name);
return true; return true;
} }
@ -526,7 +529,7 @@ void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, boo
if(!w) if(!w)
{ {
show(x,y,dst,update); show(x,y,dst,update);
} }
@ -700,7 +703,7 @@ bool CVideoPlayer::open(std::string fname)
bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay) bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay)
{ {
close(); close();
this->fname = fname; this->fname = fname;
offset = 0; offset = 0;
refreshWait = 3; refreshWait = 3;
@ -790,7 +793,7 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay)
// Unsupported codec // Unsupported codec
return false; return false;
} }
// Open codec // Open codec
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 6, 0) #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 6, 0)
if ( avcodec_open(codecContext, codec) < 0 ) if ( avcodec_open(codecContext, codec) < 0 )
@ -802,7 +805,7 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay)
codec = NULL; codec = NULL;
return false; return false;
} }
// Allocate video frame // Allocate video frame
frame = avcodec_alloc_frame(); frame = avcodec_alloc_frame();
@ -826,8 +829,8 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay)
// Convert the image into YUV format that SDL uses // Convert the image into YUV format that SDL uses
if (overlay) if (overlay)
{ {
sws = sws_getContext(codecContext->width, codecContext->height, sws = sws_getContext(codecContext->width, codecContext->height,
codecContext->pix_fmt, codecContext->width, codecContext->height, codecContext->pix_fmt, codecContext->width, codecContext->height,
PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL); PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
} }
else else
@ -842,8 +845,8 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay)
default: return false; default: return false;
} }
sws = sws_getContext(codecContext->width, codecContext->height, sws = sws_getContext(codecContext->width, codecContext->height,
codecContext->pix_fmt, codecContext->width, codecContext->height, codecContext->pix_fmt, codecContext->width, codecContext->height,
screenFormat, SWS_BICUBIC, NULL, NULL, NULL); screenFormat, SWS_BICUBIC, NULL, NULL, NULL);
} }
@ -905,7 +908,7 @@ bool CVideoPlayer::nextFrame()
if (overlay) { if (overlay) {
SDL_LockYUVOverlay(overlay); SDL_LockYUVOverlay(overlay);
pict.data[0] = overlay->pixels[0]; pict.data[0] = overlay->pixels[0];
pict.data[1] = overlay->pixels[2]; pict.data[1] = overlay->pixels[2];
pict.data[2] = overlay->pixels[1]; pict.data[2] = overlay->pixels[1];
@ -945,7 +948,7 @@ void CVideoPlayer::show( int x, int y, SDL_Surface *dst, bool update )
pos.x = x; pos.x = x;
pos.y = y; pos.y = y;
CSDL_Ext::blitSurface(dest, &destRect, dst, &pos); CSDL_Ext::blitSurface(dest, &destRect, dst, &pos);
if (update) if (update)
SDL_UpdateRect(dst, pos.x, pos.y, pos.w, pos.h); SDL_UpdateRect(dst, pos.x, pos.y, pos.w, pos.h);
} }
@ -968,14 +971,14 @@ void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, boo
else else
{ {
open(fname); open(fname);
nextFrame(); nextFrame();
// The y position is wrong at the first frame. // The y position is wrong at the first frame.
// Note: either the windows player or the linux player is // Note: either the windows player or the linux player is
// broken. Compensate here until the bug is found. // broken. Compensate here until the bug is found.
show(x, y--, dst, update); show(x, y--, dst, update);
} }
} }
else else
{ {
redraw(x, y, dst, update); redraw(x, y, dst, update);
@ -986,7 +989,7 @@ void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, boo
void CVideoPlayer::close() void CVideoPlayer::close()
{ {
fname = ""; fname = "";
if (sws) if (sws)
{ {
sws_freeContext(sws); sws_freeContext(sws);
@ -1049,7 +1052,7 @@ bool CVideoPlayer::playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey)
while(nextFrame()) while(nextFrame())
{ {
if(stopOnKey && keyDown()) if(stopOnKey && keyDown())
return false; return false;
@ -1071,7 +1074,7 @@ bool CVideoPlayer::openAndPlayVideo(std::string name, int x, int y, SDL_Surface
close(); close();
return ret; return ret;
} }
CVideoPlayer::~CVideoPlayer() CVideoPlayer::~CVideoPlayer()
{ {
close(); close();

View File

@ -89,11 +89,11 @@ public:
ui8 defActionsDef; //default auto actions ui8 defActionsDef; //default auto actions
ui8 captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list ui8 captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
std::list<CIntObject *> createdObj; //stack of objs being created std::list<CIntObject *> createdObj; //stack of objs being created
static SDLKey arrowToNum(SDLKey key); //converts arrow key to according numpad key static SDLKey arrowToNum(SDLKey key); //converts arrow key to according numpad key
static SDLKey numToDigit(SDLKey key);//converts numpad digit key to normal digit key static SDLKey numToDigit(SDLKey key);//converts numpad digit key to normal digit key
static bool isNumKey(SDLKey key, bool number = true); //checks if key is on numpad (numbers - check only for numpad digits) static bool isNumKey(SDLKey key, bool number = true); //checks if key is on numpad (numbers - check only for numpad digits)
static bool isArrowKey(SDLKey key); static bool isArrowKey(SDLKey key);
static bool amIGuiThread(); static bool amIGuiThread();
static void pushSDLEvent(int type, int usercode = 0); static void pushSDLEvent(int type, int usercode = 0);
}; };
@ -122,8 +122,8 @@ struct SSetCaptureState
namespace Colors namespace Colors
{ {
}; }
#define OBJ_CONSTRUCTION SObjectConstruction obj__i(this) #define OBJ_CONSTRUCTION SObjectConstruction obj__i(this)
#define OBJ_CONSTRUCTION_CAPTURING_ALL defActions = 255; SSetCaptureState obj__i1(true, 255); SObjectConstruction obj__i(this) #define OBJ_CONSTRUCTION_CAPTURING_ALL defActions = 255; SSetCaptureState obj__i1(true, 255); SObjectConstruction obj__i(this)

View File

@ -22,7 +22,7 @@
CPicture::CPicture( SDL_Surface *BG, int x, int y, bool Free ) CPicture::CPicture( SDL_Surface *BG, int x, int y, bool Free )
{ {
init(); init();
bg = BG; bg = BG;
freeSurf = Free; freeSurf = Free;
pos.x += x; pos.x += x;
pos.y += y; pos.y += y;
@ -33,7 +33,7 @@ CPicture::CPicture( SDL_Surface *BG, int x, int y, bool Free )
CPicture::CPicture( const std::string &bmpname, int x, int y ) CPicture::CPicture( const std::string &bmpname, int x, int y )
{ {
init(); init();
bg = BitmapHandler::loadBitmap(bmpname); bg = BitmapHandler::loadBitmap(bmpname);
freeSurf = true;; freeSurf = true;;
pos.x += x; pos.x += x;
pos.y += y; pos.y += y;
@ -315,12 +315,12 @@ void CAdventureMapButton::clickLeft(tribool down, bool previousState)
if(isBlocked()) if(isBlocked())
return; return;
if (down) if (down)
{ {
if (!soundDisabled) if (!soundDisabled)
CCS->soundh->playSound(soundBase::button); CCS->soundh->playSound(soundBase::button);
setState(PRESSED); setState(PRESSED);
} }
else if(hoverable && hovered) else if(hoverable && hovered)
setState(HIGHLIGHTED); setState(HIGHLIGHTED);
else else
@ -355,8 +355,8 @@ void CAdventureMapButton::hover (bool on)
if(pressedL && on) if(pressedL && on)
setState(PRESSED); setState(PRESSED);
std::string *name = (vstd::contains(hoverTexts,getState())) std::string *name = (vstd::contains(hoverTexts,getState()))
? (&hoverTexts[getState()]) ? (&hoverTexts[getState()])
: (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL); : (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL);
if(name && name->size() && !isBlocked()) //if there is no name, there is nohing to display also if(name && name->size() && !isBlocked()) //if there is no name, there is nohing to display also
{ {
@ -533,7 +533,7 @@ void CHighlightableButtonsGroup::addButton(const std::map<int,std::string> &tool
bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID); bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID);
bt->onlyOn = true; bt->onlyOn = true;
buttons.push_back(bt); buttons.push_back(bt);
} }
CHighlightableButtonsGroup::CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange, bool musicLikeButtons) CHighlightableButtonsGroup::CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange, bool musicLikeButtons)
: onChange(OnChange), musicLike(musicLikeButtons) : onChange(OnChange), musicLike(musicLikeButtons)
@ -597,7 +597,7 @@ void CHighlightableButtonsGroup::showAll(SDL_Surface * to)
void CHighlightableButtonsGroup::block( ui8 on ) void CHighlightableButtonsGroup::block( ui8 on )
{ {
for(size_t i=0;i<buttons.size(); ++i) for(size_t i=0;i<buttons.size(); ++i)
{ {
buttons[i]->block(on); buttons[i]->block(on);
} }
@ -614,7 +614,7 @@ void CSlider::mouseMoved (const SDL_MouseMotionEvent & sEvent)
double v = 0; double v = 0;
if(horizontal) if(horizontal)
{ {
if( std::abs(sEvent.y-(pos.y+pos.h/2)) > pos.h/2+40 || std::abs(sEvent.x-(pos.x+pos.w/2)) > pos.w/2 ) if( std::abs(sEvent.y-(pos.y+pos.h/2)) > pos.h/2+40 || std::abs(sEvent.x-(pos.x+pos.w/2)) > pos.w/2 )
return; return;
v = sEvent.x - pos.x - 24; v = sEvent.x - pos.x - 24;
v *= positions; v *= positions;
@ -622,7 +622,7 @@ void CSlider::mouseMoved (const SDL_MouseMotionEvent & sEvent)
} }
else else
{ {
if(std::abs(sEvent.x-(pos.x+pos.w/2)) > pos.w/2+40 || std::abs(sEvent.y-(pos.y+pos.h/2)) > pos.h/2 ) if(std::abs(sEvent.x-(pos.x+pos.w/2)) > pos.w/2+40 || std::abs(sEvent.y-(pos.y+pos.h/2)) > pos.h/2 )
return; return;
v = sEvent.y - pos.y - 24; v = sEvent.y - pos.y - 24;
v *= positions; v *= positions;
@ -746,7 +746,7 @@ CSlider::CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int
left->pos.x = pos.x; left->pos.x = pos.x;
right->pos.x = pos.x + totalw - 16; right->pos.x = pos.x + totalw - 16;
} }
else else
{ {
left->pos.x = slider->pos.x = right->pos.x = pos.x; left->pos.x = slider->pos.x = right->pos.x = pos.x;
left->pos.y = pos.y; left->pos.y = pos.y;
@ -859,7 +859,7 @@ void CSlider::keyPressed(const SDL_KeyboardEvent & key)
return; return;
} }
moveTo(moveDest); moveTo(moveDest);
} }
void CSlider::moveToMax() void CSlider::moveToMax()
@ -1270,7 +1270,7 @@ void CBoundedLabel::showAll(SDL_Surface * to)
CIntObject::showAll(to); CIntObject::showAll(to);
const Font &f = *graphics->fonts[font]; const Font &f = *graphics->fonts[font];
int lineHeight = f.height; int lineHeight = f.height;
int lineCapacity = pos.h / lineHeight; int lineCapacity = pos.h / lineHeight;
int dy = f.height; //line height int dy = f.height; //line height
@ -1301,7 +1301,7 @@ void CBoundedLabel::recalculateLines(const std::string &Txt)
lines.clear(); lines.clear();
const Font &f = *graphics->fonts[font]; const Font &f = *graphics->fonts[font];
int lineHeight = f.height; int lineHeight = f.height;
lines = CMessage::breakText(Txt, pos.w, font); lines = CMessage::breakText(Txt, pos.w, font);
@ -1313,13 +1313,13 @@ void CBoundedLabel::recalculateLines(const std::string &Txt)
CLabelGroup::CLabelGroup(EFonts Font, EAlignment Align, const SDL_Color &Color): CLabelGroup::CLabelGroup(EFonts Font, EAlignment Align, const SDL_Color &Color):
font(Font), align(Align), color(Color) font(Font), align(Align), color(Color)
{}; {}
void CLabelGroup::add(int x, int y, const std::string &text) void CLabelGroup::add(int x, int y, const std::string &text)
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
new CLabel(x, y, font, align, color, text); new CLabel(x, y, font, align, color, text);
}; }
CTextBox::CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= Colors::Cornsilk*/) CTextBox::CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= Colors::Cornsilk*/)
:CBoundedLabel(rect.x, rect.y, Font, Align, Color, Text), sliderStyle(SliderStyle), slider(NULL) :CBoundedLabel(rect.x, rect.y, Font, Align, Color, Text), sliderStyle(SliderStyle), slider(NULL)
@ -1340,7 +1340,7 @@ void CTextBox::recalculateLines(const std::string &Txt)
vstd::clear_pointer(slider); vstd::clear_pointer(slider);
lines.clear(); lines.clear();
const Font &f = *graphics->fonts[font]; const Font &f = *graphics->fonts[font];
int lineHeight = f.height; int lineHeight = f.height;
int lineCapacity = pos.h / lineHeight; int lineCapacity = pos.h / lineHeight;
lines = CMessage::breakText(Txt, pos.w, font); lines = CMessage::breakText(Txt, pos.w, font);
@ -1535,7 +1535,7 @@ void CTextInput::clickLeft( tribool down, bool previousState )
void CTextInput::keyPressed( const SDL_KeyboardEvent & key ) void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
{ {
if(!focus || key.state != SDL_PRESSED) if(!focus || key.state != SDL_PRESSED)
return; return;
if(key.keysym.sym == SDLK_TAB) if(key.keysym.sym == SDLK_TAB)

View File

@ -193,4 +193,4 @@ namespace CSDL_Ext
void applyEffect(SDL_Surface * surf, const SDL_Rect * rect, int mode); //mode: 0 - sepia, 1 - grayscale void applyEffect(SDL_Surface * surf, const SDL_Rect * rect, int mode); //mode: 0 - sepia, 1 - grayscale
std::string trimToFit(std::string text, int widthLimit, EFonts font); std::string trimToFit(std::string text, int widthLimit, EFonts font);
}; }

View File

@ -55,12 +55,12 @@ bool CArtifact::isBig () const
// { // {
// if (!vstd::contains(possibleSlots, slotID)) // if (!vstd::contains(possibleSlots, slotID))
// return false; // return false;
// //
// // Can't put an artifact in a locked slot. // // Can't put an artifact in a locked slot.
// std::map<ui16, const CArtifact*>::const_iterator it = artifWorn.find(slotID); // std::map<ui16, const CArtifact*>::const_iterator it = artifWorn.find(slotID);
// if (it != artifWorn.end() && it->second->id == 145) // if (it != artifWorn.end() && it->second->id == 145)
// return false; // return false;
// //
// // Check if a combination artifact fits. // // Check if a combination artifact fits.
// // TODO: Might want a more general algorithm? // // TODO: Might want a more general algorithm?
// // Assumes that misc & rings fits only in their slots, and others in only one slot and no duplicates. // // Assumes that misc & rings fits only in their slots, and others in only one slot and no duplicates.
@ -71,14 +71,14 @@ bool CArtifact::isBig () const
// const ui16 miscSlots[] = {9, 10, 11, 12, 18}; // const ui16 miscSlots[] = {9, 10, 11, 12, 18};
// int rings = 0; // int rings = 0;
// int misc = 0; // int misc = 0;
// //
// VLC->arth->unequipArtifact(tempArtifWorn, slotID); // VLC->arth->unequipArtifact(tempArtifWorn, slotID);
// //
// BOOST_FOREACH(ui32 constituentID, *constituents) // BOOST_FOREACH(ui32 constituentID, *constituents)
// { // {
// const CArtifact& constituent = *VLC->arth->artifacts[constituentID]; // const CArtifact& constituent = *VLC->arth->artifacts[constituentID];
// const int slot = constituent.possibleSlots[0]; // const int slot = constituent.possibleSlots[0];
// //
// if (slot == 6 || slot == 7) // if (slot == 6 || slot == 7)
// rings++; // rings++;
// else if ((slot >= 9 && slot <= 12) || slot == 18) // else if ((slot >= 9 && slot <= 12) || slot == 18)
@ -86,18 +86,18 @@ bool CArtifact::isBig () const
// else if (tempArtifWorn.find(slot) != tempArtifWorn.end()) // else if (tempArtifWorn.find(slot) != tempArtifWorn.end())
// return false; // return false;
// } // }
// //
// // Ensure enough ring slots are free // // Ensure enough ring slots are free
// for (int i = 0; i < sizeof(ringSlots)/sizeof(*ringSlots); i++) // for (int i = 0; i < sizeof(ringSlots)/sizeof(*ringSlots); i++)
// { // {
// if (tempArtifWorn.find(ringSlots[i]) == tempArtifWorn.end() || ringSlots[i] == slotID) // if (tempArtifWorn.find(ringSlots[i]) == tempArtifWorn.end() || ringSlots[i] == slotID)
// rings--; // rings--;
// } // }
// if (rings > 0) // if (rings > 0)
// return false; // return false;
// //
// // Ensure enough misc slots are free. // // Ensure enough misc slots are free.
// for (int i = 0; i < sizeof(miscSlots)/sizeof(*miscSlots); i++) // for (int i = 0; i < sizeof(miscSlots)/sizeof(*miscSlots); i++)
// { // {
// if (tempArtifWorn.find(miscSlots[i]) == tempArtifWorn.end() || miscSlots[i] == slotID) // if (tempArtifWorn.find(miscSlots[i]) == tempArtifWorn.end() || miscSlots[i] == slotID)
// misc--; // misc--;
@ -105,7 +105,7 @@ bool CArtifact::isBig () const
// if (misc > 0) // if (misc > 0)
// return false; // return false;
// } // }
// //
// return true; // return true;
// } // }
@ -113,16 +113,16 @@ bool CArtifact::isBig () const
// { // {
// if (constituentOf == NULL || !vstd::contains(*constituentOf, artifactID)) // if (constituentOf == NULL || !vstd::contains(*constituentOf, artifactID))
// return false; // return false;
// //
// const CArtifact &artifact = *VLC->arth->artifacts[artifactID]; // const CArtifact &artifact = *VLC->arth->artifacts[artifactID];
// assert(artifact.constituents); // assert(artifact.constituents);
// //
// BOOST_FOREACH(ui32 constituentID, *artifact.constituents) // BOOST_FOREACH(ui32 constituentID, *artifact.constituents)
// { // {
// bool found = false; // bool found = false;
// for (std::map<ui16, const CArtifact*>::const_iterator it = artifWorn.begin(); it != artifWorn.end(); ++it) // for (std::map<ui16, const CArtifact*>::const_iterator it = artifWorn.begin(); it != artifWorn.end(); ++it)
// { // {
// if (it->second->id == constituentID) // if (it->second->id == constituentID)
// { // {
// found = true; // found = true;
// break; // break;
@ -131,7 +131,7 @@ bool CArtifact::isBig () const
// if (!found) // if (!found)
// return false; // return false;
// } // }
// //
// return true; // return true;
// } // }
@ -237,7 +237,7 @@ void CArtHandler::loadArtifacts(bool onlyTxt)
std::vector<ui16> slots; std::vector<ui16> slots;
slots += 17, 16, 15, 14, 13, 18, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0; slots += 17, 16, 15, 14, 13, 18, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0;
growingArtifacts += 146, 147, 148, 150, 151, 152, 153; growingArtifacts += 146, 147, 148, 150, 151, 152, 153;
static std::map<char, CArtifact::EartClass> classes = static std::map<char, CArtifact::EartClass> classes =
map_list_of('S',CArtifact::ART_SPECIAL)('T',CArtifact::ART_TREASURE)('N',CArtifact::ART_MINOR)('J',CArtifact::ART_MAJOR)('R',CArtifact::ART_RELIC); map_list_of('S',CArtifact::ART_SPECIAL)('T',CArtifact::ART_TREASURE)('N',CArtifact::ART_MINOR)('J',CArtifact::ART_MAJOR)('R',CArtifact::ART_RELIC);
CLegacyConfigParser parser("DATA/ARTRAITS.TXT"); CLegacyConfigParser parser("DATA/ARTRAITS.TXT");
@ -287,7 +287,7 @@ void CArtHandler::loadArtifacts(bool onlyTxt)
// Fill in information about combined artifacts. Should perhaps be moved to a config file? // Fill in information about combined artifacts. Should perhaps be moved to a config file?
nart.constituentOf = NULL; nart.constituentOf = NULL;
switch (nart.id) switch (nart.id)
{ {
case 129: // Angelic Alliance case 129: // Angelic Alliance
nart.constituents = new std::vector<ui32>(); nart.constituents = new std::vector<ui32>();
@ -363,7 +363,7 @@ void CArtHandler::loadArtifacts(bool onlyTxt)
const JsonNode config(ResourceID("config/commanders.json")); const JsonNode config(ResourceID("config/commanders.json"));
BOOST_FOREACH(const JsonNode &artifact, config["artifacts"].Vector()) BOOST_FOREACH(const JsonNode &artifact, config["artifacts"].Vector())
{ {
auto ga = dynamic_cast <CGrowingArtifact *>(artifacts[artifact["id"].Float()].get()); auto ga = dynamic_cast <CGrowingArtifact *>(artifacts[artifact["id"].Float()].get());
BOOST_FOREACH (auto b, artifact["bonusesPerLevel"].Vector()) BOOST_FOREACH (auto b, artifact["bonusesPerLevel"].Vector())
{ {
ga->bonusesPerLevel.push_back (std::pair <ui16, Bonus> (b["level"].Float(), *ParseBonus (b["bonus"].Vector()))); ga->bonusesPerLevel.push_back (std::pair <ui16, Bonus> (b["level"].Float(), *ParseBonus (b["bonus"].Vector())));
@ -382,11 +382,11 @@ void CArtHandler::loadArtifacts(bool onlyTxt)
addBonuses(); addBonuses();
// Populate reverse mappings of combinational artifacts. // Populate reverse mappings of combinational artifacts.
BOOST_FOREACH(CArtifact *artifact, artifacts) BOOST_FOREACH(CArtifact *artifact, artifacts)
{ {
if (artifact->constituents != NULL) if (artifact->constituents != NULL)
{ {
BOOST_FOREACH(ui32 constituentID, *artifact->constituents) BOOST_FOREACH(ui32 constituentID, *artifact->constituents)
{ {
if (artifacts[constituentID]->constituentOf == NULL) if (artifacts[constituentID]->constituentOf == NULL)
artifacts[constituentID]->constituentOf = new std::vector<ui32>(); artifacts[constituentID]->constituentOf = new std::vector<ui32>();
@ -484,7 +484,7 @@ ui16 CArtHandler::getArtSync (ui32 rand, int flags)
std::vector<ConstTransitivePtr<CArtifact> > out; std::vector<ConstTransitivePtr<CArtifact> > out;
getAllowed(out, flags); getAllowed(out, flags);
CArtifact *art = out[rand % out.size()]; CArtifact *art = out[rand % out.size()];
return art->id; return art->id;
} }
void CArtHandler::getAllowed(std::vector<ConstTransitivePtr<CArtifact> > &out, int flags) void CArtHandler::getAllowed(std::vector<ConstTransitivePtr<CArtifact> > &out, int flags)
{ {
@ -575,7 +575,7 @@ void CArtHandler::makeItCreatureArt (int aid, bool onlyCreature /*=true*/)
a->possibleSlots[ArtBearer::COMMANDER].clear(); a->possibleSlots[ArtBearer::COMMANDER].clear();
} }
a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT); a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT);
}; }
void CArtHandler::makeItCommanderArt (int aid, bool onlyCommander /*=true*/) void CArtHandler::makeItCommanderArt (int aid, bool onlyCommander /*=true*/)
{ {
@ -587,7 +587,7 @@ void CArtHandler::makeItCommanderArt (int aid, bool onlyCommander /*=true*/)
} }
for (int i = ArtifactPosition::COMMANDER1; i <= ArtifactPosition::COMMANDER6; ++i) for (int i = ArtifactPosition::COMMANDER1; i <= ArtifactPosition::COMMANDER6; ++i)
a->possibleSlots[ArtBearer::COMMANDER].push_back(i); a->possibleSlots[ArtBearer::COMMANDER].push_back(i);
}; }
void CArtHandler::addBonuses() void CArtHandler::addBonuses()
{ {
@ -601,11 +601,11 @@ void CArtHandler::addBonuses()
//Propagators/limiters used more than once //Propagators/limiters used more than once
auto battleWidePropagator = make_shared<CPropagatorNodeType>(CBonusSystemNode::BATTLE); auto battleWidePropagator = make_shared<CPropagatorNodeType>(CBonusSystemNode::BATTLE);
auto visitedTownPropagator = make_shared<CPropagatorNodeType>(CBonusSystemNode::TOWN_AND_VISITOR); auto visitedTownPropagator = make_shared<CPropagatorNodeType>(CBonusSystemNode::TOWN_AND_VISITOR);
auto shooterOnlyLimiter = make_shared<HasAnotherBonusLimiter>(Bonus::SHOOTER); auto shooterOnlyLimiter = make_shared<HasAnotherBonusLimiter>(Bonus::SHOOTER);
auto dragonNatureLimiter = make_shared<HasAnotherBonusLimiter>(Bonus::DRAGON_NATURE); auto dragonNatureLimiter = make_shared<HasAnotherBonusLimiter>(Bonus::DRAGON_NATURE);
//Attack bonus artifacts (Weapons) //Attack bonus artifacts (Weapons)
ART_PRIM_SKILL(7,0,+2); //Centaur Axe ART_PRIM_SKILL(7,0,+2); //Centaur Axe
ART_PRIM_SKILL(8,0,+3); //Blackshard of the Dead Knight ART_PRIM_SKILL(8,0,+3); //Blackshard of the Dead Knight
@ -625,7 +625,7 @@ void CArtHandler::addBonuses()
ART_PRIM_SKILL(18,0,-3); //Sentinel's Shield ART_PRIM_SKILL(18,0,-3); //Sentinel's Shield
//Knowledge bonus artifacts (Helmets) //Knowledge bonus artifacts (Helmets)
ART_PRIM_SKILL(19,3,+1); //Helm of the Alabaster Unicorn ART_PRIM_SKILL(19,3,+1); //Helm of the Alabaster Unicorn
ART_PRIM_SKILL(20,3,+2); //Skull Helmet ART_PRIM_SKILL(20,3,+2); //Skull Helmet
ART_PRIM_SKILL(21,3,+3); //Helm of Chaos ART_PRIM_SKILL(21,3,+3); //Helm of Chaos
ART_PRIM_SKILL(22,3,+4); //Crown of the Supreme Magi ART_PRIM_SKILL(22,3,+4); //Crown of the Supreme Magi
@ -662,13 +662,13 @@ void CArtHandler::addBonuses()
ART_POWER_AND_KNOWLEDGE(43,+3); //Necklace of Dragonteeth ART_POWER_AND_KNOWLEDGE(43,+3); //Necklace of Dragonteeth
ART_POWER_AND_KNOWLEDGE(44,+4); //Crown of Dragontooth ART_POWER_AND_KNOWLEDGE(44,+4); //Crown of Dragontooth
//Luck and morale //Luck and morale
ART_MORALE(45,+1); //Still Eye of the Dragon ART_MORALE(45,+1); //Still Eye of the Dragon
ART_LUCK(45,+1); //Still Eye of the Dragon ART_LUCK(45,+1); //Still Eye of the Dragon
ART_LUCK(46,+1); //Clover of Fortune ART_LUCK(46,+1); //Clover of Fortune
ART_LUCK(47,+1); //Cards of Prophecy ART_LUCK(47,+1); //Cards of Prophecy
ART_LUCK(48,+1); //Ladybird of Luck ART_LUCK(48,+1); //Ladybird of Luck
ART_MORALE(49,+1); //Badge of Courage -> +1 morale ART_MORALE(49,+1); //Badge of Courage -> +1 morale
giveArtBonus(49,Bonus::MIND_IMMUNITY,0); //immunity to hostile mind spells: giveArtBonus(49,Bonus::MIND_IMMUNITY,0); //immunity to hostile mind spells:
ART_MORALE(50,+1); //Crest of Valor ART_MORALE(50,+1); //Crest of Valor
ART_MORALE(51,+1); //Glyph of Gallantry ART_MORALE(51,+1); //Glyph of Gallantry
@ -772,11 +772,11 @@ void CArtHandler::addBonuses()
giveArtBonus(121,Bonus::CREATURE_GROWTH,+2,4, visitedTownPropagator); //Arms of Legion giveArtBonus(121,Bonus::CREATURE_GROWTH,+2,4, visitedTownPropagator); //Arms of Legion
giveArtBonus(122,Bonus::CREATURE_GROWTH,+1,5, visitedTownPropagator); //Head of Legion giveArtBonus(122,Bonus::CREATURE_GROWTH,+1,5, visitedTownPropagator); //Head of Legion
//Sea Captain's Hat //Sea Captain's Hat
giveArtBonus(123,Bonus::WHIRLPOOL_PROTECTION,0); giveArtBonus(123,Bonus::WHIRLPOOL_PROTECTION,0);
giveArtBonus(123,Bonus::SEA_MOVEMENT,+500); giveArtBonus(123,Bonus::SEA_MOVEMENT,+500);
giveArtBonus(123,Bonus::SPELL,3,0, Bonus::INDEPENDENT_MAX); giveArtBonus(123,Bonus::SPELL,3,0, Bonus::INDEPENDENT_MAX);
giveArtBonus(123,Bonus::SPELL,3,1, Bonus::INDEPENDENT_MAX); giveArtBonus(123,Bonus::SPELL,3,1, Bonus::INDEPENDENT_MAX);
giveArtBonus(124, Bonus::SPELLS_OF_LEVEL,3,1); //Spellbinder's Hat giveArtBonus(124, Bonus::SPELLS_OF_LEVEL,3,1); //Spellbinder's Hat
giveArtBonus(125, Bonus::BATTLE_NO_FLEEING,0, 0, battleWidePropagator); //Shackles of War giveArtBonus(125, Bonus::BATTLE_NO_FLEEING,0, 0, battleWidePropagator); //Shackles of War
@ -919,32 +919,32 @@ void CArtHandler::clear()
// void CArtHandler::equipArtifact( std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art ) const // void CArtHandler::equipArtifact( std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art ) const
// { // {
// unequipArtifact(artifWorn, slotID); // unequipArtifact(artifWorn, slotID);
// //
// if (art) //false when artifact is NULL -> slot set to empty // if (art) //false when artifact is NULL -> slot set to empty
// { // {
// const CArtifact &artifact = *art; // const CArtifact &artifact = *art;
// //
// // Add artifact. // // Add artifact.
// artifWorn[slotID] = art; // artifWorn[slotID] = art;
// //
// // Add locks, in reverse order of being removed. // // Add locks, in reverse order of being removed.
// if (artifact.constituents != NULL) // if (artifact.constituents != NULL)
// { // {
// bool destConsumed = false; // Determines which constituent that will be counted for together with the artifact. // bool destConsumed = false; // Determines which constituent that will be counted for together with the artifact.
// //
// BOOST_FOREACH(ui32 constituentID, *artifact.constituents) // BOOST_FOREACH(ui32 constituentID, *artifact.constituents)
// { // {
// const CArtifact &constituent = *artifacts[constituentID]; // const CArtifact &constituent = *artifacts[constituentID];
// //
// if (!destConsumed && vstd::contains(constituent.possibleSlots, slotID)) // if (!destConsumed && vstd::contains(constituent.possibleSlots, slotID))
// { // {
// destConsumed = true; // destConsumed = true;
// } // }
// else // else
// { // {
// BOOST_FOREACH(ui16 slot, constituent.possibleSlots) // BOOST_FOREACH(ui16 slot, constituent.possibleSlots)
// { // {
// if (!vstd::contains(artifWorn, slot)) // if (!vstd::contains(artifWorn, slot))
// { // {
// artifWorn[slot] = VLC->arth->artifacts[145]; //lock // artifWorn[slot] = VLC->arth->artifacts[145]; //lock
// break; // break;
@ -955,7 +955,7 @@ void CArtHandler::clear()
// } // }
// } // }
// } // }
// //
// /** // /**
// * Locally unequips an artifact from a hero's worn slots. // * Locally unequips an artifact from a hero's worn slots.
// * Does not test if the operation is legal. // * Does not test if the operation is legal.
@ -966,30 +966,30 @@ void CArtHandler::clear()
// { // {
// if (!vstd::contains(artifWorn, slotID)) // if (!vstd::contains(artifWorn, slotID))
// return; // return;
// //
// const CArtifact &artifact = *artifWorn[slotID]; // const CArtifact &artifact = *artifWorn[slotID];
// //
// // Remove artifact, if it's not already removed. // // Remove artifact, if it's not already removed.
// artifWorn.erase(slotID); // artifWorn.erase(slotID);
// //
// // Remove locks, in reverse order of being added. // // Remove locks, in reverse order of being added.
// if (artifact.constituents != NULL) // if (artifact.constituents != NULL)
// { // {
// bool destConsumed = false; // bool destConsumed = false;
// //
// BOOST_FOREACH(ui32 constituentID, *artifact.constituents) // BOOST_FOREACH(ui32 constituentID, *artifact.constituents)
// { // {
// const CArtifact &constituent = *artifacts[constituentID]; // const CArtifact &constituent = *artifacts[constituentID];
// //
// if (!destConsumed && vstd::contains(constituent.possibleSlots, slotID)) // if (!destConsumed && vstd::contains(constituent.possibleSlots, slotID))
// { // {
// destConsumed = true; // destConsumed = true;
// } // }
// else // else
// { // {
// BOOST_REVERSE_FOREACH(ui16 slot, constituent.possibleSlots) // BOOST_REVERSE_FOREACH(ui16 slot, constituent.possibleSlots)
// { // {
// if (vstd::contains(artifWorn, slot) && artifWorn[slot]->id == 145) // if (vstd::contains(artifWorn, slot) && artifWorn[slot]->id == 145)
// { // {
// artifWorn.erase(slot); // artifWorn.erase(slot);
// break; // break;
@ -1152,7 +1152,7 @@ std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CA
|| artType->constituents) //combined artifact already: no combining of combined artifacts... for now. || artType->constituents) //combined artifact already: no combining of combined artifacts... for now.
return ret; return ret;
BOOST_FOREACH(ui32 possibleCombinedArt, *artType->constituentOf) BOOST_FOREACH(ui32 possibleCombinedArt, *artType->constituentOf)
{ {
const CArtifact * const artifact = VLC->arth->artifacts[possibleCombinedArt]; const CArtifact * const artifact = VLC->arth->artifacts[possibleCombinedArt];
assert(artifact->constituents); assert(artifact->constituents);
@ -1228,7 +1228,7 @@ bool CArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
return supposedPart == this; return supposedPart == this;
} }
bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet *artSet, int slot, bool assumeDestRemoved /*= false*/) const bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet *artSet, int slot, bool assumeDestRemoved /*= false*/) const
{ {
bool canMainArtifactBePlaced = CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved); bool canMainArtifactBePlaced = CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved);
if(!canMainArtifactBePlaced) if(!canMainArtifactBePlaced)
@ -1319,7 +1319,7 @@ void CCombinedArtifactInstance::putAt(ArtifactLocation al)
const bool suggestedPosValid = ci.art->canBePutAt(suggestedPos); const bool suggestedPosValid = ci.art->canBePutAt(suggestedPos);
int pos = -1; int pos = -1;
if(inActiveSlot && suggestedPosValid) //there is a valid suggestion where to place lock if(inActiveSlot && suggestedPosValid) //there is a valid suggestion where to place lock
pos = ci.slot; pos = ci.slot;
else else
ci.slot = pos = ci.art->firstAvailableSlot(al.getHolderArtSet()); ci.slot = pos = ci.art->firstAvailableSlot(al.getHolderArtSet());
@ -1517,7 +1517,7 @@ CArtifactSet::~CArtifactSet()
ArtSlotInfo & CArtifactSet::retreiveNewArtSlot(ui16 slot) ArtSlotInfo & CArtifactSet::retreiveNewArtSlot(ui16 slot)
{ {
assert(!vstd::contains(artifactsWorn, slot)); assert(!vstd::contains(artifactsWorn, slot));
ArtSlotInfo &ret = slot < GameConstants::BACKPACK_START ArtSlotInfo &ret = slot < GameConstants::BACKPACK_START
? artifactsWorn[slot] ? artifactsWorn[slot]
: *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - GameConstants::BACKPACK_START), ArtSlotInfo()); : *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - GameConstants::BACKPACK_START), ArtSlotInfo());

View File

@ -25,9 +25,10 @@
#else #else
#define WIN32_LEAN_AND_MEAN //excludes rarely used stuff from windows headers - delete this line if something is missing #define WIN32_LEAN_AND_MEAN //excludes rarely used stuff from windows headers - delete this line if something is missing
#include <windows.h> #include <windows.h>
#ifndef __MINGW32__
#include <dbghelp.h> #include <dbghelp.h>
#pragma comment(lib, "dbghelp.lib") #pragma comment(lib, "dbghelp.lib")
#endif
typedef WORD TColor; typedef WORD TColor;
HANDLE handleIn; HANDLE handleIn;
HANDLE handleOut; HANDLE handleOut;
@ -108,19 +109,20 @@ LONG WINAPI onUnhandledException(EXCEPTION_POINTERS* exception)
if (einfo->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) if (einfo->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
{ {
tlog1 << "Attempt to " << (einfo->ExceptionInformation[0] == 1 ? "write to " : "read from ") tlog1 << "Attempt to " << (einfo->ExceptionInformation[0] == 1 ? "write to " : "read from ")
<< "0x" << std::setw(8) << (void*)einfo->ExceptionInformation[1] << std::endl;; << "0x" << std::setw(8) << (void*)einfo->ExceptionInformation[1] << std::endl;;
} }
const DWORD threadId = ::GetCurrentThreadId(); const DWORD threadId = ::GetCurrentThreadId();
tlog1 << "Thread ID: " << threadId << " [" << std::dec << std::setw(0) << threadId << "]\n"; tlog1 << "Thread ID: " << threadId << " [" << std::dec << std::setw(0) << threadId << "]\n";
#ifndef __MINGW32__
//exception info to be placed in the dump //exception info to be placed in the dump
MINIDUMP_EXCEPTION_INFORMATION meinfo = {threadId, exception, TRUE}; MINIDUMP_EXCEPTION_INFORMATION meinfo = {threadId, exception, TRUE};
//create file where dump will be placed //create file where dump will be placed
char *mname = NULL; char *mname = NULL;
char buffer[MAX_PATH + 1]; char buffer[MAX_PATH + 1];
HMODULE hModule = NULL; HMODULE hModule = NULL;
GetModuleFileNameA(hModule, buffer, MAX_PATH); GetModuleFileNameA(hModule, buffer, MAX_PATH);
mname = strrchr(buffer, '\\'); mname = strrchr(buffer, '\\');
if (mname != 0) if (mname != 0)
@ -132,6 +134,7 @@ LONG WINAPI onUnhandledException(EXCEPTION_POINTERS* exception)
HANDLE dfile = CreateFileA(mname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0); HANDLE dfile = CreateFileA(mname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
tlog1 << "Crash info will be put in " << mname << std::endl; tlog1 << "Crash info will be put in " << mname << std::endl;
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), dfile, MiniDumpWithDataSegs, &meinfo, 0, 0); MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), dfile, MiniDumpWithDataSegs, &meinfo, 0, 0);
#endif
MessageBoxA(0, "VCMI has crashed. We are sorry. File with information about encountered problem has been created.", "VCMI Crashhandler", MB_OK | MB_ICONERROR); MessageBoxA(0, "VCMI has crashed. We are sorry. File with information about encountered problem has been created.", "VCMI Crashhandler", MB_OK | MB_ICONERROR);
return EXCEPTION_EXECUTE_HANDLER; return EXCEPTION_EXECUTE_HANDLER;
} }
@ -233,7 +236,7 @@ CConsoleHandler::~CConsoleHandler()
} }
void CConsoleHandler::end() void CConsoleHandler::end()
{ {
if (thread) if (thread)
{ {
#ifndef _WIN32 #ifndef _WIN32
thread->interrupt(); thread->interrupt();

View File

@ -133,7 +133,7 @@ public:
class DLL_LINKAGE CCreatureSet : public IArmyDescriptor //seven combined creatures class DLL_LINKAGE CCreatureSet : public IArmyDescriptor //seven combined creatures
{ {
CCreatureSet(const CCreatureSet&);; CCreatureSet(const CCreatureSet&);
CCreatureSet &operator=(const CCreatureSet&); CCreatureSet &operator=(const CCreatureSet&);
public: public:
TSlots stacks; //slots[slot_id]->> pair(creature_id,creature_quantity) TSlots stacks; //slots[slot_id]->> pair(creature_id,creature_quantity)
@ -143,7 +143,7 @@ public:
virtual ~CCreatureSet(); virtual ~CCreatureSet();
virtual void armyChanged(); virtual void armyChanged();
const CStackInstance &operator[](TSlot slot) const; const CStackInstance &operator[](TSlot slot) const;
const TSlots &Slots() const {return stacks;} const TSlots &Slots() const {return stacks;}
@ -161,13 +161,13 @@ public:
void giveStackExp(expType exp); void giveStackExp(expType exp);
void setStackExp(TSlot slot, expType exp); void setStackExp(TSlot slot, expType exp);
//derivative //derivative
void eraseStack(TSlot slot); //slot must be occupied void eraseStack(TSlot slot); //slot must be occupied
void joinStack(TSlot slot, CStackInstance * stack); //adds new stack to the existing stack of the same type void joinStack(TSlot slot, CStackInstance * stack); //adds new stack to the existing stack of the same type
void changeStackCount(TSlot slot, TQuantity toAdd); //stack must exist! void changeStackCount(TSlot slot, TQuantity toAdd); //stack must exist!
bool setCreature (TSlot slot, TCreature type, TQuantity quantity) OVERRIDE; //replaces creature in stack; slots 0 to 6, if quantity=0 erases stack bool setCreature (TSlot slot, TCreature type, TQuantity quantity) OVERRIDE; //replaces creature in stack; slots 0 to 6, if quantity=0 erases stack
void setToArmy(CSimpleArmy &src); //erases all our army and moves stacks from src to us; src MUST NOT be an armed object! WARNING: use it wisely. Or better do not use at all. void setToArmy(CSimpleArmy &src); //erases all our army and moves stacks from src to us; src MUST NOT be an armed object! WARNING: use it wisely. Or better do not use at all.
const CStackInstance& getStack(TSlot slot) const; //stack must exist const CStackInstance& getStack(TSlot slot) const; //stack must exist
const CStackInstance* getStackPtr(TSlot slot) const; //if stack doesn't exist, returns NULL const CStackInstance* getStackPtr(TSlot slot) const; //if stack doesn't exist, returns NULL
const CCreature* getCreature(TSlot slot) const; //workaround of map issue; const CCreature* getCreature(TSlot slot) const; //workaround of map issue;
@ -186,7 +186,7 @@ public:
ui64 getPower (TSlot slot) const; //value of specific stack ui64 getPower (TSlot slot) const; //value of specific stack
std::string getRoughAmount (TSlot slot) const; //rough size of specific stack std::string getRoughAmount (TSlot slot) const; //rough size of specific stack
bool hasStackAtSlot(TSlot slot) const; bool hasStackAtSlot(TSlot slot) const;
bool contains(const CStackInstance *stack) const; bool contains(const CStackInstance *stack) const;
bool canBeMergedWith(const CCreatureSet &cs, bool allowMergingStacks = true) const; bool canBeMergedWith(const CCreatureSet &cs, bool allowMergingStacks = true) const;

View File

@ -53,13 +53,13 @@ std::vector<const CArtifact *> CGTownInstance::merchantArtifacts;
std::vector<int> CGTownInstance::universitySkills; std::vector<int> CGTownInstance::universitySkills;
void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const
{}; {}
void IObjectInterface::onHeroLeave(const CGHeroInstance * h) const void IObjectInterface::onHeroLeave(const CGHeroInstance * h) const
{}; {}
void IObjectInterface::newTurn () const void IObjectInterface::newTurn () const
{}; {}
IObjectInterface::~IObjectInterface() IObjectInterface::~IObjectInterface()
{} {}

View File

@ -35,7 +35,7 @@ void CThreadHelper::processTasks()
while(true) while(true)
{ {
{ {
boost::unique_lock<boost::mutex> lock(rtinm); boost::unique_lock<boost::mutex> lock(rtinm);
if((pom = currentTask) >= amount) if((pom = currentTask) >= amount)
break; break;
else else
@ -50,6 +50,7 @@ void CThreadHelper::processTasks()
void setThreadName(const std::string &name) void setThreadName(const std::string &name)
{ {
#ifdef _WIN32 #ifdef _WIN32
#ifndef __GNUC__
//follows http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx //follows http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
const DWORD MS_VC_EXCEPTION=0x406D1388; const DWORD MS_VC_EXCEPTION=0x406D1388;
#pragma pack(push,8) #pragma pack(push,8)
@ -67,6 +68,7 @@ void setThreadName(const std::string &name)
info.dwThreadID = -1; info.dwThreadID = -1;
info.dwFlags = 0; info.dwFlags = 0;
__try __try
{ {
RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
@ -74,7 +76,11 @@ void setThreadName(const std::string &name)
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
} }
#else
//not supported
#endif
#else #else
prctl(PR_SET_NAME, name.c_str(), 0, 0, 0); prctl(PR_SET_NAME, name.c_str(), 0, 0, 0);
#endif #endif
} }

View File

@ -5,8 +5,8 @@
#include <boost/type_traits/is_fundamental.hpp> #include <boost/type_traits/is_fundamental.hpp>
#include <boost/type_traits/is_enum.hpp> #include <boost/type_traits/is_enum.hpp>
#include <boost/type_traits/is_pointer.hpp> #include <boost/type_traits/is_pointer.hpp>
#include <boost/type_traits/is_class.hpp> #include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_base_of.hpp> #include <boost/type_traits/is_base_of.hpp>
#include <boost/type_traits/is_array.hpp> #include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/remove_pointer.hpp> #include <boost/type_traits/remove_pointer.hpp>
@ -66,7 +66,7 @@ namespace boost
class basic_socket_acceptor; class basic_socket_acceptor;
} }
class mutex; class mutex;
}; }
enum SerializationLvl enum SerializationLvl
{ {
@ -200,7 +200,7 @@ struct LoadWrong
template<typename T> template<typename T>
struct SerializationLevel struct SerializationLevel
{ {
typedef mpl::integral_c_tag tag; typedef mpl::integral_c_tag tag;
typedef typedef
typename mpl::eval_if< typename mpl::eval_if<
@ -252,7 +252,7 @@ public:
TTypeVecMap vectors; //entry must be a pointer to vector containing pointers to the objects of key type TTypeVecMap vectors; //entry must be a pointer to vector containing pointers to the objects of key type
bool smartVectorMembersSerialization; bool smartVectorMembersSerialization;
bool sendStackInstanceByIds; bool sendStackInstanceByIds;
CSerializer(); CSerializer();
~CSerializer(); ~CSerializer();
@ -274,7 +274,7 @@ public:
const VectorisedObjectInfo<T> *getVectorisedTypeInfo() const VectorisedObjectInfo<T> *getVectorisedTypeInfo()
{ {
const std::type_info *myType = NULL; const std::type_info *myType = NULL;
// //
// if(boost::is_base_of<CGObjectInstance, T>::value) //ugly workaround to support also types derived from CGObjectInstance -> if we encounter one, treat it aas CGObj.. // if(boost::is_base_of<CGObjectInstance, T>::value) //ugly workaround to support also types derived from CGObjectInstance -> if we encounter one, treat it aas CGObj..
// myType = &typeid(CGObjectInstance); // myType = &typeid(CGObjectInstance);
// else // else
@ -342,7 +342,7 @@ public:
template <typename T> //metafunction returning CGObjectInstance if T is its derivate or T elsewise template <typename T> //metafunction returning CGObjectInstance if T is its derivate or T elsewise
struct VectorisedTypeFor struct VectorisedTypeFor
{ {
typedef typename typedef typename
//if //if
mpl::eval_if<boost::is_base_of<CGObjectInstance,T>, mpl::eval_if<boost::is_base_of<CGObjectInstance,T>,
mpl::identity<CGObjectInstance>, mpl::identity<CGObjectInstance>,
@ -471,8 +471,8 @@ public:
COSer & operator&(const T & t) COSer & operator&(const T & t)
{ {
return * this->This() << t; return * this->This() << t;
} }
int write(const void * data, unsigned size); int write(const void * data, unsigned size);
@ -539,7 +539,7 @@ public:
//that part of ptr serialization was extracted to allow customization of its behavior in derived classes //that part of ptr serialization was extracted to allow customization of its behavior in derived classes
template <typename T> template <typename T>
void savePointerHlp(ui16 tid, const T &data) void savePointerHlp(ui16 tid, const T &data)
{ {
if(!tid) if(!tid)
*this << *data; //if type is unregistered simply write all data in a standard way *this << *data; //if type is unregistered simply write all data in a standard way
else else
@ -556,7 +556,7 @@ public:
template <typename T> template <typename T>
void save(const T &data) void save(const T &data)
{ {
typedef typedef
//if //if
typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Primitive> >, typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Primitive> >,
mpl::identity<SavePrimitive<Serializer,T> >, mpl::identity<SavePrimitive<Serializer,T> >,
@ -703,7 +703,7 @@ public:
~CISer() ~CISer()
{ {
std::map<ui16,CBasicPointerLoader*>::iterator iter; std::map<ui16,CBasicPointerLoader*>::iterator iter;
for(iter = loaders.begin(); iter != loaders.end(); iter++) for(iter = loaders.begin(); iter != loaders.end(); iter++)
delete iter->second; delete iter->second;
} }
@ -725,18 +725,18 @@ public:
this->This()->load(t); this->This()->load(t);
return * this->This(); return * this->This();
} }
template<class T> template<class T>
CISer & operator&(T & t) CISer & operator&(T & t)
{ {
return * this->This() >> t; return * this->This() >> t;
} }
int write(const void * data, unsigned size); int write(const void * data, unsigned size);
template <typename T> template <typename T>
void load(T &data) void load(T &data)
{ {
typedef typedef
//if //if
typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Primitive> >, typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Primitive> >,
mpl::identity<LoadPrimitive<Serializer,T> >, mpl::identity<LoadPrimitive<Serializer,T> >,
@ -782,7 +782,7 @@ public:
nonConstT &hlp = const_cast<nonConstT&>(data); nonConstT &hlp = const_cast<nonConstT&>(data);
hlp.serialize(*this,fileVersion); hlp.serialize(*this,fileVersion);
//data.serialize(*this,myVersion); //data.serialize(*this,myVersion);
} }
template <typename T> template <typename T>
void loadSerializable(T &data) void loadSerializable(T &data)
@ -806,7 +806,7 @@ public:
data = NULL; data = NULL;
return; return;
} }
if(smartVectorMembersSerialization) if(smartVectorMembersSerialization)
{ {
typedef typename boost::remove_const<typename boost::remove_pointer<T>::type>::type TObjectType; //eg: const CGHeroInstance * => CGHeroInstance typedef typename boost::remove_const<typename boost::remove_pointer<T>::type>::type TObjectType; //eg: const CGHeroInstance * => CGHeroInstance
@ -830,7 +830,7 @@ public:
return; return;
} }
ui32 pid = 0xffffffff; //pointer id (or maybe rather pointee id) ui32 pid = 0xffffffff; //pointer id (or maybe rather pointee id)
if(smartPointerSerialization) if(smartPointerSerialization)
{ {
*this >> pid; //get the id *this >> pid; //get the id
@ -1081,7 +1081,7 @@ template<typename T>
class CApplier class CApplier
{ {
public: public:
std::map<ui16,T*> apps; std::map<ui16,T*> apps;
~CApplier() ~CApplier()
{ {

View File

@ -217,7 +217,7 @@ struct DLL_LINKAGE Bonus
enum BonusDuration //when bonus is automatically removed enum BonusDuration //when bonus is automatically removed
{ {
PERMANENT = 1, PERMANENT = 1,
ONE_BATTLE = 2, //at the end of battle ONE_BATTLE = 2, //at the end of battle
ONE_DAY = 4, //at the end of day ONE_DAY = 4, //at the end of day
ONE_WEEK = 8, //at the end of week (bonus lasts till the end of week, thats NOT 7 days ONE_WEEK = 8, //at the end of week (bonus lasts till the end of week, thats NOT 7 days
N_TURNS = 16, //used during battles, after battle bonus is always removed N_TURNS = 16, //used during battles, after battle bonus is always removed
@ -236,7 +236,7 @@ struct DLL_LINKAGE Bonus
enum LimitEffect enum LimitEffect
{ {
NO_LIMIT = 0, NO_LIMIT = 0,
ONLY_DISTANCE_FIGHT=1, ONLY_MELEE_FIGHT, //used to mark bonuses for attack/defense primary skills from spells like Precision (distance only) ONLY_DISTANCE_FIGHT=1, ONLY_MELEE_FIGHT, //used to mark bonuses for attack/defense primary skills from spells like Precision (distance only)
ONLY_ENEMY_ARMY ONLY_ENEMY_ARMY
}; };
@ -265,7 +265,7 @@ struct DLL_LINKAGE Bonus
TLimiterPtr limiter; TLimiterPtr limiter;
TPropagatorPtr propagator; TPropagatorPtr propagator;
std::string description; std::string description;
Bonus(ui16 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype=-1); Bonus(ui16 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype=-1);
Bonus(ui16 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, si32 Subtype=-1, ui8 ValType = ADDITIVE_VALUE); Bonus(ui16 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, si32 Subtype=-1, ui8 ValType = ADDITIVE_VALUE);
@ -357,7 +357,7 @@ private:
public: public:
BonusList(bool BelongsToTree = false); BonusList(bool BelongsToTree = false);
BonusList(const BonusList &bonusList); BonusList(const BonusList &bonusList);
BonusList& operator=(const BonusList &bonusList); BonusList& operator=(const BonusList &bonusList);
// wrapper functions of the STL vector container // wrapper functions of the STL vector container
std::vector<Bonus*>::size_type size() const { return bonuses.size(); } std::vector<Bonus*>::size_type size() const { return bonuses.size(); }
@ -393,7 +393,7 @@ public:
//void limit(const CBonusSystemNode &node); //erases bonuses using limitor //void limit(const CBonusSystemNode &node); //erases bonuses using limitor
void eliminateDuplicates(); void eliminateDuplicates();
// remove_if implementation for STL vector types // remove_if implementation for STL vector types
template <class Predicate> template <class Predicate>
void remove_if(Predicate pred) void remove_if(Predicate pred)
@ -409,7 +409,7 @@ public:
bonuses.resize(newList.size()); bonuses.resize(newList.size());
std::copy(newList.begin(), newList.end(), bonuses.begin()); std::copy(newList.begin(), newList.end(), bonuses.begin());
} }
template <class InputIterator> template <class InputIterator>
void insert(const int position, InputIterator first, InputIterator last); void insert(const int position, InputIterator first, InputIterator last);
@ -465,7 +465,7 @@ public:
CPropagatorNodeType(); CPropagatorNodeType();
CPropagatorNodeType(ui8 NodeType); CPropagatorNodeType(ui8 NodeType);
bool shouldBeAttached(CBonusSystemNode *dest); bool shouldBeAttached(CBonusSystemNode *dest);
//CBonusSystemNode *getDestNode(CBonusSystemNode *source, CBonusSystemNode *redParent, CBonusSystemNode *redChild) OVERRIDE; //CBonusSystemNode *getDestNode(CBonusSystemNode *source, CBonusSystemNode *redParent, CBonusSystemNode *redChild) OVERRIDE;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
@ -479,7 +479,7 @@ struct BonusLimitationContext
const CBonusSystemNode &node; const CBonusSystemNode &node;
const BonusList &alreadyAccepted; const BonusList &alreadyAccepted;
}; };
class DLL_LINKAGE ILimiter class DLL_LINKAGE ILimiter
{ {
public: public:
@ -500,7 +500,7 @@ public:
// * selector is predicate that tests if HeroBonus matches our criteria // * selector is predicate that tests if HeroBonus matches our criteria
// * root is node on which call was made (NULL will be replaced with this) // * root is node on which call was made (NULL will be replaced with this)
//interface //interface
virtual const TBonusListPtr getAllBonuses(const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root = NULL, const std::string &cachingStr = "") const = 0; virtual const TBonusListPtr getAllBonuses(const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root = NULL, const std::string &cachingStr = "") const = 0;
void getModifiersWDescr(TModDescr &out, const CSelector &selector, const std::string &cachingStr = "") const; //out: pairs<modifier value, modifier description> void getModifiersWDescr(TModDescr &out, const CSelector &selector, const std::string &cachingStr = "") const; //out: pairs<modifier value, modifier description>
int getBonusesCount(const CSelector &selector, const std::string &cachingStr = "") const; int getBonusesCount(const CSelector &selector, const std::string &cachingStr = "") const;
int valOfBonuses(const CSelector &selector, const std::string &cachingStr = "") const; int valOfBonuses(const CSelector &selector, const std::string &cachingStr = "") const;
@ -508,7 +508,7 @@ public:
const TBonusListPtr getBonuses(const CSelector &selector, const CSelector &limit, const std::string &cachingStr = "") const; const TBonusListPtr getBonuses(const CSelector &selector, const CSelector &limit, const std::string &cachingStr = "") const;
const TBonusListPtr getBonuses(const CSelector &selector, const std::string &cachingStr = "") const; const TBonusListPtr getBonuses(const CSelector &selector, const std::string &cachingStr = "") const;
//legacy interface //legacy interface
int valOfBonuses(Bonus::BonusType type, const CSelector &selector) const; int valOfBonuses(Bonus::BonusType type, const CSelector &selector) const;
int valOfBonuses(Bonus::BonusType type, int subtype = -1) const; //subtype -> subtype of bonus, if -1 then anyt; int valOfBonuses(Bonus::BonusType type, int subtype = -1) const; //subtype -> subtype of bonus, if -1 then anyt;
bool hasBonusOfType(Bonus::BonusType type, int subtype = -1) const;//determines if hero has a bonus of given type (and optionally subtype) bool hasBonusOfType(Bonus::BonusType type, int subtype = -1) const;//determines if hero has a bonus of given type (and optionally subtype)
@ -540,16 +540,16 @@ private:
TNodesVector parents; //parents -> we inherit bonuses from them, we may attach our bonuses to them TNodesVector parents; //parents -> we inherit bonuses from them, we may attach our bonuses to them
TNodesVector children; TNodesVector children;
ui8 nodeType; ui8 nodeType;
std::string description; std::string description;
static const bool cachingEnabled; static const bool cachingEnabled;
mutable BonusList cachedBonuses; mutable BonusList cachedBonuses;
mutable int cachedLast; mutable int cachedLast;
static int treeChanged; static int treeChanged;
// Setting a value to cachingStr before getting any bonuses caches the result for later requests. // Setting a value to cachingStr before getting any bonuses caches the result for later requests.
// This string needs to be unique, that's why it has to be setted in the following manner: // This string needs to be unique, that's why it has to be setted in the following manner:
// [property key]_[value] => only for selector // [property key]_[value] => only for selector
mutable std::map<std::string, TBonusListPtr > cachedRequests; mutable std::map<std::string, TBonusListPtr > cachedRequests;
@ -562,7 +562,7 @@ public:
explicit CBonusSystemNode(); explicit CBonusSystemNode();
virtual ~CBonusSystemNode(); virtual ~CBonusSystemNode();
void limitBonuses(const BonusList &allBonuses, BonusList &out) const; //out will bo populed with bonuses that are not limited here void limitBonuses(const BonusList &allBonuses, BonusList &out) const; //out will bo populed with bonuses that are not limited here
TBonusListPtr limitBonuses(const BonusList &allBonuses) const; //same as above, returns out by val for convienence TBonusListPtr limitBonuses(const BonusList &allBonuses) const; //same as above, returns out by val for convienence
const TBonusListPtr getAllBonuses(const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root = NULL, const std::string &cachingStr = "") const; const TBonusListPtr getAllBonuses(const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root = NULL, const std::string &cachingStr = "") const;
@ -573,8 +573,8 @@ public:
void getParents(TNodes &out); //retrieves list of parent nodes (nodes to inherit bonuses from) void getParents(TNodes &out); //retrieves list of parent nodes (nodes to inherit bonuses from)
void getRedParents(TNodes &out); //retrieves list of red parent nodes (nodes bonuses propagate from) void getRedParents(TNodes &out); //retrieves list of red parent nodes (nodes bonuses propagate from)
void getRedAncestors(TNodes &out); void getRedAncestors(TNodes &out);
void getRedChildren(TNodes &out); void getRedChildren(TNodes &out);
void getRedDescendants(TNodes &out); void getRedDescendants(TNodes &out);
Bonus *getBonus(const CSelector &selector); Bonus *getBonus(const CSelector &selector);
void attachTo(CBonusSystemNode *parent); void attachTo(CBonusSystemNode *parent);
@ -604,7 +604,7 @@ public:
void deserializationFix(); void deserializationFix();
void exportBonus(Bonus * b); void exportBonus(Bonus * b);
void exportBonuses(); void exportBonuses();
static void incrementTreeChangedNum(); static void incrementTreeChangedNum();
BonusList &getBonusList(); BonusList &getBonusList();
const BonusList &getBonusList() const; const BonusList &getBonusList() const;
@ -628,7 +628,7 @@ public:
} }
enum ENodeTypes enum ENodeTypes
{ {
UNKNOWN, STACK_INSTANCE, STACK_BATTLE, SPECIALITY, ARTIFACT, CREATURE, ARTIFACT_INSTANCE, HERO, PLAYER, TEAM, UNKNOWN, STACK_INSTANCE, STACK_BATTLE, SPECIALITY, ARTIFACT, CREATURE, ARTIFACT_INSTANCE, HERO, PLAYER, TEAM,
TOWN_AND_VISITOR, BATTLE TOWN_AND_VISITOR, BATTLE
}; };
}; };
@ -641,7 +641,7 @@ namespace NBonus
//DLL_LINKAGE const HeroBonus * get(const CBonusSystemNode *obj, int from, int id ); //DLL_LINKAGE const HeroBonus * get(const CBonusSystemNode *obj, int from, int id );
DLL_LINKAGE void getModifiersWDescr(const CBonusSystemNode *obj, TModDescr &out, Bonus::BonusType type, int subtype = -1 ); //out: pairs<modifier value, modifier description> DLL_LINKAGE void getModifiersWDescr(const CBonusSystemNode *obj, TModDescr &out, Bonus::BonusType type, int subtype = -1 ); //out: pairs<modifier value, modifier description>
DLL_LINKAGE int getCount(const CBonusSystemNode *obj, int from, int id); DLL_LINKAGE int getCount(const CBonusSystemNode *obj, int from, int id);
}; }
/// generates HeroBonus from given data /// generates HeroBonus from given data
inline Bonus makeFeatureVal(Bonus::BonusType type, ui8 duration, si16 subtype, si32 value, Bonus::BonusSource source, ui16 turnsRemain = 0, si32 additionalInfo = 0) inline Bonus makeFeatureVal(Bonus::BonusType type, ui8 duration, si16 subtype, si32 value, Bonus::BonusSource source, ui16 turnsRemain = 0, si32 additionalInfo = 0)
@ -725,7 +725,7 @@ public:
{ {
return turnsRequested <= 0 //every present effect will last zero (or "less") turns return turnsRequested <= 0 //every present effect will last zero (or "less") turns
|| !(bonus->duration & Bonus::N_TURNS) //so do every not expriing after N-turns effect || !(bonus->duration & Bonus::N_TURNS) //so do every not expriing after N-turns effect
|| bonus->turnsRemain > turnsRequested; || bonus->turnsRemain > turnsRequested;
} }
CWillLastTurns& operator()(const int &setVal) CWillLastTurns& operator()(const int &setVal)
{ {
@ -769,7 +769,7 @@ public:
} }
}; };
class DLL_LINKAGE CreatureNativeTerrainLimiter : public ILimiter //applies only to creatures that are on their native terrain class DLL_LINKAGE CreatureNativeTerrainLimiter : public ILimiter //applies only to creatures that are on their native terrain
{ {
public: public:
si8 terrainType; si8 terrainType;

View File

@ -48,7 +48,7 @@ struct CPack
{ {
tlog1 << "CPack serialized... this should not happen!\n"; tlog1 << "CPack serialized... this should not happen!\n";
} }
DLL_LINKAGE void applyGs(CGameState *gs) void applyGs(CGameState *gs)
{}; {};
}; };
@ -60,7 +60,7 @@ struct CPackForClient : public CPack
void applyFirstCl(CClient *cl)//called before applying to gs void applyFirstCl(CClient *cl)//called before applying to gs
{}; {};
void applyCl(CClient *cl)//called after applying to gs void applyCl(CClient *cl)//called after applying to gs
{}; {};
}; };
struct CPackForServer : public CPack struct CPackForServer : public CPack
@ -70,7 +70,7 @@ struct CPackForServer : public CPack
CGameState* GS(CGameHandler *gh); CGameState* GS(CGameHandler *gh);
CPackForServer() CPackForServer()
{ {
type = 2; type = 2;
c = NULL; c = NULL;
player = 255; player = 255;
}; };
@ -82,7 +82,7 @@ struct CPackForServer : public CPack
struct Query : public CPackForClient struct Query : public CPackForClient
{ {
ui32 queryID; // equals to -1 if it is not an actual query (and should not be answered) ui32 queryID; // equals to -1 if it is not an actual query (and should not be answered)
Query() Query()
{ {
queryID = -1; queryID = -1;
@ -95,7 +95,7 @@ struct MetaString : public CPack //2001 helper for object scrips
private: private:
enum EMessage {TEXACT_STRING, TLOCAL_STRING, TNUMBER, TREPLACE_ESTRING, TREPLACE_LSTRING, TREPLACE_NUMBER, TREPLACE_PLUSNUMBER}; enum EMessage {TEXACT_STRING, TLOCAL_STRING, TNUMBER, TREPLACE_ESTRING, TREPLACE_LSTRING, TREPLACE_NUMBER, TREPLACE_PLUSNUMBER};
public: public:
enum {GENERAL_TXT=1, XTRAINFO_TXT, OBJ_NAMES, RES_NAMES, ART_NAMES, ARRAY_TXT, CRE_PL_NAMES, CREGENS, MINE_NAMES, enum {GENERAL_TXT=1, XTRAINFO_TXT, OBJ_NAMES, RES_NAMES, ART_NAMES, ARRAY_TXT, CRE_PL_NAMES, CREGENS, MINE_NAMES,
MINE_EVNTS, ADVOB_TXT, ART_EVNTS, SPELL_NAME, SEC_SKILL_NAME, CRE_SING_NAMES, CREGENS4, COLOR, ART_DESCR}; MINE_EVNTS, ADVOB_TXT, ART_EVNTS, SPELL_NAME, SEC_SKILL_NAME, CRE_SING_NAMES, CREGENS4, COLOR, ART_DESCR};
std::vector<ui8> message; //vector of EMessage std::vector<ui8> message; //vector of EMessage
@ -169,7 +169,7 @@ public:
{ {
type = 2001; type = 2001;
} }
}; };
struct StackLocation struct StackLocation
{ {
@ -276,16 +276,16 @@ struct SetResource : public CPackForClient //102
{ {
h & player & resid & val; h & player & resid & val;
} }
}; };
struct SetResources : public CPackForClient //104 struct SetResources : public CPackForClient //104
{ {
SetResources(){type = 104;}; SetResources(){type = 104;};
void applyCl(CClient *cl); void applyCl(CClient *cl);
DLL_LINKAGE void applyGs(CGameState *gs); DLL_LINKAGE void applyGs(CGameState *gs);
ui8 player; ui8 player;
TResources res; //res[resid] => res amount TResources res; //res[resid] => res amount
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & player & res; h & player & res;
@ -307,7 +307,7 @@ struct SetPrimSkill : public CPackForClient //105
{ {
h & abs & id & which & val; h & abs & id & which & val;
} }
}; };
struct SetSecSkill : public CPackForClient //106 struct SetSecSkill : public CPackForClient //106
{ {
SetSecSkill(){type = 106;}; SetSecSkill(){type = 106;};
@ -344,7 +344,7 @@ struct HeroVisitCastle : public CPackForClient //108
{ {
h & flags & tid & hid; h & flags & tid & hid;
} }
}; };
struct ChangeSpells : public CPackForClient //109 struct ChangeSpells : public CPackForClient //109
{ {
ChangeSpells(){type = 109;}; ChangeSpells(){type = 109;};
@ -359,7 +359,7 @@ struct ChangeSpells : public CPackForClient //109
{ {
h & learn & hid & spells; h & learn & hid & spells;
} }
}; };
struct SetMana : public CPackForClient //110 struct SetMana : public CPackForClient //110
{ {
@ -402,7 +402,7 @@ struct FoWChange : public CPackForClient //112
{ {
h & tiles & player & mode; h & tiles & player & mode;
} }
}; };
struct SetAvailableHeroes : public CPackForClient //113 struct SetAvailableHeroes : public CPackForClient //113
{ {
@ -431,7 +431,7 @@ struct GiveBonus : public CPackForClient //115
{ {
GiveBonus(ui8 Who = 0) GiveBonus(ui8 Who = 0)
{ {
who = Who; who = Who;
type = 115; type = 115;
} }
@ -454,7 +454,7 @@ struct ChangeObjPos : public CPackForClient //116
{ {
ChangeObjPos() ChangeObjPos()
{ {
type = 116; type = 116;
flags = 0; flags = 0;
} }
void applyFirstCl(CClient *cl); void applyFirstCl(CClient *cl);
@ -495,7 +495,7 @@ struct RemoveBonus : public CPackForClient //118
{ {
RemoveBonus(ui8 Who = 0) RemoveBonus(ui8 Who = 0)
{ {
who = Who; who = Who;
type = 118; type = 118;
} }
@ -584,7 +584,7 @@ struct RemoveObject : public CPackForClient //500
{ {
h & id; h & id;
} }
}; };
struct TryMoveHero : public CPackForClient //501 struct TryMoveHero : public CPackForClient //501
{ {
TryMoveHero(){type = 501;humanKnows=false; attackedFrom = int3(-1, -1, -1);}; TryMoveHero(){type = 501;humanKnows=false; attackedFrom = int3(-1, -1, -1);};
@ -616,24 +616,24 @@ struct TryMoveHero : public CPackForClient //501
// SetGarrisons(){type = 502;}; // SetGarrisons(){type = 502;};
// void applyCl(CClient *cl); // void applyCl(CClient *cl);
// DLL_LINKAGE void applyGs(CGameState *gs); // DLL_LINKAGE void applyGs(CGameState *gs);
// //
// std::map<ui32,CCreatureSet> garrs; // std::map<ui32,CCreatureSet> garrs;
// //
// template <typename Handler> void serialize(Handler &h, const int version) // template <typename Handler> void serialize(Handler &h, const int version)
// { // {
// h & garrs; // h & garrs;
// } // }
// }; // };
struct NewStructures : public CPackForClient //504 struct NewStructures : public CPackForClient //504
{ {
NewStructures(){type = 504;}; NewStructures(){type = 504;};
void applyCl(CClient *cl); void applyCl(CClient *cl);
DLL_LINKAGE virtual void applyGs(CGameState *gs); DLL_LINKAGE void applyGs(CGameState *gs);
si32 tid; si32 tid;
std::set<si32> bid; std::set<si32> bid;
si16 builded; si16 builded;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
@ -648,7 +648,7 @@ struct RazeStructures : public CPackForClient //505
si32 tid; si32 tid;
std::set<si32> bid; std::set<si32> bid;
si16 destroyed; si16 destroyed;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
@ -668,7 +668,7 @@ struct SetAvailableCreatures : public CPackForClient //506
{ {
h & tid & creatures; h & tid & creatures;
} }
}; };
struct SetHeroesInTown : public CPackForClient //508 struct SetHeroesInTown : public CPackForClient //508
{ {
SetHeroesInTown(){type = 508;}; SetHeroesInTown(){type = 508;};
@ -689,19 +689,19 @@ struct SetHeroesInTown : public CPackForClient //508
// void applyCl(CClient *cl); // void applyCl(CClient *cl);
// DLL_LINKAGE void applyGs(CGameState *gs); // DLL_LINKAGE void applyGs(CGameState *gs);
// DLL_LINKAGE void setArtAtPos(ui16 pos, const CArtifact* art); // DLL_LINKAGE void setArtAtPos(ui16 pos, const CArtifact* art);
// //
// si32 hid; // si32 hid;
// std::vector<const CArtifact*> artifacts; //hero's artifacts from bag // std::vector<const CArtifact*> artifacts; //hero's artifacts from bag
// std::map<ui16, const CArtifact*> artifWorn; //map<position,artifact_id>; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5 // std::map<ui16, const CArtifact*> artifWorn; //map<position,artifact_id>; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
// //
// template <typename Handler> void serialize(Handler &h, const int version) // template <typename Handler> void serialize(Handler &h, const int version)
// { // {
// h & hid & artifacts & artifWorn; // h & hid & artifacts & artifWorn;
// } // }
// //
// std::vector<const CArtifact*> equipped, unequipped; //used locally // std::vector<const CArtifact*> equipped, unequipped; //used locally
// BonusList gained, lost; //used locally as hlp when applying // BonusList gained, lost; //used locally as hlp when applying
// }; // };
struct HeroRecruited : public CPackForClient //515 struct HeroRecruited : public CPackForClient //515
{ {
@ -717,7 +717,7 @@ struct HeroRecruited : public CPackForClient //515
{ {
h & hid & tid & tile & player; h & hid & tid & tile & player;
} }
}; };
struct GiveHero : public CPackForClient //516 struct GiveHero : public CPackForClient //516
{ {
@ -733,7 +733,7 @@ struct GiveHero : public CPackForClient //516
{ {
h & id & player; h & id & player;
} }
}; };
struct OpenWindow : public CPackForClient //517 struct OpenWindow : public CPackForClient //517
{ {
@ -1072,7 +1072,7 @@ struct NewTurn : public CPackForClient //101
{ {
h & heroes & cres & res & day & resetBuilded & specialWeek & creatureid; h & heroes & cres & res & day & resetBuilded & specialWeek & creatureid;
} }
}; };
struct Component : public CPack //2002 helper for object scrips informations struct Component : public CPack //2002 helper for object scrips informations
{ {
@ -1110,10 +1110,10 @@ struct InfoWindow : public CPackForClient //103 - displays simple info window
{ {
h & text & components & player & soundID; h & text & components & player & soundID;
} }
InfoWindow() InfoWindow()
{ {
type = 103; type = 103;
soundID = 0; soundID = 0;
} }
}; };
@ -1134,7 +1134,7 @@ struct SetObjectProperty : public CPackForClient//1001
ui32 val; ui32 val;
SetObjectProperty(){type = 1001;}; SetObjectProperty(){type = 1001;};
SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;}; SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & id & what & val; h & id & what & val;
@ -1149,7 +1149,7 @@ struct SetHoverName : public CPackForClient//1002
MetaString name; MetaString name;
SetHoverName(){type = 1002;}; SetHoverName(){type = 1002;};
SetHoverName(ui32 ID, MetaString& Name):id(ID),name(Name){type = 1002;}; SetHoverName(ui32 ID, MetaString& Name):id(ID),name(Name){type = 1002;};
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & id & name; h & id & name;
@ -1165,7 +1165,7 @@ struct HeroLevelUp : public Query//2000
std::vector<ui16> skills; std::vector<ui16> skills;
HeroLevelUp(){type = 2000;}; HeroLevelUp(){type = 2000;};
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & queryID & heroid & primskill & level & skills; h & queryID & heroid & primskill & level & skills;
@ -1273,14 +1273,14 @@ struct BattleStart : public CPackForClient//3000
BattleInfo * info; BattleInfo * info;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & info; h & info;
} }
}; };
struct BattleNextRound : public CPackForClient//3001 struct BattleNextRound : public CPackForClient//3001
{ {
BattleNextRound(){type = 3001;}; BattleNextRound(){type = 3001;};
void applyFirstCl(CClient *cl); void applyFirstCl(CClient *cl);
void applyCl(CClient *cl); void applyCl(CClient *cl);
@ -1874,7 +1874,7 @@ struct GarrisonHeroSwap : public CPackForServer
{ {
GarrisonHeroSwap(){}; GarrisonHeroSwap(){};
GarrisonHeroSwap(si32 TID):tid(TID){}; GarrisonHeroSwap(si32 TID):tid(TID){};
si32 tid; si32 tid;
bool applyGh(CGameHandler *gh); bool applyGh(CGameHandler *gh);
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
@ -1971,7 +1971,7 @@ struct HireHero : public CPackForServer
} }
}; };
struct BuildBoat : public CPackForServer struct BuildBoat : public CPackForServer
{ {
BuildBoat(){}; BuildBoat(){};
si32 objid; //where player wants to buy a boat si32 objid; //where player wants to buy a boat
@ -2084,7 +2084,7 @@ struct PlayerMessage : public CPackForClient, public CPackForServer //513
{ {
h & text & player; h & text & player;
} }
}; };
struct SetSelection : public CPackForClient, public CPackForServer //514 struct SetSelection : public CPackForClient, public CPackForServer //514
@ -2241,7 +2241,7 @@ struct RequestOptionsChange : public CPregamePackToHost
{ {
enum {TOWN, HERO, BONUS}; enum {TOWN, HERO, BONUS};
ui8 what; ui8 what;
si8 direction; //-1 or +1 si8 direction; //-1 or +1
ui8 playerID; ui8 playerID;
RequestOptionsChange(ui8 What, si8 Dir, ui8 Player) RequestOptionsChange(ui8 What, si8 Dir, ui8 Player)

View File

@ -10,7 +10,7 @@ namespace Res
class ResourceSet; class ResourceSet;
bool canAfford(const ResourceSet &res, const ResourceSet &price); //can a be used to pay price b bool canAfford(const ResourceSet &res, const ResourceSet &price); //can a be used to pay price b
enum ERes enum ERes
{ {
WOOD = 0, MERCURY, ORE, SULFUR, CRYSTAL, GEMS, GOLD, MITHRIL WOOD = 0, MERCURY, ORE, SULFUR, CRYSTAL, GEMS, GOLD, MITHRIL
}; };
@ -25,7 +25,7 @@ namespace Res
#define scalarOperator(OPSIGN) \ #define scalarOperator(OPSIGN) \
DLL_LINKAGE ResourceSet operator OPSIGN(const TResource &rhs) const \ ResourceSet operator OPSIGN(const TResource &rhs) const \
{ \ { \
ResourceSet ret = *this; \ ResourceSet ret = *this; \
for(int i = 0; i < size(); i++) \ for(int i = 0; i < size(); i++) \
@ -37,7 +37,7 @@ namespace Res
#define vectorOperator(OPSIGN) \ #define vectorOperator(OPSIGN) \
DLL_LINKAGE ResourceSet operator OPSIGN(const ResourceSet &rhs) const \ ResourceSet operator OPSIGN(const ResourceSet &rhs) const \
{ \ { \
ResourceSet ret = *this; \ ResourceSet ret = *this; \
for(int i = 0; i < size(); i++) \ for(int i = 0; i < size(); i++) \
@ -48,7 +48,7 @@ namespace Res
#define opEqOperator(OPSIGN, RHS_TYPE) \ #define opEqOperator(OPSIGN, RHS_TYPE) \
DLL_LINKAGE ResourceSet& operator OPSIGN ## =(const RHS_TYPE &rhs) \ ResourceSet& operator OPSIGN ## =(const RHS_TYPE &rhs) \
{ \ { \
return *this = *this OPSIGN rhs; \ return *this = *this OPSIGN rhs; \
} }
@ -70,7 +70,7 @@ namespace Res
#undef opEqOperator #undef opEqOperator
//to be used for calculations of type "how many units of sth can I afford?" //to be used for calculations of type "how many units of sth can I afford?"
DLL_LINKAGE int operator/(const ResourceSet &rhs) int operator/(const ResourceSet &rhs)
{ {
int ret = INT_MAX; int ret = INT_MAX;
for(int i = 0; i < size(); i++) for(int i = 0; i < size(); i++)
@ -80,7 +80,7 @@ namespace Res
return ret; return ret;
} }
DLL_LINKAGE ResourceSet & operator=(const TResource &rhs) ResourceSet & operator=(const TResource &rhs)
{ {
for(int i = 0; i < size(); i++) for(int i = 0; i < size(); i++)
at(i) = rhs; at(i) = rhs;
@ -88,14 +88,14 @@ namespace Res
return *this; return *this;
} }
// WARNING: comparison operators are used for "can afford" relation: a <= b means that foreach i a[i] <= b[i] // WARNING: comparison operators are used for "can afford" relation: a <= b means that foreach i a[i] <= b[i]
// that doesn't work the other way: a > b doesn't mean that a cannot be afforded with b, it's still b can afford a // that doesn't work the other way: a > b doesn't mean that a cannot be afforded with b, it's still b can afford a
// bool operator<(const ResourceSet &rhs) // bool operator<(const ResourceSet &rhs)
// { // {
// for(int i = 0; i < size(); i++) // for(int i = 0; i < size(); i++)
// if(at(i) >= rhs[i]) // if(at(i) >= rhs[i])
// return false; // return false;
// //
// return true; // return true;
// } // }
@ -118,7 +118,7 @@ namespace Res
} cur; } cur;
const ResourceSet &rs; const ResourceSet &rs;
void advance(); void advance();
public: public:
nziterator(const ResourceSet &RS); nziterator(const ResourceSet &RS);
bool valid(); bool valid();
@ -126,7 +126,7 @@ namespace Res
nziterator operator++(int); nziterator operator++(int);
const ResEntry& operator*() const; const ResEntry& operator*() const;
const ResEntry* operator->() const; const ResEntry* operator->() const;
}; };
}; };
} }