From cc631b1362f26e09bb0f522b70a4210bd4ef4b15 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Thu, 16 Apr 2009 11:14:13 +0000 Subject: [PATCH] * next ubuntux's patch * normalized line endings (CR+LF) * translated comments in CMessage.cpp --- AI_Base.h | 24 +- AdventureMapButton.h | 206 +++--- CCallback.h | 408 +++++------ CCastleInterface.h | 464 ++++++------- CConsoleHandler.h | 88 +-- CCursorHandler.h | 62 +- CGameInfo.h | 132 ++-- CGameInterface.h | 240 +++---- CMessage.cpp | 182 ++--- CMessage.h | 142 ++-- CPreGame.h | 606 ++++++++--------- CThreadHelper.h | 94 +-- SDL_Extensions.h | 164 ++--- StartInfo.h | 128 ++-- client/CBitmapHandler.h | 92 +-- client/CConfigHandler.h | 142 ++-- client/CCreatureAnimation.h | 126 ++-- client/CSpellWindow.h | 190 +++--- client/Graphics.h | 146 ++-- hch/CBuildingHandler.h | 86 +-- hch/CCreatureHandler.h | 178 ++--- hch/CDefHandler.h | 126 ++-- hch/CDefObjInfoHandler.h | 126 ++-- hch/CLodHandler.h | 128 ++-- hch/CMusicHandler.h | 46 +- hch/CSndHandler.h | 126 ++-- hch/CSpellHandler.h | 110 +-- hch/CTownHandler.h | 152 ++--- int3.h | 270 ++++---- lib/BattleAction.h | 36 +- lib/CondSh.h | 36 +- lib/Connection.h | 1282 +++++++++++++++++------------------ lib/VCMI_Lib.h | 130 ++-- mapHandler.h | 244 +++---- server/CVCMIServer.h | 76 +-- timeHandler.h | 40 +- 36 files changed, 3428 insertions(+), 3400 deletions(-) diff --git a/AI_Base.h b/AI_Base.h index 80dc15667..4896d8acf 100644 --- a/AI_Base.h +++ b/AI_Base.h @@ -1,10 +1,10 @@ -#ifndef __AI_BASE_H__ -#define __AI_BASE_H__ - -#include -#include -#include "CGameInterface.h" - +#ifndef __AI_BASE_H__ +#define __AI_BASE_H__ + +#include +#include +#include "CGameInterface.h" + /* * AI_Base.h, part of VCMI engine * @@ -13,8 +13,8 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -#define AI_INTERFACE_VER 1 - -#endif // __AI_BASE_H__ + */ + +#define AI_INTERFACE_VER 1 + +#endif // __AI_BASE_H__ diff --git a/AdventureMapButton.h b/AdventureMapButton.h index fc376e45e..fce502919 100644 --- a/AdventureMapButton.h +++ b/AdventureMapButton.h @@ -1,12 +1,12 @@ -#ifndef __ADVENTUREMAPBUTTON_H__ -#define __ADVENTUREMAPBUTTON_H__ - - - -#include "CPlayerInterface.h" -#include "client/FunctionList.h" -#include - +#ifndef __ADVENTUREMAPBUTTON_H__ +#define __ADVENTUREMAPBUTTON_H__ + + + +#include "CPlayerInterface.h" +#include "client/FunctionList.h" +#include + /* * AdventureMapButton.h, part of VCMI engine * @@ -15,97 +15,97 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -namespace config{struct ButtonInfo;} - -class AdventureMapButton - : public ClickableR, public Hoverable, public KeyShortcut, public CButtonBase -{ -public: - std::map hoverTexts; //state -> text for statusbar - std::string helpBox; //for right-click help - CFunctionList callback; - bool colorChange, - actOnDown; //runs when mouse is pressed down over it, not when up - ui8 blocked; - - void clickRight (tribool down); - virtual void clickLeft (tribool down); - void hover (bool on); - void block(ui8 on); //if button is blocked then it'll change it's graphic to inactive (offset==2) and won't react on l-clicks - void activate(); // makes button active - void deactivate(); // makes button inactive (but doesn't delete) - - AdventureMapButton(); //c-tor - AdventureMapButton( const std::map &, const std::string &HelpBox, const CFunctionList &Callback, int x, int y, const std::string &defName, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor - AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &Callback, int x, int y, const std::string &defName, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor - AdventureMapButton( const std::pair help, const CFunctionList &Callback, int x, int y, const std::string &defName, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor - AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &Callback, config::ButtonInfo *info, int key=0);//c-tor - //AdventureMapButton( std::string Name, std::string HelpBox, boost::function Callback, int x, int y, std::string defName, bool activ=false, std::vector * add = NULL, bool playerColoredButton = false );//c-tor - - void init(const CFunctionList &Callback, const std::map &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector * add, int x, int y, int key ); -}; - -class CHighlightableButton - : public AdventureMapButton -{ -public: - CHighlightableButton(const CFunctionList &onSelect, const CFunctionList &onDeselect, const std::map &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector * add, int x, int y, int key=0 ); - bool selected, onlyOn; - CFunctionList callback2; //when disselecting - void select(bool on); - void clickLeft (tribool down); -}; - -class CHighlightableButtonsGroup -{ -public: - CFunctionList2 onChange; //called when changing selected button with new button's id - std::vector buttons; - - //void addButton(const std::map &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid); - void addButton(CHighlightableButton* bt);//add existing button, it'll be deleted by CHighlightableButtonsGroup destructor - void addButton(const std::map &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList &OnSelect=0, int key=0); //creates new button - CHighlightableButtonsGroup(const CFunctionList2 &OnChange); - ~CHighlightableButtonsGroup(); - void activate(); - void deactivate(); - void select(int id, bool mode); //mode==0: id is serial; mode==1: id is unique button id - void selectionChanged(int to); - void show(SDL_Surface * to); -}; - - -class CSlider : public IShowable, public MotionInterested, public ClickableL -{ -public: - AdventureMapButton left, right, slider; //if vertical then left=up - int capacity,//how many elements can be active at same time - amount, //how many elements - value; //first active element - bool horizontal, moving; - CDefEssential *imgs ; - - boost::function moved; - //void(T::*moved)(int to); - //T* owner; - - void redrawSlider(); - - void sliderClicked(); - void moveLeft(); - void clickLeft (tribool down); - void mouseMoved (const SDL_MouseMotionEvent & sEvent); - void moveRight(); - void moveTo(int to); - void block(bool on); - void activate(); // makes button active - void deactivate(); // makes button inactive (but doesn't delete) - void show(SDL_Surface * to); - CSlider(int x, int y, int totalw, boost::function Moved, int Capacity, int Amount, - int Value=0, bool Horizontal=true); - ~CSlider(); -}; - -#endif // __ADVENTUREMAPBUTTON_H__ + */ + +namespace config{struct ButtonInfo;} + +class AdventureMapButton + : public ClickableR, public Hoverable, public KeyShortcut, public CButtonBase +{ +public: + std::map hoverTexts; //state -> text for statusbar + std::string helpBox; //for right-click help + CFunctionList callback; + bool colorChange, + actOnDown; //runs when mouse is pressed down over it, not when up + ui8 blocked; + + void clickRight (tribool down); + virtual void clickLeft (tribool down); + void hover (bool on); + void block(ui8 on); //if button is blocked then it'll change it's graphic to inactive (offset==2) and won't react on l-clicks + void activate(); // makes button active + void deactivate(); // makes button inactive (but doesn't delete) + + AdventureMapButton(); //c-tor + AdventureMapButton( const std::map &, const std::string &HelpBox, const CFunctionList &Callback, int x, int y, const std::string &defName, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor + AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &Callback, int x, int y, const std::string &defName, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor + AdventureMapButton( const std::pair help, const CFunctionList &Callback, int x, int y, const std::string &defName, int key=0, std::vector * add = NULL, bool playerColoredButton = false );//c-tor + AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList &Callback, config::ButtonInfo *info, int key=0);//c-tor + //AdventureMapButton( std::string Name, std::string HelpBox, boost::function Callback, int x, int y, std::string defName, bool activ=false, std::vector * add = NULL, bool playerColoredButton = false );//c-tor + + void init(const CFunctionList &Callback, const std::map &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector * add, int x, int y, int key ); +}; + +class CHighlightableButton + : public AdventureMapButton +{ +public: + CHighlightableButton(const CFunctionList &onSelect, const CFunctionList &onDeselect, const std::map &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector * add, int x, int y, int key=0 ); + bool selected, onlyOn; + CFunctionList callback2; //when disselecting + void select(bool on); + void clickLeft (tribool down); +}; + +class CHighlightableButtonsGroup +{ +public: + CFunctionList2 onChange; //called when changing selected button with new button's id + std::vector buttons; + + //void addButton(const std::map &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid); + void addButton(CHighlightableButton* bt);//add existing button, it'll be deleted by CHighlightableButtonsGroup destructor + void addButton(const std::map &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList &OnSelect=0, int key=0); //creates new button + CHighlightableButtonsGroup(const CFunctionList2 &OnChange); + ~CHighlightableButtonsGroup(); + void activate(); + void deactivate(); + void select(int id, bool mode); //mode==0: id is serial; mode==1: id is unique button id + void selectionChanged(int to); + void show(SDL_Surface * to); +}; + + +class CSlider : public IShowable, public MotionInterested, public ClickableL +{ +public: + AdventureMapButton left, right, slider; //if vertical then left=up + int capacity,//how many elements can be active at same time + amount, //how many elements + value; //first active element + bool horizontal, moving; + CDefEssential *imgs ; + + boost::function moved; + //void(T::*moved)(int to); + //T* owner; + + void redrawSlider(); + + void sliderClicked(); + void moveLeft(); + void clickLeft (tribool down); + void mouseMoved (const SDL_MouseMotionEvent & sEvent); + void moveRight(); + void moveTo(int to); + void block(bool on); + void activate(); // makes button active + void deactivate(); // makes button inactive (but doesn't delete) + void show(SDL_Surface * to); + CSlider(int x, int y, int totalw, boost::function Moved, int Capacity, int Amount, + int Value=0, bool Horizontal=true); + ~CSlider(); +}; + +#endif // __ADVENTUREMAPBUTTON_H__ diff --git a/CCallback.h b/CCallback.h index e235a1bc5..f8a654583 100644 --- a/CCallback.h +++ b/CCallback.h @@ -1,16 +1,16 @@ -#ifndef __CCALLBACK_H__ -#define __CCALLBACK_H__ - -#include "global.h" -#ifdef _WIN32 -#include "tchar.h" -#else -#include "tchar_amigaos4.h" //XXX this is mingw header are we need this for something? for 'true' -//support of unicode we should use ICU or some boost wraper areound it -//(boost using this lib during compilation i dont know what for exactly) -#endif -#include "CGameState.h" - +#ifndef __CCALLBACK_H__ +#define __CCALLBACK_H__ + +#include "global.h" +#ifdef _WIN32 +#include "tchar.h" +#else +#include "tchar_amigaos4.h" //XXX this is mingw header are we need this for something? for 'true' +//support of unicode we should use ICU or some boost wraper areound it +//(boost using this lib during compilation i dont know what for exactly) +#endif +#include "CGameState.h" + /* * CCallback.h, part of VCMI engine * @@ -19,194 +19,194 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CGHeroInstance; -class CGameState; -struct CPath; -class CGObjectInstance; -class CArmedInstance; -class SComponent; -class IChosen; -class CSelectableComponent; -struct BattleAction; -class CGTownInstance; -struct StartInfo; -class CStack; -struct lua_State; -class CClient; -struct TerrainTile; -//structure gathering info about upgrade possibilites - -class ICallback -{ -public: - virtual bool moveHero(const CGHeroInstance *h, int3 dst) const =0; //dst must be free, neighbouring tile (this function can move hero only by one tile) - virtual void selectionMade(int selection, int asker) =0; - virtual int swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2)=0;//swaps creatures between two posiibly different garrisons // TODO: AI-unsafe code - fix it! - virtual int mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2)=0;//joins first stack tothe second (creatures must be same type) - virtual int splitStack(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2, int val)=0;//split creatures from the first stack - virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses diven hero; true - successfuly, false - not successfuly - virtual bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes - virtual void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount)=0; - virtual bool dismissCreature(const CArmedInstance *obj, int stackPos)=0; - virtual bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1)=0; //if newID==-1 then best possible upgrade will be made - virtual void endTurn()=0; - virtual void swapGarrisonHero(const CGTownInstance *town)=0; - virtual void buyArtifact(const CGHeroInstance *hero, int aid)=0; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith) - virtual void trade(int mode, int id1, int id2, int val1)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce - virtual void setFormation(const CGHeroInstance * hero, bool tight)=0; - virtual void setSelection(const CArmedInstance * obj)=0; - virtual void recruitHero(const CGTownInstance *town, const CGHeroInstance *hero)=0; - virtual void save(const std::string &fname) = 0; - virtual void sendMessage(const std::string &mess) = 0; - -//get info - virtual bool verifyPath(CPath * path, bool blockSea)const =0; - virtual int getDate(int mode=0)const =0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month - virtual std::vector< std::vector< std::vector > > & getVisibilityMap()const =0; //returns visibility map (TODO: make it const) - virtual const CGHeroInstance * getHeroInfo(int val, int mode=2)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID - virtual int getResourceAmount(int type)const =0; - virtual int howManyHeroes(bool includeGarrisoned = true)const =0; - virtual const CGTownInstance * getTownInfo(int val, bool mode)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID - virtual int howManyTowns()const =0; - virtual std::vector < std::string > getObjDescriptions(int3 pos)const =0; //returns descriptions of objects at pos in order from the lowest to the highest - virtual std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true)const =0; - virtual bool isVisible(int3 pos)const =0; - virtual int getMyColor()const =0; - virtual int getMySerial()const =0; - virtual int getHeroSerial(const CGHeroInstance * hero)const =0; - virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)const =0; - virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)const =0; - virtual const StartInfo * getStartInfo()const =0; - virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)const =0; - virtual std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos)const =0; - virtual void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0)const =0; - virtual std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const =0; - virtual int3 getMapSize() const =0; //returns size of map - z is 1 for one - level map and 2 for two level map - virtual std::vector getAvailableHeroes(const CGTownInstance * town) const =0; //heroes that can be recruited - virtual const TerrainTile * getTileInfo(int3 tile) const = 0; - virtual int canBuildStructure(const CGTownInstance *t, int ID) =0;//// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements - virtual CPath * getPath(int3 src, int3 dest, const CGHeroInstance * hero)=0; - -//battle - virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship - virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield - virtual std::vector battleGetAllObstacles()=0; //returns all obstacles on the battlefield - virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile - virtual CStack * battleGetStackByID(int ID)=0; //returns stack info by given ID - virtual CStack * battleGetStackByPos(int pos)=0; //returns stack info by given pos - virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack - virtual int battleMakeAction(BattleAction* action)=0;//for casting spells by hero - DO NOT use it for moving active stack - virtual std::map battleGetStacks()=0; //returns stacks on battlefield - virtual std::vector battleGetStackQueue()=0; //returns vector of stack in order of their move sequence - virtual CCreature battleGetCreature(int number)=0; //returns type of creature by given number of stack - //virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible - virtual std::vector battleGetAvailableHexes(int ID, bool addOccupiable)=0; //reutrns numbers of hexes reachable by creature with id ID - virtual bool battleIsStackMine(int ID)=0; //returns true if stack with id ID belongs to caller - virtual bool battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest -}; - -struct HeroMoveDetails -{ - HeroMoveDetails(){}; - HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho); - int3 src, dst; //source and destination points - CGHeroInstance * ho; //object instance of this hero - int owner, style; //style: 0 - normal move, 1 - teleport, 2 - instant jump - bool successful; -}; - -class CCallback : public ICallback -{ -private: - CCallback(CGameState * GS, int Player, CClient *C):gs(GS), cl(C), player(Player){}; - CGameState * gs; - CClient *cl; - bool isVisible(int3 pos, int Player) const; - bool isVisible(CGObjectInstance *obj, int Player) const; - -protected: - int player; - -public: -//commands - bool moveHero(const CGHeroInstance *h, int3 dst) const; //dst must be free, neighbouring tile (this function can move hero only by one tile) - void selectionMade(int selection, int asker); - int swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2); - int mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2); //first goes to the second - int splitStack(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2, int val); - bool dismissHero(const CGHeroInstance * hero); - bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2); - bool buildBuilding(const CGTownInstance *town, si32 buildingID); - void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount); - bool dismissCreature(const CArmedInstance *obj, int stackPos); - bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1); - void endTurn(); - void swapGarrisonHero(const CGTownInstance *town); - void buyArtifact(const CGHeroInstance *hero, int aid); - void trade(int mode, int id1, int id2, int val1); - void setFormation(const CGHeroInstance * hero, bool tight); - void setSelection(const CArmedInstance * obj); - void recruitHero(const CGTownInstance *town, const CGHeroInstance *hero); - void save(const std::string &fname); - void sendMessage(const std::string &mess); - -//get info - bool verifyPath(CPath * path, bool blockSea) const; - int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month - std::vector< std::vector< std::vector > > & getVisibilityMap() const; //returns visibility map (TODO: make it const) - const CGHeroInstance * getHeroInfo(int val, int mode=2) const; //mode = 0 -> val = serial; mode = 1 -> val = hero type id (subID); mode = 2 -> val = global object serial id (id) - int getResourceAmount(int type) const; - std::vector getResourceAmount() const; - int howManyHeroes(bool includeGarrisoned = true) const; - const CGTownInstance * getTownInfo(int val, bool mode) const; //mode = 0 -> val = serial; mode = 1 -> val = ID - std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true) const; - int howManyTowns()const; - std::vector < std::string > getObjDescriptions(int3 pos) const; //returns descriptions of objects at pos in order from the lowest to the highest - std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true) const; - bool isVisible(int3 pos) const; - int getMyColor() const; - int getHeroSerial(const CGHeroInstance * hero) const; - int getMySerial() const; - const CCreatureSet* getGarrison(const CGObjectInstance *obj) const; - UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos) const; - const StartInfo * getStartInfo() const; - std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos) const; - std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos) const; - void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0) const; - std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const; - int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map - std::vector getAvailableHeroes(const CGTownInstance * town) const; //heroes that can be recruited - const TerrainTile * getTileInfo(int3 tile) const; - int canBuildStructure(const CGTownInstance *t, int ID);//// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements - CPath * getPath(int3 src, int3 dest, const CGHeroInstance * hero); - - //battle - int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship - int battleGetObstaclesAtTile(int tile); //returns bitfield - std::vector battleGetAllObstacles(); //returns all obstacles on the battlefield - int battleGetStack(int pos); //returns ID of stack on the tile - CStack * battleGetStackByID(int ID); //returns stack info by given ID - CStack * battleGetStackByPos(int pos); //returns stack info by given pos - int battleGetPos(int stack); //returns position (tile ID) of stack - int battleMakeAction(BattleAction* action);//for casting spells by hero - DO NOT use it for moving active stack - std::map battleGetStacks(); //returns stacks on battlefield - std::vector battleGetStackQueue(); //returns vector of stack in order of their move sequence - CCreature battleGetCreature(int number); //returns type of creature by given number of stack - std::vector battleGetAvailableHexes(int ID, bool addOccupiable); //reutrns numbers of hexes reachable by creature with id ID - bool battleIsStackMine(int ID); //returns true if stack with id ID belongs to caller - bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest - - -//XXX hmmm _tmain on _GNUC_ wtf? -//friends - friend class CClient; -#ifndef __GNUC__ - friend int _tmain(int argc, _TCHAR* argv[]); -#else - friend int main(int argc, char** argv); -#endif -}; - -#endif // __CCALLBACK_H__ + */ + +class CGHeroInstance; +class CGameState; +struct CPath; +class CGObjectInstance; +class CArmedInstance; +class SComponent; +class IChosen; +class CSelectableComponent; +struct BattleAction; +class CGTownInstance; +struct StartInfo; +class CStack; +struct lua_State; +class CClient; +struct TerrainTile; +//structure gathering info about upgrade possibilites + +class ICallback +{ +public: + virtual bool moveHero(const CGHeroInstance *h, int3 dst) const =0; //dst must be free, neighbouring tile (this function can move hero only by one tile) + virtual void selectionMade(int selection, int asker) =0; + virtual int swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2)=0;//swaps creatures between two posiibly different garrisons // TODO: AI-unsafe code - fix it! + virtual int mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2)=0;//joins first stack tothe second (creatures must be same type) + virtual int splitStack(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2, int val)=0;//split creatures from the first stack + virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses diven hero; true - successfuly, false - not successfuly + virtual bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes + virtual void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount)=0; + virtual bool dismissCreature(const CArmedInstance *obj, int stackPos)=0; + virtual bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1)=0; //if newID==-1 then best possible upgrade will be made + virtual void endTurn()=0; + virtual void swapGarrisonHero(const CGTownInstance *town)=0; + virtual void buyArtifact(const CGHeroInstance *hero, int aid)=0; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith) + virtual void trade(int mode, int id1, int id2, int val1)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce + virtual void setFormation(const CGHeroInstance * hero, bool tight)=0; + virtual void setSelection(const CArmedInstance * obj)=0; + virtual void recruitHero(const CGTownInstance *town, const CGHeroInstance *hero)=0; + virtual void save(const std::string &fname) = 0; + virtual void sendMessage(const std::string &mess) = 0; + +//get info + virtual bool verifyPath(CPath * path, bool blockSea)const =0; + virtual int getDate(int mode=0)const =0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month + virtual std::vector< std::vector< std::vector > > & getVisibilityMap()const =0; //returns visibility map (TODO: make it const) + virtual const CGHeroInstance * getHeroInfo(int val, int mode=2)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID + virtual int getResourceAmount(int type)const =0; + virtual int howManyHeroes(bool includeGarrisoned = true)const =0; + virtual const CGTownInstance * getTownInfo(int val, bool mode)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID + virtual int howManyTowns()const =0; + virtual std::vector < std::string > getObjDescriptions(int3 pos)const =0; //returns descriptions of objects at pos in order from the lowest to the highest + virtual std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true)const =0; + virtual bool isVisible(int3 pos)const =0; + virtual int getMyColor()const =0; + virtual int getMySerial()const =0; + virtual int getHeroSerial(const CGHeroInstance * hero)const =0; + virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)const =0; + virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)const =0; + virtual const StartInfo * getStartInfo()const =0; + virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)const =0; + virtual std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos)const =0; + virtual void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0)const =0; + virtual std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const =0; + virtual int3 getMapSize() const =0; //returns size of map - z is 1 for one - level map and 2 for two level map + virtual std::vector getAvailableHeroes(const CGTownInstance * town) const =0; //heroes that can be recruited + virtual const TerrainTile * getTileInfo(int3 tile) const = 0; + virtual int canBuildStructure(const CGTownInstance *t, int ID) =0;//// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements + virtual CPath * getPath(int3 src, int3 dest, const CGHeroInstance * hero)=0; + +//battle + virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship + virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield + virtual std::vector battleGetAllObstacles()=0; //returns all obstacles on the battlefield + virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile + virtual CStack * battleGetStackByID(int ID)=0; //returns stack info by given ID + virtual CStack * battleGetStackByPos(int pos)=0; //returns stack info by given pos + virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack + virtual int battleMakeAction(BattleAction* action)=0;//for casting spells by hero - DO NOT use it for moving active stack + virtual std::map battleGetStacks()=0; //returns stacks on battlefield + virtual std::vector battleGetStackQueue()=0; //returns vector of stack in order of their move sequence + virtual CCreature battleGetCreature(int number)=0; //returns type of creature by given number of stack + //virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible + virtual std::vector battleGetAvailableHexes(int ID, bool addOccupiable)=0; //reutrns numbers of hexes reachable by creature with id ID + virtual bool battleIsStackMine(int ID)=0; //returns true if stack with id ID belongs to caller + virtual bool battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest +}; + +struct HeroMoveDetails +{ + HeroMoveDetails(){}; + HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho); + int3 src, dst; //source and destination points + CGHeroInstance * ho; //object instance of this hero + int owner, style; //style: 0 - normal move, 1 - teleport, 2 - instant jump + bool successful; +}; + +class CCallback : public ICallback +{ +private: + CCallback(CGameState * GS, int Player, CClient *C):gs(GS), cl(C), player(Player){}; + CGameState * gs; + CClient *cl; + bool isVisible(int3 pos, int Player) const; + bool isVisible(CGObjectInstance *obj, int Player) const; + +protected: + int player; + +public: +//commands + bool moveHero(const CGHeroInstance *h, int3 dst) const; //dst must be free, neighbouring tile (this function can move hero only by one tile) + void selectionMade(int selection, int asker); + int swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2); + int mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2); //first goes to the second + int splitStack(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2, int val); + bool dismissHero(const CGHeroInstance * hero); + bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2); + bool buildBuilding(const CGTownInstance *town, si32 buildingID); + void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount); + bool dismissCreature(const CArmedInstance *obj, int stackPos); + bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1); + void endTurn(); + void swapGarrisonHero(const CGTownInstance *town); + void buyArtifact(const CGHeroInstance *hero, int aid); + void trade(int mode, int id1, int id2, int val1); + void setFormation(const CGHeroInstance * hero, bool tight); + void setSelection(const CArmedInstance * obj); + void recruitHero(const CGTownInstance *town, const CGHeroInstance *hero); + void save(const std::string &fname); + void sendMessage(const std::string &mess); + +//get info + bool verifyPath(CPath * path, bool blockSea) const; + int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month + std::vector< std::vector< std::vector > > & getVisibilityMap() const; //returns visibility map (TODO: make it const) + const CGHeroInstance * getHeroInfo(int val, int mode=2) const; //mode = 0 -> val = serial; mode = 1 -> val = hero type id (subID); mode = 2 -> val = global object serial id (id) + int getResourceAmount(int type) const; + std::vector getResourceAmount() const; + int howManyHeroes(bool includeGarrisoned = true) const; + const CGTownInstance * getTownInfo(int val, bool mode) const; //mode = 0 -> val = serial; mode = 1 -> val = ID + std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true) const; + int howManyTowns()const; + std::vector < std::string > getObjDescriptions(int3 pos) const; //returns descriptions of objects at pos in order from the lowest to the highest + std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true) const; + bool isVisible(int3 pos) const; + int getMyColor() const; + int getHeroSerial(const CGHeroInstance * hero) const; + int getMySerial() const; + const CCreatureSet* getGarrison(const CGObjectInstance *obj) const; + UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos) const; + const StartInfo * getStartInfo() const; + std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos) const; + std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos) const; + void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0) const; + std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const; + int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map + std::vector getAvailableHeroes(const CGTownInstance * town) const; //heroes that can be recruited + const TerrainTile * getTileInfo(int3 tile) const; + int canBuildStructure(const CGTownInstance *t, int ID);//// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements + CPath * getPath(int3 src, int3 dest, const CGHeroInstance * hero); + + //battle + int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship + int battleGetObstaclesAtTile(int tile); //returns bitfield + std::vector battleGetAllObstacles(); //returns all obstacles on the battlefield + int battleGetStack(int pos); //returns ID of stack on the tile + CStack * battleGetStackByID(int ID); //returns stack info by given ID + CStack * battleGetStackByPos(int pos); //returns stack info by given pos + int battleGetPos(int stack); //returns position (tile ID) of stack + int battleMakeAction(BattleAction* action);//for casting spells by hero - DO NOT use it for moving active stack + std::map battleGetStacks(); //returns stacks on battlefield + std::vector battleGetStackQueue(); //returns vector of stack in order of their move sequence + CCreature battleGetCreature(int number); //returns type of creature by given number of stack + std::vector battleGetAvailableHexes(int ID, bool addOccupiable); //reutrns numbers of hexes reachable by creature with id ID + bool battleIsStackMine(int ID); //returns true if stack with id ID belongs to caller + bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest + + +//XXX hmmm _tmain on _GNUC_ wtf? +//friends + friend class CClient; +#ifndef __GNUC__ + friend int _tmain(int argc, _TCHAR* argv[]); +#else + friend int main(int argc, char** argv); +#endif +}; + +#endif // __CCALLBACK_H__ diff --git a/CCastleInterface.h b/CCastleInterface.h index 1c44bb235..a8dd09c4d 100644 --- a/CCastleInterface.h +++ b/CCastleInterface.h @@ -1,20 +1,20 @@ -#ifndef __CCASTLEINTERFACE_H__ -#define __CCASTLEINTERFACE_H__ - - - -#include "global.h" -#include -#include "CPlayerInterface.h" -//#include "boost/tuple/tuple.hpp" -class CGTownInstance; -class CTownHandler; -class CHallInterface; -struct Structure; -class CSpell; -class AdventureMapButton; -class CResDataBar; - +#ifndef __CCASTLEINTERFACE_H__ +#define __CCASTLEINTERFACE_H__ + + + +#include "global.h" +#include +#include "CPlayerInterface.h" +//#include "boost/tuple/tuple.hpp" +class CGTownInstance; +class CTownHandler; +class CHallInterface; +struct Structure; +class CSpell; +class AdventureMapButton; +class CResDataBar; + /* * CCastleInterface.h, part of VCMI engine * @@ -23,218 +23,218 @@ class CResDataBar; * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CBuildingRect : public Hoverable, public MotionInterested, public ClickableL, public ClickableR//, public TimeInterested -{ -public: - bool moi; //motion interested is active - int offset, max; //first and last animation frame - Structure* str; - CDefHandler* def; - SDL_Surface* border; - SDL_Surface* area; - CBuildingRect(Structure *Str); - ~CBuildingRect(); - void activate(); - void deactivate(); - bool operator<(const CBuildingRect & p2) const; - void hover(bool on); - void clickLeft (tribool down); - void clickRight (tribool down); - void mouseMoved (const SDL_MouseMotionEvent & sEvent); -}; -class CHeroGSlot : public ClickableL, public ClickableR, public Hoverable -{ -public: - CCastleInterface *owner; - const CGHeroInstance *hero; - int upg; //0 - up garrison, 1 - down garrison - bool highlight; - - void hover (bool on); - void clickRight (boost::logic::tribool down); - void clickLeft(boost::logic::tribool down); - void activate(); - void deactivate(); - void show(SDL_Surface * to); - CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h,CCastleInterface * Owner); - ~CHeroGSlot(); -}; - -class CCastleInterface : public CWindowWithGarrison -{ -public: - SDL_Rect pos; - bool showing; - CBuildingRect * hBuild; //highlighted building - SDL_Surface * townInt; - SDL_Surface * cityBg; - const CGTownInstance * town; - CStatusBar * statusbar; - CResDataBar *resdatabar; - unsigned char animval, count; - - CDefEssential *bars, //0 - yellow, 1 - green, 2 - red, 3 - gray - *status; //0 - already, 1 - can't, 2 - lack of resources - CDefHandler *hall,*fort; - CDefEssential* bicons; //150x70 buildings imgs - CTownList * townlist; - - CHeroGSlot hslotup, hslotdown; - AdventureMapButton *exit; - AdventureMapButton *split; - - std::vector buildings; //building id, building def, structure struct, border, filling - - CCastleInterface(const CGTownInstance * Town); - ~CCastleInterface(); - void townChange(); - void show(SDL_Surface * to); - void showAll(SDL_Surface * to); - void buildingClicked(int building); - void enterMageGuild(); - CRecrutationWindow * showRecruitmentWindow(int building); - void enterHall(); - void close(); - void splitF(); - void activate(); - void deactivate(); - void addBuilding(int bid); - void removeBuilding(int bid); - void recreateBuildings(); -}; -class CHallInterface : public IShowActivable -{ -public: - CMinorResDataBar resdatabar; - SDL_Rect pos; - - class CBuildingBox : public Hoverable, public ClickableL, public ClickableR - { - public: - int BID; - int state;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements - //(-1) - forbidden in this town, 0 - possible, 1 - lack of res, 2 - requirements/buildings per turn limit, (3) - already exists - void hover(bool on); - void clickLeft (tribool down); - void clickRight (tribool down); - void show(SDL_Surface * to); - void activate(); - void deactivate(); - CBuildingBox(int id); - CBuildingBox(int id, int x, int y); - ~CBuildingBox(); - }; - - class CBuildWindow: public IShowActivable, public ClickableR - { - public: - int tid, bid, state; //town id, building id, state - bool mode; // 0 - normal (with buttons), 1 - r-click popup - SDL_Surface * bitmap; //main window bitmap, with blitted res/text, without buttons/subtitle in "statusbar" - AdventureMapButton *buy, *cancel; - - void activate(); - void deactivate(); - std::string getTextForState(int state); - void clickRight (tribool down); - void show(SDL_Surface * to); - void Buy(); - void close(); - CBuildWindow(int Tid, int Bid, int State, bool Mode); - ~CBuildWindow(); - }; - - std::vector< std::vector >boxes; - - AdventureMapButton *exit; - - SDL_Surface * bg; - - - CHallInterface(CCastleInterface * owner); - ~CHallInterface(); - void close(); - void show(SDL_Surface * to); - void activate(); - void deactivate(); -}; - -class CFortScreen : public IShowActivable, public CIntObject -{ - class RecArea : public ClickableL, public ClickableR - { - public: - int bid; - RecArea(int BID):bid(BID){}; - void clickLeft (tribool down); - void clickRight (tribool down); - void activate(); - void deactivate(); - }; -public: - CMinorResDataBar resdatabar; - AdventureMapButton *exit; - SDL_Surface * bg; - std::vector positions; - std::vector recAreas; - std::vector crePics; - - CFortScreen(CCastleInterface * owner); - - void draw( CCastleInterface * owner, bool first); - ~CFortScreen(); - void close(); - void show(SDL_Surface * to); - void activate(); - void deactivate(); -}; - -class CMageGuildScreen : public IShowActivable, public CIntObject -{ -public: - class Scroll : public ClickableL, public Hoverable, public ClickableR - { - public: - CSpell *spell; - - Scroll(CSpell *Spell):spell(Spell){}; - void clickLeft (tribool down); - void clickRight (tribool down); - void hover(bool on); - void activate(); - void deactivate(); - }; - std::vector > positions; - - SDL_Surface *bg; - CDefEssential *scrolls, *scrolls2; - AdventureMapButton *exit; - std::vector spells; - CMinorResDataBar resdatabar; - - - CMageGuildScreen(CCastleInterface * owner); - ~CMageGuildScreen(); - void close(); - void show(SDL_Surface * to); - void activate(); - void deactivate(); -}; - -class CBlacksmithDialog : public IShowActivable, public CIntObject -{ -public: - AdventureMapButton *buy, *cancel; - SDL_Surface *bmp; - - CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid); - ~CBlacksmithDialog(); - void close(); - void show(SDL_Surface * to); - void activate(); - void deactivate(); -}; - -#endif // __CCASTLEINTERFACE_H__ + */ + +class CBuildingRect : public Hoverable, public MotionInterested, public ClickableL, public ClickableR//, public TimeInterested +{ +public: + bool moi; //motion interested is active + int offset, max; //first and last animation frame + Structure* str; + CDefHandler* def; + SDL_Surface* border; + SDL_Surface* area; + CBuildingRect(Structure *Str); + ~CBuildingRect(); + void activate(); + void deactivate(); + bool operator<(const CBuildingRect & p2) const; + void hover(bool on); + void clickLeft (tribool down); + void clickRight (tribool down); + void mouseMoved (const SDL_MouseMotionEvent & sEvent); +}; +class CHeroGSlot : public ClickableL, public ClickableR, public Hoverable +{ +public: + CCastleInterface *owner; + const CGHeroInstance *hero; + int upg; //0 - up garrison, 1 - down garrison + bool highlight; + + void hover (bool on); + void clickRight (boost::logic::tribool down); + void clickLeft(boost::logic::tribool down); + void activate(); + void deactivate(); + void show(SDL_Surface * to); + CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h,CCastleInterface * Owner); + ~CHeroGSlot(); +}; + +class CCastleInterface : public CWindowWithGarrison +{ +public: + SDL_Rect pos; + bool showing; + CBuildingRect * hBuild; //highlighted building + SDL_Surface * townInt; + SDL_Surface * cityBg; + const CGTownInstance * town; + CStatusBar * statusbar; + CResDataBar *resdatabar; + unsigned char animval, count; + + CDefEssential *bars, //0 - yellow, 1 - green, 2 - red, 3 - gray + *status; //0 - already, 1 - can't, 2 - lack of resources + CDefHandler *hall,*fort; + CDefEssential* bicons; //150x70 buildings imgs + CTownList * townlist; + + CHeroGSlot hslotup, hslotdown; + AdventureMapButton *exit; + AdventureMapButton *split; + + std::vector buildings; //building id, building def, structure struct, border, filling + + CCastleInterface(const CGTownInstance * Town); + ~CCastleInterface(); + void townChange(); + void show(SDL_Surface * to); + void showAll(SDL_Surface * to); + void buildingClicked(int building); + void enterMageGuild(); + CRecrutationWindow * showRecruitmentWindow(int building); + void enterHall(); + void close(); + void splitF(); + void activate(); + void deactivate(); + void addBuilding(int bid); + void removeBuilding(int bid); + void recreateBuildings(); +}; +class CHallInterface : public IShowActivable +{ +public: + CMinorResDataBar resdatabar; + SDL_Rect pos; + + class CBuildingBox : public Hoverable, public ClickableL, public ClickableR + { + public: + int BID; + int state;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements + //(-1) - forbidden in this town, 0 - possible, 1 - lack of res, 2 - requirements/buildings per turn limit, (3) - already exists + void hover(bool on); + void clickLeft (tribool down); + void clickRight (tribool down); + void show(SDL_Surface * to); + void activate(); + void deactivate(); + CBuildingBox(int id); + CBuildingBox(int id, int x, int y); + ~CBuildingBox(); + }; + + class CBuildWindow: public IShowActivable, public ClickableR + { + public: + int tid, bid, state; //town id, building id, state + bool mode; // 0 - normal (with buttons), 1 - r-click popup + SDL_Surface * bitmap; //main window bitmap, with blitted res/text, without buttons/subtitle in "statusbar" + AdventureMapButton *buy, *cancel; + + void activate(); + void deactivate(); + std::string getTextForState(int state); + void clickRight (tribool down); + void show(SDL_Surface * to); + void Buy(); + void close(); + CBuildWindow(int Tid, int Bid, int State, bool Mode); + ~CBuildWindow(); + }; + + std::vector< std::vector >boxes; + + AdventureMapButton *exit; + + SDL_Surface * bg; + + + CHallInterface(CCastleInterface * owner); + ~CHallInterface(); + void close(); + void show(SDL_Surface * to); + void activate(); + void deactivate(); +}; + +class CFortScreen : public IShowActivable, public CIntObject +{ + class RecArea : public ClickableL, public ClickableR + { + public: + int bid; + RecArea(int BID):bid(BID){}; + void clickLeft (tribool down); + void clickRight (tribool down); + void activate(); + void deactivate(); + }; +public: + CMinorResDataBar resdatabar; + AdventureMapButton *exit; + SDL_Surface * bg; + std::vector positions; + std::vector recAreas; + std::vector crePics; + + CFortScreen(CCastleInterface * owner); + + void draw( CCastleInterface * owner, bool first); + ~CFortScreen(); + void close(); + void show(SDL_Surface * to); + void activate(); + void deactivate(); +}; + +class CMageGuildScreen : public IShowActivable, public CIntObject +{ +public: + class Scroll : public ClickableL, public Hoverable, public ClickableR + { + public: + CSpell *spell; + + Scroll(CSpell *Spell):spell(Spell){}; + void clickLeft (tribool down); + void clickRight (tribool down); + void hover(bool on); + void activate(); + void deactivate(); + }; + std::vector > positions; + + SDL_Surface *bg; + CDefEssential *scrolls, *scrolls2; + AdventureMapButton *exit; + std::vector spells; + CMinorResDataBar resdatabar; + + + CMageGuildScreen(CCastleInterface * owner); + ~CMageGuildScreen(); + void close(); + void show(SDL_Surface * to); + void activate(); + void deactivate(); +}; + +class CBlacksmithDialog : public IShowActivable, public CIntObject +{ +public: + AdventureMapButton *buy, *cancel; + SDL_Surface *bmp; + + CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid); + ~CBlacksmithDialog(); + void close(); + void show(SDL_Surface * to); + void activate(); + void deactivate(); +}; + +#endif // __CCASTLEINTERFACE_H__ diff --git a/CConsoleHandler.h b/CConsoleHandler.h index 74392d688..e107e8166 100644 --- a/CConsoleHandler.h +++ b/CConsoleHandler.h @@ -1,16 +1,16 @@ -#ifndef __CCONSOLEHANDLER_H__ -#define __CCONSOLEHANDLER_H__ - -#ifndef _WIN32 -#define WORD std::string -#endif - -#ifndef _WIN32 -#define _kill_thread(a,b) pthread_cancel(a); -#else -#define _kill_thread(a,b) TerminateThread(a,b); -#endif - +#ifndef __CCONSOLEHANDLER_H__ +#define __CCONSOLEHANDLER_H__ + +#ifndef _WIN32 +#define WORD std::string +#endif + +#ifndef _WIN32 +#define _kill_thread(a,b) pthread_cancel(a); +#else +#define _kill_thread(a,b) TerminateThread(a,b); +#endif + /* * CConsoleHandler.h, part of VCMI engine * @@ -19,34 +19,34 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -namespace boost -{ - template - class function; -} -class DLL_EXPORT CConsoleHandler -{ -public: - boost::function *cb; - int curLvl; - int run(); - void setColor(int level); - CConsoleHandler(); - ~CConsoleHandler(); -#ifndef _WIN32 - static void killConsole(pthread_t hThread); //for windows only, use native handle to the thread -#else - static void killConsole(void *hThread); //for windows only, use native handle to the thread -#endif - template void print(const T &data, int level) - { - setColor(level); - std::cout << data << std::flush; - setColor(-1); - } -}; - - -#endif // __CCONSOLEHANDLER_H__ + */ + +namespace boost +{ + template + class function; +} +class DLL_EXPORT CConsoleHandler +{ +public: + boost::function *cb; + int curLvl; + int run(); + void setColor(int level); + CConsoleHandler(); + ~CConsoleHandler(); +#ifndef _WIN32 + static void killConsole(pthread_t hThread); //for windows only, use native handle to the thread +#else + static void killConsole(void *hThread); //for windows only, use native handle to the thread +#endif + template void print(const T &data, int level) + { + setColor(level); + std::cout << data << std::flush; + setColor(-1); + } +}; + + +#endif // __CCONSOLEHANDLER_H__ diff --git a/CCursorHandler.h b/CCursorHandler.h index e38f4829b..f7f24a37e 100644 --- a/CCursorHandler.h +++ b/CCursorHandler.h @@ -1,11 +1,11 @@ -#ifndef __CCURSORHANDLER_H__ -#define __CCURSORHANDLER_H__ -#include "global.h" -#include -struct SDL_Thread; -class CDefHandler; -struct SDL_Surface; - +#ifndef __CCURSORHANDLER_H__ +#define __CCURSORHANDLER_H__ +#include "global.h" +#include +struct SDL_Thread; +class CDefHandler; +struct SDL_Surface; + /* * CCursorhandler.h, part of VCMI engine * @@ -14,26 +14,26 @@ struct SDL_Surface; * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CCursorHandler //handles cursor -{ -public: - int mode, number; - SDL_Surface * help; - bool Show; - - std::vector cursors; - int xpos, ypos; //position of cursor - void initCursor(); //inits cursorHandler - void cursorMove(const int & x, const int & y); //change cursor's positions to (x, y) - void changeGraphic(const int & type, const int & no); //changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame no (not used for type 3) - void draw1(); - void draw2(); - void hide(){Show=0;}; - void show(){Show=1;}; -}; - - - -#endif // __CCURSORHANDLER_H__ + */ + +class CCursorHandler //handles cursor +{ +public: + int mode, number; + SDL_Surface * help; + bool Show; + + std::vector cursors; + int xpos, ypos; //position of cursor + void initCursor(); //inits cursorHandler + void cursorMove(const int & x, const int & y); //change cursor's positions to (x, y) + void changeGraphic(const int & type, const int & no); //changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame no (not used for type 3) + void draw1(); + void draw2(); + void hide(){Show=0;}; + void show(){Show=1;}; +}; + + + +#endif // __CCURSORHANDLER_H__ diff --git a/CGameInfo.h b/CGameInfo.h index 5ad7a1407..0b9734a45 100644 --- a/CGameInfo.h +++ b/CGameInfo.h @@ -1,10 +1,10 @@ -#ifndef __CGAMEINFO_H__ -#define __CGAMEINFO_H__ -#include "global.h" - -#include - - +#ifndef __CGAMEINFO_H__ +#define __CGAMEINFO_H__ +#include "global.h" + +#include + + /* * CGameInfo.h, part of VCMI engine * @@ -13,62 +13,62 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CMapHandler; -class CArtHandler; -class CHeroHandler; -class CCreatureHandler; -class CAbilityHandler; -class CSpellHandler; -class CAmbarCendamo; -class CPreGameTextHandler; -class CBuildingHandler; -class CObjectHandler; -class CMusicHandler; -class CSemiLodHandler; -class CDefObjInfoHandler; -class CTownHandler; -class CLodHandler; -class CGeneralTextHandler; -class CConsoleHandler; -class CPathfinder; -class CCursorHandler; -class CScreenHandler; -class CGameState; -class CMapHandler; -class CGameInterface; -class CPreGame; -class CDefHandler; -/* - CGameInfo class - for allowing different functions for modifying game informations -*/ -class CGameInfo -{ -public: - CGameState * state; - CArtHandler * arth; - CHeroHandler * heroh; - CCreatureHandler * creh; - CSpellHandler * spellh; - CMapHandler * mh; - CBuildingHandler * buildh; - CObjectHandler * objh; - CMusicHandler * mush; - CSemiLodHandler * sspriteh; - CDefObjInfoHandler * dobjinfo; - CTownHandler * townh; - CLodHandler * spriteh; - CLodHandler * bitmaph; - CGeneralTextHandler * generaltexth; - CConsoleHandler * consoleh; - CCursorHandler * curh; - CScreenHandler * screenh; - - CGameInfo(); - void setFromLib(); -}; - - -#endif // __CGAMEINFO_H__ + */ + +class CMapHandler; +class CArtHandler; +class CHeroHandler; +class CCreatureHandler; +class CAbilityHandler; +class CSpellHandler; +class CAmbarCendamo; +class CPreGameTextHandler; +class CBuildingHandler; +class CObjectHandler; +class CMusicHandler; +class CSemiLodHandler; +class CDefObjInfoHandler; +class CTownHandler; +class CLodHandler; +class CGeneralTextHandler; +class CConsoleHandler; +class CPathfinder; +class CCursorHandler; +class CScreenHandler; +class CGameState; +class CMapHandler; +class CGameInterface; +class CPreGame; +class CDefHandler; +/* + CGameInfo class + for allowing different functions for modifying game informations +*/ +class CGameInfo +{ +public: + CGameState * state; + CArtHandler * arth; + CHeroHandler * heroh; + CCreatureHandler * creh; + CSpellHandler * spellh; + CMapHandler * mh; + CBuildingHandler * buildh; + CObjectHandler * objh; + CMusicHandler * mush; + CSemiLodHandler * sspriteh; + CDefObjInfoHandler * dobjinfo; + CTownHandler * townh; + CLodHandler * spriteh; + CLodHandler * bitmaph; + CGeneralTextHandler * generaltexth; + CConsoleHandler * consoleh; + CCursorHandler * curh; + CScreenHandler * screenh; + + CGameInfo(); + void setFromLib(); +}; + + +#endif // __CGAMEINFO_H__ diff --git a/CGameInterface.h b/CGameInterface.h index accf6fae1..a82cff183 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -1,11 +1,11 @@ -#ifndef __CGAMEINTERFACE_H__ -#define __CGAMEINTERFACE_H__ -#include "global.h" -#include -#include -#include "lib/BattleAction.h" -#include "client/FunctionList.h" - +#ifndef __CGAMEINTERFACE_H__ +#define __CGAMEINTERFACE_H__ +#include "global.h" +#include +#include +#include "lib/BattleAction.h" +#include "client/FunctionList.h" + /* * CGameInterface.h, part of VCMI engine * @@ -14,115 +14,115 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -using namespace boost::logic; -class CCallback; -class ICallback; -class CGlobalAI; -class CGHeroInstance; -class Component; -class CSelectableComponent; -struct HeroMoveDetails; -class CGHeroInstance; -class CGTownInstance; -class CGObjectInstance; -class CCreatureSet; -class CArmedInstance; -struct BattleResult; -struct BattleAttack; -struct BattleStackAttacked; -struct SpellCasted; -struct SetStackEffect; -struct HeroBonus; -struct PackageApplied; -class CLoadFile; -class CSaveFile; -template class CISer; -template class COSer; - -class CObstacle -{ - int ID; - int position; - //TODO: add some kind of the blockmap -}; - -struct StackState -{ - StackState(){attackBonus=defenseBonus=healthBonus=speedBonus=morale=luck=shotsLeft=currentHealth=0;}; - int attackBonus, defenseBonus, healthBonus, speedBonus; - int currentHealth; - int shotsLeft; - std::set effects; //IDs of spells affecting stack - int morale, luck; -}; - -class CGameInterface -{ -public: - bool human; - int playerID, serialID; - std::string dllName; - - virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished - virtual void garrisonChanged(const CGObjectInstance * obj){}; - virtual void heroArtifactSetChanged(const CGHeroInstance*hero){}; - virtual void heroCreated(const CGHeroInstance*){}; - virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector &skills, boost::function &callback)=0; //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id - virtual void heroInGarrisonChange(const CGTownInstance *town){}; - virtual void heroKilled(const CGHeroInstance*){}; - virtual void heroMoved(const HeroMoveDetails & details){}; - virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val){}; - virtual void heroManaPointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after spell casts - virtual void heroMovePointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after movement - virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){}; - virtual void init(ICallback * CB){}; - virtual void receivedResource(int type, int val){}; - virtual void showInfoDialog(const std::string &text, const std::vector &components){}; - //virtual void showSelDialog(const std::string &text, const std::vector &components, ui32 askID){}; - //virtual void showYesNoDialog(const std::string &text, const std::vector &components, ui32 askID){}; - virtual void showBlockingDialog(const std::string &text, const std::vector &components, ui32 askID, bool selection, bool cancel) = 0; //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. - virtual void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, boost::function &onEnd) = 0; //all stacks operations between these objects become allowed, interface has to call onEnd when done - virtual void tileHidden(const std::set &pos){}; - virtual void tileRevealed(const std::set &pos){}; - virtual void yourTurn(){}; - virtual void availableCreaturesChanged(const CGTownInstance *town){}; - virtual void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain){};//if gain hero received bonus, else he lost it - virtual void requestRealized(PackageApplied *pa){} - virtual void serialize(COSer &h, const int version){}; //saving - virtual void serialize(CISer &h, const int version){}; //loading - - //battle call-ins - virtual void actionFinished(const BattleAction *action){};//occurs AFTER every action taken by any stack or by the hero - virtual void actionStarted(const BattleAction *action){};//occurs BEFORE every action taken by any stack or by the hero - virtual BattleAction activeStack(int stackID)=0; //called when it's turn of that stack - virtual void battleAttack(BattleAttack *ba){}; //called when stack is performing attack - virtual void battleStacksAttacked(std::set & bsa){}; //called when stack receives damage (after battleAttack()) - virtual void battleEnd(BattleResult *br){}; - virtual void battleNewRound(int round){}; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - virtual void battleStackMoved(int ID, int dest, int distance, bool end){}; - virtual void battleSpellCasted(SpellCasted *sc){}; - virtual void battleStacksEffectsSet(SetStackEffect & sse){};//called when a specific effect is set to stacks - virtual void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right - virtual void battlefieldPrepared(int battlefieldType, std::vector obstacles){}; //called when battlefield is prepared, prior the battle beginning -}; -class CAIHandler -{ -public: - static CGlobalAI * getNewAI(CCallback * cb, std::string dllname); -}; -class CGlobalAI : public CGameInterface // AI class (to derivate) -{ -public: - //CGlobalAI(); - virtual void yourTurn(){}; - virtual void heroKilled(const CGHeroInstance*){}; - virtual void heroCreated(const CGHeroInstance*){}; - virtual void battleStackMoved(int ID, int dest, int distance){}; - virtual void battleStackAttacking(int ID, int dest){}; - virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting){}; - virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;}; -}; - -#endif // __CGAMEINTERFACE_H__ + */ + +using namespace boost::logic; +class CCallback; +class ICallback; +class CGlobalAI; +class CGHeroInstance; +class Component; +class CSelectableComponent; +struct HeroMoveDetails; +class CGHeroInstance; +class CGTownInstance; +class CGObjectInstance; +class CCreatureSet; +class CArmedInstance; +struct BattleResult; +struct BattleAttack; +struct BattleStackAttacked; +struct SpellCasted; +struct SetStackEffect; +struct HeroBonus; +struct PackageApplied; +class CLoadFile; +class CSaveFile; +template class CISer; +template class COSer; + +class CObstacle +{ + int ID; + int position; + //TODO: add some kind of the blockmap +}; + +struct StackState +{ + StackState(){attackBonus=defenseBonus=healthBonus=speedBonus=morale=luck=shotsLeft=currentHealth=0;}; + int attackBonus, defenseBonus, healthBonus, speedBonus; + int currentHealth; + int shotsLeft; + std::set effects; //IDs of spells affecting stack + int morale, luck; +}; + +class CGameInterface +{ +public: + bool human; + int playerID, serialID; + std::string dllName; + + virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished + virtual void garrisonChanged(const CGObjectInstance * obj){}; + virtual void heroArtifactSetChanged(const CGHeroInstance*hero){}; + virtual void heroCreated(const CGHeroInstance*){}; + virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector &skills, boost::function &callback)=0; //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id + virtual void heroInGarrisonChange(const CGTownInstance *town){}; + virtual void heroKilled(const CGHeroInstance*){}; + virtual void heroMoved(const HeroMoveDetails & details){}; + virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val){}; + virtual void heroManaPointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after spell casts + virtual void heroMovePointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after movement + virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){}; + virtual void init(ICallback * CB){}; + virtual void receivedResource(int type, int val){}; + virtual void showInfoDialog(const std::string &text, const std::vector &components){}; + //virtual void showSelDialog(const std::string &text, const std::vector &components, ui32 askID){}; + //virtual void showYesNoDialog(const std::string &text, const std::vector &components, ui32 askID){}; + virtual void showBlockingDialog(const std::string &text, const std::vector &components, ui32 askID, bool selection, bool cancel) = 0; //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. + virtual void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, boost::function &onEnd) = 0; //all stacks operations between these objects become allowed, interface has to call onEnd when done + virtual void tileHidden(const std::set &pos){}; + virtual void tileRevealed(const std::set &pos){}; + virtual void yourTurn(){}; + virtual void availableCreaturesChanged(const CGTownInstance *town){}; + virtual void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain){};//if gain hero received bonus, else he lost it + virtual void requestRealized(PackageApplied *pa){} + virtual void serialize(COSer &h, const int version){}; //saving + virtual void serialize(CISer &h, const int version){}; //loading + + //battle call-ins + virtual void actionFinished(const BattleAction *action){};//occurs AFTER every action taken by any stack or by the hero + virtual void actionStarted(const BattleAction *action){};//occurs BEFORE every action taken by any stack or by the hero + virtual BattleAction activeStack(int stackID)=0; //called when it's turn of that stack + virtual void battleAttack(BattleAttack *ba){}; //called when stack is performing attack + virtual void battleStacksAttacked(std::set & bsa){}; //called when stack receives damage (after battleAttack()) + virtual void battleEnd(BattleResult *br){}; + virtual void battleNewRound(int round){}; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn + virtual void battleStackMoved(int ID, int dest, int distance, bool end){}; + virtual void battleSpellCasted(SpellCasted *sc){}; + virtual void battleStacksEffectsSet(SetStackEffect & sse){};//called when a specific effect is set to stacks + virtual void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right + virtual void battlefieldPrepared(int battlefieldType, std::vector obstacles){}; //called when battlefield is prepared, prior the battle beginning +}; +class CAIHandler +{ +public: + static CGlobalAI * getNewAI(CCallback * cb, std::string dllname); +}; +class CGlobalAI : public CGameInterface // AI class (to derivate) +{ +public: + //CGlobalAI(); + virtual void yourTurn(){}; + virtual void heroKilled(const CGHeroInstance*){}; + virtual void heroCreated(const CGHeroInstance*){}; + virtual void battleStackMoved(int ID, int dest, int distance){}; + virtual void battleStackAttacking(int ID, int dest){}; + virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting){}; + virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;}; +}; + +#endif // __CGAMEINTERFACE_H__ diff --git a/CMessage.cpp b/CMessage.cpp index e18887355..e6919ed22 100644 --- a/CMessage.cpp +++ b/CMessage.cpp @@ -110,66 +110,86 @@ SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor) //draws box for return ret; } -std::vector * CMessage::breakText(std::string text, size_t line, bool userBreak, bool ifor) //TODO userBreak -- use me +/* The map file contains long texts, with or without line breaks. This + * method takes such a text and breaks it into into several lines. */ +std::vector * CMessage::breakText(std::string text, size_t max_line_size, + bool userBreak, bool ifor) { std::vector * ret = new std::vector(); - while (text.length()>line) - { - int whereCut = -1, braces=0; - bool pom = true, opened=false; - for (size_t i=0; i0&&pom; i--) - { - if (text[i]==' ') - { - whereCut = i; - break; - } - else if (opened && text[i]=='{') - opened = false; - else if (text[i]=='}') - opened = true; + + if ((text[z] != 0) && (text[z] != 0x0a)) { + /* We have a long line. Try to do a nice line break, if + * possible. We backtrack on the line until we find a + * suitable character. */ + int pos = z-1; + + /* TODO: boost should have a nice method to do that. */ + while(pos > 0 && + text[pos] != ' ' && + text[pos] != ',' && + text[pos] != '.' && + text[pos] != ';' && + text[pos] != '!' && + text[pos] != '?') + pos --; + if (pos > 0) + z = pos+1; } - ret->push_back(text.substr(0,whereCut)); - text.erase(0,whereCut); - boost::algorithm::trim_left_if(text,boost::algorithm::is_any_of(" ")); - if (opened) - { - (*(ret->end()-1))+='}'; - text.insert(0,"{"); + + /* Note: empty lines will be skipped. Is that different than H3? */ + if (z) { + ret->push_back(text.substr(0, z)); + + if (opened) + /* Close the brace for the current line. */ + (*(ret->end()-1))+='}'; + + text.erase(0, z); + } + + if (text[0] == 0x0a) { + /* Braces do not carry over lines. The map author forgot + * to close it. */ + opened = false; + + /* Remove LF */ + text.erase(0, 1); + } + + boost::algorithm::trim(text); + + if (opened) { + /* Add an opening brace for the next line. */ + if (text.length()) + text.insert(0, "{"); } } - for (size_t i=0;ipush_back(text.substr(0,i)); - text.erase(0,i); - i=0; - } - } - if (text.length() > 0) - ret->push_back(text); + + /* Trim whitespaces of every line. */ for (size_t i=0; isize(); i++) - { boost::algorithm::trim((*ret)[i]); - } + return ret; } @@ -178,7 +198,7 @@ std::pair CMessage::getMaxSizes(std::vector > std::pair ret; ret.first = -1; ret.second=0; - for (size_t i=0; isize();i++) //szukamy najszerszej linii i lacznej wysokosci + for (size_t i=0; isize();i++) //we are searching widest line and total height { int lw=0; for (size_t j=0;j<(*txtg)[i].size();j++) @@ -223,33 +243,40 @@ std::vector > * CMessage::drawText(std::vectorresize(brtext->size()); for (size_t i=0; isize();i++) //foreach line { - while((*brtext)[i].length()) //jesli zostalo cos + while((*brtext)[i].length()) //if something left { - size_t z=0; bool br=true; - while( ((*brtext)[i][z]) != ('{') ) - { - if (z >= (((*brtext)[i].length())-1)) - { - br=false; - break; - } - z++; - } - if (!br) + size_t z; + + /* Handle normal text. */ + z = 0; + while((*brtext)[i][z]!= 0 && (*brtext)[i][z] != ('{')) z++; + if (z) - (*txtg)[i].push_back(TTF_RenderText_Blended(font,(*brtext)[i].substr(0,z).c_str(),zwykly)); + (*txtg)[i].push_back(TTF_RenderText_Blended(font, (*brtext)[i].substr(0,z).c_str(), zwykly)); (*brtext)[i].erase(0,z); - z=0; - if ( ((*brtext)[i].length()==0) || ((*brtext)[i][z]!='{') ) - { + + if ((*brtext)[i][0] == '{') + /* Remove '{' */ + (*brtext)[i].erase(0,1); + + if ((*brtext)[i].length()==0) + /* End of line */ continue; - } - while( ((*brtext)[i][++z]) != ('}') ) - {} - //tyemp = (*brtext)[i].substr(1,z-1); //od 1 bo pomijamy otwierajaca klamre - (*txtg)[i].push_back(TTF_RenderText_Blended(font,(*brtext)[i].substr(1,z-1).c_str(),tytulowy)); - (*brtext)[i].erase(0,z+1); //z+1 bo dajemy zamykajaca klamre + + /* This text will be highlighted. */ + z = 0; + while((*brtext)[i][z]!= 0 && (*brtext)[i][z] != ('}')) + z++; + + if (z) + (*txtg)[i].push_back(TTF_RenderText_Blended(font, (*brtext)[i].substr(0,z).c_str(), tytulowy)); + (*brtext)[i].erase(0,z); + + if ((*brtext)[i][0] == '}') + /* Remove '}' */ + (*brtext)[i].erase(0,1); + } //ends while((*brtext)[i].length()) } //ends for(int i=0; isize();i++) return txtg; @@ -367,13 +394,13 @@ SDL_Surface * CMessage::genMessage { //max x 320 okolo 30 znakow std::vector * tekst; - if (text.length() < 30) //nie trzeba polamac + if (text.length() < 30) //does not need breaking { tekst = new std::vector(); tekst->push_back(text); } else tekst = breakText(text); - int ww, hh; //wymiary boksa + int ww, hh; //dimensions of box if (319>30+13*text.length()) ww = 30+13*text.length(); else ww = 319; @@ -428,7 +455,7 @@ SDL_Surface * CMessage::genMessage void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x, int y) { - //obwodka I-szego rzedu pozioma + //obwodka I-szego rzedu pozioma //border of 1st series, horizontal for (int i=0; iw; i+=piecesOfBox[playerColor][6]->w) { SDL_BlitSurface @@ -436,7 +463,7 @@ void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int SDL_BlitSurface (piecesOfBox[playerColor][7],NULL,ret,&genRect(piecesOfBox[playerColor][7]->h,piecesOfBox[playerColor][7]->w,x+i,y+h-piecesOfBox[playerColor][7]->h)); } - //obwodka I-szego rzedu pionowa + //obwodka I-szego rzedu pionowa //border of 1st series, vertical for (int i=0; ih; i+=piecesOfBox[playerColor][4]->h) { SDL_BlitSurface @@ -505,6 +532,7 @@ ComponentsToBlit::ComponentsToBlit(std::vector & SComps, int maxw, int toadd = (SComps[i]->getImg()->w + 12 + (_or ? _or->w : 0)); if (curw + toadd > maxw) { + curr++; amax(w,curw); curw = SComps[i]->getImg()->w; comps.resize(curr+1); diff --git a/CMessage.h b/CMessage.h index 665534d12..85cfcbcbf 100644 --- a/CMessage.h +++ b/CMessage.h @@ -1,11 +1,11 @@ -#ifndef __CMESSAGE_H__ -#define __CMESSAGE_H__ - -#include "global.h" -#include -#include -#include "CPreGame.h" - +#ifndef __CMESSAGE_H__ +#define __CMESSAGE_H__ + +#include "global.h" +#include +#include +#include "CPreGame.h" + /* * CMessage.h, part of VCMI engine * @@ -14,66 +14,66 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -enum EWindowType {infoOnly, infoOK, yesOrNO}; -class CPreGame; -class MapSel; -class CSimpleWindow; -class CInfoWindow; -class CDefHandler; -class SComponent; -class CSelWindow; -class CSelectableComponent; -namespace NMessage -{ - extern CDefHandler * ok, *cancel; - extern std::vector > piecesOfBox; //in colors of all players - extern SDL_Surface * background ; -} - -struct ComponentResolved -{ - SComponent *comp; - - SDL_Surface *img; - std::vector > * txt; - - ComponentResolved(); - ComponentResolved(SComponent *Comp); - ~ComponentResolved(); -}; - -struct ComponentsToBlit -{ - std::vector< std::vector > comps; - int w, h; - - void blitCompsOnSur(SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret); - ComponentsToBlit(std::vector & SComps, int maxw, SDL_Surface* _or); - ~ComponentsToBlit(); -}; - -class CMessage -{ -public: - - static std::pair getMaxSizes(std::vector > * txtg); - static std::vector > * drawText(std::vector * brtext, TTF_Font *font = NULL); - static SDL_Surface * blitTextOnSur(std::vector > * txtg, int & curh, SDL_Surface * ret, int xCenterPos=-1); //xPos==-1 works as if ret->w/2 - static void drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline); - static CSimpleWindow * genWindow(std::string text, int player, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins - static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly, - std::vector *addPics=NULL, void * cb=NULL); - static SDL_Surface * drawBox1(int w, int h, int playerColor=1); - static void drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x=0, int y=0); - static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30, int imgToBmp=55); - static std::vector * breakText(std::string text, size_t line=30, bool userBreak=true, bool ifor=true); //line - chars per line - static void init(); - static void dispose(); -}; -// - - - -#endif // __CMESSAGE_H__ + */ + +enum EWindowType {infoOnly, infoOK, yesOrNO}; +class CPreGame; +class MapSel; +class CSimpleWindow; +class CInfoWindow; +class CDefHandler; +class SComponent; +class CSelWindow; +class CSelectableComponent; +namespace NMessage +{ + extern CDefHandler * ok, *cancel; + extern std::vector > piecesOfBox; //in colors of all players + extern SDL_Surface * background ; +} + +struct ComponentResolved +{ + SComponent *comp; + + SDL_Surface *img; + std::vector > * txt; + + ComponentResolved(); + ComponentResolved(SComponent *Comp); + ~ComponentResolved(); +}; + +struct ComponentsToBlit +{ + std::vector< std::vector > comps; + int w, h; + + void blitCompsOnSur(SDL_Surface * _or, int inter, int &curh, SDL_Surface *ret); + ComponentsToBlit(std::vector & SComps, int maxw, SDL_Surface* _or); + ~ComponentsToBlit(); +}; + +class CMessage +{ +public: + + static std::pair getMaxSizes(std::vector > * txtg); + static std::vector > * drawText(std::vector * brtext, TTF_Font *font = NULL); + static SDL_Surface * blitTextOnSur(std::vector > * txtg, int & curh, SDL_Surface * ret, int xCenterPos=-1); //xPos==-1 works as if ret->w/2 + static void drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline); + static CSimpleWindow * genWindow(std::string text, int player, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins + static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly, + std::vector *addPics=NULL, void * cb=NULL); + static SDL_Surface * drawBox1(int w, int h, int playerColor=1); + static void drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x=0, int y=0); + static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30, int imgToBmp=55); + static std::vector * breakText(std::string text, size_t max_line_size=30, bool userBreak=true, bool ifor=true); + static void init(); + static void dispose(); +}; +// + + + +#endif // __CMESSAGE_H__ diff --git a/CPreGame.h b/CPreGame.h index 3d3c6466c..0f7104238 100644 --- a/CPreGame.h +++ b/CPreGame.h @@ -1,16 +1,16 @@ -#ifndef __CPREGAME_H__ -#define __CPREGAME_H__ -#include "global.h" -#include -#include -#include "StartInfo.h" -#include "CMessage.h" -#include "map.h" -#include "hch/CMusicHandler.h" -#include -#include -#include - +#ifndef __CPREGAME_H__ +#define __CPREGAME_H__ +#include "global.h" +#include +#include +#include "StartInfo.h" +#include "CMessage.h" +#include "map.h" +#include "hch/CMusicHandler.h" +#include +#include +#include + /* * CPreGame.h, part of VCMI engine * @@ -19,293 +19,293 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CPreGame; -class CDefHandler; -extern CPreGame * CPG; - -typedef void(CPreGame::*ttt)(); -class CGroup; -class CPoinGroup ; -class IntSelBut; - -struct HighButton -{ - int ID; - int type; - SDL_Rect pos; - CDefHandler* imgs; - int state; - bool freeimgs; - HighButton( SDL_Rect Pos, CDefHandler* Imgs, bool Sel=false, int id=-1); - HighButton(); - virtual ~HighButton(); - bool selectable, selected; - bool highlightable, highlighted; - virtual void show(); - virtual void press(bool down=true); - virtual void hover(bool on=true)=0; - virtual void select(bool on=true)=0; -}; -struct Button: public HighButton -{ - CGroup *ourGroup; - Button( SDL_Rect Pos, boost::function Fun,CDefHandler* Imgs, bool Sel=false, CGroup* gr=NULL, int id=-1); - Button(); - boost::function fun; - virtual void hover(bool on=true); - virtual void select(bool on=true); -}; -struct SetrButton: public Button -{ - int key, * poin; - virtual void press(bool down=true); - SetrButton(); -}; - -class Slider -{ -public: - bool vertical; // false means horizontal - SDL_Rect pos; // position - Button *up, *down, //or left/right - *slider; - int positionsAmnt, capacity;// capacity - amount of positions dispplayed at once - int whereAreWe; // first displayed thing - bool moving; - boost::function fun; - void clickDown(int x, int y, bool bzgl=true); - void clickUp(int x, int y, bool bzgl=true); - void mMove(int x, int y, bool bzgl=true); - void moveUp(); - void moveDown(); - void deactivate(); - void activate(); - Slider(int x, int y, int h, int amnt, int cap, bool ver); - ~Slider(); - void updateSlid(); - void handleIt(SDL_Event sev); -}; - -struct IntBut: public Button -{ -public: - int key; - int * what; - IntBut(); - void set(); -}; -class CGroup -{ -public: - Button * selected; - int type; // 1=sinsel - CGroup():selected(NULL),type(0){}; -}; - -class CPoinGroup :public CGroup -{ -public: - int * gdzie; //where (po polsku, bo by by�o s�owo kluczowe :/) - void setYour(IntSelBut * your); -}; -struct IntSelBut: public Button -{ -public: - CPoinGroup * ourPoinGroup; - int key; - IntSelBut(){}; - IntSelBut( SDL_Rect Pos, boost::function Fun,CDefHandler* Imgs, bool Sel=false, CPoinGroup* gr=NULL, int My=-1); - void select(bool on=true); -}; -class PreGameTab -{ -public: - bool showed; - virtual void init()=0; - virtual void show()=0; - virtual void hide()=0; - PreGameTab(); -}; -class RanSel : public PreGameTab -{ - Button horcpl[9], horcte[9], conpl[9], conte[8], water[4], monster[4], //last is random - size[4], twoLevel, showRand; - CGroup *Ghorcpl, *Ghorcte, *Gconpl, *Gconte, *Gwater, *Gmonster, *Gsize; -}; -class Options : public PreGameTab -{ - bool inited; - struct OptionSwitch:public HighButton - { - void hover(bool on=true){}; - void select(bool on=true){}; - OptionSwitch( SDL_Rect Pos, CDefHandler* Imgs, bool Left, int Which) - :HighButton(Pos,Imgs,false,7),left(Left),which(Which) - {selectable=false;highlightable=false;} - void press(bool down=true); - bool left; - int playerID; - int serialID; - int which; //-1=castle;0=hero;1=bonus - }; - struct PlayerFlag:public HighButton - { - int color; - PlayerFlag(SDL_Rect Pos, CDefHandler* Imgs, int Color) - :HighButton(Pos,Imgs,false,7),color(Color) - {selectable=false;highlightable=true;} - void hover(bool on=true); - void press(bool down=true); - void select(bool on=true){}; - }; - struct PlayerOptions - { - PlayerOptions(int serial, int player); - Ecolor color; - PlayerFlag flag; - //SDL_Surface * bg; - OptionSwitch Cleft, Cright, Hleft, Hright, Bleft, Bright; - int nr; - }; -public: - std::set usedHeroes; - Slider * turnLength; - SDL_Surface * bg, - * rHero, * rCastle, * nHero, * nCastle; - std::vector bgs; - std::vector flags; - CDefHandler //* castles, * heroes, * bonus, - * left, * right, - * bonuses; - std::vector poptions; - void show(); - void hide(); - void init(); - void showIcon (int what, int nr, bool abs); //what: -1=castle, 0=hero, 1=bonus, 2=all; abs=true -> nr is absolute - bool canUseThisHero(int ID); - int nextAllowedHero(int min, int max, int incl, int dir); //incl 0 - wlacznie; incl 1 - wylacznie; min-max - zakres szukania - Options(){inited=showed=false;}; - ~Options(); -}; -class MapSel : public PreGameTab -{ -public: - ESortBy sortBy; - SDL_Surface * bg; - int selected; //selected map - CDefHandler * Dtypes, * Dvic; - CDefHandler *Dsizes, * Dloss, - * sFlags; - std::vector scenImgs; - //int current; - std::vector ourMaps; - std::vector ourGames; - IntBut small, medium, large, xlarge, all; - SetrButton nrplayer, mapsize, type, name, viccon, loscon; - Slider *slid, *descslid; - int sizeFilter; - int whichWL(int nr); - int countWL(); - void show(); - void hide(); - void init(); - std::string gdiff(std::string ss); - void printMaps(int from,int to=18, int at=0, bool abs=false); - void select(int which, bool updateMapsList=true, bool forceSettingsUpdate=false); - void moveByOne(bool up); - void printSelectedInfo(); - void printFlags(); - void processMaps(const std::vector &pliczkiTemp, int start, int threads); - void processGames(const std::vector &pliczkiTemp); - CMapInfo &selectedMap(); - std::vector &curVector(); - MapSel(); - ~MapSel(); -}; -class ScenSel -{ -public: - CPoinGroup * difficulty; - bool listShowed; - //RanSel ransel; - MapSel mapsel; - SDL_Surface * background, *savenameStrip, *scenInf, *scenList, *randMap, *options ; - Button bScens, bOptions, bRandom, bBegin, bLoad, bBack; - IntSelBut bEasy, bNormal, bHard, bExpert, bImpossible; - Button * pressed; - std::vector maps; - int selectedDiff; - void initRanSel(); - void showRanSel(); - void hideRanSel(); - void genScenList(); - ScenSel(); - ~ScenSel(); -} ; -class CPreGame -{ -public: - std::string playerName; - int playerColor; - HighButton * highlighted; - PreGameTab* currentTab; - StartInfo ret; - bool run; - bool first; //hasn't we showed the scensel - int fromnewgame; //1 - new game; 0 - load game; 2 - save game - std::vector interested; - CMusicHandler * mush; - std::vector btns; - SDL_Rect * currentMessage; - SDL_Surface * behindCurMes; - CDefHandler *ok, *cancel; - enum EState { //where are we? - mainMenu, newGame, loadGame, ScenarioList - } state; - struct menuItems { - menuItems(); - ~menuItems(); - SDL_Surface * background, *bgAd; - CDefHandler *newGame, *loadGame, *highScores,*credits, *quit; - SDL_Rect lNewGame, lLoadGame, lHighScores, lCredits, lQuit; - ttt fNewGame, fLoadGame, fHighScores, fCredits, fQuit; - int highlighted;//0=none; 1=new game; 2=load game; 3=high score; 4=credits; 5=quit - } * ourMainMenu, * ourNewMenu, * ourLoadMenu; - ScenSel *ourScenSel; - Options * ourOptions; - std::string map; //selected map - CPreGame(); //c-tor - ~CPreGame();//d-tor - std::string buttonText(int which); - menuItems * currentItems(); - void(CPreGame::*handleOther)(SDL_Event&); - void scenHandleEv(SDL_Event& sEvent); - void begin(){run=false;ret.difficulty=ourScenSel->selectedDiff;}; - void quitAskBox(); - void quit(){exit(EXIT_SUCCESS);}; - void initScenSel(); - void showScenSel(); - void showScenList(); - void initOptions(); - void showOptions(); - void initNewMenu(); - void initLoadMenu(); - void showNewMenu(); - void showLoadMenu(); - void showMainMenu(); - StartInfo runLoop(); // runs mainloop of PreGame - void initMainMenu(); //loads components for main menu - void highlightButton(int which, int on); //highlights one from 5 main menu buttons - void showCenBox (std::string data); // - void showAskBox (std::string data, void(*f1)(),void(*f2)()); - void hideBox (); - void printRating(); - void printMapsFrom(int from); - void setTurnLength(int on); - void sortMaps(); -}; - - -#endif // __CPREGAME_H__ + */ + +class CPreGame; +class CDefHandler; +extern CPreGame * CPG; + +typedef void(CPreGame::*ttt)(); +class CGroup; +class CPoinGroup ; +class IntSelBut; + +struct HighButton +{ + int ID; + int type; + SDL_Rect pos; + CDefHandler* imgs; + int state; + bool freeimgs; + HighButton( SDL_Rect Pos, CDefHandler* Imgs, bool Sel=false, int id=-1); + HighButton(); + virtual ~HighButton(); + bool selectable, selected; + bool highlightable, highlighted; + virtual void show(); + virtual void press(bool down=true); + virtual void hover(bool on=true)=0; + virtual void select(bool on=true)=0; +}; +struct Button: public HighButton +{ + CGroup *ourGroup; + Button( SDL_Rect Pos, boost::function Fun,CDefHandler* Imgs, bool Sel=false, CGroup* gr=NULL, int id=-1); + Button(); + boost::function fun; + virtual void hover(bool on=true); + virtual void select(bool on=true); +}; +struct SetrButton: public Button +{ + int key, * poin; + virtual void press(bool down=true); + SetrButton(); +}; + +class Slider +{ +public: + bool vertical; // false means horizontal + SDL_Rect pos; // position + Button *up, *down, //or left/right + *slider; + int positionsAmnt, capacity;// capacity - amount of positions dispplayed at once + int whereAreWe; // first displayed thing + bool moving; + boost::function fun; + void clickDown(int x, int y, bool bzgl=true); + void clickUp(int x, int y, bool bzgl=true); + void mMove(int x, int y, bool bzgl=true); + void moveUp(); + void moveDown(); + void deactivate(); + void activate(); + Slider(int x, int y, int h, int amnt, int cap, bool ver); + ~Slider(); + void updateSlid(); + void handleIt(SDL_Event sev); +}; + +struct IntBut: public Button +{ +public: + int key; + int * what; + IntBut(); + void set(); +}; +class CGroup +{ +public: + Button * selected; + int type; // 1=sinsel + CGroup():selected(NULL),type(0){}; +}; + +class CPoinGroup :public CGroup +{ +public: + int * gdzie; //where (po polsku, bo by by�o s�owo kluczowe :/) + void setYour(IntSelBut * your); +}; +struct IntSelBut: public Button +{ +public: + CPoinGroup * ourPoinGroup; + int key; + IntSelBut(){}; + IntSelBut( SDL_Rect Pos, boost::function Fun,CDefHandler* Imgs, bool Sel=false, CPoinGroup* gr=NULL, int My=-1); + void select(bool on=true); +}; +class PreGameTab +{ +public: + bool showed; + virtual void init()=0; + virtual void show()=0; + virtual void hide()=0; + PreGameTab(); +}; +class RanSel : public PreGameTab +{ + Button horcpl[9], horcte[9], conpl[9], conte[8], water[4], monster[4], //last is random + size[4], twoLevel, showRand; + CGroup *Ghorcpl, *Ghorcte, *Gconpl, *Gconte, *Gwater, *Gmonster, *Gsize; +}; +class Options : public PreGameTab +{ + bool inited; + struct OptionSwitch:public HighButton + { + void hover(bool on=true){}; + void select(bool on=true){}; + OptionSwitch( SDL_Rect Pos, CDefHandler* Imgs, bool Left, int Which) + :HighButton(Pos,Imgs,false,7),left(Left),which(Which) + {selectable=false;highlightable=false;} + void press(bool down=true); + bool left; + int playerID; + int serialID; + int which; //-1=castle;0=hero;1=bonus + }; + struct PlayerFlag:public HighButton + { + int color; + PlayerFlag(SDL_Rect Pos, CDefHandler* Imgs, int Color) + :HighButton(Pos,Imgs,false,7),color(Color) + {selectable=false;highlightable=true;} + void hover(bool on=true); + void press(bool down=true); + void select(bool on=true){}; + }; + struct PlayerOptions + { + PlayerOptions(int serial, int player); + Ecolor color; + PlayerFlag flag; + //SDL_Surface * bg; + OptionSwitch Cleft, Cright, Hleft, Hright, Bleft, Bright; + int nr; + }; +public: + std::set usedHeroes; + Slider * turnLength; + SDL_Surface * bg, + * rHero, * rCastle, * nHero, * nCastle; + std::vector bgs; + std::vector flags; + CDefHandler //* castles, * heroes, * bonus, + * left, * right, + * bonuses; + std::vector poptions; + void show(); + void hide(); + void init(); + void showIcon (int what, int nr, bool abs); //what: -1=castle, 0=hero, 1=bonus, 2=all; abs=true -> nr is absolute + bool canUseThisHero(int ID); + int nextAllowedHero(int min, int max, int incl, int dir); //incl 0 - wlacznie; incl 1 - wylacznie; min-max - zakres szukania + Options(){inited=showed=false;}; + ~Options(); +}; +class MapSel : public PreGameTab +{ +public: + ESortBy sortBy; + SDL_Surface * bg; + int selected; //selected map + CDefHandler * Dtypes, * Dvic; + CDefHandler *Dsizes, * Dloss, + * sFlags; + std::vector scenImgs; + //int current; + std::vector ourMaps; + std::vector ourGames; + IntBut small, medium, large, xlarge, all; + SetrButton nrplayer, mapsize, type, name, viccon, loscon; + Slider *slid, *descslid; + int sizeFilter; + int whichWL(int nr); + int countWL(); + void show(); + void hide(); + void init(); + std::string gdiff(std::string ss); + void printMaps(int from,int to=18, int at=0, bool abs=false); + void select(int which, bool updateMapsList=true, bool forceSettingsUpdate=false); + void moveByOne(bool up); + void printSelectedInfo(); + void printFlags(); + void processMaps(const std::vector &pliczkiTemp, int start, int threads); + void processGames(const std::vector &pliczkiTemp); + CMapInfo &selectedMap(); + std::vector &curVector(); + MapSel(); + ~MapSel(); +}; +class ScenSel +{ +public: + CPoinGroup * difficulty; + bool listShowed; + //RanSel ransel; + MapSel mapsel; + SDL_Surface * background, *savenameStrip, *scenInf, *scenList, *randMap, *options ; + Button bScens, bOptions, bRandom, bBegin, bLoad, bBack; + IntSelBut bEasy, bNormal, bHard, bExpert, bImpossible; + Button * pressed; + std::vector maps; + int selectedDiff; + void initRanSel(); + void showRanSel(); + void hideRanSel(); + void genScenList(); + ScenSel(); + ~ScenSel(); +} ; +class CPreGame +{ +public: + std::string playerName; + int playerColor; + HighButton * highlighted; + PreGameTab* currentTab; + StartInfo ret; + bool run; + bool first; //hasn't we showed the scensel + int fromnewgame; //1 - new game; 0 - load game; 2 - save game + std::vector interested; + CMusicHandler * mush; + std::vector btns; + SDL_Rect * currentMessage; + SDL_Surface * behindCurMes; + CDefHandler *ok, *cancel; + enum EState { //where are we? + mainMenu, newGame, loadGame, ScenarioList + } state; + struct menuItems { + menuItems(); + ~menuItems(); + SDL_Surface * background, *bgAd; + CDefHandler *newGame, *loadGame, *highScores,*credits, *quit; + SDL_Rect lNewGame, lLoadGame, lHighScores, lCredits, lQuit; + ttt fNewGame, fLoadGame, fHighScores, fCredits, fQuit; + int highlighted;//0=none; 1=new game; 2=load game; 3=high score; 4=credits; 5=quit + } * ourMainMenu, * ourNewMenu, * ourLoadMenu; + ScenSel *ourScenSel; + Options * ourOptions; + std::string map; //selected map + CPreGame(); //c-tor + ~CPreGame();//d-tor + std::string buttonText(int which); + menuItems * currentItems(); + void(CPreGame::*handleOther)(SDL_Event&); + void scenHandleEv(SDL_Event& sEvent); + void begin(){run=false;ret.difficulty=ourScenSel->selectedDiff;}; + void quitAskBox(); + void quit(){exit(EXIT_SUCCESS);}; + void initScenSel(); + void showScenSel(); + void showScenList(); + void initOptions(); + void showOptions(); + void initNewMenu(); + void initLoadMenu(); + void showNewMenu(); + void showLoadMenu(); + void showMainMenu(); + StartInfo runLoop(); // runs mainloop of PreGame + void initMainMenu(); //loads components for main menu + void highlightButton(int which, int on); //highlights one from 5 main menu buttons + void showCenBox (std::string data); // + void showAskBox (std::string data, void(*f1)(),void(*f2)()); + void hideBox (); + void printRating(); + void printMapsFrom(int from); + void setTurnLength(int on); + void sortMaps(); +}; + + +#endif // __CPREGAME_H__ diff --git a/CThreadHelper.h b/CThreadHelper.h index 83e2f1b6f..2b2b6c944 100644 --- a/CThreadHelper.h +++ b/CThreadHelper.h @@ -1,11 +1,11 @@ -#ifndef __CTHREADHELPER_H__ -#define __CTHREADHELPER_H__ - -#include "global.h" -#include -#include - - +#ifndef __CTHREADHELPER_H__ +#define __CTHREADHELPER_H__ + +#include "global.h" +#include +#include + + /* * CThreadHelper.h, part of VCMI engine * @@ -14,42 +14,42 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -typedef boost::function Task; - -class CThreadHelper -{ - boost::mutex rtinm; - int currentTask, amount, threads; - std::vector *tasks; - - - void processTasks(); -public: - CThreadHelper(std::vector > *Tasks, int Threads); - void run(); -}; - -template inline void setData(T * data, boost::function func) -{ - *data = func(); -} - - -#define GET_DATA(TYPE,DESTINATION,FUNCTION_TO_GET) \ - (boost::bind(&setData,&DESTINATION,FUNCTION_TO_GET)) -#define GET_SURFACE(SUR_DESTINATION, SUR_NAME) \ - (GET_DATA \ - (SDL_Surface*,SUR_DESTINATION,\ - boost::function(boost::bind(&BitmapHandler::loadBitmap,SUR_NAME,true)))) -#define GET_DEF(DESTINATION, DEF_NAME) \ - (GET_DATA \ - (CDefHandler*,DESTINATION,\ - boost::function(boost::bind(CDefHandler::giveDef,DEF_NAME,(CLodHandler*)NULL)))) -#define GET_DEF_ESS(DESTINATION, DEF_NAME) \ - (GET_DATA \ - (CDefEssential*,DESTINATION,\ - boost::function(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL)))) - -#endif // __CTHREADHELPER_H__ + */ + +typedef boost::function Task; + +class CThreadHelper +{ + boost::mutex rtinm; + int currentTask, amount, threads; + std::vector *tasks; + + + void processTasks(); +public: + CThreadHelper(std::vector > *Tasks, int Threads); + void run(); +}; + +template inline void setData(T * data, boost::function func) +{ + *data = func(); +} + + +#define GET_DATA(TYPE,DESTINATION,FUNCTION_TO_GET) \ + (boost::bind(&setData,&DESTINATION,FUNCTION_TO_GET)) +#define GET_SURFACE(SUR_DESTINATION, SUR_NAME) \ + (GET_DATA \ + (SDL_Surface*,SUR_DESTINATION,\ + boost::function(boost::bind(&BitmapHandler::loadBitmap,SUR_NAME,true)))) +#define GET_DEF(DESTINATION, DEF_NAME) \ + (GET_DATA \ + (CDefHandler*,DESTINATION,\ + boost::function(boost::bind(CDefHandler::giveDef,DEF_NAME,(CLodHandler*)NULL)))) +#define GET_DEF_ESS(DESTINATION, DEF_NAME) \ + (GET_DATA \ + (CDefEssential*,DESTINATION,\ + boost::function(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL)))) + +#endif // __CTHREADHELPER_H__ diff --git a/SDL_Extensions.h b/SDL_Extensions.h index 814df5d0f..c025122b9 100644 --- a/SDL_Extensions.h +++ b/SDL_Extensions.h @@ -1,8 +1,8 @@ -#ifndef __SDL_EXTENSIONS_H__ -#define __SDL_EXTENSIONS_H__ -#include "SDL.h" -#include "SDL_ttf.h" - +#ifndef __SDL_EXTENSIONS_H__ +#define __SDL_EXTENSIONS_H__ +#include "SDL.h" +#include "SDL_ttf.h" + /* * SDL_Extensions.h, part of VCMI engine * @@ -11,80 +11,80 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -extern SDL_Surface * screen, *screen2; -extern SDL_Color tytulowy, tlo, zwykly ; -extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM; -void blitAtWR(SDL_Surface * src, int x, int y, SDL_Surface * dst=screen); -void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=screen); -void blitAtWR(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst=screen); -void blitAt(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst=screen); -void updateRect (SDL_Rect * rect, SDL_Surface * scr = screen); -bool isItIn(const SDL_Rect * rect, int x, int y); -template int getIndexOf(const std::vector & v, const T & val) -{ - for(int i=0;ipixels + y * ekran->pitch + x * ekran->format->BytesPerPixel; - - p[0] = B; - p[1] = G; - p[2] = R; - if(ekran->format->BytesPerPixel==4) - p[3] = A; - } - - SDL_Surface * rotate01(SDL_Surface * toRot); //vertical flip - SDL_Surface * hFlip(SDL_Surface * toRot); //horizontal flip - SDL_Surface * rotate02(SDL_Surface * toRot); //rotate 90 degrees left - SDL_Surface * rotate03(SDL_Surface * toRot); //rotate 180 degrees - SDL_Cursor * SurfaceToCursor(SDL_Surface *image, int hx, int hy); - Uint32 SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte = false); - SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y); - SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details) - void blitWithRotate1(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests - void blitWithRotate2(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests - void blitWithRotate3(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests - void blitWithRotate1clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests preserving clip_rect - void blitWithRotate2clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests preserving clip_rect - void blitWithRotate3clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests preserving clip_rect - int blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface - Uint32 colorToUint32(const SDL_Color * color); //little endian only - void printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y) - void printToWR(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y) - void printAtMiddle(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2, bool refresh = false); // quality: 0 - lowest, 1 - medium, 2 - highest - void printAtMiddleWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen); - void printAtWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen); - void printAt(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2, bool refresh = false); // quality: 0 - lowest, 1 - medium, 2 - highest - void printAtWR(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest - void update(SDL_Surface * what = screen); //updates whole surface (default - main screen) - void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 color); - void setPlayerColor(SDL_Surface * sur, unsigned char player); //sets correct color of flags; -1 for neutral - std::string processStr(std::string str, std::vector & tor); //replaces %s in string - SDL_Surface * newSurface(int w, int h, SDL_Surface * mod=screen); //creates new surface, with flags/format same as in surface given - SDL_Surface * copySurface(SDL_Surface * mod); //returns copy of given surface -}; - - -#endif // __SDL_EXTENSIONS_H__ + */ + +extern SDL_Surface * screen, *screen2; +extern SDL_Color tytulowy, tlo, zwykly ; +extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM; +void blitAtWR(SDL_Surface * src, int x, int y, SDL_Surface * dst=screen); +void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=screen); +void blitAtWR(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst=screen); +void blitAt(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst=screen); +void updateRect (SDL_Rect * rect, SDL_Surface * scr = screen); +bool isItIn(const SDL_Rect * rect, int x, int y); +template int getIndexOf(const std::vector & v, const T & val) +{ + for(int i=0;ipixels + y * ekran->pitch + x * ekran->format->BytesPerPixel; + + p[0] = B; + p[1] = G; + p[2] = R; + if(ekran->format->BytesPerPixel==4) + p[3] = A; + } + + SDL_Surface * rotate01(SDL_Surface * toRot); //vertical flip + SDL_Surface * hFlip(SDL_Surface * toRot); //horizontal flip + SDL_Surface * rotate02(SDL_Surface * toRot); //rotate 90 degrees left + SDL_Surface * rotate03(SDL_Surface * toRot); //rotate 180 degrees + SDL_Cursor * SurfaceToCursor(SDL_Surface *image, int hx, int hy); + Uint32 SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte = false); + SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y); + SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details) + void blitWithRotate1(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests + void blitWithRotate2(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests + void blitWithRotate3(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests + void blitWithRotate1clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests preserving clip_rect + void blitWithRotate2clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests preserving clip_rect + void blitWithRotate3clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests preserving clip_rect + int blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface + Uint32 colorToUint32(const SDL_Color * color); //little endian only + void printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y) + void printToWR(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y) + void printAtMiddle(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2, bool refresh = false); // quality: 0 - lowest, 1 - medium, 2 - highest + void printAtMiddleWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen); + void printAtWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen); + void printAt(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2, bool refresh = false); // quality: 0 - lowest, 1 - medium, 2 - highest + void printAtWR(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest + void update(SDL_Surface * what = screen); //updates whole surface (default - main screen) + void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 color); + void setPlayerColor(SDL_Surface * sur, unsigned char player); //sets correct color of flags; -1 for neutral + std::string processStr(std::string str, std::vector & tor); //replaces %s in string + SDL_Surface * newSurface(int w, int h, SDL_Surface * mod=screen); //creates new surface, with flags/format same as in surface given + SDL_Surface * copySurface(SDL_Surface * mod); //returns copy of given surface +}; + + +#endif // __SDL_EXTENSIONS_H__ diff --git a/StartInfo.h b/StartInfo.h index c8b875f3a..e27345b7c 100644 --- a/StartInfo.h +++ b/StartInfo.h @@ -1,9 +1,9 @@ -#ifndef __STARTINFO_H__ -#define __STARTINFO_H__ - -#include "global.h" -#include - +#ifndef __STARTINFO_H__ +#define __STARTINFO_H__ + +#include "global.h" +#include + /* * StartInfo.h, part of VCMI engine * @@ -12,61 +12,61 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -enum Ebonus {brandom=-1,bartifact, bgold, bresource}; - -struct PlayerSettings -{ - si32 castle, hero, //ID, if -1 then random, if -2 then none - heroPortrait; //-1 if default, else ID - std::string heroName; - si8 bonus; //usees enum type Ebonus - ui8 color; //from 0 - - ui8 serial; - ui8 handicap;//0-no, 1-mild, 2-severe - std::string name; - ui8 human; - template void serialize(Handler &h, const int version) - { - h & castle; - h & hero; - h & heroPortrait; - h & heroName; - h & bonus; - h & color; - h & serial; - h & handicap; - h & name; - h & human; - } -}; - -struct StartInfo -{ - ui8 mode; //0 - new game; 1 - load game - ui8 difficulty; //0=easy; 4=impossible - std::vector playerInfos; - ui8 turnTime; //in minutes, 0=unlimited - std::string mapname; - PlayerSettings & getIthPlayersSettings(int no) - { - for(unsigned int i=0; i void serialize(Handler &h, const int version) - { - h & mode; - h & difficulty; - h & playerInfos; - h & turnTime; - h & mapname; - } -}; - - -#endif // __STARTINFO_H__ + */ + +enum Ebonus {brandom=-1,bartifact, bgold, bresource}; + +struct PlayerSettings +{ + si32 castle, hero, //ID, if -1 then random, if -2 then none + heroPortrait; //-1 if default, else ID + std::string heroName; + si8 bonus; //usees enum type Ebonus + ui8 color; //from 0 - + ui8 serial; + ui8 handicap;//0-no, 1-mild, 2-severe + std::string name; + ui8 human; + template void serialize(Handler &h, const int version) + { + h & castle; + h & hero; + h & heroPortrait; + h & heroName; + h & bonus; + h & color; + h & serial; + h & handicap; + h & name; + h & human; + } +}; + +struct StartInfo +{ + ui8 mode; //0 - new game; 1 - load game + ui8 difficulty; //0=easy; 4=impossible + std::vector playerInfos; + ui8 turnTime; //in minutes, 0=unlimited + std::string mapname; + PlayerSettings & getIthPlayersSettings(int no) + { + for(unsigned int i=0; i void serialize(Handler &h, const int version) + { + h & mode; + h & difficulty; + h & playerInfos; + h & turnTime; + h & mapname; + } +}; + + +#endif // __STARTINFO_H__ diff --git a/client/CBitmapHandler.h b/client/CBitmapHandler.h index 829109d65..27f1b6444 100644 --- a/client/CBitmapHandler.h +++ b/client/CBitmapHandler.h @@ -1,12 +1,12 @@ -#ifndef __CBITMAPHANDLER_H__ -#define __CBITMAPHANDLER_H__ - - - -#include "../global.h" -struct SDL_Surface; -class CLodHandler; - +#ifndef __CBITMAPHANDLER_H__ +#define __CBITMAPHANDLER_H__ + + + +#include "../global.h" +struct SDL_Surface; +class CLodHandler; + /* * CBitmapHandler.h, part of VCMI engine * @@ -15,40 +15,40 @@ class CLodHandler; * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -enum Epcxformat {PCX8B, PCX24B}; - -struct BMPPalette -{ - unsigned char R,G,B,F; -}; -struct BMPHeader -{ - int fullSize, _h1, _h2, _h3, _c1, _c2, _c3, _c4, x, y, - dataSize1, dataSize2; //DataSize=X*Y+2*Y - unsigned char _c5[8]; - void print(std::ostream & out); - BMPHeader(){_h1=_h2=0;for(int i=0;i<8;i++)_c5[i]=0;}; -}; -class CPCXConv -{ -public: - unsigned char * pcx, *bmp; - int pcxs, bmps; - void fromFile(std::string path); - void saveBMP(std::string path); - void openPCX(char * PCX, int len); - void convert(); - SDL_Surface * getSurface(); //for standard H3 PCX - //SDL_Surface * getSurfaceZ(); //for ZSoft PCX - CPCXConv(){pcx=bmp=NULL;pcxs=bmps=0;}; - ~CPCXConv(){if (pcxs) delete[] pcx; if(bmps) delete[] bmp;} -}; -namespace BitmapHandler -{ - extern CLodHandler *bitmaph; - SDL_Surface * loadBitmap(std::string fname, bool setKey=false); -}; - -#endif // __CBITMAPHANDLER_H__ + */ + +enum Epcxformat {PCX8B, PCX24B}; + +struct BMPPalette +{ + unsigned char R,G,B,F; +}; +struct BMPHeader +{ + int fullSize, _h1, _h2, _h3, _c1, _c2, _c3, _c4, x, y, + dataSize1, dataSize2; //DataSize=X*Y+2*Y + unsigned char _c5[8]; + void print(std::ostream & out); + BMPHeader(){_h1=_h2=0;for(int i=0;i<8;i++)_c5[i]=0;}; +}; +class CPCXConv +{ +public: + unsigned char * pcx, *bmp; + int pcxs, bmps; + void fromFile(std::string path); + void saveBMP(std::string path); + void openPCX(char * PCX, int len); + void convert(); + SDL_Surface * getSurface(); //for standard H3 PCX + //SDL_Surface * getSurfaceZ(); //for ZSoft PCX + CPCXConv(){pcx=bmp=NULL;pcxs=bmps=0;}; + ~CPCXConv(){if (pcxs) delete[] pcx; if(bmps) delete[] bmp;} +}; +namespace BitmapHandler +{ + extern CLodHandler *bitmaph; + SDL_Surface * loadBitmap(std::string fname, bool setKey=false); +}; + +#endif // __CBITMAPHANDLER_H__ diff --git a/client/CConfigHandler.h b/client/CConfigHandler.h index 91f3ca7a6..0c5503c1a 100644 --- a/client/CConfigHandler.h +++ b/client/CConfigHandler.h @@ -1,8 +1,8 @@ -#ifndef __CCONFIGHANDLER_H__ -#define __CCONFIGHANDLER_H__ -#include "../global.h" -class CAdvMapInt; - +#ifndef __CCONFIGHANDLER_H__ +#define __CCONFIGHANDLER_H__ +#include "../global.h" +class CAdvMapInt; + /* * CConfighandler.h, part of VCMI engine * @@ -11,69 +11,69 @@ class CAdvMapInt; * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -namespace config -{ - struct ClientConfig - { - int resx, resy, bpp, fullscreen; //client resolution/colours - int port, localInformation; - std::string server, //server address (e.g. 127.0.0.1) - defaultAI; //dll name - }; - struct ButtonInfo - { - std::string defName; - std::vector additionalDefs; - int x, y; //position on the screen - bool playerColoured; //if true button will be colored to main player's color (works properly only for appropriate 8bpp graphics) - }; - struct AdventureMapConfig - { - //minimap properties - int minimapX, minimapY, minimapW, minimapH; - //statusbar - int statusbarX, statusbarY; //pos - std::string statusbarG; //graphic name - //resdatabar - int resdatabarX, resdatabarY, resDist, resDateDist, resOffsetX, resOffsetY; //pos - std::string resdatabarG; //graphic name - //infobox - int infoboxX, infoboxY; - //advmap - int tilesW, tilesH, advmapX, advmapY, advmapTrimX, advmapTrimY; - bool smoothMove; - //general properties - std::string mainGraphic; - //buttons - ButtonInfo kingOverview, underground, questlog, sleepWake, moveHero, spellbook, advOptions, - sysOptions, nextHero, endTurn; - //hero list - int hlistX, hlistY, hlistSize; - std::string hlistMB, hlistMN, hlistAU, hlistAD; - //town list - int tlistX, tlistY, tlistSize; - std::string tlistAU, tlistAD; - //gems - int gemX[4], gemY[4]; - std::vector gemG; - }; - struct GUIOptions - { - AdventureMapConfig ac; - }; - class CConfigHandler - { - public: - ClientConfig cc; - std::map, GUIOptions > guiOptions; - GUIOptions *go(); //return pointer to gui options appropriate for used screen resolution - void init(); - CConfigHandler(void); - ~CConfigHandler(void); - }; -} -extern config::CConfigHandler conf; - -#endif // __CCONFIGHANDLER_H__ + */ + +namespace config +{ + struct ClientConfig + { + int resx, resy, bpp, fullscreen; //client resolution/colours + int port, localInformation; + std::string server, //server address (e.g. 127.0.0.1) + defaultAI; //dll name + }; + struct ButtonInfo + { + std::string defName; + std::vector additionalDefs; + int x, y; //position on the screen + bool playerColoured; //if true button will be colored to main player's color (works properly only for appropriate 8bpp graphics) + }; + struct AdventureMapConfig + { + //minimap properties + int minimapX, minimapY, minimapW, minimapH; + //statusbar + int statusbarX, statusbarY; //pos + std::string statusbarG; //graphic name + //resdatabar + int resdatabarX, resdatabarY, resDist, resDateDist, resOffsetX, resOffsetY; //pos + std::string resdatabarG; //graphic name + //infobox + int infoboxX, infoboxY; + //advmap + int tilesW, tilesH, advmapX, advmapY, advmapTrimX, advmapTrimY; + bool smoothMove; + //general properties + std::string mainGraphic; + //buttons + ButtonInfo kingOverview, underground, questlog, sleepWake, moveHero, spellbook, advOptions, + sysOptions, nextHero, endTurn; + //hero list + int hlistX, hlistY, hlistSize; + std::string hlistMB, hlistMN, hlistAU, hlistAD; + //town list + int tlistX, tlistY, tlistSize; + std::string tlistAU, tlistAD; + //gems + int gemX[4], gemY[4]; + std::vector gemG; + }; + struct GUIOptions + { + AdventureMapConfig ac; + }; + class CConfigHandler + { + public: + ClientConfig cc; + std::map, GUIOptions > guiOptions; + GUIOptions *go(); //return pointer to gui options appropriate for used screen resolution + void init(); + CConfigHandler(void); + ~CConfigHandler(void); + }; +} +extern config::CConfigHandler conf; + +#endif // __CCONFIGHANDLER_H__ diff --git a/client/CCreatureAnimation.h b/client/CCreatureAnimation.h index 8172ef51f..3426ab212 100644 --- a/client/CCreatureAnimation.h +++ b/client/CCreatureAnimation.h @@ -1,11 +1,11 @@ -#ifndef __CCREATUREANIMATION_H__ -#define __CCREATUREANIMATION_H__ - - -#include "../global.h" -#include "../CPlayerInterface.h" -#include "../hch/CDefHandler.h" - +#ifndef __CCREATUREANIMATION_H__ +#define __CCREATUREANIMATION_H__ + + +#include "../global.h" +#include "../CPlayerInterface.h" +#include "../hch/CDefHandler.h" + /* * CCreatureAnimation.h, part of VCMI engine * @@ -14,58 +14,58 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CCreatureAnimation : public CIntObject -{ -private: - int totalEntries, DEFType, totalBlocks; - int length; - BMPPalette palette[256]; - int * RLEntries; - struct SEntry - { - int offset; - int group; - } ; - std::vector SEntries ; - std::string defName, curDir; - int readNormalNr (int pos, int bytCon, unsigned char * str=NULL) const; - void putPixel( - SDL_Surface * dest, - const int & ftcp, - const BMPPalette & color, - const unsigned char & palc, - const bool & yellowBorder, - const bool & blueBorder, - const unsigned char & animCount - ) const; - - //////////// - - unsigned char * FDef; //animation raw data - int curFrame, internalFrame; //number of currently displayed frame - unsigned int frames; //number of frames -public: - std::map > frameGroups; //groups of frames; [groupID] -> vector of frame IDs in group - int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1]) - int fullWidth, fullHeight; //read-only, please! - CCreatureAnimation(std::string name); //c-tor - ~CCreatureAnimation(); //d-tor - - void setType(int type); //sets type of animation and cleares framecount - int getType() const; //returns type of animation - - int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool incrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next - int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool IncrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next - void incrementFrame(); - int getFrame() const; - bool onLastFrameInGroup(); - - bool once; - void playOnce(int type); //plays once given stage of animation, then resets to 2 - - int framesInGroup(int group) const; //retirns number of fromes in given group -}; - -#endif // __CCREATUREANIMATION_H__ + */ + +class CCreatureAnimation : public CIntObject +{ +private: + int totalEntries, DEFType, totalBlocks; + int length; + BMPPalette palette[256]; + int * RLEntries; + struct SEntry + { + int offset; + int group; + } ; + std::vector SEntries ; + std::string defName, curDir; + int readNormalNr (int pos, int bytCon, unsigned char * str=NULL) const; + void putPixel( + SDL_Surface * dest, + const int & ftcp, + const BMPPalette & color, + const unsigned char & palc, + const bool & yellowBorder, + const bool & blueBorder, + const unsigned char & animCount + ) const; + + //////////// + + unsigned char * FDef; //animation raw data + int curFrame, internalFrame; //number of currently displayed frame + unsigned int frames; //number of frames +public: + std::map > frameGroups; //groups of frames; [groupID] -> vector of frame IDs in group + int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1]) + int fullWidth, fullHeight; //read-only, please! + CCreatureAnimation(std::string name); //c-tor + ~CCreatureAnimation(); //d-tor + + void setType(int type); //sets type of animation and cleares framecount + int getType() const; //returns type of animation + + int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool incrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next + int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, unsigned char animCount, bool IncrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next + void incrementFrame(); + int getFrame() const; + bool onLastFrameInGroup(); + + bool once; + void playOnce(int type); //plays once given stage of animation, then resets to 2 + + int framesInGroup(int group) const; //retirns number of fromes in given group +}; + +#endif // __CCREATUREANIMATION_H__ diff --git a/client/CSpellWindow.h b/client/CSpellWindow.h index 340ebd692..455b7f78d 100644 --- a/client/CSpellWindow.h +++ b/client/CSpellWindow.h @@ -1,10 +1,10 @@ -#ifndef __CSPELLWINDOW_H__ -#define __CSPELLWINDOW_H__ - - -#include "../global.h" -#include "../CPlayerInterface.h" - +#ifndef __CSPELLWINDOW_H__ +#define __CSPELLWINDOW_H__ + + +#include "../global.h" +#include "../CPlayerInterface.h" + /* * CSpellWindow.h, part of VCMI engine * @@ -13,91 +13,91 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -struct SDL_Surface; -class CDefHandler; -struct SDL_Rect; -class CGHeroInstance; - -class SpellbookInteractiveArea : public ClickableL, public ClickableR, public Hoverable -{ -private: - boost::function onLeft; - std::string textOnRclick; - boost::function onHoverOn; - boost::function onHoverOff; -public: - void clickLeft(boost::logic::tribool down); - void clickRight(boost::logic::tribool down); - void hover(bool on); - void activate(); - void deactivate(); - - SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function funcL, const std::string & textR, boost::function funcHon, boost::function funcHoff);//c-tor -}; - -class CSpellWindow : public IShowActivable, public CIntObject -{ -private: - class SpellArea : public ClickableL, public ClickableR, public Hoverable - { - public: - int mySpell; - CSpellWindow * owner; - - SpellArea(SDL_Rect pos, CSpellWindow * owner); - void clickLeft(boost::logic::tribool down); - void clickRight(boost::logic::tribool down); - void hover(bool on); - void activate(); - void deactivate(); - }; - - SDL_Surface * background, * leftCorner, * rightCorner; - CDefHandler * spells, //pictures of spells - * spellTab, //school select - * schools, //schools' pictures - * schoolBorders [4]; //schools' 'borders': [0]: air, [1]: fire, [2]: water, [3]: earth - - SpellbookInteractiveArea * exitBtn, * battleSpells, * adventureSpells, * manaPoints; - SpellbookInteractiveArea * selectSpellsA, * selectSpellsE, * selectSpellsF, * selectSpellsW, * selectSpellsAll; - SpellbookInteractiveArea * lCorner, * rCorner; - SpellArea * spellAreas[12]; - CStatusBar * statusBar; - - Uint8 sitesPerTabAdv[5]; - Uint8 sitesPerTabBattle[5]; - - bool battleSpellsOnly; //if true, only battle spells are displayed; if false, only adventure map spells are displayed - Uint8 selectedTab; // 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic, 4 - all schools - Uint8 spellSite; //changes when corners are clicked - std::set mySpells; //all spels in this spellbook - Uint8 schoolLvls[4]; //levels of magic for different schools: [0]: air, [1]: fire, [2]: water, [3]: earth; 0 - none, 1 - beginner, 2 - medium, 3 - expert - - void computeSpellsPerArea(); //recalculates spellAreas::mySpell - -public: - CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHero); //c-tor - ~CSpellWindow(); //d-tor - - void fexitb(); - void fadvSpellsb(); - void fbattleSpellsb(); - void fmanaPtsb(); - - void fspellsAb(); - void fspellsEb(); - void fspellsFb(); - void fspellsWb(); - void fspellsAllb(); - - void fLcornerb(); - void fRcornerb(); - - void activate(); - void deactivate(); - void show(SDL_Surface * to); -}; - -#endif // __CSPELLWINDOW_H__ + */ + +struct SDL_Surface; +class CDefHandler; +struct SDL_Rect; +class CGHeroInstance; + +class SpellbookInteractiveArea : public ClickableL, public ClickableR, public Hoverable +{ +private: + boost::function onLeft; + std::string textOnRclick; + boost::function onHoverOn; + boost::function onHoverOff; +public: + void clickLeft(boost::logic::tribool down); + void clickRight(boost::logic::tribool down); + void hover(bool on); + void activate(); + void deactivate(); + + SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function funcL, const std::string & textR, boost::function funcHon, boost::function funcHoff);//c-tor +}; + +class CSpellWindow : public IShowActivable, public CIntObject +{ +private: + class SpellArea : public ClickableL, public ClickableR, public Hoverable + { + public: + int mySpell; + CSpellWindow * owner; + + SpellArea(SDL_Rect pos, CSpellWindow * owner); + void clickLeft(boost::logic::tribool down); + void clickRight(boost::logic::tribool down); + void hover(bool on); + void activate(); + void deactivate(); + }; + + SDL_Surface * background, * leftCorner, * rightCorner; + CDefHandler * spells, //pictures of spells + * spellTab, //school select + * schools, //schools' pictures + * schoolBorders [4]; //schools' 'borders': [0]: air, [1]: fire, [2]: water, [3]: earth + + SpellbookInteractiveArea * exitBtn, * battleSpells, * adventureSpells, * manaPoints; + SpellbookInteractiveArea * selectSpellsA, * selectSpellsE, * selectSpellsF, * selectSpellsW, * selectSpellsAll; + SpellbookInteractiveArea * lCorner, * rCorner; + SpellArea * spellAreas[12]; + CStatusBar * statusBar; + + Uint8 sitesPerTabAdv[5]; + Uint8 sitesPerTabBattle[5]; + + bool battleSpellsOnly; //if true, only battle spells are displayed; if false, only adventure map spells are displayed + Uint8 selectedTab; // 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic, 4 - all schools + Uint8 spellSite; //changes when corners are clicked + std::set mySpells; //all spels in this spellbook + Uint8 schoolLvls[4]; //levels of magic for different schools: [0]: air, [1]: fire, [2]: water, [3]: earth; 0 - none, 1 - beginner, 2 - medium, 3 - expert + + void computeSpellsPerArea(); //recalculates spellAreas::mySpell + +public: + CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHero); //c-tor + ~CSpellWindow(); //d-tor + + void fexitb(); + void fadvSpellsb(); + void fbattleSpellsb(); + void fmanaPtsb(); + + void fspellsAb(); + void fspellsEb(); + void fspellsFb(); + void fspellsWb(); + void fspellsAllb(); + + void fLcornerb(); + void fRcornerb(); + + void activate(); + void deactivate(); + void show(SDL_Surface * to); +}; + +#endif // __CSPELLWINDOW_H__ diff --git a/client/Graphics.h b/client/Graphics.h index 641b34471..284797ff6 100644 --- a/client/Graphics.h +++ b/client/Graphics.h @@ -1,9 +1,9 @@ -#ifndef __GRAPHICS_H__ -#define __GRAPHICS_H__ - - -#include "../global.h" - +#ifndef __GRAPHICS_H__ +#define __GRAPHICS_H__ + + +#include "../global.h" + /* * Graphics.h, part of VCMI engine * @@ -12,70 +12,70 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CDefEssential; -struct SDL_Surface; -class CGHeroInstance; -class CGTownInstance; -class CDefHandler; -class CHeroClass; -struct SDL_Color; -class Graphics -{ -public: - //various graphics - SDL_Color * playerColors; //array [8] - SDL_Color * neutralColor; - SDL_Color * playerColorPalette; //palette to make interface colors good - array of size [256] - SDL_Surface * hInfo, *tInfo; //hero and town infobox bgs - SDL_Surface *heroInGarrison; //icon for town infobox - std::vector > slotsPos; //creature slot positions in infoboxes - CDefEssential *luck22, *luck30, *luck42, *luck82, - *morale22, *morale30, *morale42, *morale82, - *halls, *forts, *bigTownPic; - std::map heroWins; //hero_ID => infobox - std::map townWins; //town_ID => infobox - CDefHandler * artDefs; //artifacts - std::vector portraitSmall; //48x32 px portraits of heroes - std::vector portraitLarge; //58x64 px portraits of heroes - std::vector flags1, flags2, flags3, flags4; //flags blitted on heroes when , - CDefHandler * pskillsb, *resources; //82x93 - CDefHandler * pskillsm; //42x42 - CDefHandler * un44; //many things - CDefHandler * smallIcons, *resources32; //resources 32x32 - CDefHandler * flags; - std::vector heroAnims; // [class id: 0 - 17] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing - //creatures - std::map smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border - std::map bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border - std::map backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral - std::map backgroundsm; //castle ID -> 100x120 background creature image // -1 is for neutral - //for battles - std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type - std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle - std::map< int, std::vector < std::string > > battleACToDef; //maps AC format to vector of appropriate def names - CDefHandler * spellEffectsPics; //bitmaps representing spells affecting a stack in battle - std::vector guildBgs;// name of bitmaps with imgs for mage guild screen - //abilities - CDefHandler * abils32, * abils44, * abils82; - //spells - CDefHandler *spellscr; //spell on the scroll 83x61 - //functions - Graphics(); - void initializeBattleGraphics(); - void loadPaletteAndColors(); - void loadHeroFlags(); - void loadHeroFlags(std::pair Graphics::*, std::vector > &pr, bool mode); - void loadHeroAnim(); - void loadHeroPortraits(); - SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh); - SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS); - SDL_Surface * drawTownInfoWin(const CGTownInstance * curh); - SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //returns small picture of town: ID=-1 - blank; -2 - border; -3 - random - void blueToPlayersAdv(SDL_Surface * sur, int player); //replaces blue interface colour with a color of player -}; - -extern Graphics * graphics; - -#endif // __GRAPHICS_H__ + */ + +class CDefEssential; +struct SDL_Surface; +class CGHeroInstance; +class CGTownInstance; +class CDefHandler; +class CHeroClass; +struct SDL_Color; +class Graphics +{ +public: + //various graphics + SDL_Color * playerColors; //array [8] + SDL_Color * neutralColor; + SDL_Color * playerColorPalette; //palette to make interface colors good - array of size [256] + SDL_Surface * hInfo, *tInfo; //hero and town infobox bgs + SDL_Surface *heroInGarrison; //icon for town infobox + std::vector > slotsPos; //creature slot positions in infoboxes + CDefEssential *luck22, *luck30, *luck42, *luck82, + *morale22, *morale30, *morale42, *morale82, + *halls, *forts, *bigTownPic; + std::map heroWins; //hero_ID => infobox + std::map townWins; //town_ID => infobox + CDefHandler * artDefs; //artifacts + std::vector portraitSmall; //48x32 px portraits of heroes + std::vector portraitLarge; //58x64 px portraits of heroes + std::vector flags1, flags2, flags3, flags4; //flags blitted on heroes when , + CDefHandler * pskillsb, *resources; //82x93 + CDefHandler * pskillsm; //42x42 + CDefHandler * un44; //many things + CDefHandler * smallIcons, *resources32; //resources 32x32 + CDefHandler * flags; + std::vector heroAnims; // [class id: 0 - 17] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing + //creatures + std::map smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border + std::map bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border + std::map backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral + std::map backgroundsm; //castle ID -> 100x120 background creature image // -1 is for neutral + //for battles + std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type + std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle + std::map< int, std::vector < std::string > > battleACToDef; //maps AC format to vector of appropriate def names + CDefHandler * spellEffectsPics; //bitmaps representing spells affecting a stack in battle + std::vector guildBgs;// name of bitmaps with imgs for mage guild screen + //abilities + CDefHandler * abils32, * abils44, * abils82; + //spells + CDefHandler *spellscr; //spell on the scroll 83x61 + //functions + Graphics(); + void initializeBattleGraphics(); + void loadPaletteAndColors(); + void loadHeroFlags(); + void loadHeroFlags(std::pair Graphics::*, std::vector > &pr, bool mode); + void loadHeroAnim(); + void loadHeroPortraits(); + SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh); + SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS); + SDL_Surface * drawTownInfoWin(const CGTownInstance * curh); + SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //returns small picture of town: ID=-1 - blank; -2 - border; -3 - random + void blueToPlayersAdv(SDL_Surface * sur, int player); //replaces blue interface colour with a color of player +}; + +extern Graphics * graphics; + +#endif // __GRAPHICS_H__ diff --git a/hch/CBuildingHandler.h b/hch/CBuildingHandler.h index ea53051af..b81221981 100644 --- a/hch/CBuildingHandler.h +++ b/hch/CBuildingHandler.h @@ -1,9 +1,9 @@ -#ifndef __CBUILDINGHANDLER_H__ -#define __CBUILDINGHANDLER_H__ -#include "../global.h" -#include -#include - +#ifndef __CBUILDINGHANDLER_H__ +#define __CBUILDINGHANDLER_H__ +#include "../global.h" +#include +#include + /* * CBuildingHandler.h, part of VCMI engine * @@ -12,40 +12,40 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -//enum EbuildingType {NEUTRAL=-1, CASTLE, RAMPART, TOWER, INFERNO, NECROPOLIS, DUNGEON, STRONGHOLD, FORTRESS, CONFLUX}; -class DLL_EXPORT CBuilding //a typical building encountered in every castle ;] -{ -public: - int tid, bid; //town ID and structure ID - std::vector resources; - std::string name; - std::string description; - - const std::string &Name(); - const std::string &Description(); - - template void serialize(Handler &h, const int version) - { - h & tid & bid & resources & name & description; - } -}; - -class DLL_EXPORT CBuildingHandler -{ -public: - std::map > buildings; ///< first int is the castle ID, second the building ID (in ERM-U format) - std::map > > > > hall; //map >[5]> - external vector is the vector of buildings in the row, internal is the list of buildings for the specific slot - - void loadBuildings(); //main loader - ~CBuildingHandler(); - - template void serialize(Handler &h, const int version) - { - h & buildings & hall; - } -}; - - -#endif // __CBUILDINGHANDLER_H__ + */ + +//enum EbuildingType {NEUTRAL=-1, CASTLE, RAMPART, TOWER, INFERNO, NECROPOLIS, DUNGEON, STRONGHOLD, FORTRESS, CONFLUX}; +class DLL_EXPORT CBuilding //a typical building encountered in every castle ;] +{ +public: + int tid, bid; //town ID and structure ID + std::vector resources; + std::string name; + std::string description; + + const std::string &Name(); + const std::string &Description(); + + template void serialize(Handler &h, const int version) + { + h & tid & bid & resources & name & description; + } +}; + +class DLL_EXPORT CBuildingHandler +{ +public: + std::map > buildings; ///< first int is the castle ID, second the building ID (in ERM-U format) + std::map > > > > hall; //map >[5]> - external vector is the vector of buildings in the row, internal is the list of buildings for the specific slot + + void loadBuildings(); //main loader + ~CBuildingHandler(); + + template void serialize(Handler &h, const int version) + { + h & buildings & hall; + } +}; + + +#endif // __CBUILDINGHANDLER_H__ diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index e31a1db30..039dd3a99 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -1,11 +1,11 @@ -#ifndef __CCREATUREHANDLER_H__ -#define __CCREATUREHANDLER_H__ -#include "../global.h" -#include -#include -#include -#include - +#ifndef __CCREATUREHANDLER_H__ +#define __CCREATUREHANDLER_H__ +#include "../global.h" +#include +#include +#include +#include + /* * CCreatureHandler.h, part of VCMI engine * @@ -14,84 +14,84 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CLodHandler; - -class DLL_EXPORT CCreature -{ -public: - std::string namePl, nameSing, nameRef; //name in singular and plural form; and reference name - std::vector cost; //cost[res_id] - amount of that resource - std::set upgrades; // IDs of creatures to which this creature can be upgraded - ui32 fightValue, AIValue, growth, hordeGrowth, hitPoints, speed, attack, defence, shots, spells; - ui32 damageMin, damageMax; - ui32 ammMin, ammMax; - ui8 level; // 0 - unknown - std::string abilityText; //description of abilities - std::string abilityRefs; //references to abilities, in textformat - std::string animDefName; - ui32 idNumber; - std::set abilities; - si8 faction; //-1 = neutral - - ///animation info - float timeBetweenFidgets, walkAnimationTime, attackAnimationTime, flightAnimationDistance; - int upperRightMissleOffsetX, rightMissleOffsetX, lowerRightMissleOffsetX, upperRightMissleOffsetY, rightMissleOffsetY, lowerRightMissleOffsetY; - float missleFrameAngles[12]; - int troopCountLocationOffset, attackClimaxFrame; - ///end of anim info - - bool isDoubleWide() const; //returns true if unit is double wide on battlefield - bool isFlying() const; //returns true if it is a flying unit - bool isShooting() const; //returns true if unit can shoot - si32 maxAmount(const std::vector &res) const; //how many creatures can be bought - static int getQuantityID(const int & quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion - - template void serialize(Handler &h, const int version) - { - h & namePl & nameSing & nameRef - & cost & upgrades - & fightValue & AIValue & growth & hordeGrowth & hitPoints & speed & attack & defence & shots & spells - & damageMin & damageMax & ammMin & ammMax & level - & abilityText & abilityRefs & animDefName - & idNumber & abilities & faction - - & timeBetweenFidgets & walkAnimationTime & attackAnimationTime & flightAnimationDistance - & upperRightMissleOffsetX & rightMissleOffsetX & lowerRightMissleOffsetX & upperRightMissleOffsetY & rightMissleOffsetY & lowerRightMissleOffsetY - & missleFrameAngles & troopCountLocationOffset & attackClimaxFrame; - } -}; - - -class DLL_EXPORT CCreatureHandler -{ -public: - std::set notUsedMonsters; - std::vector creatures; //creature ID -> creature info - std::map > levelCreatures; //level -> list of creatures - std::map nameToID; - std::map idToProjectile; - std::map idToProjectileSpin; //if true, appropriate projectile is spinning during flight - void loadCreatures(); - void loadAnimationInfo(); - void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i); - CCreatureHandler(); - ~CCreatureHandler(); - - template void serialize(Handler &h, const int version) - { - //TODO: should be optimized, not all these informations needs to be serialized (same for ccreature) - h & notUsedMonsters & creatures & nameToID & idToProjectile & idToProjectileSpin; - - if(!h.saving) - { - for (int i=0; i cost; //cost[res_id] - amount of that resource + std::set upgrades; // IDs of creatures to which this creature can be upgraded + ui32 fightValue, AIValue, growth, hordeGrowth, hitPoints, speed, attack, defence, shots, spells; + ui32 damageMin, damageMax; + ui32 ammMin, ammMax; + ui8 level; // 0 - unknown + std::string abilityText; //description of abilities + std::string abilityRefs; //references to abilities, in textformat + std::string animDefName; + ui32 idNumber; + std::set abilities; + si8 faction; //-1 = neutral + + ///animation info + float timeBetweenFidgets, walkAnimationTime, attackAnimationTime, flightAnimationDistance; + int upperRightMissleOffsetX, rightMissleOffsetX, lowerRightMissleOffsetX, upperRightMissleOffsetY, rightMissleOffsetY, lowerRightMissleOffsetY; + float missleFrameAngles[12]; + int troopCountLocationOffset, attackClimaxFrame; + ///end of anim info + + bool isDoubleWide() const; //returns true if unit is double wide on battlefield + bool isFlying() const; //returns true if it is a flying unit + bool isShooting() const; //returns true if unit can shoot + si32 maxAmount(const std::vector &res) const; //how many creatures can be bought + static int getQuantityID(const int & quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion + + template void serialize(Handler &h, const int version) + { + h & namePl & nameSing & nameRef + & cost & upgrades + & fightValue & AIValue & growth & hordeGrowth & hitPoints & speed & attack & defence & shots & spells + & damageMin & damageMax & ammMin & ammMax & level + & abilityText & abilityRefs & animDefName + & idNumber & abilities & faction + + & timeBetweenFidgets & walkAnimationTime & attackAnimationTime & flightAnimationDistance + & upperRightMissleOffsetX & rightMissleOffsetX & lowerRightMissleOffsetX & upperRightMissleOffsetY & rightMissleOffsetY & lowerRightMissleOffsetY + & missleFrameAngles & troopCountLocationOffset & attackClimaxFrame; + } +}; + + +class DLL_EXPORT CCreatureHandler +{ +public: + std::set notUsedMonsters; + std::vector creatures; //creature ID -> creature info + std::map > levelCreatures; //level -> list of creatures + std::map nameToID; + std::map idToProjectile; + std::map idToProjectileSpin; //if true, appropriate projectile is spinning during flight + void loadCreatures(); + void loadAnimationInfo(); + void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i); + CCreatureHandler(); + ~CCreatureHandler(); + + template void serialize(Handler &h, const int version) + { + //TODO: should be optimized, not all these informations needs to be serialized (same for ccreature) + h & notUsedMonsters & creatures & nameToID & idToProjectile & idToProjectileSpin; + + if(!h.saving) + { + for (int i=0; i SEntries ; - -public: - int width, height; //width and height - static CLodHandler * Spriteh; - std::string defName, curDir; - std::vector ourImages; - bool alphaTransformed; - bool notFreeImgs; - - CDefHandler(); - ~CDefHandler(); - static void print (std::ostream & stream, int nr, int bytcon); - int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false); - static unsigned char *writeNormalNr (int nr, int bytCon); - SDL_Surface * getSprite (int SIndex, unsigned char * FDef, BMPPalette * palette); //zapisuje klatke o zadanym numerze do "testtt.bmp" - void openDef(std::string name); - void expand(unsigned char N,unsigned char & BL, unsigned char & BR); - void openFromMemory(unsigned char * table, std::string name); - CDefEssential * essentialize(); - - static CDefHandler * giveDef(std::string defName, CLodHandler * spriteh=NULL); - static CDefEssential * giveDefEss(std::string defName, CLodHandler * spriteh=NULL); -}; - -class CDefEssential //DefHandler with images only -{ -public: - std::vector ourImages; - ~CDefEssential(); -}; - - -#endif // __CDEFHANDLER_H__ + */ + +struct Cimage +{ + int groupNumber; + std::string imName; //name without extension + SDL_Surface * bitmap; +}; + +class CDefHandler +{ +private: + int totalEntries, DEFType, totalBlocks; + bool allowRepaint; + int length; + unsigned int * RWEntries; + struct SEntry + { + std::string name; + int offset; + int group; + } ; + std::vector SEntries ; + +public: + int width, height; //width and height + static CLodHandler * Spriteh; + std::string defName, curDir; + std::vector ourImages; + bool alphaTransformed; + bool notFreeImgs; + + CDefHandler(); + ~CDefHandler(); + static void print (std::ostream & stream, int nr, int bytcon); + int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false); + static unsigned char *writeNormalNr (int nr, int bytCon); + SDL_Surface * getSprite (int SIndex, unsigned char * FDef, BMPPalette * palette); //zapisuje klatke o zadanym numerze do "testtt.bmp" + void openDef(std::string name); + void expand(unsigned char N,unsigned char & BL, unsigned char & BR); + void openFromMemory(unsigned char * table, std::string name); + CDefEssential * essentialize(); + + static CDefHandler * giveDef(std::string defName, CLodHandler * spriteh=NULL); + static CDefEssential * giveDefEss(std::string defName, CLodHandler * spriteh=NULL); +}; + +class CDefEssential //DefHandler with images only +{ +public: + std::vector ourImages; + ~CDefEssential(); +}; + + +#endif // __CDEFHANDLER_H__ diff --git a/hch/CDefObjInfoHandler.h b/hch/CDefObjInfoHandler.h index aec35b273..1de927ef8 100644 --- a/hch/CDefObjInfoHandler.h +++ b/hch/CDefObjInfoHandler.h @@ -1,9 +1,9 @@ -#ifndef __CDEFOBJINFOHANDLER_H__ -#define __CDEFOBJINFOHANDLER_H__ -#include -#include -#include "../global.h" - +#ifndef __CDEFOBJINFOHANDLER_H__ +#define __CDEFOBJINFOHANDLER_H__ +#include +#include +#include "../global.h" + /* * CDefObjInfoHandler.h, part of VCMI engine * @@ -12,60 +12,60 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CDefHandler; -class CLodHandler; -class DLL_EXPORT CGDefInfo -{ -public: - std::string name; - - ui8 visitMap[6]; - ui8 blockMap[6]; - ui8 visitDir; //directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7) - si32 id, subid; //of object described by this defInfo - si32 serial; - si32 terrainAllowed, //on which terrain it is possible to place object - terrainMenu; //in which menus in map editor object will be showed - si32 width, height; //tiles - si32 type; //(0- ground, 1- towns, 2-creatures, 3- heroes, 4-artifacts, 5- resources) - CDefHandler * handler; - si32 printPriority; - bool isVisitable(); - bool operator<(const CGDefInfo& por) - { - if(id!=por.id) - return id void serialize(Handler &h, const int version) - { - h & name & serial & visitMap & blockMap & visitDir & id & subid &terrainAllowed - & terrainMenu & width & height & type & printPriority; - } - CGDefInfo(); -}; -class DLL_EXPORT CDefObjInfoHandler -{ -public: - std::map > gobjs; - std::map castles; - - void load(); - ~CDefObjInfoHandler(); - - template void serialize(Handler &h, const int version) - { - h & gobjs; - - if(!h.saving) //recrete castles map - for(std::map >::iterator i=gobjs.begin(); i!=gobjs.end(); i++) - for(std::map::iterator j=i->second.begin(); j!=i->second.end(); j++) - if(j->second->id == TOWNI_TYPE) - castles[j->second->subid]=j->second; - } -}; - -#endif // __CDEFOBJINFOHANDLER_H__ + */ + +class CDefHandler; +class CLodHandler; +class DLL_EXPORT CGDefInfo +{ +public: + std::string name; + + ui8 visitMap[6]; + ui8 blockMap[6]; + ui8 visitDir; //directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7) + si32 id, subid; //of object described by this defInfo + si32 serial; + si32 terrainAllowed, //on which terrain it is possible to place object + terrainMenu; //in which menus in map editor object will be showed + si32 width, height; //tiles + si32 type; //(0- ground, 1- towns, 2-creatures, 3- heroes, 4-artifacts, 5- resources) + CDefHandler * handler; + si32 printPriority; + bool isVisitable(); + bool operator<(const CGDefInfo& por) + { + if(id!=por.id) + return id void serialize(Handler &h, const int version) + { + h & name & serial & visitMap & blockMap & visitDir & id & subid &terrainAllowed + & terrainMenu & width & height & type & printPriority; + } + CGDefInfo(); +}; +class DLL_EXPORT CDefObjInfoHandler +{ +public: + std::map > gobjs; + std::map castles; + + void load(); + ~CDefObjInfoHandler(); + + template void serialize(Handler &h, const int version) + { + h & gobjs; + + if(!h.saving) //recrete castles map + for(std::map >::iterator i=gobjs.begin(); i!=gobjs.end(); i++) + for(std::map::iterator j=i->second.begin(); j!=i->second.end(); j++) + if(j->second->id == TOWNI_TYPE) + castles[j->second->subid]=j->second; + } +}; + +#endif // __CDEFOBJINFOHANDLER_H__ diff --git a/hch/CLodHandler.h b/hch/CLodHandler.h index 76386c8ef..b75f54c17 100644 --- a/hch/CLodHandler.h +++ b/hch/CLodHandler.h @@ -1,11 +1,11 @@ -#ifndef __CLODHANDLER_H__ -#define __CLODHANDLER_H__ -#include "../global.h" -#include -#include -#include -#include "../nodrze.h" - +#ifndef __CLODHANDLER_H__ +#define __CLODHANDLER_H__ +#include "../global.h" +#include +#include +#include +#include "../nodrze.h" + /* * CLodhandler.h, part of VCMI engine * @@ -14,59 +14,59 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -struct SDL_Surface; -class CDefHandler; -class CDefEssential; -namespace boost -{class mutex;}; -namespace NLoadHandlerHelp -{ - const int dmHelp=0, dmNoExtractingMask=1; - //std::string P1,P2,CurDir; - const int fCHUNK = 50000; -}; - -struct Entry -{ - unsigned char name[12], //filename - hlam_1[4], //??? - hlam_2[4]; //probably type of file - std::string nameStr; - int offset, //from beginning - realSize, //size without compression - size; //and with - bool operator<(const std::string & comp) const - { - return nameStr entries; - unsigned int totalFiles; - boost::mutex *mutex; - std::string myDir; //load files from this dir instead of .lod file - - int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper - int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler - int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler - unsigned char * giveFile(std::string defName, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed! - std::string getTextFile(std::string name); //extracts one file - void extract(std::string FName); - void extractFile(std::string FName, std::string name); //extracts a specific file - void init(std::string lodFile, std::string dirName); -}; - - -#endif // __CLODHANDLER_H__ + */ + +struct SDL_Surface; +class CDefHandler; +class CDefEssential; +namespace boost +{class mutex;}; +namespace NLoadHandlerHelp +{ + const int dmHelp=0, dmNoExtractingMask=1; + //std::string P1,P2,CurDir; + const int fCHUNK = 50000; +}; + +struct Entry +{ + unsigned char name[12], //filename + hlam_1[4], //??? + hlam_2[4]; //probably type of file + std::string nameStr; + int offset, //from beginning + realSize, //size without compression + size; //and with + bool operator<(const std::string & comp) const + { + return nameStr entries; + unsigned int totalFiles; + boost::mutex *mutex; + std::string myDir; //load files from this dir instead of .lod file + + int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper + int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler + int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler + unsigned char * giveFile(std::string defName, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed! + std::string getTextFile(std::string name); //extracts one file + void extract(std::string FName); + void extractFile(std::string FName, std::string name); //extracts a specific file + void init(std::string lodFile, std::string dirName); +}; + + +#endif // __CLODHANDLER_H__ diff --git a/hch/CMusicHandler.h b/hch/CMusicHandler.h index 91adeee02..2588d0e17 100644 --- a/hch/CMusicHandler.h +++ b/hch/CMusicHandler.h @@ -1,9 +1,9 @@ -#ifndef __CMUSICHANDLER_H__ -#define __CMUSICHANDLER_H__ - -#include -#include "CSndHandler.h" - +#ifndef __CMUSICHANDLER_H__ +#define __CMUSICHANDLER_H__ + +#include +#include "CSndHandler.h" + /* * CMusicHandler.h, part of VCMI engine * @@ -12,20 +12,20 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CMusicHandler -{ -protected: - CSndHandler *sndh; -public: - Mix_Music *AITheme0, *AITheme1, *AITheme2, *combat1, *combat2, *combat3, *combat4, *castleTown, *defendCastle, *dirt, *dungeon, *elemTown, *evilTheme, *fortressTown, *goodTheme, *grass, *infernoTown, *lava, *loopLepr, *loseCampain, *loseCastle, *loseCombat, *mainMenu, *mainMenuWoG, *necroTown, *neutralTheme, *rampart, *retreatBattle, *rough, *sand, *secretTheme, *snow, *stronghold, *surrenderBattle, *swamp, *towerTown, *ultimateLose, *underground, *water, *winScenario, *winBattle; - Mix_Chunk * buildTown, *click; - void initMusics(); - void playClick(); //plays click music ;] - void playLodSnd(std::string sndname); // plays sound wavs from Heroes3.snd -}; - - - -#endif // __CMUSICHANDLER_H__ + */ + +class CMusicHandler +{ +protected: + CSndHandler *sndh; +public: + Mix_Music *AITheme0, *AITheme1, *AITheme2, *combat1, *combat2, *combat3, *combat4, *castleTown, *defendCastle, *dirt, *dungeon, *elemTown, *evilTheme, *fortressTown, *goodTheme, *grass, *infernoTown, *lava, *loopLepr, *loseCampain, *loseCastle, *loseCombat, *mainMenu, *mainMenuWoG, *necroTown, *neutralTheme, *rampart, *retreatBattle, *rough, *sand, *secretTheme, *snow, *stronghold, *surrenderBattle, *swamp, *towerTown, *ultimateLose, *underground, *water, *winScenario, *winBattle; + Mix_Chunk * buildTown, *click; + void initMusics(); + void playClick(); //plays click music ;] + void playLodSnd(std::string sndname); // plays sound wavs from Heroes3.snd +}; + + + +#endif // __CMUSICHANDLER_H__ diff --git a/hch/CSndHandler.h b/hch/CSndHandler.h index 54efc7036..792e0619e 100644 --- a/hch/CSndHandler.h +++ b/hch/CSndHandler.h @@ -1,10 +1,10 @@ -#ifndef __CSNDHANDLER_H__ -#define __CSNDHANDLER_H__ - -#include -#include -#include - +#ifndef __CSNDHANDLER_H__ +#define __CSNDHANDLER_H__ + +#include +#include +#include + /* * CSndHandler.h, part of VCMI engine * @@ -13,59 +13,59 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -struct MemberFile -{ - std::ifstream * ifs; - int length; -}; -class CSndHandler -{ -protected: - const int CHUNK; - struct Entry - { - std::string name; - int size, offset; - }; - std::ifstream file; - int readNormalNr (int pos, int bytCon); - bool opened; -public: - std::vector entries; - std::map fimap; // map of wav file and index - ~CSndHandler(); - CSndHandler(std::string fname); - void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file - unsigned char * extract (std::string srcfile, int & size); //return selecte file data, NULL if file doesn't exist - void extract(int index, std::string dstfile); //saves selected file - MemberFile getFile(std::string name);//nie testowane - sprawdzic - unsigned char * extract (int index, int & size); //return selecte file - NIE TESTOWANE -}; -class CVidHandler -{ -protected: - const int CHUNK; - struct Entry - { - std::string name; - int size, offset, something; - }; - std::ifstream file; - int readNormalNr (int pos, int bytCon); - bool opened; -public: - std::vector entries; - ~CVidHandler(); - CVidHandler(std::string fname); - std::ifstream & extract(std::string srcfile); - void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file - unsigned char * extract (std::string srcfile, int & size); //return selecte file, - void extract(int index, std::string dstfile); //saves selected file - MemberFile getFile(std::string name); //nie testowane - sprawdzic -}; - - - -#endif // __CSNDHANDLER_H__ + */ + +struct MemberFile +{ + std::ifstream * ifs; + int length; +}; +class CSndHandler +{ +protected: + const int CHUNK; + struct Entry + { + std::string name; + int size, offset; + }; + std::ifstream file; + int readNormalNr (int pos, int bytCon); + bool opened; +public: + std::vector entries; + std::map fimap; // map of wav file and index + ~CSndHandler(); + CSndHandler(std::string fname); + void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file + unsigned char * extract (std::string srcfile, int & size); //return selecte file data, NULL if file doesn't exist + void extract(int index, std::string dstfile); //saves selected file + MemberFile getFile(std::string name);//nie testowane - sprawdzic + unsigned char * extract (int index, int & size); //return selecte file - NIE TESTOWANE +}; +class CVidHandler +{ +protected: + const int CHUNK; + struct Entry + { + std::string name; + int size, offset, something; + }; + std::ifstream file; + int readNormalNr (int pos, int bytCon); + bool opened; +public: + std::vector entries; + ~CVidHandler(); + CVidHandler(std::string fname); + std::ifstream & extract(std::string srcfile); + void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file + unsigned char * extract (std::string srcfile, int & size); //return selecte file, + void extract(int index, std::string dstfile); //saves selected file + MemberFile getFile(std::string name); //nie testowane - sprawdzic +}; + + + +#endif // __CSNDHANDLER_H__ diff --git a/hch/CSpellHandler.h b/hch/CSpellHandler.h index 6d65795f4..e76de1153 100644 --- a/hch/CSpellHandler.h +++ b/hch/CSpellHandler.h @@ -1,10 +1,10 @@ -#ifndef __CSPELLHANDLER_H__ -#define __CSPELLHANDLER_H__ - -#include -#include -#include - +#ifndef __CSPELLHANDLER_H__ +#define __CSPELLHANDLER_H__ + +#include +#include +#include + /* * CSpellHandler.h, part of VCMI engine * @@ -13,51 +13,51 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class DLL_EXPORT CSpell -{ -public: - ui32 id; - std::string name; - std::string abbName; //abbreviated name - std::vector descriptions; //descriptions of spell for skill levels: 0 - none, 1 - basic, etc - si32 level; - bool earth; - bool water; - bool fire; - bool air; - si32 power; //spell's power - std::vector costs; //per skill level: 0 - none, 1 - basic, etc - std::vector powers; //[er skill level: 0 - none, 1 - basic, etc - std::vector probabilities; //% chance to gain for castles - std::vector AIVals; //AI values: per skill level: 0 - none, 1 - basic, etc - std::string attributes; //reference only attributes - bool combatSpell; //is this spell combat (true) or adventure (false) - bool creatureAbility; //if true, only creatures can use this spell - si8 positiveness; //1 if spell is positive for influenced stacks, 0 if it is indifferent, -1 if it's negative - std::vector range; //description of spell's range in SRSL by magic school level - std::set rangeInHexes(unsigned int centralHex, ui8 schoolLvl ) const; //convert range to specific hexes - - - template void serialize(Handler &h, const int version) - { - h & id & name & abbName & descriptions & level & earth & water & fire & air & power & costs - & powers & probabilities & AIVals & attributes & combatSpell & creatureAbility & positiveness & range; - } -}; - -class DLL_EXPORT CSpellHandler -{ -public: - std::vector spells; - void loadSpells(); - - template void serialize(Handler &h, const int version) - { - h & spells; - } -}; - - -#endif // __CSPELLHANDLER_H__ + */ + +class DLL_EXPORT CSpell +{ +public: + ui32 id; + std::string name; + std::string abbName; //abbreviated name + std::vector descriptions; //descriptions of spell for skill levels: 0 - none, 1 - basic, etc + si32 level; + bool earth; + bool water; + bool fire; + bool air; + si32 power; //spell's power + std::vector costs; //per skill level: 0 - none, 1 - basic, etc + std::vector powers; //[er skill level: 0 - none, 1 - basic, etc + std::vector probabilities; //% chance to gain for castles + std::vector AIVals; //AI values: per skill level: 0 - none, 1 - basic, etc + std::string attributes; //reference only attributes + bool combatSpell; //is this spell combat (true) or adventure (false) + bool creatureAbility; //if true, only creatures can use this spell + si8 positiveness; //1 if spell is positive for influenced stacks, 0 if it is indifferent, -1 if it's negative + std::vector range; //description of spell's range in SRSL by magic school level + std::set rangeInHexes(unsigned int centralHex, ui8 schoolLvl ) const; //convert range to specific hexes + + + template void serialize(Handler &h, const int version) + { + h & id & name & abbName & descriptions & level & earth & water & fire & air & power & costs + & powers & probabilities & AIVals & attributes & combatSpell & creatureAbility & positiveness & range; + } +}; + +class DLL_EXPORT CSpellHandler +{ +public: + std::vector spells; + void loadSpells(); + + template void serialize(Handler &h, const int version) + { + h & spells; + } +}; + + +#endif // __CSPELLHANDLER_H__ diff --git a/hch/CTownHandler.h b/hch/CTownHandler.h index a83bc2e24..9e00a35f2 100644 --- a/hch/CTownHandler.h +++ b/hch/CTownHandler.h @@ -1,8 +1,8 @@ -#ifndef __CTOWNHANDLER_H__ -#define __CTOWNHANDLER_H__ -#include "../global.h" -#include - +#ifndef __CTOWNHANDLER_H__ +#define __CTOWNHANDLER_H__ +#include "../global.h" +#include + /* * CTownHandler.h, part of VCMI engine * @@ -11,74 +11,74 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CBuilding; -class CSpell; -class CHero; -class CGTownInstance; -class DLL_EXPORT CTown -{ - std::string name; //name of type -public: - - std::vector names; //names of the town instances - std::vector basicCreatures; //level (from 0) -> ID - std::vector upgradedCreatures; //level (from 0) -> ID - std::map hordeLvl; //[0] - first horde building creature level; [1] - second horde building (-1 if not present) - ui32 mageLevel; //max available mage guild level - int bonus; //pic number - ui16 primaryRes, warMachine; - ui8 typeID; - - - const std::vector & Names() const; - const std::string & Name() const; - void Name(const std::string & val) { name = val; } - - - template void serialize(Handler &h, const int version) - { - h & names & basicCreatures & upgradedCreatures & hordeLvl & mageLevel & bonus - & primaryRes & warMachine & typeID; - } -}; - -struct DLL_EXPORT Structure -{ - int ID; - int3 pos; - std::string defName, borderName, areaName, name; - int townID, group; - - bool operator<(const Structure & p2) const - { - if(pos.z != p2.pos.z) - return (pos.z) < (p2.pos.z); - else - return (ID) < (p2.ID); - } -}; - -class DLL_EXPORT CTownHandler -{ -public: - std::vector towns; - std::map > structures; // > - std::map > > requirements; //requirements[town_id][structure_id] -> set of required buildings - - CTownHandler(); - ~CTownHandler(); - void loadNames(); - void loadStructures(); - - template void serialize(Handler &h, const int version) - { - h & towns & requirements; - if(!h.saving) - loadStructures(); - } -}; - - -#endif // __CTOWNHANDLER_H__ + */ + +class CBuilding; +class CSpell; +class CHero; +class CGTownInstance; +class DLL_EXPORT CTown +{ + std::string name; //name of type +public: + + std::vector names; //names of the town instances + std::vector basicCreatures; //level (from 0) -> ID + std::vector upgradedCreatures; //level (from 0) -> ID + std::map hordeLvl; //[0] - first horde building creature level; [1] - second horde building (-1 if not present) + ui32 mageLevel; //max available mage guild level + int bonus; //pic number + ui16 primaryRes, warMachine; + ui8 typeID; + + + const std::vector & Names() const; + const std::string & Name() const; + void Name(const std::string & val) { name = val; } + + + template void serialize(Handler &h, const int version) + { + h & names & basicCreatures & upgradedCreatures & hordeLvl & mageLevel & bonus + & primaryRes & warMachine & typeID; + } +}; + +struct DLL_EXPORT Structure +{ + int ID; + int3 pos; + std::string defName, borderName, areaName, name; + int townID, group; + + bool operator<(const Structure & p2) const + { + if(pos.z != p2.pos.z) + return (pos.z) < (p2.pos.z); + else + return (ID) < (p2.ID); + } +}; + +class DLL_EXPORT CTownHandler +{ +public: + std::vector towns; + std::map > structures; // > + std::map > > requirements; //requirements[town_id][structure_id] -> set of required buildings + + CTownHandler(); + ~CTownHandler(); + void loadNames(); + void loadStructures(); + + template void serialize(Handler &h, const int version) + { + h & towns & requirements; + if(!h.saving) + loadStructures(); + } +}; + + +#endif // __CTOWNHANDLER_H__ diff --git a/int3.h b/int3.h index 504621f3d..61c866897 100644 --- a/int3.h +++ b/int3.h @@ -1,9 +1,9 @@ -#ifndef __INT3_H__ -#define __INT3_H__ -#include -#include -#include - +#ifndef __INT3_H__ +#define __INT3_H__ +#include +#include +#include + /* * int3.h, part of VCMI engine * @@ -12,132 +12,132 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CCreature; -class CCreatureSet //seven combined creatures -{ -public: - std::map > slots; //slots[slot_id]=> pair(creature_id,creature_quantity) - bool formation; //false - wide, true - tight - si32 getSlotFor(ui32 creature, ui32 slotsAmount=7) const //returns -1 if no slot available - { - for(std::map >::const_iterator i=slots.begin(); i!=slots.end(); ++i) - { - if(i->second.first == creature) - { - return i->first; //if there is already such creature we return its slot id - } - } - for(ui32 i=0; i void serialize(Handler &h, const int version) - { - h & slots & formation; - } - operator bool() const - { - return slots.size()>0; - } - void sweep() - { - for(std::map >::iterator i=slots.begin(); i!=slots.end(); ++i) - { - if(!i->second.second) - { - slots.erase(i); - sweep(); - break; - } - } - } -}; - -class int3 -{ -public: - si32 x,y,z; - inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0 - inline int3(const si32 & X, const si32 & Y, const si32 & Z):x(X),y(Y),z(Z){}; //c-tor - inline int3(const int3 & val) : x(val.x), y(val.y), z(val.z){} //copy c-tor - inline int3 operator=(const int3 & val) {x = val.x; y = val.y; z = val.z; return *this;} //assignemt operator - ~int3() {} // d-tor - does nothing - inline int3 operator+(const int3 & i) const //returns int3 with coordinates increased by corresponding coordinate of given int3 - {return int3(x+i.x,y+i.y,z+i.z);} - inline int3 operator+(const si32 i) const //returns int3 with coordinates increased by given numer - {return int3(x+i,y+i,z+i);} - inline int3 operator-(const int3 & i) const //returns int3 with coordinates decreased by corresponding coordinate of given int3 - {return int3(x-i.x,y-i.y,z-i.z);} - inline int3 operator-(const si32 i) const //returns int3 with coordinates decreased by given numer - {return int3(x-i,y-i,z-i);} - inline int3 operator-() const //returns opposite position - {return int3(-x,-y,-z);} - inline double dist2d(const int3 other) const //distance (z coord is not used) - {return std::sqrt((double)(x-other.x)*(x-other.x) + (y-other.y)*(y-other.y));} - inline void operator+=(const int3 & i) - { - x+=i.x; - y+=i.y; - z+=i.z; - } - inline void operator+=(const si32 & i) - { - x+=i; - y+=i; - z+=i; - } - inline void operator-=(const int3 & i) - { - x-=i.x; - y-=i.y; - z-=i.z; - } - inline void operator-=(const si32 & i) - { - x+=i; - y+=i; - z+=i; - } - inline bool operator==(const int3 & i) const - {return (x==i.x) && (y==i.y) && (z==i.z);} - inline bool operator!=(const int3 & i) const - {return !(*this==i);} - inline bool operator<(const int3 & i) const - { - if (zi.z) - return false; - if (yi.y) - return false; - if (xi.x) - return false; - return false; - } - template void serialize(Handler &h, const int version) - { - h & x & y & z; - } -}; -inline std::istream & operator>>(std::istream & str, int3 & dest) -{ - str>>dest.x>>dest.y>>dest.z; - return str; -} -inline std::ostream & operator<<(std::ostream & str, const int3 & sth) -{ - return str< > slots; //slots[slot_id]=> pair(creature_id,creature_quantity) + bool formation; //false - wide, true - tight + si32 getSlotFor(ui32 creature, ui32 slotsAmount=7) const //returns -1 if no slot available + { + for(std::map >::const_iterator i=slots.begin(); i!=slots.end(); ++i) + { + if(i->second.first == creature) + { + return i->first; //if there is already such creature we return its slot id + } + } + for(ui32 i=0; i void serialize(Handler &h, const int version) + { + h & slots & formation; + } + operator bool() const + { + return slots.size()>0; + } + void sweep() + { + for(std::map >::iterator i=slots.begin(); i!=slots.end(); ++i) + { + if(!i->second.second) + { + slots.erase(i); + sweep(); + break; + } + } + } +}; + +class int3 +{ +public: + si32 x,y,z; + inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0 + inline int3(const si32 & X, const si32 & Y, const si32 & Z):x(X),y(Y),z(Z){}; //c-tor + inline int3(const int3 & val) : x(val.x), y(val.y), z(val.z){} //copy c-tor + inline int3 operator=(const int3 & val) {x = val.x; y = val.y; z = val.z; return *this;} //assignemt operator + ~int3() {} // d-tor - does nothing + inline int3 operator+(const int3 & i) const //returns int3 with coordinates increased by corresponding coordinate of given int3 + {return int3(x+i.x,y+i.y,z+i.z);} + inline int3 operator+(const si32 i) const //returns int3 with coordinates increased by given numer + {return int3(x+i,y+i,z+i);} + inline int3 operator-(const int3 & i) const //returns int3 with coordinates decreased by corresponding coordinate of given int3 + {return int3(x-i.x,y-i.y,z-i.z);} + inline int3 operator-(const si32 i) const //returns int3 with coordinates decreased by given numer + {return int3(x-i,y-i,z-i);} + inline int3 operator-() const //returns opposite position + {return int3(-x,-y,-z);} + inline double dist2d(const int3 other) const //distance (z coord is not used) + {return std::sqrt((double)(x-other.x)*(x-other.x) + (y-other.y)*(y-other.y));} + inline void operator+=(const int3 & i) + { + x+=i.x; + y+=i.y; + z+=i.z; + } + inline void operator+=(const si32 & i) + { + x+=i; + y+=i; + z+=i; + } + inline void operator-=(const int3 & i) + { + x-=i.x; + y-=i.y; + z-=i.z; + } + inline void operator-=(const si32 & i) + { + x+=i; + y+=i; + z+=i; + } + inline bool operator==(const int3 & i) const + {return (x==i.x) && (y==i.y) && (z==i.z);} + inline bool operator!=(const int3 & i) const + {return !(*this==i);} + inline bool operator<(const int3 & i) const + { + if (zi.z) + return false; + if (yi.y) + return false; + if (xi.x) + return false; + return false; + } + template void serialize(Handler &h, const int version) + { + h & x & y & z; + } +}; +inline std::istream & operator>>(std::istream & str, int3 & dest) +{ + str>>dest.x>>dest.y>>dest.z; + return str; +} +inline std::ostream & operator<<(std::ostream & str, const int3 & sth) +{ + return str< void serialize(Handler &h, const int version) - { - h & side & stackNumber & actionType & destinationTile & additionalInfo; - } -}; -#endif // __BATTLEACTION_H__ + */ + +struct BattleAction +{ + ui8 side; //who made this action: false - left, true - right player + ui32 stackNumber;//stack ID, -1 left hero, -2 right hero, + ui8 actionType; // 0 = No action; 1 = Hero cast a spell 2 = Walk 3 = Defend 4 = Retreat from the battle 5 = Surrender 6 = Walk and Attack 7 = Shoot 8 = Wait 9 = Catapult 10 = Monster casts a spell (i.e. Faerie Dragons) 11 - Bad morale freeze + ui16 destinationTile; + si32 additionalInfo; // e.g. spell number if type is 1 || 10; tile to attack if type is 6 + template void serialize(Handler &h, const int version) + { + h & side & stackNumber & actionType & destinationTile & additionalInfo; + } +}; +#endif // __BATTLEACTION_H__ diff --git a/lib/CondSh.h b/lib/CondSh.h index f4d0de4ad..3913c5648 100644 --- a/lib/CondSh.h +++ b/lib/CondSh.h @@ -1,7 +1,7 @@ -#ifndef __CONDSH_H__ -#define __CONDSH_H__ -#include - +#ifndef __CONDSH_H__ +#define __CONDSH_H__ +#include + /* * CondSh.h, part of VCMI engine * @@ -10,17 +10,17 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -template struct CondSh -{ - T data; - boost::condition_variable cond; - boost::mutex mx; - CondSh(){}; - CondSh(T t){data = t;}; - void set(T t){mx.lock();data=t;mx.unlock();}; //set data - void setn(T t){mx.lock();data=t;mx.unlock();cond.notify_all();}; //set data and notify - T get(){boost::unique_lock lock(mx); return data;}; -}; -#endif // __CONDSH_H__ + */ + +template struct CondSh +{ + T data; + boost::condition_variable cond; + boost::mutex mx; + CondSh(){}; + CondSh(T t){data = t;}; + void set(T t){mx.lock();data=t;mx.unlock();}; //set data + void setn(T t){mx.lock();data=t;mx.unlock();cond.notify_all();}; //set data and notify + T get(){boost::unique_lock lock(mx); return data;}; +}; +#endif // __CONDSH_H__ diff --git a/lib/Connection.h b/lib/Connection.h index 23b3aca54..60854c955 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -1,28 +1,28 @@ -#ifndef __CONNECTION_H__ -#define __CONNECTION_H__ -#include "../global.h" -#include -#include -#include -#include -#include //XXX this is in namespace std if you want w/o use typeinfo.h? - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -const ui32 version = 704; -class CConnection; -namespace mpl = boost::mpl; - +#ifndef __CONNECTION_H__ +#define __CONNECTION_H__ +#include "../global.h" +#include +#include +#include +#include +#include //XXX this is in namespace std if you want w/o use typeinfo.h? + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +const ui32 version = 704; +class CConnection; +namespace mpl = boost::mpl; + /* * Connection.h, part of VCMI engine * @@ -31,619 +31,619 @@ namespace mpl = boost::mpl; * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -namespace boost -{ - namespace asio - { - namespace ip - { - class tcp; - } - class io_service; - - template class stream_socket_service; - template - class basic_stream_socket; - - template class socket_acceptor_service; - template - class basic_socket_acceptor; - } - class mutex; -}; - -enum SerializationLvl -{ - Wrong=0, - Primitive, - Array, - Pointer, - Serializable -}; - - -struct TypeComparer -{ - bool operator()(const std::type_info *a, const std::type_info *b) const - { - return a->before(*b); - } -}; - -class DLL_EXPORT CTypeList -{ - typedef std::multimap TTypeMap; - TTypeMap types; -public: - CTypeList(); - ui16 registerType(const std::type_info *type); - template ui16 registerType(const T * t = NULL) - { - return registerType(getTypeInfo(t)); - } - - ui16 getTypeID(const std::type_info *type); - template ui16 getTypeID(const T * t) - { - return getTypeID(getTypeInfo(t)); - } - - - template const std::type_info * getTypeInfo(const T * t = NULL) - { - if(t) - return &typeid(*t); - else - return &typeid(T); - } -}; - -extern DLL_EXPORT CTypeList typeList; - -template -struct SavePrimitive -{ - static void invoke(Ser &s, const T &data) - { - s.savePrimitive(data); - } -}; -template -struct SaveSerializable -{ - static void invoke(Ser &s, const T &data) - { - s.saveSerializable(data); - } -}; -template -struct LoadPrimitive -{ - static void invoke(Ser &s, T &data) - { - s.loadPrimitive(data); - } -}; -template -struct SavePointer -{ - static void invoke(Ser &s, const T &data) - { - s.savePointer(data); - } -}; -template -struct LoadPointer -{ - static void invoke(Ser &s, T &data) - { - s.loadPointer(data); - } -}; -template -struct SaveArray -{ - static void invoke(Ser &s, const T &data) - { - s.saveArray(data); - } -}; -template -struct LoadArray -{ - static void invoke(Ser &s, T &data) - { - s.loadArray(data); - } -}; -template -struct LoadSerializable -{ - static void invoke(Ser &s, T &data) - { - s.loadSerializable(data); - } -}; - -template -struct SaveWrong -{ - static void invoke(Ser &s, const T &data) - { - throw std::string("Wrong save serialization call!"); - } -}; -template -struct LoadWrong -{ - static void invoke(Ser &s, const T &data) - { - throw std::string("Wrong load serialization call!"); - } -}; - -template -struct SerializationLevel -{ - typedef mpl::integral_c_tag tag; - typedef - typename mpl::eval_if< - boost::is_fundamental, - mpl::int_, - //else - typename mpl::eval_if< - boost::is_class, - mpl::int_, - //else - typename mpl::eval_if< - boost::is_array, - mpl::int_, - //else - typename mpl::eval_if< - boost::is_pointer, - mpl::int_, - //else - typename mpl::eval_if< - boost::is_enum, - mpl::int_, - //else - mpl::int_ - > - > - > - > - >::type type; - static const int value = SerializationLevel::type::value; -}; - -class DLL_EXPORT CSerializerBase -{ -public: -}; - -class DLL_EXPORT CSaverBase : public virtual CSerializerBase -{ -}; - -class CBasicPointerSaver -{ -public: - virtual void savePtr(CSaverBase &ar, const void *data) const =0; -}; - -template class CPointerSaver : public CBasicPointerSaver -{ -public: - void savePtr(CSaverBase &ar, const void *data) const - { - Serializer &s = static_cast(ar); - const T *ptr = static_cast(data); - - //T is most derived known type, it's time to call actual serialize - const_cast(*ptr).serialize(s,version); - } -}; - -template class DLL_EXPORT COSer : public CSaverBase -{ -public: - bool saving; - std::map savers; // typeID => CPointerSaver - - COSer() - { - saving=true; - } - - template void registerType(const T * t=NULL) - { - ui16 ID = typeList.registerType(t); - savers[ID] = new CPointerSaver,T>; - } - - Serializer * This() - { - return static_cast(this); - } - - template - Serializer & operator<<(const T &t) - { - this->This()->save(t); - return * this->This(); - } - - template - COSer & operator&(const T & t) - { - return * this->This() << t; - } - - - - int write(const void * data, unsigned size); - template - void savePrimitive(const T &data) - { - this->This()->write(&data,sizeof(data)); - } - - template - void savePointer(const T &data) - { - //write if pointer is not NULL - ui8 hlp = (data!=NULL); - *this << hlp; - - //if pointer is NULL then we don't need anything more... - if(!hlp) - return; - - //write type identifier - ui16 tid = typeList.getTypeID(data); - *this << tid; - - if(!tid) - *this << *data; //if type is unregistered simply write all data in a standard way - else - savers[tid]->savePtr(*this,data); //call serializer specific for our real type - } - - template - void saveArray(const T &data) - { - ui32 size = ARRAY_COUNT(data); - for(ui32 i=0; i < size; i++) - *this << data[i]; - } - template - void save(const T &data) - { - typedef - //if - typename mpl::eval_if< mpl::equal_to,mpl::int_ >, - mpl::identity >, - //else if - typename mpl::eval_if,mpl::int_ >, - mpl::identity >, - //else if - typename mpl::eval_if,mpl::int_ >, - mpl::identity >, - //else if - typename mpl::eval_if,mpl::int_ >, - mpl::identity >, - //else - mpl::identity > - > - > - > - >::type typex; - typex::invoke(* this->This(), data); - } - template - void saveSerializable(const T &data) - { - const_cast(data).serialize(*this,version); - } - template - void saveSerializable(const std::vector &data) - { - boost::uint32_t length = data.size(); - *this << length; - for(ui32 i=0;i - void saveSerializable(const std::set &data) - { - std::set &d = const_cast &>(data); - boost::uint32_t length = d.size(); - *this << length; - for(typename std::set::iterator i=d.begin();i!=d.end();i++) - *this << *i; - } - template - void saveSerializable(const std::list &data) - { - std::list &d = const_cast &>(data); - boost::uint32_t length = d.size(); - *this << length; - for(typename std::list::iterator i=d.begin();i!=d.end();i++) - *this << *i; - } - void saveSerializable(const std::string &data) - { - *this << ui32(data.length()); - this->This()->write(data.c_str(),data.size()); - } - template - void saveSerializable(const std::pair &data) - { - *this << data.first << data.second; - } - template - void saveSerializable(const std::map &data) - { - *this << ui32(data.size()); - for(typename std::map::const_iterator i=data.begin();i!=data.end();i++) - *this << i->first << i->second; - } -}; - - - -class DLL_EXPORT CLoaderBase : public virtual CSerializerBase -{}; - -class CBasicPointerLoader -{ -public: - virtual void loadPtr(CLoaderBase &ar, void *data) const =0; //data is pointer to the ACTUAL POINTER -}; - -template class CPointerLoader : public CBasicPointerLoader -{ -public: - void loadPtr(CLoaderBase &ar, void *data) const //data is pointer to the ACTUAL POINTER - { - Serializer &s = static_cast(ar); - T *&ptr = *static_cast(data); - - //create new object under pointer - typedef typename boost::remove_pointer::type npT; - ptr = new npT; - - //T is most derived known type, it's time to call actual serialize - ptr->serialize(s,version); - } -}; - - -template class DLL_EXPORT CISer : public CLoaderBase -{ -public: - bool saving; - std::map loaders; // typeID => CPointerSaver - - CISer() - { - saving = false; - } - - template void registerType(const T * t=NULL) - { - ui16 ID = typeList.registerType(t); - loaders[ID] = new CPointerLoader,T>; - } - - Serializer * This() - { - return static_cast(this); - } - - template - Serializer & operator>>(T &t) - { - this->This()->load(t); - return * this->This(); - } - - template - CISer & operator&(T & t) - { - return * this->This() >> t; - } - - int write(const void * data, unsigned size); - template - void load(T &data) - { - typedef - //if - typename mpl::eval_if< mpl::equal_to,mpl::int_ >, - mpl::identity >, - //else if - typename mpl::eval_if,mpl::int_ >, - mpl::identity >, - //else if - typename mpl::eval_if,mpl::int_ >, - mpl::identity >, - //else if - typename mpl::eval_if,mpl::int_ >, - mpl::identity >, - //else - mpl::identity > - > - > - > - >::type typex; - typex::invoke(* this->This(), data); - } - template - void loadPrimitive(T &data) - { - this->This()->read(&data,sizeof(data)); - } - template - void loadSerializable(T &data) - { - data.serialize(*this,version); - } - template - void loadArray(T &data) - { - ui32 size = ARRAY_COUNT(data); - for(ui32 i=0; i < size; i++) - *this >> data[i]; - } - template - void loadPointer(T &data) - { - ui8 hlp; - *this >> hlp; - if(!hlp) - { - data = NULL; - return; - } - - //get type id - ui16 tid; - *this >> tid; - - if(!tid) - { - typedef typename boost::remove_pointer::type npT; - data = new npT; - *this >> *data; - } - else - { - loaders[tid]->loadPtr(*this,&data); - } - } - template - void loadSerializable(std::vector &data) - { - boost::uint32_t length; - *this >> length; - data.resize(length); - for(ui32 i=0;i> data[i]; - } - template - void loadSerializable(std::set &data) - { - boost::uint32_t length; - *this >> length; - T ins; - for(ui32 i=0;i> ins; - data.insert(ins); - } - } - template - void loadSerializable(std::list &data) - { - boost::uint32_t length; - *this >> length; - T ins; - for(ui32 i=0;i> ins; - data.push_back(ins); - } - } - template - void loadSerializable(std::pair &data) - { - *this >> data.first >> data.second; - } - - template - void loadSerializable(std::map &data) - { - ui32 length; - *this >> length; - T1 t; - for(int i=0;i> t; - *this >> data[t]; - } - } - void loadSerializable(std::string &data) - { - ui32 length; - *this >> length; - data.resize(length); - this->This()->read((void*)data.c_str(),length); - } - -}; - - -class DLL_EXPORT CSaveFile - : public COSer -{ - void dummyMagicFunction() - { - *this << std::string("This function makes stuff working."); - } -public: - std::ofstream *sfile; - CSaveFile(const std::string &fname); - ~CSaveFile(); - int write(const void * data, unsigned size); -}; - -class DLL_EXPORT CLoadFile - : public CISer -{ - void dummyMagicFunction() - { - std::string dummy = "This function makes stuff working."; - *this >> dummy; - } -public: - std::ifstream *sfile; - CLoadFile(const std::string &fname); - ~CLoadFile(); - int read(const void * data, unsigned size); -}; - -class DLL_EXPORT CConnection - :public CISer, public COSer -{ - CConnection(void); - void init(); -public: - boost::mutex *rmx, *wmx; // read/write mutexes - boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service > * socket; - bool logging; - bool connected; - bool myEndianess, contactEndianess; //true if little endian, if ednianess is different we'll have to revert recieved multi-byte vars - boost::asio::io_service *io_service; - std::string name; //who uses this connection - - CConnection - (std::string host, std::string port, std::string Name); - CConnection - (boost::asio::basic_socket_acceptor > * acceptor, - boost::asio::io_service *Io_service, std::string Name); - CConnection - (boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service > * Socket, - std::string Name); //use immediately after accepting connection into socket - int write(const void * data, unsigned size); - int read(void * data, unsigned size); - int readLine(void * data, unsigned maxSize); - void close(); - template - CConnection &operator&(const T&); - ~CConnection(void); -}; - -#endif // __CONNECTION_H__ + */ + +namespace boost +{ + namespace asio + { + namespace ip + { + class tcp; + } + class io_service; + + template class stream_socket_service; + template + class basic_stream_socket; + + template class socket_acceptor_service; + template + class basic_socket_acceptor; + } + class mutex; +}; + +enum SerializationLvl +{ + Wrong=0, + Primitive, + Array, + Pointer, + Serializable +}; + + +struct TypeComparer +{ + bool operator()(const std::type_info *a, const std::type_info *b) const + { + return a->before(*b); + } +}; + +class DLL_EXPORT CTypeList +{ + typedef std::multimap TTypeMap; + TTypeMap types; +public: + CTypeList(); + ui16 registerType(const std::type_info *type); + template ui16 registerType(const T * t = NULL) + { + return registerType(getTypeInfo(t)); + } + + ui16 getTypeID(const std::type_info *type); + template ui16 getTypeID(const T * t) + { + return getTypeID(getTypeInfo(t)); + } + + + template const std::type_info * getTypeInfo(const T * t = NULL) + { + if(t) + return &typeid(*t); + else + return &typeid(T); + } +}; + +extern DLL_EXPORT CTypeList typeList; + +template +struct SavePrimitive +{ + static void invoke(Ser &s, const T &data) + { + s.savePrimitive(data); + } +}; +template +struct SaveSerializable +{ + static void invoke(Ser &s, const T &data) + { + s.saveSerializable(data); + } +}; +template +struct LoadPrimitive +{ + static void invoke(Ser &s, T &data) + { + s.loadPrimitive(data); + } +}; +template +struct SavePointer +{ + static void invoke(Ser &s, const T &data) + { + s.savePointer(data); + } +}; +template +struct LoadPointer +{ + static void invoke(Ser &s, T &data) + { + s.loadPointer(data); + } +}; +template +struct SaveArray +{ + static void invoke(Ser &s, const T &data) + { + s.saveArray(data); + } +}; +template +struct LoadArray +{ + static void invoke(Ser &s, T &data) + { + s.loadArray(data); + } +}; +template +struct LoadSerializable +{ + static void invoke(Ser &s, T &data) + { + s.loadSerializable(data); + } +}; + +template +struct SaveWrong +{ + static void invoke(Ser &s, const T &data) + { + throw std::string("Wrong save serialization call!"); + } +}; +template +struct LoadWrong +{ + static void invoke(Ser &s, const T &data) + { + throw std::string("Wrong load serialization call!"); + } +}; + +template +struct SerializationLevel +{ + typedef mpl::integral_c_tag tag; + typedef + typename mpl::eval_if< + boost::is_fundamental, + mpl::int_, + //else + typename mpl::eval_if< + boost::is_class, + mpl::int_, + //else + typename mpl::eval_if< + boost::is_array, + mpl::int_, + //else + typename mpl::eval_if< + boost::is_pointer, + mpl::int_, + //else + typename mpl::eval_if< + boost::is_enum, + mpl::int_, + //else + mpl::int_ + > + > + > + > + >::type type; + static const int value = SerializationLevel::type::value; +}; + +class DLL_EXPORT CSerializerBase +{ +public: +}; + +class DLL_EXPORT CSaverBase : public virtual CSerializerBase +{ +}; + +class CBasicPointerSaver +{ +public: + virtual void savePtr(CSaverBase &ar, const void *data) const =0; +}; + +template class CPointerSaver : public CBasicPointerSaver +{ +public: + void savePtr(CSaverBase &ar, const void *data) const + { + Serializer &s = static_cast(ar); + const T *ptr = static_cast(data); + + //T is most derived known type, it's time to call actual serialize + const_cast(*ptr).serialize(s,version); + } +}; + +template class DLL_EXPORT COSer : public CSaverBase +{ +public: + bool saving; + std::map savers; // typeID => CPointerSaver + + COSer() + { + saving=true; + } + + template void registerType(const T * t=NULL) + { + ui16 ID = typeList.registerType(t); + savers[ID] = new CPointerSaver,T>; + } + + Serializer * This() + { + return static_cast(this); + } + + template + Serializer & operator<<(const T &t) + { + this->This()->save(t); + return * this->This(); + } + + template + COSer & operator&(const T & t) + { + return * this->This() << t; + } + + + + int write(const void * data, unsigned size); + template + void savePrimitive(const T &data) + { + this->This()->write(&data,sizeof(data)); + } + + template + void savePointer(const T &data) + { + //write if pointer is not NULL + ui8 hlp = (data!=NULL); + *this << hlp; + + //if pointer is NULL then we don't need anything more... + if(!hlp) + return; + + //write type identifier + ui16 tid = typeList.getTypeID(data); + *this << tid; + + if(!tid) + *this << *data; //if type is unregistered simply write all data in a standard way + else + savers[tid]->savePtr(*this,data); //call serializer specific for our real type + } + + template + void saveArray(const T &data) + { + ui32 size = ARRAY_COUNT(data); + for(ui32 i=0; i < size; i++) + *this << data[i]; + } + template + void save(const T &data) + { + typedef + //if + typename mpl::eval_if< mpl::equal_to,mpl::int_ >, + mpl::identity >, + //else if + typename mpl::eval_if,mpl::int_ >, + mpl::identity >, + //else if + typename mpl::eval_if,mpl::int_ >, + mpl::identity >, + //else if + typename mpl::eval_if,mpl::int_ >, + mpl::identity >, + //else + mpl::identity > + > + > + > + >::type typex; + typex::invoke(* this->This(), data); + } + template + void saveSerializable(const T &data) + { + const_cast(data).serialize(*this,version); + } + template + void saveSerializable(const std::vector &data) + { + boost::uint32_t length = data.size(); + *this << length; + for(ui32 i=0;i + void saveSerializable(const std::set &data) + { + std::set &d = const_cast &>(data); + boost::uint32_t length = d.size(); + *this << length; + for(typename std::set::iterator i=d.begin();i!=d.end();i++) + *this << *i; + } + template + void saveSerializable(const std::list &data) + { + std::list &d = const_cast &>(data); + boost::uint32_t length = d.size(); + *this << length; + for(typename std::list::iterator i=d.begin();i!=d.end();i++) + *this << *i; + } + void saveSerializable(const std::string &data) + { + *this << ui32(data.length()); + this->This()->write(data.c_str(),data.size()); + } + template + void saveSerializable(const std::pair &data) + { + *this << data.first << data.second; + } + template + void saveSerializable(const std::map &data) + { + *this << ui32(data.size()); + for(typename std::map::const_iterator i=data.begin();i!=data.end();i++) + *this << i->first << i->second; + } +}; + + + +class DLL_EXPORT CLoaderBase : public virtual CSerializerBase +{}; + +class CBasicPointerLoader +{ +public: + virtual void loadPtr(CLoaderBase &ar, void *data) const =0; //data is pointer to the ACTUAL POINTER +}; + +template class CPointerLoader : public CBasicPointerLoader +{ +public: + void loadPtr(CLoaderBase &ar, void *data) const //data is pointer to the ACTUAL POINTER + { + Serializer &s = static_cast(ar); + T *&ptr = *static_cast(data); + + //create new object under pointer + typedef typename boost::remove_pointer::type npT; + ptr = new npT; + + //T is most derived known type, it's time to call actual serialize + ptr->serialize(s,version); + } +}; + + +template class DLL_EXPORT CISer : public CLoaderBase +{ +public: + bool saving; + std::map loaders; // typeID => CPointerSaver + + CISer() + { + saving = false; + } + + template void registerType(const T * t=NULL) + { + ui16 ID = typeList.registerType(t); + loaders[ID] = new CPointerLoader,T>; + } + + Serializer * This() + { + return static_cast(this); + } + + template + Serializer & operator>>(T &t) + { + this->This()->load(t); + return * this->This(); + } + + template + CISer & operator&(T & t) + { + return * this->This() >> t; + } + + int write(const void * data, unsigned size); + template + void load(T &data) + { + typedef + //if + typename mpl::eval_if< mpl::equal_to,mpl::int_ >, + mpl::identity >, + //else if + typename mpl::eval_if,mpl::int_ >, + mpl::identity >, + //else if + typename mpl::eval_if,mpl::int_ >, + mpl::identity >, + //else if + typename mpl::eval_if,mpl::int_ >, + mpl::identity >, + //else + mpl::identity > + > + > + > + >::type typex; + typex::invoke(* this->This(), data); + } + template + void loadPrimitive(T &data) + { + this->This()->read(&data,sizeof(data)); + } + template + void loadSerializable(T &data) + { + data.serialize(*this,version); + } + template + void loadArray(T &data) + { + ui32 size = ARRAY_COUNT(data); + for(ui32 i=0; i < size; i++) + *this >> data[i]; + } + template + void loadPointer(T &data) + { + ui8 hlp; + *this >> hlp; + if(!hlp) + { + data = NULL; + return; + } + + //get type id + ui16 tid; + *this >> tid; + + if(!tid) + { + typedef typename boost::remove_pointer::type npT; + data = new npT; + *this >> *data; + } + else + { + loaders[tid]->loadPtr(*this,&data); + } + } + template + void loadSerializable(std::vector &data) + { + boost::uint32_t length; + *this >> length; + data.resize(length); + for(ui32 i=0;i> data[i]; + } + template + void loadSerializable(std::set &data) + { + boost::uint32_t length; + *this >> length; + T ins; + for(ui32 i=0;i> ins; + data.insert(ins); + } + } + template + void loadSerializable(std::list &data) + { + boost::uint32_t length; + *this >> length; + T ins; + for(ui32 i=0;i> ins; + data.push_back(ins); + } + } + template + void loadSerializable(std::pair &data) + { + *this >> data.first >> data.second; + } + + template + void loadSerializable(std::map &data) + { + ui32 length; + *this >> length; + T1 t; + for(int i=0;i> t; + *this >> data[t]; + } + } + void loadSerializable(std::string &data) + { + ui32 length; + *this >> length; + data.resize(length); + this->This()->read((void*)data.c_str(),length); + } + +}; + + +class DLL_EXPORT CSaveFile + : public COSer +{ + void dummyMagicFunction() + { + *this << std::string("This function makes stuff working."); + } +public: + std::ofstream *sfile; + CSaveFile(const std::string &fname); + ~CSaveFile(); + int write(const void * data, unsigned size); +}; + +class DLL_EXPORT CLoadFile + : public CISer +{ + void dummyMagicFunction() + { + std::string dummy = "This function makes stuff working."; + *this >> dummy; + } +public: + std::ifstream *sfile; + CLoadFile(const std::string &fname); + ~CLoadFile(); + int read(const void * data, unsigned size); +}; + +class DLL_EXPORT CConnection + :public CISer, public COSer +{ + CConnection(void); + void init(); +public: + boost::mutex *rmx, *wmx; // read/write mutexes + boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service > * socket; + bool logging; + bool connected; + bool myEndianess, contactEndianess; //true if little endian, if ednianess is different we'll have to revert recieved multi-byte vars + boost::asio::io_service *io_service; + std::string name; //who uses this connection + + CConnection + (std::string host, std::string port, std::string Name); + CConnection + (boost::asio::basic_socket_acceptor > * acceptor, + boost::asio::io_service *Io_service, std::string Name); + CConnection + (boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service > * Socket, + std::string Name); //use immediately after accepting connection into socket + int write(const void * data, unsigned size); + int read(void * data, unsigned size); + int readLine(void * data, unsigned maxSize); + void close(); + template + CConnection &operator&(const T&); + ~CConnection(void); +}; + +#endif // __CONNECTION_H__ diff --git a/lib/VCMI_Lib.h b/lib/VCMI_Lib.h index 0805bef8c..4ec5403c2 100644 --- a/lib/VCMI_Lib.h +++ b/lib/VCMI_Lib.h @@ -1,11 +1,11 @@ -#ifndef __VCMI_LIB_H__ -#define __VCMI_LIB_H__ -#include "../global.h" -#ifndef _MSC_VER -#include "../hch/CArtHandler.h" -#include "../hch/CGeneralTextHandler.h" -#endif - +#ifndef __VCMI_LIB_H__ +#define __VCMI_LIB_H__ +#include "../global.h" +#ifndef _MSC_VER +#include "../hch/CArtHandler.h" +#include "../hch/CGeneralTextHandler.h" +#endif + /* * VCMI_Lib.h, part of VCMI engine * @@ -14,60 +14,60 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CLodHandler; -class CArtHandler; -class CHeroHandler; -class CCreatureHandler; -class CSpellHandler; -//class CPreGameTextHandler; -class CBuildingHandler; -class CObjectHandler; -//class CMusicHandler; -//class CSemiLodHandler; -class CDefObjInfoHandler; -class CTownHandler; -class CGeneralTextHandler; -//class CConsoleHandler; -//class CPathfinder; -//class CGameState; - -class DLL_EXPORT LibClasses -{ -public: - CArtHandler * arth; - CHeroHandler * heroh; - CCreatureHandler * creh; - CSpellHandler * spellh; - CBuildingHandler * buildh; - CObjectHandler * objh; - CDefObjInfoHandler * dobjinfo; - CTownHandler * townh; - CGeneralTextHandler * generaltexth; - //CPathfinder * pathf; - - void init(); //uses standard config file - void clear(); //deletes all handlers and its data - - template void serialize(Handler &h, const int version) - { - h & heroh & arth & creh & townh & objh & dobjinfo & buildh & spellh; - if(!h.saving) - { - generaltexth = new CGeneralTextHandler; - generaltexth->load(); - arth->loadArtifacts(true); - } - } -}; - -extern DLL_EXPORT LibClasses * VLC; -extern CLodHandler * bitmaph; - -DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode); -DLL_EXPORT void loadToIt(si32 &dest, std::string &src, int &iter, int mode); -DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *Logfile); - - -#endif // __VCMI_LIB_H__ + */ + +class CLodHandler; +class CArtHandler; +class CHeroHandler; +class CCreatureHandler; +class CSpellHandler; +//class CPreGameTextHandler; +class CBuildingHandler; +class CObjectHandler; +//class CMusicHandler; +//class CSemiLodHandler; +class CDefObjInfoHandler; +class CTownHandler; +class CGeneralTextHandler; +//class CConsoleHandler; +//class CPathfinder; +//class CGameState; + +class DLL_EXPORT LibClasses +{ +public: + CArtHandler * arth; + CHeroHandler * heroh; + CCreatureHandler * creh; + CSpellHandler * spellh; + CBuildingHandler * buildh; + CObjectHandler * objh; + CDefObjInfoHandler * dobjinfo; + CTownHandler * townh; + CGeneralTextHandler * generaltexth; + //CPathfinder * pathf; + + void init(); //uses standard config file + void clear(); //deletes all handlers and its data + + template void serialize(Handler &h, const int version) + { + h & heroh & arth & creh & townh & objh & dobjinfo & buildh & spellh; + if(!h.saving) + { + generaltexth = new CGeneralTextHandler; + generaltexth->load(); + arth->loadArtifacts(true); + } + } +}; + +extern DLL_EXPORT LibClasses * VLC; +extern CLodHandler * bitmaph; + +DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode); +DLL_EXPORT void loadToIt(si32 &dest, std::string &src, int &iter, int mode); +DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *Logfile); + + +#endif // __VCMI_LIB_H__ diff --git a/mapHandler.h b/mapHandler.h index bd42507a9..fd80284a3 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -1,12 +1,12 @@ -#ifndef __MAPHANDLER_H__ -#define __MAPHANDLER_H__ -#include "global.h" -#include -#include - -const int Woff = 13; //width of map's frame -const int Hoff = 10; - +#ifndef __MAPHANDLER_H__ +#define __MAPHANDLER_H__ +#include "global.h" +#include +#include + +const int Woff = 13; //width of map's frame +const int Hoff = 10; + /* * mapHandler.h, part of VCMI engine * @@ -15,116 +15,116 @@ const int Hoff = 10; * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CGObjectInstance; -class CGHeroInstance; -struct Mapa; -class CGDefInfo; -class CGObjectInstance; -class CDefHandler; -struct TerrainTile; -struct SDL_Surface; -struct SDL_Rect; - -struct TerrainTile2 -{ - int3 pos; - const TerrainTile *tileInfo; - SDL_Surface * terbitmap; //frames of terrain animation - std::vector rivbitmap; //frames of river animation - std::vector roadbitmap; //frames of road animation - - std::vector < std::pair > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen - TerrainTile2(); -}; - -//pathfinder -// map iDTerenu=>koszt_pola -// map IDdrogi=>koszt_drogi -template class PseudoV -{ -public: - int offset; - std::vector inver; - PseudoV(){}; - PseudoV(std::vector &src, int rest, int Offset, const T& fill) - { - inver.resize(Offset*2+rest); - offset=Offset; - for(int i=0; i > > ttiles; - int3 sizes; - Mapa * map; - std::set usedHeroes; - CDefHandler * fullHide; - CDefHandler * partialHide; - - std::vector > terrainGraphics; // [terrain id] [view type] [rotation type] - std::vector roadDefs; - std::vector staticRiverDefs; - std::vector defs; - - std::map loadedDefs; //pointers to loaded defs (key is filename, uppercase) - - std::vector > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile - - CMapHandler(); - ~CMapHandler(); - - void loadDefs(); - SDL_Surface * getVisBitmap(int x, int y, const std::vector< std::vector< std::vector > > & visibilityMap, int lvl); - - int getCost(int3 & a, int3 & b, const CGHeroInstance * hero); - std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position - //std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position - CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid - std::string getDefName(int id, int subid); //returns name of def for object with given id and subid - bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map - bool hideObject(const CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist) - bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope) - void initHeroDef(CGHeroInstance * h); - void init(); - void calculateBlockedPos(); - void initObjectRects(); - void borderAndTerrainBitmapInit(); - void roadsRiverTerrainInit(); - void prepareFOWDefs(); - - SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect, int moveX, int moveY, bool smooth); - void updateWater(); - unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function - void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper - static unsigned char getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b] - -}; - - -#endif // __MAPHANDLER_H__ + */ + +class CGObjectInstance; +class CGHeroInstance; +struct Mapa; +class CGDefInfo; +class CGObjectInstance; +class CDefHandler; +struct TerrainTile; +struct SDL_Surface; +struct SDL_Rect; + +struct TerrainTile2 +{ + int3 pos; + const TerrainTile *tileInfo; + SDL_Surface * terbitmap; //frames of terrain animation + std::vector rivbitmap; //frames of river animation + std::vector roadbitmap; //frames of road animation + + std::vector < std::pair > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen + TerrainTile2(); +}; + +//pathfinder +// map iDTerenu=>koszt_pola +// map IDdrogi=>koszt_drogi +template class PseudoV +{ +public: + int offset; + std::vector inver; + PseudoV(){}; + PseudoV(std::vector &src, int rest, int Offset, const T& fill) + { + inver.resize(Offset*2+rest); + offset=Offset; + for(int i=0; i > > ttiles; + int3 sizes; + Mapa * map; + std::set usedHeroes; + CDefHandler * fullHide; + CDefHandler * partialHide; + + std::vector > terrainGraphics; // [terrain id] [view type] [rotation type] + std::vector roadDefs; + std::vector staticRiverDefs; + std::vector defs; + + std::map loadedDefs; //pointers to loaded defs (key is filename, uppercase) + + std::vector > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile + + CMapHandler(); + ~CMapHandler(); + + void loadDefs(); + SDL_Surface * getVisBitmap(int x, int y, const std::vector< std::vector< std::vector > > & visibilityMap, int lvl); + + int getCost(int3 & a, int3 & b, const CGHeroInstance * hero); + std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position + //std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position + CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid + std::string getDefName(int id, int subid); //returns name of def for object with given id and subid + bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map + bool hideObject(const CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist) + bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope) + void initHeroDef(CGHeroInstance * h); + void init(); + void calculateBlockedPos(); + void initObjectRects(); + void borderAndTerrainBitmapInit(); + void roadsRiverTerrainInit(); + void prepareFOWDefs(); + + SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect, int moveX, int moveY, bool smooth); + void updateWater(); + unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function + void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper + static unsigned char getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b] + +}; + + +#endif // __MAPHANDLER_H__ diff --git a/server/CVCMIServer.h b/server/CVCMIServer.h index 517d360b3..6111c15cd 100644 --- a/server/CVCMIServer.h +++ b/server/CVCMIServer.h @@ -1,8 +1,8 @@ -#ifndef __CVCMISERVER_H__ -#define __CVCMISERVER_H__ -#include "../global.h" -#include - +#ifndef __CVCMISERVER_H__ +#define __CVCMISERVER_H__ +#include "../global.h" +#include + /* * CVCMIServer.h, part of VCMI engine * @@ -11,36 +11,36 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class CConnection; -namespace boost -{ - namespace asio - { - class io_service; - namespace ip - { - class tcp; - } - template class socket_acceptor_service; - template - class basic_socket_acceptor; - } -}; - -class CVCMIServer -{ - boost::asio::io_service *io; - boost::asio::basic_socket_acceptor > * acceptor; - std::map connections; - std::set conns; -public: - CVCMIServer(); - ~CVCMIServer(); - void setUpConnection(CConnection *c, std::string mapname, si32 checksum); - void newGame(CConnection *c); - void loadGame(CConnection *c); - void start(); -}; -#endif // __CVCMISERVER_H__ + */ + +class CConnection; +namespace boost +{ + namespace asio + { + class io_service; + namespace ip + { + class tcp; + } + template class socket_acceptor_service; + template + class basic_socket_acceptor; + } +}; + +class CVCMIServer +{ + boost::asio::io_service *io; + boost::asio::basic_socket_acceptor > * acceptor; + std::map connections; + std::set conns; +public: + CVCMIServer(); + ~CVCMIServer(); + void setUpConnection(CConnection *c, std::string mapname, si32 checksum); + void newGame(CConnection *c); + void loadGame(CConnection *c); + void start(); +}; +#endif // __CVCMISERVER_H__ diff --git a/timeHandler.h b/timeHandler.h index ca090ecd4..7be16bc9f 100644 --- a/timeHandler.h +++ b/timeHandler.h @@ -1,8 +1,8 @@ -#ifndef __TIMEHANDLER_H__ -#define __TIMEHANDLER_H__ - -#include - +#ifndef __TIMEHANDLER_H__ +#define __TIMEHANDLER_H__ + +#include + /* * timeHandler.h, part of VCMI engine * @@ -11,18 +11,18 @@ * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * - */ - -class timeHandler -{ -public: - clock_t start, last, mem; - timeHandler():start(clock()){last=clock();mem=0;}; - long getDif(){long ret=clock()-last;last=clock();return ret;}; - void update(){last=clock();}; - void remember(){mem=clock();}; - long memDif(){return mem-clock();}; -}; - - -#endif // __TIMEHANDLER_H__ + */ + +class timeHandler +{ +public: + clock_t start, last, mem; + timeHandler():start(clock()){last=clock();mem=0;}; + long getDif(){long ret=clock()-last;last=clock();return ret;}; + void update(){last=clock();}; + void remember(){mem=clock();}; + long memDif(){return mem-clock();}; +}; + + +#endif // __TIMEHANDLER_H__