2008-01-09 19:21:31 +02:00
|
|
|
#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"
|
2008-01-12 13:32:40 +02:00
|
|
|
#include <sstream>
|
2008-01-09 19:21:31 +02:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
2008-01-15 23:38:01 +02:00
|
|
|
class SORTHELP
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool operator ()
|
|
|
|
(const boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*> *a ,
|
|
|
|
const boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*> *b)
|
|
|
|
{
|
|
|
|
return (a->get<0>())<(b->get<0>());
|
|
|
|
}
|
|
|
|
} srthlp ;
|
2008-01-09 19:21:31 +02:00
|
|
|
|
|
|
|
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");
|
2008-01-12 13:32:40 +02:00
|
|
|
bigTownPic = CGI->spriteh->giveDef("ITPT.DEF");
|
|
|
|
flag = CGI->spriteh->giveDef("CREST58.DEF");
|
2008-01-09 19:21:31 +02:00
|
|
|
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;
|
2008-01-15 23:38:01 +02:00
|
|
|
|
|
|
|
for (std::set<int>::const_iterator i=town->builtBuildings.begin();i!=town->builtBuildings.end();i++)
|
|
|
|
{
|
|
|
|
if(CGI->townh->structures.find(town->subID) != CGI->townh->structures.end())
|
|
|
|
{
|
|
|
|
if(CGI->townh->structures[town->subID].find(*i)!=CGI->townh->structures[town->subID].end())
|
|
|
|
{
|
|
|
|
CDefHandler *b = CGI->spriteh->giveDef(CGI->townh->structures[town->subID][*i]->defName);
|
|
|
|
boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*> *t
|
|
|
|
= new boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*>
|
|
|
|
(*i,b,CGI->townh->structures[town->subID][*i],NULL,NULL);
|
|
|
|
//TODO: obw�dki i pola
|
|
|
|
buildings.push_back(t);
|
|
|
|
}
|
|
|
|
else continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(buildings.begin(),buildings.end(),srthlp);
|
|
|
|
|
2008-01-09 19:21:31 +02:00
|
|
|
if(Activate)
|
|
|
|
{
|
|
|
|
activate();
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CCastleInterface::~CCastleInterface()
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(townInt);
|
|
|
|
SDL_FreeSurface(cityBg);
|
|
|
|
delete exit;
|
|
|
|
delete hall;
|
|
|
|
delete fort;
|
2008-01-12 13:32:40 +02:00
|
|
|
delete bigTownPic;
|
|
|
|
delete flag;
|
2008-01-15 23:38:01 +02:00
|
|
|
|
|
|
|
for(int i=0;i<buildings.size();i++)
|
|
|
|
{
|
|
|
|
if (buildings[i]->get<1>())
|
|
|
|
delete (buildings[i]->get<1>());
|
|
|
|
//if (buildings[i]->get<2>())
|
|
|
|
// delete (buildings[i]->get<2>());
|
|
|
|
if (buildings[i]->get<3>())
|
|
|
|
SDL_FreeSurface(buildings[i]->get<3>());
|
|
|
|
if (buildings[i]->get<4>())
|
|
|
|
SDL_FreeSurface(buildings[i]->get<4>());
|
|
|
|
delete buildings[i];
|
|
|
|
}
|
|
|
|
|
2008-01-09 19:21:31 +02:00
|
|
|
}
|
|
|
|
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;
|
2008-01-09 21:59:23 +02:00
|
|
|
|
|
|
|
//draw fort icon
|
2008-01-09 19:21:31 +02:00
|
|
|
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);
|
|
|
|
|
2008-01-09 21:59:23 +02:00
|
|
|
//draw ((village/town/city) hall)/capitol icon
|
2008-01-09 19:21:31 +02:00
|
|
|
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);
|
|
|
|
|
2008-01-09 21:59:23 +02:00
|
|
|
//draw creatures icons and their growths
|
|
|
|
for(int i=0;i<CREATURES_PER_TOWN;i++)
|
|
|
|
{
|
|
|
|
int cid = -1;
|
|
|
|
if (town->builtBuildings.find(30+i)!=town->builtBuildings.end())
|
|
|
|
{
|
|
|
|
cid = (14*town->subID)+(i*2);
|
|
|
|
if (town->builtBuildings.find(30+CREATURES_PER_TOWN+i)!=town->builtBuildings.end())
|
|
|
|
{
|
|
|
|
cid++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cid>=0)
|
|
|
|
{
|
2008-01-12 13:32:40 +02:00
|
|
|
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);
|
2008-01-09 21:59:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//print name and income
|
2008-01-09 19:21:31 +02:00
|
|
|
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);
|
2008-01-12 13:32:40 +02:00
|
|
|
|
|
|
|
//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);
|
|
|
|
}
|
2008-01-15 23:38:01 +02:00
|
|
|
|
|
|
|
//blit buildings
|
|
|
|
for(int i=0;i<buildings.size();i++)
|
|
|
|
{
|
|
|
|
blitAt(buildings[i]->get<1>()->ourImages[0].bitmap,buildings[i]->get<2>()->x,buildings[i]->get<2>()->y);
|
|
|
|
}
|
2008-01-12 13:32:40 +02:00
|
|
|
|
2008-01-09 19:21:31 +02:00
|
|
|
}
|
|
|
|
void CCastleInterface::activate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void CCastleInterface::deactivate()
|
|
|
|
{
|
|
|
|
exit->deactivate();
|
|
|
|
}
|