Переглянути джерело

Now features in town interface:
* town garrison
* creature growths
* town big pic

Michał W. Urbańczyk 18 роки тому
батько
коміт
b976857c6c
9 змінених файлів з 87 додано та 18 видалено
  1. 31 1
      CCastleInterface.cpp
  2. 2 1
      CCastleInterface.h
  3. 2 0
      CMT.cpp
  4. 29 0
      SDL_Extensions.cpp
  5. 1 0
      SDL_Extensions.h
  6. 1 0
      global.h
  7. 13 15
      hch/CAmbarCendamo.cpp
  8. 7 1
      hch/CCreatureHandler.cpp
  9. 1 0
      hch/CCreatureHandler.h

+ 31 - 1
CCastleInterface.cpp

@@ -7,6 +7,7 @@
 #include "CAdvmapInterface.h"
 #include "hch/CTownHandler.h"
 #include "AdventureMapButton.h"
+#include <sstream>
 std::string getBgName(int type) //TODO - co z tym zrobiæ?
 {
 	switch (type)
@@ -41,6 +42,8 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
 	cityBg = CGI->bitmaph->loadBitmap(getBgName(town->subID));
 	hall = CGI->spriteh->giveDef("ITMTL.DEF");
 	fort = CGI->spriteh->giveDef("ITMCL.DEF");
+	bigTownPic =  CGI->spriteh->giveDef("ITPT.DEF");
+	flag =  CGI->spriteh->giveDef("CREST58.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;
@@ -57,6 +60,8 @@ CCastleInterface::~CCastleInterface()
 	delete exit;
 	delete hall;
 	delete fort;
+	delete bigTownPic;
+	delete flag;
 }
 void CCastleInterface::close()
 {
@@ -107,7 +112,13 @@ void CCastleInterface::show()
 		}
 		if (cid>=0)
 		{
-			;
+			int pomx, pomy;
+			pomx = 22 + (55*((i>3)?(i-4):i));
+			pomy = (i>3)?(507):(459);
+			blitAt(CGI->creh->smallImgs[cid],pomx,pomy);
+			std::ostringstream oss;
+			oss << '+' << town->creatureIncome[i];
+			CSDL_Ext::printAtMiddle(oss.str(),pomx+16,pomy+37,GEOR13,zwykly);
 		}
 	}
 
@@ -116,6 +127,25 @@ void CCastleInterface::show()
 	char temp[10];
 	itoa(town->income,temp,10);
 	CSDL_Ext::printAtMiddle(temp,195,442,GEOR13,zwykly);
+
+	//blit town icon
+	pom = town->subID*2;
+	if (!town->hasFort())
+		pom += F_NUMBER*2;
+	if(town->builded >= MAX_BUILDING_PER_TURN)
+		pom++;
+	blitAt(bigTownPic->ourImages[pom].bitmap,15,387);
+
+	//flag
+	blitAt(flag->ourImages[town->getOwner()].bitmap,241,387);
+	//print garrison
+	for(std::map<int,std::pair<CCreature*,int> >::const_iterator i=town->garrison.slots.begin();i!=town->garrison.slots.end();i++)
+	{
+		blitAt(CGI->creh->bigImgs[i->second.first->idNumber],305+(62*(i->first)),387);
+		itoa(i->second.second,temp,10);
+		CSDL_Ext::printTo(temp,305+(62*(i->first))+57,387+61,GEOR13,zwykly);
+	}
+	
 }
 void CCastleInterface::activate()
 {

+ 2 - 1
CCastleInterface.h

@@ -17,7 +17,8 @@ public:
 	SDL_Surface * cityBg;
 	const CGTownInstance * town;
 
-	CDefHandler *hall,*fort;
+	CDefHandler *hall,*fort,
+		*bigTownPic, *flag;
 
 	AdventureMapButton<CCastleInterface> * exit;
 

+ 2 - 0
CMT.cpp

@@ -190,6 +190,8 @@ void initGameState(CGameInfo * cgi)
 	{
 		CGTownInstance * vti = new CGTownInstance();
 		(*vti)=*(cgi->townh->townInstances[i]);
+		vti->creatureIncome.resize(CREATURES_PER_TOWN);
+		vti->creaturesLeft.resize(CREATURES_PER_TOWN);
 		if (vti->name.length()==0) // if town hasn't name we draw it
 			vti->name=vti->town->names[rand()%vti->town->names.size()];
 		

+ 29 - 0
SDL_Extensions.cpp

@@ -141,6 +141,35 @@ void CSDL_Ext::printAt(std::string text, int x, int y, TTF_Font * font, SDL_Colo
 	SDL_UpdateRect(dst,x,y,temp->w,temp->h);
 	SDL_FreeSurface(temp);
 }
+void CSDL_Ext::printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality)
+{
+	if (text.length()==0)
+		return;
+	SDL_Surface * temp;
+	switch (quality)
+	{
+	case 0:
+		temp = TTF_RenderText_Solid(font,text.c_str(),kolor);
+		break;
+	case 1:
+		SDL_Color tem;
+		tem.b = 0xff-kolor.b;
+		tem.g = 0xff-kolor.g;
+		tem.r = 0xff-kolor.r;
+		tem.unused = 0xff-kolor.unused;
+		temp = TTF_RenderText_Shaded(font,text.c_str(),kolor,tem);
+		break;
+	case 2:
+		temp = TTF_RenderText_Blended(font,text.c_str(),kolor);
+		break;
+	default:
+		temp = TTF_RenderText_Blended(font,text.c_str(),kolor);
+		break;
+	}
+	SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x-temp->w,y-temp->h));
+	SDL_UpdateRect(dst,x-temp->w,y-temp->h,temp->w,temp->h);
+	SDL_FreeSurface(temp);
+}
 void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC, Uint8 A)
 {
 	Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC;

+ 1 - 0
SDL_Extensions.h

@@ -27,6 +27,7 @@ namespace CSDL_Ext
 	SDL_Surface * secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha); //alpha is a surface we want to blit src to
 	void fullAlphaTransform(SDL_Surface *& src); //performs first and second alpha transform
 	Uint32 colorToUint32(const SDL_Color * color); //little endian only
+	void printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2);
 	void printAtMiddle(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest
 	void printAtMiddleWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran);
 	void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest

+ 1 - 0
global.h

@@ -53,6 +53,7 @@ const int PRIMARY_SKILLS=4;
 const int NEUTRAL_PLAYER=255;
 const int NAMES_PER_TOWN=16;
 const int CREATURES_PER_TOWN = 7; //without upgrades
+const int MAX_BUILDING_PER_TURN = 1;
 
 #define MARK_BLOCKED_POSITIONS false
 #define MARK_VISITABLE_POSITIONS false

+ 13 - 15
hch/CAmbarCendamo.cpp

@@ -1762,22 +1762,20 @@ void CAmbarCendamo::deh3m()
 								}
 
 							}//else if (ir==3)
-							else if (ir==4)
+							else if (ir==4 && bs==0)
 							{
-									if(bs%2) //ulepszone
-									{
-										if(spec->buildingSettings[ir] & (1<<bs))
-										{
-											nt->builtBuildings.insert(40+(bs/2)); 
-										}
-									}
-									else
-									{
-										if(spec->buildingSettings[ir] & (1<<bs))
-										{
-											nt->builtBuildings.insert((int)(34+(bs/2))); 
-										}
-									}
+								if(spec->buildingSettings[ir] & 1<<0)
+									nt->builtBuildings.insert(40);
+								if(spec->buildingSettings[ir] & 1<<2)
+									nt->builtBuildings.insert(34); 
+								if(spec->buildingSettings[ir] & 1<<3)
+									nt->builtBuildings.insert(41); 
+								if(spec->buildingSettings[ir] & 1<<5)
+									nt->builtBuildings.insert(35); 
+								if(spec->buildingSettings[ir] & 1<<6)
+									nt->builtBuildings.insert(42); 
+								if(spec->buildingSettings[ir] & 1<<7)
+									nt->builtBuildings.insert(36); 
 							}//else if (ir==4)
 							else if (ir==5)
 							{

+ 7 - 1
hch/CCreatureHandler.cpp

@@ -297,7 +297,13 @@ void CCreatureHandler::loadCreatures()
 		boost::assign::insert(smallImgs)(i-2,smi->ourImages[i].bitmap);
 	}
 	delete smi;
-
+	smi = CGI->spriteh->giveDef("TWCRPORT.DEF");
+	smi->notFreeImgs = true;
+	for (int i=0; i<smi->ourImages.size(); i++)
+	{
+		boost::assign::insert(bigImgs)(i-2,smi->ourImages[i].bitmap);
+	}
+	delete smi;
 }
 
 void CCreatureHandler::loadAnimationInfo()

+ 1 - 0
hch/CCreatureHandler.h

@@ -49,6 +49,7 @@ class CCreatureHandler
 {
 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::vector<CCreature> creatures;
 	std::map<std::string,int> nameToID;
 	void loadCreatures();