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-03-06 20:54:35 +02:00
# include "hch/CBuildingHandler.h"
2008-01-12 13:32:40 +02:00
# include <sstream>
2008-03-06 20:54:35 +02:00
# include "CMessage.h"
2008-03-11 23:36:59 +02:00
# include "hch/CGeneralTextHandler.h"
2008-04-07 20:51:46 +03:00
# include "CCallback.h"
2008-03-21 02:03:31 +02:00
extern TTF_Font * GEOR16 ;
2008-01-19 13:55:04 +02:00
CBuildingRect : : CBuildingRect ( Structure * Str )
2008-03-23 03:01:17 +02:00
: str ( Str ) , moi ( false )
2008-01-19 13:55:04 +02:00
{
def = CGI - > spriteh - > giveDef ( Str - > defName ) ;
2008-02-02 02:41:00 +02:00
pos . x = str - > pos . x ;
pos . y = str - > pos . y ;
pos . w = def - > ourImages [ 0 ] . bitmap - > w ;
pos . h = def - > ourImages [ 0 ] . bitmap - > h ;
if ( Str - > ID < 0 | | ( Str - > ID > = 27 & & Str - > ID < = 29 ) )
{
area = border = NULL ;
return ;
}
2008-01-20 18:24:03 +02:00
if ( border = CGI - > bitmaph - > loadBitmap ( str - > borderName ) )
SDL_SetColorKey ( border , SDL_SRCCOLORKEY , SDL_MapRGB ( border - > format , 0 , 255 , 255 ) ) ;
else
std : : cout < < " Warning: no border for " < < Str - > ID < < std : : endl ;
if ( area = CGI - > bitmaph - > loadBitmap ( str - > areaName ) )
; //SDL_SetColorKey(area,SDL_SRCCOLORKEY,SDL_MapRGB(area->format,0,255,255));
else
std : : cout < < " Warning: no area for " < < Str - > ID < < std : : endl ;
2008-01-19 13:55:04 +02:00
}
CBuildingRect : : ~ CBuildingRect ( )
{
delete def ;
if ( border )
SDL_FreeSurface ( border ) ;
if ( area )
SDL_FreeSurface ( area ) ;
}
void CBuildingRect : : activate ( )
{
2008-01-20 18:24:03 +02:00
Hoverable : : activate ( ) ;
2008-01-19 13:55:04 +02:00
ClickableL : : activate ( ) ;
ClickableR : : activate ( ) ;
2008-03-23 03:01:17 +02:00
2008-01-19 13:55:04 +02:00
}
void CBuildingRect : : deactivate ( )
{
2008-01-20 18:24:03 +02:00
Hoverable : : deactivate ( ) ;
2008-01-19 13:55:04 +02:00
ClickableL : : deactivate ( ) ;
ClickableR : : deactivate ( ) ;
2008-03-23 03:01:17 +02:00
if ( moi )
MotionInterested : : deactivate ( ) ;
moi = false ;
2008-01-19 13:55:04 +02:00
}
bool CBuildingRect : : operator < ( const CBuildingRect & p2 ) const
{
if ( str - > pos . z ! = p2 . str - > pos . z )
return ( str - > pos . z ) < ( p2 . str - > pos . z ) ;
else
return ( str - > ID ) < ( p2 . str - > ID ) ;
}
2008-01-20 18:24:03 +02:00
void CBuildingRect : : hover ( bool on )
2008-01-19 13:55:04 +02:00
{
2008-01-24 00:15:33 +02:00
Hoverable : : hover ( on ) ;
if ( on )
2008-01-20 18:24:03 +02:00
{
2008-03-23 03:01:17 +02:00
if ( ! moi )
MotionInterested : : activate ( ) ;
moi = true ;
2008-01-24 00:15:33 +02:00
}
else
{
2008-03-23 03:01:17 +02:00
if ( moi )
MotionInterested : : deactivate ( ) ;
moi = false ;
2008-01-24 00:15:33 +02:00
if ( LOCPLINT - > castleInt - > hBuild = = this )
2008-01-27 22:37:10 +02:00
{
2008-01-24 00:15:33 +02:00
LOCPLINT - > castleInt - > hBuild = NULL ;
2008-01-27 22:37:10 +02:00
LOCPLINT - > statusbar - > clear ( ) ;
}
2008-01-20 18:24:03 +02:00
}
2008-01-19 13:55:04 +02:00
}
void CBuildingRect : : clickLeft ( tribool down )
{
2008-03-06 20:54:35 +02:00
2008-03-10 01:06:35 +02:00
if ( area & & ( LOCPLINT - > castleInt - > hBuild = = this ) & & ! ( indeterminate ( down ) ) & & ( CSDL_Ext : : SDL_GetPixel ( area , LOCPLINT - > current - > motion . x - pos . x , LOCPLINT - > current - > motion . y - pos . y ) ! = 0 ) ) //na polu
2008-03-06 20:54:35 +02:00
{
2008-03-10 01:06:35 +02:00
if ( pressedL & & ! down )
LOCPLINT - > castleInt - > buildingClicked ( str - > ID ) ;
ClickableL : : clickLeft ( down ) ;
2008-03-06 20:54:35 +02:00
}
2008-01-19 13:55:04 +02:00
//todo - handle
}
void CBuildingRect : : clickRight ( tribool down )
{
2008-03-10 01:06:35 +02:00
if ( ( ! area ) | | ( ! ( ( bool ) down ) ) | | ( this ! = LOCPLINT - > castleInt - > hBuild ) )
2008-03-06 20:54:35 +02:00
return ;
if ( ( CSDL_Ext : : SDL_GetPixel ( area , LOCPLINT - > current - > motion . x - pos . x , LOCPLINT - > current - > motion . y - pos . y ) ! = 0 ) ) //na polu
{
CInfoPopup * vinya = new CInfoPopup ( ) ;
vinya - > free = true ;
vinya - > bitmap = CMessage : : drawBoxTextBitmapSub
( LOCPLINT - > playerID ,
CGI - > buildh - > buildings [ str - > townID ] [ str - > ID ] - > description ,
LOCPLINT - > castleInt - > bicons - > ourImages [ str - > ID ] . bitmap ,
CGI - > buildh - > buildings [ str - > townID ] [ str - > ID ] - > name ) ;
2008-04-25 12:25:59 +03:00
vinya - > pos . x = screen - > w / 2 - vinya - > bitmap - > w / 2 ;
vinya - > pos . y = screen - > h / 2 - vinya - > bitmap - > h / 2 ;
2008-03-06 20:54:35 +02:00
vinya - > activate ( ) ;
}
2008-01-19 13:55:04 +02:00
}
2008-01-24 00:15:33 +02:00
void CBuildingRect : : mouseMoved ( SDL_MouseMotionEvent & sEvent )
{
if ( area )
{
2008-03-15 19:48:05 +02:00
if ( CSDL_Ext : : SDL_GetPixel ( area , sEvent . x - pos . x , sEvent . y - pos . y ) = = 0 ) //hovered pixel is inside this building
2008-01-24 00:15:33 +02:00
{
if ( LOCPLINT - > castleInt - > hBuild = = this )
2008-01-27 22:37:10 +02:00
{
2008-01-24 00:15:33 +02:00
LOCPLINT - > castleInt - > hBuild = NULL ;
2008-01-27 22:37:10 +02:00
LOCPLINT - > statusbar - > clear ( ) ;
}
2008-01-24 00:15:33 +02:00
}
2008-03-15 19:48:05 +02:00
else //inside the area of this building
2008-01-24 00:15:33 +02:00
{
2008-03-15 19:48:05 +02:00
if ( LOCPLINT - > castleInt - > hBuild ) //a building is hovered
2008-01-24 00:15:33 +02:00
{
2008-03-15 19:48:05 +02:00
if ( ( * LOCPLINT - > castleInt - > hBuild ) < ( * this ) ) //set if we are on top
2008-01-24 00:15:33 +02:00
{
LOCPLINT - > castleInt - > hBuild = this ;
2008-03-06 20:54:35 +02:00
if ( CGI - > buildh - > buildings [ str - > townID ] [ str - > ID ] & & CGI - > buildh - > buildings [ str - > townID ] [ str - > ID ] - > name . length ( ) )
LOCPLINT - > statusbar - > print ( CGI - > buildh - > buildings [ str - > townID ] [ str - > ID ] - > name ) ;
else
LOCPLINT - > statusbar - > print ( str - > name ) ;
2008-01-24 00:15:33 +02:00
}
}
2008-03-15 19:48:05 +02:00
else //no building hovered
2008-01-24 00:15:33 +02:00
{
LOCPLINT - > castleInt - > hBuild = this ;
2008-03-06 20:54:35 +02:00
if ( CGI - > buildh - > buildings [ str - > townID ] [ str - > ID ] & & CGI - > buildh - > buildings [ str - > townID ] [ str - > ID ] - > name . length ( ) )
LOCPLINT - > statusbar - > print ( CGI - > buildh - > buildings [ str - > townID ] [ str - > ID ] - > name ) ;
else
LOCPLINT - > statusbar - > print ( str - > name ) ;
2008-01-24 00:15:33 +02:00
}
}
}
//if(border)
// blitAt(border,pos.x,pos.y);
}
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 ( )
2008-01-19 13:55:04 +02:00
( const CBuildingRect * a ,
const CBuildingRect * b )
2008-01-15 23:38:01 +02:00
{
2008-01-19 13:55:04 +02:00
return ( * a ) < ( * b ) ;
2008-01-15 23:38:01 +02:00
}
} srthlp ;
2008-01-09 19:21:31 +02:00
CCastleInterface : : CCastleInterface ( const CGTownInstance * Town , bool Activate )
2008-01-31 23:35:30 +02:00
{
2008-03-11 23:36:59 +02:00
hall = NULL ;
2008-01-09 19:21:31 +02:00
townInt = CGI - > bitmaph - > loadBitmap ( " TOWNSCRN.bmp " ) ;
2008-01-31 23:35:30 +02:00
cityBg = CGI - > bitmaph - > loadBitmap ( getBgName ( Town - > subID ) ) ;
2008-01-09 19:21:31 +02:00
hall = CGI - > spriteh - > giveDef ( " ITMTL.DEF " ) ;
fort = CGI - > spriteh - > giveDef ( " ITMCL.DEF " ) ;
2008-01-12 13:32:40 +02:00
flag = CGI - > spriteh - > giveDef ( " CREST58.DEF " ) ;
2008-04-19 19:15:04 +03:00
hBuild = NULL ;
count = 0 ;
town = Town ;
//garrison
garr = new CGarrisonInt ( 305 , 387 , 4 , 32 , townInt , 243 , 13 , town , town - > visitingHero ) ;
2008-05-18 20:33:39 +03:00
townlist = new CTownList ( 3 , & genRect ( 128 , 48 , 744 , 414 ) , 744 , 414 , 744 , 526 ) ;
exit = new AdventureMapButton
( CGI - > townh - > tcommands [ 8 ] , " " , boost : : bind ( & CCastleInterface : : close , this ) , 744 , 544 , " TSBTNS.DEF " , false , NULL , false ) ;
split = new AdventureMapButton
( CGI - > townh - > tcommands [ 3 ] , " " , boost : : bind ( & CGarrisonInt : : splitClick , garr ) , 744 , 382 , " TSBTNS.DEF " , false , NULL , false ) ;
2008-01-27 22:37:10 +02:00
statusbar = new CStatusBar ( 8 , 555 , " TSTATBAR.bmp " , 732 ) ;
2008-01-31 23:35:30 +02:00
2008-05-18 20:33:39 +03:00
townlist - > fun = boost : : bind ( & CCastleInterface : : townChange , this ) ;
2008-01-31 23:35:30 +02:00
townlist - > genList ( ) ;
townlist - > selected = getIndexOf ( townlist - > items , Town ) ;
if ( ( townlist - > selected + 1 ) > townlist - > SIZE )
townlist - > from = townlist - > selected - townlist - > SIZE + 1 ;
CSDL_Ext : : blueToPlayersAdv ( townInt , LOCPLINT - > playerID ) ;
exit - > bitmapOffset = 4 ;
2008-01-15 23:38:01 +02:00
2008-01-28 16:01:09 +02:00
//buildings
2008-03-23 03:01:17 +02:00
recreateBuildings ( ) ;
2008-01-15 23:38:01 +02:00
2008-01-28 16:01:09 +02:00
2008-01-15 23:38:01 +02:00
2008-01-09 19:21:31 +02:00
if ( Activate )
{
2008-01-19 14:26:55 +02:00
LOCPLINT - > objsToBlit . push_back ( this ) ;
2008-01-09 19:21:31 +02:00
activate ( ) ;
2008-01-19 14:26:55 +02:00
showAll ( ) ;
2008-01-09 19:21:31 +02:00
}
2008-01-19 14:26:55 +02:00
2008-03-06 20:54:35 +02:00
std : : string defname ;
switch ( town - > subID )
{
case 0 :
defname = " HALLCSTL.DEF " ;
break ;
case 1 :
defname = " HALLRAMP.DEF " ;
break ;
case 2 :
defname = " HALLTOWR.DEF " ;
break ;
case 3 :
defname = " HALLINFR.DEF " ;
break ;
case 4 :
defname = " HALLNECR.DEF " ;
break ;
case 5 :
defname = " HALLDUNG.DEF " ;
break ;
case 6 :
defname = " HALLSTRN.DEF " ;
break ;
case 7 :
defname = " HALLFORT.DEF " ;
break ;
case 8 :
defname = " HALLELEM.DEF " ;
break ;
default :
throw new std : : exception ( " Bad town subID " ) ;
}
bicons = CGI - > spriteh - > giveDefEss ( defname ) ;
2008-01-19 14:26:55 +02:00
//blit buildings on bg
//for(int i=0;i<buildings.size();i++)
//{
// blitAt(buildings[i]->def->ourImages[0].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,cityBg);
//}
2008-01-09 19:21:31 +02:00
}
CCastleInterface : : ~ CCastleInterface ( )
{
SDL_FreeSurface ( townInt ) ;
SDL_FreeSurface ( cityBg ) ;
delete exit ;
2008-01-30 00:47:43 +02:00
delete split ;
2008-01-09 19:21:31 +02:00
delete hall ;
delete fort ;
2008-01-12 13:32:40 +02:00
delete flag ;
2008-01-26 23:50:51 +02:00
delete garr ;
2008-01-31 23:35:30 +02:00
delete townlist ;
delete statusbar ;
2008-01-15 23:38:01 +02:00
for ( int i = 0 ; i < buildings . size ( ) ; i + + )
{
delete buildings [ i ] ;
}
2008-03-06 20:54:35 +02:00
delete bicons ;
2008-01-15 23:38:01 +02:00
2008-01-09 19:21:31 +02:00
}
void CCastleInterface : : close ( )
{
2008-01-19 14:26:55 +02:00
LOCPLINT - > objsToBlit . erase ( std : : find ( LOCPLINT - > objsToBlit . begin ( ) , LOCPLINT - > objsToBlit . end ( ) , this ) ) ;
2008-01-09 19:21:31 +02:00
deactivate ( ) ;
LOCPLINT - > castleInt = NULL ;
2008-02-23 00:26:31 +02:00
LOCPLINT - > adventureInt - > activate ( ) ;
2008-01-09 19:21:31 +02:00
delete this ;
}
2008-01-30 00:47:43 +02:00
void CCastleInterface : : splitF ( )
{
}
2008-03-10 01:06:35 +02:00
void CCastleInterface : : buildingClicked ( int building )
{
std : : cout < < " You've clicked on " < < building < < std : : endl ;
2008-05-03 18:30:11 +03:00
if ( building = = 19 | | building = = 18 )
{
building = town - > town - > hordeLvl [ 0 ] + 30 ;
}
else if ( building = = 24 | | building = = 25 )
{
building = town - > town - > hordeLvl [ 1 ] + 30 ;
}
2008-04-04 20:30:53 +03:00
if ( building > = 30 )
{
if ( building > 36 )
building - = 7 ;
std : : vector < std : : pair < int , int > > crs ;
int amount = ( const_cast < CGTownInstance * > ( town ) ) - > strInfo . creatures [ building - 30 ] ; //trzeba odconstowac, bo inaczej operator [] by sypal :(
if ( town - > builtBuildings . find ( building + 7 ) ! = town - > builtBuildings . end ( ) ) //check if there is an upgraded building
crs . push_back ( std : : make_pair ( town - > town - > upgradedCreatures [ building - 30 ] , amount ) ) ;
2008-05-03 18:30:11 +03:00
crs . push_back ( std : : make_pair ( town - > town - > basicCreatures [ building - 30 ] , amount ) ) ;
2008-04-11 20:41:02 +03:00
CRecrutationWindow * rw = new CRecrutationWindow ( crs , this ) ;
2008-04-04 20:30:53 +03:00
rw - > activate ( ) ;
}
2008-04-20 15:39:33 +03:00
else
2008-03-10 01:06:35 +02:00
{
2008-04-20 15:39:33 +03:00
switch ( building )
{
case 10 : case 11 : case 12 : case 13 :
enterHall ( ) ;
break ;
default :
std : : cout < < " This building isn't handled... \n " ;
}
2008-03-10 01:06:35 +02:00
}
}
void CCastleInterface : : enterHall ( )
{
deactivate ( ) ;
2008-03-11 23:36:59 +02:00
hallInt = new CHallInterface ( this ) ;
hallInt - > activate ( ) ;
hallInt - > show ( ) ;
2008-03-10 01:06:35 +02:00
}
2008-01-19 14:26:55 +02:00
void CCastleInterface : : showAll ( SDL_Surface * to )
{
if ( ! to )
2008-04-25 12:25:59 +03:00
to = screen ;
2008-01-19 14:26:55 +02:00
blitAt ( cityBg , 0 , 0 , to ) ;
blitAt ( townInt , 0 , 374 , to ) ;
2008-01-09 19:21:31 +02:00
LOCPLINT - > adventureInt - > resdatabar . draw ( ) ;
2008-01-31 23:35:30 +02:00
townlist - > draw ( ) ;
2008-03-10 01:06:35 +02:00
statusbar - > show ( ) ;
2008-01-09 19:21:31 +02:00
2008-03-10 01:06:35 +02:00
garr - > show ( ) ;
2008-01-09 19:21:31 +02:00
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 ;
2008-01-19 14:26:55 +02:00
blitAt ( fort - > ourImages [ pom ] . bitmap , 122 , 413 , to ) ;
2008-01-09 19:21:31 +02:00
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 ;
2008-01-19 14:26:55 +02:00
blitAt ( hall - > ourImages [ pom ] . bitmap , 80 , 413 , to ) ;
2008-01-09 19:21:31 +02:00
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 ( ) )
{
if ( town - > builtBuildings . find ( 30 + CREATURES_PER_TOWN + i ) ! = town - > builtBuildings . end ( ) )
2008-04-04 20:30:53 +03:00
cid = town - > town - > upgradedCreatures [ i ] ;
else
cid = town - > town - > basicCreatures [ i ] ;
2008-01-09 21:59:23 +02:00
}
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 ) ;
2008-01-19 14:26:55 +02:00
blitAt ( CGI - > creh - > smallImgs [ cid ] , pomx , pomy , to ) ;
2008-01-12 13:32:40 +02:00
std : : ostringstream oss ;
2008-04-11 20:41:02 +03:00
oss < < ' + ' < < town - > creatureGrowth ( i ) ;
2008-01-19 14:26:55 +02:00
CSDL_Ext : : printAtMiddle ( oss . str ( ) , pomx + 16 , pomy + 37 , GEOR13 , zwykly , to ) ;
2008-01-09 21:59:23 +02:00
}
}
//print name and income
2008-01-19 14:26:55 +02:00
CSDL_Ext : : printAt ( town - > name , 85 , 389 , GEOR13 , zwykly , to ) ;
2008-01-09 19:21:31 +02:00
char temp [ 10 ] ;
2008-02-18 23:14:28 +02:00
itoa ( town - > dailyIncome ( ) , temp , 10 ) ;
2008-01-19 14:26:55 +02:00
CSDL_Ext : : printAtMiddle ( temp , 195 , 442 , GEOR13 , zwykly , to ) ;
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 + + ;
2008-02-18 23:14:28 +02:00
blitAt ( LOCPLINT - > bigTownPic - > ourImages [ pom ] . bitmap , 15 , 387 , to ) ;
2008-01-12 13:32:40 +02:00
//flag
2008-02-01 02:38:17 +02:00
if ( town - > getOwner ( ) < PLAYER_LIMIT )
blitAt ( flag - > ourImages [ town - > getOwner ( ) ] . bitmap , 241 , 387 , to ) ;
2008-01-26 21:36:31 +02:00
2008-01-19 14:26:55 +02:00
show ( ) ;
}
2008-01-31 23:35:30 +02:00
void CCastleInterface : : townChange ( )
{
const CGTownInstance * nt = townlist - > items [ townlist - > selected ] ;
deactivate ( ) ;
LOCPLINT - > objsToBlit . erase ( std : : find ( LOCPLINT - > objsToBlit . begin ( ) , LOCPLINT - > objsToBlit . end ( ) , this ) ) ;
delete this ;
LOCPLINT - > castleInt = new CCastleInterface ( nt , true ) ;
}
2008-01-19 14:26:55 +02:00
void CCastleInterface : : show ( SDL_Surface * to )
{
2008-03-11 23:36:59 +02:00
if ( ! showing )
return ;
2008-01-19 14:26:55 +02:00
if ( ! to )
2008-04-25 12:25:59 +03:00
to = screen ;
2008-01-19 14:26:55 +02:00
count + + ;
2008-01-29 15:00:45 +02:00
if ( count = = 4 )
2008-01-19 14:26:55 +02:00
{
count = 0 ;
animval + + ;
2008-01-12 13:32:40 +02:00
}
2008-01-15 23:38:01 +02:00
2008-01-20 18:24:03 +02:00
blitAt ( cityBg , 0 , 0 , to ) ;
2008-01-19 14:26:55 +02:00
2008-01-15 23:38:01 +02:00
//blit buildings
for ( int i = 0 ; i < buildings . size ( ) ; i + + )
{
2008-01-19 14:26:55 +02:00
if ( ( animval ) % ( buildings [ i ] - > def - > ourImages . size ( ) ) )
{
blitAt ( buildings [ i ] - > def - > ourImages [ 0 ] . bitmap , buildings [ i ] - > pos . x , buildings [ i ] - > pos . y , to ) ;
blitAt ( buildings [ i ] - > def - > ourImages [ ( animval ) % ( buildings [ i ] - > def - > ourImages . size ( ) ) ] . bitmap , buildings [ i ] - > pos . x , buildings [ i ] - > pos . y , to ) ;
}
else
blitAt ( buildings [ i ] - > def - > ourImages [ ( animval ) % ( buildings [ i ] - > def - > ourImages . size ( ) ) ] . bitmap , buildings [ i ] - > pos . x , buildings [ i ] - > pos . y , to ) ;
2008-01-24 00:15:33 +02:00
//if(buildings[i]->hovered && buildings[i]->border)
// blitAt(buildings[i]->border,buildings[i]->pos.x,buildings[i]->pos.y);
if ( hBuild = = buildings [ i ] & & hBuild - > border )
blitAt ( hBuild - > border , hBuild - > pos , to ) ;
2008-01-15 23:38:01 +02:00
}
2008-01-12 13:32:40 +02:00
2008-01-09 19:21:31 +02:00
}
void CCastleInterface : : activate ( )
{
2008-03-11 23:36:59 +02:00
showing = true ;
2008-01-31 23:35:30 +02:00
townlist - > activate ( ) ;
2008-01-26 21:36:31 +02:00
garr - > activate ( ) ;
2008-01-20 14:34:39 +02:00
LOCPLINT - > curint = this ;
2008-01-27 22:37:10 +02:00
LOCPLINT - > statusbar = statusbar ;
2008-01-26 21:36:31 +02:00
exit - > activate ( ) ;
2008-01-30 00:47:43 +02:00
split - > activate ( ) ;
2008-01-20 18:24:03 +02:00
for ( int i = 0 ; i < buildings . size ( ) ; i + + )
buildings [ i ] - > activate ( ) ;
2008-01-09 19:21:31 +02:00
}
void CCastleInterface : : deactivate ( )
{
2008-03-11 23:36:59 +02:00
showing = false ;
2008-01-31 23:35:30 +02:00
townlist - > deactivate ( ) ;
2008-01-26 21:36:31 +02:00
garr - > deactivate ( ) ;
2008-01-09 19:21:31 +02:00
exit - > deactivate ( ) ;
2008-01-30 00:47:43 +02:00
split - > deactivate ( ) ;
2008-01-20 18:24:03 +02:00
for ( int i = 0 ; i < buildings . size ( ) ; i + + )
buildings [ i ] - > deactivate ( ) ;
2008-03-10 01:06:35 +02:00
}
2008-03-23 03:01:17 +02:00
void CCastleInterface : : addBuilding ( int bid )
{
2008-05-03 18:30:11 +03:00
//TODO: lepiej by bylo tylko dodawac co trzeba pamietajac o grupach
2008-03-23 03:01:17 +02:00
recreateBuildings ( ) ;
}
void CCastleInterface : : removeBuilding ( int bid )
{
2008-05-03 18:30:11 +03:00
//TODO: lepiej by bylo tylko usuwac co trzeba pamietajac o grupach
2008-03-23 03:01:17 +02:00
recreateBuildings ( ) ;
}
void CCastleInterface : : recreateBuildings ( )
{
for ( int i = 0 ; i < buildings . size ( ) ; i + + )
{
if ( showing )
buildings [ i ] - > deactivate ( ) ;
delete buildings [ i ] ;
}
buildings . clear ( ) ;
hBuild = NULL ;
std : : set < std : : pair < int , int > > s ; //group - id
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 ( ) ) //we have info about structures in this town
{
if ( CGI - > townh - > structures [ town - > subID ] . find ( * i ) ! = CGI - > townh - > structures [ town - > subID ] . end ( ) ) //we have info about that structure
{
Structure * st = CGI - > townh - > structures [ town - > subID ] [ * i ] ;
if ( st - > group < 0 ) //no group - just add it
{
buildings . push_back ( new CBuildingRect ( st ) ) ;
}
else
{
std : : set < std : : pair < int , int > > : : iterator obecny = s . end ( ) ;
for ( std : : set < std : : pair < int , int > > : : iterator seti = s . begin ( ) ; seti ! = s . end ( ) ; seti + + ) //check if we have already building from same group
{
if ( seti - > first = = st - > group )
{
obecny = seti ;
break ;
}
}
if ( obecny ! = s . end ( ) )
{
if ( ( * ( CGI - > townh - > structures [ town - > subID ] [ obecny - > second ] ) ) < ( * ( CGI - > townh - > structures [ town - > subID ] [ st - > ID ] ) ) ) //we have to replace old building with current one
{
for ( int itpb = 0 ; itpb < buildings . size ( ) ; itpb + + )
{
if ( buildings [ itpb ] - > str - > ID = = obecny - > second )
{
delete buildings [ itpb ] ;
buildings . erase ( buildings . begin ( ) + itpb ) ;
obecny - > second = st - > ID ;
buildings . push_back ( new CBuildingRect ( st ) ) ;
}
}
}
}
else
{
buildings . push_back ( new CBuildingRect ( st ) ) ;
s . insert ( std : : pair < int , int > ( st - > group , st - > ID ) ) ;
}
}
}
else continue ;
}
else
break ;
}
2008-04-04 20:30:53 +03:00
std : : sort ( buildings . begin ( ) , buildings . end ( ) , srthlp ) ;
2008-03-23 03:01:17 +02:00
}
2008-04-11 20:41:02 +03:00
void CCastleInterface : : recruit ( int ID , int amount )
{
LOCPLINT - > cb - > recruitCreatures ( town , ID , amount ) ;
}
2008-03-10 01:06:35 +02:00
void CHallInterface : : CResDataBar : : show ( SDL_Surface * to )
{
2008-03-11 23:36:59 +02:00
blitAt ( bg , pos . x , pos . y ) ;
char * buf = new char [ 15 ] ;
for ( int i = 0 ; i < 7 ; i + + )
{
itoa ( LOCPLINT - > cb - > getResourceAmount ( i ) , buf , 10 ) ;
CSDL_Ext : : printAtMiddle ( buf , pos . x + 50 + 76 * i , pos . y + pos . h / 2 , GEOR13 , zwykly ) ;
}
std : : vector < std : : string > temp ;
itoa ( LOCPLINT - > cb - > getDate ( 3 ) , buf , 10 ) ; temp . push_back ( std : : string ( buf ) ) ;
itoa ( LOCPLINT - > cb - > getDate ( 2 ) , buf , 10 ) ; temp . push_back ( buf ) ;
itoa ( LOCPLINT - > cb - > getDate ( 1 ) , buf , 10 ) ; temp . push_back ( buf ) ;
CSDL_Ext : : printAtMiddle ( CSDL_Ext : : processStr (
CGI - > generaltexth - > allTexts [ 62 ]
+ " : %s, "
+ CGI - > generaltexth - > allTexts [ 63 ]
+ " : %s, "
+ CGI - > generaltexth - > allTexts [ 64 ]
+ " : %s " , temp )
, pos . x + 545 + ( pos . w - 545 ) / 2 , pos . y + pos . h / 2 , GEOR13 , zwykly ) ;
temp . clear ( ) ;
2008-04-25 12:25:59 +03:00
//updateRect(&pos,screen);
2008-03-11 23:36:59 +02:00
delete [ ] buf ;
2008-03-10 01:06:35 +02:00
}
CHallInterface : : CResDataBar : : CResDataBar ( )
{
2008-03-11 23:36:59 +02:00
bg = CGI - > bitmaph - > loadBitmap ( " Z2ESBAR.bmp " ) ;
2008-03-21 02:03:31 +02:00
SDL_SetColorKey ( bg , SDL_SRCCOLORKEY , SDL_MapRGB ( bg - > format , 0 , 255 , 255 ) ) ;
2008-03-16 02:09:43 +02:00
CSDL_Ext : : blueToPlayersAdv ( bg , LOCPLINT - > playerID ) ;
2008-03-11 23:36:59 +02:00
pos . x = 7 ;
pos . y = 575 ;
pos . w = bg - > w ;
pos . h = bg - > h ;
2008-03-10 01:06:35 +02:00
}
CHallInterface : : CResDataBar : : ~ CResDataBar ( )
{
2008-03-11 23:36:59 +02:00
SDL_FreeSurface ( bg ) ;
2008-03-10 01:06:35 +02:00
}
void CHallInterface : : CBuildingBox : : hover ( bool on )
{
2008-03-16 02:09:43 +02:00
Hoverable : : hover ( on ) ;
if ( on )
{
std : : string toPrint = CGI - > townh - > hcommands [ state ] ;
std : : vector < std : : string > name ;
2008-03-21 02:03:31 +02:00
name . push_back ( CGI - > buildh - > buildings [ LOCPLINT - > castleInt - > town - > subID ] [ BID ] - > name ) ;
2008-03-16 02:09:43 +02:00
LOCPLINT - > statusbar - > print ( CSDL_Ext : : processStr ( toPrint , name ) ) ;
}
else
LOCPLINT - > statusbar - > clear ( ) ;
2008-03-10 01:06:35 +02:00
}
void CHallInterface : : CBuildingBox : : clickLeft ( tribool down )
{
2008-03-21 02:03:31 +02:00
if ( pressedL & & ( ! down ) )
{
LOCPLINT - > castleInt - > hallInt - > deactivate ( ) ;
new CHallInterface : : CBuildWindow ( LOCPLINT - > castleInt - > town - > subID , BID , state , 0 ) ;
}
ClickableL : : clickLeft ( down ) ;
2008-03-10 01:06:35 +02:00
}
void CHallInterface : : CBuildingBox : : clickRight ( tribool down )
{
2008-03-21 02:03:31 +02:00
if ( down )
{
LOCPLINT - > castleInt - > hallInt - > deactivate ( ) ;
new CHallInterface : : CBuildWindow ( LOCPLINT - > castleInt - > town - > subID , BID , state , 1 ) ;
}
ClickableR : : clickRight ( down ) ;
2008-03-10 01:06:35 +02:00
}
2008-03-11 23:36:59 +02:00
void CHallInterface : : CBuildingBox : : show ( SDL_Surface * to )
{
2008-03-21 02:03:31 +02:00
blitAt ( LOCPLINT - > castleInt - > bicons - > ourImages [ BID ] . bitmap , pos . x , pos . y ) ;
2008-03-16 02:09:43 +02:00
int pom , pom2 = - 1 ;
2008-03-11 23:36:59 +02:00
switch ( state )
{
2008-03-16 02:09:43 +02:00
case 4 :
2008-03-11 23:36:59 +02:00
pom = 0 ;
2008-03-16 02:09:43 +02:00
pom2 = 0 ;
2008-03-11 23:36:59 +02:00
break ;
2008-03-16 02:09:43 +02:00
case 7 :
2008-03-11 23:36:59 +02:00
pom = 1 ;
break ;
2008-03-16 02:09:43 +02:00
case 6 :
pom2 = 2 ;
2008-03-11 23:36:59 +02:00
pom = 2 ;
break ;
2008-03-23 03:01:17 +02:00
case 0 : case 5 : case 8 :
2008-03-16 02:09:43 +02:00
pom2 = 1 ;
pom = 2 ;
break ;
case 2 : case 1 : default :
2008-03-11 23:36:59 +02:00
pom = 3 ;
2008-03-16 02:09:43 +02:00
break ;
2008-03-11 23:36:59 +02:00
}
blitAt ( LOCPLINT - > castleInt - > hallInt - > bars - > ourImages [ pom ] . bitmap , pos . x - 1 , pos . y + 71 ) ;
2008-03-16 02:09:43 +02:00
if ( pom2 > = 0 )
blitAt ( LOCPLINT - > castleInt - > hallInt - > status - > ourImages [ pom2 ] . bitmap , pos . x + 135 , pos . y + 54 ) ;
2008-03-21 02:03:31 +02:00
CSDL_Ext : : printAtMiddle ( CGI - > buildh - > buildings [ LOCPLINT - > castleInt - > town - > subID ] [ BID ] - > name , pos . x - 1 + LOCPLINT - > castleInt - > hallInt - > bars - > ourImages [ 0 ] . bitmap - > w / 2 , pos . y + 71 + LOCPLINT - > castleInt - > hallInt - > bars - > ourImages [ 0 ] . bitmap - > h / 2 , GEOR13 , zwykly ) ;
2008-03-11 23:36:59 +02:00
}
2008-03-10 01:06:35 +02:00
void CHallInterface : : CBuildingBox : : activate ( )
{
2008-03-16 02:09:43 +02:00
Hoverable : : activate ( ) ;
ClickableL : : activate ( ) ;
ClickableR : : activate ( ) ;
2008-03-10 01:06:35 +02:00
}
void CHallInterface : : CBuildingBox : : deactivate ( )
{
2008-03-16 02:09:43 +02:00
Hoverable : : deactivate ( ) ;
ClickableL : : deactivate ( ) ;
ClickableR : : deactivate ( ) ;
2008-03-10 01:06:35 +02:00
}
CHallInterface : : CBuildingBox : : ~ CBuildingBox ( )
{
}
2008-03-11 23:36:59 +02:00
CHallInterface : : CBuildingBox : : CBuildingBox ( int id )
2008-03-21 02:03:31 +02:00
: BID ( id )
2008-03-11 23:36:59 +02:00
{
pos . w = 150 ;
pos . h = 70 ;
}
CHallInterface : : CBuildingBox : : CBuildingBox ( int id , int x , int y )
2008-03-21 02:03:31 +02:00
: BID ( id )
2008-03-11 23:36:59 +02:00
{
pos . x = x ;
pos . y = y ;
2008-03-16 02:09:43 +02:00
pos . w = 150 ;
pos . h = 70 ;
2008-03-11 23:36:59 +02:00
}
2008-03-10 01:06:35 +02:00
CHallInterface : : CHallInterface ( CCastleInterface * owner )
{
2008-03-11 23:36:59 +02:00
bg = CGI - > bitmaph - > loadBitmap ( CGI - > buildh - > hall [ owner - > town - > subID ] . first ) ;
2008-03-16 02:09:43 +02:00
CSDL_Ext : : blueToPlayersAdv ( bg , LOCPLINT - > playerID ) ;
2008-03-11 23:36:59 +02:00
bars = CGI - > spriteh - > giveDefEss ( " TPTHBAR.DEF " ) ;
status = CGI - > spriteh - > giveDefEss ( " TPTHCHK.DEF " ) ;
2008-05-18 20:33:39 +03:00
exit = new AdventureMapButton
( CGI - > townh - > tcommands [ 8 ] , " " , boost : : bind ( & CHallInterface : : close , this ) , 748 , 556 , " TPMAGE1.DEF " , false , NULL , false ) ;
2008-03-21 02:03:31 +02:00
//preparing boxes with buildings//
2008-03-16 02:09:43 +02:00
boxes . resize ( 5 ) ;
2008-03-11 23:36:59 +02:00
for ( int i = 0 ; i < 5 ; i + + ) //for each row
{
for ( int j = 0 ; j < CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] . size ( ) ; j + + ) //for each box
{
int k = 0 ;
for ( ; k < CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] [ j ] . size ( ) ; k + + ) //we are looking for the first not build structure
{
if (
( owner - > town - > builtBuildings . find ( CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] [ j ] [ k ] ) )
= =
( owner - > town - > builtBuildings . end ( ) ) )
{
int x = 34 + 194 * j ,
2008-03-16 02:09:43 +02:00
y = 37 + 104 * i ,
ID = CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] [ j ] [ k ] ;
if ( CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] . size ( ) = = 2 ) //only two boxes in this row
2008-03-11 23:36:59 +02:00
x + = 194 ;
2008-03-16 02:09:43 +02:00
else if ( CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] . size ( ) = = 3 ) //only three boxes in this row
2008-03-11 23:36:59 +02:00
x + = 97 ;
boxes [ i ] . push_back ( new CBuildingBox ( CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] [ j ] [ k ] , x , y ) ) ;
2008-03-16 02:09:43 +02:00
boxes [ i ] [ boxes [ i ] . size ( ) - 1 ] - > state = 7 ; //allowed by default
2008-03-11 23:36:59 +02:00
//can we build it?
2008-03-16 02:09:43 +02:00
if ( owner - > town - > forbiddenBuildings . find ( CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] [ j ] [ k ] ) ! = owner - > town - > forbiddenBuildings . end ( ) )
2008-03-11 23:36:59 +02:00
boxes [ i ] [ boxes [ i ] . size ( ) - 1 ] - > state = 2 ; //forbidden
2008-03-16 02:09:43 +02:00
else if ( owner - > town - > builded > = MAX_BUILDING_PER_TURN )
2008-03-23 03:01:17 +02:00
boxes [ i ] [ boxes [ i ] . size ( ) - 1 ] - > state = 5 ; //building limit
2008-03-21 02:03:31 +02:00
//checking resources
CBuilding * pom = CGI - > buildh - > buildings [ owner - > town - > subID ] [ CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] [ j ] [ k ] ] ;
for ( int res = 0 ; res < 7 ; res + + ) //TODO: support custom amount of resources
{
if ( pom - > resources [ res ] > LOCPLINT - > cb - > getResourceAmount ( res ) )
boxes [ i ] [ boxes [ i ] . size ( ) - 1 ] - > state = 6 ; //lack of res
}
2008-03-11 23:36:59 +02:00
2008-03-21 02:03:31 +02:00
//checking for requirements
2008-03-16 02:09:43 +02:00
for ( std : : set < int > : : iterator ri = CGI - > townh - > requirements [ owner - > town - > subID ] [ ID ] . begin ( ) ;
ri ! = CGI - > townh - > requirements [ owner - > town - > subID ] [ ID ] . end ( ) ;
ri + + )
2008-03-11 23:36:59 +02:00
{
2008-03-16 02:09:43 +02:00
if ( owner - > town - > builtBuildings . find ( * ri ) = = owner - > town - > builtBuildings . end ( ) )
2008-03-23 03:01:17 +02:00
boxes [ i ] [ boxes [ i ] . size ( ) - 1 ] - > state = 8 ; //lack of requirements - cannot build
2008-03-16 02:09:43 +02:00
}
2008-03-11 23:36:59 +02:00
2008-03-16 02:09:43 +02:00
//TODO: check if capital is already built, check if there is water for shipyard
2008-03-11 23:36:59 +02:00
2008-03-10 01:06:35 +02:00
2008-03-16 02:09:43 +02:00
2008-03-11 23:36:59 +02:00
break ;
}
}
if ( k = = CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] [ j ] . size ( ) ) //all buildings built - let's take the last one
{
int x = 34 + 194 * j ,
y = 37 + 104 * i ;
if ( CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] . size ( ) = = 2 )
x + = 194 ;
else if ( CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] . size ( ) = = 3 )
x + = 97 ;
boxes [ i ] . push_back ( new CBuildingBox ( CGI - > buildh - > hall [ owner - > town - > subID ] . second [ i ] [ j ] [ k - 1 ] , x , y ) ) ;
2008-03-16 02:09:43 +02:00
boxes [ i ] [ boxes [ i ] . size ( ) - 1 ] - > state = 4 ; //already exists
2008-03-11 23:36:59 +02:00
}
}
}
2008-03-10 01:06:35 +02:00
}
CHallInterface : : ~ CHallInterface ( )
{
2008-03-16 02:09:43 +02:00
delete bars ;
delete status ;
SDL_FreeSurface ( bg ) ;
for ( int i = 0 ; i < boxes . size ( ) ; i + + )
for ( int j = 0 ; j < boxes [ i ] . size ( ) ; j + + )
delete boxes [ i ] [ j ] ;
delete exit ;
2008-03-10 01:06:35 +02:00
}
void CHallInterface : : close ( )
{
2008-03-11 23:36:59 +02:00
deactivate ( ) ;
2008-03-23 03:01:17 +02:00
delete this ;
2008-03-11 23:36:59 +02:00
LOCPLINT - > castleInt - > activate ( ) ;
LOCPLINT - > castleInt - > showAll ( ) ;
2008-03-10 01:06:35 +02:00
}
void CHallInterface : : show ( SDL_Surface * to )
{
2008-03-11 23:36:59 +02:00
blitAt ( bg , 0 , 0 ) ;
resdatabar . show ( ) ;
exit - > show ( ) ;
for ( int i = 0 ; i < 5 ; i + + )
{
for ( int j = 0 ; j < boxes [ i ] . size ( ) ; j + + )
boxes [ i ] [ j ] - > show ( ) ;
}
2008-03-10 01:06:35 +02:00
}
void CHallInterface : : activate ( )
{
2008-03-11 23:36:59 +02:00
for ( int i = 0 ; i < 5 ; i + + )
for ( int j = 0 ; j < boxes [ i ] . size ( ) ; j + + )
boxes [ i ] [ j ] - > activate ( ) ;
exit - > activate ( ) ;
2008-03-10 01:06:35 +02:00
}
void CHallInterface : : deactivate ( )
{
2008-03-11 23:36:59 +02:00
for ( int i = 0 ; i < 5 ; i + + )
{
for ( int j = 0 ; j < boxes [ i ] . size ( ) ; j + + )
{
boxes [ i ] [ j ] - > deactivate ( ) ;
}
}
exit - > deactivate ( ) ;
2008-03-16 02:09:43 +02:00
}
void CHallInterface : : CBuildWindow : : activate ( )
{
2008-03-23 03:01:17 +02:00
LOCPLINT - > objsToBlit . push_back ( this ) ;
ClickableR : : activate ( ) ;
if ( mode )
return ;
2008-04-04 20:30:53 +03:00
if ( state = = 7 )
buy - > activate ( ) ;
2008-03-21 02:03:31 +02:00
cancel - > activate ( ) ;
2008-03-16 02:09:43 +02:00
}
void CHallInterface : : CBuildWindow : : deactivate ( )
{
2008-03-23 03:01:17 +02:00
LOCPLINT - > objsToBlit . erase ( std : : find ( LOCPLINT - > objsToBlit . begin ( ) , LOCPLINT - > objsToBlit . end ( ) , this ) ) ;
ClickableR : : deactivate ( ) ;
if ( mode )
return ;
2008-04-04 20:30:53 +03:00
if ( state = = 7 )
buy - > deactivate ( ) ;
2008-03-21 02:03:31 +02:00
cancel - > deactivate ( ) ;
}
void CHallInterface : : CBuildWindow : : Buy ( )
{
LOCPLINT - > cb - > buildBuilding ( LOCPLINT - > castleInt - > town , bid ) ;
2008-03-23 03:01:17 +02:00
deactivate ( ) ;
delete this ;
delete LOCPLINT - > castleInt - > hallInt ;
LOCPLINT - > castleInt - > hallInt = NULL ;
LOCPLINT - > castleInt - > activate ( ) ;
LOCPLINT - > castleInt - > showAll ( ) ;
2008-03-21 02:03:31 +02:00
}
void CHallInterface : : CBuildWindow : : close ( )
{
deactivate ( ) ;
delete this ;
LOCPLINT - > castleInt - > hallInt - > activate ( ) ;
LOCPLINT - > castleInt - > hallInt - > show ( ) ;
}
void CHallInterface : : CBuildWindow : : clickRight ( tribool down )
{
if ( ( ! down | | indeterminate ( down ) ) & & mode )
close ( ) ;
2008-03-16 02:09:43 +02:00
}
void CHallInterface : : CBuildWindow : : show ( SDL_Surface * to )
{
2008-03-21 02:03:31 +02:00
SDL_Rect pom = genRect ( bitmap - > h - 1 , bitmap - > w - 1 , pos . x , pos . y ) ;
SDL_Rect poms = pom ; poms . x = 0 ; poms . y = 0 ;
2008-04-25 12:25:59 +03:00
SDL_BlitSurface ( bitmap , & poms , to ? to : screen , & pom ) ;
2008-03-23 03:01:17 +02:00
if ( ! mode )
{
buy - > show ( ) ;
cancel - > show ( ) ;
}
2008-03-21 02:03:31 +02:00
}
2008-03-23 03:01:17 +02:00
std : : string CHallInterface : : CBuildWindow : : getTextForState ( int state )
2008-03-21 02:03:31 +02:00
{
2008-03-23 03:01:17 +02:00
std : : string ret ;
2008-03-21 02:03:31 +02:00
if ( state < 7 )
2008-03-23 03:01:17 +02:00
ret = CGI - > townh - > hcommands [ state ] ;
2008-03-21 02:03:31 +02:00
switch ( state )
{
2008-03-23 03:01:17 +02:00
case 4 :
ret . replace ( ret . find_first_of ( " %s " ) , 2 , CGI - > buildh - > buildings [ tid ] [ bid ] - > name ) ;
break ;
2008-03-21 02:03:31 +02:00
case 7 :
return CGI - > generaltexth - > allTexts [ 219 ] ; //all prereq. are met
2008-03-23 03:01:17 +02:00
case 8 :
{
ret = CGI - > generaltexth - > allTexts [ 52 ] ;
std : : set < int > used ;
used . insert ( bid ) ;
std : : set < int > reqs ;
for ( std : : set < int > : : iterator i = CGI - > townh - > requirements [ tid ] [ bid ] . begin ( ) ; i ! = CGI - > townh - > requirements [ tid ] [ bid ] . end ( ) ; i + + )
if ( LOCPLINT - > castleInt - > town - > builtBuildings . find ( * i ) = = LOCPLINT - > castleInt - > town - > builtBuildings . end ( ) )
reqs . insert ( * i ) ;
while ( true )
{
int czystych = 0 ;
for ( std : : set < int > : : iterator i = reqs . begin ( ) ; i ! = reqs . end ( ) ; i + + )
{
if ( used . find ( * i ) = = used . end ( ) ) //we haven't added requirements for this building
{
used . insert ( * i ) ;
for (
std : : set < int > : : iterator j = CGI - > townh - > requirements [ tid ] [ * i ] . begin ( ) ;
j ! = CGI - > townh - > requirements [ tid ] [ * i ] . end ( ) ;
j + +
)
{
if ( LOCPLINT - > castleInt - > town - > builtBuildings . find ( * j ) = = //this building is not built
LOCPLINT - > castleInt - > town - > builtBuildings . end ( ) )
reqs . insert ( * j ) ;
}
}
else
{
czystych + + ;
}
}
if ( czystych = = reqs . size ( ) )
break ;
}
bool first = true ;
for ( std : : set < int > : : iterator i = reqs . begin ( ) ; i ! = reqs . end ( ) ; i + + )
{
ret + = ( ( ( first ) ? ( " " ) : ( " , " ) ) + CGI - > buildh - > buildings [ tid ] [ * i ] - > name ) ;
first = false ;
}
}
2008-03-21 02:03:31 +02:00
}
2008-03-23 03:01:17 +02:00
return ret ;
2008-03-16 02:09:43 +02:00
}
CHallInterface : : CBuildWindow : : CBuildWindow ( int Tid , int Bid , int State , bool Mode )
: tid ( Tid ) , bid ( Bid ) , mode ( Mode ) , state ( State )
{
2008-03-21 02:03:31 +02:00
SDL_Surface * hhlp = CGI - > bitmaph - > loadBitmap ( " TPUBUILD.bmp " ) ;
2008-04-25 12:25:59 +03:00
bitmap = SDL_ConvertSurface ( hhlp , screen - > format , 0 ) ; //na 8bitowej mapie by sie psulo
2008-03-21 02:03:31 +02:00
SDL_SetColorKey ( hhlp , SDL_SRCCOLORKEY , SDL_MapRGB ( hhlp - > format , 0 , 255 , 255 ) ) ;
SDL_FreeSurface ( hhlp ) ;
2008-04-25 12:25:59 +03:00
pos . x = screen - > w / 2 - bitmap - > w / 2 ;
pos . y = screen - > h / 2 - bitmap - > h / 2 ;
2008-03-16 02:09:43 +02:00
CSDL_Ext : : blueToPlayersAdv ( bitmap , LOCPLINT - > playerID ) ;
2008-03-21 02:03:31 +02:00
blitAt ( LOCPLINT - > castleInt - > bicons - > ourImages [ bid ] . bitmap , 125 , 50 , bitmap ) ;
std : : vector < std : : string > pom ; pom . push_back ( CGI - > buildh - > buildings [ tid ] [ bid ] - > name ) ;
CSDL_Ext : : printAtMiddleWB ( CGI - > buildh - > buildings [ tid ] [ bid ] - > description , 197 , 168 , GEOR16 , 40 , zwykly , bitmap ) ;
CSDL_Ext : : printAtMiddleWB ( getTextForState ( state ) , 197 , 248 , GEOR13 , 50 , zwykly , bitmap ) ;
CSDL_Ext : : printAtMiddle ( CSDL_Ext : : processStr ( CGI - > townh - > hcommands [ 7 ] , pom ) , 197 , 30 , GEOR16 , tytulowy , bitmap ) ;
int resamount = 0 ; for ( int i = 0 ; i < 7 ; i + + ) if ( CGI - > buildh - > buildings [ tid ] [ bid ] - > resources [ i ] ) resamount + + ;
int ah = ( resamount > 4 ) ? 304 : 341 ;
int cn = - 1 , it = 0 ;
int row1w = std : : min ( resamount , 4 ) * 32 + ( std : : min ( resamount , 4 ) - 1 ) * 45 ,
row2w = ( resamount - 4 ) * 32 + ( resamount - 5 ) * 45 ;
char buf [ 15 ] ;
while ( + + cn < 7 )
{
if ( ! CGI - > buildh - > buildings [ tid ] [ bid ] - > resources [ cn ] )
continue ;
itoa ( CGI - > buildh - > buildings [ tid ] [ bid ] - > resources [ cn ] , buf , 10 ) ;
if ( it < 4 )
{
CSDL_Ext : : printAtMiddle ( buf , ( bitmap - > w / 2 - row1w / 2 ) + 77 * it + 16 , ah + 42 , GEOR16 , zwykly , bitmap ) ;
blitAt ( CGI - > townh - > resources - > ourImages [ cn ] . bitmap , ( bitmap - > w / 2 - row1w / 2 ) + 77 * it + + , ah , bitmap ) ;
}
else
{
CSDL_Ext : : printAtMiddle ( buf , ( bitmap - > w / 2 - row2w / 2 ) + 77 * it + 16 - 308 , ah + 42 , GEOR16 , zwykly , bitmap ) ;
blitAt ( CGI - > townh - > resources - > ourImages [ cn ] . bitmap , ( bitmap - > w / 2 - row2w / 2 ) + 77 * it + + - 308 , ah , bitmap ) ;
}
if ( it = = 4 )
ah + = 75 ;
}
2008-03-23 03:01:17 +02:00
if ( ! mode )
{
2008-05-18 20:33:39 +03:00
buy = new AdventureMapButton
( " " , " " , boost : : bind ( & CBuildWindow : : Buy , this ) , pos . x + 45 , pos . y + 446 , " IBUY30.DEF " , false , NULL , false ) ;
cancel = new AdventureMapButton
( " " , " " , boost : : bind ( & CBuildWindow : : close , this ) , pos . x + 290 , pos . y + 445 , " ICANCEL.DEF " , false , NULL , false ) ;
2008-04-04 20:30:53 +03:00
if ( state ! = 7 )
buy - > state = 2 ;
2008-03-23 03:01:17 +02:00
}
2008-03-21 02:03:31 +02:00
activate ( ) ;
2008-03-16 02:09:43 +02:00
}
CHallInterface : : CBuildWindow : : ~ CBuildWindow ( )
{
2008-03-21 02:03:31 +02:00
SDL_FreeSurface ( bitmap ) ;
2008-03-23 03:01:17 +02:00
if ( ! mode )
{
delete buy ;
delete cancel ;
}
2008-01-09 19:21:31 +02:00
}