Browse Source

corrected that missclick! hope so

Łukasz Wychrystenko 17 năm trước cách đây
mục cha
commit
b356524aee
44 tập tin đã thay đổi với 6029 bổ sung3728 xóa
  1. 181 181
      AI/GeniusAI/CGeniusAI.h
  2. 14 14
      AI_Base.h
  3. 98 101
      AdventureMapButton.h
  4. 177 177
      CAdvmapInterface.h
  5. 257 260
      CBattleInterface.h
  6. 227 230
      CCastleInterface.h
  7. 132 135
      CHeroWindow.h
  8. 43 46
      client/CBitmapHandler.h
  9. 65 66
      client/CConfigHandler.h
  10. 53 56
      client/CCreatureAnimation.h
  11. 91 94
      client/CSpellWindow.h
  12. 61 64
      client/Client.h
  13. 65 68
      client/Graphics.h
  14. 5 0
      client/vcmi_client/.dep.inc
  15. 92 0
      client/vcmi_client/Makefile
  16. 257 0
      client/vcmi_client/nbproject/Makefile-Debug.mk
  17. 253 0
      client/vcmi_client/nbproject/Makefile-Release.mk
  18. 123 0
      client/vcmi_client/nbproject/Makefile-impl.mk
  19. 72 0
      client/vcmi_client/nbproject/Package-Debug.bash
  20. 72 0
      client/vcmi_client/nbproject/Package-Release.bash
  21. 595 0
      client/vcmi_client/nbproject/configurations.xml
  22. 37 0
      client/vcmi_client/nbproject/private/configurations.xml
  23. 0 0
      client/vcmi_client/nbproject/private/private.properties
  24. 26 0
      client/vcmi_client/nbproject/private/private.xml
  25. 0 0
      client/vcmi_client/nbproject/project.properties
  26. 17 0
      client/vcmi_client/nbproject/project.xml
  27. 58 58
      hch/CDefObjInfoHandler.h
  28. 150 150
      hch/CVideoHandler.h
  29. 14 13
      lib/BattleAction.h
  30. 14 13
      lib/CondSh.h
  31. 416 417
      lib/Connection.h
  32. 53 52
      lib/IGameCallback.h
  33. 92 0
      lib/vcmi_lib/Makefile-nb
  34. 163 0
      lib/vcmi_lib/nbproject/Makefile-Debug.mk
  35. 163 0
      lib/vcmi_lib/nbproject/Makefile-Release.mk
  36. 123 0
      lib/vcmi_lib/nbproject/Makefile-impl.mk
  37. 72 0
      lib/vcmi_lib/nbproject/Package-Debug.bash
  38. 72 0
      lib/vcmi_lib/nbproject/Package-Release.bash
  39. 390 390
      map.h
  40. 912 912
      nodrze.h
  41. 171 172
      server/CGameHandler.h
  42. 34 32
      server/CVCMIServer.h
  43. 92 0
      server/vcmi_server/Makefile
  44. 27 27
      stdafx.h

+ 181 - 181
AI/GeniusAI/CGeniusAI.h

@@ -1,181 +1,181 @@
-#ifndef __GENIUS_AI__
-#define __GENIUS_AI__
-
-#define VCMI_DLL
-
-#pragma warning (disable: 4100 4251 4245 4018 4081)
-#include "../../global.h"
-#include "../../AI_Base.h"
-#include "../../CCallback.h"
-#include "../../hch/CCreatureHandler.h"
-#include "../../hch/CObjectHandler.h"
-
-#pragma warning (default: 4100 4251 4245 4018 4081)
-
-#pragma warning (disable: 4100)
-
-namespace GeniusAI {
-
-class CBattleHelper
-{
-public:
-	CBattleHelper();
-	~CBattleHelper();
-
-	int GetBattleFieldPosition(int x, int y);
-	int DecodeXPosition(int battleFieldPosition);
-	int DecodeYPosition(int battleFieldPosition);
-
-	int GetShortestDistance(int pointA, int pointB);
-	int GetDistanceWithObstacles(int pointA, int pointB);
-
-	int GetVoteForMaxDamage() const { return m_voteForMaxDamage; }
-	int GetVoteForMinDamage() const { return m_voteForMinDamage; }
-	int GetVoteForMaxSpeed() const { return m_voteForMaxSpeed; }
-	int GetVoteForDistance() const { return m_voteForDistance; }
-	int GetVoteForDistanceFromShooters() const { return m_voteForDistanceFromShooters; }
-	int GetVoteForHitPoints() const { return m_voteForHitPoints; }
-
-	const int InfiniteDistance;
-	const int BattlefieldWidth;
-	const int BattlefieldHeight;
-private:
-	int m_voteForMaxDamage;
-	int m_voteForMinDamage;
-	int m_voteForMaxSpeed;
-	int m_voteForDistance;
-	int m_voteForDistanceFromShooters;
-	int m_voteForHitPoints;
-
-	CBattleHelper(const CBattleHelper &);
-	CBattleHelper &operator=(const CBattleHelper &);
-};
-
-/**
- * Maybe it is a additional proxy, but i've separated the game IA for transparent.
- */
-class CBattleLogic
-{
-private:
-	enum EMainStrategyType
-	{
-		strategy_super_aggresive,
-		strategy_aggresive,
-		strategy_neutral,
-		strategy_defensive,
-		strategy_super_defensive,
-		strategy_berserk_attack /** cause max damage, usually when creatures fight against overwhelming army*/
-	};
-	enum ECreatureRoleInBattle
-	{
-		creature_role_shooter,
-		creature_role_defenser,
-		creature_role_fast_attacker,
-		creature_role_attacker
-	};
-	enum EActionType
-	{
-		action_cancel = 0,				// Cancel BattleAction   
-		action_cast_spell = 1,			// Hero cast a spell   
-		action_walk = 2,				// Walk   
-		action_defend = 3,				// Defend   
-		action_retreat = 4,				// Retreat from the battle   
-		action_surrender = 5,			// Surrender   
-		action_walk_and_attack = 6,		// Walk and Attack   
-		action_shoot = 7,				// Shoot    
-		action_wait = 8,				// Wait   
-		action_catapult = 9,			// Catapult 
-		action_monster_casts_spell = 10 // Monster casts a spell (i.e. Faerie Dragons)
-	};
-	struct SCreatureCasualties
-	{
-		int amount_max; // amount of creatures that will be dead
-		int amount_min;
-		int damage_max; // number of hit points that creature will lost
-		int damage_min;
-		int leftHitPoints_for_max; // number of hit points that will remain (for last unity)
-		int leftHitPoint_for_min; // scenario
-	};
-public:
-	CBattleLogic(ICallback *cb, CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side);
-	~CBattleLogic();
-
-	void SetCurrentTurn(int turn);
-
-	BattleAction MakeDecision(int stackID);
-private:
-	CBattleHelper m_battleHelper;
-	//BattleInfo m_battleInfo;
-	int m_iCurrentTurn;
-	bool m_bIsAttacker;
-	ICallback *m_cb;
-	CCreatureSet *m_army1;
-	CCreatureSet *m_army2; 
-	int3 m_tile; 
-	CGHeroInstance *m_hero1;
-	CGHeroInstance *m_hero2; 
-	bool m_side;
-
-	void MakeStatistics(int currentCreatureId); // before decision we have to make some calculation and simulation
-	// statistics
-	typedef std::vector<std::pair<int, int> > creature_stat; // first - creature id, second - value
-	creature_stat m_statMaxDamage;
-	creature_stat m_statMinDamage;
-	//
-	creature_stat m_statMaxSpeed;
-	creature_stat m_statDistance;
-	creature_stat m_statDistanceFromShooters;
-	creature_stat m_statHitPoints;
-
-	typedef std::vector<std::pair<int, SCreatureCasualties> > creature_stat_casualties;
-	creature_stat_casualties m_statCasualties;
-
-	bool m_bEnemyDominates;
-
-	std::vector<int> GetAvailableHexesForAttacker(CStack *defender, CStack *attacker = NULL);
-
-	BattleAction MakeDefend(int stackID);
-
-	int PerformBerserkAttack(int stackID); // return ID of creature to attack, -2 means wait, -1 - defend
-	int PerformDefaultAction(int stackID);
-
-	void CBattleLogic::PrintBattleAction(const BattleAction &action);
-};
-
-class CGeniusAI : public CGlobalAI
-{
-private:
-	ICallback *m_cb;
-	CBattleLogic *m_battleLogic;
-public:
-	virtual void init(ICallback * CB);
-	virtual void yourTurn();
-	virtual void heroKilled(const CGHeroInstance *);
-	virtual void heroCreated(const CGHeroInstance *);
-	virtual void heroMoved(const HeroMoveDetails &);
-	virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) {};
-	virtual void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID){};
-	virtual void tileRevealed(int3 pos){};
-	virtual void tileHidden(int3 pos){};
-	virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
-	// battle
-	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 void battleAttack(BattleAttack *ba); //called when stack is performing attack
-	virtual void battleStackAttacked(BattleStackAttacked * 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);
-	virtual void battleSpellCasted(SpellCasted *sc);
-	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<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
-	//
-	virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving);
-	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);
-};
-
-}
-
-#endif/*__GENIUS_AI__*/
+#ifndef __CGENIUSAI_H__
+#define __CGENIUSAI_H__
+
+#define VCMI_DLL
+
+#pragma warning (disable: 4100 4251 4245 4018 4081)
+#include "../../global.h"
+#include "../../AI_Base.h"
+#include "../../CCallback.h"
+#include "../../hch/CCreatureHandler.h"
+#include "../../hch/CObjectHandler.h"
+
+#pragma warning (default: 4100 4251 4245 4018 4081)
+
+#pragma warning (disable: 4100)
+
+namespace GeniusAI {
+
+class CBattleHelper
+{
+public:
+	CBattleHelper();
+	~CBattleHelper();
+
+	int GetBattleFieldPosition(int x, int y);
+	int DecodeXPosition(int battleFieldPosition);
+	int DecodeYPosition(int battleFieldPosition);
+
+	int GetShortestDistance(int pointA, int pointB);
+	int GetDistanceWithObstacles(int pointA, int pointB);
+
+	int GetVoteForMaxDamage() const { return m_voteForMaxDamage; }
+	int GetVoteForMinDamage() const { return m_voteForMinDamage; }
+	int GetVoteForMaxSpeed() const { return m_voteForMaxSpeed; }
+	int GetVoteForDistance() const { return m_voteForDistance; }
+	int GetVoteForDistanceFromShooters() const { return m_voteForDistanceFromShooters; }
+	int GetVoteForHitPoints() const { return m_voteForHitPoints; }
+
+	const int InfiniteDistance;
+	const int BattlefieldWidth;
+	const int BattlefieldHeight;
+private:
+	int m_voteForMaxDamage;
+	int m_voteForMinDamage;
+	int m_voteForMaxSpeed;
+	int m_voteForDistance;
+	int m_voteForDistanceFromShooters;
+	int m_voteForHitPoints;
+
+	CBattleHelper(const CBattleHelper &);
+	CBattleHelper &operator=(const CBattleHelper &);
+};
+
+/**
+ * Maybe it is a additional proxy, but i've separated the game IA for transparent.
+ */
+class CBattleLogic
+{
+private:
+	enum EMainStrategyType
+	{
+		strategy_super_aggresive,
+		strategy_aggresive,
+		strategy_neutral,
+		strategy_defensive,
+		strategy_super_defensive,
+		strategy_berserk_attack /** cause max damage, usually when creatures fight against overwhelming army*/
+	};
+	enum ECreatureRoleInBattle
+	{
+		creature_role_shooter,
+		creature_role_defenser,
+		creature_role_fast_attacker,
+		creature_role_attacker
+	};
+	enum EActionType
+	{
+		action_cancel = 0,				// Cancel BattleAction   
+		action_cast_spell = 1,			// Hero cast a spell   
+		action_walk = 2,				// Walk   
+		action_defend = 3,				// Defend   
+		action_retreat = 4,				// Retreat from the battle   
+		action_surrender = 5,			// Surrender   
+		action_walk_and_attack = 6,		// Walk and Attack   
+		action_shoot = 7,				// Shoot    
+		action_wait = 8,				// Wait   
+		action_catapult = 9,			// Catapult 
+		action_monster_casts_spell = 10 // Monster casts a spell (i.e. Faerie Dragons)
+	};
+	struct SCreatureCasualties
+	{
+		int amount_max; // amount of creatures that will be dead
+		int amount_min;
+		int damage_max; // number of hit points that creature will lost
+		int damage_min;
+		int leftHitPoints_for_max; // number of hit points that will remain (for last unity)
+		int leftHitPoint_for_min; // scenario
+	};
+public:
+	CBattleLogic(ICallback *cb, CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side);
+	~CBattleLogic();
+
+	void SetCurrentTurn(int turn);
+
+	BattleAction MakeDecision(int stackID);
+private:
+	CBattleHelper m_battleHelper;
+	//BattleInfo m_battleInfo;
+	int m_iCurrentTurn;
+	bool m_bIsAttacker;
+	ICallback *m_cb;
+	CCreatureSet *m_army1;
+	CCreatureSet *m_army2; 
+	int3 m_tile; 
+	CGHeroInstance *m_hero1;
+	CGHeroInstance *m_hero2; 
+	bool m_side;
+
+	void MakeStatistics(int currentCreatureId); // before decision we have to make some calculation and simulation
+	// statistics
+	typedef std::vector<std::pair<int, int> > creature_stat; // first - creature id, second - value
+	creature_stat m_statMaxDamage;
+	creature_stat m_statMinDamage;
+	//
+	creature_stat m_statMaxSpeed;
+	creature_stat m_statDistance;
+	creature_stat m_statDistanceFromShooters;
+	creature_stat m_statHitPoints;
+
+	typedef std::vector<std::pair<int, SCreatureCasualties> > creature_stat_casualties;
+	creature_stat_casualties m_statCasualties;
+
+	bool m_bEnemyDominates;
+
+	std::vector<int> GetAvailableHexesForAttacker(CStack *defender, CStack *attacker = NULL);
+
+	BattleAction MakeDefend(int stackID);
+
+	int PerformBerserkAttack(int stackID); // return ID of creature to attack, -2 means wait, -1 - defend
+	int PerformDefaultAction(int stackID);
+
+	void CBattleLogic::PrintBattleAction(const BattleAction &action);
+};
+
+class CGeniusAI : public CGlobalAI
+{
+private:
+	ICallback *m_cb;
+	CBattleLogic *m_battleLogic;
+public:
+	virtual void init(ICallback * CB);
+	virtual void yourTurn();
+	virtual void heroKilled(const CGHeroInstance *);
+	virtual void heroCreated(const CGHeroInstance *);
+	virtual void heroMoved(const HeroMoveDetails &);
+	virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) {};
+	virtual void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID){};
+	virtual void tileRevealed(int3 pos){};
+	virtual void tileHidden(int3 pos){};
+	virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
+	// battle
+	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 void battleAttack(BattleAttack *ba); //called when stack is performing attack
+	virtual void battleStackAttacked(BattleStackAttacked * 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);
+	virtual void battleSpellCasted(SpellCasted *sc);
+	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<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
+	//
+	virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving);
+	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);
+};
+
+}
+
+#endif // __CGENIUSAI_H__

+ 14 - 14
AI_Base.h

@@ -1,14 +1,14 @@
-#ifndef AIBASE_H
-#define AIBASE_H
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-#include <vector>
-#include <iostream>
-#include "CGameInterface.h"
-
-#define AI_INTERFACE_VER 1
-
-#endif //AIBASE_H
+#ifndef __AI_BASE_H__
+#define __AI_BASE_H__
+#ifndef __AI_BASE_H__
+#define __AI_BASE_H__
+
+
+#include <vector>
+#include <iostream>
+#include "CGameInterface.h"
+
+#define AI_INTERFACE_VER 1
+
+#endif // __AI_BASE_H__
+#endif // __AI_BASE_H__

+ 98 - 101
AdventureMapButton.h

@@ -1,101 +1,98 @@
-#ifndef ADVENTUREMAPBUTTON_H
-#define ADVENTUREMAPBUTTON_H
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-
-#include "CPlayerInterface.h"
-#include "client/FunctionList.h"
-#include <boost/bind.hpp>
-
-namespace config{struct ButtonInfo;}
-
-class AdventureMapButton 
-	: public ClickableR, public Hoverable, public KeyShortcut, public CButtonBase
-{
-public:
-	std::map<int,std::string> hoverTexts; //state -> text for statusbar
-	std::string helpBox; //for right-click help
-	CFunctionList<void()> callback;
-	bool colorChange, blocked,
-		actOnDown; //runs when mouse is pressed down over it, not when up
-
-	void clickRight (tribool down);
-	virtual void clickLeft (tribool down);
-	void hover (bool on);
-	void block(bool 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<int,std::string> &, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key=0, std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
-	AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key=0, std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
-	AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, config::ButtonInfo *info, int key=0);//c-tor
-	//AdventureMapButton( std::string Name, std::string HelpBox, boost::function<void()> Callback, int x, int y, std::string defName, bool activ=false,  std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
-
-	void init(const CFunctionList<void()> &Callback, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key );
-};
-
-class CHighlightableButton 
-	: public AdventureMapButton
-{
-public:
-	CHighlightableButton(const CFunctionList<void()> &onSelect, const CFunctionList<void()> &onDeselect, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key=0 );
-	bool selected, onlyOn;
-	CFunctionList<void()> callback2; //when disselecting
-	void select(bool on);
-	void clickLeft (tribool down);
-};
-
-class CHighlightableButtonsGroup
-{
-public:
-	CFunctionList2<void(int)> onChange; //called when changing selected button with new button's id
-	std::vector<CHighlightableButton*> buttons;
-
-	//void addButton(const std::map<int,std::string> &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<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect=0, int key=0); //creates new button
-	CHighlightableButtonsGroup(const CFunctionList2<void(int)> &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 = NULL);
-};
-
-
-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<void(int)> 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 = NULL);
-	CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount, 
-		int Value=0, bool Horizontal=true);
-	~CSlider();
-};	
-#endif //ADVENTUREMAPBUTTON_H
+#ifndef ADVENTUREMAPBUTTON_H
+#define ADVENTUREMAPBUTTON_H
+
+
+
+#include "CPlayerInterface.h"
+#include "client/FunctionList.h"
+#include <boost/bind.hpp>
+
+namespace config{struct ButtonInfo;}
+
+class AdventureMapButton 
+	: public ClickableR, public Hoverable, public KeyShortcut, public CButtonBase
+{
+public:
+	std::map<int,std::string> hoverTexts; //state -> text for statusbar
+	std::string helpBox; //for right-click help
+	CFunctionList<void()> callback;
+	bool colorChange, blocked,
+		actOnDown; //runs when mouse is pressed down over it, not when up
+
+	void clickRight (tribool down);
+	virtual void clickLeft (tribool down);
+	void hover (bool on);
+	void block(bool 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<int,std::string> &, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key=0, std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
+	AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key=0, std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
+	AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, config::ButtonInfo *info, int key=0);//c-tor
+	//AdventureMapButton( std::string Name, std::string HelpBox, boost::function<void()> Callback, int x, int y, std::string defName, bool activ=false,  std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
+
+	void init(const CFunctionList<void()> &Callback, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key );
+};
+
+class CHighlightableButton 
+	: public AdventureMapButton
+{
+public:
+	CHighlightableButton(const CFunctionList<void()> &onSelect, const CFunctionList<void()> &onDeselect, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key=0 );
+	bool selected, onlyOn;
+	CFunctionList<void()> callback2; //when disselecting
+	void select(bool on);
+	void clickLeft (tribool down);
+};
+
+class CHighlightableButtonsGroup
+{
+public:
+	CFunctionList2<void(int)> onChange; //called when changing selected button with new button's id
+	std::vector<CHighlightableButton*> buttons;
+
+	//void addButton(const std::map<int,std::string> &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<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect=0, int key=0); //creates new button
+	CHighlightableButtonsGroup(const CFunctionList2<void(int)> &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 = NULL);
+};
+
+
+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<void(int)> 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 = NULL);
+	CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount, 
+		int Value=0, bool Horizontal=true);
+	~CSlider();
+};	
+#endif //ADVENTUREMAPBUTTON_H

+ 177 - 177
CAdvmapInterface.h

@@ -1,177 +1,177 @@
-#ifndef CADVENTUREMAPINTERFACE_H
-#define CADVENTUREMAPINTERFACE_H
-#include <typeinfo>
-#include "global.h"
-#include "SDL.h"
-#include "CPlayerInterface.h"
-#include <map>
-#include "AdventureMapButton.h"
-class CDefHandler;
-class CCallback;
-struct CPath;
-class CAdvMapInt;
-class CGHeroInstance;
-class CGTownInstance;
-class CHeroWindow;
-/*****************************/
-class CMinimap
-	: public ClickableL, public ClickableR, public Hoverable, public MotionInterested, public virtual CIntObject
-{
-public:
-	SDL_Surface * radar;
-	SDL_Surface * temps;
-	std::map<int,SDL_Color> colors;
-	std::map<int,SDL_Color> colorsBlocked;
-	std::vector<SDL_Surface *> map, FoW; //one bitmap for each level (terrain, Fog of War)
-	//TODO flagged buildings
-	std::string statusbarTxt, rcText;
-
-	CMinimap(bool draw=true);
-	void draw();
-	void redraw(int level=-1);// (level==-1) => redraw all levels
-	void updateRadar();
-
-	void clickRight (tribool down);
-	void clickLeft (tribool down);
-	void hover (bool on);
-	void mouseMoved (const SDL_MouseMotionEvent & sEvent);
-	void activate(); // makes button active
-	void deactivate(); // makes button inactive (but don't deletes)
-	void hideTile(const int3 &pos); //puts FoW
-	void showTile(const int3 &pos); //removes FoW
-};
-class CTerrainRect
-	:  public ClickableL, public ClickableR, public Hoverable, public MotionInterested
-{
-public:
-	int tilesw, tilesh; //width and height of terrain to blit in tiles
-	int3 curHoveredTile;
-	int moveX, moveY; //shift between actual position of screen and the one we wil blit; ranges from -31 to 31 (in pixels)
-
-	CDefHandler * arrows;
-	CTerrainRect();
-	CPath * currentPath;
-	void activate();
-	void deactivate();
-	void clickLeft(tribool down);
-	void clickRight(tribool down);
-	void hover(bool on);
-	void mouseMoved (const SDL_MouseMotionEvent & sEvent);
-	void show();
-	void showPath();
-	int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position
-	int3 whichTileIsIt(); //uses current cursor pos
-};
-class CResDataBar
-	:public ClickableR, public virtual CIntObject
-{
-public:
-	SDL_Surface * bg;
-	std::vector<std::pair<int,int> > txtpos;
-	std::string datetext;
-
-	void clickRight (tribool down);
-	void activate();
-	void deactivate();
-	CResDataBar();
-	CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist);
-	~CResDataBar();
-
-	void draw();
-};
-class CInfoBar
-	:public virtual CIntObject, public TimeInterested
-{
-public:
-	CDefHandler *day, *week1, *week2, *week3, *week4;
-	SComponent * current;
-	int mode;
-	int pom;
-
-	CInfoBar();
-	~CInfoBar();
-	void newDay(int Day);
-	void showComp(SComponent * comp, int time=5000);
-	void tick();
-	void draw(const CGObjectInstance * specific=NULL); // if specific==0 function draws info about selected hero/town
-	void blitAnim(int mode);//0 - day, 1 - week
-	CDefHandler * getAnim(int mode);
-};
-/*****************************/
-class CAdvMapInt : public CMainInterface, public KeyInterested //adventure map interface
-{
-public:
-	CAdvMapInt(int Player);
-	~CAdvMapInt();
-
-	int3 position; //top left corner of visible map part
-	int player;
-
-	std::vector<CDefHandler *> gems;
-
-	bool scrollingLeft ;
-	bool scrollingRight ;
-	bool scrollingUp ;
-	bool scrollingDown ;
-	bool updateScreen, updateMinimap ;
-	unsigned char anim, animValHitCount; //animation frame
-	unsigned char heroAnim, heroAnimValHitCount; //animation frame
-
-	CMinimap minimap;
-
-
-	SDL_Surface * bg;
-	AdventureMapButton kingOverview,//- kingdom overview
-		underground,//- underground switch
-		questlog,//- questlog
-		sleepWake, //- sleep/wake hero
-		moveHero, //- move hero
-		spellbook,//- spellbook
-		advOptions, //- adventure options
-		sysOptions,//- system options
-		nextHero, //- next hero
-		endTurn;//- end turn
-	//CHeroList herolist;
-
-	CTerrainRect terrain; //visible terrain
-
-	CStatusBar statusbar;
-	CResDataBar resdatabar;
-
-	CHeroList heroList;
-	CTownList townList;
-	CInfoBar infoBar;
-
-	CHeroWindow * heroWindow;
-
-	const CArmedInstance *selection;
-
-	//fuctions binded to buttons
-	void fshowOverview();
-	void fswitchLevel();
-	void fshowQuestlog();
-	void fsleepWake();
-	void fmoveHero();
-	void fshowSpellbok();
-	void fadventureOPtions();
-	void fsystemOptions();
-	void fnextHero();
-	void fendTurn();
-
-	void activate();
-	void deactivate();
-
-	void show(SDL_Surface * to=NULL); //shows and activates adv. map interface
-	void hide(); //deactivates advmap interface
-	void update(); //redraws terrain
-
-	void select(const CArmedInstance *sel);
-	void selectionChanged();
-	void centerOn(int3 on);
-	int3 verifyPos(int3 ver);
-	void handleRightClick(std::string text, tribool down, CIntObject * client);
-	void keyPressed(const SDL_KeyboardEvent & key);
-
-
-};
-#endif //CADVENTUREMAPINTERFACE_H
+#ifndef __CADVMAPINTERFACE_H__
+#define __CADVMAPINTERFACE_H__
+#include <typeinfo>
+#include "global.h"
+#include "SDL.h"
+#include "CPlayerInterface.h"
+#include <map>
+#include "AdventureMapButton.h"
+class CDefHandler;
+class CCallback;
+struct CPath;
+class CAdvMapInt;
+class CGHeroInstance;
+class CGTownInstance;
+class CHeroWindow;
+/*****************************/
+class CMinimap
+	: public ClickableL, public ClickableR, public Hoverable, public MotionInterested, public virtual CIntObject
+{
+public:
+	SDL_Surface * radar;
+	SDL_Surface * temps;
+	std::map<int,SDL_Color> colors;
+	std::map<int,SDL_Color> colorsBlocked;
+	std::vector<SDL_Surface *> map, FoW; //one bitmap for each level (terrain, Fog of War)
+	//TODO flagged buildings
+	std::string statusbarTxt, rcText;
+
+	CMinimap(bool draw=true);
+	void draw();
+	void redraw(int level=-1);// (level==-1) => redraw all levels
+	void updateRadar();
+
+	void clickRight (tribool down);
+	void clickLeft (tribool down);
+	void hover (bool on);
+	void mouseMoved (const SDL_MouseMotionEvent & sEvent);
+	void activate(); // makes button active
+	void deactivate(); // makes button inactive (but don't deletes)
+	void hideTile(const int3 &pos); //puts FoW
+	void showTile(const int3 &pos); //removes FoW
+};
+class CTerrainRect
+	:  public ClickableL, public ClickableR, public Hoverable, public MotionInterested
+{
+public:
+	int tilesw, tilesh; //width and height of terrain to blit in tiles
+	int3 curHoveredTile;
+	int moveX, moveY; //shift between actual position of screen and the one we wil blit; ranges from -31 to 31 (in pixels)
+
+	CDefHandler * arrows;
+	CTerrainRect();
+	CPath * currentPath;
+	void activate();
+	void deactivate();
+	void clickLeft(tribool down);
+	void clickRight(tribool down);
+	void hover(bool on);
+	void mouseMoved (const SDL_MouseMotionEvent & sEvent);
+	void show();
+	void showPath();
+	int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position
+	int3 whichTileIsIt(); //uses current cursor pos
+};
+class CResDataBar
+	:public ClickableR, public virtual CIntObject
+{
+public:
+	SDL_Surface * bg;
+	std::vector<std::pair<int,int> > txtpos;
+	std::string datetext;
+
+	void clickRight (tribool down);
+	void activate();
+	void deactivate();
+	CResDataBar();
+	CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist);
+	~CResDataBar();
+
+	void draw();
+};
+class CInfoBar
+	:public virtual CIntObject, public TimeInterested
+{
+public:
+	CDefHandler *day, *week1, *week2, *week3, *week4;
+	SComponent * current;
+	int mode;
+	int pom;
+
+	CInfoBar();
+	~CInfoBar();
+	void newDay(int Day);
+	void showComp(SComponent * comp, int time=5000);
+	void tick();
+	void draw(const CGObjectInstance * specific=NULL); // if specific==0 function draws info about selected hero/town
+	void blitAnim(int mode);//0 - day, 1 - week
+	CDefHandler * getAnim(int mode);
+};
+/*****************************/
+class CAdvMapInt : public CMainInterface, public KeyInterested //adventure map interface
+{
+public:
+	CAdvMapInt(int Player);
+	~CAdvMapInt();
+
+	int3 position; //top left corner of visible map part
+	int player;
+
+	std::vector<CDefHandler *> gems;
+
+	bool scrollingLeft ;
+	bool scrollingRight ;
+	bool scrollingUp ;
+	bool scrollingDown ;
+	bool updateScreen, updateMinimap ;
+	unsigned char anim, animValHitCount; //animation frame
+	unsigned char heroAnim, heroAnimValHitCount; //animation frame
+
+	CMinimap minimap;
+
+
+	SDL_Surface * bg;
+	AdventureMapButton kingOverview,//- kingdom overview
+		underground,//- underground switch
+		questlog,//- questlog
+		sleepWake, //- sleep/wake hero
+		moveHero, //- move hero
+		spellbook,//- spellbook
+		advOptions, //- adventure options
+		sysOptions,//- system options
+		nextHero, //- next hero
+		endTurn;//- end turn
+	//CHeroList herolist;
+
+	CTerrainRect terrain; //visible terrain
+
+	CStatusBar statusbar;
+	CResDataBar resdatabar;
+
+	CHeroList heroList;
+	CTownList townList;
+	CInfoBar infoBar;
+
+	CHeroWindow * heroWindow;
+
+	const CArmedInstance *selection;
+
+	//fuctions binded to buttons
+	void fshowOverview();
+	void fswitchLevel();
+	void fshowQuestlog();
+	void fsleepWake();
+	void fmoveHero();
+	void fshowSpellbok();
+	void fadventureOPtions();
+	void fsystemOptions();
+	void fnextHero();
+	void fendTurn();
+
+	void activate();
+	void deactivate();
+
+	void show(SDL_Surface * to=NULL); //shows and activates adv. map interface
+	void hide(); //deactivates advmap interface
+	void update(); //redraws terrain
+
+	void select(const CArmedInstance *sel);
+	void selectionChanged();
+	void centerOn(int3 on);
+	int3 verifyPos(int3 ver);
+	void handleRightClick(std::string text, tribool down, CIntObject * client);
+	void keyPressed(const SDL_KeyboardEvent & key);
+
+
+};
+#endif // __CADVMAPINTERFACE_H__

+ 257 - 260
CBattleInterface.h

@@ -1,261 +1,258 @@
-#ifndef CBATTLEINTERFACE_H
-#define CBATTLEINTERFACE_H
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-
-#include "global.h"
-#include "CPlayerInterface.h"
-#include <list>
-
-class CCreatureSet;
-class CGHeroInstance;
-class CDefHandler;
-class CStack;
-class CCallback;
-class AdventureMapButton;
-class CHighlightableButton;
-class CHighlightableButtonsGroup;
-struct BattleResult;
-struct SpellCasted;
-template <typename T> struct CondSh;
-
-class CBattleInterface;
-
-class CBattleHero : public IShowable, public ClickableL
-{
-public:
-	bool flip; //false if it's attacking hero, true otherwise
-	CDefHandler * dh, *flag; //animation and flag
-	const CGHeroInstance * myHero; //this animation's hero instance
-	const CBattleInterface * myOwner; //battle interface to which this animation is assigned
-	int phase; //stage of animation
-	int image; //frame of animation
-	unsigned char flagAnim, flagAnimCount; //for flag animation
-	void show(SDL_Surface * to); //prints next frame of animation to to
-	void activate();
-	void deactivate();
-	void setPhase(int newPhase);
-	void clickLeft(boost::logic::tribool down);
-	CBattleHero(const std::string & defName, int phaseG, int imageG, bool filpG, unsigned char player, const CGHeroInstance * hero, const CBattleInterface * owner); //c-tor
-	~CBattleHero(); //d-tor
-};
-
-class CBattleHex : public Hoverable, public MotionInterested, public ClickableL, public ClickableR
-{
-private:
-	bool setAlterText; //if true, this hex has set alternative text in console and will clean it
-public:
-	unsigned int myNumber;
-	bool accesible;
-	//CStack * ourStack;
-	bool hovered, strictHovered;
-	CBattleInterface * myInterface; //interface that owns me
-	static std::pair<int, int> getXYUnitAnim(const int & hexNum, const bool & attacker, const CCreature * creature); //returns (x, y) of left top corner of animation
-	//for user interactions
-	void hover (bool on);
-	void activate();
-	void deactivate();
-	void mouseMoved (const SDL_MouseMotionEvent & sEvent);
-	void clickLeft(boost::logic::tribool down);
-	void clickRight(boost::logic::tribool down);
-	CBattleHex();
-};
-
-class CBattleObstacle
-{
-	std::vector<int> lockedHexes;
-};
-
-class CBattleConsole : public IShowable, public CIntObject
-{
-private:
-	std::vector< std::string > texts; //a place where texts are stored
-	int lastShown; //last shown line of text
-public:
-	std::string alterTxt; //if it's not empty, this text is displayed
-	CBattleConsole(); //c-tor
-	~CBattleConsole(); //d-tor
-	void show(SDL_Surface * to = 0);
-	bool addText(const std::string & text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters)
-	void eraseText(unsigned int pos); //erases added text at position pos
-	void changeTextAt(const std::string & text, unsigned int pos); //if we have more than pos texts, pos-th is changed to given one
-	void scrollUp(unsigned int by = 1); //scrolls console up by 'by' positions
-	void scrollDown(unsigned int by = 1); //scrolls console up by 'by' positions
-};
-
-class CBattleReslutWindow : public IShowable, public CIntObject, public IActivable
-{
-private:
-	SDL_Surface * background;
-	AdventureMapButton * exit;
-public:
-	CBattleReslutWindow(const BattleResult & br, const SDL_Rect & pos, const CBattleInterface * owner); //c-tor
-	~CBattleReslutWindow(); //d-tor
-
-	void bExitf();
-
-	void activate();
-	void deactivate();
-	void show(SDL_Surface * to = 0);
-};
-
-class CBattleOptionsWindow : public IShowable, public CIntObject, public IActivable
-{
-private:
-	CBattleInterface * myInt;
-	SDL_Surface * background;
-	AdventureMapButton * setToDefault, * exit;
-	CHighlightableButton * viewGrid, * movementShadow, * mouseShadow;
-	CHighlightableButtonsGroup * animSpeeds;
-public:
-	CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface * owner); //c-tor
-	~CBattleOptionsWindow(); //d-tor
-
-	void bDefaultf();
-	void bExitf();
-
-	void activate();
-	void deactivate();
-	void show(SDL_Surface * to = 0);
-};
-
-class CBattleInterface : public CMainInterface, public MotionInterested, public KeyInterested
-{
-private:
-	SDL_Surface * background, * menu, * amountNormal, * amountNegative, * amountPositive, * amountEffNeutral, * cellBorders, * backgroundWithHexes;
-	AdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
-		* bWait, * bDefence, * bConsoleUp, * bConsoleDown;
-	CBattleConsole * console;
-	CBattleHero * attackingHero, * defendingHero;
-	CCreatureSet * army1, * army2; //fighting armies
-	CGHeroInstance * attackingHeroInstance, * defendingHeroInstance;
-	std::map< int, CCreatureAnimation * > creAnims; //animations of creatures from fighting armies (order by BattleInfo's stacks' ID)
-	std::map< int, CDefHandler * > idToProjectile; //projectiles of creaures (creatureID, defhandler)
-	std::map< int, bool > creDir; // <creatureID, if false reverse creature's animation>
-	unsigned char animCount;
-	int activeStack; //number of active stack; -1 - no one
-	std::vector<int> shadedHexes; //hexes available for active stack
-	int previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago
-	int currentlyHoveredHex; //number of hex that is supposed to be hovered (for a while it may be inappropriately set, but will be renewed soon)
-	int animSpeed; //speed of animation; 1 - slowest, 2 - medium, 4 - fastest
-	float getAnimSpeedMultiplier() const; //returns multiplier for number of frames in a group
-
-	bool spellDestSelectMode; //if true, player is choosing destination for his spell
-	int spellSelMode; //0 - any location, 1 - any firendly creature, 2 - any hostile creature, 3 - any creature, 4 - obstacle, -1 - no location
-	BattleAction * spellToCast; //spell for which player is choosing destination
-
-	class CAttHelper
-	{
-	public:
-		int ID; //attacking stack
-		int IDby; //attacked stack
-		int dest; //atacked hex
-		int frame, maxframe; //frame of animation, number of frames of animation
-		int hitCount; //for delaying animation
-		bool reversing;
-		int posShiftDueToDist;
-		bool shooting;
-		int shootingGroup; //if shooting is true, print this animation group
-	} * attackingInfo;
-	void attackingShowHelper();
-	void redrawBackgroundWithHexes(int activeStack);
-	void printConsoleAttacked(int ID, int dmg, int killed, int IDby);
-
-	struct SProjectileInfo
-	{
-		int x, y; //position on the screen
-		int dx, dy; //change in position in one step
-		int step, lastStep; //to know when finish showing this projectile
-		int creID; //ID of creature that shot this projectile
-		int frameNum; //frame to display form projectile animation
-		bool spin; //if true, frameNum will be increased
-		int animStartDelay; //how many times projectile must be attempted to be shown till it's really show (decremented after hit)
-	};
-	std::list<SProjectileInfo> projectiles;
-	void projectileShowHelper(SDL_Surface * to=NULL); //prints projectiles present on the battlefield
-	void giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional=-1);
-	bool isTileAttackable(const int & number) const; //returns true if tile 'number' is neighbouring any tile from active stack's range or is one of these tiles
-
-	struct SBattleEffect
-	{
-		int x, y; //position on the screen
-		int frame, maxFrame;
-		CDefHandler * anim; //animation to display
-	};
-	std::list<SBattleEffect> battleEffects; //different animations to display on the screen like spell effects
-public:
-	CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect); //c-tor
-	~CBattleInterface(); //d-tor
-
-	//std::vector<TimeInterested*> timeinterested; //animation handling
-	bool printCellBorders; //if true, cell borders will be printed
-	void setPrintCellBorders(bool set); //set for above member
-	bool printStackRange; //if true,range of active stack will be printed
-	void setPrintStackRange(bool set); //set for above member
-	bool printMouseShadow; //if true, hex under mouse will be shaded
-	void setPrintMouseShadow(bool set); //set for above member
-	void setAnimSpeed(int set); //set for animSpeed
-	int getAnimSpeed() const; //get for animSpeed
-
-	CBattleHex bfield[BFIELD_SIZE]; //11 lines, 17 hexes on each
-	std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield
-	SDL_Surface * cellBorder, * cellShade;
-	CondSh<BattleAction *> *givenCommand; //data != NULL if we have i.e. moved current unit
-	bool myTurn; //if true, interface is active (commands can be ordered
-	CBattleReslutWindow * resWindow; //window of end of battle
-	bool showStackQueue; //if true, queue of stacks will be shown
-
-	//button handle funcs:
-	void bOptionsf();
-	void bSurrenderf();
-	void bFleef();
-	void reallyFlee(); //performs fleeing without asking player
-	void bAutofightf();
-	void bSpellf();
-	void bWaitf();
-	void bDefencef();
-	void bConsoleUpf();
-	void bConsoleDownf();
-	//end of button handle funcs
-	//napisz tu klase odpowiadajaca za wyswietlanie bitwy i obsluge uzytkownika, polecenia ma przekazywac callbackiem
-	void activate();
-	void deactivate();
-	void show(SDL_Surface * to = NULL);
-	void keyPressed(const SDL_KeyboardEvent & key);
-	void mouseMoved(const SDL_MouseMotionEvent &sEvent);
-	bool reverseCreature(int number, int hex, bool wideTrick = false); //reverses animation of given creature playing animation of reversing
-
-	struct SStackAttackedInfo
-	{
-		int ID; //id of attacked stack
-		int dmg; //damage dealt
-		int amountKilled; //how many creatures in stack has been killed
-		int IDby; //ID of attacking stack
-		bool byShooting; //if true, stack has been attacked by shooting
-		bool killed; //if true, stack has been killed
-	};
-
-	//call-ins
-	void newStack(CStack stack); //new stack appeared on battlefield
-	void stackRemoved(CStack stack); //stack disappeared from batlefiled
-	//void stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting); //stack has been killed (but corpses remain)
-	void stackActivated(int number); //active stack has been changed
-	void stackMoved(int number, int destHex, bool endMoving); //stack with id number moved to destHex
-	void stacksAreAttacked(std::vector<SStackAttackedInfo> attackedInfos); //called when a certain amount of stacks has been attacked
-	void stackAttacking(int ID, int dest); //called when stack with id ID is attacking something on hex dest
-	void newRound(int number); //caled when round is ended; number is the number of round
-	void hexLclicked(int whichOne); //hex only call-in
-	void stackIsShooting(int ID, int dest); //called when stack with id ID is shooting to hex dest
-	void battleFinished(const BattleResult& br); //called when battle is finished - battleresult window should be printed
-	void spellCasted(SpellCasted * sc); //called when a hero casts a spell
-	void castThisSpell(int spellID); //called when player has chosen a spell from spellbook
-	void displayEffect(ui32 effect, int destTile); //displays effect of a spell on the battlefield; affected: true - attacker. false - defender
-
-	friend class CBattleHex;
-	friend class CBattleReslutWindow;
-	friend class CPlayerInterface;
-};
+#ifndef CBATTLEINTERFACE_H
+#define CBATTLEINTERFACE_H
+
+
+
+#include "global.h"
+#include "CPlayerInterface.h"
+#include <list>
+
+class CCreatureSet;
+class CGHeroInstance;
+class CDefHandler;
+class CStack;
+class CCallback;
+class AdventureMapButton;
+class CHighlightableButton;
+class CHighlightableButtonsGroup;
+struct BattleResult;
+struct SpellCasted;
+template <typename T> struct CondSh;
+
+class CBattleInterface;
+
+class CBattleHero : public IShowable, public ClickableL
+{
+public:
+	bool flip; //false if it's attacking hero, true otherwise
+	CDefHandler * dh, *flag; //animation and flag
+	const CGHeroInstance * myHero; //this animation's hero instance
+	const CBattleInterface * myOwner; //battle interface to which this animation is assigned
+	int phase; //stage of animation
+	int image; //frame of animation
+	unsigned char flagAnim, flagAnimCount; //for flag animation
+	void show(SDL_Surface * to); //prints next frame of animation to to
+	void activate();
+	void deactivate();
+	void setPhase(int newPhase);
+	void clickLeft(boost::logic::tribool down);
+	CBattleHero(const std::string & defName, int phaseG, int imageG, bool filpG, unsigned char player, const CGHeroInstance * hero, const CBattleInterface * owner); //c-tor
+	~CBattleHero(); //d-tor
+};
+
+class CBattleHex : public Hoverable, public MotionInterested, public ClickableL, public ClickableR
+{
+private:
+	bool setAlterText; //if true, this hex has set alternative text in console and will clean it
+public:
+	unsigned int myNumber;
+	bool accesible;
+	//CStack * ourStack;
+	bool hovered, strictHovered;
+	CBattleInterface * myInterface; //interface that owns me
+	static std::pair<int, int> getXYUnitAnim(const int & hexNum, const bool & attacker, const CCreature * creature); //returns (x, y) of left top corner of animation
+	//for user interactions
+	void hover (bool on);
+	void activate();
+	void deactivate();
+	void mouseMoved (const SDL_MouseMotionEvent & sEvent);
+	void clickLeft(boost::logic::tribool down);
+	void clickRight(boost::logic::tribool down);
+	CBattleHex();
+};
+
+class CBattleObstacle
+{
+	std::vector<int> lockedHexes;
+};
+
+class CBattleConsole : public IShowable, public CIntObject
+{
+private:
+	std::vector< std::string > texts; //a place where texts are stored
+	int lastShown; //last shown line of text
+public:
+	std::string alterTxt; //if it's not empty, this text is displayed
+	CBattleConsole(); //c-tor
+	~CBattleConsole(); //d-tor
+	void show(SDL_Surface * to = 0);
+	bool addText(const std::string & text); //adds text at the last position; returns false if failed (e.g. text longer than 70 characters)
+	void eraseText(unsigned int pos); //erases added text at position pos
+	void changeTextAt(const std::string & text, unsigned int pos); //if we have more than pos texts, pos-th is changed to given one
+	void scrollUp(unsigned int by = 1); //scrolls console up by 'by' positions
+	void scrollDown(unsigned int by = 1); //scrolls console up by 'by' positions
+};
+
+class CBattleReslutWindow : public IShowable, public CIntObject, public IActivable
+{
+private:
+	SDL_Surface * background;
+	AdventureMapButton * exit;
+public:
+	CBattleReslutWindow(const BattleResult & br, const SDL_Rect & pos, const CBattleInterface * owner); //c-tor
+	~CBattleReslutWindow(); //d-tor
+
+	void bExitf();
+
+	void activate();
+	void deactivate();
+	void show(SDL_Surface * to = 0);
+};
+
+class CBattleOptionsWindow : public IShowable, public CIntObject, public IActivable
+{
+private:
+	CBattleInterface * myInt;
+	SDL_Surface * background;
+	AdventureMapButton * setToDefault, * exit;
+	CHighlightableButton * viewGrid, * movementShadow, * mouseShadow;
+	CHighlightableButtonsGroup * animSpeeds;
+public:
+	CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface * owner); //c-tor
+	~CBattleOptionsWindow(); //d-tor
+
+	void bDefaultf();
+	void bExitf();
+
+	void activate();
+	void deactivate();
+	void show(SDL_Surface * to = 0);
+};
+
+class CBattleInterface : public CMainInterface, public MotionInterested, public KeyInterested
+{
+private:
+	SDL_Surface * background, * menu, * amountNormal, * amountNegative, * amountPositive, * amountEffNeutral, * cellBorders, * backgroundWithHexes;
+	AdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
+		* bWait, * bDefence, * bConsoleUp, * bConsoleDown;
+	CBattleConsole * console;
+	CBattleHero * attackingHero, * defendingHero;
+	CCreatureSet * army1, * army2; //fighting armies
+	CGHeroInstance * attackingHeroInstance, * defendingHeroInstance;
+	std::map< int, CCreatureAnimation * > creAnims; //animations of creatures from fighting armies (order by BattleInfo's stacks' ID)
+	std::map< int, CDefHandler * > idToProjectile; //projectiles of creaures (creatureID, defhandler)
+	std::map< int, bool > creDir; // <creatureID, if false reverse creature's animation>
+	unsigned char animCount;
+	int activeStack; //number of active stack; -1 - no one
+	std::vector<int> shadedHexes; //hexes available for active stack
+	int previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago
+	int currentlyHoveredHex; //number of hex that is supposed to be hovered (for a while it may be inappropriately set, but will be renewed soon)
+	int animSpeed; //speed of animation; 1 - slowest, 2 - medium, 4 - fastest
+	float getAnimSpeedMultiplier() const; //returns multiplier for number of frames in a group
+
+	bool spellDestSelectMode; //if true, player is choosing destination for his spell
+	int spellSelMode; //0 - any location, 1 - any firendly creature, 2 - any hostile creature, 3 - any creature, 4 - obstacle, -1 - no location
+	BattleAction * spellToCast; //spell for which player is choosing destination
+
+	class CAttHelper
+	{
+	public:
+		int ID; //attacking stack
+		int IDby; //attacked stack
+		int dest; //atacked hex
+		int frame, maxframe; //frame of animation, number of frames of animation
+		int hitCount; //for delaying animation
+		bool reversing;
+		int posShiftDueToDist;
+		bool shooting;
+		int shootingGroup; //if shooting is true, print this animation group
+	} * attackingInfo;
+	void attackingShowHelper();
+	void redrawBackgroundWithHexes(int activeStack);
+	void printConsoleAttacked(int ID, int dmg, int killed, int IDby);
+
+	struct SProjectileInfo
+	{
+		int x, y; //position on the screen
+		int dx, dy; //change in position in one step
+		int step, lastStep; //to know when finish showing this projectile
+		int creID; //ID of creature that shot this projectile
+		int frameNum; //frame to display form projectile animation
+		bool spin; //if true, frameNum will be increased
+		int animStartDelay; //how many times projectile must be attempted to be shown till it's really show (decremented after hit)
+	};
+	std::list<SProjectileInfo> projectiles;
+	void projectileShowHelper(SDL_Surface * to=NULL); //prints projectiles present on the battlefield
+	void giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional=-1);
+	bool isTileAttackable(const int & number) const; //returns true if tile 'number' is neighbouring any tile from active stack's range or is one of these tiles
+
+	struct SBattleEffect
+	{
+		int x, y; //position on the screen
+		int frame, maxFrame;
+		CDefHandler * anim; //animation to display
+	};
+	std::list<SBattleEffect> battleEffects; //different animations to display on the screen like spell effects
+public:
+	CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect); //c-tor
+	~CBattleInterface(); //d-tor
+
+	//std::vector<TimeInterested*> timeinterested; //animation handling
+	bool printCellBorders; //if true, cell borders will be printed
+	void setPrintCellBorders(bool set); //set for above member
+	bool printStackRange; //if true,range of active stack will be printed
+	void setPrintStackRange(bool set); //set for above member
+	bool printMouseShadow; //if true, hex under mouse will be shaded
+	void setPrintMouseShadow(bool set); //set for above member
+	void setAnimSpeed(int set); //set for animSpeed
+	int getAnimSpeed() const; //get for animSpeed
+
+	CBattleHex bfield[BFIELD_SIZE]; //11 lines, 17 hexes on each
+	std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield
+	SDL_Surface * cellBorder, * cellShade;
+	CondSh<BattleAction *> *givenCommand; //data != NULL if we have i.e. moved current unit
+	bool myTurn; //if true, interface is active (commands can be ordered
+	CBattleReslutWindow * resWindow; //window of end of battle
+	bool showStackQueue; //if true, queue of stacks will be shown
+
+	//button handle funcs:
+	void bOptionsf();
+	void bSurrenderf();
+	void bFleef();
+	void reallyFlee(); //performs fleeing without asking player
+	void bAutofightf();
+	void bSpellf();
+	void bWaitf();
+	void bDefencef();
+	void bConsoleUpf();
+	void bConsoleDownf();
+	//end of button handle funcs
+	//napisz tu klase odpowiadajaca za wyswietlanie bitwy i obsluge uzytkownika, polecenia ma przekazywac callbackiem
+	void activate();
+	void deactivate();
+	void show(SDL_Surface * to = NULL);
+	void keyPressed(const SDL_KeyboardEvent & key);
+	void mouseMoved(const SDL_MouseMotionEvent &sEvent);
+	bool reverseCreature(int number, int hex, bool wideTrick = false); //reverses animation of given creature playing animation of reversing
+
+	struct SStackAttackedInfo
+	{
+		int ID; //id of attacked stack
+		int dmg; //damage dealt
+		int amountKilled; //how many creatures in stack has been killed
+		int IDby; //ID of attacking stack
+		bool byShooting; //if true, stack has been attacked by shooting
+		bool killed; //if true, stack has been killed
+	};
+
+	//call-ins
+	void newStack(CStack stack); //new stack appeared on battlefield
+	void stackRemoved(CStack stack); //stack disappeared from batlefiled
+	//void stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting); //stack has been killed (but corpses remain)
+	void stackActivated(int number); //active stack has been changed
+	void stackMoved(int number, int destHex, bool endMoving); //stack with id number moved to destHex
+	void stacksAreAttacked(std::vector<SStackAttackedInfo> attackedInfos); //called when a certain amount of stacks has been attacked
+	void stackAttacking(int ID, int dest); //called when stack with id ID is attacking something on hex dest
+	void newRound(int number); //caled when round is ended; number is the number of round
+	void hexLclicked(int whichOne); //hex only call-in
+	void stackIsShooting(int ID, int dest); //called when stack with id ID is shooting to hex dest
+	void battleFinished(const BattleResult& br); //called when battle is finished - battleresult window should be printed
+	void spellCasted(SpellCasted * sc); //called when a hero casts a spell
+	void castThisSpell(int spellID); //called when player has chosen a spell from spellbook
+	void displayEffect(ui32 effect, int destTile); //displays effect of a spell on the battlefield; affected: true - attacker. false - defender
+
+	friend class CBattleHex;
+	friend class CBattleReslutWindow;
+	friend class CPlayerInterface;
+};
 #endif //CBATTLEINTERFACE_H

+ 227 - 230
CCastleInterface.h

@@ -1,231 +1,228 @@
-#ifndef CCASTLEINTERFACE_H
-#define CCASTLEINTERFACE_H
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-
-#include "global.h"
-#include <SDL.h>
-#include "CPlayerInterface.h"
-//#include "boost/tuple/tuple.hpp"
-class CGTownInstance;
-class CTownHandler;
-class CHallInterface;
-struct Structure;
-class CSpell;
-class AdventureMapButton;
-class CResDataBar;
-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();
-	CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h,CCastleInterface * Owner);
-	~CHeroGSlot();
-};
-
-class CCastleInterface : public CMainInterface
-{
-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;
-
-	CDefHandler *hall,*fort;
-	CDefEssential* bicons; //150x70 buildings imgs
-	CTownList * townlist;
-
-	CHeroGSlot hslotup, hslotdown;
-	CGarrisonInt * garr;
-	AdventureMapButton *exit;
-	AdventureMapButton *split;
-
-	std::vector<CBuildingRect*> buildings; //building id, building def, structure struct, border, filling
-
-	CCastleInterface(const CGTownInstance * Town, bool Activate=true);
-	~CCastleInterface();
-	void townChange();
-	void show(SDL_Surface * to=NULL);
-	void showAll(SDL_Surface * to=NULL, bool forceTotalRedraw = false);
-	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=NULL);
-		void activate();
-		void deactivate();
-		CBuildingBox(int id);
-		CBuildingBox(int id, int x, int y);
-		~CBuildingBox();
-	};
-
-	class CBuildWindow: public IShowable, 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=NULL);
-		void Buy();
-		void close();
-		CBuildWindow(int Tid, int Bid, int State, bool Mode);
-		~CBuildWindow();
-	};
-
-	CDefEssential *bars, //0 - yellow, 1 - green, 2 - red, 3 - gray
-		*status; //0 - already, 1 - can't, 2 - lack of resources
-	std::vector< std::vector<CBuildingBox*> >boxes;
-
-	AdventureMapButton *exit;
-
-	SDL_Surface * bg;
-
-
-	CHallInterface(CCastleInterface * owner);
-	~CHallInterface();
-	void close();
-	void show(SDL_Surface * to=NULL);
-	void activate();
-	void deactivate();
-};
-
-class CFortScreen : public CMainInterface, public CIntObject
-{
-	class RecArea : public ClickableL
-	{
-	public:
-		int bid;
-		RecArea(int BID):bid(BID){};
-		void clickLeft (tribool down);
-		void activate();
-		void deactivate();
-	};
-public:
-	CMinorResDataBar resdatabar;
-	AdventureMapButton *exit;
-	SDL_Surface * bg;
-	std::vector<SDL_Rect> positions;
-	std::vector<RecArea*> recAreas;
-	std::vector<CCreaturePic*> crePics;
-
-	CFortScreen(CCastleInterface * owner);
-
-	void draw( CCastleInterface * owner, bool first);
-	~CFortScreen();
-	void close();
-	void show(SDL_Surface * to=NULL);
-	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<std::vector<SDL_Rect> > positions;
-
-	SDL_Surface *bg;
-	CDefEssential *scrolls, *scrolls2;
-	AdventureMapButton *exit;
-	std::vector<Scroll> spells;
-	CMinorResDataBar resdatabar;
-
-
-	CMageGuildScreen(CCastleInterface * owner);
-	~CMageGuildScreen();
-	void close();
-	void show(SDL_Surface * to=NULL);
-	void activate();
-	void deactivate();
-};
-
-class CBlacksmithDialog : public IShowable, 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=NULL);
-	void activate();
-	void deactivate();
-};
+#ifndef CCASTLEINTERFACE_H
+#define CCASTLEINTERFACE_H
+
+
+
+#include "global.h"
+#include <SDL.h>
+#include "CPlayerInterface.h"
+//#include "boost/tuple/tuple.hpp"
+class CGTownInstance;
+class CTownHandler;
+class CHallInterface;
+struct Structure;
+class CSpell;
+class AdventureMapButton;
+class CResDataBar;
+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();
+	CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h,CCastleInterface * Owner);
+	~CHeroGSlot();
+};
+
+class CCastleInterface : public CMainInterface
+{
+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;
+
+	CDefHandler *hall,*fort;
+	CDefEssential* bicons; //150x70 buildings imgs
+	CTownList * townlist;
+
+	CHeroGSlot hslotup, hslotdown;
+	CGarrisonInt * garr;
+	AdventureMapButton *exit;
+	AdventureMapButton *split;
+
+	std::vector<CBuildingRect*> buildings; //building id, building def, structure struct, border, filling
+
+	CCastleInterface(const CGTownInstance * Town, bool Activate=true);
+	~CCastleInterface();
+	void townChange();
+	void show(SDL_Surface * to=NULL);
+	void showAll(SDL_Surface * to=NULL, bool forceTotalRedraw = false);
+	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=NULL);
+		void activate();
+		void deactivate();
+		CBuildingBox(int id);
+		CBuildingBox(int id, int x, int y);
+		~CBuildingBox();
+	};
+
+	class CBuildWindow: public IShowable, 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=NULL);
+		void Buy();
+		void close();
+		CBuildWindow(int Tid, int Bid, int State, bool Mode);
+		~CBuildWindow();
+	};
+
+	CDefEssential *bars, //0 - yellow, 1 - green, 2 - red, 3 - gray
+		*status; //0 - already, 1 - can't, 2 - lack of resources
+	std::vector< std::vector<CBuildingBox*> >boxes;
+
+	AdventureMapButton *exit;
+
+	SDL_Surface * bg;
+
+
+	CHallInterface(CCastleInterface * owner);
+	~CHallInterface();
+	void close();
+	void show(SDL_Surface * to=NULL);
+	void activate();
+	void deactivate();
+};
+
+class CFortScreen : public CMainInterface, public CIntObject
+{
+	class RecArea : public ClickableL
+	{
+	public:
+		int bid;
+		RecArea(int BID):bid(BID){};
+		void clickLeft (tribool down);
+		void activate();
+		void deactivate();
+	};
+public:
+	CMinorResDataBar resdatabar;
+	AdventureMapButton *exit;
+	SDL_Surface * bg;
+	std::vector<SDL_Rect> positions;
+	std::vector<RecArea*> recAreas;
+	std::vector<CCreaturePic*> crePics;
+
+	CFortScreen(CCastleInterface * owner);
+
+	void draw( CCastleInterface * owner, bool first);
+	~CFortScreen();
+	void close();
+	void show(SDL_Surface * to=NULL);
+	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<std::vector<SDL_Rect> > positions;
+
+	SDL_Surface *bg;
+	CDefEssential *scrolls, *scrolls2;
+	AdventureMapButton *exit;
+	std::vector<Scroll> spells;
+	CMinorResDataBar resdatabar;
+
+
+	CMageGuildScreen(CCastleInterface * owner);
+	~CMageGuildScreen();
+	void close();
+	void show(SDL_Surface * to=NULL);
+	void activate();
+	void deactivate();
+};
+
+class CBlacksmithDialog : public IShowable, 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=NULL);
+	void activate();
+	void deactivate();
+};
 #endif //CCASTLEINTERFACE_H

+ 132 - 135
CHeroWindow.h

@@ -1,136 +1,133 @@
-#ifndef CHEROWINDOW_H
-#define CHEROWINDOW_H
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-#include "CPlayerInterface.h"
-
-class AdventureMapButton;
-struct SDL_Surface;
-class CGHeroInstance;
-class CDefHandler;
-class CArtifact;
-class CHeroWindow;
-
-class LClickableArea: public ClickableL
-{
-public:
-	virtual void clickLeft (tribool down);
-	virtual void activate();
-	virtual void deactivate();
-};
-
-class RClickableArea: public ClickableR
-{
-public:
-	virtual void clickRight (tribool down);
-	virtual void activate();
-	virtual void deactivate();
-};
-
-class LClickableAreaHero : public LClickableArea
-{
-public:
-	int id;
-	CHeroWindow * owner;
-	virtual void clickLeft (tribool down);
-};
-
-class LRClickableAreaWText: public LClickableArea, public RClickableArea, public Hoverable
-{
-public:
-	std::string text, hoverText;
-	virtual void activate();
-	virtual void deactivate();
-	virtual void clickLeft (tribool down);
-	virtual void clickRight (tribool down);
-	virtual void hover(bool on);
-};
-
-class LRClickableAreaWTextComp: public LClickableArea, public RClickableArea, public Hoverable
-{
-public:
-	std::string text, hoverText;
-	int baseType;
-	int bonus, type;
-	virtual void activate();
-	virtual void deactivate();
-	virtual void clickLeft (tribool down);
-	virtual void clickRight (tribool down);
-	virtual void hover(bool on);
-};
-
-class CArtPlace: public IShowable, public LRClickableAreaWTextComp
-{
-private:
-	bool active;
-public:
-	//bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4,
-	//	misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso,
-	//	lHand, rHand, neck, shoulders, head; //my types
-	ui16 slotID; //0   	head	1 	shoulders		2 	neck		3 	right hand		4 	left hand		5 	torso		6 	right ring		7 	left ring		8 	feet		9 	misc. slot 1		10 	misc. slot 2		11 	misc. slot 3		12 	misc. slot 4		13 	ballista (war machine 1)		14 	ammo cart (war machine 2)		15 	first aid tent (war machine 3)		16 	catapult		17 	spell book		18 	misc. slot 5		19+ 	backpack slots
-
-	bool clicked;
-	CHeroWindow * ourWindow;
-	const CArtifact * ourArt;
-	CArtPlace(const CArtifact * Art);
-	void clickLeft (tribool down);
-	void clickRight (tribool down);
-	void activate();
-	void deactivate();
-	void show(SDL_Surface * to = NULL);
-	bool fitsHere(const CArtifact * art); //returns true if given artifact can be placed here
-	~CArtPlace();
-};
-
-class CHeroWindow: public IShowActivable, public virtual CIntObject
-{
-	SDL_Surface * background, * curBack;
-	const CGHeroInstance * curHero;
-	CGarrisonInt * garInt;
-	CStatusBar * ourBar; //heroWindow's statusBar
-
-	//general graphics
-	CDefHandler *flags;
-
-	//buttons
-	AdventureMapButton * gar4button; //splitting
-	std::vector<LClickableAreaHero *> heroListMi; //new better list of heroes
-
-	std::vector<CArtPlace *> artWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
-	std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
-	int backpackPos; //unmber of first art visible in backpack (in hero's vector)
-	CArtPlace * activeArtPlace;
-	//clickable areas
-	LRClickableAreaWText * portraitArea;
-	std::vector<LRClickableAreaWTextComp *> primSkillAreas;
-	LRClickableAreaWText * expArea;
-	LRClickableAreaWText * spellPointsArea;
-	std::vector<LRClickableAreaWTextComp *> secSkillAreas;
-public:
-	AdventureMapButton * quitButton, * dismissButton, * questlogButton, //general
-		* leftArtRoll, * rightArtRoll;
-	CHighlightableButton *gar2button; //garrison / formation handling;
-	CHighlightableButtonsGroup *formations;
-	int player;
-	CHeroWindow(int playerColor); //c-tor
-	~CHeroWindow(); //d-tor
-	void setHero(const CGHeroInstance * Hero); //sets main displayed hero
-	void activate(); //activates hero window;
-	void deactivate(); //activates hero window;
-	virtual void show(SDL_Surface * to = NULL); //shows hero window
-	void redrawCurBack(); //redraws curBAck from scratch
-	void quit(); //stops displaying hero window
-	void dismissCurrent(); //dissmissed currently displayed hero (curHero)
-	void questlog(); //show quest log in hero window
-	void leftArtRoller(); //scrolls artifacts in bag left
-	void rightArtRoller(); //scrolls artifacts in bag right
-	void switchHero(); //changes displayed hero
-
-	//friends
-	friend void CArtPlace::clickLeft(tribool down);
-	friend class CPlayerInterface;
-};
+#ifndef CHEROWINDOW_H
+#define CHEROWINDOW_H
+
+
+#include "CPlayerInterface.h"
+
+class AdventureMapButton;
+struct SDL_Surface;
+class CGHeroInstance;
+class CDefHandler;
+class CArtifact;
+class CHeroWindow;
+
+class LClickableArea: public ClickableL
+{
+public:
+	virtual void clickLeft (tribool down);
+	virtual void activate();
+	virtual void deactivate();
+};
+
+class RClickableArea: public ClickableR
+{
+public:
+	virtual void clickRight (tribool down);
+	virtual void activate();
+	virtual void deactivate();
+};
+
+class LClickableAreaHero : public LClickableArea
+{
+public:
+	int id;
+	CHeroWindow * owner;
+	virtual void clickLeft (tribool down);
+};
+
+class LRClickableAreaWText: public LClickableArea, public RClickableArea, public Hoverable
+{
+public:
+	std::string text, hoverText;
+	virtual void activate();
+	virtual void deactivate();
+	virtual void clickLeft (tribool down);
+	virtual void clickRight (tribool down);
+	virtual void hover(bool on);
+};
+
+class LRClickableAreaWTextComp: public LClickableArea, public RClickableArea, public Hoverable
+{
+public:
+	std::string text, hoverText;
+	int baseType;
+	int bonus, type;
+	virtual void activate();
+	virtual void deactivate();
+	virtual void clickLeft (tribool down);
+	virtual void clickRight (tribool down);
+	virtual void hover(bool on);
+};
+
+class CArtPlace: public IShowable, public LRClickableAreaWTextComp
+{
+private:
+	bool active;
+public:
+	//bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4,
+	//	misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso,
+	//	lHand, rHand, neck, shoulders, head; //my types
+	ui16 slotID; //0   	head	1 	shoulders		2 	neck		3 	right hand		4 	left hand		5 	torso		6 	right ring		7 	left ring		8 	feet		9 	misc. slot 1		10 	misc. slot 2		11 	misc. slot 3		12 	misc. slot 4		13 	ballista (war machine 1)		14 	ammo cart (war machine 2)		15 	first aid tent (war machine 3)		16 	catapult		17 	spell book		18 	misc. slot 5		19+ 	backpack slots
+
+	bool clicked;
+	CHeroWindow * ourWindow;
+	const CArtifact * ourArt;
+	CArtPlace(const CArtifact * Art);
+	void clickLeft (tribool down);
+	void clickRight (tribool down);
+	void activate();
+	void deactivate();
+	void show(SDL_Surface * to = NULL);
+	bool fitsHere(const CArtifact * art); //returns true if given artifact can be placed here
+	~CArtPlace();
+};
+
+class CHeroWindow: public IShowActivable, public virtual CIntObject
+{
+	SDL_Surface * background, * curBack;
+	const CGHeroInstance * curHero;
+	CGarrisonInt * garInt;
+	CStatusBar * ourBar; //heroWindow's statusBar
+
+	//general graphics
+	CDefHandler *flags;
+
+	//buttons
+	AdventureMapButton * gar4button; //splitting
+	std::vector<LClickableAreaHero *> heroListMi; //new better list of heroes
+
+	std::vector<CArtPlace *> artWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
+	std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
+	int backpackPos; //unmber of first art visible in backpack (in hero's vector)
+	CArtPlace * activeArtPlace;
+	//clickable areas
+	LRClickableAreaWText * portraitArea;
+	std::vector<LRClickableAreaWTextComp *> primSkillAreas;
+	LRClickableAreaWText * expArea;
+	LRClickableAreaWText * spellPointsArea;
+	std::vector<LRClickableAreaWTextComp *> secSkillAreas;
+public:
+	AdventureMapButton * quitButton, * dismissButton, * questlogButton, //general
+		* leftArtRoll, * rightArtRoll;
+	CHighlightableButton *gar2button; //garrison / formation handling;
+	CHighlightableButtonsGroup *formations;
+	int player;
+	CHeroWindow(int playerColor); //c-tor
+	~CHeroWindow(); //d-tor
+	void setHero(const CGHeroInstance * Hero); //sets main displayed hero
+	void activate(); //activates hero window;
+	void deactivate(); //activates hero window;
+	virtual void show(SDL_Surface * to = NULL); //shows hero window
+	void redrawCurBack(); //redraws curBAck from scratch
+	void quit(); //stops displaying hero window
+	void dismissCurrent(); //dissmissed currently displayed hero (curHero)
+	void questlog(); //show quest log in hero window
+	void leftArtRoller(); //scrolls artifacts in bag left
+	void rightArtRoller(); //scrolls artifacts in bag right
+	void switchHero(); //changes displayed hero
+
+	//friends
+	friend void CArtPlace::clickLeft(tribool down);
+	friend class CPlayerInterface;
+};
 #endif //CHEROWINDOW_H

+ 43 - 46
client/CBitmapHandler.h

@@ -1,47 +1,44 @@
-#ifndef CBITMAPHANDLER_H
-#define CBITMAPHANDLER_H
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-
-#include "../global.h"
-struct SDL_Surface;
-class CLodHandler;
-
-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 openPCX();
-	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);
-};
+#ifndef CBITMAPHANDLER_H
+#define CBITMAPHANDLER_H
+
+
+
+#include "../global.h"
+struct SDL_Surface;
+class CLodHandler;
+
+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 openPCX();
+	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

+ 65 - 66
client/CConfigHandler.h

@@ -1,67 +1,66 @@
-#ifndef CCONFIGHANDLER_H
-#define CCONFIGHANDLER_H
-#pragma once
-#include "../global.h"
-class CAdvMapInt;
-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<std::string> 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;
-		//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<std::string> gemG;
-	};
-	struct GUIOptions
-	{
-		AdventureMapConfig ac;
-	};
-	class CConfigHandler
-	{
-	public:
-		ClientConfig cc;
-		std::map<std::pair<int,int>, GUIOptions > guiOptions;
-		GUIOptions *go(); //return pointer to gui options appropriate for used screen resolution
-		void init();
-		CConfigHandler(void);
-		~CConfigHandler(void);
-	};
-}
-extern config::CConfigHandler conf;
+#ifndef CCONFIGHANDLER_H
+#define CCONFIGHANDLER_H
+#include "../global.h"
+class CAdvMapInt;
+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<std::string> 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;
+		//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<std::string> gemG;
+	};
+	struct GUIOptions
+	{
+		AdventureMapConfig ac;
+	};
+	class CConfigHandler
+	{
+	public:
+		ClientConfig cc;
+		std::map<std::pair<int,int>, 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

+ 53 - 56
client/CCreatureAnimation.h

@@ -1,57 +1,54 @@
-#ifndef CCREATUREANIMATION_H
-#define CCREATUREANIMATION_H
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-#include "../global.h"
-#include "../CPlayerInterface.h"
-#include "../hch/CDefHandler.h"
-
-class CCreatureAnimation : public CIntObject
-{
-private:
-	int totalEntries, DEFType, totalBlocks;
-	int length;
-	BMPPalette palette[256];
-	int * RLEntries;
-	struct SEntry
-	{
-		std::string name;
-		int offset;
-		int group;
-	} ;
-	std::vector<SEntry> 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;
-
-	////////////
-
-	unsigned char * FDef; //animation raw data
-	int curFrame; //number of currently displayed frame
-	unsigned int frames; //number of frames
-public:
-	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, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next 
-	int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, bool IncrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next 
-	void incrementFrame();
-	int getFrame() const;
-
-	int framesInGroup(int group) const; //retirns number of fromes in given group
-};
+#ifndef CCREATUREANIMATION_H
+#define CCREATUREANIMATION_H
+
+
+#include "../global.h"
+#include "../CPlayerInterface.h"
+#include "../hch/CDefHandler.h"
+
+class CCreatureAnimation : public CIntObject
+{
+private:
+	int totalEntries, DEFType, totalBlocks;
+	int length;
+	BMPPalette palette[256];
+	int * RLEntries;
+	struct SEntry
+	{
+		std::string name;
+		int offset;
+		int group;
+	} ;
+	std::vector<SEntry> 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;
+
+	////////////
+
+	unsigned char * FDef; //animation raw data
+	int curFrame; //number of currently displayed frame
+	unsigned int frames; //number of frames
+public:
+	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, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next 
+	int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, bool IncrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next 
+	void incrementFrame();
+	int getFrame() const;
+
+	int framesInGroup(int group) const; //retirns number of fromes in given group
+};
 #endif //CCREATUREANIMATION_H

+ 91 - 94
client/CSpellWindow.h

@@ -1,95 +1,92 @@
-#ifndef CSPELLWINDOW_H
-#define CSPELLWINDOW_H
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-#include "../global.h"
-#include "../CPlayerInterface.h"
-
-struct SDL_Surface;
-class CDefHandler;
-struct SDL_Rect;
-class CGHeroInstance;
-
-class SpellbookInteractiveArea : public ClickableL, public ClickableR, public Hoverable
-{
-private:
-	boost::function<void()> onLeft;
-	std::string textOnRclick;
-	boost::function<void()> onHoverOn;
-	boost::function<void()> 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<void()> funcL, const std::string & textR, boost::function<void()> funcHon, boost::function<void()> 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<ui32> 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 = NULL);
-};
+#ifndef CSPELLWINDOW_H
+#define CSPELLWINDOW_H
+
+
+#include "../global.h"
+#include "../CPlayerInterface.h"
+
+struct SDL_Surface;
+class CDefHandler;
+struct SDL_Rect;
+class CGHeroInstance;
+
+class SpellbookInteractiveArea : public ClickableL, public ClickableR, public Hoverable
+{
+private:
+	boost::function<void()> onLeft;
+	std::string textOnRclick;
+	boost::function<void()> onHoverOn;
+	boost::function<void()> 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<void()> funcL, const std::string & textR, boost::function<void()> funcHon, boost::function<void()> 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<ui32> 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 = NULL);
+};
 #endif //CSPELLWINDOW_H

+ 61 - 64
client/Client.h

@@ -1,65 +1,62 @@
-#ifndef CLIENT_H
-#define CLIENT_H
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-#include "../global.h"
-#include <boost/thread.hpp>
-struct StartInfo;
-class CGameState;
-class CGameInterface;
-class CConnection;
-class CCallback;
-class CClient;
-void processCommand(const std::string &message, CClient *&client);
-namespace boost
-{
-	class mutex;
-	class condition_variable;
-}
-
-template <typename T>
-struct CSharedCond
-{
-	boost::mutex *mx;
-	boost::condition_variable *cv;
-	T *res;
-	CSharedCond(T*R)
-	{
-		res = R;
-		mx = new boost::mutex;
-		cv = new boost::condition_variable;
-	}
-	~CSharedCond()
-	{
-		delete res;
-		delete mx;
-		delete cv;
-	}
-};
-
-class CClient
-{
-	CCallback *cb;
-	CGameState *gs;
-	std::map<ui8,CGameInterface *> playerint;
-	CConnection *serv;
-
-	void waitForMoveAndSend(int color);
-public:
-	CClient(void);
-	CClient(CConnection *con, StartInfo *si);
-	~CClient(void);
-
-	void close();
-	void save(const std::string & fname);
-	void process(int what);
-	void run();
-
-	friend class CCallback; //handling players actions
-	friend class CScriptCallback; //for objects scripts
-	friend void processCommand(const std::string &message, CClient *&client); //handling console
-};
+#ifndef CLIENT_H
+#define CLIENT_H
+
+
+#include "../global.h"
+#include <boost/thread.hpp>
+struct StartInfo;
+class CGameState;
+class CGameInterface;
+class CConnection;
+class CCallback;
+class CClient;
+void processCommand(const std::string &message, CClient *&client);
+namespace boost
+{
+	class mutex;
+	class condition_variable;
+}
+
+template <typename T>
+struct CSharedCond
+{
+	boost::mutex *mx;
+	boost::condition_variable *cv;
+	T *res;
+	CSharedCond(T*R)
+	{
+		res = R;
+		mx = new boost::mutex;
+		cv = new boost::condition_variable;
+	}
+	~CSharedCond()
+	{
+		delete res;
+		delete mx;
+		delete cv;
+	}
+};
+
+class CClient
+{
+	CCallback *cb;
+	CGameState *gs;
+	std::map<ui8,CGameInterface *> playerint;
+	CConnection *serv;
+
+	void waitForMoveAndSend(int color);
+public:
+	CClient(void);
+	CClient(CConnection *con, StartInfo *si);
+	~CClient(void);
+
+	void close();
+	void save(const std::string & fname);
+	void process(int what);
+	void run();
+
+	friend class CCallback; //handling players actions
+	friend class CScriptCallback; //for objects scripts
+	friend void processCommand(const std::string &message, CClient *&client); //handling console
+};
 #endif //CLIENT_H

+ 65 - 68
client/Graphics.h

@@ -1,69 +1,66 @@
-#ifndef GRAPHICS_H
-#define GRAPHICS_H
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-#include "../global.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<std::pair<int, int> > slotsPos; //creature slot positions in infoboxes
-	CDefEssential *luck22, *luck30, *luck42, *luck82,
-		*morale22, *morale30, *morale42, *morale82,
-		*halls, *forts, *bigTownPic;
-	std::map<int,SDL_Surface*> heroWins; //hero_ID => infobox
-	std::map<int,SDL_Surface*> townWins; //town_ID => infobox
-	CDefHandler * artDefs; //artifacts
-	std::vector<SDL_Surface *> portraitSmall; //48x32 px portraits of heroes
-	std::vector<SDL_Surface *> portraitLarge; //58x64 px portraits of heroes
-	std::vector<CDefHandler *> 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;
-	//creatures
-	std::map<int,SDL_Surface*> smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border
-	std::map<int,SDL_Surface*> bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border
-	std::map<int,SDL_Surface*> backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral
-	std::map<int,SDL_Surface*> 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<std::string> guildBgs;// name of bitmaps with imgs for mage guild screen
-	//functions
-	Graphics();	
-	void initializeBattleGraphics();
-	void loadPaletteAndColors();
-	void loadHeroFlags();
-	void loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, std::vector<const char *> > &pr, bool mode);
-	void loadHeroAnim(std::vector<CDefHandler **> & anims);
-	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;
+#ifndef GRAPHICS_H
+#define GRAPHICS_H
+
+
+#include "../global.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<std::pair<int, int> > slotsPos; //creature slot positions in infoboxes
+	CDefEssential *luck22, *luck30, *luck42, *luck82,
+		*morale22, *morale30, *morale42, *morale82,
+		*halls, *forts, *bigTownPic;
+	std::map<int,SDL_Surface*> heroWins; //hero_ID => infobox
+	std::map<int,SDL_Surface*> townWins; //town_ID => infobox
+	CDefHandler * artDefs; //artifacts
+	std::vector<SDL_Surface *> portraitSmall; //48x32 px portraits of heroes
+	std::vector<SDL_Surface *> portraitLarge; //58x64 px portraits of heroes
+	std::vector<CDefHandler *> 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;
+	//creatures
+	std::map<int,SDL_Surface*> smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border
+	std::map<int,SDL_Surface*> bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border
+	std::map<int,SDL_Surface*> backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral
+	std::map<int,SDL_Surface*> 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<std::string> guildBgs;// name of bitmaps with imgs for mage guild screen
+	//functions
+	Graphics();	
+	void initializeBattleGraphics();
+	void loadPaletteAndColors();
+	void loadHeroFlags();
+	void loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, std::vector<const char *> > &pr, bool mode);
+	void loadHeroAnim(std::vector<CDefHandler **> & anims);
+	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

+ 5 - 0
client/vcmi_client/.dep.inc

@@ -0,0 +1,5 @@
+# This code depends on make tool being used
+DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES}))
+ifneq (${DEPFILES},)
+include ${DEPFILES}
+endif

+ 92 - 0
client/vcmi_client/Makefile

@@ -0,0 +1,92 @@
+#
+#  There exist several targets which are by default empty and which can be 
+#  used for execution of your targets. These targets are usually executed 
+#  before and after some main targets. They are: 
+#
+#     .build-pre:              called before 'build' target
+#     .build-post:             called after 'build' target
+#     .clean-pre:              called before 'clean' target
+#     .clean-post:             called after 'clean' target
+#     .clobber-pre:            called before 'clobber' target
+#     .clobber-post:           called after 'clobber' target
+#     .all-pre:                called before 'all' target
+#     .all-post:               called after 'all' target
+#     .help-pre:                called before 'help' target
+#     .help-post:               called after 'help' target
+#
+#  Targets beginning with '.' are not intended to be called on their own.
+#
+#  Main targets can be executed directly, and they are:
+#  
+#     build                    build a specific configuration
+#     clean                    remove built files from a configuration
+#     clobber                  remove all built files
+#     all                      build all configurations
+#     help                     print help mesage
+#  
+#  Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
+#  .help-impl are implemented in nbproject/makefile-impl.mk.
+#
+# NOCDDL
+
+
+# Environment 
+MKDIR=mkdir
+CP=cp
+CCADMIN=CCadmin
+RANLIB=ranlib
+
+
+# build
+build: .build-post
+
+.build-pre:
+# Add your pre 'build' code here...
+
+.build-post: .build-impl
+# Add your post 'build' code here...
+
+
+# clean
+clean: .clean-post
+
+.clean-pre:
+# Add your pre 'clean' code here...
+
+.clean-post: .clean-impl
+# Add your post 'clean' code here...
+
+
+# clobber
+clobber: .clobber-post
+
+.clobber-pre:
+# Add your pre 'clobber' code here...
+
+.clobber-post: .clobber-impl
+# Add your post 'clobber' code here...
+
+
+# all
+all: .all-post
+
+.all-pre:
+# Add your pre 'all' code here...
+
+.all-post: .all-impl
+# Add your post 'all' code here...
+
+
+# help
+help: .help-post
+
+.help-pre:
+# Add your pre 'help' code here...
+
+.help-post: .help-impl
+# Add your post 'help' code here...
+
+
+
+# include project implementation makefile
+include nbproject/Makefile-impl.mk

+ 257 - 0
client/vcmi_client/nbproject/Makefile-Debug.mk

@@ -0,0 +1,257 @@
+#
+# Generated Makefile - do not edit!
+#
+# Edit the Makefile in the project folder instead (../Makefile). Each target
+# has a -pre and a -post target defined where you can add customized code.
+#
+# This makefile implements configuration specific macros and targets.
+
+
+# Environment
+MKDIR=mkdir
+CP=cp
+CCADMIN=CCadmin
+RANLIB=ranlib
+CC=gcc
+CCC=g++
+CXX=g++
+FC=
+
+# Macros
+PLATFORM=GNU-Linux-x86
+
+# Include project Makefile
+include Makefile
+
+# Object Directory
+OBJECTDIR=build/Debug/${PLATFORM}
+
+# Object Files
+OBJECTFILES= \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSpellHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CLuaHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCastleInterface.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCursorHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CObjectHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CCreatureAnimation.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Client.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInfo.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CHeroWindow.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMessage.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPlayerInterface.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CAbilityHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSndHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../mapHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPathfinder.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInterface.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPreGame.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CBitmapHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Graphics.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CDefHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../AdventureMapButton.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_Extensions.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CConfigHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CAdvmapInterface.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CThreadHelper.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_framerate.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCallback.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMT.o
+
+# C Compiler Flags
+CFLAGS=
+
+# CC Compiler Flags
+CCFLAGS=-D_GNU_SOURCE=1 -D_REENTRANT
+CXXFLAGS=-D_GNU_SOURCE=1 -D_REENTRANT
+
+# Fortran Compiler Flags
+FFLAGS=
+
+# Link Libraries and Options
+LDLIBSOPTIONS=-L../../../../boost/lib -Wl,-rpath ../../lib/vcmi_lib/dist/Debug/GNU-Linux-x86 -L../../lib/vcmi_lib/dist/Debug/GNU-Linux-x86 -lvcmi_lib
+
+# Build Targets
+.build-conf: ${BUILD_SUBPROJECTS}
+	${MAKE}  -f nbproject/Makefile-Debug.mk dist/Debug/${PLATFORM}/vcmi_client
+
+dist/Debug/${PLATFORM}/vcmi_client: ../../lib/vcmi_lib/dist/Debug/GNU-Linux-x86/libvcmi_lib.so
+
+dist/Debug/${PLATFORM}/vcmi_client: ${OBJECTFILES}
+	${MKDIR} -p dist/Debug/${PLATFORM}
+	${LINK.cc} -lboost_system-gcc43-mt-1_37 -lboost_thread-gcc43-mt-1_37 -lboost_filesystem-gcc43-mt-1_37 -lSDL -lSDL_ttf -lSDL_image -lSDL_mixer -o dist/Debug/${PLATFORM}/vcmi_client ${OBJECTFILES} ${LDLIBSOPTIONS} 
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSpellHandler.o: ../../hch/CSpellHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSpellHandler.o ../../hch/CSpellHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CLuaHandler.o: ../../CLuaHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CLuaHandler.o ../../CLuaHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.o: ../CSpellWindow.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.o ../CSpellWindow.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCastleInterface.o: ../../CCastleInterface.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCastleInterface.o ../../CCastleInterface.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCursorHandler.o: ../../CCursorHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCursorHandler.o ../../CCursorHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CObjectHandler.o: ../../hch/CObjectHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CObjectHandler.o ../../hch/CObjectHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CCreatureAnimation.o: ../CCreatureAnimation.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CCreatureAnimation.o ../CCreatureAnimation.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Client.o: ../Client.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Client.o ../Client.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInfo.o: ../../CGameInfo.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInfo.o ../../CGameInfo.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CHeroWindow.o: ../../CHeroWindow.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CHeroWindow.o ../../CHeroWindow.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMessage.o: ../../CMessage.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMessage.o ../../CMessage.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPlayerInterface.o: ../../CPlayerInterface.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPlayerInterface.o ../../CPlayerInterface.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CAbilityHandler.o: ../../hch/CAbilityHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CAbilityHandler.o ../../hch/CAbilityHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSndHandler.o: ../../hch/CSndHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSndHandler.o ../../hch/CSndHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.o: ../../CBattleInterface.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.o ../../CBattleInterface.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../mapHandler.o: ../../mapHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../mapHandler.o ../../mapHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPathfinder.o: ../../CPathfinder.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPathfinder.o ../../CPathfinder.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInterface.o: ../../CGameInterface.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInterface.o ../../CGameInterface.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPreGame.o: ../../CPreGame.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPreGame.o ../../CPreGame.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CBitmapHandler.o: ../CBitmapHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CBitmapHandler.o ../CBitmapHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Graphics.o: ../Graphics.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Graphics.o ../Graphics.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CDefHandler.o: ../../hch/CDefHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CDefHandler.o ../../hch/CDefHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../AdventureMapButton.o: ../../AdventureMapButton.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../AdventureMapButton.o ../../AdventureMapButton.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_Extensions.o: ../../SDL_Extensions.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_Extensions.o ../../SDL_Extensions.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CConfigHandler.o: ../CConfigHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CConfigHandler.o ../CConfigHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CAdvmapInterface.o: ../../CAdvmapInterface.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CAdvmapInterface.o ../../CAdvmapInterface.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CThreadHelper.o: ../../CThreadHelper.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CThreadHelper.o ../../CThreadHelper.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.o: ../../hch/CMusicHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.o ../../hch/CMusicHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_framerate.o: ../../SDL_framerate.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_framerate.o ../../SDL_framerate.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCallback.o: ../../CCallback.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCallback.o ../../CCallback.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMT.o: ../../CMT.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -Wall -I/usr/include/SDL -I../../../../boost/include/boost-1_37 -I.. -I../../hch -I/usr/include/lua5.1 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMT.o ../../CMT.cpp
+
+# Subprojects
+.build-subprojects:
+	cd ../../lib/vcmi_lib && ${MAKE}  -f Makefile-nb CONF=Debug
+
+# Clean Targets
+.clean-conf: ${CLEAN_SUBPROJECTS}
+	${RM} -r build/Debug
+	${RM} dist/Debug/${PLATFORM}/vcmi_client
+
+# Subprojects
+.clean-subprojects:
+	cd ../../lib/vcmi_lib && ${MAKE}  -f Makefile-nb CONF=Debug clean
+
+# Enable dependency checking
+.dep.inc: .depcheck-impl
+
+include .dep.inc

+ 253 - 0
client/vcmi_client/nbproject/Makefile-Release.mk

@@ -0,0 +1,253 @@
+#
+# Generated Makefile - do not edit!
+#
+# Edit the Makefile in the project folder instead (../Makefile). Each target
+# has a -pre and a -post target defined where you can add customized code.
+#
+# This makefile implements configuration specific macros and targets.
+
+
+# Environment
+MKDIR=mkdir
+CP=cp
+CCADMIN=CCadmin
+RANLIB=ranlib
+CC=gcc
+CCC=g++
+CXX=g++
+FC=
+
+# Macros
+PLATFORM=GNU-Linux-x86
+
+# Include project Makefile
+include Makefile
+
+# Object Directory
+OBJECTDIR=build/Release/${PLATFORM}
+
+# Object Files
+OBJECTFILES= \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSpellHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CLuaHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCastleInterface.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCursorHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CObjectHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CCreatureAnimation.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Client.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInfo.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CHeroWindow.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMessage.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPlayerInterface.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CAbilityHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSndHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../mapHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPathfinder.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInterface.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPreGame.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CBitmapHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Graphics.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CDefHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../AdventureMapButton.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_Extensions.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CConfigHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CAdvmapInterface.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CThreadHelper.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_framerate.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCallback.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMT.o
+
+# C Compiler Flags
+CFLAGS=
+
+# CC Compiler Flags
+CCFLAGS=
+CXXFLAGS=
+
+# Fortran Compiler Flags
+FFLAGS=
+
+# Link Libraries and Options
+LDLIBSOPTIONS=
+
+# Build Targets
+.build-conf: ${BUILD_SUBPROJECTS}
+	${MAKE}  -f nbproject/Makefile-Release.mk dist/Release/${PLATFORM}/vcmi_client
+
+dist/Release/${PLATFORM}/vcmi_client: ${OBJECTFILES}
+	${MKDIR} -p dist/Release/${PLATFORM}
+	${LINK.cc} -o dist/Release/${PLATFORM}/vcmi_client ${OBJECTFILES} ${LDLIBSOPTIONS} 
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSpellHandler.o: ../../hch/CSpellHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSpellHandler.o ../../hch/CSpellHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CLuaHandler.o: ../../CLuaHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CLuaHandler.o ../../CLuaHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.o: ../CSpellWindow.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.o ../CSpellWindow.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCastleInterface.o: ../../CCastleInterface.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCastleInterface.o ../../CCastleInterface.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCursorHandler.o: ../../CCursorHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCursorHandler.o ../../CCursorHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CObjectHandler.o: ../../hch/CObjectHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CObjectHandler.o ../../hch/CObjectHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CCreatureAnimation.o: ../CCreatureAnimation.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CCreatureAnimation.o ../CCreatureAnimation.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Client.o: ../Client.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Client.o ../Client.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInfo.o: ../../CGameInfo.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInfo.o ../../CGameInfo.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CHeroWindow.o: ../../CHeroWindow.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CHeroWindow.o ../../CHeroWindow.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMessage.o: ../../CMessage.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMessage.o ../../CMessage.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPlayerInterface.o: ../../CPlayerInterface.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPlayerInterface.o ../../CPlayerInterface.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CAbilityHandler.o: ../../hch/CAbilityHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CAbilityHandler.o ../../hch/CAbilityHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSndHandler.o: ../../hch/CSndHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CSndHandler.o ../../hch/CSndHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.o: ../../CBattleInterface.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.o ../../CBattleInterface.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../mapHandler.o: ../../mapHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../mapHandler.o ../../mapHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPathfinder.o: ../../CPathfinder.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPathfinder.o ../../CPathfinder.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInterface.o: ../../CGameInterface.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CGameInterface.o ../../CGameInterface.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPreGame.o: ../../CPreGame.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CPreGame.o ../../CPreGame.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CBitmapHandler.o: ../CBitmapHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CBitmapHandler.o ../CBitmapHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Graphics.o: ../Graphics.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../Graphics.o ../Graphics.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CDefHandler.o: ../../hch/CDefHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CDefHandler.o ../../hch/CDefHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../AdventureMapButton.o: ../../AdventureMapButton.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../AdventureMapButton.o ../../AdventureMapButton.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_Extensions.o: ../../SDL_Extensions.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_Extensions.o ../../SDL_Extensions.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CConfigHandler.o: ../CConfigHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../CConfigHandler.o ../CConfigHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CAdvmapInterface.o: ../../CAdvmapInterface.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CAdvmapInterface.o ../../CAdvmapInterface.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CThreadHelper.o: ../../CThreadHelper.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CThreadHelper.o ../../CThreadHelper.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.o: ../../hch/CMusicHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.o ../../hch/CMusicHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_framerate.o: ../../SDL_framerate.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../SDL_framerate.o ../../SDL_framerate.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCallback.o: ../../CCallback.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CCallback.o ../../CCallback.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMT.o: ../../CMT.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/client/vcmi_client/../../CMT.o ../../CMT.cpp
+
+# Subprojects
+.build-subprojects:
+
+# Clean Targets
+.clean-conf:
+	${RM} -r build/Release
+	${RM} dist/Release/${PLATFORM}/vcmi_client
+
+# Subprojects
+.clean-subprojects:
+
+# Enable dependency checking
+.dep.inc: .depcheck-impl
+
+include .dep.inc

+ 123 - 0
client/vcmi_client/nbproject/Makefile-impl.mk

@@ -0,0 +1,123 @@
+# 
+# Generated Makefile - do not edit! 
+# 
+# Edit the Makefile in the project folder instead (../Makefile). Each target
+# has a pre- and a post- target defined where you can add customization code.
+#
+# This makefile implements macros and targets common to all configurations.
+#
+# NOCDDL
+
+
+# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
+# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
+# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
+# and .clean-reqprojects-conf unless SUB has the value 'no'
+SUB_no=NO
+SUBPROJECTS=${SUB_${SUB}}
+BUILD_SUBPROJECTS_=.build-subprojects
+BUILD_SUBPROJECTS_NO=
+BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
+CLEAN_SUBPROJECTS_=.clean-subprojects
+CLEAN_SUBPROJECTS_NO=
+CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
+
+
+# Project Name
+PROJECTNAME=vcmi_client
+
+# Active Configuration
+DEFAULTCONF=Debug
+CONF=${DEFAULTCONF}
+
+# All Configurations
+ALLCONFS=Debug Release 
+
+
+# build
+.build-impl: .build-pre .validate-impl .depcheck-impl
+	@#echo "=> Running $@... Configuration=$(CONF)"
+	${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
+
+
+# clean
+.clean-impl: .clean-pre .validate-impl .depcheck-impl
+	@#echo "=> Running $@... Configuration=$(CONF)"
+	${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
+
+
+# clobber 
+.clobber-impl: .clobber-pre .depcheck-impl
+	@#echo "=> Running $@..."
+	for CONF in ${ALLCONFS}; \
+	do \
+	    ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf; \
+	done
+
+# all 
+.all-impl: .all-pre .depcheck-impl
+	@#echo "=> Running $@..."
+	for CONF in ${ALLCONFS}; \
+	do \
+	    ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf; \
+	done
+
+# dependency checking support
+.depcheck-impl:
+	@echo "# This code depends on make tool being used" >.dep.inc
+	@if [ -n "${MAKE_VERSION}" ]; then \
+	    echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
+	    echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
+	    echo "include \$${DEPFILES}" >>.dep.inc; \
+	    echo "endif" >>.dep.inc; \
+	else \
+	    echo ".KEEP_STATE:" >>.dep.inc; \
+	    echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
+	fi
+
+# configuration validation
+.validate-impl:
+	@if [ ! -f nbproject/Makefile-${CONF}.mk ]; \
+	then \
+	    echo ""; \
+	    echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \
+	    echo "See 'make help' for details."; \
+	    echo "Current directory: " `pwd`; \
+	    echo ""; \
+	fi
+	@if [ ! -f nbproject/Makefile-${CONF}.mk ]; \
+	then \
+	    exit 1; \
+	fi
+
+
+# help
+.help-impl: .help-pre
+	@echo "This makefile supports the following configurations:"
+	@echo "    ${ALLCONFS}"
+	@echo ""
+	@echo "and the following targets:"
+	@echo "    build  (default target)"
+	@echo "    clean"
+	@echo "    clobber"
+	@echo "    all"
+	@echo "    help"
+	@echo ""
+	@echo "Makefile Usage:"
+	@echo "    make [CONF=<CONFIGURATION>] [SUB=no] build"
+	@echo "    make [CONF=<CONFIGURATION>] [SUB=no] clean"
+	@echo "    make [SUB=no] clobber"
+	@echo "    make [SUB=no] all"
+	@echo "    make help"
+	@echo ""
+	@echo "Target 'build' will build a specific configuration and, unless 'SUB=no',"
+	@echo "    also build subprojects."
+	@echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no',"
+	@echo "    also clean subprojects."
+	@echo "Target 'clobber' will remove all built files from all configurations and,"
+	@echo "    unless 'SUB=no', also from subprojects."
+	@echo "Target 'all' will will build all configurations and, unless 'SUB=no',"
+	@echo "    also build subprojects."
+	@echo "Target 'help' prints this message."
+	@echo ""
+

+ 72 - 0
client/vcmi_client/nbproject/Package-Debug.bash

@@ -0,0 +1,72 @@
+#!/bin/bash -x
+
+#
+# Generated - do not edit!
+#
+
+# Macros
+TOP=`pwd`
+PLATFORM=GNU-Linux-x86
+TMPDIR=build/Debug/${PLATFORM}/tmp-packaging
+TMPDIRNAME=tmp-packaging
+OUTPUT_PATH=dist/Debug/${PLATFORM}/vcmi_client
+OUTPUT_BASENAME=vcmi_client
+PACKAGE_TOP_DIR=vcmiclient/
+
+# Functions
+function checkReturnCode
+{
+    rc=$?
+    if [ $rc != 0 ]
+    then
+        exit $rc
+    fi
+}
+function makeDirectory
+# $1 directory path
+# $2 permission (optional)
+{
+    mkdir -p "$1"
+    checkReturnCode
+    if [ "$2" != "" ]
+    then
+      chmod $2 "$1"
+      checkReturnCode
+    fi
+}
+function copyFileToTmpDir
+# $1 from-file path
+# $2 to-file path
+# $3 permission
+{
+    cp "$1" "$2"
+    checkReturnCode
+    if [ "$3" != "" ]
+    then
+        chmod $3 "$2"
+        checkReturnCode
+    fi
+}
+
+# Setup
+cd "${TOP}"
+mkdir -p dist/Debug/${PLATFORM}/package
+rm -rf ${TMPDIR}
+mkdir -p ${TMPDIR}
+
+# Copy files and create directories and links
+cd "${TOP}"
+makeDirectory ${TMPDIR}/vcmiclient/bin
+copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
+
+
+# Generate tar file
+cd "${TOP}"
+rm -f dist/Debug/${PLATFORM}/package/vcmiclient.tar
+cd ${TMPDIR}
+tar -vcf ../../../../dist/Debug/${PLATFORM}/package/vcmiclient.tar *
+checkReturnCode
+
+# Cleanup
+cd "${TOP}"
+rm -rf ${TMPDIR}

+ 72 - 0
client/vcmi_client/nbproject/Package-Release.bash

@@ -0,0 +1,72 @@
+#!/bin/bash -x
+
+#
+# Generated - do not edit!
+#
+
+# Macros
+TOP=`pwd`
+PLATFORM=GNU-Linux-x86
+TMPDIR=build/Release/${PLATFORM}/tmp-packaging
+TMPDIRNAME=tmp-packaging
+OUTPUT_PATH=dist/Release/${PLATFORM}/vcmi_client
+OUTPUT_BASENAME=vcmi_client
+PACKAGE_TOP_DIR=vcmiclient/
+
+# Functions
+function checkReturnCode
+{
+    rc=$?
+    if [ $rc != 0 ]
+    then
+        exit $rc
+    fi
+}
+function makeDirectory
+# $1 directory path
+# $2 permission (optional)
+{
+    mkdir -p "$1"
+    checkReturnCode
+    if [ "$2" != "" ]
+    then
+      chmod $2 "$1"
+      checkReturnCode
+    fi
+}
+function copyFileToTmpDir
+# $1 from-file path
+# $2 to-file path
+# $3 permission
+{
+    cp "$1" "$2"
+    checkReturnCode
+    if [ "$3" != "" ]
+    then
+        chmod $3 "$2"
+        checkReturnCode
+    fi
+}
+
+# Setup
+cd "${TOP}"
+mkdir -p dist/Release/${PLATFORM}/package
+rm -rf ${TMPDIR}
+mkdir -p ${TMPDIR}
+
+# Copy files and create directories and links
+cd "${TOP}"
+makeDirectory ${TMPDIR}/vcmiclient/bin
+copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755
+
+
+# Generate tar file
+cd "${TOP}"
+rm -f dist/Release/${PLATFORM}/package/vcmiclient.tar
+cd ${TMPDIR}
+tar -vcf ../../../../dist/Release/${PLATFORM}/package/vcmiclient.tar *
+checkReturnCode
+
+# Cleanup
+cd "${TOP}"
+rm -rf ${TMPDIR}

+ 595 - 0
client/vcmi_client/nbproject/configurations.xml

@@ -0,0 +1,595 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configurationDescriptor version="51">
+  <logicalFolder name="root" displayName="root" projectFiles="true">
+    <logicalFolder name="HeaderFiles"
+                   displayName="Header Files"
+                   projectFiles="true">
+      <itemPath>../../AdventureMapButton.h</itemPath>
+      <itemPath>../../AI_Base.h</itemPath>
+      <itemPath>../../hch/CAbilityHandler.h</itemPath>
+      <itemPath>../../CAdvmapInterface.h</itemPath>
+      <itemPath>../../hch/CAmbarCendamo.h</itemPath>
+      <itemPath>../../hch/CArtHandler.h</itemPath>
+      <itemPath>../../CBattleInterface.h</itemPath>
+      <itemPath>../CBitmapHandler.h</itemPath>
+      <itemPath>../../hch/CBuildingHandler.h</itemPath>
+      <itemPath>../../CCallback.h</itemPath>
+      <itemPath>../../CCastleInterface.h</itemPath>
+      <itemPath>../CConfigHandler.h</itemPath>
+      <itemPath>../CCreatureAnimation.h</itemPath>
+      <itemPath>../../CCursorHandler.h</itemPath>
+      <itemPath>../../hch/CDefHandler.h</itemPath>
+      <itemPath>../../CGameInfo.h</itemPath>
+      <itemPath>../../CGameInterface.h</itemPath>
+      <itemPath>../../hch/CHeroHandler.h</itemPath>
+      <itemPath>../../CHeroWindow.h</itemPath>
+      <itemPath>../Client.h</itemPath>
+      <itemPath>../../CLuaHandler.h</itemPath>
+      <itemPath>../../CMessage.h</itemPath>
+      <itemPath>../../hch/CMusicHandler.h</itemPath>
+      <itemPath>../../hch/CObjectHandler.h</itemPath>
+      <itemPath>../../CPathfinder.h</itemPath>
+      <itemPath>../../CPlayerInterface.h</itemPath>
+      <itemPath>../../CPreGame.h</itemPath>
+      <itemPath>../../hch/CSndHandler.h</itemPath>
+      <itemPath>../CSpellWindow.h</itemPath>
+      <itemPath>../../CThreadHelper.h</itemPath>
+      <itemPath>../FunctionList.h</itemPath>
+      <itemPath>../../global.h</itemPath>
+      <itemPath>../Graphics.h</itemPath>
+      <itemPath>../../int3.h</itemPath>
+      <itemPath>../../map.h</itemPath>
+      <itemPath>../../mapHandler.h</itemPath>
+      <itemPath>../../nodrze.h</itemPath>
+      <itemPath>../../SDL_framerate.h</itemPath>
+      <itemPath>../../StartInfo.h</itemPath>
+      <itemPath>../../stdafx.h</itemPath>
+      <itemPath>../../timeHandler.h</itemPath>
+    </logicalFolder>
+    <logicalFolder name="ResourceFiles"
+                   displayName="Resource Files"
+                   projectFiles="true">
+    </logicalFolder>
+    <logicalFolder name="SourceFiles"
+                   displayName="Source Files"
+                   projectFiles="true">
+      <itemPath>../../AdventureMapButton.cpp</itemPath>
+      <itemPath>../../hch/CAbilityHandler.cpp</itemPath>
+      <itemPath>../../CAdvmapInterface.cpp</itemPath>
+      <itemPath>../../CBattleInterface.cpp</itemPath>
+      <itemPath>../CBitmapHandler.cpp</itemPath>
+      <itemPath>../../CCallback.cpp</itemPath>
+      <itemPath>../../CCastleInterface.cpp</itemPath>
+      <itemPath>../CConfigHandler.cpp</itemPath>
+      <itemPath>../CCreatureAnimation.cpp</itemPath>
+      <itemPath>../../CCursorHandler.cpp</itemPath>
+      <itemPath>../../hch/CDefHandler.cpp</itemPath>
+      <itemPath>../../CGameInfo.cpp</itemPath>
+      <itemPath>../../CGameInterface.cpp</itemPath>
+      <itemPath>../../CHeroWindow.cpp</itemPath>
+      <itemPath>../Client.cpp</itemPath>
+      <itemPath>../../CLuaHandler.cpp</itemPath>
+      <itemPath>../../CMessage.cpp</itemPath>
+      <itemPath>../../CMT.cpp</itemPath>
+      <itemPath>../../hch/CMusicHandler.cpp</itemPath>
+      <itemPath>../../hch/CObjectHandler.cpp</itemPath>
+      <itemPath>../../CPathfinder.cpp</itemPath>
+      <itemPath>../../CPlayerInterface.cpp</itemPath>
+      <itemPath>../../CPreGame.cpp</itemPath>
+      <itemPath>../../hch/CSndHandler.cpp</itemPath>
+      <itemPath>../../hch/CSpellHandler.cpp</itemPath>
+      <itemPath>../CSpellWindow.cpp</itemPath>
+      <itemPath>../../CThreadHelper.cpp</itemPath>
+      <itemPath>../Graphics.cpp</itemPath>
+      <itemPath>../../mapHandler.cpp</itemPath>
+      <itemPath>../../SDL_Extensions.cpp</itemPath>
+      <itemPath>../../SDL_framerate.cpp</itemPath>
+    </logicalFolder>
+    <logicalFolder name="ExternalFiles"
+                   displayName="Important Files"
+                   projectFiles="false">
+      <itemPath>Makefile</itemPath>
+    </logicalFolder>
+  </logicalFolder>
+  <sourceRootList>
+    <Elem>..</Elem>
+  </sourceRootList>
+  <projectmakefile>Makefile</projectmakefile>
+  <confs>
+    <conf name="Debug" type="1">
+      <toolsSet>
+        <developmentServer>localhost</developmentServer>
+        <compilerSet>GNU|GNU</compilerSet>
+        <platform>2</platform>
+      </toolsSet>
+      <compileType>
+        <ccCompilerTool>
+          <includeDirectories>
+            <directoryPath>/usr/include/SDL</directoryPath>
+            <directoryPath>../../../../boost/include/boost-1_37</directoryPath>
+            <directoryPath>..</directoryPath>
+            <directoryPath>../../hch</directoryPath>
+            <directoryPath>/usr/include/lua5.1</directoryPath>
+          </includeDirectories>
+          <commandLine>-D_GNU_SOURCE=1 -D_REENTRANT</commandLine>
+          <warningLevel>2</warningLevel>
+        </ccCompilerTool>
+        <linkerTool>
+          <output>dist/Debug/${PLATFORM}/vcmi_client</output>
+          <linkerAddLib>
+            <directoryPath>../../../../boost/lib</directoryPath>
+          </linkerAddLib>
+          <linkerLibItems>
+            <linkerLibProjectItem>
+              <makeArtifact PL="../../lib/vcmi_lib"
+                            CT="2"
+                            CN="Debug"
+                            AC="true"
+                            BL="true"
+                            WD="../../lib/vcmi_lib"
+                            BC="${MAKE}  -f Makefile-nb CONF=Debug"
+                            CC="${MAKE}  -f Makefile-nb CONF=Debug clean"
+                            OP="dist/Debug/GNU-Linux-x86/libvcmi_lib.so">
+              </makeArtifact>
+            </linkerLibProjectItem>
+          </linkerLibItems>
+          <commandLine>-lboost_system-gcc43-mt-1_37 -lboost_thread-gcc43-mt-1_37 -lboost_filesystem-gcc43-mt-1_37 -lSDL -lSDL_ttf -lSDL_image -lSDL_mixer</commandLine>
+        </linkerTool>
+      </compileType>
+      <item path="../../AI_Base.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../AdventureMapButton.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../AdventureMapButton.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CAdvmapInterface.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CAdvmapInterface.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CBattleInterface.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CBattleInterface.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CCallback.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CCallback.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CCastleInterface.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CCastleInterface.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CCursorHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CCursorHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CGameInfo.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CGameInfo.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CGameInterface.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CGameInterface.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CHeroWindow.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CHeroWindow.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CLuaHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CLuaHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CMT.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CMessage.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CMessage.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CPathfinder.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CPathfinder.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CPlayerInterface.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CPlayerInterface.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CPreGame.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CPreGame.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CThreadHelper.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CThreadHelper.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../SDL_Extensions.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../SDL_framerate.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../SDL_framerate.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../StartInfo.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../global.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CAbilityHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../hch/CAbilityHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CAmbarCendamo.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CArtHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CBuildingHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CDefHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../hch/CDefHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CHeroHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CMusicHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../hch/CMusicHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CObjectHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../hch/CObjectHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CSndHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../hch/CSndHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CSpellHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../int3.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../map.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../mapHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../mapHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../nodrze.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../stdafx.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../timeHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../CBitmapHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../CBitmapHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../CConfigHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../CConfigHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../CCreatureAnimation.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../CCreatureAnimation.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../CSpellWindow.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../CSpellWindow.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../Client.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../Client.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../FunctionList.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../Graphics.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../Graphics.h">
+        <itemTool>3</itemTool>
+      </item>
+    </conf>
+    <conf name="Release" type="1">
+      <toolsSet>
+        <developmentServer>localhost</developmentServer>
+        <compilerSet>GNU|GNU</compilerSet>
+        <platform>2</platform>
+      </toolsSet>
+      <compileType>
+        <cCompilerTool>
+          <developmentMode>5</developmentMode>
+        </cCompilerTool>
+        <ccCompilerTool>
+          <developmentMode>5</developmentMode>
+        </ccCompilerTool>
+        <fortranCompilerTool>
+          <developmentMode>5</developmentMode>
+        </fortranCompilerTool>
+        <linkerTool>
+          <linkerLibItems>
+          </linkerLibItems>
+        </linkerTool>
+      </compileType>
+      <item path="../../AI_Base.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../AdventureMapButton.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../AdventureMapButton.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CAdvmapInterface.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CAdvmapInterface.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CBattleInterface.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CBattleInterface.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CCallback.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CCallback.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CCastleInterface.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CCastleInterface.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CCursorHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CCursorHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CGameInfo.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CGameInfo.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CGameInterface.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CGameInterface.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CHeroWindow.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CHeroWindow.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CLuaHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CLuaHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CMT.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CMessage.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CMessage.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CPathfinder.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CPathfinder.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CPlayerInterface.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CPlayerInterface.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CPreGame.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CPreGame.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../CThreadHelper.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../CThreadHelper.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../SDL_Extensions.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../SDL_framerate.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../SDL_framerate.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../StartInfo.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../global.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CAbilityHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../hch/CAbilityHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CAmbarCendamo.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CArtHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CBuildingHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CDefHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../hch/CDefHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CHeroHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CMusicHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../hch/CMusicHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CObjectHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../hch/CObjectHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CSndHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../hch/CSndHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../hch/CSpellHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../int3.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../map.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../mapHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../../mapHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../nodrze.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../stdafx.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../../timeHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../CBitmapHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../CBitmapHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../CConfigHandler.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../CConfigHandler.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../CCreatureAnimation.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../CCreatureAnimation.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../CSpellWindow.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../CSpellWindow.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../Client.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../Client.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../FunctionList.h">
+        <itemTool>3</itemTool>
+      </item>
+      <item path="../Graphics.cpp">
+        <itemTool>1</itemTool>
+      </item>
+      <item path="../Graphics.h">
+        <itemTool>3</itemTool>
+      </item>
+    </conf>
+  </confs>
+</configurationDescriptor>

+ 37 - 0
client/vcmi_client/nbproject/private/configurations.xml

@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configurationDescriptor version="51">
+  <projectmakefile>Makefile</projectmakefile>
+  <defaultConf>0</defaultConf>
+  <confs>
+    <conf name="Debug" type="1">
+      <gdbdebugger version="2">
+        <gdb_command>gdb</gdb_command>
+        <array_repeat_threshold>10</array_repeat_threshold>
+      </gdbdebugger>
+      <runprofile version="5">
+        <args></args>
+        <rundir></rundir>
+        <buildfirst>true</buildfirst>
+        <console-type>0</console-type>
+        <terminal-type>0</terminal-type>
+        <environment>
+        </environment>
+      </runprofile>
+    </conf>
+    <conf name="Release" type="1">
+      <gdbdebugger version="2">
+        <gdb_command>gdb</gdb_command>
+        <array_repeat_threshold>10</array_repeat_threshold>
+      </gdbdebugger>
+      <runprofile version="5">
+        <args></args>
+        <rundir></rundir>
+        <buildfirst>true</buildfirst>
+        <console-type>0</console-type>
+        <terminal-type>0</terminal-type>
+        <environment>
+        </environment>
+      </runprofile>
+    </conf>
+  </confs>
+</configurationDescriptor>

+ 0 - 0
client/vcmi_client/nbproject/private/private.properties


+ 26 - 0
client/vcmi_client/nbproject/private/private.xml

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
+    <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1">
+        <file>
+            <url>file:/home/t0/vcmi/trunk/client/vcmi_client/../../hch/CMusicHandler.cpp</url>
+            <line>67</line>
+        </file>
+        <file>
+            <url>file:/home/t0/vcmi/trunk/CPreGame.h</url>
+            <line>272</line>
+        </file>
+        <file>
+            <url>file:/home/t0/vcmi/trunk/client/vcmi_client/../CSpellWindow.cpp</url>
+            <line>638</line>
+        </file>
+        <file>
+            <url>file:/home/t0/vcmi/trunk/client/vcmi_client/../../CBattleInterface.cpp</url>
+            <line>1754</line>
+            <line>2257</line>
+        </file>
+        <file>
+            <url>file:/home/t0/vcmi/trunk/CMessage.cpp</url>
+            <line>103</line>
+        </file>
+    </editor-bookmarks>
+</project-private>

+ 0 - 0
client/vcmi_client/nbproject/project.properties


+ 17 - 0
client/vcmi_client/nbproject/project.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+    <type>org.netbeans.modules.cnd.makeproject</type>
+    <configuration>
+        <data xmlns="http://www.netbeans.org/ns/make-project/1">
+            <name>vcmi_client</name>
+            <make-project-type>0</make-project-type>
+            <c-extensions/>
+            <cpp-extensions>cpp</cpp-extensions>
+            <header-extensions>h</header-extensions>
+            <sourceEncoding>UTF-8</sourceEncoding>
+            <make-dep-projects>
+                <make-dep-project>../../lib/vcmi_lib</make-dep-project>
+            </make-dep-projects>
+        </data>
+    </configuration>
+</project>

+ 58 - 58
hch/CDefObjInfoHandler.h

@@ -1,58 +1,58 @@
-#ifndef COBJINFOECTHANDLER_H
-#define COBJINFOECTHANDLER_H
-#include <vector>
-#include <map>
-#include "../global.h"
-class CDefHandler;
-class CLodHandler;
-class DLL_EXPORT CGDefInfo
-{
-public:
-	std::string name;
-
-	unsigned char visitMap[6];
-	unsigned char blockMap[6];
-	unsigned char visitDir; //directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7)
-	int id, subid; //of object described by this defInfo
-	int terrainAllowed, //on which terrain it is possible to place object
-		 terrainMenu; //in which menus in map editor object will be showed
-	int width, height; //tiles
-	int type; //(0- ground, 1- towns, 2-creatures, 3- heroes, 4-artifacts, 5- resources)   
-	CDefHandler * handler;
-	int printPriority;
-	bool isVisitable();
-	bool operator<(const CGDefInfo& por)
-	{
-		if(id!=por.id)
-			return id<por.id;
-		else
-			return subid<por.subid;
-	}
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & name & visitMap & blockMap & visitDir & id & subid &terrainAllowed & terrainMenu & width & height & type & printPriority;
-	}
-	CGDefInfo();
-};
-class DLL_EXPORT CDefObjInfoHandler
-{
-public:
-	std::map<int,std::map<int,CGDefInfo*> > gobjs;
-	std::map<int,CGDefInfo*> castles;
-	//std::vector<DefObjInfo> objs;
-	void load();
-
-
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & gobjs;
-
-		if(!h.saving) //recrete castles map
-			for(std::map<int,std::map<int,CGDefInfo*> >::iterator i=gobjs.begin(); i!=gobjs.end(); i++)
-				for(std::map<int,CGDefInfo*>::iterator j=i->second.begin(); j!=i->second.end(); j++)
-					if(j->second->id == 98)
-						castles[j->second->subid]=j->second;
-	}
-};
-
-#endif //COBJINFOECTHANDLER_H
+#ifndef __CDEFOBJINFOHANDLER_H__
+#define __CDEFOBJINFOHANDLER_H__
+#include <vector>
+#include <map>
+#include "../global.h"
+class CDefHandler;
+class CLodHandler;
+class DLL_EXPORT CGDefInfo
+{
+public:
+	std::string name;
+
+	unsigned char visitMap[6];
+	unsigned char blockMap[6];
+	unsigned char visitDir; //directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7)
+	int id, subid; //of object described by this defInfo
+	int terrainAllowed, //on which terrain it is possible to place object
+		 terrainMenu; //in which menus in map editor object will be showed
+	int width, height; //tiles
+	int type; //(0- ground, 1- towns, 2-creatures, 3- heroes, 4-artifacts, 5- resources)   
+	CDefHandler * handler;
+	int printPriority;
+	bool isVisitable();
+	bool operator<(const CGDefInfo& por)
+	{
+		if(id!=por.id)
+			return id<por.id;
+		else
+			return subid<por.subid;
+	}
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & name & visitMap & blockMap & visitDir & id & subid &terrainAllowed & terrainMenu & width & height & type & printPriority;
+	}
+	CGDefInfo();
+};
+class DLL_EXPORT CDefObjInfoHandler
+{
+public:
+	std::map<int,std::map<int,CGDefInfo*> > gobjs;
+	std::map<int,CGDefInfo*> castles;
+	//std::vector<DefObjInfo> objs;
+	void load();
+
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & gobjs;
+
+		if(!h.saving) //recrete castles map
+			for(std::map<int,std::map<int,CGDefInfo*> >::iterator i=gobjs.begin(); i!=gobjs.end(); i++)
+				for(std::map<int,CGDefInfo*>::iterator j=i->second.begin(); j!=i->second.end(); j++)
+					if(j->second->id == 98)
+						castles[j->second->subid]=j->second;
+	}
+};
+
+#endif // __CDEFOBJINFOHANDLER_H__

+ 150 - 150
hch/CVideoHandler.h

@@ -1,150 +1,150 @@
-#ifndef CVIDEOHANDLEER_H
-#define CVIDEOHANDLEER_H
-
-#include <stdio.h>
-#ifdef WIN32
-#include <windows.h>
-#else
-#include <dlfcn.h>
-#endif
-
-//
-#define BINKNOTHREADEDIO 0x00800000
-//
-//  protected
-//    FLib: HINST;
-//    FLibName: string;
-//    FFileHandle: HFile;
-//    function GetCurrentFrame: int; virtual; abstract;
-//    function GetFramesCount: int; virtual; abstract;
-//    procedure SetCurrentFrame(v: int); virtual; abstract;
-//    procedure DoOpen(FileHandle: hFile); virtual; abstract;
-//    function NormalizeFrame(i:int):int;
-//    procedure SetPause(v:Boolean); virtual; abstract;
-//
-//    procedure LoadProc(var Proc:Pointer; const ProcName:string);
-//  public
-//    Width:pint;
-//    Height:pint;
-//    constructor Create(const LibName:string);
-//    destructor Destroy; override;
-//    procedure Open(FileHandle:hFile); overload;
-//    procedure Open(FileName:string); overload;
-////    procedure Open(FileData:TRSByteArray); overload;
-//    procedure SetVolume(i: int); virtual;
-//    procedure Close; virtual;
-//    procedure NextFrame; virtual; abstract;
-//    procedure PreparePic(b:TBitmap); virtual;
-//    procedure GotoFrame(Index:int; b:TBitmap); virtual;
-//    function ExtractFrame(b:TBitmap = nil):TBitmap; virtual; abstract;
-//    function Wait:Boolean; virtual; abstract;
-//      // Workaround for Bink and Smack thread synchronization bug
-//    property Frame: int read GetCurrentFrame write SetCurrentFrame;
-//    property FramesCount: int read GetFramesCount;
-//    property LibInstance: HINST read FLib;
-//    property Pause: Boolean write SetPause;
-
-  //TRSSmkStruct = packed record
-  //  Version: int;
-  //  Width: int;
-  //  Height: int;
-  //  FrameCount: int;
-  //  mspf: int;
-  //  Unk1: array[0..87] of byte;
-  //  Palette: array[0..775] of byte;
-  //  CurrentFrame: int; // Starting with 0
-  //   // 72 - Øèï
-  //   // 1060 - interesting
-  //   // 1100 - Mute:Bool
-  //end;
-
-  //TRSBinkStruct = packed record
-  //  Width: int;
-  //  Height: int;
-  //  FrameCount: int;
-  //  CurrentFrame: int; // Starting with 1
-  //  LastFrame: int;
-  //  FPSMul: int; // frames/second multiplier
-  //  FPSDiv: int; // frames/second divisor
-  //  Unk1: int;
-  //  Flags: int;
-  //  Unk2: array[0..259] of byte;
-  //  CurrentPlane: int;
-  //  Plane1: ptr;
-  //  Plane2: ptr;
-  //  Unk3: array[0..1] of int;
-  //  YPlaneWidth: int;
-  //  YPlaneHeight: int;
-  //  UVPlaneWidth: int;
-  //  UVPlaneHeight: int;
-  //end;
-typedef struct
-{
-	int width;
-	int height;
-	int frameCount;
-	int currentFrame;
-	int lastFrame;
-	int FPSMul;
-	int FPSDiv;
-	int unknown0;
-	unsigned char flags;
-	unsigned char unknown1[260];
-	int CurPlane;		// current plane
-	void *plane0;		// pointer to plane 0
-	void *plane1;		// pointer to plane 1
-	int unknown2;
-	int unknown3;
-	int yWidth;			// Y plane width
-	int yHeight;		// Y plane height
-	int uvWidth;		// U&V plane width
-	int uvHeight;		// U&V plane height
-	int d,e,f,g,h,i;
-} BINK_STRUCT, *HBINK;
-
-struct SMKStruct
-{
-	int version, width, height, frameCount, mspf, currentFrame;
-	unsigned char unk1[88], palette[776];
-};
-
-
-
-
-class DLLHandler
-{
-public:
-#if !defined(__amigaos4__) && !defined(__unix__)
-	HINSTANCE dll;
-#else
-	void *dll;
-#endif
-	void Instantiate(const char *filename);
-	const char *GetLibExtension();
-	void *FindAddress234(const char *symbol);
-
-	virtual ~DLLHandler();
-};
-
-class CBIKHandler
-{
-public:
-	DLLHandler ourLib;
-	int newmode;
-#if !defined(__amigaos4__) && !defined(__unix__)
-	HANDLE hBinkFile;
-#else
-	void *hBinkFile;
-#endif
-	HBINK hBink;
-	BINK_STRUCT data;
-	unsigned char * buffer;
-	void * waveOutOpen, * BinkGetError, *BinkOpen, *BinkSetSoundSystem ;
-
-	int width, height;
-
-	CBIKHandler();
-	void open(std::string name);
-	void close();
-};
-#endif //CVIDEOHANDLEER_H
+#ifndef __CVIDEOHANDLER_H__
+#define __CVIDEOHANDLER_H__
+
+#include <stdio.h>
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <dlfcn.h>
+#endif
+
+//
+#define BINKNOTHREADEDIO 0x00800000
+//
+//  protected
+//    FLib: HINST;
+//    FLibName: string;
+//    FFileHandle: HFile;
+//    function GetCurrentFrame: int; virtual; abstract;
+//    function GetFramesCount: int; virtual; abstract;
+//    procedure SetCurrentFrame(v: int); virtual; abstract;
+//    procedure DoOpen(FileHandle: hFile); virtual; abstract;
+//    function NormalizeFrame(i:int):int;
+//    procedure SetPause(v:Boolean); virtual; abstract;
+//
+//    procedure LoadProc(var Proc:Pointer; const ProcName:string);
+//  public
+//    Width:pint;
+//    Height:pint;
+//    constructor Create(const LibName:string);
+//    destructor Destroy; override;
+//    procedure Open(FileHandle:hFile); overload;
+//    procedure Open(FileName:string); overload;
+////    procedure Open(FileData:TRSByteArray); overload;
+//    procedure SetVolume(i: int); virtual;
+//    procedure Close; virtual;
+//    procedure NextFrame; virtual; abstract;
+//    procedure PreparePic(b:TBitmap); virtual;
+//    procedure GotoFrame(Index:int; b:TBitmap); virtual;
+//    function ExtractFrame(b:TBitmap = nil):TBitmap; virtual; abstract;
+//    function Wait:Boolean; virtual; abstract;
+//      // Workaround for Bink and Smack thread synchronization bug
+//    property Frame: int read GetCurrentFrame write SetCurrentFrame;
+//    property FramesCount: int read GetFramesCount;
+//    property LibInstance: HINST read FLib;
+//    property Pause: Boolean write SetPause;
+
+  //TRSSmkStruct = packed record
+  //  Version: int;
+  //  Width: int;
+  //  Height: int;
+  //  FrameCount: int;
+  //  mspf: int;
+  //  Unk1: array[0..87] of byte;
+  //  Palette: array[0..775] of byte;
+  //  CurrentFrame: int; // Starting with 0
+  //   // 72 - Øèï
+  //   // 1060 - interesting
+  //   // 1100 - Mute:Bool
+  //end;
+
+  //TRSBinkStruct = packed record
+  //  Width: int;
+  //  Height: int;
+  //  FrameCount: int;
+  //  CurrentFrame: int; // Starting with 1
+  //  LastFrame: int;
+  //  FPSMul: int; // frames/second multiplier
+  //  FPSDiv: int; // frames/second divisor
+  //  Unk1: int;
+  //  Flags: int;
+  //  Unk2: array[0..259] of byte;
+  //  CurrentPlane: int;
+  //  Plane1: ptr;
+  //  Plane2: ptr;
+  //  Unk3: array[0..1] of int;
+  //  YPlaneWidth: int;
+  //  YPlaneHeight: int;
+  //  UVPlaneWidth: int;
+  //  UVPlaneHeight: int;
+  //end;
+typedef struct
+{
+	int width;
+	int height;
+	int frameCount;
+	int currentFrame;
+	int lastFrame;
+	int FPSMul;
+	int FPSDiv;
+	int unknown0;
+	unsigned char flags;
+	unsigned char unknown1[260];
+	int CurPlane;		// current plane
+	void *plane0;		// pointer to plane 0
+	void *plane1;		// pointer to plane 1
+	int unknown2;
+	int unknown3;
+	int yWidth;			// Y plane width
+	int yHeight;		// Y plane height
+	int uvWidth;		// U&V plane width
+	int uvHeight;		// U&V plane height
+	int d,e,f,g,h,i;
+} BINK_STRUCT, *HBINK;
+
+struct SMKStruct
+{
+	int version, width, height, frameCount, mspf, currentFrame;
+	unsigned char unk1[88], palette[776];
+};
+
+
+
+
+class DLLHandler
+{
+public:
+#if !defined(__amigaos4__) && !defined(__unix__)
+	HINSTANCE dll;
+#else
+	void *dll;
+#endif
+	void Instantiate(const char *filename);
+	const char *GetLibExtension();
+	void *FindAddress234(const char *symbol);
+
+	virtual ~DLLHandler();
+};
+
+class CBIKHandler
+{
+public:
+	DLLHandler ourLib;
+	int newmode;
+#if !defined(__amigaos4__) && !defined(__unix__)
+	HANDLE hBinkFile;
+#else
+	void *hBinkFile;
+#endif
+	HBINK hBink;
+	BINK_STRUCT data;
+	unsigned char * buffer;
+	void * waveOutOpen, * BinkGetError, *BinkOpen, *BinkSetSoundSystem ;
+
+	int width, height;
+
+	CBIKHandler();
+	void open(std::string name);
+	void close();
+};
+#endif // __CVIDEOHANDLER_H__

+ 14 - 13
lib/BattleAction.h

@@ -1,13 +1,14 @@
-#pragma once
-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 = Cancel BattleAction   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)
-	ui16 destinationTile;
-	si32 additionalInfo; // e.g. spell number if type is 1 || 10; tile to attack if type is 6
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & side & stackNumber & actionType & destinationTile & additionalInfo;
-	}
-};
+#ifndef __BATTLEACTION_H__
+#define __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 = Cancel BattleAction   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)
+	ui16 destinationTile;
+	si32 additionalInfo; // e.g. spell number if type is 1 || 10; tile to attack if type is 6
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & side & stackNumber & actionType & destinationTile & additionalInfo;
+	}
+};#endif // __BATTLEACTION_H__

+ 14 - 13
lib/CondSh.h

@@ -1,13 +1,14 @@
-#pragma once
-#include <boost/thread.hpp>
-template <typename T> 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<boost::mutex> lock(mx); return data;};
-};
+#ifndef __CONDSH_H__
+#define __CONDSH_H__
+#include <boost/thread.hpp>
+template <typename T> 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<boost::mutex> lock(mx); return data;};
+};#endif // __CONDSH_H__

+ 416 - 417
lib/Connection.h

@@ -1,417 +1,416 @@
-#ifndef CONNECTION_H
-#define CONNECTION_H
-#pragma once
-#include "../global.h"
-#include <string>
-#include <vector>
-#include <set>
-
-#include <boost/type_traits/is_fundamental.hpp>
-#include <boost/type_traits/is_enum.hpp>
-#include <boost/type_traits/is_pointer.hpp> 
-#include <boost/type_traits/is_class.hpp> 
-#include  <boost/type_traits/remove_pointer.hpp>
-
-#include <boost/mpl/eval_if.hpp>
-#include <boost/mpl/equal_to.hpp>
-#include <boost/mpl/int.hpp>
-#include <boost/mpl/identity.hpp>
-
-#include <boost/type_traits/is_array.hpp>
-const int version = 63;
-class CConnection;
-
-namespace mpl = boost::mpl;
-
-namespace boost
-{
-	namespace asio
-	{
-		namespace ip
-		{
-			class tcp;
-		}
-		class io_service;
-
-		template <typename Protocol> class stream_socket_service;
-		template <typename Protocol,typename StreamSocketService>
-		class basic_stream_socket;
-
-		template <typename Protocol> class socket_acceptor_service;
-		template <typename Protocol,typename SocketAcceptorService>
-		class basic_socket_acceptor;
-	}
-	class mutex;
-};
-
-enum SerializationLvl
-{
-	Wrong=0,
-	Primitive,
-	Pointer,
-	Serializable
-};
-
-template<typename Ser,typename T>
-struct SavePrimitive
-{
-	static void invoke(Ser &s, const T &data)
-	{
-		s.savePrimitive(data);
-	}
-};
-template<typename Ser,typename T>
-struct SaveSerializable
-{
-	static void invoke(Ser &s, const T &data)
-	{
-		s.saveSerializable(data);
-	}
-};
-template<typename Ser,typename T>
-struct LoadPrimitive
-{
-	static void invoke(Ser &s, T &data)
-	{
-		s.loadPrimitive(data);
-	}
-};
-template<typename Ser,typename T>
-struct SavePointer
-{
-	static void invoke(Ser &s, const T &data)
-	{
-		s.savePointer(data);
-	}
-};
-template<typename Ser,typename T>
-struct LoadPointer
-{
-	static void invoke(Ser &s, T &data)
-	{
-		s.loadPointer(data);
-	}
-};
-template<typename Ser,typename T>
-struct LoadSerializable
-{
-	static void invoke(Ser &s, T &data)
-	{
-		s.loadSerializable(data);
-	}
-};
-
-template<typename Ser,typename T>
-struct SaveWrong
-{
-	static void invoke(Ser &s, const T &data)
-	{
-		throw std::exception("Wrong save serialization call!");
-	}
-};
-template<typename Ser,typename T>
-struct LoadWrong
-{
-	static void invoke(Ser &s, const T &data)
-	{
-		throw std::exception("Wrong load serialization call!");
-	}
-};
-
-template<typename T>
-struct SerializationLevel
-{    
-	typedef mpl::integral_c_tag tag;
-	typedef
-		typename mpl::eval_if<
-			boost::is_fundamental<T>,
-			mpl::int_<Primitive>,
-		//else
-		typename mpl::eval_if<
-			boost::is_class<T>,
-			mpl::int_<Serializable>,
-		//else
-		typename mpl::eval_if<
-			boost::is_array<T>,
-			mpl::int_<Primitive>,
-		//else
-		typename mpl::eval_if<
-			boost::is_pointer<T>,
-			mpl::int_<Pointer>,
-		//else
-		typename mpl::eval_if<
-			boost::is_enum<T>,
-			mpl::int_<Primitive>,
-		//else
-			mpl::int_<Wrong>
-		>
-		>
-		>
-		>
-		>::type type;
-	static const int value = SerializationLevel::type::value;
-};
-
-template <typename Serializer> class DLL_EXPORT COSer
-{
-public:
-	bool saving;
-	COSer(){saving=true;};
-    Serializer * This()
-	{
-		return static_cast<Serializer*>(this);
-	}
-
-	template<class T>
-	Serializer & operator<<(const T &t)
-	{
-		this->This()->save(t);
-		return * this->This();
-	}
-	
-	template<class T>
-	COSer & operator&(T & t)
-	{
-		return * this->This() << t;
-	}	
-	
-
-
-	int write(const void * data, unsigned size);
-	template <typename T>
-	void savePrimitive(const T &data)
-	{
-		this->This()->write(&data,sizeof(data));
-	}
-	template <typename T>
-	void savePointer(const T &data)
-	{
-		*this << *data;
-	}
-	template <typename T>
-	void save(const T &data)
-	{
-		typedef 
-			//if
-			typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Primitive> >,
-			mpl::identity<SavePrimitive<Serializer,T> >,
-			//else if
-			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Pointer> >,
-			mpl::identity<SavePointer<Serializer,T> >,
-			//else if
-			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Serializable> >,
-			mpl::identity<SaveSerializable<Serializer,T> >,
-			//else
-			mpl::identity<SaveWrong<Serializer,T> >
-			>
-			>
-			>::type typex;
-		typex::invoke(* this->This(), data);
-	}
-	template <typename T>
-	void saveSerializable(const T &data)
-	{
-		const_cast<T&>(data).serialize(*this,version);
-	}
-	template <typename T>
-	void saveSerializable(const std::vector<T> &data)
-	{
-		boost::uint32_t length = data.size();
-		*this << length;
-		for(ui32 i=0;i<length;i++)
-			*this << data[i];
-	}
-	template <typename T>
-	void saveSerializable(const std::set<T> &data)
-	{
-		std::set<T> &d = const_cast<std::set<T> &>(data);
-		boost::uint32_t length = d.size();
-		*this << length;
-		for(typename std::set<T>::iterator i=d.begin();i!=d.end();i++)
-			*this << *i;
-	}
-	void saveSerializable(const std::string &data)
-	{
-		if(!data.length())
-		{
-			*this << ui8(0);
-		}
-		else
-		{
-			*this << ui32(data.length());
-			this->This()->write(data.c_str(),data.size());
-		}
-	}
-	template <typename T1, typename T2>
-	void saveSerializable(const std::pair<T1,T2> &data)
-	{
-		*this << data.first << data.second;
-	}
-	template <typename T1, typename T2>
-	void saveSerializable(const std::map<T1,T2> &data)
-	{
-		*this << ui32(data.size());
-		for(typename std::map<T1,T2>::const_iterator i=data.begin();i!=data.end();i++)
-			*this << i->first << i->second;
-	}
-};
-template <typename Serializer> class DLL_EXPORT CISer
-{
-public:
-	bool saving;
-	CISer(){saving = false;};
-    Serializer * This()
-	{
-		return static_cast<Serializer*>(this);
-	}
-
-	template<class T>
-	Serializer & operator>>(T &t)
-	{
-		this->This()->load(t);
-		return * this->This();
-	}
-	
-	template<class T>
-	CISer & operator&(T & t)
-	{
-		return * this->This() >> t;
-	}	
-
-	int write(const void * data, unsigned size);
-	template <typename T>
-	void load(T &data)
-	{
-		typedef 
-			//if
-			typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Primitive> >,
-			mpl::identity<LoadPrimitive<Serializer,T> >,
-			//else if
-			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Pointer> >,
-			mpl::identity<LoadPointer<Serializer,T> >,
-			//else if
-			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Serializable> >,
-			mpl::identity<LoadSerializable<Serializer,T> >,
-			//else
-			mpl::identity<LoadWrong<Serializer,T> >
-			>
-			>
-			>::type typex;
-		typex::invoke(* this->This(), data);
-	}
-	template <typename T>
-	void loadPrimitive(T &data)
-	{
-		this->This()->read(&data,sizeof(data));
-	}
-	template <typename T>
-	void loadSerializable(T &data)
-	{
-		data.serialize(*this,version);
-	}	
-	template <typename T>
-	void loadPointer(T &data)
-	{
-		tlog5<<"Allocating memory for pointer!"<<std::endl;
-		typedef typename boost::remove_pointer<T>::type npT;
-		data = new npT;
-		*this >> *data;
-	}
-	template <typename T>
-	void loadSerializable(std::vector<T> &data)
-	{
-		boost::uint32_t length;
-		*this >> length;
-		data.resize(length);
-		for(ui32 i=0;i<length;i++)
-			*this >> data[i];
-	}
-	template <typename T>
-	void loadSerializable(std::set<T> &data)
-	{
-		boost::uint32_t length;
-		*this >> length;
-		T ins;
-		for(ui32 i=0;i<length;i++)
-		{
-			*this >> ins;
-			data.insert(ins);
-		}
-	}
-	template <typename T1, typename T2>
-	void loadSerializable(std::pair<T1,T2> &data)
-	{
-		*this >> data.first >> data.second;
-	}
-
-	template <typename T1, typename T2>
-	void loadSerializable(std::map<T1,T2> &data)
-	{
-		ui32 length;
-		*this >> length;
-		T1 t;
-		for(int i=0;i<length;i++)
-		{
-			*this >> t;
-			*this >> data[t];
-		}
-	}
-	void loadSerializable(std::string &data)
-	{
-		ui8 length[4];
-		*this >> length[0];
-		if(!length[0]) return;
-		*this >> length[1];
-		*this >> length[2];
-		*this >> length[3];
-		data.resize(*((ui32*)length));
-		this->This()->read((void*)data.c_str(),*((ui32*)length));
-	}
-
-};
-
-
-class DLL_EXPORT CSaveFile
-	: public COSer<CSaveFile>
-{
-	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 CConnection
-	:public CISer<CConnection>, public COSer<CConnection>
-{
-	std::ostream &out;
-	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<boost::asio::ip::tcp>  > * 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, std::ostream & Out);
-	CConnection
-		(boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::socket_acceptor_service<boost::asio::ip::tcp> > * acceptor, 
-		boost::asio::io_service *Io_service, std::string Name, std::ostream & Out);
-	CConnection
-		(boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service<boost::asio::ip::tcp>  > * Socket, 
-		std::string Name, std::ostream & Out); //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();
-	~CConnection(void);
-};
-#endif //CONNECTION_H
+#ifndef CONNECTION_H
+#define CONNECTION_H
+#include "../global.h"
+#include <string>
+#include <vector>
+#include <set>
+
+#include <boost/type_traits/is_fundamental.hpp>
+#include <boost/type_traits/is_enum.hpp>
+#include <boost/type_traits/is_pointer.hpp> 
+#include <boost/type_traits/is_class.hpp> 
+#include  <boost/type_traits/remove_pointer.hpp>
+
+#include <boost/mpl/eval_if.hpp>
+#include <boost/mpl/equal_to.hpp>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/identity.hpp>
+
+#include <boost/type_traits/is_array.hpp>
+const int version = 63;
+class CConnection;
+
+namespace mpl = boost::mpl;
+
+namespace boost
+{
+	namespace asio
+	{
+		namespace ip
+		{
+			class tcp;
+		}
+		class io_service;
+
+		template <typename Protocol> class stream_socket_service;
+		template <typename Protocol,typename StreamSocketService>
+		class basic_stream_socket;
+
+		template <typename Protocol> class socket_acceptor_service;
+		template <typename Protocol,typename SocketAcceptorService>
+		class basic_socket_acceptor;
+	}
+	class mutex;
+};
+
+enum SerializationLvl
+{
+	Wrong=0,
+	Primitive,
+	Pointer,
+	Serializable
+};
+
+template<typename Ser,typename T>
+struct SavePrimitive
+{
+	static void invoke(Ser &s, const T &data)
+	{
+		s.savePrimitive(data);
+	}
+};
+template<typename Ser,typename T>
+struct SaveSerializable
+{
+	static void invoke(Ser &s, const T &data)
+	{
+		s.saveSerializable(data);
+	}
+};
+template<typename Ser,typename T>
+struct LoadPrimitive
+{
+	static void invoke(Ser &s, T &data)
+	{
+		s.loadPrimitive(data);
+	}
+};
+template<typename Ser,typename T>
+struct SavePointer
+{
+	static void invoke(Ser &s, const T &data)
+	{
+		s.savePointer(data);
+	}
+};
+template<typename Ser,typename T>
+struct LoadPointer
+{
+	static void invoke(Ser &s, T &data)
+	{
+		s.loadPointer(data);
+	}
+};
+template<typename Ser,typename T>
+struct LoadSerializable
+{
+	static void invoke(Ser &s, T &data)
+	{
+		s.loadSerializable(data);
+	}
+};
+
+template<typename Ser,typename T>
+struct SaveWrong
+{
+	static void invoke(Ser &s, const T &data)
+	{
+		throw std::exception("Wrong save serialization call!");
+	}
+};
+template<typename Ser,typename T>
+struct LoadWrong
+{
+	static void invoke(Ser &s, const T &data)
+	{
+		throw std::exception("Wrong load serialization call!");
+	}
+};
+
+template<typename T>
+struct SerializationLevel
+{    
+	typedef mpl::integral_c_tag tag;
+	typedef
+		typename mpl::eval_if<
+			boost::is_fundamental<T>,
+			mpl::int_<Primitive>,
+		//else
+		typename mpl::eval_if<
+			boost::is_class<T>,
+			mpl::int_<Serializable>,
+		//else
+		typename mpl::eval_if<
+			boost::is_array<T>,
+			mpl::int_<Primitive>,
+		//else
+		typename mpl::eval_if<
+			boost::is_pointer<T>,
+			mpl::int_<Pointer>,
+		//else
+		typename mpl::eval_if<
+			boost::is_enum<T>,
+			mpl::int_<Primitive>,
+		//else
+			mpl::int_<Wrong>
+		>
+		>
+		>
+		>
+		>::type type;
+	static const int value = SerializationLevel::type::value;
+};
+
+template <typename Serializer> class DLL_EXPORT COSer
+{
+public:
+	bool saving;
+	COSer(){saving=true;};
+    Serializer * This()
+	{
+		return static_cast<Serializer*>(this);
+	}
+
+	template<class T>
+	Serializer & operator<<(const T &t)
+	{
+		this->This()->save(t);
+		return * this->This();
+	}
+	
+	template<class T>
+	COSer & operator&(T & t)
+	{
+		return * this->This() << t;
+	}	
+	
+
+
+	int write(const void * data, unsigned size);
+	template <typename T>
+	void savePrimitive(const T &data)
+	{
+		this->This()->write(&data,sizeof(data));
+	}
+	template <typename T>
+	void savePointer(const T &data)
+	{
+		*this << *data;
+	}
+	template <typename T>
+	void save(const T &data)
+	{
+		typedef 
+			//if
+			typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Primitive> >,
+			mpl::identity<SavePrimitive<Serializer,T> >,
+			//else if
+			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Pointer> >,
+			mpl::identity<SavePointer<Serializer,T> >,
+			//else if
+			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Serializable> >,
+			mpl::identity<SaveSerializable<Serializer,T> >,
+			//else
+			mpl::identity<SaveWrong<Serializer,T> >
+			>
+			>
+			>::type typex;
+		typex::invoke(* this->This(), data);
+	}
+	template <typename T>
+	void saveSerializable(const T &data)
+	{
+		const_cast<T&>(data).serialize(*this,version);
+	}
+	template <typename T>
+	void saveSerializable(const std::vector<T> &data)
+	{
+		boost::uint32_t length = data.size();
+		*this << length;
+		for(ui32 i=0;i<length;i++)
+			*this << data[i];
+	}
+	template <typename T>
+	void saveSerializable(const std::set<T> &data)
+	{
+		std::set<T> &d = const_cast<std::set<T> &>(data);
+		boost::uint32_t length = d.size();
+		*this << length;
+		for(typename std::set<T>::iterator i=d.begin();i!=d.end();i++)
+			*this << *i;
+	}
+	void saveSerializable(const std::string &data)
+	{
+		if(!data.length())
+		{
+			*this << ui8(0);
+		}
+		else
+		{
+			*this << ui32(data.length());
+			this->This()->write(data.c_str(),data.size());
+		}
+	}
+	template <typename T1, typename T2>
+	void saveSerializable(const std::pair<T1,T2> &data)
+	{
+		*this << data.first << data.second;
+	}
+	template <typename T1, typename T2>
+	void saveSerializable(const std::map<T1,T2> &data)
+	{
+		*this << ui32(data.size());
+		for(typename std::map<T1,T2>::const_iterator i=data.begin();i!=data.end();i++)
+			*this << i->first << i->second;
+	}
+};
+template <typename Serializer> class DLL_EXPORT CISer
+{
+public:
+	bool saving;
+	CISer(){saving = false;};
+    Serializer * This()
+	{
+		return static_cast<Serializer*>(this);
+	}
+
+	template<class T>
+	Serializer & operator>>(T &t)
+	{
+		this->This()->load(t);
+		return * this->This();
+	}
+	
+	template<class T>
+	CISer & operator&(T & t)
+	{
+		return * this->This() >> t;
+	}	
+
+	int write(const void * data, unsigned size);
+	template <typename T>
+	void load(T &data)
+	{
+		typedef 
+			//if
+			typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Primitive> >,
+			mpl::identity<LoadPrimitive<Serializer,T> >,
+			//else if
+			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Pointer> >,
+			mpl::identity<LoadPointer<Serializer,T> >,
+			//else if
+			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Serializable> >,
+			mpl::identity<LoadSerializable<Serializer,T> >,
+			//else
+			mpl::identity<LoadWrong<Serializer,T> >
+			>
+			>
+			>::type typex;
+		typex::invoke(* this->This(), data);
+	}
+	template <typename T>
+	void loadPrimitive(T &data)
+	{
+		this->This()->read(&data,sizeof(data));
+	}
+	template <typename T>
+	void loadSerializable(T &data)
+	{
+		data.serialize(*this,version);
+	}	
+	template <typename T>
+	void loadPointer(T &data)
+	{
+		tlog5<<"Allocating memory for pointer!"<<std::endl;
+		typedef typename boost::remove_pointer<T>::type npT;
+		data = new npT;
+		*this >> *data;
+	}
+	template <typename T>
+	void loadSerializable(std::vector<T> &data)
+	{
+		boost::uint32_t length;
+		*this >> length;
+		data.resize(length);
+		for(ui32 i=0;i<length;i++)
+			*this >> data[i];
+	}
+	template <typename T>
+	void loadSerializable(std::set<T> &data)
+	{
+		boost::uint32_t length;
+		*this >> length;
+		T ins;
+		for(ui32 i=0;i<length;i++)
+		{
+			*this >> ins;
+			data.insert(ins);
+		}
+	}
+	template <typename T1, typename T2>
+	void loadSerializable(std::pair<T1,T2> &data)
+	{
+		*this >> data.first >> data.second;
+	}
+
+	template <typename T1, typename T2>
+	void loadSerializable(std::map<T1,T2> &data)
+	{
+		ui32 length;
+		*this >> length;
+		T1 t;
+		for(int i=0;i<length;i++)
+		{
+			*this >> t;
+			*this >> data[t];
+		}
+	}
+	void loadSerializable(std::string &data)
+	{
+		ui8 length[4];
+		*this >> length[0];
+		if(!length[0]) return;
+		*this >> length[1];
+		*this >> length[2];
+		*this >> length[3];
+		data.resize(*((ui32*)length));
+		this->This()->read((void*)data.c_str(),*((ui32*)length));
+	}
+
+};
+
+
+class DLL_EXPORT CSaveFile
+	: public COSer<CSaveFile>
+{
+	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 CConnection
+	:public CISer<CConnection>, public COSer<CConnection>
+{
+	std::ostream &out;
+	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<boost::asio::ip::tcp>  > * 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, std::ostream & Out);
+	CConnection
+		(boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::socket_acceptor_service<boost::asio::ip::tcp> > * acceptor, 
+		boost::asio::io_service *Io_service, std::string Name, std::ostream & Out);
+	CConnection
+		(boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service<boost::asio::ip::tcp>  > * Socket, 
+		std::string Name, std::ostream & Out); //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();
+	~CConnection(void);
+};
+#endif //CONNECTION_H

+ 53 - 52
lib/IGameCallback.h

@@ -1,52 +1,53 @@
-#pragma once
-
-#include "../global.h"
-#include <vector>
-#include <set>
-#include "../client/FunctionList.h"
-
-class CGObjectInstance;
-class CGTownInstance;
-class CGHeroInstance;
-struct SelectionDialog;
-struct YesNoDialog;
-struct InfoWindow;
-struct MetaString;
-struct ShowInInfobox;
-struct BattleResult;
-
-class IGameCallback
-{
-public:
-	virtual ~IGameCallback(){};
-
-	virtual int getOwner(int heroID)=0;
-	virtual int getResource(int player, int which)=0;
-	virtual int getSelectedHero()=0;
-	virtual int getDate(int mode=0)=0;
-	virtual const CGObjectInstance* getObj(int objid)=0;
-	virtual const CGHeroInstance* getHero(int objid)=0;
-	virtual const CGTownInstance* getTown(int objid)=0;
-	virtual const CGHeroInstance* getSelectedHero(int player)=0; //NULL if no hero is selected
-	virtual int getCurrentPlayer()=0;
-
-	//do sth
-	virtual void changeSpells(int hid, bool give, const std::set<ui32> &spells)=0;
-	virtual void removeObject(int objid)=0;
-	virtual void setBlockVis(int objid, bool bv)=0;
-	virtual void setOwner(int objid, ui8 owner)=0;
-	virtual void setHoverName(int objid, MetaString * name)=0;
-	virtual void changePrimSkill(int ID, int which, int val, bool abs=false)=0;
-	virtual void showInfoDialog(InfoWindow *iw)=0;
-	virtual void showYesNoDialog(YesNoDialog *iw, const CFunctionList<void(ui32)> &callback)=0;
-	virtual void showSelectionDialog(SelectionDialog *iw, const CFunctionList<void(ui32)> &callback)=0; //returns question id
-	virtual void giveResource(int player, int which, int val)=0;
-	virtual void showCompInfo(ShowInInfobox * comp)=0;
-	virtual void heroVisitCastle(int obj, int heroID)=0;
-	virtual void stopHeroVisitCastle(int obj, int heroID)=0;
-	virtual void giveHeroArtifact(int artid, int hid, int position)=0; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
-	virtual void startBattleI(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb)=0; //use hero=NULL for no hero
-	virtual void startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb)=0; //for hero<=>neutral army
-	virtual void setAmount(int objid, ui32 val)=0;
-	virtual void moveHero(int hid, int3 pos, bool instant)=0;
-};
+#ifndef __IGAMECALLBACK_H__
+#define __IGAMECALLBACK_H__
+
+#include "../global.h"
+#include <vector>
+#include <set>
+#include "../client/FunctionList.h"
+
+class CGObjectInstance;
+class CGTownInstance;
+class CGHeroInstance;
+struct SelectionDialog;
+struct YesNoDialog;
+struct InfoWindow;
+struct MetaString;
+struct ShowInInfobox;
+struct BattleResult;
+
+class IGameCallback
+{
+public:
+	virtual ~IGameCallback(){};
+
+	virtual int getOwner(int heroID)=0;
+	virtual int getResource(int player, int which)=0;
+	virtual int getSelectedHero()=0;
+	virtual int getDate(int mode=0)=0;
+	virtual const CGObjectInstance* getObj(int objid)=0;
+	virtual const CGHeroInstance* getHero(int objid)=0;
+	virtual const CGTownInstance* getTown(int objid)=0;
+	virtual const CGHeroInstance* getSelectedHero(int player)=0; //NULL if no hero is selected
+	virtual int getCurrentPlayer()=0;
+
+	//do sth
+	virtual void changeSpells(int hid, bool give, const std::set<ui32> &spells)=0;
+	virtual void removeObject(int objid)=0;
+	virtual void setBlockVis(int objid, bool bv)=0;
+	virtual void setOwner(int objid, ui8 owner)=0;
+	virtual void setHoverName(int objid, MetaString * name)=0;
+	virtual void changePrimSkill(int ID, int which, int val, bool abs=false)=0;
+	virtual void showInfoDialog(InfoWindow *iw)=0;
+	virtual void showYesNoDialog(YesNoDialog *iw, const CFunctionList<void(ui32)> &callback)=0;
+	virtual void showSelectionDialog(SelectionDialog *iw, const CFunctionList<void(ui32)> &callback)=0; //returns question id
+	virtual void giveResource(int player, int which, int val)=0;
+	virtual void showCompInfo(ShowInInfobox * comp)=0;
+	virtual void heroVisitCastle(int obj, int heroID)=0;
+	virtual void stopHeroVisitCastle(int obj, int heroID)=0;
+	virtual void giveHeroArtifact(int artid, int hid, int position)=0; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
+	virtual void startBattleI(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb)=0; //use hero=NULL for no hero
+	virtual void startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb)=0; //for hero<=>neutral army
+	virtual void setAmount(int objid, ui32 val)=0;
+	virtual void moveHero(int hid, int3 pos, bool instant)=0;
+};#endif // __IGAMECALLBACK_H__

+ 92 - 0
lib/vcmi_lib/Makefile-nb

@@ -0,0 +1,92 @@
+#
+#  There exist several targets which are by default empty and which can be 
+#  used for execution of your targets. These targets are usually executed 
+#  before and after some main targets. They are: 
+#
+#     .build-pre:              called before 'build' target
+#     .build-post:             called after 'build' target
+#     .clean-pre:              called before 'clean' target
+#     .clean-post:             called after 'clean' target
+#     .clobber-pre:            called before 'clobber' target
+#     .clobber-post:           called after 'clobber' target
+#     .all-pre:                called before 'all' target
+#     .all-post:               called after 'all' target
+#     .help-pre:                called before 'help' target
+#     .help-post:               called after 'help' target
+#
+#  Targets beginning with '.' are not intended to be called on their own.
+#
+#  Main targets can be executed directly, and they are:
+#  
+#     build                    build a specific configuration
+#     clean                    remove built files from a configuration
+#     clobber                  remove all built files
+#     all                      build all configurations
+#     help                     print help mesage
+#  
+#  Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
+#  .help-impl are implemented in nbproject/makefile-impl.mk.
+#
+# NOCDDL
+
+
+# Environment 
+MKDIR=mkdir
+CP=cp
+CCADMIN=CCadmin
+RANLIB=ranlib
+
+
+# build
+build: .build-post
+
+.build-pre:
+# Add your pre 'build' code here...
+
+.build-post: .build-impl
+# Add your post 'build' code here...
+
+
+# clean
+clean: .clean-post
+
+.clean-pre:
+# Add your pre 'clean' code here...
+
+.clean-post: .clean-impl
+# Add your post 'clean' code here...
+
+
+# clobber
+clobber: .clobber-post
+
+.clobber-pre:
+# Add your pre 'clobber' code here...
+
+.clobber-post: .clobber-impl
+# Add your post 'clobber' code here...
+
+
+# all
+all: .all-post
+
+.all-pre:
+# Add your pre 'all' code here...
+
+.all-post: .all-impl
+# Add your post 'all' code here...
+
+
+# help
+help: .help-post
+
+.help-pre:
+# Add your pre 'help' code here...
+
+.help-post: .help-impl
+# Add your post 'help' code here...
+
+
+
+# include project implementation makefile
+include nbproject/Makefile-impl.mk

+ 163 - 0
lib/vcmi_lib/nbproject/Makefile-Debug.mk

@@ -0,0 +1,163 @@
+#
+# Generated Makefile - do not edit!
+#
+# Edit the Makefile in the project folder instead (../Makefile). Each target
+# has a -pre and a -post target defined where you can add customized code.
+#
+# This makefile implements configuration specific macros and targets.
+
+
+# Environment
+MKDIR=mkdir
+CP=cp
+CCADMIN=CCadmin
+RANLIB=ranlib
+CC=gcc
+CCC=g++
+CXX=g++
+FC=
+
+# Macros
+PLATFORM=GNU-Linux-x86
+
+# Include project Makefile
+include Makefile-nb
+
+# Object Directory
+OBJECTDIR=build/Debug/${PLATFORM}
+
+# Object Files
+OBJECTFILES= \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CHeroHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CTownHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../Connection.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../VCMI_Lib.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CSpellHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CCreatureHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CGameState.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CDefObjInfoHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CConsoleHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CLodHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CObjectHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CGameInfo.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CGeneralTextHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../map.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CArtHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CBuildingHandler.o
+
+# C Compiler Flags
+CFLAGS=
+
+# CC Compiler Flags
+CCFLAGS=
+CXXFLAGS=
+
+# Fortran Compiler Flags
+FFLAGS=
+
+# Link Libraries and Options
+LDLIBSOPTIONS=-L../../../../boost/lib
+
+# Build Targets
+.build-conf: ${BUILD_SUBPROJECTS}
+	${MAKE}  -f nbproject/Makefile-Debug.mk dist/Debug/${PLATFORM}/libvcmi_lib.so
+
+dist/Debug/${PLATFORM}/libvcmi_lib.so: ${OBJECTFILES}
+	${MKDIR} -p dist/Debug/${PLATFORM}
+	${LINK.cc} -shared -o dist/Debug/${PLATFORM}/libvcmi_lib.so -fPIC ${OBJECTFILES} ${LDLIBSOPTIONS} 
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CHeroHandler.o: ../../hch/CHeroHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CHeroHandler.o ../../hch/CHeroHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CTownHandler.o: ../../hch/CTownHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CTownHandler.o ../../hch/CTownHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../Connection.o: ../Connection.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../Connection.o ../Connection.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../VCMI_Lib.o: ../VCMI_Lib.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../VCMI_Lib.o ../VCMI_Lib.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CSpellHandler.o: ../../hch/CSpellHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CSpellHandler.o ../../hch/CSpellHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CCreatureHandler.o: ../../hch/CCreatureHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CCreatureHandler.o ../../hch/CCreatureHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CGameState.o: ../../CGameState.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CGameState.o ../../CGameState.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CDefObjInfoHandler.o: ../../hch/CDefObjInfoHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CDefObjInfoHandler.o ../../hch/CDefObjInfoHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CConsoleHandler.o: ../../CConsoleHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CConsoleHandler.o ../../CConsoleHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CLodHandler.o: ../../hch/CLodHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CLodHandler.o ../../hch/CLodHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CObjectHandler.o: ../../hch/CObjectHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CObjectHandler.o ../../hch/CObjectHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CGameInfo.o: ../../CGameInfo.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CGameInfo.o ../../CGameInfo.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CGeneralTextHandler.o: ../../hch/CGeneralTextHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CGeneralTextHandler.o ../../hch/CGeneralTextHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../map.o: ../../map.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../map.o ../../map.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CArtHandler.o: ../../hch/CArtHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CArtHandler.o ../../hch/CArtHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CBuildingHandler.o: ../../hch/CBuildingHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -g -I../../hch -I../.. -I../../../../boost/include/boost-1_37 -I/usr/include/SDL -I../../../../boost/include/boost-1_37/boost -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CBuildingHandler.o ../../hch/CBuildingHandler.cpp
+
+# Subprojects
+.build-subprojects:
+
+# Clean Targets
+.clean-conf:
+	${RM} -r build/Debug
+	${RM} dist/Debug/${PLATFORM}/libvcmi_lib.so
+
+# Subprojects
+.clean-subprojects:
+
+# Enable dependency checking
+.dep.inc: .depcheck-impl
+
+include .dep.inc

+ 163 - 0
lib/vcmi_lib/nbproject/Makefile-Release.mk

@@ -0,0 +1,163 @@
+#
+# Generated Makefile - do not edit!
+#
+# Edit the Makefile in the project folder instead (../Makefile). Each target
+# has a -pre and a -post target defined where you can add customized code.
+#
+# This makefile implements configuration specific macros and targets.
+
+
+# Environment
+MKDIR=mkdir
+CP=cp
+CCADMIN=CCadmin
+RANLIB=ranlib
+CC=gcc
+CCC=g++
+CXX=g++
+FC=
+
+# Macros
+PLATFORM=GNU-Linux-x86
+
+# Include project Makefile
+include Makefile-nb
+
+# Object Directory
+OBJECTDIR=build/Release/${PLATFORM}
+
+# Object Files
+OBJECTFILES= \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CHeroHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CTownHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../Connection.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../VCMI_Lib.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CSpellHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CCreatureHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CGameState.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CDefObjInfoHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CConsoleHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CLodHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CObjectHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CGameInfo.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CGeneralTextHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../map.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CArtHandler.o \
+	${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CBuildingHandler.o
+
+# C Compiler Flags
+CFLAGS=
+
+# CC Compiler Flags
+CCFLAGS=
+CXXFLAGS=
+
+# Fortran Compiler Flags
+FFLAGS=
+
+# Link Libraries and Options
+LDLIBSOPTIONS=
+
+# Build Targets
+.build-conf: ${BUILD_SUBPROJECTS}
+	${MAKE}  -f nbproject/Makefile-Release.mk dist/Release/${PLATFORM}/libvcmi_lib.so
+
+dist/Release/${PLATFORM}/libvcmi_lib.so: ${OBJECTFILES}
+	${MKDIR} -p dist/Release/${PLATFORM}
+	${LINK.cc} -shared -o dist/Release/${PLATFORM}/libvcmi_lib.so -fPIC ${OBJECTFILES} ${LDLIBSOPTIONS} 
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CHeroHandler.o: ../../hch/CHeroHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CHeroHandler.o ../../hch/CHeroHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CTownHandler.o: ../../hch/CTownHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CTownHandler.o ../../hch/CTownHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../Connection.o: ../Connection.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../Connection.o ../Connection.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../VCMI_Lib.o: ../VCMI_Lib.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../VCMI_Lib.o ../VCMI_Lib.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CSpellHandler.o: ../../hch/CSpellHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CSpellHandler.o ../../hch/CSpellHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CCreatureHandler.o: ../../hch/CCreatureHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CCreatureHandler.o ../../hch/CCreatureHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CGameState.o: ../../CGameState.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CGameState.o ../../CGameState.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CDefObjInfoHandler.o: ../../hch/CDefObjInfoHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CDefObjInfoHandler.o ../../hch/CDefObjInfoHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CConsoleHandler.o: ../../CConsoleHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CConsoleHandler.o ../../CConsoleHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CLodHandler.o: ../../hch/CLodHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CLodHandler.o ../../hch/CLodHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CObjectHandler.o: ../../hch/CObjectHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CObjectHandler.o ../../hch/CObjectHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CGameInfo.o: ../../CGameInfo.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../CGameInfo.o ../../CGameInfo.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CGeneralTextHandler.o: ../../hch/CGeneralTextHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CGeneralTextHandler.o ../../hch/CGeneralTextHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../map.o: ../../map.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../..
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../map.o ../../map.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CArtHandler.o: ../../hch/CArtHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CArtHandler.o ../../hch/CArtHandler.cpp
+
+${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CBuildingHandler.o: ../../hch/CBuildingHandler.cpp 
+	${MKDIR} -p ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch
+	${RM} [email protected]
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF [email protected] -o ${OBJECTDIR}/_ext/home/t0/vcmi/trunk/lib/vcmi_lib/../../hch/CBuildingHandler.o ../../hch/CBuildingHandler.cpp
+
+# Subprojects
+.build-subprojects:
+
+# Clean Targets
+.clean-conf:
+	${RM} -r build/Release
+	${RM} dist/Release/${PLATFORM}/libvcmi_lib.so
+
+# Subprojects
+.clean-subprojects:
+
+# Enable dependency checking
+.dep.inc: .depcheck-impl
+
+include .dep.inc

+ 123 - 0
lib/vcmi_lib/nbproject/Makefile-impl.mk

@@ -0,0 +1,123 @@
+# 
+# Generated Makefile - do not edit! 
+# 
+# Edit the Makefile in the project folder instead (../Makefile). Each target
+# has a pre- and a post- target defined where you can add customization code.
+#
+# This makefile implements macros and targets common to all configurations.
+#
+# NOCDDL
+
+
+# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
+# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
+# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
+# and .clean-reqprojects-conf unless SUB has the value 'no'
+SUB_no=NO
+SUBPROJECTS=${SUB_${SUB}}
+BUILD_SUBPROJECTS_=.build-subprojects
+BUILD_SUBPROJECTS_NO=
+BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
+CLEAN_SUBPROJECTS_=.clean-subprojects
+CLEAN_SUBPROJECTS_NO=
+CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
+
+
+# Project Name
+PROJECTNAME=vcmi_lib
+
+# Active Configuration
+DEFAULTCONF=Debug
+CONF=${DEFAULTCONF}
+
+# All Configurations
+ALLCONFS=Debug Release 
+
+
+# build
+.build-impl: .build-pre .validate-impl .depcheck-impl
+	@#echo "=> Running $@... Configuration=$(CONF)"
+	${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
+
+
+# clean
+.clean-impl: .clean-pre .validate-impl .depcheck-impl
+	@#echo "=> Running $@... Configuration=$(CONF)"
+	${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
+
+
+# clobber 
+.clobber-impl: .clobber-pre .depcheck-impl
+	@#echo "=> Running $@..."
+	for CONF in ${ALLCONFS}; \
+	do \
+	    ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf; \
+	done
+
+# all 
+.all-impl: .all-pre .depcheck-impl
+	@#echo "=> Running $@..."
+	for CONF in ${ALLCONFS}; \
+	do \
+	    ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf; \
+	done
+
+# dependency checking support
+.depcheck-impl:
+	@echo "# This code depends on make tool being used" >.dep.inc
+	@if [ -n "${MAKE_VERSION}" ]; then \
+	    echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
+	    echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
+	    echo "include \$${DEPFILES}" >>.dep.inc; \
+	    echo "endif" >>.dep.inc; \
+	else \
+	    echo ".KEEP_STATE:" >>.dep.inc; \
+	    echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
+	fi
+
+# configuration validation
+.validate-impl:
+	@if [ ! -f nbproject/Makefile-${CONF}.mk ]; \
+	then \
+	    echo ""; \
+	    echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \
+	    echo "See 'make help' for details."; \
+	    echo "Current directory: " `pwd`; \
+	    echo ""; \
+	fi
+	@if [ ! -f nbproject/Makefile-${CONF}.mk ]; \
+	then \
+	    exit 1; \
+	fi
+
+
+# help
+.help-impl: .help-pre
+	@echo "This makefile supports the following configurations:"
+	@echo "    ${ALLCONFS}"
+	@echo ""
+	@echo "and the following targets:"
+	@echo "    build  (default target)"
+	@echo "    clean"
+	@echo "    clobber"
+	@echo "    all"
+	@echo "    help"
+	@echo ""
+	@echo "Makefile Usage:"
+	@echo "    make [CONF=<CONFIGURATION>] [SUB=no] build"
+	@echo "    make [CONF=<CONFIGURATION>] [SUB=no] clean"
+	@echo "    make [SUB=no] clobber"
+	@echo "    make [SUB=no] all"
+	@echo "    make help"
+	@echo ""
+	@echo "Target 'build' will build a specific configuration and, unless 'SUB=no',"
+	@echo "    also build subprojects."
+	@echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no',"
+	@echo "    also clean subprojects."
+	@echo "Target 'clobber' will remove all built files from all configurations and,"
+	@echo "    unless 'SUB=no', also from subprojects."
+	@echo "Target 'all' will will build all configurations and, unless 'SUB=no',"
+	@echo "    also build subprojects."
+	@echo "Target 'help' prints this message."
+	@echo ""
+

+ 72 - 0
lib/vcmi_lib/nbproject/Package-Debug.bash

@@ -0,0 +1,72 @@
+#!/bin/bash -x
+
+#
+# Generated - do not edit!
+#
+
+# Macros
+TOP=`pwd`
+PLATFORM=GNU-Linux-x86
+TMPDIR=build/Debug/${PLATFORM}/tmp-packaging
+TMPDIRNAME=tmp-packaging
+OUTPUT_PATH=dist/Debug/${PLATFORM}/libvcmi_lib.so
+OUTPUT_BASENAME=libvcmi_lib.so
+PACKAGE_TOP_DIR=libvcmilib.so/
+
+# Functions
+function checkReturnCode
+{
+    rc=$?
+    if [ $rc != 0 ]
+    then
+        exit $rc
+    fi
+}
+function makeDirectory
+# $1 directory path
+# $2 permission (optional)
+{
+    mkdir -p "$1"
+    checkReturnCode
+    if [ "$2" != "" ]
+    then
+      chmod $2 "$1"
+      checkReturnCode
+    fi
+}
+function copyFileToTmpDir
+# $1 from-file path
+# $2 to-file path
+# $3 permission
+{
+    cp "$1" "$2"
+    checkReturnCode
+    if [ "$3" != "" ]
+    then
+        chmod $3 "$2"
+        checkReturnCode
+    fi
+}
+
+# Setup
+cd "${TOP}"
+mkdir -p dist/Debug/${PLATFORM}/package
+rm -rf ${TMPDIR}
+mkdir -p ${TMPDIR}
+
+# Copy files and create directories and links
+cd "${TOP}"
+makeDirectory ${TMPDIR}/libvcmilib.so/lib
+copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}lib/${OUTPUT_BASENAME}" 0644
+
+
+# Generate tar file
+cd "${TOP}"
+rm -f dist/Debug/${PLATFORM}/package/libvcmilib.so.tar
+cd ${TMPDIR}
+tar -vcf ../../../../dist/Debug/${PLATFORM}/package/libvcmilib.so.tar *
+checkReturnCode
+
+# Cleanup
+cd "${TOP}"
+rm -rf ${TMPDIR}

+ 72 - 0
lib/vcmi_lib/nbproject/Package-Release.bash

@@ -0,0 +1,72 @@
+#!/bin/bash -x
+
+#
+# Generated - do not edit!
+#
+
+# Macros
+TOP=`pwd`
+PLATFORM=GNU-Linux-x86
+TMPDIR=build/Release/${PLATFORM}/tmp-packaging
+TMPDIRNAME=tmp-packaging
+OUTPUT_PATH=dist/Release/${PLATFORM}/libvcmi_lib.so
+OUTPUT_BASENAME=libvcmi_lib.so
+PACKAGE_TOP_DIR=libvcmilib.so/
+
+# Functions
+function checkReturnCode
+{
+    rc=$?
+    if [ $rc != 0 ]
+    then
+        exit $rc
+    fi
+}
+function makeDirectory
+# $1 directory path
+# $2 permission (optional)
+{
+    mkdir -p "$1"
+    checkReturnCode
+    if [ "$2" != "" ]
+    then
+      chmod $2 "$1"
+      checkReturnCode
+    fi
+}
+function copyFileToTmpDir
+# $1 from-file path
+# $2 to-file path
+# $3 permission
+{
+    cp "$1" "$2"
+    checkReturnCode
+    if [ "$3" != "" ]
+    then
+        chmod $3 "$2"
+        checkReturnCode
+    fi
+}
+
+# Setup
+cd "${TOP}"
+mkdir -p dist/Release/${PLATFORM}/package
+rm -rf ${TMPDIR}
+mkdir -p ${TMPDIR}
+
+# Copy files and create directories and links
+cd "${TOP}"
+makeDirectory ${TMPDIR}/libvcmilib.so/lib
+copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}lib/${OUTPUT_BASENAME}" 0644
+
+
+# Generate tar file
+cd "${TOP}"
+rm -f dist/Release/${PLATFORM}/package/libvcmilib.so.tar
+cd ${TMPDIR}
+tar -vcf ../../../../dist/Release/${PLATFORM}/package/libvcmilib.so.tar *
+checkReturnCode
+
+# Cleanup
+cd "${TOP}"
+rm -rf ${TMPDIR}

+ 390 - 390
map.h

@@ -1,390 +1,390 @@
-#ifndef MAPD_H
-#define MAPD_H
-#ifdef _MSC_VER
-#pragma warning (disable : 4482)
-#endif
-#include <cstring>
-#include <vector>
-#include <map>
-#include <set>
-#include "global.h"
-class CGDefInfo;
-class CGObjectInstance;
-class CGHeroInstance;
-class CGTownInstance;
-enum ESortBy{_name, _playerAm, _size, _format, _viccon, _loscon};
-enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF, 
-	EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF, ARTIFACT_DEF, WITCHHUT_DEF, SCHOLAR_DEF, PLAYERONLY_DEF, 
-	SHRINE_DEF, SPELLSCROLL_DEF, PANDORA_DEF, GRAIL_DEF, CREGEN_DEF, CREGEN2_DEF, CREGEN3_DEF, 
-	BORDERGUARD_DEF, HEROPLACEHOLDER_DEF};
-
-class DLL_EXPORT CSpecObjInfo
-{
-public:
-	virtual ~CSpecObjInfo(){};
-};
-
-class DLL_EXPORT CCreGenObjInfo : public CSpecObjInfo
-{
-public:
-	unsigned char player; //owner
-	bool asCastle;
-	int identifier;
-	unsigned char castles[2]; //allowed castles
-};
-class DLL_EXPORT CCreGen2ObjInfo : public CSpecObjInfo
-{
-public:
-	unsigned char player; //owner
-	bool asCastle;
-	int identifier;
-	unsigned char castles[2]; //allowed castles
-	unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6>
-};
-class DLL_EXPORT CCreGen3ObjInfo : public CSpecObjInfo
-{
-public:
-	unsigned char player; //owner
-	unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6>
-};
-
-struct DLL_EXPORT Sresource
-{
-	std::string resName; //name of this resource
-	int amount; //it can be greater and lesser than 0
-};
-struct DLL_EXPORT TimeEvent
-{
-	std::string eventName;
-	std::string message;
-	std::vector<Sresource> decIncRes; //decreases / increases of resources
-	unsigned int whichPlayers; //which players are affected by this event (+1 - first, +2 - second, +4 - third, +8 - fourth etc.)
-	bool areHumansAffected;
-	bool areCompsAffected;
-	int firstAfterNDays; //how many days after appears this event
-	int nextAfterNDays; //how many days after the epperance before appaers this event
-};
-struct DLL_EXPORT TerrainTile
-{
-	EterrainType tertype; // type of terrain
-	unsigned char terview; // look of terrain
-	Eriver nuine; // type of Eriver (0 if there is no Eriver)
-	unsigned char rivDir; // direction of Eriver
-	Eroad malle; // type of Eroad (0 if there is no Eriver)
-	unsigned char roadDir; // direction of Eroad
-	unsigned char siodmyTajemniczyBajt; //bitfield, info whether this tile is coastal and how to rotate tile graphics
-
-	bool visitable; //false = not visitable; true = visitable
-	bool blocked; //false = free; true = blocked;
-
-	std::vector <CGObjectInstance*> visitableObjects; //pointers to objects hero can visit while being on this tile
-	std::vector <CGObjectInstance*> blockingObjects; //pointers to objects that are blocking this tile
-
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & tertype & terview & nuine & rivDir & malle &roadDir & siodmyTajemniczyBajt;
-	}
-};
-struct DLL_EXPORT SheroName //name of starting hero
-{
-	int heroID;
-	std::string heroName;
-
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & heroID & heroName;
-	}
-};
-struct DLL_EXPORT PlayerInfo
-{
-	si32 p7, p8, p9;
-	ui8 canHumanPlay;
-	ui8 canComputerPlay;
-	ui32 AITactic; //(00 - random, 01 -  warrior, 02 - builder, 03 - explorer)
-	ui32 allowedFactions; //(01 - castle; 02 - rampart; 04 - tower; 08 - inferno; 16 - necropolis; 32 - dungeon; 64 - stronghold; 128 - fortress; 256 - conflux);
-	ui8 isFactionRandom;
-	ui32 mainHeroPortrait; //it's ID of hero with choosen portrait; 255 if standard
-	std::string mainHeroName;
-	std::vector<SheroName> heroesNames;
-	ui8 hasMainTown;
-	ui8 generateHeroAtMainTown;
-	int3 posOfMainTown;
-	ui8 team;
-	ui8 generateHero;
-
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & p7 & p8 & p9 & canHumanPlay & canComputerPlay & AITactic & allowedFactions & isFactionRandom &
-			mainHeroPortrait & mainHeroName & heroesNames & hasMainTown & generateHeroAtMainTown &
-			posOfMainTown & team & generateHero;
-	}
-};
-struct DLL_EXPORT LossCondition
-{
-	ElossCon typeOfLossCon;
-	int3 castlePos;
-	int3 heroPos;
-	int timeLimit; // in days
-
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & typeOfLossCon & castlePos & heroPos & timeLimit;
-	}
-};
-struct DLL_EXPORT CspecificVictoryConidtions
-{
-	bool allowNormalVictory;
-	bool appliesToAI;
-};
-struct DLL_EXPORT VicCon0 : public CspecificVictoryConidtions //acquire artifact
-{
-	int ArtifactID;
-};
-struct DLL_EXPORT VicCon1 : public CspecificVictoryConidtions //accumulate creatures
-{
-	int monsterID;
-	int neededQuantity;
-};
-struct DLL_EXPORT VicCon2 : public CspecificVictoryConidtions // accumulate resources
-{
-	int resourceID;
-	int neededQuantity;
-};
-struct DLL_EXPORT VicCon3 : public CspecificVictoryConidtions // upgrade specific town
-{
-	int3 posOfCity;
-	int councilNeededLevel; //0 - town; 1 - city; 2 - capitol
-	int fortNeededLevel;// 0 - fort; 1 - citadel; 2 - castle
-};
-struct DLL_EXPORT VicCon4 : public CspecificVictoryConidtions // build grail structure
-{
-	bool anyLocation;
-	int3 whereBuildGrail;
-};
-struct DLL_EXPORT VicCon5 : public CspecificVictoryConidtions // defeat a specific hero
-{
-	int3 locationOfHero;
-};
-struct DLL_EXPORT VicCon6 : public CspecificVictoryConidtions // capture a specific town
-{
-	int3 locationOfTown;
-};
-struct DLL_EXPORT VicCon7 : public CspecificVictoryConidtions // defeat a specific monster
-{
-	int3 locationOfMonster;
-};
-struct DLL_EXPORT VicCona : public CspecificVictoryConidtions //transport specific artifact
-{
-	int artifactID;
-	int3 destinationPlace;
-};
-struct DLL_EXPORT Rumor
-{
-	std::string name, text;
-
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & name & text;
-	}
-};
-
-struct DLL_EXPORT DisposedHero
-{
-	ui32 ID;
-	ui16 portrait; //0xFF - default
-	std::string name;
-	ui8 players; //who can hire this hero (bitfield)
-
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & ID & portrait & name & players;
-	}
-};
-
-class DLL_EXPORT CMapEvent
-{
-public:
-	std::string name, message;
-	si32 wood, mercury, ore, sulfur, crystal, gems, gold; //gained / taken resources
-	ui8 players; //affected players
-	ui8 humanAffected;
-	ui8 computerAffected;
-	ui32 firstOccurence;
-	ui32 nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time;
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & name & message & wood & mercury & ore & sulfur & crystal & gems & gold
-			& players & humanAffected & computerAffected & firstOccurence & nextOccurence;
-	}
-};
-class DLL_EXPORT CMapHeader
-{
-public:
-	Eformat version; // version of map Eformat
-	bool areAnyPLayers; // if there are any playable players on map
-	int height, width;
-	bool twoLevel; // if map has underground level
-	std::string name;  //name of map
-	std::string description;  //and description
-	int difficulty; // 0 easy - 4 impossible
-	int levelLimit;
-	LossCondition lossCondition;
-	EvictoryConditions victoryCondition; //victory conditions
-	CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
-	PlayerInfo players[8]; // info about players
-	std::vector<int> teams;  // teams[i] = team of player no i
-	int howManyTeams;
-	CMapHeader(unsigned char *map); //an argument is a reference to string described a map (unpacked)
-};
-class DLL_EXPORT CMapInfo : public CMapHeader
-{
-public:
-	std::string filename;
-	int playerAmnt, humenPlayers;
-	CMapInfo(std::string fname, unsigned char *map):CMapHeader(map),filename(fname)
-	{
-		playerAmnt=humenPlayers=0;
-		for (int i=0;i<PLAYER_LIMIT;i++)
-		{
-			if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
-			else if (players[i].canComputerPlay) {playerAmnt++;}
-		}
-	};
-};
-
-
-class DLL_EXPORT mapSorter
-{
-public:
-	ESortBy sortBy;
-	bool operator()(const CMapHeader & a, const CMapHeader& b)
-	{
-		switch (sortBy)
-		{
-		case _format:
-			return (a.version<b.version);
-			break;
-		case _loscon:
-			return (a.lossCondition.typeOfLossCon<b.lossCondition.typeOfLossCon);
-			break;
-		case _playerAm:
-			int playerAmntB,humenPlayersB,playerAmntA,humenPlayersA;
-			playerAmntB=humenPlayersB=playerAmntA=humenPlayersA=0;
-			for (int i=0;i<8;i++)
-			{
-				if (a.players[i].canHumanPlay) {playerAmntA++;humenPlayersA++;}
-				else if (a.players[i].canComputerPlay) {playerAmntA++;}
-				if (b.players[i].canHumanPlay) {playerAmntB++;humenPlayersB++;}
-				else if (b.players[i].canComputerPlay) {playerAmntB++;}
-			}
-			if (playerAmntB!=playerAmntA)
-				return (playerAmntA<playerAmntB);
-			else
-				return (humenPlayersA<humenPlayersB);
-			break;
-		case _size:
-			return (a.width<b.width);
-			break;
-		case _viccon:
-			return (a.victoryCondition<b.victoryCondition);
-			break;
-		case _name:
-			return (a.name<b.name);
-			break;
-		default:
-			return (a.name<b.name);
-			break;
-		}
-	};
-	mapSorter(ESortBy es):sortBy(es){};
-};
-struct DLL_EXPORT Mapa
-{
-	Eformat version; // version of map Eformat
-	ui32 checksum;
-	int twoLevel; // if map has underground level
-	int difficulty; // 0 easy - 4 impossible
-	int levelLimit;
-	bool areAnyPLayers; // if there are any playable players on map
-	std::string name;  //name of map
-	std::string description;  //and description
-	int height, width; 
-	TerrainTile*** terrain; 
-	std::vector<Rumor> rumors;
-	std::vector<DisposedHero> disposedHeroes;
-	std::vector<CGHeroInstance*> predefinedHeroes;
-	std::vector<CGDefInfo *> defy; // list of .def files with definitions from .h3m (may be custom)
-	std::set<CGDefInfo *> defs; // other defInfos - for randomized objects, objects added or modified by scripts
-	PlayerInfo players[8]; // info about players
-	std::vector<int> teams;  // teams[i] = team of player no i 
-	LossCondition lossCondition;
-	EvictoryConditions victoryCondition; //victory conditions
-	CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
-	int howManyTeams;
-	std::vector<bool> allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed
-	std::vector<bool> allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed
-	std::vector<bool> allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed
-	std::vector<bool> allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed
-	std::vector<CMapEvent> events;
-
-	int3 grailPos;
-	int grailRadious;
-
-	std::vector<CGObjectInstance*> objects;
-	std::vector<CGHeroInstance*> heroes;
-	std::vector<CGTownInstance*> towns;
-
-	void initFromBytes(unsigned char * bufor); //creates map from decompressed .h3m data
-
-	void readEvents( unsigned char * bufor, int &i);
-	void readObjects( unsigned char * bufor, int &i);
-	void readDefInfo( unsigned char * bufor, int &i);
-	void readTerrain( unsigned char * bufor, int &i);
-	void readPredefinedHeroes( unsigned char * bufor, int &i);
-	void readHeader( unsigned char * bufor, int &i);
-	void readRumors( unsigned char * bufor, int &i);
-	void loadViCLossConditions( unsigned char * bufor, int &i);
-	void loadPlayerInfo( int &pom, unsigned char * bufor, int &i);
-	void loadHero( CGObjectInstance * &nobj, unsigned char * bufor, int &i);
-	void loadTown( CGObjectInstance * &nobj, unsigned char * bufor, int &i);
-	int loadSeerHut( unsigned char * bufor, int i, CGObjectInstance *& nobj);
-
-
-	void addBlockVisTiles(CGObjectInstance * obj);
-	void removeBlockVisTiles(CGObjectInstance * obj);
-	Mapa(std::string filename); //creates map structure from .h3m file
-	CGHeroInstance * getHero(int ID, int mode=0);
-	bool isInTheMap(int3 pos);
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & version & name & description & width & height & twoLevel & difficulty & levelLimit & rumors & defy & defs
-			& players & teams & lossCondition & victoryCondition & howManyTeams & allowedSpell & allowedAbilities
-			& allowedArtifact &allowedHeroes & events;
-		//TODO: viccondetails
-		if(h.saving)
-		{
-			//saving terrain
-			for (int i = 0; i < width ; i++)
-				for (int j = 0; j < height ; j++)
-					for (int k = 0; k <= twoLevel ; k++)
-						h & terrain[i][j][k];
-		}
-		else
-		{
-			//loading terrain
-			terrain = new TerrainTile**[width]; // allocate memory 
-			for (int ii=0;ii<width;ii++)
-			{
-				terrain[ii] = new TerrainTile*[height]; // allocate memory 
-				for(int jj=0;jj<height;jj++)
-					terrain[ii][jj] = new TerrainTile[twoLevel+1];
-			}
-			for (int i = 0; i < width ; i++)
-				for (int j = 0; j < height ; j++)
-					for (int k = 0; k <= twoLevel ; k++)
-						h & terrain[i][j][k];
-		}
-		//TODO: recreate blockvis maps
-	}
-};
-#endif //MAPD_H
+#ifndef __MAP_H__
+#define __MAP_H__
+#ifdef _MSC_VER
+#pragma warning (disable : 4482)
+#endif
+#include <cstring>
+#include <vector>
+#include <map>
+#include <set>
+#include "global.h"
+class CGDefInfo;
+class CGObjectInstance;
+class CGHeroInstance;
+class CGTownInstance;
+enum ESortBy{_name, _playerAm, _size, _format, _viccon, _loscon};
+enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF, 
+	EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF, ARTIFACT_DEF, WITCHHUT_DEF, SCHOLAR_DEF, PLAYERONLY_DEF, 
+	SHRINE_DEF, SPELLSCROLL_DEF, PANDORA_DEF, GRAIL_DEF, CREGEN_DEF, CREGEN2_DEF, CREGEN3_DEF, 
+	BORDERGUARD_DEF, HEROPLACEHOLDER_DEF};
+
+class DLL_EXPORT CSpecObjInfo
+{
+public:
+	virtual ~CSpecObjInfo(){};
+};
+
+class DLL_EXPORT CCreGenObjInfo : public CSpecObjInfo
+{
+public:
+	unsigned char player; //owner
+	bool asCastle;
+	int identifier;
+	unsigned char castles[2]; //allowed castles
+};
+class DLL_EXPORT CCreGen2ObjInfo : public CSpecObjInfo
+{
+public:
+	unsigned char player; //owner
+	bool asCastle;
+	int identifier;
+	unsigned char castles[2]; //allowed castles
+	unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6>
+};
+class DLL_EXPORT CCreGen3ObjInfo : public CSpecObjInfo
+{
+public:
+	unsigned char player; //owner
+	unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6>
+};
+
+struct DLL_EXPORT Sresource
+{
+	std::string resName; //name of this resource
+	int amount; //it can be greater and lesser than 0
+};
+struct DLL_EXPORT TimeEvent
+{
+	std::string eventName;
+	std::string message;
+	std::vector<Sresource> decIncRes; //decreases / increases of resources
+	unsigned int whichPlayers; //which players are affected by this event (+1 - first, +2 - second, +4 - third, +8 - fourth etc.)
+	bool areHumansAffected;
+	bool areCompsAffected;
+	int firstAfterNDays; //how many days after appears this event
+	int nextAfterNDays; //how many days after the epperance before appaers this event
+};
+struct DLL_EXPORT TerrainTile
+{
+	EterrainType tertype; // type of terrain
+	unsigned char terview; // look of terrain
+	Eriver nuine; // type of Eriver (0 if there is no Eriver)
+	unsigned char rivDir; // direction of Eriver
+	Eroad malle; // type of Eroad (0 if there is no Eriver)
+	unsigned char roadDir; // direction of Eroad
+	unsigned char siodmyTajemniczyBajt; //bitfield, info whether this tile is coastal and how to rotate tile graphics
+
+	bool visitable; //false = not visitable; true = visitable
+	bool blocked; //false = free; true = blocked;
+
+	std::vector <CGObjectInstance*> visitableObjects; //pointers to objects hero can visit while being on this tile
+	std::vector <CGObjectInstance*> blockingObjects; //pointers to objects that are blocking this tile
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & tertype & terview & nuine & rivDir & malle &roadDir & siodmyTajemniczyBajt;
+	}
+};
+struct DLL_EXPORT SheroName //name of starting hero
+{
+	int heroID;
+	std::string heroName;
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & heroID & heroName;
+	}
+};
+struct DLL_EXPORT PlayerInfo
+{
+	si32 p7, p8, p9;
+	ui8 canHumanPlay;
+	ui8 canComputerPlay;
+	ui32 AITactic; //(00 - random, 01 -  warrior, 02 - builder, 03 - explorer)
+	ui32 allowedFactions; //(01 - castle; 02 - rampart; 04 - tower; 08 - inferno; 16 - necropolis; 32 - dungeon; 64 - stronghold; 128 - fortress; 256 - conflux);
+	ui8 isFactionRandom;
+	ui32 mainHeroPortrait; //it's ID of hero with choosen portrait; 255 if standard
+	std::string mainHeroName;
+	std::vector<SheroName> heroesNames;
+	ui8 hasMainTown;
+	ui8 generateHeroAtMainTown;
+	int3 posOfMainTown;
+	ui8 team;
+	ui8 generateHero;
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & p7 & p8 & p9 & canHumanPlay & canComputerPlay & AITactic & allowedFactions & isFactionRandom &
+			mainHeroPortrait & mainHeroName & heroesNames & hasMainTown & generateHeroAtMainTown &
+			posOfMainTown & team & generateHero;
+	}
+};
+struct DLL_EXPORT LossCondition
+{
+	ElossCon typeOfLossCon;
+	int3 castlePos;
+	int3 heroPos;
+	int timeLimit; // in days
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & typeOfLossCon & castlePos & heroPos & timeLimit;
+	}
+};
+struct DLL_EXPORT CspecificVictoryConidtions
+{
+	bool allowNormalVictory;
+	bool appliesToAI;
+};
+struct DLL_EXPORT VicCon0 : public CspecificVictoryConidtions //acquire artifact
+{
+	int ArtifactID;
+};
+struct DLL_EXPORT VicCon1 : public CspecificVictoryConidtions //accumulate creatures
+{
+	int monsterID;
+	int neededQuantity;
+};
+struct DLL_EXPORT VicCon2 : public CspecificVictoryConidtions // accumulate resources
+{
+	int resourceID;
+	int neededQuantity;
+};
+struct DLL_EXPORT VicCon3 : public CspecificVictoryConidtions // upgrade specific town
+{
+	int3 posOfCity;
+	int councilNeededLevel; //0 - town; 1 - city; 2 - capitol
+	int fortNeededLevel;// 0 - fort; 1 - citadel; 2 - castle
+};
+struct DLL_EXPORT VicCon4 : public CspecificVictoryConidtions // build grail structure
+{
+	bool anyLocation;
+	int3 whereBuildGrail;
+};
+struct DLL_EXPORT VicCon5 : public CspecificVictoryConidtions // defeat a specific hero
+{
+	int3 locationOfHero;
+};
+struct DLL_EXPORT VicCon6 : public CspecificVictoryConidtions // capture a specific town
+{
+	int3 locationOfTown;
+};
+struct DLL_EXPORT VicCon7 : public CspecificVictoryConidtions // defeat a specific monster
+{
+	int3 locationOfMonster;
+};
+struct DLL_EXPORT VicCona : public CspecificVictoryConidtions //transport specific artifact
+{
+	int artifactID;
+	int3 destinationPlace;
+};
+struct DLL_EXPORT Rumor
+{
+	std::string name, text;
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & name & text;
+	}
+};
+
+struct DLL_EXPORT DisposedHero
+{
+	ui32 ID;
+	ui16 portrait; //0xFF - default
+	std::string name;
+	ui8 players; //who can hire this hero (bitfield)
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & ID & portrait & name & players;
+	}
+};
+
+class DLL_EXPORT CMapEvent
+{
+public:
+	std::string name, message;
+	si32 wood, mercury, ore, sulfur, crystal, gems, gold; //gained / taken resources
+	ui8 players; //affected players
+	ui8 humanAffected;
+	ui8 computerAffected;
+	ui32 firstOccurence;
+	ui32 nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time;
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & name & message & wood & mercury & ore & sulfur & crystal & gems & gold
+			& players & humanAffected & computerAffected & firstOccurence & nextOccurence;
+	}
+};
+class DLL_EXPORT CMapHeader
+{
+public:
+	Eformat version; // version of map Eformat
+	bool areAnyPLayers; // if there are any playable players on map
+	int height, width;
+	bool twoLevel; // if map has underground level
+	std::string name;  //name of map
+	std::string description;  //and description
+	int difficulty; // 0 easy - 4 impossible
+	int levelLimit;
+	LossCondition lossCondition;
+	EvictoryConditions victoryCondition; //victory conditions
+	CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
+	PlayerInfo players[8]; // info about players
+	std::vector<int> teams;  // teams[i] = team of player no i
+	int howManyTeams;
+	CMapHeader(unsigned char *map); //an argument is a reference to string described a map (unpacked)
+};
+class DLL_EXPORT CMapInfo : public CMapHeader
+{
+public:
+	std::string filename;
+	int playerAmnt, humenPlayers;
+	CMapInfo(std::string fname, unsigned char *map):CMapHeader(map),filename(fname)
+	{
+		playerAmnt=humenPlayers=0;
+		for (int i=0;i<PLAYER_LIMIT;i++)
+		{
+			if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
+			else if (players[i].canComputerPlay) {playerAmnt++;}
+		}
+	};
+};
+
+
+class DLL_EXPORT mapSorter
+{
+public:
+	ESortBy sortBy;
+	bool operator()(const CMapHeader & a, const CMapHeader& b)
+	{
+		switch (sortBy)
+		{
+		case _format:
+			return (a.version<b.version);
+			break;
+		case _loscon:
+			return (a.lossCondition.typeOfLossCon<b.lossCondition.typeOfLossCon);
+			break;
+		case _playerAm:
+			int playerAmntB,humenPlayersB,playerAmntA,humenPlayersA;
+			playerAmntB=humenPlayersB=playerAmntA=humenPlayersA=0;
+			for (int i=0;i<8;i++)
+			{
+				if (a.players[i].canHumanPlay) {playerAmntA++;humenPlayersA++;}
+				else if (a.players[i].canComputerPlay) {playerAmntA++;}
+				if (b.players[i].canHumanPlay) {playerAmntB++;humenPlayersB++;}
+				else if (b.players[i].canComputerPlay) {playerAmntB++;}
+			}
+			if (playerAmntB!=playerAmntA)
+				return (playerAmntA<playerAmntB);
+			else
+				return (humenPlayersA<humenPlayersB);
+			break;
+		case _size:
+			return (a.width<b.width);
+			break;
+		case _viccon:
+			return (a.victoryCondition<b.victoryCondition);
+			break;
+		case _name:
+			return (a.name<b.name);
+			break;
+		default:
+			return (a.name<b.name);
+			break;
+		}
+	};
+	mapSorter(ESortBy es):sortBy(es){};
+};
+struct DLL_EXPORT Mapa
+{
+	Eformat version; // version of map Eformat
+	ui32 checksum;
+	int twoLevel; // if map has underground level
+	int difficulty; // 0 easy - 4 impossible
+	int levelLimit;
+	bool areAnyPLayers; // if there are any playable players on map
+	std::string name;  //name of map
+	std::string description;  //and description
+	int height, width; 
+	TerrainTile*** terrain; 
+	std::vector<Rumor> rumors;
+	std::vector<DisposedHero> disposedHeroes;
+	std::vector<CGHeroInstance*> predefinedHeroes;
+	std::vector<CGDefInfo *> defy; // list of .def files with definitions from .h3m (may be custom)
+	std::set<CGDefInfo *> defs; // other defInfos - for randomized objects, objects added or modified by scripts
+	PlayerInfo players[8]; // info about players
+	std::vector<int> teams;  // teams[i] = team of player no i 
+	LossCondition lossCondition;
+	EvictoryConditions victoryCondition; //victory conditions
+	CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
+	int howManyTeams;
+	std::vector<bool> allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed
+	std::vector<bool> allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed
+	std::vector<bool> allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed
+	std::vector<bool> allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed
+	std::vector<CMapEvent> events;
+
+	int3 grailPos;
+	int grailRadious;
+
+	std::vector<CGObjectInstance*> objects;
+	std::vector<CGHeroInstance*> heroes;
+	std::vector<CGTownInstance*> towns;
+
+	void initFromBytes(unsigned char * bufor); //creates map from decompressed .h3m data
+
+	void readEvents( unsigned char * bufor, int &i);
+	void readObjects( unsigned char * bufor, int &i);
+	void readDefInfo( unsigned char * bufor, int &i);
+	void readTerrain( unsigned char * bufor, int &i);
+	void readPredefinedHeroes( unsigned char * bufor, int &i);
+	void readHeader( unsigned char * bufor, int &i);
+	void readRumors( unsigned char * bufor, int &i);
+	void loadViCLossConditions( unsigned char * bufor, int &i);
+	void loadPlayerInfo( int &pom, unsigned char * bufor, int &i);
+	void loadHero( CGObjectInstance * &nobj, unsigned char * bufor, int &i);
+	void loadTown( CGObjectInstance * &nobj, unsigned char * bufor, int &i);
+	int loadSeerHut( unsigned char * bufor, int i, CGObjectInstance *& nobj);
+
+
+	void addBlockVisTiles(CGObjectInstance * obj);
+	void removeBlockVisTiles(CGObjectInstance * obj);
+	Mapa(std::string filename); //creates map structure from .h3m file
+	CGHeroInstance * getHero(int ID, int mode=0);
+	bool isInTheMap(int3 pos);
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & version & name & description & width & height & twoLevel & difficulty & levelLimit & rumors & defy & defs
+			& players & teams & lossCondition & victoryCondition & howManyTeams & allowedSpell & allowedAbilities
+			& allowedArtifact &allowedHeroes & events;
+		//TODO: viccondetails
+		if(h.saving)
+		{
+			//saving terrain
+			for (int i = 0; i < width ; i++)
+				for (int j = 0; j < height ; j++)
+					for (int k = 0; k <= twoLevel ; k++)
+						h & terrain[i][j][k];
+		}
+		else
+		{
+			//loading terrain
+			terrain = new TerrainTile**[width]; // allocate memory 
+			for (int ii=0;ii<width;ii++)
+			{
+				terrain[ii] = new TerrainTile*[height]; // allocate memory 
+				for(int jj=0;jj<height;jj++)
+					terrain[ii][jj] = new TerrainTile[twoLevel+1];
+			}
+			for (int i = 0; i < width ; i++)
+				for (int j = 0; j < height ; j++)
+					for (int k = 0; k <= twoLevel ; k++)
+						h & terrain[i][j][k];
+		}
+		//TODO: recreate blockvis maps
+	}
+};
+#endif // __MAP_H__

+ 912 - 912
nodrze.h

@@ -1,912 +1,912 @@
-#ifndef __NODRZE_H__
-#define __NODRZE_H__
-
-//don't look here, it's a horrible, partially working implementation of RB trees
-
-//ignore comment above, it is simply TowDragon's envy. Everything (without removing) is working fine
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <vector>
-
-#define CLOG(x)
-
-const bool CZERWONY=true, CZARNY=false;
-template <typename T>  class wezel
-{
-public:
-	bool kolor:1;
-	T * zawart;
-	wezel * ojciec, *lewy, *prawy;
-	wezel(bool kol):kolor(kol),ojciec(NULL),lewy(NULL),prawy(NULL){zawart = new T;};
-	wezel(wezel * NIL);
-	~wezel(){delete zawart;}
-};
-template <typename T>  std::ostream & piszAdresy(std::ostream & strum, wezel<T> & w)
-{
-	strum << "Informacje o wezle: "<<&w;
-	strum <<"\n\tOjciec: "<<(w.ojciec);
-	strum<<"\n\tLewy syn: "<<(w.lewy);
-	strum<<"\n\tPrawy syn: "<<(w.prawy);
-	strum<<"\n\tKolor: "<<((w.kolor)?(std::string("Czerwony")):(std::string("Czarny")))<<std::endl<<std::endl;
-	return strum;
-}
-template <typename T>  std::ostream & operator<<(std::ostream & strum, wezel<T> & w)
-{
-	strum << "Informacje o wezle: "<<&w<<" - "<<*w.zawart;
-	strum <<"\n\tOjciec: "<<(w.ojciec)<<" - "<<*w.ojciec->zawart;
-	strum<<"\n\tLewy syn: "<<(w.lewy)<<" - "<<*w.lewy->zawart;
-	strum<<"\n\tPrawy syn: "<<(w.prawy)<<" - "<<*w.prawy->zawart;
-	strum<<"\n\tKolor: "<<((w.kolor)?(std::string("Czerwony")):(std::string("Czarny")))<<std::endl<<std::endl;
-	return strum;
-}
-template <typename T> wezel<T>::wezel(wezel * NIL)
-{
-	ojciec=NIL; lewy=NIL; prawy=NIL; kolor=CZERWONY; zawart = NULL;
-}
-template <typename T>  class nodrze
-{
-private:
-	wezel<T> * NIL, *ostatnio;
-	int ile, ktory;
-	void zepsuj();
-	void dodajBSTC (wezel<T> * nowy);
-	void dodajBST (T co);
-	void dodajRBT (wezel<T> * nowy);
-	wezel<T> * usunRBT (wezel<T> * nowy);
-	void naprawWstaw (wezel<T> * nowy);
-	void naprawUsun (wezel<T> * x);
-	wezel<T> * minimum(wezel<T> * w);
-	wezel<T> * maksimum(wezel<T> * w);
-	wezel<T> * nastepnik(wezel<T> * w);
-	wezel<T> * poprzednik(wezel<T> * w);
-	wezel<T> * szukajRek(wezel<T> * w, T co);
-	wezel<T> * szukajIter(wezel<T> * w, T co);
-	void in(std::ostream & strum, wezel<T> * wsk);
-	void inIt(std::ostream & strum, wezel<T> * wsk);
-	void pre(std::ostream & strum, wezel<T> * wsk);
-	void post(std::ostream & strum, wezel<T> * wsk);
-	void rotacjaLewa (wezel<T> * x);
-	void rotacjaPrawa (wezel<T> * y);
-	bool czyBST (wezel<T> * w);
-	bool sprawdzW(wezel<T> * w);
-	void destrukcja(wezel<T> * w);
-	void wypisuj(wezel<T> * w, std::ostream & strum);
-	void wypisujPre(wezel<T> * w, std::ostream & strum);
-public:
-	wezel<T> * korzen; //root
-	nodrze():ile(0) //najzwyczajniejszy w swiecie kosntruktor // c-tor
-	{
-		NIL=new wezel<T>(CZARNY);
-		NIL->zawart=NULL;
-		korzen=NIL;
-		ostatnio=NIL;
-		ktory=0;
-	};
-	T * begin () {return minimumimum();}; //first element (=minimum)
-	T * end () {return NIL;}; //
-	void clear(); // czysci az do korzenia wlacznie
-				// removes all elements, including root
-	void usun (T co); // usuwa element z drzewa
-					// remove element (value)
-	bool sprawdz(); // sprawdza, czy drzewo jest poprawnym drzewem BST
-					//checks if tree is correct (rather useful only for debugging)
-	T * nast(T czego); // nastepnik zadanego elementu
-						// successor of that element
-	T * maksimumimum (); // najwiekszy element w drzewie
-						//biggest element (and last)
-	bool czyJest(T co); // czy cos jest w drzewie
-						//check if given element is in tree
-	T * minimumimum (); // najmniejszy element w drzewie
-						//smallest element (first)
-	void dodaj (T co); // dodaje element do drzewa
-						// adds (copies)
-	void inorder(std::ostream & strum); // wypisuje na zadane wyjscie elementy w porzadku inorder
-										//print all elements inorder
-	void preorder(std::ostream & strum); // wypisuje na zadane wyjscie elementy w porzadku preorder
-										//print all elements preorder
-	void postorder(std::ostream & strum); // wypisuje na zadane wyjscie elementy w porzadku postorder
-										//print all elements postorder
-	void wypiszObficie(std::ostream & strum); //wypisuje dane o kazdym wezle -- wymaga operatora >> dla zawartosci
-										//prints info about all nodes - >> operator for T needed
-	std::vector<T> vectorize(); //returns vector with all nodrze elements
-	T * znajdz (T co, bool iter = true); // wyszukuje zadany element
-										//search for T
-	int size(); //ilosc elementow
-				//returns size of tree
-	T* operator()(int i) ; //n-ty element przez wskaxnik
-							//returns pointer to element with index i
-	nodrze<T> & operator()(std::istream & potoczek) ; //zczytanie n elemntow z listy
-													//read elements from istream (first must be given amount of elements)
-	T& operator[](int i) ; //dostep do obiektu, ale przez wartosc
-						//returns value of object with index i
-	bool operator+=(T * co); //add
-	bool operator+=(T co); //add
-	bool operator-=(T co); //remove
-	bool operator-=(T * co); //remove
-	T* operator%(T * co); // search and return pointer
-	bool operator&(T co); // check if exist
-	bool operator&(T * co); // check if exist
-	template <typename Y, class X> friend Y* operator%(nodrze<Y> & drzewko, X co); // search and return pointer
-	void push_back(T co){(*this)+=co;}; // add
-};
-template <typename T> std::vector<T> nodrze<T>::vectorize()
-{
-	std::vector<T> ret;
-	for (int i=0; i<ile; i++)
-		ret.push_back((*this)[i]);
-	return ret;
-}
-template <typename T> void nodrze<T>::wypisuj(wezel<T> * w, std::ostream & strum)
-{
-	if (w==NIL) return;
-	wypisuj(w->lewy, strum);
-
-	strum << "Informacje o wezle: "<<std::flush<<w<<std::flush;
-	if (w->ojciec!=NIL)
-		strum <<"\n\tOjciec: "<<(w->ojciec)<<" - "<<*(w->ojciec->zawart);
-	else strum <<"\n\tOjciec: NIL";
-	if (w->lewy!=NIL)
-		strum<<"\n\tLewy syn: "<<(w->lewy)<<" - "<<*(w->lewy->zawart);
-	else strum <<"\n\tLewy syn: NIL";
-	if (w->prawy!=NIL)
-		strum<<"\n\tPrawy syn: "<<(w->prawy)<<" - "<<*(w->prawy->zawart);
-	else strum <<"\n\tPrawy syn: NIL";
-	strum<<"\n\tZawartosc: "<<*w->zawart;
-	strum<<"\n\tKolor: "<<((w->kolor)?(std::string("Czerwony")):(std::string("Czarny")))<<std::endl<<std::endl;
-
-	wypisuj(w->prawy, strum);
-}
-template <typename T> void nodrze<T>::wypisujPre(wezel<T> * w, std::ostream & strum)
-{
-	if (w==NIL) return;
-
-	strum << "Informacje o wezle: "<<std::flush<<w<<std::flush;
-	if (w->ojciec!=NIL)
-		strum <<"\n\tOjciec: "<<(w->ojciec)<<" - "<<*(w->ojciec->zawart);
-	else strum <<"\n\tOjciec: NIL";
-	if (w->lewy!=NIL)
-		strum<<"\n\tLewy syn: "<<(w->lewy)<<" - "<<*(w->lewy->zawart);
-	else strum <<"\n\tLewy syn: NIL";
-	if (w->prawy!=NIL)
-		strum<<"\n\tPrawy syn: "<<(w->prawy)<<" - "<<*(w->prawy->zawart);
-	else strum <<"\n\tPrawy syn: NIL";
-	strum<<"\n\tZawartosc: "<<*w->zawart;
-	strum<<"\n\tKolor: "<<((w->kolor)?(std::string("Czerwony")):(std::string("Czarny")))<<std::endl<<std::endl;
-
-	wypisujPre(w->lewy, strum);
-	wypisujPre(w->prawy, strum);
-}
-template <typename T> void nodrze<T>::wypiszObficie(std::ostream & strum)
-{
-	strum << "Nodrze " <<this<<" ma " << ile << " elementów."<<std::endl;
-	strum << "NIL to " << NIL <<std::endl;
-	strum << "Ostatnio bralismy "<<ktory<<std::flush<<" element, czyli "<<" ("<<ostatnio<<")"<<std::flush<<*ostatnio<<std::flush<<std::endl;
-	strum << "Nasze wezly in-order"<<std::endl;
-	wypisujPre(korzen,strum);
-};
-template <typename T, class X> T* operator%(nodrze<T> & drzewko, X co)
-{
-	CLOG ("Szukam " <<co <<std::endl);
-#ifdef _MSC_VER
-	drzewko.wypiszObficie(*C->gl->loguj);
-#endif
-	wezel<T> * w = drzewko.korzen;
-	while (w!=drzewko.NIL && (*w->zawart)!=co)
-	{
-		if ((*w->zawart) > co)
-			w=w->lewy;
-		else w=w->prawy;
-	}
-	return w->zawart;
-};
-template <typename T> int nodrze<T>::size()
-{
-	return ile;
-}
-template <typename T> void nodrze<T>::clear()
-{
-	destrukcja(korzen);
-	korzen=NIL;
-	ostatnio=NIL;
-	ktory=0;
-}
-template <typename T> void nodrze<T>::destrukcja(wezel<T> * w)
-{
-	if (w==NIL) return;
-	destrukcja(w->lewy);
-	destrukcja(w->prawy);
-	//delete w->zawart;
-	delete w;
-};
-template <typename T> nodrze<T> & nodrze<T>::operator()(std::istream & potoczek)
-{
-	int temp;
-	potoczek >> temp;
-	for (int i=0;i<temp;++i)
-		potoczek >> (*this);
-	return (*this);
-}
-template <typename T> T* nodrze<T>::operator()(int i)
-{
-	int j;
-	wezel<T> * nasz;
-	if (ostatnio!=NIL)
-	{
-		j=i-ktory;
-		if (j>0)
-		{
-			if (j > (ile-i))
-			{
-				ktory = i;
-				i=ile-i-1;
-				nasz = maksimum(korzen);
-				for (j=0;j<i;j++)
-				{
-					nasz = poprzednik(nasz);
-				}
-				ostatnio=nasz;
-				return (nasz->zawart);
-			}
-			else
-			{
-				ktory = i;
-				nasz = ostatnio;
-				for (i=0;i<j;i++)
-				{
-					nasz = nastepnik(nasz);
-				}
-				ostatnio=nasz;
-				return (nasz->zawart);
-			}
-		}
-		if (j==0)
-		{
-			return (ostatnio->zawart);
-		}
-		else
-		{
-			ktory = i;
-			if ((-j)>i)
-			{
-				nasz = minimum(korzen);
-				for (j=0;j<i;j++)
-				{
-					nasz = nastepnik(nasz);
-				}
-				ostatnio=nasz;
-				return (nasz->zawart);
-			}
-			else
-			{
-				nasz = ostatnio;
-				for (i=0;i>j;i--)
-				{
-					nasz = poprzednik(nasz);
-				}
-				ostatnio=nasz;
-				return (nasz->zawart);
-			}
-		}
-	}
-	else
-	{
-		ktory = i;
-		nasz = minimum(korzen);
-		for (j=0;j<i;j++)
-		{
-			nasz = nastepnik(nasz);
-		}
-		ostatnio=nasz;
-		return (nasz->zawart);
-	}
-}
-template <typename T> T& nodrze<T>::operator[](int i)
-{
-	int j;
-	wezel<T> * nasz;
-	if (ostatnio!=NIL)
-	{
-		j=i-ktory;
-		if (j>0)
-		{
-			if (j > (ile-i))
-			{
-				ktory = i;
-				i=ile-i-1;
-				nasz = maksimum(korzen);
-				for (j=0;j<i;j++)
-				{
-					nasz = poprzednik(nasz);
-				}
-				ostatnio=nasz;
-				return *(nasz->zawart);
-			}
-			else
-			{
-				ktory = i;
-				nasz = ostatnio;
-				for (i=0;i<j;i++)
-				{
-					nasz = nastepnik(nasz);
-				}
-				ostatnio=nasz;
-				return *(nasz->zawart);
-			}
-		}
-		if (j==0)
-		{
-			return *(ostatnio->zawart);
-		}
-		else
-		{
-			ktory = i;
-			if ((-j)>i)
-			{
-				nasz = minimum(korzen);
-				for (j=0;j<i;j++)
-				{
-					nasz = nastepnik(nasz);
-				}
-				ostatnio=nasz;
-				return *(nasz->zawart);
-			}
-			else
-			{
-				nasz = ostatnio;
-				for (i=0;i>j;i--)
-				{
-					nasz = poprzednik(nasz);
-				}
-				ostatnio=nasz;
-				return *(nasz->zawart);
-			}
-		}
-	}
-	else
-	{
-		ktory = i;
-		nasz = minimum(korzen);
-		for (j=0;j<i;j++)
-		{
-			nasz = nastepnik(nasz);
-		}
-		ostatnio=nasz;
-		return *(nasz->zawart);
-	}
-}
-template <typename T> bool nodrze<T>::operator+=(T * co)
-{
-	wezel<T> * w = new wezel<T>(NIL);
-	w->kolor=CZERWONY;
-	w->zawart = co;
-	dodajRBT(w);
-	return true;
-}
-template <typename T> bool nodrze<T>::operator+=(T co)
-{
-	dodaj(co);
-	return true;
-}
-template <typename T> bool nodrze<T>::operator-=(T co)
-{
-	usun(co);
-	return true;
-}
-template <typename T> bool nodrze<T>::operator-=(T * co)
-{
-	usun(*co);
-	return true;
-}
-template <typename T> T* nodrze<T>::operator%(T * co)
-{
-	wezel<T> * w = szukajIter(korzen,*co);
-	if (w != NIL)
-		return w;
-	else return NULL;
-}
-template <typename T> bool nodrze<T>::operator&(T co)
-{
-	return czyJest(co);
-}
-template <typename T> bool nodrze<T>::operator&(T * co)
-{
-	return czyJest(*co);
-}
-template <typename T> class iterator
-{
-	/*nodrze<T> * dd;
-	wezel<T> * akt;
-public:
-	T * operator->()
-	{
-		return akt->zawart;
-	}
-	iterator& operator++()
-	{
-		akt = dd->nastepnik(akt);
-		return this;
-	}
-	iterator& operator--()
-	{
-		akt = dd->poprzednik(akt);
-		return this;
-	}
-	T * operator=(T*)
-	{
-		akt->zawart = T;
-		return akt->zawart;
-	}*/
-	/*void start()
-	{
-		akt = maksimum(korzen);
-	}*/
-};
-template <typename T> void nodrze<T>::inIt(std::ostream & strum, wezel<T> * wsk)
-{
-	if (wsk == NIL)
-		return;
-
-  // Start from the minimumimum wsk
-	while (wsk->lewy != NIL)
-		wsk=wsk->lewy;
-	do
-	{
-		visit(wsk);
-		// Next in order will be our right child's leftmost child (if NIL, our right child)
-		if (wsk->prawy != NIL)
-		{
-			wsk = wsk->prawy;
-			while (wsk->lewy != NIL)
-				wsk = wsk->left;
-		}
-		else
-		{
-			while (true)
-			{
-				if (wsk->ojciec == NIL)
-				{
-					wsk = NIL;
-					break;
-				}
-				wsk = wsk->ojciec;
-				// If wsk is its parents left child, then its parent hasn't been visited yet
-				if (wsk->ojciec->lewy == wsk)
-					break;
-			}
-		}
-	}
-	while (wsk != NIL);
-
-};
-template <typename T> bool nodrze<T>::sprawdz()
-{
-	return (sprawdzW(korzen));
-};
-template <typename T> T * nodrze<T>::znajdz (T co, bool iter)
-{
-	return ((iter)?(szukajIter(korzen,co)->zawart):(szukajRek(korzen,co)->zawart));
-};
-template <typename T> void nodrze<T>::usun (T co)
-{
-	wezel<T> * w = szukajIter(korzen, co);
-	usunRBT(w);
-	delete w;
-}
-template <typename T> void nodrze<T>::naprawUsun (wezel<T> * x)
-{
-	wezel<T> *w;
-	while ( (x != korzen)  &&  (x->kolor == CZARNY) )
-	{
-		CLOG("6... "<<std::flush);
-		if (x == x->ojciec->lewy)
-		{
-			CLOG("7... "<<std::flush);
-			w = x->ojciec->prawy;
-			if (w->kolor == CZERWONY)
-			{
-				w->kolor = CZARNY;
-				x->ojciec->kolor = CZERWONY;
-				rotacjaLewa(x->ojciec);
-				w = x->ojciec->prawy;
-			}
-			CLOG("8... "<<std::flush);
-			if ( (w->lewy->kolor == CZARNY)  &&  (w->prawy->kolor == CZARNY) )
-			{
-				CLOG("8,1... "<<std::flush);
-				w->kolor = CZERWONY;
-				x = x->ojciec;
-			}
-			else
-			{
-				CLOG("9... "<<std::flush);
-				if (w->prawy->kolor == CZARNY)
-				{
-					CLOG("9,1... "<<std::flush);
-					w->lewy->kolor = CZARNY;
-					w->kolor = CZERWONY;
-					rotacjaPrawa(w);
-					w = x->ojciec->prawy;
-					CLOG("9,2... "<<std::flush);
-				}
-				CLOG("9,3... "<<std::flush);
-				w->kolor = x->ojciec->kolor;
-				x->ojciec->kolor = CZARNY;
-				w->prawy->kolor = CZARNY;
-				rotacjaLewa(x->ojciec);
-				x=korzen;
-				CLOG("9,4... "<<std::flush);
-
-			}
-		}
-		else
-		{
-			CLOG("10... "<<std::flush);
-			w = x->ojciec->lewy;
-			if (w->kolor == CZERWONY)
-			{
-				w->kolor = CZARNY;
-				x->ojciec->kolor = CZERWONY;
-				rotacjaPrawa(x->ojciec);
-				w = x->ojciec->lewy;
-			}
-			CLOG("11... "<<std::flush);
-			if ( (w->lewy->kolor == CZARNY)  &&  (w->prawy->kolor == CZARNY) )
-			{
-				w->kolor = CZERWONY;
-				x = x->ojciec;
-			}
-			else
-			{
-				if (w->lewy->kolor == CZARNY)
-				{
-					w->prawy->kolor = CZARNY;
-					w->kolor = CZERWONY;
-					rotacjaLewa(w);
-					w = x->ojciec->lewy;
-				}
-				w->kolor = x->ojciec->kolor;
-				x->ojciec->kolor = CZARNY;
-				w->lewy->kolor = CZARNY;
-				rotacjaPrawa(x->ojciec);
-				x=korzen;
-				CLOG("12... "<<std::flush);
-			}
-		}
-	}
-	x->kolor = CZARNY;
-	CLOG("13... "<<std::flush);
-};
-template <typename T> wezel<T> * nodrze<T>::usunRBT (wezel<T> * nowy)
-{
-	CLOG ("Usuwam "<<*nowy->zawart<<std::endl);
-	ile--;
-	if ((*nowy->zawart) < (*ostatnio->zawart))
-	{
-		ktory--;
-		CLOG("Ostatnio to "<<(*ostatnio->zawart)<<", czyli teraz "<<(ktory)<<" (mniej) element."<<std::endl);
-	}
-	else if (nowy == ostatnio)
-	{
-		CLOG ("To by³ ostatnio ogl¹dany element. Elementem o numerze "<<ktory<<" bedzie teraz ");
-		if (ktory < ile)
-		{
-			ostatnio = nastepnik(ostatnio);
-		}
-		else
-		{
-			CLOG ("Ojej, koniec. Cofamy siê. "<<std::endl);
-			ostatnio = poprzednik(ostatnio);
-			ktory--;
-		}
-		CLOG(*ostatnio->zawart<<std::endl);
-	}
-	CLOG("1... "<<std::flush);
-	wezel<T> *y, *x;
-	if ( (nowy->lewy == NIL)  ||  (nowy->prawy == NIL) )
-		y=nowy;
-	else y = nastepnik(nowy);
-	CLOG("2... "<<std::flush);
-	if (y->lewy != NIL)
-		x = y->lewy;
-	else x = y->prawy;
-	x->ojciec = y->ojciec;
-	CLOG("3... "<<std::flush);
-	if (y->ojciec == NIL)
-		korzen = x;
-	else if (y == y->ojciec->lewy)
-		y->ojciec->lewy = x;
-	else
-		y->ojciec->prawy = x;
-	CLOG("4... "<<std::flush);
-	if (y != nowy)
-		(*nowy) = (*y); // skopiowanie
-	CLOG("5... "<<std::flush);
-	if (y->kolor == CZARNY)
-		naprawUsun(x);
-	CLOG ("koniec usuwania"<<std::endl);
-	return y;
-};
-template <typename T> void nodrze<T>::naprawWstaw (wezel<T> * nowy)
-{
-	//CLOG ("Naprawiam po wstawieniu"<<std::endl);
-	while (nowy->ojciec->kolor==CZERWONY)
-	{
-		if (nowy->ojciec == nowy->ojciec->ojciec->lewy) // ojciec nowego lest lewy
-		{
-			wezel<T> * y = nowy->ojciec->ojciec->prawy;
-			if (y->kolor == CZERWONY) // a stryj jest czerwony
-			{
-				nowy->ojciec->kolor = CZARNY;
-				y->kolor = CZARNY;
-				nowy->ojciec->ojciec->kolor = CZERWONY;
-				nowy = nowy->ojciec->ojciec;
-			}
-			else
-			{
-				if (nowy->ojciec->prawy == nowy) // nowy jest prawym synem
-				{
-					nowy = nowy->ojciec;
-					rotacjaLewa(nowy);
-				}
-				nowy->ojciec->kolor=CZARNY;
-				nowy->ojciec->ojciec->kolor=CZERWONY;
-				rotacjaPrawa(nowy->ojciec->ojciec);
-			}
-		}
-		else
-		{
-			wezel<T> * y = nowy->ojciec->ojciec->lewy;
-			if (y->kolor == CZERWONY) // a stryj jest czerwony
-			{
-				nowy->ojciec->kolor = CZARNY;
-				y->kolor = CZARNY;
-				nowy->ojciec->ojciec->kolor = CZERWONY;
-				nowy = nowy->ojciec->ojciec;
-			}
-			else
-			{
-				if (nowy->ojciec->lewy == nowy)
-				{
-					nowy = nowy->ojciec;
-					rotacjaPrawa(nowy);
-				}
-				nowy->ojciec->kolor=CZARNY;
-				nowy->ojciec->ojciec->kolor=CZERWONY;
-				rotacjaLewa(nowy->ojciec->ojciec);
-			}
-		}
-	}
-	korzen->kolor = CZARNY;
-}
-template <typename T> void nodrze<T>::dodajRBT (wezel<T> * nowy)
-{
-	//CLOG("Dodaje do drzewa "<<nowy->zawart<<std::endl);
-	ile++;
-	if(ostatnio==NIL)
-	{
-		ostatnio = nowy;
-		ktory=0;
-	}
-	else if ((*nowy->zawart) < (*ostatnio->zawart))
-	{
-		ktory++;
-	}
-	wezel<T> * y =NIL, * x = korzen;
-	while (x != NIL)
-	{
-		y=x;
-		if ((*nowy->zawart) < (*x->zawart))
-			x=x->lewy;
-		else x = x->prawy;
-	}
-	nowy->ojciec = y;
-	if (y == NIL)
-	{
-		korzen=nowy;
-		ostatnio=korzen;
-		ktory=0;
-	}
-	else if ((*nowy->zawart) < (*y->zawart))
-		y->lewy = nowy;
-	else y->prawy = nowy;
-	nowy->kolor = CZERWONY;
-	naprawWstaw(nowy);
-};
-template <typename T> void nodrze<T>::dodaj (T co)
-{
-	wezel<T> * w = new wezel<T>(NIL);
-	w->lewy=w->prawy=w->ojciec=NIL;
-	w->zawart = new T(co);
-	dodajRBT(w);
-}
-template <typename T> void nodrze<T>::zepsuj()
-{
-	int pom;
-	pom = *korzen->zawart;
-	*korzen->zawart = *korzen->prawy->zawart;
-	*korzen->prawy->zawart = pom;
-}
-template <typename T> bool nodrze<T>::czyBST (wezel<T> * w)
-{
-	if (w->prawy != NIL)
-	{
-		if ((*w->prawy->zawart) < (*w->zawart))
-			return false;
-	}
-	if (w->lewy != NIL)
-	{
-		if((*w->lewy->zawart) > (*w->zawart))
-			return false;
-	}
-	return true;
-}
-template <typename T> bool nodrze<T>::sprawdzW(wezel<T> * w)
-{
-	bool ret = czyBST(w);
-	if (w->prawy != NIL)
-		ret&=sprawdzW(w->prawy);
-	if (w->lewy != NIL)
-		ret&=sprawdzW(w->lewy);
-	return ret;
-}
-template <typename T> void nodrze<T>::rotacjaLewa (wezel<T> * x)
-{
-	//CLOG("Wykonuje lew¹ rotacjê na "<<x->zawart<<std::endl);
-	wezel<T> * y = x->prawy;
-	x->prawy = y->lewy; // zamiana lewego poddrzewa y na prawe poddrzewo x
-	if (y->lewy != NIL) y->lewy->ojciec = x; // i przypisanie ojcostwa temu poddrzewu
-	y->ojciec = x->ojciec; // ojcem y bedzie ojciec x
-	if (x->ojciec == NIL)
-		korzen = y;
-	else if ((x->ojciec->lewy) == x)
-		x->ojciec->lewy = y;
-	else
-		x->ojciec->prawy = y;
-	y->lewy = x; // a x bedzie lewym synem y
-	x->ojciec = y;
-};
-template <typename T> void nodrze<T>::rotacjaPrawa (wezel<T> * y)
-{
-	//CLOG("Wykonuje prawa rotacjê na "<<y->zawart<<std::endl);
-	wezel<T> * x = y->lewy;
-	y->lewy = x->prawy; // zamiana prawe poddrzewa x na lewe poddrzewo y
-	if (x->prawy != NIL) x->prawy->ojciec = y; // i przypisanie ojcostwa temu poddrzewu
-	x->ojciec = y->ojciec; // ojcem x bedzie ojciec y
-	if (x->ojciec == NIL)
-		korzen = x;
-	else if ((y->ojciec->lewy) == y)
-		y->ojciec->lewy = x;
-	else
-		y->ojciec->prawy = x;
-	x->prawy = y; // a y bedzie prawym synem x
-	y->ojciec = x;
-};
-template <typename T> T * nodrze<T>::nast(T czego)
-{
-	wezel<T> * w = szukajIter(korzen,czego);
-	if (w != NIL)
-		w = nastepnik(w);
-	else throw std::exception("Nie znaleziono wartosci");
-	if (w != NIL)
-		return (w->zawart);
-	else throw std::exception("Nie znaleziono nastepnika");
-};
-template <typename T> bool nodrze<T>::czyJest(T co)
-{
-	if ( szukajIter(korzen,co) != NIL )
-		return true;
-	else return false;
-}
-template <typename T> wezel<T> * nodrze<T>::szukajRek(wezel<T> * w, T co)
-{
-	if (w==NIL || (!(((*w->zawart)<co)||(co<(*w->zawart)))))
-		return w;
-	if (co < (*w->zawart))
-		return szukajRek(w->lewy,co);
-	else return szukajRek(w->prawy,co);
-};
-template <typename T> wezel<T> * nodrze<T>::szukajIter(wezel<T> * w, T co)
-{
-	while ( w!=NIL && (((*w->zawart)<co)||(co<(*w->zawart))) )
-	{
-		if (co < (*w->zawart))
-			w=w->lewy;
-		else w=w->prawy;
-	}
-	return (w)?w:NULL;
-};
-template <typename T> wezel<T> * nodrze<T>::minimum(wezel<T> * w)
-{
-	while (w->lewy != NIL)
-		w=w->lewy;
-	return w;
-};
-template <typename T> wezel<T> * nodrze<T>::maksimum(wezel<T> * w)
-{
-	while (w->prawy != NIL)
-		w=w->prawy;
-	return w;
-};
-template <typename T> wezel<T> * nodrze<T>::nastepnik(wezel<T> * w)
-{
-	if (w->prawy != NIL)
-		return minimum(w->prawy);
-	wezel<T> * y = w->ojciec;
-	while (y!= NIL && w == y->prawy)
-	{
-		w=y;
-		y=y->ojciec;
-	}
-	return y;
-};
-template <typename T> wezel<T> * nodrze<T>::poprzednik(wezel<T> * w)
-{
-	if (w->lewy != NIL)
-		return maksimum(w->lewy);
-	wezel<T> * y = w->ojciec;
-	while (y!= NIL && w == y->lewy)
-	{
-		w=y;
-		y=y->ojciec;
-	}
-	return y;
-};
-template <typename T> T * nodrze<T>::maksimumimum ()
-{
-	wezel<T> * ret = maksimum(korzen);
-	if (ret != NIL)
-		return (ret->zawart);
-	else throw std::exception("Drzewo jest puste");
-};
-template <typename T> T * nodrze<T>::minimumimum ()
-{
-	wezel<T> * ret = minimum(korzen);
-	if (ret != NIL)
-		return (ret->zawart);
-	else throw std::exception("Drzewo jest puste");
-};
-template <typename T> void nodrze<T>::inorder(std::ostream & strum)
-{
-	in(strum,korzen);
-}
-template <typename T> void nodrze<T>::preorder(std::ostream & strum)
-{
-	pre(strum,korzen);
-}
-template <typename T> void nodrze<T>::postorder(std::ostream & strum)
-{
-	post(strum,korzen);
-}
-template <typename T> void nodrze<T>::in(std::ostream & strum, wezel<T> * wsk)
-{
-	if (wsk==NIL)
-		return;
-	if (wsk->lewy != NIL)
-		in(strum,wsk->lewy);
-	strum << *wsk->zawart<<"\t";
-	if (wsk->prawy != NIL)
-		in(strum,wsk->prawy);
-};
-template <typename T> void nodrze<T>::post(std::ostream & strum, wezel<T> * wsk)
-{
-	if (wsk==NIL)
-		return;
-	if (wsk->lewy != NIL)
-		post(strum,wsk->lewy);
-	if (wsk->prawy != NIL)
-		post(strum,wsk->prawy);
-	strum << *wsk->zawart<<"\t";
-};
-template <typename T> void nodrze<T>::pre(std::ostream & strum, wezel<T> * wsk)
-{
-	if (wsk == NIL)
-		return;
-	strum << *wsk->zawart<<"\t";
-	if (wsk->lewy != NIL)
-		pre(strum,wsk->lewy);
-	if (wsk->prawy != NIL)
-		pre(strum,wsk->prawy);
-};
-#endif // __NODRZE_H__
+#ifndef _NODRZE_H
+#define _NODRZE_H
+
+//don't look here, it's a horrible, partially working implementation of RB trees
+
+//ignore comment above, it is simply TowDragon's envy. Everything (without removing) is working fine
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <vector>
+
+#define CLOG(x)
+
+const bool CZERWONY=true, CZARNY=false;
+template <typename T>  class wezel
+{
+public:
+	bool kolor:1;
+	T * zawart;
+	wezel * ojciec, *lewy, *prawy;
+	wezel(bool kol):kolor(kol),ojciec(NULL),lewy(NULL),prawy(NULL){zawart = new T;};
+	wezel(wezel * NIL);
+	~wezel(){delete zawart;}
+};
+template <typename T>  std::ostream & piszAdresy(std::ostream & strum, wezel<T> & w)
+{
+	strum << "Informacje o wezle: "<<&w;
+	strum <<"\n\tOjciec: "<<(w.ojciec);
+	strum<<"\n\tLewy syn: "<<(w.lewy);
+	strum<<"\n\tPrawy syn: "<<(w.prawy);
+	strum<<"\n\tKolor: "<<((w.kolor)?(std::string("Czerwony")):(std::string("Czarny")))<<std::endl<<std::endl;
+	return strum;
+}
+template <typename T>  std::ostream & operator<<(std::ostream & strum, wezel<T> & w)
+{
+	strum << "Informacje o wezle: "<<&w<<" - "<<*w.zawart;
+	strum <<"\n\tOjciec: "<<(w.ojciec)<<" - "<<*w.ojciec->zawart;
+	strum<<"\n\tLewy syn: "<<(w.lewy)<<" - "<<*w.lewy->zawart;
+	strum<<"\n\tPrawy syn: "<<(w.prawy)<<" - "<<*w.prawy->zawart;
+	strum<<"\n\tKolor: "<<((w.kolor)?(std::string("Czerwony")):(std::string("Czarny")))<<std::endl<<std::endl;
+	return strum;
+}
+template <typename T> wezel<T>::wezel(wezel * NIL)
+{
+	ojciec=NIL; lewy=NIL; prawy=NIL; kolor=CZERWONY; zawart = NULL;
+}
+template <typename T>  class nodrze
+{
+private:
+	wezel<T> * NIL, *ostatnio;
+	int ile, ktory;
+	void zepsuj();
+	void dodajBSTC (wezel<T> * nowy);
+	void dodajBST (T co);
+	void dodajRBT (wezel<T> * nowy);
+	wezel<T> * usunRBT (wezel<T> * nowy);
+	void naprawWstaw (wezel<T> * nowy);
+	void naprawUsun (wezel<T> * x);
+	wezel<T> * minimum(wezel<T> * w);
+	wezel<T> * maksimum(wezel<T> * w);
+	wezel<T> * nastepnik(wezel<T> * w);
+	wezel<T> * poprzednik(wezel<T> * w);
+	wezel<T> * szukajRek(wezel<T> * w, T co);
+	wezel<T> * szukajIter(wezel<T> * w, T co);
+	void in(std::ostream & strum, wezel<T> * wsk);
+	void inIt(std::ostream & strum, wezel<T> * wsk);
+	void pre(std::ostream & strum, wezel<T> * wsk);
+	void post(std::ostream & strum, wezel<T> * wsk);
+	void rotacjaLewa (wezel<T> * x);
+	void rotacjaPrawa (wezel<T> * y);
+	bool czyBST (wezel<T> * w);
+	bool sprawdzW(wezel<T> * w);
+	void destrukcja(wezel<T> * w);
+	void wypisuj(wezel<T> * w, std::ostream & strum);
+	void wypisujPre(wezel<T> * w, std::ostream & strum);
+public:
+	wezel<T> * korzen; //root
+	nodrze():ile(0) //najzwyczajniejszy w swiecie kosntruktor // c-tor
+	{
+		NIL=new wezel<T>(CZARNY);
+		NIL->zawart=NULL;
+		korzen=NIL;
+		ostatnio=NIL;
+		ktory=0;
+	};
+	T * begin () {return minimumimum();}; //first element (=minimum)
+	T * end () {return NIL;}; //
+	void clear(); // czysci az do korzenia wlacznie
+				// removes all elements, including root
+	void usun (T co); // usuwa element z drzewa
+					// remove element (value)
+	bool sprawdz(); // sprawdza, czy drzewo jest poprawnym drzewem BST
+					//checks if tree is correct (rather useful only for debugging)
+	T * nast(T czego); // nastepnik zadanego elementu
+						// successor of that element
+	T * maksimumimum (); // najwiekszy element w drzewie
+						//biggest element (and last)
+	bool czyJest(T co); // czy cos jest w drzewie
+						//check if given element is in tree
+	T * minimumimum (); // najmniejszy element w drzewie
+						//smallest element (first)
+	void dodaj (T co); // dodaje element do drzewa
+						// adds (copies)
+	void inorder(std::ostream & strum); // wypisuje na zadane wyjscie elementy w porzadku inorder
+										//print all elements inorder
+	void preorder(std::ostream & strum); // wypisuje na zadane wyjscie elementy w porzadku preorder
+										//print all elements preorder
+	void postorder(std::ostream & strum); // wypisuje na zadane wyjscie elementy w porzadku postorder
+										//print all elements postorder
+	void wypiszObficie(std::ostream & strum); //wypisuje dane o kazdym wezle -- wymaga operatora >> dla zawartosci
+										//prints info about all nodes - >> operator for T needed
+	std::vector<T> vectorize(); //returns vector with all nodrze elements
+	T * znajdz (T co, bool iter = true); // wyszukuje zadany element
+										//search for T
+	int size(); //ilosc elementow
+				//returns size of tree
+	T* operator()(int i) ; //n-ty element przez wskaxnik
+							//returns pointer to element with index i
+	nodrze<T> & operator()(std::istream & potoczek) ; //zczytanie n elemntow z listy
+													//read elements from istream (first must be given amount of elements)
+	T& operator[](int i) ; //dostep do obiektu, ale przez wartosc
+						//returns value of object with index i
+	bool operator+=(T * co); //add
+	bool operator+=(T co); //add
+	bool operator-=(T co); //remove
+	bool operator-=(T * co); //remove
+	T* operator%(T * co); // search and return pointer
+	bool operator&(T co); // check if exist
+	bool operator&(T * co); // check if exist
+	template <typename Y, class X> friend Y* operator%(nodrze<Y> & drzewko, X co); // search and return pointer
+	void push_back(T co){(*this)+=co;}; // add
+};
+template <typename T> std::vector<T> nodrze<T>::vectorize()
+{
+	std::vector<T> ret;
+	for (int i=0; i<ile; i++)
+		ret.push_back((*this)[i]);
+	return ret;
+}
+template <typename T> void nodrze<T>::wypisuj(wezel<T> * w, std::ostream & strum)
+{
+	if (w==NIL) return;
+	wypisuj(w->lewy, strum);
+
+	strum << "Informacje o wezle: "<<std::flush<<w<<std::flush;
+	if (w->ojciec!=NIL)
+		strum <<"\n\tOjciec: "<<(w->ojciec)<<" - "<<*(w->ojciec->zawart);
+	else strum <<"\n\tOjciec: NIL";
+	if (w->lewy!=NIL)
+		strum<<"\n\tLewy syn: "<<(w->lewy)<<" - "<<*(w->lewy->zawart);
+	else strum <<"\n\tLewy syn: NIL";
+	if (w->prawy!=NIL)
+		strum<<"\n\tPrawy syn: "<<(w->prawy)<<" - "<<*(w->prawy->zawart);
+	else strum <<"\n\tPrawy syn: NIL";
+	strum<<"\n\tZawartosc: "<<*w->zawart;
+	strum<<"\n\tKolor: "<<((w->kolor)?(std::string("Czerwony")):(std::string("Czarny")))<<std::endl<<std::endl;
+
+	wypisuj(w->prawy, strum);
+}
+template <typename T> void nodrze<T>::wypisujPre(wezel<T> * w, std::ostream & strum)
+{
+	if (w==NIL) return;
+
+	strum << "Informacje o wezle: "<<std::flush<<w<<std::flush;
+	if (w->ojciec!=NIL)
+		strum <<"\n\tOjciec: "<<(w->ojciec)<<" - "<<*(w->ojciec->zawart);
+	else strum <<"\n\tOjciec: NIL";
+	if (w->lewy!=NIL)
+		strum<<"\n\tLewy syn: "<<(w->lewy)<<" - "<<*(w->lewy->zawart);
+	else strum <<"\n\tLewy syn: NIL";
+	if (w->prawy!=NIL)
+		strum<<"\n\tPrawy syn: "<<(w->prawy)<<" - "<<*(w->prawy->zawart);
+	else strum <<"\n\tPrawy syn: NIL";
+	strum<<"\n\tZawartosc: "<<*w->zawart;
+	strum<<"\n\tKolor: "<<((w->kolor)?(std::string("Czerwony")):(std::string("Czarny")))<<std::endl<<std::endl;
+
+	wypisujPre(w->lewy, strum);
+	wypisujPre(w->prawy, strum);
+}
+template <typename T> void nodrze<T>::wypiszObficie(std::ostream & strum)
+{
+	strum << "Nodrze " <<this<<" ma " << ile << " elementów."<<std::endl;
+	strum << "NIL to " << NIL <<std::endl;
+	strum << "Ostatnio bralismy "<<ktory<<std::flush<<" element, czyli "<<" ("<<ostatnio<<")"<<std::flush<<*ostatnio<<std::flush<<std::endl;
+	strum << "Nasze wezly in-order"<<std::endl;
+	wypisujPre(korzen,strum);
+};
+template <typename T, class X> T* operator%(nodrze<T> & drzewko, X co)
+{
+	CLOG ("Szukam " <<co <<std::endl);
+#ifdef _MSC_VER
+	drzewko.wypiszObficie(*C->gl->loguj);
+#endif
+	wezel<T> * w = drzewko.korzen;
+	while (w!=drzewko.NIL && (*w->zawart)!=co)
+	{
+		if ((*w->zawart) > co)
+			w=w->lewy;
+		else w=w->prawy;
+	}
+	return w->zawart;
+};
+template <typename T> int nodrze<T>::size()
+{
+	return ile;
+}
+template <typename T> void nodrze<T>::clear()
+{
+	destrukcja(korzen);
+	korzen=NIL;
+	ostatnio=NIL;
+	ktory=0;
+}
+template <typename T> void nodrze<T>::destrukcja(wezel<T> * w)
+{
+	if (w==NIL) return;
+	destrukcja(w->lewy);
+	destrukcja(w->prawy);
+	//delete w->zawart;
+	delete w;
+};
+template <typename T> nodrze<T> & nodrze<T>::operator()(std::istream & potoczek)
+{
+	int temp;
+	potoczek >> temp;
+	for (int i=0;i<temp;++i)
+		potoczek >> (*this);
+	return (*this);
+}
+template <typename T> T* nodrze<T>::operator()(int i)
+{
+	int j;
+	wezel<T> * nasz;
+	if (ostatnio!=NIL)
+	{
+		j=i-ktory;
+		if (j>0)
+		{
+			if (j > (ile-i))
+			{
+				ktory = i;
+				i=ile-i-1;
+				nasz = maksimum(korzen);
+				for (j=0;j<i;j++)
+				{
+					nasz = poprzednik(nasz);
+				}
+				ostatnio=nasz;
+				return (nasz->zawart);
+			}
+			else
+			{
+				ktory = i;
+				nasz = ostatnio;
+				for (i=0;i<j;i++)
+				{
+					nasz = nastepnik(nasz);
+				}
+				ostatnio=nasz;
+				return (nasz->zawart);
+			}
+		}
+		if (j==0)
+		{
+			return (ostatnio->zawart);
+		}
+		else
+		{
+			ktory = i;
+			if ((-j)>i)
+			{
+				nasz = minimum(korzen);
+				for (j=0;j<i;j++)
+				{
+					nasz = nastepnik(nasz);
+				}
+				ostatnio=nasz;
+				return (nasz->zawart);
+			}
+			else
+			{
+				nasz = ostatnio;
+				for (i=0;i>j;i--)
+				{
+					nasz = poprzednik(nasz);
+				}
+				ostatnio=nasz;
+				return (nasz->zawart);
+			}
+		}
+	}
+	else
+	{
+		ktory = i;
+		nasz = minimum(korzen);
+		for (j=0;j<i;j++)
+		{
+			nasz = nastepnik(nasz);
+		}
+		ostatnio=nasz;
+		return (nasz->zawart);
+	}
+}
+template <typename T> T& nodrze<T>::operator[](int i)
+{
+	int j;
+	wezel<T> * nasz;
+	if (ostatnio!=NIL)
+	{
+		j=i-ktory;
+		if (j>0)
+		{
+			if (j > (ile-i))
+			{
+				ktory = i;
+				i=ile-i-1;
+				nasz = maksimum(korzen);
+				for (j=0;j<i;j++)
+				{
+					nasz = poprzednik(nasz);
+				}
+				ostatnio=nasz;
+				return *(nasz->zawart);
+			}
+			else
+			{
+				ktory = i;
+				nasz = ostatnio;
+				for (i=0;i<j;i++)
+				{
+					nasz = nastepnik(nasz);
+				}
+				ostatnio=nasz;
+				return *(nasz->zawart);
+			}
+		}
+		if (j==0)
+		{
+			return *(ostatnio->zawart);
+		}
+		else
+		{
+			ktory = i;
+			if ((-j)>i)
+			{
+				nasz = minimum(korzen);
+				for (j=0;j<i;j++)
+				{
+					nasz = nastepnik(nasz);
+				}
+				ostatnio=nasz;
+				return *(nasz->zawart);
+			}
+			else
+			{
+				nasz = ostatnio;
+				for (i=0;i>j;i--)
+				{
+					nasz = poprzednik(nasz);
+				}
+				ostatnio=nasz;
+				return *(nasz->zawart);
+			}
+		}
+	}
+	else
+	{
+		ktory = i;
+		nasz = minimum(korzen);
+		for (j=0;j<i;j++)
+		{
+			nasz = nastepnik(nasz);
+		}
+		ostatnio=nasz;
+		return *(nasz->zawart);
+	}
+}
+template <typename T> bool nodrze<T>::operator+=(T * co)
+{
+	wezel<T> * w = new wezel<T>(NIL);
+	w->kolor=CZERWONY;
+	w->zawart = co;
+	dodajRBT(w);
+	return true;
+}
+template <typename T> bool nodrze<T>::operator+=(T co)
+{
+	dodaj(co);
+	return true;
+}
+template <typename T> bool nodrze<T>::operator-=(T co)
+{
+	usun(co);
+	return true;
+}
+template <typename T> bool nodrze<T>::operator-=(T * co)
+{
+	usun(*co);
+	return true;
+}
+template <typename T> T* nodrze<T>::operator%(T * co)
+{
+	wezel<T> * w = szukajIter(korzen,*co);
+	if (w != NIL)
+		return w;
+	else return NULL;
+}
+template <typename T> bool nodrze<T>::operator&(T co)
+{
+	return czyJest(co);
+}
+template <typename T> bool nodrze<T>::operator&(T * co)
+{
+	return czyJest(*co);
+}
+template <typename T> class iterator
+{
+	/*nodrze<T> * dd;
+	wezel<T> * akt;
+public:
+	T * operator->()
+	{
+		return akt->zawart;
+	}
+	iterator& operator++()
+	{
+		akt = dd->nastepnik(akt);
+		return this;
+	}
+	iterator& operator--()
+	{
+		akt = dd->poprzednik(akt);
+		return this;
+	}
+	T * operator=(T*)
+	{
+		akt->zawart = T;
+		return akt->zawart;
+	}*/
+	/*void start()
+	{
+		akt = maksimum(korzen);
+	}*/
+};
+template <typename T> void nodrze<T>::inIt(std::ostream & strum, wezel<T> * wsk)
+{
+	if (wsk == NIL)
+		return;
+
+  // Start from the minimumimum wsk
+	while (wsk->lewy != NIL)
+		wsk=wsk->lewy;
+	do
+	{
+		visit(wsk);
+		// Next in order will be our right child's leftmost child (if NIL, our right child)
+		if (wsk->prawy != NIL)
+		{
+			wsk = wsk->prawy;
+			while (wsk->lewy != NIL)
+				wsk = wsk->left;
+		}
+		else
+		{
+			while (true)
+			{
+				if (wsk->ojciec == NIL)
+				{
+					wsk = NIL;
+					break;
+				}
+				wsk = wsk->ojciec;
+				// If wsk is its parents left child, then its parent hasn't been visited yet
+				if (wsk->ojciec->lewy == wsk)
+					break;
+			}
+		}
+	}
+	while (wsk != NIL);
+
+};
+template <typename T> bool nodrze<T>::sprawdz()
+{
+	return (sprawdzW(korzen));
+};
+template <typename T> T * nodrze<T>::znajdz (T co, bool iter)
+{
+	return ((iter)?(szukajIter(korzen,co)->zawart):(szukajRek(korzen,co)->zawart));
+};
+template <typename T> void nodrze<T>::usun (T co)
+{
+	wezel<T> * w = szukajIter(korzen, co);
+	usunRBT(w);
+	delete w;
+}
+template <typename T> void nodrze<T>::naprawUsun (wezel<T> * x)
+{
+	wezel<T> *w;
+	while ( (x != korzen)  &&  (x->kolor == CZARNY) )
+	{
+		CLOG("6... "<<std::flush);
+		if (x == x->ojciec->lewy)
+		{
+			CLOG("7... "<<std::flush);
+			w = x->ojciec->prawy;
+			if (w->kolor == CZERWONY)
+			{
+				w->kolor = CZARNY;
+				x->ojciec->kolor = CZERWONY;
+				rotacjaLewa(x->ojciec);
+				w = x->ojciec->prawy;
+			}
+			CLOG("8... "<<std::flush);
+			if ( (w->lewy->kolor == CZARNY)  &&  (w->prawy->kolor == CZARNY) )
+			{
+				CLOG("8,1... "<<std::flush);
+				w->kolor = CZERWONY;
+				x = x->ojciec;
+			}
+			else
+			{
+				CLOG("9... "<<std::flush);
+				if (w->prawy->kolor == CZARNY)
+				{
+					CLOG("9,1... "<<std::flush);
+					w->lewy->kolor = CZARNY;
+					w->kolor = CZERWONY;
+					rotacjaPrawa(w);
+					w = x->ojciec->prawy;
+					CLOG("9,2... "<<std::flush);
+				}
+				CLOG("9,3... "<<std::flush);
+				w->kolor = x->ojciec->kolor;
+				x->ojciec->kolor = CZARNY;
+				w->prawy->kolor = CZARNY;
+				rotacjaLewa(x->ojciec);
+				x=korzen;
+				CLOG("9,4... "<<std::flush);
+
+			}
+		}
+		else
+		{
+			CLOG("10... "<<std::flush);
+			w = x->ojciec->lewy;
+			if (w->kolor == CZERWONY)
+			{
+				w->kolor = CZARNY;
+				x->ojciec->kolor = CZERWONY;
+				rotacjaPrawa(x->ojciec);
+				w = x->ojciec->lewy;
+			}
+			CLOG("11... "<<std::flush);
+			if ( (w->lewy->kolor == CZARNY)  &&  (w->prawy->kolor == CZARNY) )
+			{
+				w->kolor = CZERWONY;
+				x = x->ojciec;
+			}
+			else
+			{
+				if (w->lewy->kolor == CZARNY)
+				{
+					w->prawy->kolor = CZARNY;
+					w->kolor = CZERWONY;
+					rotacjaLewa(w);
+					w = x->ojciec->lewy;
+				}
+				w->kolor = x->ojciec->kolor;
+				x->ojciec->kolor = CZARNY;
+				w->lewy->kolor = CZARNY;
+				rotacjaPrawa(x->ojciec);
+				x=korzen;
+				CLOG("12... "<<std::flush);
+			}
+		}
+	}
+	x->kolor = CZARNY;
+	CLOG("13... "<<std::flush);
+};
+template <typename T> wezel<T> * nodrze<T>::usunRBT (wezel<T> * nowy)
+{
+	CLOG ("Usuwam "<<*nowy->zawart<<std::endl);
+	ile--;
+	if ((*nowy->zawart) < (*ostatnio->zawart))
+	{
+		ktory--;
+		CLOG("Ostatnio to "<<(*ostatnio->zawart)<<", czyli teraz "<<(ktory)<<" (mniej) element."<<std::endl);
+	}
+	else if (nowy == ostatnio)
+	{
+		CLOG ("To by³ ostatnio ogl¹dany element. Elementem o numerze "<<ktory<<" bedzie teraz ");
+		if (ktory < ile)
+		{
+			ostatnio = nastepnik(ostatnio);
+		}
+		else
+		{
+			CLOG ("Ojej, koniec. Cofamy siê. "<<std::endl);
+			ostatnio = poprzednik(ostatnio);
+			ktory--;
+		}
+		CLOG(*ostatnio->zawart<<std::endl);
+	}
+	CLOG("1... "<<std::flush);
+	wezel<T> *y, *x;
+	if ( (nowy->lewy == NIL)  ||  (nowy->prawy == NIL) )
+		y=nowy;
+	else y = nastepnik(nowy);
+	CLOG("2... "<<std::flush);
+	if (y->lewy != NIL)
+		x = y->lewy;
+	else x = y->prawy;
+	x->ojciec = y->ojciec;
+	CLOG("3... "<<std::flush);
+	if (y->ojciec == NIL)
+		korzen = x;
+	else if (y == y->ojciec->lewy)
+		y->ojciec->lewy = x;
+	else
+		y->ojciec->prawy = x;
+	CLOG("4... "<<std::flush);
+	if (y != nowy)
+		(*nowy) = (*y); // skopiowanie
+	CLOG("5... "<<std::flush);
+	if (y->kolor == CZARNY)
+		naprawUsun(x);
+	CLOG ("koniec usuwania"<<std::endl);
+	return y;
+};
+template <typename T> void nodrze<T>::naprawWstaw (wezel<T> * nowy)
+{
+	//CLOG ("Naprawiam po wstawieniu"<<std::endl);
+	while (nowy->ojciec->kolor==CZERWONY)
+	{
+		if (nowy->ojciec == nowy->ojciec->ojciec->lewy) // ojciec nowego lest lewy
+		{
+			wezel<T> * y = nowy->ojciec->ojciec->prawy;
+			if (y->kolor == CZERWONY) // a stryj jest czerwony
+			{
+				nowy->ojciec->kolor = CZARNY;
+				y->kolor = CZARNY;
+				nowy->ojciec->ojciec->kolor = CZERWONY;
+				nowy = nowy->ojciec->ojciec;
+			}
+			else
+			{
+				if (nowy->ojciec->prawy == nowy) // nowy jest prawym synem
+				{
+					nowy = nowy->ojciec;
+					rotacjaLewa(nowy);
+				}
+				nowy->ojciec->kolor=CZARNY;
+				nowy->ojciec->ojciec->kolor=CZERWONY;
+				rotacjaPrawa(nowy->ojciec->ojciec);
+			}
+		}
+		else
+		{
+			wezel<T> * y = nowy->ojciec->ojciec->lewy;
+			if (y->kolor == CZERWONY) // a stryj jest czerwony
+			{
+				nowy->ojciec->kolor = CZARNY;
+				y->kolor = CZARNY;
+				nowy->ojciec->ojciec->kolor = CZERWONY;
+				nowy = nowy->ojciec->ojciec;
+			}
+			else
+			{
+				if (nowy->ojciec->lewy == nowy)
+				{
+					nowy = nowy->ojciec;
+					rotacjaPrawa(nowy);
+				}
+				nowy->ojciec->kolor=CZARNY;
+				nowy->ojciec->ojciec->kolor=CZERWONY;
+				rotacjaLewa(nowy->ojciec->ojciec);
+			}
+		}
+	}
+	korzen->kolor = CZARNY;
+}
+template <typename T> void nodrze<T>::dodajRBT (wezel<T> * nowy)
+{
+	//CLOG("Dodaje do drzewa "<<nowy->zawart<<std::endl);
+	ile++;
+	if(ostatnio==NIL)
+	{
+		ostatnio = nowy;
+		ktory=0;
+	}
+	else if ((*nowy->zawart) < (*ostatnio->zawart))
+	{
+		ktory++;
+	}
+	wezel<T> * y =NIL, * x = korzen;
+	while (x != NIL)
+	{
+		y=x;
+		if ((*nowy->zawart) < (*x->zawart))
+			x=x->lewy;
+		else x = x->prawy;
+	}
+	nowy->ojciec = y;
+	if (y == NIL)
+	{
+		korzen=nowy;
+		ostatnio=korzen;
+		ktory=0;
+	}
+	else if ((*nowy->zawart) < (*y->zawart))
+		y->lewy = nowy;
+	else y->prawy = nowy;
+	nowy->kolor = CZERWONY;
+	naprawWstaw(nowy);
+};
+template <typename T> void nodrze<T>::dodaj (T co)
+{
+	wezel<T> * w = new wezel<T>(NIL);
+	w->lewy=w->prawy=w->ojciec=NIL;
+	w->zawart = new T(co);
+	dodajRBT(w);
+}
+template <typename T> void nodrze<T>::zepsuj()
+{
+	int pom;
+	pom = *korzen->zawart;
+	*korzen->zawart = *korzen->prawy->zawart;
+	*korzen->prawy->zawart = pom;
+}
+template <typename T> bool nodrze<T>::czyBST (wezel<T> * w)
+{
+	if (w->prawy != NIL)
+	{
+		if ((*w->prawy->zawart) < (*w->zawart))
+			return false;
+	}
+	if (w->lewy != NIL)
+	{
+		if((*w->lewy->zawart) > (*w->zawart))
+			return false;
+	}
+	return true;
+}
+template <typename T> bool nodrze<T>::sprawdzW(wezel<T> * w)
+{
+	bool ret = czyBST(w);
+	if (w->prawy != NIL)
+		ret&=sprawdzW(w->prawy);
+	if (w->lewy != NIL)
+		ret&=sprawdzW(w->lewy);
+	return ret;
+}
+template <typename T> void nodrze<T>::rotacjaLewa (wezel<T> * x)
+{
+	//CLOG("Wykonuje lew¹ rotacjê na "<<x->zawart<<std::endl);
+	wezel<T> * y = x->prawy;
+	x->prawy = y->lewy; // zamiana lewego poddrzewa y na prawe poddrzewo x
+	if (y->lewy != NIL) y->lewy->ojciec = x; // i przypisanie ojcostwa temu poddrzewu
+	y->ojciec = x->ojciec; // ojcem y bedzie ojciec x
+	if (x->ojciec == NIL)
+		korzen = y;
+	else if ((x->ojciec->lewy) == x)
+		x->ojciec->lewy = y;
+	else
+		x->ojciec->prawy = y;
+	y->lewy = x; // a x bedzie lewym synem y
+	x->ojciec = y;
+};
+template <typename T> void nodrze<T>::rotacjaPrawa (wezel<T> * y)
+{
+	//CLOG("Wykonuje prawa rotacjê na "<<y->zawart<<std::endl);
+	wezel<T> * x = y->lewy;
+	y->lewy = x->prawy; // zamiana prawe poddrzewa x na lewe poddrzewo y
+	if (x->prawy != NIL) x->prawy->ojciec = y; // i przypisanie ojcostwa temu poddrzewu
+	x->ojciec = y->ojciec; // ojcem x bedzie ojciec y
+	if (x->ojciec == NIL)
+		korzen = x;
+	else if ((y->ojciec->lewy) == y)
+		y->ojciec->lewy = x;
+	else
+		y->ojciec->prawy = x;
+	x->prawy = y; // a y bedzie prawym synem x
+	y->ojciec = x;
+};
+template <typename T> T * nodrze<T>::nast(T czego)
+{
+	wezel<T> * w = szukajIter(korzen,czego);
+	if (w != NIL)
+		w = nastepnik(w);
+	else throw std::exception("Nie znaleziono wartosci");
+	if (w != NIL)
+		return (w->zawart);
+	else throw std::exception("Nie znaleziono nastepnika");
+};
+template <typename T> bool nodrze<T>::czyJest(T co)
+{
+	if ( szukajIter(korzen,co) != NIL )
+		return true;
+	else return false;
+}
+template <typename T> wezel<T> * nodrze<T>::szukajRek(wezel<T> * w, T co)
+{
+	if (w==NIL || (!(((*w->zawart)<co)||(co<(*w->zawart)))))
+		return w;
+	if (co < (*w->zawart))
+		return szukajRek(w->lewy,co);
+	else return szukajRek(w->prawy,co);
+};
+template <typename T> wezel<T> * nodrze<T>::szukajIter(wezel<T> * w, T co)
+{
+	while ( w!=NIL && (((*w->zawart)<co)||(co<(*w->zawart))) )
+	{
+		if (co < (*w->zawart))
+			w=w->lewy;
+		else w=w->prawy;
+	}
+	return (w)?w:NULL;
+};
+template <typename T> wezel<T> * nodrze<T>::minimum(wezel<T> * w)
+{
+	while (w->lewy != NIL)
+		w=w->lewy;
+	return w;
+};
+template <typename T> wezel<T> * nodrze<T>::maksimum(wezel<T> * w)
+{
+	while (w->prawy != NIL)
+		w=w->prawy;
+	return w;
+};
+template <typename T> wezel<T> * nodrze<T>::nastepnik(wezel<T> * w)
+{
+	if (w->prawy != NIL)
+		return minimum(w->prawy);
+	wezel<T> * y = w->ojciec;
+	while (y!= NIL && w == y->prawy)
+	{
+		w=y;
+		y=y->ojciec;
+	}
+	return y;
+};
+template <typename T> wezel<T> * nodrze<T>::poprzednik(wezel<T> * w)
+{
+	if (w->lewy != NIL)
+		return maksimum(w->lewy);
+	wezel<T> * y = w->ojciec;
+	while (y!= NIL && w == y->lewy)
+	{
+		w=y;
+		y=y->ojciec;
+	}
+	return y;
+};
+template <typename T> T * nodrze<T>::maksimumimum ()
+{
+	wezel<T> * ret = maksimum(korzen);
+	if (ret != NIL)
+		return (ret->zawart);
+	else throw std::exception("Drzewo jest puste");
+};
+template <typename T> T * nodrze<T>::minimumimum ()
+{
+	wezel<T> * ret = minimum(korzen);
+	if (ret != NIL)
+		return (ret->zawart);
+	else throw std::exception("Drzewo jest puste");
+};
+template <typename T> void nodrze<T>::inorder(std::ostream & strum)
+{
+	in(strum,korzen);
+}
+template <typename T> void nodrze<T>::preorder(std::ostream & strum)
+{
+	pre(strum,korzen);
+}
+template <typename T> void nodrze<T>::postorder(std::ostream & strum)
+{
+	post(strum,korzen);
+}
+template <typename T> void nodrze<T>::in(std::ostream & strum, wezel<T> * wsk)
+{
+	if (wsk==NIL)
+		return;
+	if (wsk->lewy != NIL)
+		in(strum,wsk->lewy);
+	strum << *wsk->zawart<<"\t";
+	if (wsk->prawy != NIL)
+		in(strum,wsk->prawy);
+};
+template <typename T> void nodrze<T>::post(std::ostream & strum, wezel<T> * wsk)
+{
+	if (wsk==NIL)
+		return;
+	if (wsk->lewy != NIL)
+		post(strum,wsk->lewy);
+	if (wsk->prawy != NIL)
+		post(strum,wsk->prawy);
+	strum << *wsk->zawart<<"\t";
+};
+template <typename T> void nodrze<T>::pre(std::ostream & strum, wezel<T> * wsk)
+{
+	if (wsk == NIL)
+		return;
+	strum << *wsk->zawart<<"\t";
+	if (wsk->lewy != NIL)
+		pre(strum,wsk->lewy);
+	if (wsk->prawy != NIL)
+		pre(strum,wsk->prawy);
+};
+#endif //_NODRZE_H

+ 171 - 172
server/CGameHandler.h

@@ -1,173 +1,172 @@
-#ifndef CGAMEHANDLER_H
-#define CGAMEHANDLER_H
-
-#pragma once
-#include "../global.h"
-#include <set>
-#include "../client/FunctionList.h"
-#include "../CGameState.h"
-#include "../lib/Connection.h"
-#include "../lib/IGameCallback.h"
-#include <boost/function.hpp>
-#include <boost/thread.hpp>
-class CVCMIServer;
-class CGameState;
-struct StartInfo;
-class CCPPObjectScript;
-class CScriptCallback;
-struct BattleResult;
-struct BattleAttack;
-struct BattleStackAttacked;
-template <typename T> struct CPack;
-template <typename T> struct Query;
-class CGHeroInstance;
-extern std::map<ui32, CFunctionList<void(ui32)> > callbacks; //question id => callback functions - for selection dialogs
-extern boost::mutex gsm;
-
-struct PlayerStatus
-{
-	bool makingTurn, engagedIntoBattle;
-	std::set<ui32> queries;
-
-	PlayerStatus():makingTurn(false),engagedIntoBattle(false){};
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & makingTurn & engagedIntoBattle & queries;
-	}
-};
-class PlayerStatuses
-{
-public:
-	std::map<ui8,PlayerStatus> players;
-	boost::mutex mx;
-	boost::condition_variable cv; //notifies when any changes are made
-
-	void addPlayer(ui8 player);
-	PlayerStatus operator[](ui8 player);
-	bool hasQueries(ui8 player);
-	bool checkFlag(ui8 player, bool PlayerStatus::*flag);
-	void setFlag(ui8 player, bool PlayerStatus::*flag, bool val);
-	void addQuery(ui8 player, ui32 id);
-	void removeQuery(ui8 player, ui32 id);
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & players;
-	}
-};
-
-class CGameHandler : public IGameCallback
-{
-	static ui32 QID;
-	CGameState *gs;
-	//std::set<CCPPObjectScript *> cppscripts; //C++ scripts
-	//std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts 
-
-	CVCMIServer *s;
-	std::map<int,CConnection*> connections; //player color -> connection to clinet with interface of that player
-	PlayerStatuses states; //player color -> player state
-	std::set<CConnection*> conns;
-
-	void changeSecSkill(int ID, ui16 which, int val, bool abs=false);
-	void giveSpells(const CGTownInstance *t, const CGHeroInstance *h);
-	void moveStack(int stack, int dest);
-	void startBattle(CCreatureSet army1, CCreatureSet army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb); //use hero=NULL for no hero
-	void prepareAttack(BattleAttack &bat, CStack *att, CStack *def); //if last parameter is true, attack is by shooting, if false it's a melee attack
-	void prepareAttacked(BattleStackAttacked &bsa, CStack *def);
-	void checkForBattleEnd( std::vector<CStack*> &stacks );
-	void setupBattle( BattleInfo * curB, int3 tile, CCreatureSet &army1, CCreatureSet &army2, CGHeroInstance * hero1, CGHeroInstance * hero2 );
-
-public:
-	CGameHandler(void);
-	~CGameHandler(void);
-
-	//////////////////////////////////////////////////////////////////////////
-	//from IGameCallback
-	//get info
-	int getOwner(int heroID);
-	int getResource(int player, int which);
-	int getSelectedHero();
-	int getDate(int mode=0);
-	const CGObjectInstance* getObj(int objid);
-	const CGHeroInstance* getHero(int objid);
-	const CGTownInstance* getTown(int objid);
-	const CGHeroInstance* getSelectedHero(int player); //NULL if no hero is selected
-	int getCurrentPlayer();
-
-	//do sth
-	void changeSpells(int hid, bool give, const std::set<ui32> &spells);
-	void removeObject(int objid);
-	void setBlockVis(int objid, bool bv);
-	void setOwner(int objid, ui8 owner);
-	void setHoverName(int objid, MetaString * name);
-	void changePrimSkill(int ID, int which, int val, bool abs=false);
-	void showInfoDialog(InfoWindow *iw);
-	void showYesNoDialog(YesNoDialog *iw, const CFunctionList<void(ui32)> &callback);
-	void showSelectionDialog(SelectionDialog *iw, const CFunctionList<void(ui32)> &callback); //returns question id
-	void giveResource(int player, int which, int val);
-	void showCompInfo(ShowInInfobox * comp);
-	void heroVisitCastle(int obj, int heroID);
-	void stopHeroVisitCastle(int obj, int heroID);
-	void giveHeroArtifact(int artid, int hid, int position); //pos==-1 - first free slot in backpack; pos==-2 - default if available or backpack
-	void startBattleI(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb); //use hero=NULL for no hero
-	void startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb); //for hero<=>neutral army
-	void setAmount(int objid, ui32 val);
-	void moveHero(int hid, int3 pos, bool instant);
-	//////////////////////////////////////////////////////////////////////////
-
-	void init(StartInfo *si, int Seed);
-	void handleConnection(std::set<int> players, CConnection &c);
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & QID & gs & states;
-	}
-	template <typename T> void applyAndAsk(Query<T> * sel, ui8 player, boost::function<void(ui32)> &callback)
-	{
-		gsm.lock();
-		sel->id = QID;
-		callbacks[QID] = callback;
-		states.addQuery(player,QID);
-		QID++; 
-		sendAndApply(sel);
-		gsm.unlock();
-	}
-	template <typename T> void ask(Query<T> * sel, ui8 player, const CFunctionList<void(ui32)> &callback)
-	{
-		gsm.lock();
-		sel->id = QID;
-		callbacks[QID] = callback;
-		states.addQuery(player,QID);
-		sendToAllClients(sel);
-		QID++; 
-		gsm.unlock();
-	}
-
-	template <typename T>void sendDataToClients(const T & data)
-	{
-		for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
-		{
-			(*i)->wmx->lock();
-			**i << data;
-			(*i)->wmx->unlock();
-		}
-	}
-	template <typename T>void sendToAllClients(CPack<T> * info)
-	{
-		for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
-		{
-			(*i)->wmx->lock();
-			**i << info->getType() << *info->This();
-			(*i)->wmx->unlock();
-		}
-	}
-	template <typename T>void sendAndApply(CPack<T> * info)
-	{
-		gs->apply(info);
-		sendToAllClients(info);
-	}
-	void run();
-	void newTurn();
-
-	friend class CVCMIServer;
-	friend class CScriptCallback;
-};
+#ifndef CGAMEHANDLER_H
+#define CGAMEHANDLER_H
+
+#include "../global.h"
+#include <set>
+#include "../client/FunctionList.h"
+#include "../CGameState.h"
+#include "../lib/Connection.h"
+#include "../lib/IGameCallback.h"
+#include <boost/function.hpp>
+#include <boost/thread.hpp>
+class CVCMIServer;
+class CGameState;
+struct StartInfo;
+class CCPPObjectScript;
+class CScriptCallback;
+struct BattleResult;
+struct BattleAttack;
+struct BattleStackAttacked;
+template <typename T> struct CPack;
+template <typename T> struct Query;
+class CGHeroInstance;
+extern std::map<ui32, CFunctionList<void(ui32)> > callbacks; //question id => callback functions - for selection dialogs
+extern boost::mutex gsm;
+
+struct PlayerStatus
+{
+	bool makingTurn, engagedIntoBattle;
+	std::set<ui32> queries;
+
+	PlayerStatus():makingTurn(false),engagedIntoBattle(false){};
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & makingTurn & engagedIntoBattle & queries;
+	}
+};
+class PlayerStatuses
+{
+public:
+	std::map<ui8,PlayerStatus> players;
+	boost::mutex mx;
+	boost::condition_variable cv; //notifies when any changes are made
+
+	void addPlayer(ui8 player);
+	PlayerStatus operator[](ui8 player);
+	bool hasQueries(ui8 player);
+	bool checkFlag(ui8 player, bool PlayerStatus::*flag);
+	void setFlag(ui8 player, bool PlayerStatus::*flag, bool val);
+	void addQuery(ui8 player, ui32 id);
+	void removeQuery(ui8 player, ui32 id);
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & players;
+	}
+};
+
+class CGameHandler : public IGameCallback
+{
+	static ui32 QID;
+	CGameState *gs;
+	//std::set<CCPPObjectScript *> cppscripts; //C++ scripts
+	//std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts 
+
+	CVCMIServer *s;
+	std::map<int,CConnection*> connections; //player color -> connection to clinet with interface of that player
+	PlayerStatuses states; //player color -> player state
+	std::set<CConnection*> conns;
+
+	void changeSecSkill(int ID, ui16 which, int val, bool abs=false);
+	void giveSpells(const CGTownInstance *t, const CGHeroInstance *h);
+	void moveStack(int stack, int dest);
+	void startBattle(CCreatureSet army1, CCreatureSet army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb); //use hero=NULL for no hero
+	void prepareAttack(BattleAttack &bat, CStack *att, CStack *def); //if last parameter is true, attack is by shooting, if false it's a melee attack
+	void prepareAttacked(BattleStackAttacked &bsa, CStack *def);
+	void checkForBattleEnd( std::vector<CStack*> &stacks );
+	void setupBattle( BattleInfo * curB, int3 tile, CCreatureSet &army1, CCreatureSet &army2, CGHeroInstance * hero1, CGHeroInstance * hero2 );
+
+public:
+	CGameHandler(void);
+	~CGameHandler(void);
+
+	//////////////////////////////////////////////////////////////////////////
+	//from IGameCallback
+	//get info
+	int getOwner(int heroID);
+	int getResource(int player, int which);
+	int getSelectedHero();
+	int getDate(int mode=0);
+	const CGObjectInstance* getObj(int objid);
+	const CGHeroInstance* getHero(int objid);
+	const CGTownInstance* getTown(int objid);
+	const CGHeroInstance* getSelectedHero(int player); //NULL if no hero is selected
+	int getCurrentPlayer();
+
+	//do sth
+	void changeSpells(int hid, bool give, const std::set<ui32> &spells);
+	void removeObject(int objid);
+	void setBlockVis(int objid, bool bv);
+	void setOwner(int objid, ui8 owner);
+	void setHoverName(int objid, MetaString * name);
+	void changePrimSkill(int ID, int which, int val, bool abs=false);
+	void showInfoDialog(InfoWindow *iw);
+	void showYesNoDialog(YesNoDialog *iw, const CFunctionList<void(ui32)> &callback);
+	void showSelectionDialog(SelectionDialog *iw, const CFunctionList<void(ui32)> &callback); //returns question id
+	void giveResource(int player, int which, int val);
+	void showCompInfo(ShowInInfobox * comp);
+	void heroVisitCastle(int obj, int heroID);
+	void stopHeroVisitCastle(int obj, int heroID);
+	void giveHeroArtifact(int artid, int hid, int position); //pos==-1 - first free slot in backpack; pos==-2 - default if available or backpack
+	void startBattleI(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb); //use hero=NULL for no hero
+	void startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb); //for hero<=>neutral army
+	void setAmount(int objid, ui32 val);
+	void moveHero(int hid, int3 pos, bool instant);
+	//////////////////////////////////////////////////////////////////////////
+
+	void init(StartInfo *si, int Seed);
+	void handleConnection(std::set<int> players, CConnection &c);
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & QID & gs & states;
+	}
+	template <typename T> void applyAndAsk(Query<T> * sel, ui8 player, boost::function<void(ui32)> &callback)
+	{
+		gsm.lock();
+		sel->id = QID;
+		callbacks[QID] = callback;
+		states.addQuery(player,QID);
+		QID++; 
+		sendAndApply(sel);
+		gsm.unlock();
+	}
+	template <typename T> void ask(Query<T> * sel, ui8 player, const CFunctionList<void(ui32)> &callback)
+	{
+		gsm.lock();
+		sel->id = QID;
+		callbacks[QID] = callback;
+		states.addQuery(player,QID);
+		sendToAllClients(sel);
+		QID++; 
+		gsm.unlock();
+	}
+
+	template <typename T>void sendDataToClients(const T & data)
+	{
+		for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
+		{
+			(*i)->wmx->lock();
+			**i << data;
+			(*i)->wmx->unlock();
+		}
+	}
+	template <typename T>void sendToAllClients(CPack<T> * info)
+	{
+		for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
+		{
+			(*i)->wmx->lock();
+			**i << info->getType() << *info->This();
+			(*i)->wmx->unlock();
+		}
+	}
+	template <typename T>void sendAndApply(CPack<T> * info)
+	{
+		gs->apply(info);
+		sendToAllClients(info);
+	}
+	void run();
+	void newTurn();
+
+	friend class CVCMIServer;
+	friend class CScriptCallback;
+};
 #endif //CGAMEHANDLER_H

+ 34 - 32
server/CVCMIServer.h

@@ -1,32 +1,34 @@
-#pragma once
-#include "../global.h"
-#include <set>
-class CConnection;
-namespace boost
-{
-	namespace asio
-	{
-		class io_service;
-		namespace ip
-		{
-			class tcp;
-		}
-		template <typename Protocol> class socket_acceptor_service;
-		template <typename Protocol,typename SocketAcceptorService>
-		class basic_socket_acceptor;
-	}
-};
-
-class CVCMIServer
-{
-	boost::asio::io_service *io;
-	boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::socket_acceptor_service<boost::asio::ip::tcp> > * acceptor;
-	std::map<int,CConnection*> connections;
-	std::set<CConnection*> conns;
-public:
-	CVCMIServer();
-	~CVCMIServer();
-	void setUpConnection(CConnection *c, std::string mapname, si32 checksum);
-	void newGame(CConnection *c);
-	void start();
-};
+#ifndef __CVCMISERVER_H__
+#define __CVCMISERVER_H__
+#include "../global.h"
+#include <set>
+class CConnection;
+namespace boost
+{
+	namespace asio
+	{
+		class io_service;
+		namespace ip
+		{
+			class tcp;
+		}
+		template <typename Protocol> class socket_acceptor_service;
+		template <typename Protocol,typename SocketAcceptorService>
+		class basic_socket_acceptor;
+	}
+};
+
+class CVCMIServer
+{
+	boost::asio::io_service *io;
+	boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::socket_acceptor_service<boost::asio::ip::tcp> > * acceptor;
+	std::map<int,CConnection*> connections;
+	std::set<CConnection*> conns;
+public:
+	CVCMIServer();
+	~CVCMIServer();
+	void setUpConnection(CConnection *c, std::string mapname, si32 checksum);
+	void newGame(CConnection *c);
+	void start();
+};
+#endif // __CVCMISERVER_H__

+ 92 - 0
server/vcmi_server/Makefile

@@ -0,0 +1,92 @@
+#
+#  There exist several targets which are by default empty and which can be 
+#  used for execution of your targets. These targets are usually executed 
+#  before and after some main targets. They are: 
+#
+#     .build-pre:              called before 'build' target
+#     .build-post:             called after 'build' target
+#     .clean-pre:              called before 'clean' target
+#     .clean-post:             called after 'clean' target
+#     .clobber-pre:            called before 'clobber' target
+#     .clobber-post:           called after 'clobber' target
+#     .all-pre:                called before 'all' target
+#     .all-post:               called after 'all' target
+#     .help-pre:                called before 'help' target
+#     .help-post:               called after 'help' target
+#
+#  Targets beginning with '.' are not intended to be called on their own.
+#
+#  Main targets can be executed directly, and they are:
+#  
+#     build                    build a specific configuration
+#     clean                    remove built files from a configuration
+#     clobber                  remove all built files
+#     all                      build all configurations
+#     help                     print help mesage
+#  
+#  Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
+#  .help-impl are implemented in nbproject/makefile-impl.mk.
+#
+# NOCDDL
+
+
+# Environment 
+MKDIR=mkdir
+CP=cp
+CCADMIN=CCadmin
+RANLIB=ranlib
+
+
+# build
+build: .build-post
+
+.build-pre:
+# Add your pre 'build' code here...
+
+.build-post: .build-impl
+# Add your post 'build' code here...
+
+
+# clean
+clean: .clean-post
+
+.clean-pre:
+# Add your pre 'clean' code here...
+
+.clean-post: .clean-impl
+# Add your post 'clean' code here...
+
+
+# clobber
+clobber: .clobber-post
+
+.clobber-pre:
+# Add your pre 'clobber' code here...
+
+.clobber-post: .clobber-impl
+# Add your post 'clobber' code here...
+
+
+# all
+all: .all-post
+
+.all-pre:
+# Add your pre 'all' code here...
+
+.all-post: .all-impl
+# Add your post 'all' code here...
+
+
+# help
+help: .help-post
+
+.help-pre:
+# Add your pre 'help' code here...
+
+.help-post: .help-impl
+# Add your post 'help' code here...
+
+
+
+# include project implementation makefile
+include nbproject/Makefile-impl.mk

+ 27 - 27
stdafx.h

@@ -1,27 +1,27 @@
-#ifndef _ZJEBANYNAGLOWEKWINDOWEGOVISUALAKTORENIKTNIEUZYWA_H
-#define _ZJEBANYNAGLOWEKWINDOWEGOVISUALAKTORENIKTNIEUZYWA_H
-
-// stdafx.h : include file for standard system include files,
-// or project specific include files that are used frequently, but
-// are changed infrequently
-//
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
-#include <cstdio>
-#ifdef _WIN32
-#include <tchar.h>
-#else
-#include "tchar_amigaos4.h"
-#endif
-#include <string>
-#include <vector>
-#include <map>
-#include <algorithm>
-#include <fstream>
-#include "global.h"
-// TODO: reference additional headers your program requires here
-
-#endif //_ZJEBANYNAGLOWEKWINDOWEGOVISUALAKTORENIKTNIEUZYWA_H
+#ifndef __STDAFX_H__
+#define __STDAFX_H__
+#ifndef __STDAFX_H__
+#define __STDAFX_H__
+
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
+#include <cstdio>
+#ifdef _WIN32
+#include <tchar.h>
+#else
+#include "tchar_amigaos4.h"
+#endif
+#include <string>
+#include <vector>
+#include <map>
+#include <algorithm>
+#include <fstream>
+#include "global.h"
+// TODO: reference additional headers your program requires here
+
+#endif // __STDAFX_H__
+#endif // __STDAFX_H__