Răsfoiți Sursa

Town interface and minor improvements.

Michał W. Urbańczyk 18 ani în urmă
părinte
comite
b334dbd79d

+ 114 - 0
AdventureMapButton.h

@@ -0,0 +1,114 @@
+#include "SDL_Extensions.h"
+template <typename T>
+AdventureMapButton<T>::AdventureMapButton ()
+{
+	type=2;
+	abs=true;
+	active=false;
+	ourObj=NULL;
+	state=0;
+}
+template <typename T>
+AdventureMapButton<T>::AdventureMapButton
+( std::string Name, std::string HelpBox, void(T::*Function)(), int x, int y, std::string defName, T* Owner, bool activ, std::vector<std::string> * add )
+{
+	owner = Owner;
+	type=2;
+	abs=true;
+	active=false;
+	ourObj=NULL;
+	state=0;
+	name=Name;
+	helpBox=HelpBox;
+	int est = LOCPLINT->playerID;
+	CDefHandler * temp = CGI->spriteh->giveDef(defName); //todo: moze cieknac
+	for (int i=0;i<temp->ourImages.size();i++)
+	{
+		imgs.resize(1);
+		imgs[0].push_back(temp->ourImages[i].bitmap);
+		CSDL_Ext::blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
+	}
+	if (add)
+	{
+		imgs.resize(imgs.size()+add->size());
+		for (int i=0; i<add->size();i++)
+		{
+			temp = CGI->spriteh->giveDef((*add)[i]);
+			for (int j=0;j<temp->ourImages.size();j++)
+			{
+				imgs[i+1].push_back(temp->ourImages[j].bitmap);
+				CSDL_Ext::blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
+			}
+		}
+		delete add;
+	}
+	function = Function;
+	pos.x=x;
+	pos.y=y;
+	pos.w = imgs[curimg][0]->w;
+	pos.h = imgs[curimg][0]->h  -1;
+	if (activ)
+		activate();
+}
+
+template <typename T>
+void AdventureMapButton<T>::clickLeft (tribool down)
+{
+	if (down)
+	{
+		state=1;
+	}
+	else 
+	{
+		state=0;
+	}
+	show();
+	if (pressedL && (down==false))
+	{
+		pressedL=state;
+		(owner->*function)();
+	}
+	else
+	{
+		pressedL=state;
+	}
+}
+template <typename T>
+void AdventureMapButton<T>::clickRight (tribool down)
+{
+	LOCPLINT->adventureInt->handleRightClick(helpBox,down,this);
+}
+template <typename T>
+void AdventureMapButton<T>::hover (bool on)
+{
+	Hoverable::hover(on);
+	if (on)
+		LOCPLINT->adventureInt->statusbar.print(name);
+	else if (LOCPLINT->adventureInt->statusbar.current==name)
+		LOCPLINT->adventureInt->statusbar.clear();
+}
+template <typename T>
+void AdventureMapButton<T>::activate()
+{
+	if (active) return;
+	active=true;
+	ClickableL::activate();
+	ClickableR::activate();
+	Hoverable::activate();
+	KeyInterested::activate();
+}
+template <typename T>
+void AdventureMapButton<T>::keyPressed (SDL_KeyboardEvent & key)
+{
+	//TODO: check if it's shortcut
+}
+template <typename T>
+void AdventureMapButton<T>::deactivate()
+{
+	if (!active) return;
+	active=false;
+	ClickableL::deactivate();
+	ClickableR::deactivate();
+	Hoverable::deactivate();
+	KeyInterested::deactivate();
+}

+ 16 - 114
CAdvmapInterface.cpp

@@ -18,7 +18,7 @@
 #include "hch/CHeroHandler.h"
 #include <sstream>
 extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
-
+#include "AdventureMapButton.h"
 using namespace boost::logic;
 using namespace boost::assign;
 using namespace CSDL_Ext;
@@ -26,106 +26,6 @@ CAdvMapInt::~CAdvMapInt()
 {
 	SDL_FreeSurface(bg);
 }
-
-AdventureMapButton::AdventureMapButton ()
-{
-	type=2;
-	abs=true;
-	active=false;
-	ourObj=NULL;
-	state=0;
-}
-AdventureMapButton::AdventureMapButton
-( std::string Name, std::string HelpBox, void(CAdvMapInt::*Function)(), int x, int y, std::string defName, bool activ, std::vector<std::string> * add )
-{
-	type=2;
-	abs=true;
-	active=false;
-	ourObj=NULL;
-	state=0;
-	name=Name;
-	helpBox=HelpBox;
-	int est = LOCPLINT->playerID;
-	CDefHandler * temp = CGI->spriteh->giveDef(defName); //todo: moze cieknac
-	for (int i=0;i<temp->ourImages.size();i++)
-	{
-		imgs.resize(1);
-		imgs[0].push_back(temp->ourImages[i].bitmap);
-		blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
-	}
-	if (add)
-	{
-		imgs.resize(imgs.size()+add->size());
-		for (int i=0; i<add->size();i++)
-		{
-			temp = CGI->spriteh->giveDef((*add)[i]);
-			for (int j=0;j<temp->ourImages.size();j++)
-			{
-				imgs[i+1].push_back(temp->ourImages[j].bitmap);
-				blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
-			}
-		}
-		delete add;
-	}
-	function = Function;
-	pos.x=x;
-	pos.y=y;
-	pos.w = imgs[curimg][0]->w;
-	pos.h = imgs[curimg][0]->h  -1;
-	if (activ)
-		activate();
-}
-
-void AdventureMapButton::clickLeft (tribool down)
-{
-	if (down)
-	{
-		state=1;
-	}
-	else 
-	{
-		state=0;
-	}
-	show();
-	if (pressedL && (down==false))
-		(LOCPLINT->adventureInt->*function)();
-	pressedL=state;
-}
-void AdventureMapButton::clickRight (tribool down)
-{
-	LOCPLINT->adventureInt->handleRightClick(helpBox,down,this);
-}
-void AdventureMapButton::hover (bool on)
-{
-	Hoverable::hover(on);
-	if (on)
-		LOCPLINT->adventureInt->statusbar.print(name);
-	else if (LOCPLINT->adventureInt->statusbar.current==name)
-		LOCPLINT->adventureInt->statusbar.clear();
-}
-void AdventureMapButton::activate()
-{
-	if (active) return;
-	active=true;
-	ClickableL::activate();
-	ClickableR::activate();
-	Hoverable::activate();
-	KeyInterested::activate();
-}
-void AdventureMapButton::keyPressed (SDL_KeyboardEvent & key)
-{
-	//TODO: check if it's shortcut
-}
-void AdventureMapButton::deactivate()
-{
-	if (!active) return;
-	active=false;
-	ClickableL::deactivate();
-	ClickableR::deactivate();
-	Hoverable::deactivate();
-	KeyInterested::deactivate();
-}
-
 void CList::activate()
 {
 	ClickableL::activate();
@@ -456,7 +356,10 @@ void CTownList::clickLeft(tribool down)
 		float ny = (float)hy/(float)32;
 		if (ny>5 || ny<0)
 			return;
-		select(ny+from);
+		if (((int)(ny+from))==selected)
+			LOCPLINT->openTownWindow(items[selected]);//print town screen
+		else
+			select(ny+from);
 	}
 	else
 	{
@@ -528,13 +431,12 @@ void CTownList::draw()
 			continue;
 		}
 
-		blitAt(CGI->townh->getPic(items[i]->town->typeID),posporx,pospory+i*32);
+		blitAt(CGI->townh->getPic(items[i]->subID,items[i]->hasFort(),items[i]->builded),posporx,pospory+i*32);
 
 		if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE))
 		{
 			blitAt(CGI->townh->getPic(-2),posporx,pospory+i*32);
 		}
-		//TODO: dodac oznaczanie zbudowania w danej turze i posiadania fortu
 	}
 	if (from>0)
 		blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
@@ -1326,34 +1228,34 @@ CAdvMapInt::CAdvMapInt(int Player)
 :player(Player),
 statusbar(7,556),
 kingOverview(CGI->preth->advKingdomOverview.first,CGI->preth->advKingdomOverview.second,
-			 &CAdvMapInt::fshowOverview, 679, 196, "IAM002.DEF"),
+			 &CAdvMapInt::fshowOverview, 679, 196, "IAM002.DEF", this),
 
 underground(CGI->preth->advSurfaceSwitch.first,CGI->preth->advSurfaceSwitch.second,
-		   &CAdvMapInt::fswitchLevel, 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF"))),
+		   &CAdvMapInt::fswitchLevel, 711, 196, "IAM010.DEF", this, false, new std::vector<std::string>(1,std::string("IAM003.DEF"))),
 
 questlog(CGI->preth->advQuestlog.first,CGI->preth->advQuestlog.second,
-		 &CAdvMapInt::fshowQuestlog, 679, 228, "IAM004.DEF"),
+		 &CAdvMapInt::fshowQuestlog, 679, 228, "IAM004.DEF", this),
 
 sleepWake(CGI->preth->advSleepWake.first,CGI->preth->advSleepWake.second,
-		  &CAdvMapInt::fsleepWake, 711, 228, "IAM005.DEF"),
+		  &CAdvMapInt::fsleepWake, 711, 228, "IAM005.DEF", this),
 
 moveHero(CGI->preth->advMoveHero.first,CGI->preth->advMoveHero.second,
-		  &CAdvMapInt::fmoveHero, 679, 260, "IAM006.DEF"),
+		  &CAdvMapInt::fmoveHero, 679, 260, "IAM006.DEF", this),
 
 spellbook(CGI->preth->advCastSpell.first,CGI->preth->advCastSpell.second,
-		  &CAdvMapInt::fshowSpellbok, 711, 260, "IAM007.DEF"),
+		  &CAdvMapInt::fshowSpellbok, 711, 260, "IAM007.DEF", this),
 
 advOptions(CGI->preth->advAdvOptions.first,CGI->preth->advAdvOptions.second,
-		  &CAdvMapInt::fadventureOPtions, 679, 292, "IAM008.DEF"),
+		  &CAdvMapInt::fadventureOPtions, 679, 292, "IAM008.DEF", this),
 
 sysOptions(CGI->preth->advSystemOptions.first,CGI->preth->advSystemOptions.second,
-		  &CAdvMapInt::fsystemOptions, 711, 292, "IAM009.DEF"),
+		  &CAdvMapInt::fsystemOptions, 711, 292, "IAM009.DEF", this),
 
 nextHero(CGI->preth->advNextHero.first,CGI->preth->advNextHero.second,
-		  &CAdvMapInt::fnextHero, 679, 324, "IAM000.DEF"),
+		  &CAdvMapInt::fnextHero, 679, 324, "IAM000.DEF", this),
 
 endTurn(CGI->preth->advEndTurn.first,CGI->preth->advEndTurn.second,
-		  &CAdvMapInt::fendTurn, 679, 356, "IAM001.DEF")
+		  &CAdvMapInt::fendTurn, 679, 356, "IAM001.DEF", this)
 {
 	LOCPLINT->adventureInt=this;
 	bg = CGI->bitmaph->loadBitmap("ADVMAP.bmp");

+ 6 - 19
CAdvmapInterface.h

@@ -5,13 +5,14 @@
 #include "SDL.h"
 #include "CPlayerInterface.h"
 #include <map>
-
 class CDefHandler;
 class CCallback;
 class CTownInstance;
 class CPath; 
+class CAdvMapInt;
 class CGHeroInstance;
 class CGTownInstance;
+template <typename T=CAdvMapInt>
 class AdventureMapButton 
 	: public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public CButtonBase
 {
@@ -19,7 +20,8 @@ public:
 	std::string name; //for status bar 
 	std::string helpBox; //for right-click help
 	char key; //key shortcut
-	void (CAdvMapInt::*function)(); //function in CAdvMapInt called when this button is pressed, different for each button
+	T* owner;
+	void (T::*function)(); //function in CAdvMapInt called when this button is pressed, different for each button
 
 	void clickRight (tribool down);
 	void clickLeft (tribool down);
@@ -29,8 +31,7 @@ public:
 	void deactivate(); // makes button inactive (but doesn't delete)
 
 	AdventureMapButton(); //c-tor
-	AdventureMapButton( std::string Name, std::string HelpBox, void(CAdvMapInt::*Function)(), int x, int y, std::string defName, bool activ=false,  std::vector<std::string> * add = NULL );//c-tor
-
+	AdventureMapButton( std::string Name, std::string HelpBox, void(T::*Function)(), int x, int y, std::string defName, T* Owner, bool activ=false,  std::vector<std::string> * add = NULL );//c-tor
 };
 /*****************************/
 class CList 
@@ -93,20 +94,6 @@ public:
 	void keyPressed (SDL_KeyboardEvent & key);
 	void draw();
 };
-class CResourceBar
-	:public ClickableR
-{
-	SDL_Surface * bg;
-	void clickRight(tribool down);
-	void refresh();
-};
-class CDataBar
-	:public ClickableR
-{
-	SDL_Surface * bg;
-	void clickRight(tribool down);
-	void refresh();
-};
 class CStatusBar
 	: public CIntObject
 {
@@ -228,7 +215,7 @@ public:
 
 
 	SDL_Surface * bg;
-	AdventureMapButton kingOverview,//- kingdom overview
+	AdventureMapButton<> kingOverview,//- kingdom overview
 		underground,//- underground switch
 		questlog,//- questlog
 		sleepWake, //- sleep/wake hero

+ 104 - 0
CCastleInterface.cpp

@@ -0,0 +1,104 @@
+#include "stdafx.h"
+#include "CCastleInterface.h"
+#include "hch/CObjectHandler.h"
+#include "CGameInfo.h"
+#include "hch/CLodHandler.h"
+#include "SDL_Extensions.h"
+#include "CAdvmapInterface.h"
+#include "hch/CTownHandler.h"
+#include "AdventureMapButton.h"
+std::string getBgName(int type) //TODO - co z tym zrobiæ?
+{
+	switch (type)
+	{
+	case 0:
+		return "TBCSBACK.bmp";
+	case 1:
+		return "TBRMBACK.bmp";
+	case 2:
+		return "TBTWBACK.bmp";
+	case 3:
+		return "TBINBACK.bmp";
+	case 4:
+		return "TBNCBACK.bmp";
+	case 5:
+		return "TBDNBACK.bmp";
+	case 6:
+		return "TBSTBACK.bmp";
+	case 7:
+		return "TBFRBACK.bmp";
+	case 8:
+		return "TBELBACK.bmp";
+	default:
+		throw new std::exception("std::string getBgName(int type): invalid type");
+	}
+}
+
+CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
+{
+	town = Town;
+	townInt = CGI->bitmaph->loadBitmap("TOWNSCRN.bmp");
+	cityBg = CGI->bitmaph->loadBitmap(getBgName(town->subID));
+	hall = CGI->spriteh->giveDef("ITMTL.DEF");
+	fort = CGI->spriteh->giveDef("ITMCL.DEF");
+	CSDL_Ext::blueToPlayersAdv(townInt,LOCPLINT->playerID);
+	exit = new AdventureMapButton<CCastleInterface>(CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,Activate);
+	exit->bitmapOffset = 4;
+	if(Activate)
+	{
+		activate();
+		show();
+	}
+}
+CCastleInterface::~CCastleInterface()
+{
+	SDL_FreeSurface(townInt);
+	SDL_FreeSurface(cityBg);
+	delete exit;
+	delete hall;
+	delete fort;
+}
+void CCastleInterface::close()
+{
+	deactivate();
+	LOCPLINT->castleInt = NULL;
+	LOCPLINT->adventureInt->show();
+	delete this;
+}
+void CCastleInterface::show()
+{
+	blitAt(cityBg,0,0);
+	blitAt(townInt,0,374);
+	LOCPLINT->adventureInt->resdatabar.draw();
+
+	int pom;
+	if(town->builtBuildings.find(9)!=town->builtBuildings.end())
+		pom = 2;
+	else if(town->builtBuildings.find(8)!=town->builtBuildings.end())
+		pom = 1;
+	else if(town->builtBuildings.find(7)!=town->builtBuildings.end())
+		pom = 0;
+	else pom = 3;
+	blitAt(fort->ourImages[pom].bitmap,122,413);
+
+	if(town->builtBuildings.find(13)!=town->builtBuildings.end())
+		pom = 3;
+	else if(town->builtBuildings.find(12)!=town->builtBuildings.end())
+		pom = 2;
+	else if(town->builtBuildings.find(11)!=town->builtBuildings.end())
+		pom = 1;
+	else pom = 0;
+	blitAt(hall->ourImages[pom].bitmap,80,413);
+
+	CSDL_Ext::printAt(town->name,85,389,GEOR13,zwykly);
+	char temp[10];
+	itoa(town->income,temp,10);
+	CSDL_Ext::printAtMiddle(temp,195,442,GEOR13,zwykly);
+}
+void CCastleInterface::activate()
+{
+}
+void CCastleInterface::deactivate()
+{
+	exit->deactivate();
+}

+ 29 - 0
CCastleInterface.h

@@ -0,0 +1,29 @@
+#include "global.h"
+#include "SDL.h"
+#include "CPlayerInterface.h"
+class CGTownInstance;
+template <typename T> class AdventureMapButton;
+class CBuildingRect : public MotionInterested, public ClickableL, public ClickableR, public TimeInterested
+{
+	void activate();
+	void deactivate();
+};
+
+class CCastleInterface
+{
+public:
+	SDL_Surface * townInt;
+	SDL_Surface * cityBg;
+	const CGTownInstance * town;
+
+	CDefHandler *hall,*fort;
+
+	AdventureMapButton<CCastleInterface> * exit;
+
+	CCastleInterface(const CGTownInstance * Town, bool Activate=true);
+	~CCastleInterface();
+	void show();
+	void close();
+	void activate();
+	void deactivate();
+};

+ 58 - 47
CPlayerInterface.cpp

@@ -15,6 +15,7 @@
 #include "hch/CHeroHandler.h"
 #include "SDL_framerate.h"
 #include "hch/CGeneralTextHandler.h"
+#include "CCastleInterface.h"
 using namespace CSDL_Ext;
 
 class OCM_HLP_CGIN
@@ -305,6 +306,7 @@ template <typename T> void CSCButton<typename T>::show(SDL_Surface * to)
 }
 CButtonBase::CButtonBase()
 {
+	bitmapOffset = 0;
 	curimg=0;
 	type=-1;
 	abs=false;
@@ -318,12 +320,12 @@ void CButtonBase::show(SDL_Surface * to)
 		to=ekran;
 	if (abs)
 	{
-		blitAt(imgs[curimg][state],pos.x,pos.y,to);
+		blitAt(imgs[curimg][state+bitmapOffset],pos.x,pos.y,to);
 		//updateRect(&pos,to);
 	}
 	else
 	{
-		blitAt(imgs[curimg][state],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
+		blitAt(imgs[curimg][state+bitmapOffset],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
 		//updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y),to);
 		
 	}
@@ -430,7 +432,7 @@ void CPlayerInterface::init(ICallback * CB)
 	cb = dynamic_cast<CCallback*>(CB);
 	CGI->localPlayer = serialID;
 	adventureInt = new CAdvMapInt(playerID);
-	
+	castleInt = NULL;
 	std::vector <const CGHeroInstance *> hh = cb->getHeroesInfo(false);
 	for(int i=0;i<hh.size();i++)
 	{
@@ -472,60 +474,63 @@ void CPlayerInterface::yourTurn()
 		{
 			handleEvent(&sEvent);
 		}
-		++LOCPLINT->adventureInt->animValHitCount; //for animations
-		if(LOCPLINT->adventureInt->animValHitCount == 4)
-		{
-			LOCPLINT->adventureInt->animValHitCount = 0;
-			++animVal;
-			LOCPLINT->adventureInt->updateScreen = true;
-
-		}
-		++heroAnimVal;
-		if(LOCPLINT->adventureInt->scrollingLeft)
+		if (!castleInt) //stuff for advMapInt
 		{
-			if(LOCPLINT->adventureInt->position.x>-Woff)
+			++LOCPLINT->adventureInt->animValHitCount; //for animations
+			if(LOCPLINT->adventureInt->animValHitCount == 4)
 			{
-				LOCPLINT->adventureInt->position.x--;
+				LOCPLINT->adventureInt->animValHitCount = 0;
+				++animVal;
 				LOCPLINT->adventureInt->updateScreen = true;
-				adventureInt->updateMinimap=true;
+
 			}
-		}
-		if(LOCPLINT->adventureInt->scrollingRight)
-		{
-			if(LOCPLINT->adventureInt->position.x<CGI->ac->map.width-19+4)
+			++heroAnimVal;
+			if(LOCPLINT->adventureInt->scrollingLeft)
 			{
-				LOCPLINT->adventureInt->position.x++;
-				LOCPLINT->adventureInt->updateScreen = true;
-				adventureInt->updateMinimap=true;
+				if(LOCPLINT->adventureInt->position.x>-Woff)
+				{
+					LOCPLINT->adventureInt->position.x--;
+					LOCPLINT->adventureInt->updateScreen = true;
+					adventureInt->updateMinimap=true;
+				}
 			}
-		}
-		if(LOCPLINT->adventureInt->scrollingUp)
-		{
-			if(LOCPLINT->adventureInt->position.y>-Hoff)
+			if(LOCPLINT->adventureInt->scrollingRight)
 			{
-				LOCPLINT->adventureInt->position.y--;
-				LOCPLINT->adventureInt->updateScreen = true;
-				adventureInt->updateMinimap=true;
+				if(LOCPLINT->adventureInt->position.x<CGI->ac->map.width-19+4)
+				{
+					LOCPLINT->adventureInt->position.x++;
+					LOCPLINT->adventureInt->updateScreen = true;
+					adventureInt->updateMinimap=true;
+				}
 			}
-		}
-		if(LOCPLINT->adventureInt->scrollingDown)
-		{
-			if(LOCPLINT->adventureInt->position.y<CGI->ac->map.height-18+4)
+			if(LOCPLINT->adventureInt->scrollingUp)
 			{
-				LOCPLINT->adventureInt->position.y++;
-				LOCPLINT->adventureInt->updateScreen = true;
-				adventureInt->updateMinimap=true;
+				if(LOCPLINT->adventureInt->position.y>-Hoff)
+				{
+					LOCPLINT->adventureInt->position.y--;
+					LOCPLINT->adventureInt->updateScreen = true;
+					adventureInt->updateMinimap=true;
+				}
+			}
+			if(LOCPLINT->adventureInt->scrollingDown)
+			{
+				if(LOCPLINT->adventureInt->position.y<CGI->ac->map.height-18+4)
+				{
+					LOCPLINT->adventureInt->position.y++;
+					LOCPLINT->adventureInt->updateScreen = true;
+					adventureInt->updateMinimap=true;
+				}
+			}
+			if(LOCPLINT->adventureInt->updateScreen)
+			{
+				adventureInt->update();
+				adventureInt->updateScreen=false;
+			}
+			if (LOCPLINT->adventureInt->updateMinimap)
+			{
+				adventureInt->minimap.draw();
+				adventureInt->updateMinimap=false;
 			}
-		}
-		if(LOCPLINT->adventureInt->updateScreen)
-		{
-			adventureInt->update();
-			adventureInt->updateScreen=false;
-		}
-		if (LOCPLINT->adventureInt->updateMinimap)
-		{
-			adventureInt->minimap.draw();
-			adventureInt->updateMinimap=false;
 		}
 		for(int i=0;i<objsToBlit.size();i++)
 			objsToBlit[i]->show();
@@ -1226,6 +1231,12 @@ SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh)
 	return NULL;
 }
 
+void CPlayerInterface::openTownWindow(const CGTownInstance * town)
+{
+	adventureInt->hide();
+	castleInt = new CCastleInterface(town,true);
+}
+
 SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
 {
 	if (specific)

+ 5 - 2
CPlayerInterface.h

@@ -11,7 +11,7 @@ struct HeroMoveDetails;
 class CDefEssential;
 class CGHeroInstance;
 class CAdvMapInt;
-
+class CCastleInterface;
 class IShowable
 {
 public:
@@ -43,6 +43,7 @@ public:
 class CButtonBase : public virtual CIntObject, public IShowable, public IActivable //basic buttton class
 {
 public:
+	int bitmapOffset;
 	int type; //advmapbutton=2
 	bool abs;
 	bool active;
@@ -182,8 +183,9 @@ class CPlayerInterface : public CGameInterface
 {
 public:
 	bool makingTurn;
-	SDL_Event * current;
+		SDL_Event * current;
 	CAdvMapInt * adventureInt;
+	CCastleInterface * castleInt;
 	FPSmanager * mainFPSmng;
 	//TODO: town interace, battle interface, other interfaces
 
@@ -217,6 +219,7 @@ public:
 
 	void showComp(SComponent comp);
 
+	void openTownWindow(const CGTownInstance * town);
 	SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero //TODO - gdy sie dorobi sensowna hierarchie klas ins. to wywalic tego brzydkiego void*
 	void handleEvent(SDL_Event * sEvent);
 	void handleKeyDown(SDL_Event *sEvent);

+ 1 - 1
hch/CAbilityHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CAbilityHandler.h"
 #include "../CGameInfo.h"
 #include "CGeneralTextHandler.h"

+ 1 - 1
hch/CAmbarCendamo.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CAmbarCendamo.h"
 #include "CSemiDefHandler.h"
 #include "../CGameInfo.h"

+ 1 - 1
hch/CArtHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CArtHandler.h"
 #include "../CGameInfo.h"
 #include "CGeneralTextHandler.h"

+ 1 - 1
hch/CBuildingHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "../CGameInfo.h"
 #include "CBuildingHandler.h"
 #include "CLodHandler.h"

+ 14 - 0
hch/CBuildingHandler.h

@@ -17,6 +17,20 @@ public:
 	bool isDwelling; //true, if this building is a dwelling
 };
 
+//class CGBuilding
+//{
+//	int ID, subID;
+//
+//	struct {
+//		int x, y;
+//	} pos;
+//
+//	bool allowed;
+//	bool built;
+//
+//	std::string name, description
+//};
+
 class CBuildingHandler
 {
 public:

+ 1 - 1
hch/CCastleHandler.cpp

@@ -1,2 +1,2 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CCastleHandler.h"

+ 2 - 1
hch/CCreatureHandler.cpp

@@ -1,5 +1,6 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "../CGameInfo.h"
+#include "CDefHandler.h"
 #include "CCreatureHandler.h"
 #include "CLodHandler.h"
 #include <sstream>

BIN
hch/CDefHandler.cpp


+ 1 - 1
hch/CDefObjInfoHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CDefObjInfoHandler.h"
 #include "../CGameInfo.h"
 #include "CLodHandler.h"

+ 1 - 1
hch/CGeneralTextHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CGeneralTextHandler.h"
 #include "../CGameInfo.h"
 #include "CLodHandler.h"

+ 1 - 1
hch/CHeroHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CHeroHandler.h"
 #include "../CGameInfo.h"
 #include <sstream>

+ 1 - 1
hch/CHeroHandler.h

@@ -103,7 +103,7 @@ public:
 
 	friend void CAmbarCendamo::deh3m();
 	friend void initGameState(CGameInfo * cgi);
-	friend class CConsoleHandler;
+	//friend class CConsoleHandler;
 
 	//friend void CPlayerInterface::heroMoved(const HeroMoveDetails & details); //TODO: wywalic, wstretne!!!
 };

+ 2 - 1
hch/CLodHandler.cpp

@@ -1,6 +1,7 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CLodHandler.h"
 #include "../SDL_Extensions.h"
+#include "CDefHandler.h"
 #include <sstream>
 #include <algorithm>
 #include <cctype>

+ 5 - 2
hch/CLodHandler.h

@@ -6,8 +6,12 @@
 #include <vector>
 #include <string>
 #include "zlib.h"
-#include "CDefHandler.h"
 #include "../nodrze.h"
+#include "SDL.h"
+
+
+class CDefHandler;
+class CDefEssential;
 
 enum Epcxformat {PCX8B, PCX24B};
 
@@ -73,5 +77,4 @@ public:
 	SDL_Surface * loadBitmap(std::string fname);
 };
 
-
 #endif //CLODHANDLER_H

+ 1 - 1
hch/CMusicHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CMusicHandler.h"
 
 void CMusicHandler::initMusics()

+ 6 - 1
hch/CObjectHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CObjectHandler.h"
 #include "../CGameInfo.h"
 #include "CGeneralTextHandler.h"
@@ -267,6 +267,10 @@ int CGTownInstance::getSightDistance() const //returns sight distance
 {
 	return 10;
 }
+bool CGTownInstance::hasFort() const
+{
+	return (builtBuildings.find(7))!=builtBuildings.end();
+}
 CGTownInstance::CGTownInstance()
 {
 	pos = int3(-1,-1,-1);
@@ -275,6 +279,7 @@ CGTownInstance::CGTownInstance()
 	garrisonHero=NULL;
 	//state->owner=-1;
 	town=NULL;
+	income = 500;
 }
 
 CGObjectInstance::CGObjectInstance()

+ 8 - 2
hch/CObjectHandler.h

@@ -2,6 +2,7 @@
 #define COBJECTHANDLER_H
 #include <string>
 #include <vector>
+#include <set>
 #include "CCreatureHandler.h"
 #include "CArtHandler.h"
 #include "CAbilityHandler.h"
@@ -426,17 +427,22 @@ public:
 	CCreatureSet garrison;
 	int builded; //how many buildings has been built this turn
 	int destroyed; //how many buildings has been destroyed this turn
+
+	int income;
 	
 	//TODO:
-	std::vector<CBuilding *> allBuildings, possibleBuildings, builtBuildings;
+	std::set<int> possibleBuildings, builtBuildings;
 	std::vector<int> creatureIncome; //vector by level
 	std::vector<int> creaturesLeft; //that can be recruited
 
-	CHero * garrisonHero;
+	CGHeroInstance * garrisonHero;
 
 	std::vector<CSpell *> possibleSpells, obligatorySpells, availableSpells;
 
 	int getSightDistance() const; //returns sight distance
+	bool hasFort() const;
+	int dailyIncome() const;
+
 	CGTownInstance();
 	virtual ~CGTownInstance();
 };

+ 1 - 1
hch/CPreGameTextHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CPreGameTextHandler.h"
 #include "../CGameInfo.h"
 #include "CLodHandler.h"

+ 1 - 1
hch/CSemiDefHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CSemiDefHandler.h"
 #include <fstream>
 extern SDL_Surface * ekran;

+ 1 - 1
hch/CSemiLodHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CSemiLodHandler.h"
 void CSemiLodHandler::openLod(std::string path)
 {

+ 3 - 2
hch/CSndHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CSndHandler.h"
 
 
@@ -236,5 +236,6 @@ MemberFile CVidHandler::getFile(std::string name)
 			}
 		}
 	}
-	return ret;
+	throw ret;
+	//return ret;
 }

+ 1 - 1
hch/CSpellHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CSpellHandler.h"
 #include "../CGameInfo.h"
 #include "CLodHandler.h"

+ 12 - 3
hch/CTownHandler.cpp

@@ -1,9 +1,9 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include "CTownHandler.h"
 #include "../CGameInfo.h"
 #include "CLodHandler.h"
 #include <sstream>
-
+#include "CGeneralTextHandler.h"
 CTownHandler::CTownHandler()
 {
 	smallIcons = CGI->spriteh->giveDef("ITPA.DEF");
@@ -34,6 +34,16 @@ void CTownHandler::loadNames()
 		if (town.name.length())
 			towns.push_back(town);
 	}
+
+	std::string  strs = CGI->bitmaph->getTextFile("TCOMMAND.TXT");
+	int itr=0;
+	while(itr<strs.length()-1)
+	{
+		std::string tmp;
+		CGeneralTextHandler::loadToIt(tmp, strs, itr, 3);
+		tcommands.push_back(tmp);
+
+	}
 }
 SDL_Surface * CTownHandler::getPic(int ID, bool fort, bool builded)
 {
@@ -69,7 +79,6 @@ CTownInstance::CTownInstance()
 	builded=-1;
 	destroyed=-1;
 	garrisonHero=NULL;
-	owner=-1;
 	town=NULL;
 }
 

+ 4 - 3
hch/CTownHandler.h

@@ -13,6 +13,7 @@ class CSpell;
 class CHero;
 class CTownInstance;
 class CGTownInstance;
+class CHeroInstance;
 class CTown
 {
 public:
@@ -29,6 +30,7 @@ public:
 	CTownHandler();
 	~CTownHandler();
 	std::vector<CTown> towns;
+	std::vector<std::string> tcommands;
 	void loadNames();
 	SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //ID=-1 - blank; -2 - border; -3 - random
 	static int getTypeByDefName(std::string name);
@@ -40,7 +42,6 @@ public:
 class CTownInstance
 {
 public:
-	int owner; //ID of owner
 	int3 pos; //position
 	CTown * town;
 	std::string name; // name of town
@@ -49,11 +50,11 @@ public:
 	int destroyed; //how many buildings has been destroyed this turn
 	
 	//TODO:
-	std::vector<CBuilding *> allBuildings, possibleBuildings, builtBuildings;
+	std::vector<CBuilding *> /*allBuildings,*/ possibleBuildings, builtBuildings;
 	std::vector<int> creatureIncome; //vector by level
 	std::vector<int> creaturesLeft; //that can be recruited
 
-	CHero * garrisonHero;
+	CHeroInstance * garrisonHero;
 
 	std::vector<CSpell *> possibleSpells, obligatorySpells, availableSpells;
 

+ 1 - 1
hch/CVideoHandler.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "../stdafx.h"
 #include <iostream>
 #include "CVideoHandler.h"
 #include "SDL.h"