Bladeren bron

Fighting with includes.

Michał W. Urbańczyk 17 jaren geleden
bovenliggende
commit
1b73678b7c
19 gewijzigde bestanden met toevoegingen van 175 en 154 verwijderingen
  1. 3 1
      CAdvmapInterface.cpp
  2. 17 16
      CBattleInterface.cpp
  3. 5 4
      CCallback.cpp
  4. 12 9
      CCallback.h
  5. 1 0
      CCastleInterface.cpp
  6. 9 9
      CConsoleHandler.cpp
  7. 1 3
      CGameInfo.h
  8. 1 1
      CGameState.h
  9. 2 0
      CHeroWindow.cpp
  10. 2 0
      CLua.cpp
  11. 1 1
      CMT.cpp
  12. 1 0
      CPathfinder.cpp
  13. 3 0
      CPlayerInterface.cpp
  14. 26 0
      client/Graphics.cpp
  15. 5 2
      client/Graphics.h
  16. 5 27
      mapHandler.cpp
  17. 9 8
      mapHandler.h
  18. 1 1
      server/VCMI_server.vcproj
  19. 71 72
      server/server_main.cpp

+ 3 - 1
CAdvmapInterface.cpp

@@ -20,6 +20,8 @@
 #include "AdventureMapButton.h"
 #include "CHeroWindow.h"
 #include "client/Graphics.h"
+#include "hch/CObjectHandler.h"
+#include "map.h"
 #pragma warning (disable : 4355) 
 extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
 
@@ -558,7 +560,7 @@ void CTerrainRect::show()
 	SDL_Surface * teren = CGI->mh->terrainRect
 		(LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
 		tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
-		LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
+		&LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
 		screen,&genRect(547,594,7,6)
 		);
 	//SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));

+ 17 - 16
CBattleInterface.cpp

@@ -4,6 +4,7 @@
 #include "SDL_Extensions.h"
 #include "CAdvmapInterface.h"
 #include "AdventureMapButton.h"
+#include "hch/CObjectHandler.h"
 #include "hch/CHeroHandler.h"
 #include "hch/CDefHandler.h"
 #include "CCallback.h"
@@ -35,7 +36,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
 		creDir[b->second.ID] = b->second.owner==attackingHeroInstance->tempOwner;
 	}
 	//preparing menu background and terrain
-	std::vector< std::string > & backref = CGI->mh->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ];
+	std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ];
 	background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] );
 	menu = BitmapHandler::loadBitmap("CBAR.BMP");
 	graphics->blueToPlayersAdv(menu, hero1->tempOwner);
@@ -81,7 +82,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
 	//loading hero animations
 	if(hero1) // attacking hero
 	{
-		attackingHero = new CBattleHero(CGI->mh->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner);
+		attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner);
 		attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40, 0);
 	}
 	else
@@ -90,7 +91,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
 	}
 	if(hero2) // defending hero
 	{
-		defendingHero = new CBattleHero(CGI->mh->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner);
+		defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner);
 		defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690, 0);
 	}
 	else
@@ -323,7 +324,7 @@ bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
 	}
 	creDir[number] = !creDir[number];
 
-	CStack curs = LOCPLINT->cb->battleGetStackByID(number);
+	CStack curs = *LOCPLINT->cb->battleGetStackByID(number);
 	std::pair <int, int> coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature);
 	creAnims[number]->pos.x = coords.first;
 	//creAnims[number]->pos.y = coords.second;
@@ -504,7 +505,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo
 			CSDL_Ext::update();
 			SDL_framerateDelay(LOCPLINT->mainFPSmng);
 		}
-		if( (LOCPLINT->cb->battleGetStackByID(number).owner == attackingHeroInstance->tempOwner ) != creDir[number])
+		if( (LOCPLINT->cb->battleGetStackByID(number)->owner == attackingHeroInstance->tempOwner ) != creDir[number])
 		{
 			reverseCreature(number, curStackPos, true);
 		}
@@ -585,7 +586,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo
 	}
 
 	creAnims[number]->setType(2); //resetting to default
-	CStack curs = LOCPLINT->cb->battleGetStackByID(number);
+	CStack curs = *LOCPLINT->cb->battleGetStackByID(number);
 	if(endMoving) //resetting to default
 	{
 		if(creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))
@@ -614,7 +615,7 @@ void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby)
 
 void CBattleInterface::stackAttacking(int ID, int dest)
 {
-	CStack aStack = LOCPLINT->cb->battleGetStackByID(ID); //attacking stack
+	CStack aStack = *LOCPLINT->cb->battleGetStackByID(ID); //attacking stack
 	if(aStack.creature->isDoubleWide())
 	{
 		switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
@@ -733,7 +734,7 @@ void CBattleInterface::hexLclicked(int whichOne)
 			ba->stackNumber = activeStack;
 			givenCommand = ba;
 		}
-		else if(LOCPLINT->cb->battleGetStackByID(atCre).owner != attackingHeroInstance->tempOwner) //attacking
+		else if(LOCPLINT->cb->battleGetStackByID(atCre)->owner != attackingHeroInstance->tempOwner) //attacking
 		{
 			BattleAction * ba = new BattleAction(); //to be deleted by engine
 			ba->actionType = 6;
@@ -760,7 +761,7 @@ void CBattleInterface::attackingShowHelper()
 	{
 		if(attackingInfo->frame == 0)
 		{
-			CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
+			CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
 			if(aStack.creature->isDoubleWide())
 			{
 				switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
@@ -813,7 +814,7 @@ void CBattleInterface::attackingShowHelper()
 		else if(attackingInfo->frame == (attackingInfo->maxframe - 1))
 		{
 			attackingInfo->reversing = true;
-			CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
+			CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
 			if(aStack.creature->isDoubleWide())
 			{
 				switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
@@ -871,8 +872,8 @@ void CBattleInterface::attackingShowHelper()
 void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDby)
 {
 	char tabh[200];
-	CStack attacker = LOCPLINT->cb->battleGetStackByID(IDby);
-	CStack defender = LOCPLINT->cb->battleGetStackByID(ID);
+	CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby);
+	CStack defender = *LOCPLINT->cb->battleGetStackByID(ID);
 	int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker.amount > 1 ? 377 : 376].c_str(),
 		(attacker.amount > 1 ? attacker.creature->namePl.c_str() : attacker.creature->nameSing.c_str()),
 		dmg);
@@ -1054,11 +1055,11 @@ void CBattleHex::mouseMoved(SDL_MouseMotionEvent &sEvent)
 	if(hovered && strictHovered) //print attacked creature to console
 	{
 		if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 &&
-			LOCPLINT->cb->battleGetStackByPos(myNumber).owner != LOCPLINT->playerID &&
-			LOCPLINT->cb->battleGetStackByPos(myNumber).alive)
+			LOCPLINT->cb->battleGetStackByPos(myNumber)->owner != LOCPLINT->playerID &&
+			LOCPLINT->cb->battleGetStackByPos(myNumber)->alive)
 		{
 			char tabh[160];
-			CStack attackedStack = LOCPLINT->cb->battleGetStackByPos(myNumber);
+			CStack attackedStack = *LOCPLINT->cb->battleGetStackByPos(myNumber);
 			std::string attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl;
 			sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str());
 			myInterface->console->alterTxt = std::string(tabh);
@@ -1085,7 +1086,7 @@ void CBattleHex::clickRight(boost::logic::tribool down)
 	int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile
 	if(hovered && strictHovered && stID!=-1)
 	{
-		CStack myst = LOCPLINT->cb->battleGetStackByID(stID); //stack info
+		CStack myst = *LOCPLINT->cb->battleGetStackByID(stID); //stack info
 		StackState *pom = NULL;
 		if(down)
 		{

+ 5 - 4
CCallback.cpp

@@ -13,6 +13,7 @@
 #include "CAdvmapInterface.h"
 #include "CPlayerInterface.h"
 #include "hch/CBuildingHandler.h"
+#include "hch/CObjectHandler.h"
 LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
 
 int CCallback::lowestSpeed(CGHeroInstance * chi)
@@ -783,17 +784,17 @@ int CCallback::battleGetStack(int pos)
 	return -1;
 }
 
-CStack CCallback::battleGetStackByID(int ID)
+CStack* CCallback::battleGetStackByID(int ID)
 {
 	for(int g=0; g<CGI->state->curB->stacks.size(); ++g)
 	{
 		if(CGI->state->curB->stacks[g]->ID == ID)
-			return *(CGI->state->curB->stacks[g]);
+			return CGI->state->curB->stacks[g];
 	}
-	return CStack();
+	return NULL;
 }
 
-CStack CCallback::battleGetStackByPos(int pos)
+CStack* CCallback::battleGetStackByPos(int pos)
 {
 	return battleGetStackByID(battleGetStack(pos));
 }

+ 12 - 9
CCallback.h

@@ -1,19 +1,22 @@
 #ifndef CCALLBACK_H
 #define CCALLBACK_H
 
-#include "mapHandler.h"
+#include "global.h"
 #include "tchar.h"
-#include "CGameState.h"
-
+#include <set>
+class CGHeroInstance;
 class CGameState;
 struct CPath;
 class CGObjectInstance;
+class CArmedInstance;
 class SComponent;
 class IChosen;
 class CSelectableComponent;
 struct BattleAction;
-typedef struct lua_State lua_State;
-
+class CGTownInstance;
+struct StartInfo;
+class CStack;
+struct lua_State;
 //structure gathering info about upgrade possibilites
 struct UpgradeInfo
 {
@@ -60,8 +63,8 @@ public:
 	virtual int battleGetBattlefieldType()=0; //   1. sand/shore   2. sand/mesas   3. dirt/birches   4. dirt/hills   5. dirt/pines   6. grass/hills   7. grass/pines   8. lava   9. magic plains   10. snow/mountains   11. snow/trees   12. subterranean   13. swamp/trees   14. fiery fields   15. rock lands   16. magic clouds   17. lucid pools   18. holy ground   19. clover field   20. evil fog   21. "favourable winds" text on magic plains background   22. cursed ground   23. rough   24. ship to ship   25. ship
 	virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield 
 	virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile
-	virtual CStack battleGetStackByID(int ID)=0; //returns stack info by given ID
-	virtual CStack battleGetStackByPos(int pos)=0; //returns stack info by given pos
+	virtual CStack * battleGetStackByID(int ID)=0; //returns stack info by given ID
+	virtual CStack * battleGetStackByPos(int pos)=0; //returns stack info by given pos
 	virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack
 	//virtual int battleMakeAction(BattleAction* action)=0;//perform action with an active stack (or custom action)
 	virtual std::map<int, CStack> battleGetStacks()=0; //returns stacks on battlefield
@@ -133,8 +136,8 @@ public:
 	int battleGetBattlefieldType(); //   1. sand/shore   2. sand/mesas   3. dirt/birches   4. dirt/hills   5. dirt/pines   6. grass/hills   7. grass/pines   8. lava   9. magic plains   10. snow/mountains   11. snow/trees   12. subterranean   13. swamp/trees   14. fiery fields   15. rock lands   16. magic clouds   17. lucid pools   18. holy ground   19. clover field   20. evil fog   21. "favourable winds" text on magic plains background   22. cursed ground   23. rough   24. ship to ship   25. ship
 	int battleGetObstaclesAtTile(int tile); //returns bitfield 
 	int battleGetStack(int pos); //returns ID of stack on the tile
-	CStack battleGetStackByID(int ID); //returns stack info by given ID
-	CStack battleGetStackByPos(int pos); //returns stack info by given pos
+	CStack * battleGetStackByID(int ID); //returns stack info by given ID
+	CStack * battleGetStackByPos(int pos); //returns stack info by given pos
 	int battleGetPos(int stack); //returns position (tile ID) of stack
 	//int battleMakeAction(BattleAction* action);//perform action with an active stack (or custom action)
 	std::map<int, CStack> battleGetStacks(); //returns stacks on battlefield

+ 1 - 0
CCastleInterface.cpp

@@ -8,6 +8,7 @@
 #include "hch/CTownHandler.h"
 #include "AdventureMapButton.h"
 #include "hch/CBuildingHandler.h"
+#include "hch/CDefHandler.h"
 #include <sstream>
 #include "CMessage.h"
 #include "hch/CGeneralTextHandler.h"

+ 9 - 9
CConsoleHandler.cpp

@@ -91,15 +91,15 @@ int internalFunc(void * callback)
 			//	readed>>heronum;
 			//	std::cout<<"Position of hero "<<heronum<<": "<<CGI->heroh->heroInstances[heronum]->getPosition(false)<<std::endl;
 			//	break;
-			case 'M': //move heroa
-				{
-					readed>>heronum>>dest;
-					const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0);
-					p = CGI->pathf->GetPath(Coordinate(hero->getPosition(false)),Coordinate(dest),hero);
-					cb->moveHero(heronum, CGI->pathf->ConvertToOldFormat(p), 0, 0);
-					//LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
-					break;
-				}
+			//case 'M': //move heroa
+			//	{
+			//		readed>>heronum>>dest;
+			//		const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0);
+			//		p = CGI->pathf->GetPath(Coordinate(hero->getPosition(false)),Coordinate(dest),hero);
+			//		cb->moveHero(heronum, CGI->pathf->ConvertToOldFormat(p), 0, 0);
+			//		//LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
+			//		break;
+			//	}
 			case 'D': //pos description
 				readed>>src;
 				CGI->mh->getObjDescriptions(src);

+ 1 - 3
CGameInfo.h

@@ -1,8 +1,6 @@
 #ifndef CGAMEINFO_H
 #define CGAMEINFO_H
-
-#include "StartInfo.h"
-#include "SDL.h"
+#include "global.h"
 
 #include <vector>
 

+ 1 - 1
CGameState.h

@@ -105,7 +105,7 @@ public:
 	friend void initGameState(Mapa * map, CGameInfo * cgi);
 	friend CScriptCallback;
 	friend void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
-	friend CMapHandler;
+	friend class CMapHandler;
 };
 
 #endif //CGAMESTATE_H

+ 2 - 0
CHeroWindow.cpp

@@ -14,6 +14,8 @@
 #include "CCallback.h"
 #include "hch/CArtHandler.h"
 #include "hch/CAbilityHandler.h"
+#include "hch/CDefHandler.h"
+#include "client/CBitmapHandler.h"
 #include <sstream>
 #include "client/Graphics.h"
 extern SDL_Surface * screen;

+ 2 - 0
CLua.cpp

@@ -21,6 +21,8 @@
 #include <boost/algorithm/string.hpp>
 #include <boost/algorithm/string/replace.hpp>
 #include "hch/CDefObjInfoHandler.h"
+#include "map.h"
+#include "maphandler.h"
 #pragma warning (disable : 4311)
 bool getGlobalFunc(lua_State * L, std::string fname)
 {

+ 1 - 1
CMT.cpp

@@ -61,7 +61,7 @@ void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * sc
 }
 int _tmain(int argc, _TCHAR* argv[])
 { 
-	boost::thread servthr(boost::bind(system,"Debug\\VCMI_server.exe"));
+	boost::thread servthr(boost::bind(system,"VCMI_server.exe"));
 	/*
     boost::asio::io_service io_service;
     boost::system::error_code error = boost::asio::error::host_not_found;

+ 1 - 0
CPathfinder.cpp

@@ -5,6 +5,7 @@
 #include "hch/CAmbarCendamo.h"
 #include "mapHandler.h"
 #include "CGameState.h"
+#include "hch/CObjectHandler.h"
 
 using namespace std;
 

+ 3 - 0
CPlayerInterface.cpp

@@ -23,11 +23,14 @@
 #include <boost/algorithm/string.hpp>
 #include <boost/algorithm/string/replace.hpp>
 #include "hch/CPreGameTextHandler.h"
+#include "hch/CObjectHandler.h"
 #include "CBattleInterface.h"
+#include "CGameInfo.h"
 #include "CLua.h"
 #include <cmath>
 #include "client/CCreatureAnimation.h"
 #include "client/Graphics.h"
+#include "map.h"
 using namespace CSDL_Ext;
 
 extern TTF_Font * GEOR16;

+ 26 - 0
client/Graphics.cpp

@@ -111,6 +111,31 @@ void Graphics::loadPaletteAndColors()
 		playerColors[i].unused = 0;
 	}
 	neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84;//gray
+}	
+void Graphics::initializeBattleGraphics()
+{
+	std::ifstream bback("config/battleBack.txt");
+	battleBacks.resize(9);
+	for(int i=0; i<9; ++i) //9 - number of terrains battle can be fought on
+	{
+		int am;
+		bback>>am;
+		battleBacks[i].resize(am);
+		for(int f=0; f<am; ++f)
+		{
+			bback>>battleBacks[i][f];
+		}
+	}
+
+	//initializing battle hero animation
+	std::ifstream bher("config/battleHeroes.txt");
+	int numberofh;
+	bher>>numberofh;
+	battleHeroes.resize(numberofh);
+	for(int i=0; i<numberofh; ++i) //9 - number of terrains battle can be fought on
+	{
+		bher>>battleHeroes[i];
+	}
 }
 Graphics::Graphics()
 {
@@ -128,6 +153,7 @@ Graphics::Graphics()
 	tasks += boost::bind(&Graphics::loadPaletteAndColors,this);
 	tasks += boost::bind(&Graphics::loadHeroFlags,this);
 	tasks += boost::bind(&Graphics::loadHeroPortraits,this);
+	tasks += boost::bind(&Graphics::initializeBattleGraphics,this);
 	tasks += GET_SURFACE(hInfo,"HEROQVBK.bmp");
 	tasks += GET_SURFACE(tInfo,"TOWNQVBK.bmp");
 	tasks += GET_DEF(artDefs,"ARTIFACT.DEF");

+ 5 - 2
client/Graphics.h

@@ -32,9 +32,12 @@ public:
 	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
-	
+	//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
 	//functions
-	Graphics();
+	Graphics();	
+	void initializeBattleGraphics();
 	void loadPaletteAndColors();
 	void loadHeroFlags();
 	void loadHeroFlags(std::pair<std::vector<CDefHandler *> Graphics::*, std::vector<const char *> > &pr, bool mode);

+ 5 - 27
mapHandler.cpp

@@ -13,6 +13,8 @@
 #include "client\Graphics.h"
 #include <iomanip>
 #include <sstream>
+#include "hch/CObjectHandler.h"
+#include "map.h"
 extern SDL_Surface * screen;
 std::string nameFromType (EterrainType typ)
 {
@@ -637,33 +639,9 @@ void CMapHandler::init()
 	std::cout<<"\tMaking object rects: "<<th.getDif()<<std::endl;
 	calculateBlockedPos();
 	std::cout<<"\tCalculating blockmap: "<<th.getDif()<<std::endl;
-
-	//initailizing battle backgrounds
-	std::ifstream bback("config/battleBack.txt");
-	battleBacks.resize(9);
-	for(int i=0; i<9; ++i) //9 - number of terrains battle can be fought on
-	{
-		int am;
-		bback>>am;
-		battleBacks[i].resize(am);
-		for(int f=0; f<am; ++f)
-		{
-			bback>>battleBacks[i][f];
-		}
-	}
-
-	//initializing battle hero animation
-	std::ifstream bher("config/battleHeroes.txt");
-	int numberofh;
-	bher>>numberofh;
-	battleHeroes.resize(numberofh);
-	for(int i=0; i<numberofh; ++i) //9 - number of terrains battle can be fought on
-	{
-		bher>>battleHeroes[i];
-	}
 }
 
-SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect)
+SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect)
 {
 	if(!otherHeroAnim)
 		heroAnim = anim; //the same, as it should be
@@ -831,9 +809,9 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 			sr.h=sr.w=32;
 			validateRectTerr(&sr, extRect);
 			
-			if(bx+x>=0 && by+y>=0 && bx+x<CGI->mh->map->width && by+y<CGI->mh->map->height && !visibilityMap[bx+x][by+y][level])
+			if(bx+x>=0 && by+y>=0 && bx+x<CGI->mh->map->width && by+y<CGI->mh->map->height && !(*visibilityMap)[bx+x][by+y][level])
 			{
-				SDL_Surface * hide = getVisBitmap(bx+x, by+y, visibilityMap, level);
+				SDL_Surface * hide = getVisBitmap(bx+x, by+y, *visibilityMap, level);
 				CSDL_Ext::blit8bppAlphaTo24bpp(hide, &genRect(sr.h, sr.w, 0, 0), su, &sr);
 			}
 		}

+ 9 - 8
mapHandler.h

@@ -1,15 +1,19 @@
 #ifndef MAPHANDLER_H
 #define MAPHANDLER_H
-
-#include "hch/CAmbarCendamo.h"
-#include "CGameInfo.h"
+#include "global.h"
+#include <SDL.h>
 #include "hch/CDefHandler.h"
 #include <boost/logic/tribool.hpp>
-#include "hch/CObjectHandler.h"
 #include <list>
+#include <set>
 const int Woff = 12; //width of map's frame
 const int Hoff = 8; 
 
+class CGObjectInstance;
+class CGHeroInstance;
+struct Mapa;
+class CGDefInfo;
+
 struct TerrainTile2
 {
 	int3 pos; //this tile's position
@@ -84,15 +88,12 @@ public:
 	std::vector<CDefHandler*> defs;
 
 	std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
-	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::vector<std::vector<std::vector<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
 
 	void loadDefs();
 	char & visAccess(int x, int y);
 	char & undVisAccess(int x, int y);
-	SDL_Surface mirrorImage(SDL_Surface *src); //what is this??
 	SDL_Surface * getVisBitmap(int x, int y, std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl);
 
 	int getCost(int3 & a, int3 & b, const CGHeroInstance * hero);
@@ -116,7 +117,7 @@ public:
 	void prepareFOWDefs();
 	void randomizeObjects();
 
-	SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap = CGI->mh->visibility, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it
+	SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap = NULL, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it
 	SDL_Surface * terrBitmap(int x, int y);
 	SDL_Surface * undTerrBitmap(int x, int y);
 	std::string getRandomizedDefName(CGDefInfo* di, CGObjectInstance * obj = NULL); //objinstance needed only for heroes and towns

+ 1 - 1
server/VCMI_server.vcproj

@@ -17,7 +17,7 @@
 	<Configurations>
 		<Configuration
 			Name="Debug|Win32"
-			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			OutputDirectory="$(SolutionDir)"
 			IntermediateDirectory="$(ConfigurationName)"
 			ConfigurationType="1"
 			CharacterSet="2"

+ 71 - 72
server/server_main.cpp

@@ -4,78 +4,77 @@
 #include <boost/asio.hpp>
 #include "../global.h"
 std::string NAME = NAME_VER + std::string(" (server)");
-//using boost::asio::ip::tcp;
-//using namespace boost;
-//using namespace boost::asio;
-//
-//class CConnection
-//{
-//public:
-//	int ID;
-//	tcp::socket socket;
-//	void witaj()
-//	{
-//		char message[50]; strcpy_s(message,50,NAME.c_str());message[NAME.size()]='\n';
-//		write(socket,buffer("Aiya!\n"));
-//		write(socket,buffer(message,NAME.size()+1));
-//	}
-//	CConnection(io_service& io_service, int id=-1)
-//		: socket(io_service), ID(id)
-//	{
-//	}
-//};
-//
-//class CVCMIServer
-//{
-//	tcp::acceptor acceptor;
-//	std::vector<CConnection*> connections;
-//public:
-//	CVCMIServer(io_service& io_service)
-//    : acceptor(io_service, tcp::endpoint(tcp::v4(), 3030))
-//	{
-//		start_accept();
-//	}
-//
-//private:
-//	void start_accept()
-//	{
-//		std::cout<<"Listening for connections at port " << acceptor.local_endpoint().port() << std::endl;
-//		CConnection * new_connection = new CConnection(acceptor.io_service());
-//		acceptor.accept(new_connection->socket);
-//		new_connection->witaj();
-//		acceptor.async_accept(new_connection->socket,
-//			boost::bind(&CVCMIServer::gotConnection, this, new_connection,
-//			placeholders::error));
-//	}
-//
-//	void gotConnection(CConnection * connection,const system::error_code& error)
-//	{
-//		if (!error)
-//		{
-//			std::cout<<"Got connection!" << std::endl;
-//			connection->witaj();
-//			start_accept();
-//		}
-//		else
-//		{
-//			std::cout<<"Got connection but there is an error " << std::endl;
-//		}
-//	}
-//
-//};
-//
+using boost::asio::ip::tcp;
+using namespace boost;
+using namespace boost::asio;
+
+class CConnection
+{
+public:
+	int ID;
+	tcp::socket socket;
+	void witaj()
+	{
+		char message[50]; strcpy(message,NAME.c_str());message[NAME.size()]='\n';
+		write(socket,buffer("Aiya!\n"));
+		write(socket,buffer(message,NAME.size()+1));
+	}
+	CConnection(io_service& io_service, int id=-1)
+		: socket(io_service), ID(id)
+	{
+	}
+};
+
+class CVCMIServer
+{
+	tcp::acceptor acceptor;
+	std::vector<CConnection*> connections;
+public:
+	CVCMIServer(io_service& io_service)
+    : acceptor(io_service, tcp::endpoint(tcp::v4(), 3030))
+	{
+		start_accept();
+	}
+private:
+	void start_accept()
+	{
+		std::cout<<"Listening for connections at port " << acceptor.local_endpoint().port() << std::endl;
+		CConnection * new_connection = new CConnection(acceptor.io_service());
+		acceptor.accept(new_connection->socket);
+		new_connection->witaj();
+		acceptor.async_accept(new_connection->socket,
+			boost::bind(&CVCMIServer::gotConnection, this, new_connection,
+			placeholders::error));
+	}
+
+	void gotConnection(CConnection * connection,const boost::system::error_code& error)
+	{
+		if (!error)
+		{
+			std::cout<<"Got connection!" << std::endl;
+			connection->witaj();
+			start_accept();
+		}
+		else
+		{
+			std::cout<<"Got connection but there is an error " << std::endl;
+		}
+	}
+
+};
+
 int main()
 {
-//  try
-//  {
-//    io_service io_service;
-//    CVCMIServer server(io_service);
-//    io_service.run();
-//  }
-//  catch (std::exception& e)
-//  {
-//    std::cerr << e.what() << std::endl;
-//  }
-//
+  try
+  {
+    io_service io_service;
+    CVCMIServer server(io_service);
+    io_service.run();
+  }
+  catch (std::exception& e)
+  {
+    std::cerr << e.what() << std::endl;
+  }
+
   return 0;
-}
+}