2009-05-20 13:08:56 +03:00
# include "../stdafx.h"
2009-05-20 12:02:50 +03:00
# include "CCastleInterface.h"
2008-08-20 09:57:53 +03:00
# include "AdventureMapButton.h"
# include "CAdvmapInterface.h"
2010-11-15 17:15:00 +02:00
# include "CAnimation.h"
2009-05-20 13:08:56 +03:00
# include "../CCallback.h"
2008-01-09 19:21:31 +02:00
# include "CGameInfo.h"
2008-08-20 09:57:53 +03:00
# include "CHeroWindow.h"
# include "CMessage.h"
2008-01-09 19:21:31 +02:00
# include "SDL_Extensions.h"
2009-05-20 13:08:56 +03:00
# include "CCreatureAnimation.h"
# include "Graphics.h"
# include "../hch/CArtHandler.h"
# include "../hch/CBuildingHandler.h"
# include "../hch/CDefHandler.h"
# include "../hch/CGeneralTextHandler.h"
# include "../hch/CLodHandler.h"
# include "../hch/CObjectHandler.h"
# include "../hch/CSpellHandler.h"
# include "../hch/CTownHandler.h"
2010-07-01 09:05:00 +03:00
# include "../lib/map.h"
2008-08-16 11:47:41 +03:00
# include <boost/algorithm/string.hpp>
# include <boost/algorithm/string/replace.hpp>
2010-11-15 17:15:00 +02:00
# include <boost/assign/std/vector.hpp>
2009-04-09 18:05:20 +03:00
# include <boost/lexical_cast.hpp>
2008-08-17 17:09:30 +03:00
# include <cmath>
2008-08-20 09:57:53 +03:00
# include <sstream>
2010-05-26 12:47:53 +03:00
# include <boost/format.hpp>
2008-08-17 12:11:16 +03:00
using namespace boost : : assign ;
using namespace CSDL_Ext ;
2009-04-15 17:03:31 +03:00
/*
* CCastleInterface . cpp , part of VCMI engine
*
* Authors : listed in file AUTHORS in main folder
*
* License : GNU General Public License v2 .0 or later
* Full text of license available in license . txt file , in main folder
*
*/
2010-06-30 22:27:35 +03:00
int hordeToDwellingID ( int bid ) //helper, converts horde buiding ID into corresponding dwelling ID
{
const CGTownInstance * t = LOCPLINT - > castleInt - > town ;
switch ( bid )
{
case 18 : return t - > town - > hordeLvl [ 0 ] + 30 ;
case 19 : return t - > town - > hordeLvl [ 0 ] + 37 ;
case 24 : return t - > town - > hordeLvl [ 1 ] + 30 ;
case 25 : return t - > town - > hordeLvl [ 1 ] + 37 ;
default : return bid ;
}
}
2008-01-19 13:55:04 +02:00
CBuildingRect : : CBuildingRect ( Structure * Str )
2010-11-15 17:15:00 +02:00
: CShowableAnim ( 0 , 0 , Str - > defName , CShowableAnim : : FLAG_BASE ) ,
moi ( false ) , str ( Str )
2008-08-02 18:08:03 +03:00
{
2008-06-01 16:42:29 +03:00
2010-11-15 17:15:00 +02:00
pos . x + = str - > pos . x + LOCPLINT - > castleInt - > pos . x ;
pos . y + = str - > pos . y + LOCPLINT - > castleInt - > pos . y ;
if ( str - > ID = = 33 & & str - > townID = = 4 ) //little 'hack' for estate in necropolis - background color is not always the first color in the palette
for ( size_t i = 0 ; i < anim . groupSize ( 0 ) ; i + + )
SDL_SetColorKey ( anim . image ( i , 0 ) , SDL_SRCCOLORKEY ,
* ( ( char * ) ( anim . image ( i , 0 ) - > pixels ) ) ) ;
2008-06-01 16:42:29 +03:00
2008-02-02 02:41:00 +02:00
if ( Str - > ID < 0 | | ( Str - > ID > = 27 & & Str - > ID < = 29 ) )
{
area = border = NULL ;
return ;
}
2009-10-13 07:07:26 +03:00
2010-11-15 17:15:00 +02:00
border = BitmapHandler : : loadBitmap ( str - > borderName , true ) ;
if ( ! border )
2008-12-23 15:59:03 +02:00
{
2008-09-19 15:09:15 +03:00
tlog2 < < " Warning: no border for " < < Str - > ID < < std : : endl ;
2008-12-23 15:59:03 +02:00
}
2009-10-13 07:07:26 +03:00
2010-11-15 17:15:00 +02:00
area = BitmapHandler : : loadBitmap ( str - > areaName ) ;
if ( ! area )
2008-12-23 15:59:03 +02:00
{
2008-09-19 15:09:15 +03:00
tlog2 < < " Warning: no area for " < < Str - > ID < < std : : endl ;
2008-12-23 15:59:03 +02:00
}
2008-01-19 13:55:04 +02:00
}
CBuildingRect : : ~ CBuildingRect ( )
{
if ( border )
SDL_FreeSurface ( border ) ;
if ( area )
SDL_FreeSurface ( area ) ;
}
void CBuildingRect : : activate ( )
{
2009-08-11 19:05:33 +03:00
activateHover ( ) ;
activateLClick ( ) ;
activateRClick ( ) ;
2008-03-23 03:01:17 +02:00
2008-01-19 13:55:04 +02:00
}
void CBuildingRect : : deactivate ( )
{
2009-08-11 19:05:33 +03:00
deactivateHover ( ) ;
deactivateLClick ( ) ;
deactivateRClick ( ) ;
2008-03-23 03:01:17 +02:00
if ( moi )
2009-08-11 19:05:33 +03:00
deactivateMouseMove ( ) ;
2008-03-23 03:01:17 +02:00
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
{
2009-08-11 19:05:33 +03:00
//Hoverable::hover(on);
2008-01-24 00:15:33 +02:00
if ( on )
2008-01-20 18:24:03 +02:00
{
2008-03-23 03:01:17 +02:00
if ( ! moi )
2009-08-11 19:05:33 +03:00
activateMouseMove ( ) ;
2008-03-23 03:01:17 +02:00
moi = true ;
2008-01-24 00:15:33 +02:00
}
2008-08-02 18:08:03 +03:00
else
2008-01-24 00:15:33 +02:00
{
2008-03-23 03:01:17 +02:00
if ( moi )
2009-08-11 19:05:33 +03:00
deactivateMouseMove ( ) ;
2008-03-23 03:01:17 +02:00
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 ;
2010-02-15 08:54:57 +02:00
GH . statusbar - > clear ( ) ;
2009-05-30 19:00:26 +03:00
//call mouseMoved in other buildings, cursor might have been moved while they were inactive (eg. because of r-click popup)
for ( size_t i = 0 ; i < LOCPLINT - > castleInt - > buildings . size ( ) ; i + + )
2009-08-07 01:36:51 +03:00
LOCPLINT - > castleInt - > buildings [ i ] - > mouseMoved ( GH . current - > motion ) ;
2008-01-27 22:37:10 +02:00
}
2008-01-20 18:24:03 +02:00
}
2008-01-19 13:55:04 +02:00
}
2010-11-15 17:15:00 +02:00
2009-08-11 19:05:33 +03:00
void CBuildingRect : : clickLeft ( tribool down , bool previousState )
2008-01-19 13:55:04 +02:00
{
2010-11-15 17:15:00 +02:00
if ( previousState & & ! down & & area & & ( LOCPLINT - > castleInt - > hBuild = = this ) )
if ( ! CSDL_Ext : : isTransparent ( area , GH . current - > motion . x - pos . x , GH . current - > motion . y - pos . y ) ) //inside building image
2008-03-10 01:06:35 +02:00
LOCPLINT - > castleInt - > buildingClicked ( str - > ID ) ;
2008-01-19 13:55:04 +02:00
}
2010-11-15 17:15:00 +02:00
2009-08-11 19:05:33 +03:00
void CBuildingRect : : clickRight ( tribool down , bool previousState )
2008-01-19 13:55:04 +02:00
{
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 ;
2010-02-18 14:34:44 +02:00
if ( ! CSDL_Ext : : isTransparent ( area , GH . current - > motion . x - pos . x , GH . current - > motion . y - pos . y ) ) //inside building image
2008-03-06 20:54:35 +02:00
{
2010-06-30 22:27:35 +03:00
int bid = hordeToDwellingID ( str - > ID ) ;
2010-11-15 17:15:00 +02:00
2010-08-16 12:54:09 +03:00
CBuilding * bld = CGI - > buildh - > buildings [ str - > townID ] . find ( bid ) - > second ;
2009-05-22 02:50:45 +03:00
assert ( bld ) ;
2008-03-06 20:54:35 +02:00
CInfoPopup * vinya = new CInfoPopup ( ) ;
vinya - > free = true ;
vinya - > bitmap = CMessage : : drawBoxTextBitmapSub
( LOCPLINT - > playerID ,
2009-05-22 02:50:45 +03:00
bld - > Description ( ) ,
2010-06-30 22:27:35 +03:00
LOCPLINT - > castleInt - > bicons - > ourImages [ bid ] . bitmap ,
2009-05-22 02:50:45 +03:00
bld - > 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 ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( vinya ) ;
2008-03-06 20:54:35 +02:00
}
2008-01-19 13:55:04 +02:00
}
2010-06-30 22:27:35 +03:00
2010-11-15 17:15:00 +02:00
void CBuildingRect : : show ( SDL_Surface * to )
{
CShowableAnim : : show ( to ) ;
if ( LOCPLINT - > castleInt - > hBuild = = this & & border ) //if this this higlighted structure and has border we'll blit it
blitAtLoc ( border , 0 , 0 , to ) ;
}
void CBuildingRect : : showAll ( SDL_Surface * to )
{
show ( to ) ;
}
2010-06-30 22:27:35 +03:00
std : : string getBuildingSubtitle ( int tid , int bid ) //hover text for building
{
const CGTownInstance * t = LOCPLINT - > castleInt - > town ;
bid = hordeToDwellingID ( bid ) ;
2010-11-15 17:15:00 +02:00
2010-06-30 22:27:35 +03:00
if ( bid < 30 ) //non-dwellings - only buiding name
2010-08-16 12:54:09 +03:00
return CGI - > buildh - > buildings [ tid ] . find ( bid ) - > second - > Name ( ) ;
2010-06-30 22:27:35 +03:00
else //dwellings - recruit %creature%
{
int creaID = t - > creatures [ ( bid - 30 ) % CREATURES_PER_TOWN ] . second . back ( ) ; //taking last of available creatures
return CGI - > generaltexth - > allTexts [ 16 ] + " " + CGI - > creh - > creatures [ creaID ] - > namePl ;
}
}
2008-09-25 17:09:31 +03:00
void CBuildingRect : : mouseMoved ( const SDL_MouseMotionEvent & sEvent )
2008-01-24 00:15:33 +02:00
{
2009-05-30 19:00:26 +03:00
if ( area & & isItIn ( & pos , sEvent . x , sEvent . y ) )
2008-01-24 00:15:33 +02:00
{
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 ;
2010-02-15 08:54:57 +02:00
GH . statusbar - > clear ( ) ;
2008-01-27 22:37:10 +02:00
}
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
{
2010-11-15 17:15:00 +02:00
if ( ! LOCPLINT - > castleInt - > hBuild //no building hovered
| | ( * LOCPLINT - > castleInt - > hBuild ) < ( * this ) ) //or we are on top
2008-01-24 00:15:33 +02:00
{
LOCPLINT - > castleInt - > hBuild = this ;
2010-06-30 22:27:35 +03:00
GH . statusbar - > print ( getBuildingSubtitle ( str - > townID , str - > ID ) ) ;
2008-01-24 00:15:33 +02:00
}
}
}
}
2010-11-15 17:15:00 +02:00
2008-08-16 11:47:41 +03:00
void CHeroGSlot : : hover ( bool on )
{
2010-11-15 17:15:00 +02:00
if ( ! on )
2009-12-23 03:46:15 +02:00
{
2010-02-15 08:54:57 +02:00
GH . statusbar - > clear ( ) ;
2009-12-23 03:46:15 +02:00
return ;
}
2008-08-16 11:47:41 +03:00
CHeroGSlot * other = upg ? & owner - > hslotup : & owner - > hslotdown ;
std : : string temp ;
if ( hero )
{
if ( highlight ) //view NNN
{
2008-12-22 19:48:41 +02:00
temp = CGI - > generaltexth - > tcommands [ 4 ] ;
2008-08-16 11:47:41 +03:00
boost : : algorithm : : replace_first ( temp , " %s " , hero - > name ) ;
}
else if ( other - > hero & & other - > highlight ) //exchange
{
2008-12-22 19:48:41 +02:00
temp = CGI - > generaltexth - > tcommands [ 7 ] ;
2008-08-16 11:47:41 +03:00
boost : : algorithm : : replace_first ( temp , " %s " , hero - > name ) ;
boost : : algorithm : : replace_first ( temp , " %s " , other - > hero - > name ) ;
}
else // select NNN (in ZZZ)
{
if ( upg ) //down - visiting
{
2008-12-22 19:48:41 +02:00
temp = CGI - > generaltexth - > tcommands [ 32 ] ;
2008-08-16 11:47:41 +03:00
boost : : algorithm : : replace_first ( temp , " %s " , hero - > name ) ;
}
else //up - garrison
{
2008-12-22 19:48:41 +02:00
temp = CGI - > generaltexth - > tcommands [ 12 ] ;
2008-08-16 11:47:41 +03:00
boost : : algorithm : : replace_first ( temp , " %s " , hero - > name ) ;
}
}
}
else //we are empty slot
{
if ( other - > highlight & & other - > hero ) //move NNNN
{
2008-12-22 19:48:41 +02:00
temp = CGI - > generaltexth - > tcommands [ 6 ] ;
2008-08-16 11:47:41 +03:00
boost : : algorithm : : replace_first ( temp , " %s " , other - > hero - > name ) ;
}
else //empty
{
temp = CGI - > generaltexth - > allTexts [ 507 ] ;
}
}
if ( temp . size ( ) )
2010-02-15 08:54:57 +02:00
GH . statusbar - > print ( temp ) ;
2008-08-16 11:47:41 +03:00
}
2009-04-14 15:47:09 +03:00
2009-08-11 19:05:33 +03:00
void CHeroGSlot : : clickLeft ( tribool down , bool previousState )
2008-08-16 11:47:41 +03:00
{
2008-08-25 13:25:16 +03:00
CHeroGSlot * other = upg ? & owner - > hslotup : & owner - > hslotdown ;
2008-08-16 11:47:41 +03:00
if ( ! down )
{
2009-05-25 02:21:55 +03:00
owner - > garr - > splitting = false ;
owner - > garr - > highlighted = NULL ;
2009-09-09 09:04:42 +03:00
2008-08-16 11:47:41 +03:00
if ( hero & & highlight )
{
2009-09-09 09:04:42 +03:00
setHighlight ( false ) ;
2008-08-16 11:47:41 +03:00
LOCPLINT - > openHeroWindow ( hero ) ;
}
2008-08-25 13:25:16 +03:00
else if ( other - > hero & & other - > highlight )
{
2009-04-09 18:05:20 +03:00
bool allow = true ;
2009-10-23 06:07:03 +03:00
if ( upg ) //moving hero out of town - check if it is allowed
2009-04-09 18:05:20 +03:00
{
if ( ! hero & & LOCPLINT - > cb - > howManyHeroes ( false ) > = 8 )
{
std : : string tmp = CGI - > generaltexth - > allTexts [ 18 ] ; //You already have %d adventuring heroes under your command.
boost : : algorithm : : replace_first ( tmp , " %d " , boost : : lexical_cast < std : : string > ( LOCPLINT - > cb - > howManyHeroes ( false ) ) ) ;
2009-04-22 21:48:56 +03:00
LOCPLINT - > showInfoDialog ( tmp , std : : vector < SComponent * > ( ) , soundBase : : sound_todo ) ;
2009-04-09 18:05:20 +03:00
allow = false ;
}
2010-05-02 21:20:26 +03:00
else if ( ! other - > hero - > stacksCount ( ) ) //hero has no creatures - strange, but if we have appropriate error message...
2009-04-09 18:05:20 +03:00
{
2009-04-22 21:48:56 +03:00
LOCPLINT - > showInfoDialog ( CGI - > generaltexth - > allTexts [ 19 ] , std : : vector < SComponent * > ( ) , soundBase : : sound_todo ) ; //This hero has no creatures. A hero must have creatures before he can brave the dangers of the countryside.
2009-04-09 18:05:20 +03:00
allow = false ;
}
}
2009-09-09 09:04:42 +03:00
setHighlight ( false ) ;
other - > setHighlight ( false ) ;
2009-04-09 18:05:20 +03:00
if ( allow )
LOCPLINT - > cb - > swapGarrisonHero ( owner - > town ) ;
2008-08-25 13:25:16 +03:00
}
2008-08-16 11:47:41 +03:00
else if ( hero )
{
2009-09-09 09:04:42 +03:00
setHighlight ( true ) ;
2008-08-25 13:25:16 +03:00
owner - > garr - > highlighted = NULL ;
2009-04-14 17:19:46 +03:00
show ( screen2 ) ;
2008-08-16 11:47:41 +03:00
}
hover ( false ) ; hover ( true ) ; //refresh statusbar
}
2009-08-07 01:36:51 +03:00
//if(indeterminate(down) && !isItIn(&other->pos,GH.current->motion.x,GH.current->motion.y))
2009-06-13 02:34:02 +03:00
//{
// other->highlight = highlight = false;
// show(screen2);
//}
2008-08-16 11:47:41 +03:00
}
2009-04-14 15:47:09 +03:00
2008-08-16 11:47:41 +03:00
void CHeroGSlot : : deactivate ( )
{
2008-08-27 13:19:18 +03:00
highlight = false ;
2010-11-15 17:15:00 +02:00
CIntObject : : deactivate ( ) ;
2008-08-16 11:47:41 +03:00
}
2009-04-14 15:47:09 +03:00
void CHeroGSlot : : show ( SDL_Surface * to )
2008-08-16 11:47:41 +03:00
{
if ( hero ) //there is hero
2009-04-14 15:47:09 +03:00
blitAt ( graphics - > portraitLarge [ hero - > portrait ] , pos , to ) ;
2008-08-16 11:47:41 +03:00
else if ( ! upg ) //up garrison
2009-04-14 15:47:09 +03:00
blitAt ( graphics - > flags - > ourImages [ LOCPLINT - > castleInt - > town - > getOwner ( ) ] . bitmap , pos , to ) ;
2008-08-16 11:47:41 +03:00
if ( highlight )
2009-04-14 15:47:09 +03:00
blitAt ( graphics - > bigImgs [ - 1 ] , pos , to ) ;
2008-08-16 11:47:41 +03:00
}
2009-04-14 15:47:09 +03:00
2008-08-16 11:47:41 +03:00
CHeroGSlot : : CHeroGSlot ( int x , int y , int updown , const CGHeroInstance * h , CCastleInterface * Owner )
{
owner = Owner ;
pos . x = x ;
pos . y = y ;
pos . w = 58 ;
pos . h = 64 ;
hero = h ;
upg = updown ;
highlight = false ;
}
2009-04-14 15:47:09 +03:00
2008-08-16 11:47:41 +03:00
CHeroGSlot : : ~ CHeroGSlot ( )
{
}
2009-04-14 15:47:09 +03:00
2009-09-09 09:04:42 +03:00
void CHeroGSlot : : setHighlight ( bool on )
{
highlight = on ;
if ( owner - > hslotup . hero & & owner - > hslotdown . hero ) //two heroes in town
{
for ( size_t i = 0 ; i < owner - > garr - > splitButtons . size ( ) ; i + + ) //splitting enabled when slot higlighted
owner - > garr - > splitButtons [ i ] - > block ( ! on ) ;
}
}
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
2009-07-20 11:18:33 +03:00
CCastleInterface : : CCastleInterface ( const CGTownInstance * Town , int listPos )
2008-08-16 11:47:41 +03:00
: hslotup ( 241 , 387 , 0 , Town - > garrisonHero , this ) , hslotdown ( 241 , 483 , 1 , Town - > visitingHero , this )
2008-08-02 18:08:03 +03:00
{
2009-07-26 06:33:13 +03:00
showing = false ;
2009-04-14 15:47:09 +03:00
bars = CDefHandler : : giveDefEss ( " TPTHBAR.DEF " ) ;
status = CDefHandler : : giveDefEss ( " TPTHCHK.DEF " ) ;
2008-11-28 03:36:34 +02:00
LOCPLINT - > castleInt = this ;
2008-03-11 23:36:59 +02:00
hall = NULL ;
2009-12-23 03:46:15 +02:00
fort = NULL ;
market = NULL ;
2008-06-12 09:45:51 +03:00
townInt = BitmapHandler : : loadBitmap ( " TOWNSCRN.bmp " ) ;
2008-11-28 03:36:34 +02:00
pos . x = screen - > w / 2 - 400 ;
pos . y = screen - > h / 2 - 300 ;
hslotup . pos . x + = pos . x ;
hslotup . pos . y + = pos . y ;
hslotdown . pos . x + = pos . x ;
hslotdown . pos . y + = pos . y ;
2008-04-19 19:15:04 +03:00
hBuild = NULL ;
count = 0 ;
town = Town ;
2009-05-29 16:43:33 +03:00
animval = 0 ;
2010-02-28 12:01:36 +02:00
winMode = 1 ;
2008-04-19 19:15:04 +03:00
//garrison
2009-06-28 11:21:50 +03:00
garr = new CGarrisonInt ( pos . x + 305 , pos . y + 387 , 4 , Point ( 0 , 96 ) , townInt , Point ( 62 , 374 ) , town , town - > visitingHero ) ;
2008-04-19 19:15:04 +03:00
2008-11-28 03:36:34 +02:00
townlist = new CTownList ( 3 , pos . x + 744 , pos . y + 414 , " IAM014.DEF " , " IAM015.DEF " ) ; //744,526);
2008-05-18 20:33:39 +03:00
exit = new AdventureMapButton
2008-12-22 19:48:41 +02:00
( CGI - > generaltexth - > tcommands [ 8 ] , " " , boost : : bind ( & CCastleInterface : : close , this ) , pos . x + 744 , pos . y + 544 , " TSBTNS.DEF " , SDLK_RETURN ) ;
2009-07-20 11:18:33 +03:00
exit - > assignedKeys . insert ( SDLK_ESCAPE ) ;
2009-09-09 09:04:42 +03:00
split = new AdventureMapButton ( CGI - > generaltexth - > tcommands [ 3 ] , " " , boost : : bind ( & CGarrisonInt : : splitClick , garr ) , pos . x + 744 , pos . y + 382 , " TSBTNS.DEF " ) ;
split - > callback + = boost : : bind ( & CCastleInterface : : splitClicked , this ) ;
2010-08-27 19:20:35 +03:00
garr - > addSplitBtn ( split ) ;
2008-11-28 03:36:34 +02:00
statusbar = new CStatusBar ( pos . x + 7 , pos . y + 555 , " TSTATBAR.bmp " , 732 ) ;
2008-12-08 00:38:04 +02:00
resdatabar = new CResDataBar ( " ZRESBAR.bmp " , pos . x + 3 , pos . y + 575 , 32 , 2 , 85 , 85 ) ;
2008-01-31 23:35:30 +02:00
2008-05-18 20:33:39 +03:00
townlist - > fun = boost : : bind ( & CCastleInterface : : townChange , this ) ;
2010-02-26 13:18:09 +02:00
//townlist->genList();
townlist - > selected = vstd : : findPos ( LOCPLINT - > towns , Town ) ;
2009-07-20 11:18:33 +03:00
townlist - > from = townlist - > selected - listPos ;
amax ( townlist - > from , 0 ) ;
2010-02-26 13:18:09 +02:00
amin ( townlist - > from , LOCPLINT - > towns . size ( ) - townlist - > SIZE ) ;
2008-01-31 23:35:30 +02:00
2008-06-30 03:06:41 +03:00
graphics - > blueToPlayersAdv ( townInt , LOCPLINT - > playerID ) ;
2008-01-31 23:35:30 +02:00
exit - > bitmapOffset = 4 ;
2009-12-23 03:46:15 +02:00
//growth icons and buildings
2008-03-23 03:01:17 +02:00
recreateBuildings ( ) ;
2009-12-23 03:46:15 +02:00
recreateIcons ( ) ;
2010-08-18 17:24:30 +03:00
cityBg = BitmapHandler : : loadBitmap ( graphics - > townBgs [ town - > subID ] ) ;
bicons = CDefHandler : : giveDefEss ( graphics - > buildingPics [ town - > subID ] ) ;
CGI - > musich - > playMusic ( CGI - > musich - > townMusics [ town - > subID ] , - 1 ) ;
2008-01-09 19:21:31 +02:00
}
2009-04-14 15:47:09 +03:00
2008-01-09 19:21:31 +02:00
CCastleInterface : : ~ CCastleInterface ( )
{
2009-04-14 15:47:09 +03:00
delete bars ;
delete status ;
2008-01-09 19:21:31 +02:00
SDL_FreeSurface ( townInt ) ;
SDL_FreeSurface ( cityBg ) ;
delete exit ;
2009-09-11 08:45:40 +03:00
//delete split;
2008-01-09 19:21:31 +02:00
delete hall ;
delete fort ;
2009-12-23 03:46:15 +02:00
delete market ;
2008-01-26 23:50:51 +02:00
delete garr ;
2008-01-31 23:35:30 +02:00
delete townlist ;
delete statusbar ;
2008-12-08 00:38:04 +02:00
delete resdatabar ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < buildings . size ( ) ; i + + )
2008-01-15 23:38:01 +02:00
{
delete buildings [ i ] ;
}
2008-03-06 20:54:35 +02:00
delete bicons ;
2009-12-23 03:46:15 +02:00
for ( size_t i = 0 ; i < creainfo . size ( ) ; i + + )
{
delete creainfo [ i ] ;
}
2008-01-09 19:21:31 +02:00
}
2009-04-14 15:47:09 +03:00
2008-01-09 19:21:31 +02:00
void CCastleInterface : : close ( )
{
2010-10-31 21:56:37 +02:00
if ( town - > tempOwner = = LOCPLINT - > playerID ) //we may have opened window for an allied town
{
if ( town - > visitingHero )
adventureInt - > select ( town - > visitingHero ) ;
else
adventureInt - > select ( town ) ;
}
2009-04-14 15:47:09 +03:00
LOCPLINT - > castleInt = NULL ;
2009-08-07 01:36:51 +03:00
GH . popIntTotally ( this ) ;
2009-05-22 07:14:59 +03:00
CGI - > musich - > stopMusic ( 5000 ) ;
2008-01-09 19:21:31 +02:00
}
2009-04-14 15:47:09 +03:00
2008-01-30 00:47:43 +02:00
void CCastleInterface : : splitF ( )
{
}
2009-04-14 15:47:09 +03:00
2008-03-10 01:06:35 +02:00
void CCastleInterface : : buildingClicked ( int building )
{
2008-09-19 15:09:15 +03:00
tlog5 < < " You've clicked on " < < building < < std : : endl ;
2010-06-30 22:27:35 +03:00
building = hordeToDwellingID ( building ) ;
2010-02-24 15:03:36 +02:00
2010-08-16 12:54:09 +03:00
const CBuilding * b = CGI - > buildh - > buildings [ town - > subID ] . find ( building ) - > second ;
2010-05-26 12:47:53 +03:00
2008-04-04 20:30:53 +03:00
if ( building > = 30 )
{
2010-07-26 01:47:59 +03:00
showRecruitmentWindow ( ( building - 30 ) % CREATURES_PER_TOWN ) ;
2008-04-04 20:30:53 +03:00
}
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 )
{
2008-10-26 22:58:34 +02:00
case 0 : case 1 : case 2 : case 3 : case 4 : //mage guild
2008-08-20 09:57:53 +03:00
{
2009-06-13 02:34:02 +03:00
const CGHeroInstance * h = NULL ; //hero that "enters" mage guild
if ( ! town - > garrisonHero & & ! town - > visitingHero ) //no heroes in town
h = NULL ;
else if ( ! town - > garrisonHero ) //only visiting hero
h = town - > visitingHero ;
else if ( ! town - > visitingHero | | hslotup . highlight ) //only garrisoned hero OR both heroes present, garrisoned hero selected
h = town - > garrisonHero ;
else //both heroes present, use the visiting one
h = town - > visitingHero ;
if ( h & & ! vstd : : contains ( h - > artifWorn , ui16 ( 17 ) ) ) //hero doesn't have spellbok
2008-08-25 13:25:16 +03:00
{
if ( LOCPLINT - > cb - > getResourceAmount ( 6 ) < 500 ) //not enough gold to buy spellbook
{
2009-11-13 18:02:25 +02:00
LOCPLINT - > showInfoDialog ( CGI - > generaltexth - > allTexts [ 213 ] ) ;
2008-08-25 13:25:16 +03:00
}
else
{
2009-06-13 02:34:02 +03:00
CFunctionList < void ( ) > fl = boost : : bind ( & CCallback : : buyArtifact , LOCPLINT - > cb , h , 0 ) ;
2008-08-25 13:25:16 +03:00
fl + = boost : : bind ( & CCastleInterface : : enterMageGuild , this ) ;
std : : vector < SComponent * > vvv ( 1 , new SComponent ( SComponent : : artifact , 0 , 0 ) ) ;
2009-04-14 15:47:09 +03:00
LOCPLINT - > showYesNoDialog ( CGI - > generaltexth - > allTexts [ 214 ] , vvv , fl , 0 , true ) ;
2008-08-25 13:25:16 +03:00
}
}
else
2010-11-15 17:15:00 +02:00
{
2008-08-25 13:25:16 +03:00
enterMageGuild ( ) ;
}
2008-08-20 09:57:53 +03:00
break ;
}
2008-10-26 22:58:34 +02:00
case 5 : //tavern
{
2009-05-22 02:50:45 +03:00
enterTavern ( ) ;
2008-10-26 22:58:34 +02:00
break ;
}
2009-07-26 06:33:13 +03:00
case 6 : //shipyard
{
LOCPLINT - > showShipyardDialog ( town ) ;
break ;
}
2008-10-26 22:58:34 +02:00
case 7 : case 8 : case 9 : //fort/citadel/castle
2008-08-17 12:11:16 +03:00
{
2008-08-30 00:41:32 +03:00
CFortScreen * fs = new CFortScreen ( this ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( fs ) ;
2008-08-17 12:11:16 +03:00
break ;
}
2008-10-26 22:58:34 +02:00
case 10 : case 11 : case 12 : case 13 : //hall
2010-06-26 13:01:26 +03:00
if ( town - > visitingHero & & town - > visitingHero - > hasArt ( 2 ) & &
! vstd : : contains ( town - > builtBuildings , 26 ) ) //hero has grail, but town does not have it
2010-02-24 15:03:36 +02:00
{
if ( ! vstd : : contains ( town - > forbiddenBuildings , 26 ) )
{
LOCPLINT - > showYesNoDialog ( CGI - > generaltexth - > allTexts [ 597 ] , //Do you wish this to be the permanent home of the Grail?
2010-11-15 17:15:00 +02:00
std : : vector < SComponent * > ( ) ,
boost : : bind ( & CCallback : : buildBuilding , LOCPLINT - > cb , town , 26 ) ,
2010-02-24 15:03:36 +02:00
boost : : bind ( & CCastleInterface : : enterHall , this ) , true ) ;
}
else
{
LOCPLINT - > showInfoDialog ( CGI - > generaltexth - > allTexts [ 673 ] ) ;
( dynamic_cast < CInfoWindow * > ( GH . topInt ( ) ) ) - > buttons [ 0 ] - > callback + = boost : : bind ( & CCastleInterface : : enterHall , this ) ;
}
}
else
enterHall ( ) ;
2008-04-20 15:39:33 +03:00
break ;
2008-10-26 22:58:34 +02:00
case 14 : //marketplace
2008-09-07 06:38:37 +03:00
{
2010-05-26 12:47:53 +03:00
CMarketplaceWindow * cmw = new CMarketplaceWindow ( town , town - > visitingHero ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( cmw ) ;
2008-09-07 06:38:37 +03:00
break ;
}
2010-01-25 23:25:14 +02:00
//case 15: //resource silo - default handling only
2009-12-29 15:40:16 +02:00
2008-10-26 22:58:34 +02:00
case 16 : //blacksmith
2010-01-25 23:25:14 +02:00
enterBlacksmith ( town - > town - > warMachine ) ;
break ;
case 17 :
2008-08-27 13:19:18 +03:00
{
2010-01-25 23:25:14 +02:00
switch ( town - > subID )
2008-08-27 13:19:18 +03:00
{
2010-05-26 12:47:53 +03:00
/*Rampart*/ case 1 : //Mystic Pond
2010-01-25 23:25:14 +02:00
enterFountain ( building ) ;
break ;
2010-05-26 12:47:53 +03:00
/*Tower*/ case 2 : //Artifact Merchant
/*Dungeon*/ case 5 : //Artifact Merchant
/*Conflux*/ case 8 : //Artifact Merchant
2010-10-31 21:17:26 +02:00
if ( town - > visitingHero )
GH . pushInt ( new CMarketplaceWindow ( town , town - > visitingHero , RESOURCE_ARTIFACT ) ) ;
else
LOCPLINT - > showInfoDialog ( boost : : str ( boost : : format ( CGI - > generaltexth - > allTexts [ 273 ] ) % b - > Name ( ) ) ) ; //Only visiting heroes may use the %s.
2010-01-25 23:25:14 +02:00
break ;
default :
defaultBuildingClicked ( building ) ;
break ;
2008-08-27 13:19:18 +03:00
}
break ;
}
2010-01-25 23:25:14 +02:00
//case 18: //basic horde 1 - can't be selected
//case 19: //upg horde 1 - can't be selected
2009-07-26 06:33:13 +03:00
case 20 : //ship at shipyard
2009-11-13 18:02:25 +02:00
LOCPLINT - > showInfoDialog ( CGI - > generaltexth - > allTexts [ 51 ] ) ; //Cannot build another boat
2009-07-26 06:33:13 +03:00
break ;
2010-01-25 23:25:14 +02:00
case 21 : //special 2
{
switch ( town - > subID )
{
2010-05-26 12:47:53 +03:00
/*Rampart*/ case 1 : //Fountain of Fortune
2010-01-25 23:25:14 +02:00
enterFountain ( building ) ;
break ;
2010-05-26 12:47:53 +03:00
/*Stronghold*/ case 6 : //Freelancer's Guild
if ( town - > visitingHero )
GH . pushInt ( new CMarketplaceWindow ( town , town - > visitingHero , CREATURE_RESOURCE ) ) ;
else
LOCPLINT - > showInfoDialog ( boost : : str ( boost : : format ( CGI - > generaltexth - > allTexts [ 273 ] ) % b - > Name ( ) ) ) ; //Only visiting heroes may use the %s.
2010-01-25 23:25:14 +02:00
break ;
2010-05-26 12:47:53 +03:00
/*Conflux*/ case 8 : //Magic University
2010-07-20 17:08:13 +03:00
if ( town - > visitingHero )
GH . pushInt ( new CUniversityWindow ( town - > visitingHero , town ) ) ;
else if ( town - > garrisonHero )
GH . pushInt ( new CUniversityWindow ( town - > garrisonHero , town ) ) ;
else //no hero in town - default popup
defaultBuildingClicked ( building ) ;
2010-11-15 17:15:00 +02:00
2010-01-25 23:25:14 +02:00
break ;
default :
defaultBuildingClicked ( building ) ;
break ;
}
break ;
}
2009-05-22 02:50:45 +03:00
case 22 : //special 3
{
switch ( town - > subID )
{
2010-01-25 23:25:14 +02:00
/*Castle*/ case 0 : //brotherhood of sword
2009-05-22 02:50:45 +03:00
enterTavern ( ) ;
break ;
2010-01-25 23:25:14 +02:00
/*Inferno*/ case 3 : //Castle Gate
2010-06-26 13:01:26 +03:00
{
2010-07-27 02:20:21 +03:00
if ( ! town - > visitingHero )
{
LOCPLINT - > showInfoDialog ( CGI - > generaltexth - > allTexts [ 126 ] , std : : vector < SComponent * > ( ) , soundBase : : sound_todo ) ;
break ; //only visiting hero can use castle gates
}
2010-11-15 17:15:00 +02:00
2010-06-26 13:01:26 +03:00
std : : vector < int > availableTowns ;
std : : vector < const CGTownInstance * > Towns = LOCPLINT - > cb - > getTownsInfo ( false ) ;
for ( size_t i = 0 ; i < Towns . size ( ) ; i + + )
{
const CGTownInstance * t = Towns [ i ] ;
if ( t - > id ! = this - > town - > id & & t - > visitingHero = = NULL & & //another town, empty and this is
2010-06-30 22:27:35 +03:00
t - > subID = = 3 & & vstd : : contains ( t - > builtBuildings , 22 ) ) //inferno with castle gate
2010-06-26 13:01:26 +03:00
{
availableTowns . push_back ( t - > id ) ; //add to the list
}
}
2010-06-30 22:27:35 +03:00
CPicture * titlePic = new CPicture ( bicons - > ourImages [ building ] . bitmap , 0 , 0 , false ) ; //will be deleted by selection window
2010-06-26 13:01:26 +03:00
GH . pushInt ( new CObjectListWindow ( availableTowns , titlePic , CGI - > generaltexth - > jktexts [ 40 ] ,
CGI - > generaltexth - > jktexts [ 41 ] , boost : : bind ( & CCastleInterface : : castleTeleport , this , _1 ) ) ) ;
break ;
}
/*Necropolis*/ case 4 : //Skeleton Transformer
2010-07-03 15:00:53 +03:00
const CGHeroInstance * hero ;
if ( town - > visitingHero )
hero = town - > visitingHero ;
else if ( town - > garrisonHero )
hero = town - > garrisonHero ;
else
hero = NULL ; //no hero - will trade with town garrison
2010-11-15 17:15:00 +02:00
2010-07-03 15:00:53 +03:00
GH . pushInt ( new CTransformerWindow ( hero , town ) ) ;
break ;
2010-11-15 17:15:00 +02:00
2010-01-25 23:25:14 +02:00
/*Dungeon*/ case 5 : //Portal of Summoning
2010-07-10 19:50:23 +03:00
if ( town - > creatures [ CREATURES_PER_TOWN ] . second . empty ( ) )
2010-07-26 01:47:59 +03:00
//extra dwelling has no creatures in it
2010-07-10 19:50:23 +03:00
LOCPLINT - > showInfoDialog ( CGI - > generaltexth - > tcommands [ 30 ] , std : : vector < SComponent * > ( ) , soundBase : : sound_todo ) ;
2010-11-15 17:15:00 +02:00
else
2010-07-26 01:47:59 +03:00
this - > showRecruitmentWindow ( CREATURES_PER_TOWN ) ;
2010-01-25 23:25:14 +02:00
break ;
/*Stronghold*/ case 6 : //Ballista Yard
enterBlacksmith ( 4 ) ;
break ;
2009-05-22 02:50:45 +03:00
default :
2009-12-29 15:40:16 +02:00
defaultBuildingClicked ( building ) ;
2009-05-22 02:50:45 +03:00
break ;
}
break ;
}
2010-01-25 23:25:14 +02:00
//case 23: //special 4 - default handling only
//case 24: //basic horde 2 - can't be selected
//case 25: //upg horde 2 - can't be selected
//case 26: //grail - default handling only
2009-12-30 09:49:25 +02:00
default :
defaultBuildingClicked ( building ) ;
2009-12-29 15:40:16 +02:00
break ;
2008-04-20 15:39:33 +03:00
}
2008-03-10 01:06:35 +02:00
}
2009-12-30 09:49:25 +02:00
}
2010-06-26 13:01:26 +03:00
void CCastleInterface : : castleTeleport ( int where )
{
2010-07-06 05:10:26 +03:00
const CGTownInstance * dest = LOCPLINT - > cb - > getTownInfo ( where , 1 ) ;
2010-06-30 22:27:35 +03:00
LOCPLINT - > cb - > teleportHero ( town - > visitingHero , dest ) ;
2010-06-26 13:01:26 +03:00
}
2009-12-30 09:49:25 +02:00
void CCastleInterface : : defaultBuildingClicked ( int building )
{
std : : vector < SComponent * > comps ( 1 ,
2010-08-18 17:24:30 +03:00
new SComponent ( SComponent : : building , town - > subID , building , bicons - > ourImages [ building ] . bitmap , false ) ) ;
2009-12-29 15:40:16 +02:00
2009-12-30 09:49:25 +02:00
LOCPLINT - > showInfoDialog (
2010-08-16 12:54:09 +03:00
CGI - > buildh - > buildings [ town - > subID ] . find ( building ) - > second - > Description ( ) ,
2009-12-30 09:49:25 +02:00
comps , soundBase : : sound_todo ) ;
2008-03-10 01:06:35 +02:00
}
2009-04-14 15:47:09 +03:00
2010-01-25 23:25:14 +02:00
void CCastleInterface : : enterFountain ( int building )
{
std : : vector < SComponent * > comps ( 1 ,
2010-08-18 17:24:30 +03:00
new SComponent ( SComponent : : building , town - > subID , building , bicons - > ourImages [ building ] . bitmap , false ) ) ;
2010-01-25 23:25:14 +02:00
2010-08-16 12:54:09 +03:00
std : : string descr = CGI - > buildh - > buildings [ town - > subID ] . find ( building ) - > second - > Description ( ) ;
2010-01-25 23:25:14 +02:00
if ( building = = 21 ) //we need description for mystic pond as well
2010-08-16 12:54:09 +03:00
descr + = " \n \n " + CGI - > buildh - > buildings [ town - > subID ] . find ( 17 ) - > second - > Description ( ) ;
2010-01-28 18:15:46 +02:00
if ( town - > bonusValue . first = = 0 ) //fountain was builded this week
2010-01-25 23:25:14 +02:00
descr + = " \n \n " + CGI - > generaltexth - > allTexts [ 677 ] ;
2010-01-28 18:15:46 +02:00
else //fountain produced something;
2010-01-25 23:25:14 +02:00
{
descr + = " \n \n " + CGI - > generaltexth - > allTexts [ 678 ] ;
2010-01-28 18:15:46 +02:00
boost : : algorithm : : replace_first ( descr , " %s " , CGI - > generaltexth - > restypes [ town - > bonusValue . first ] ) ;
2010-01-25 23:25:14 +02:00
char buf [ 10 ] ;
2010-01-28 18:15:46 +02:00
SDL_itoa ( town - > bonusValue . second , buf , 10 ) ;
2010-01-25 23:25:14 +02:00
boost : : algorithm : : replace_first ( descr , " %d " , buf ) ;
2010-01-28 18:15:46 +02:00
}
2010-01-25 23:25:14 +02:00
LOCPLINT - > showInfoDialog ( descr , comps , soundBase : : sound_todo ) ;
}
void CCastleInterface : : enterBlacksmith ( int ArtifactID )
{
const CGHeroInstance * hero = town - > visitingHero ;
if ( ! hero )
{
std : : string pom = CGI - > generaltexth - > allTexts [ 273 ] ;
2010-08-16 12:54:09 +03:00
boost : : algorithm : : replace_first ( pom , " %s " , CGI - > buildh - > buildings [ town - > subID ] . find ( 16 ) - > second - > Name ( ) ) ;
2010-01-25 23:25:14 +02:00
LOCPLINT - > showInfoDialog ( pom , std : : vector < SComponent * > ( ) , soundBase : : sound_todo ) ;
return ;
}
2010-06-26 19:02:10 +03:00
int price = CGI - > arth - > artifacts [ ArtifactID ] - > price ;
2010-01-25 23:25:14 +02:00
bool possible = ( LOCPLINT - > cb - > getResourceAmount ( 6 ) > = price ) ;
if ( vstd : : contains ( hero - > artifWorn , ui16 ( ArtifactID + 9 ) ) ) //hero already has machine
possible = false ;
GH . pushInt ( new CBlacksmithDialog ( possible , CArtHandler : : convertMachineID ( ArtifactID , false ) , ArtifactID , hero - > id ) ) ;
}
2008-03-10 01:06:35 +02:00
void CCastleInterface : : enterHall ( )
{
2008-08-17 12:11:16 +03:00
CHallInterface * h = new CHallInterface ( this ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( h ) ;
2008-03-10 01:06:35 +02:00
}
2008-12-08 00:38:04 +02:00
2009-04-14 15:47:09 +03:00
void CCastleInterface : : showAll ( SDL_Surface * to /*=NULL*/ )
{
2008-11-28 03:36:34 +02:00
blitAt ( cityBg , pos , to ) ;
blitAt ( townInt , pos . x , pos . y + 374 , to ) ;
2010-02-20 15:24:38 +02:00
adventureInt - > resdatabar . draw ( to ) ;
2009-04-14 15:47:09 +03:00
townlist - > draw ( to ) ;
statusbar - > show ( to ) ;
resdatabar - > draw ( to ) ;
2008-01-09 19:21:31 +02:00
2009-04-14 15:47:09 +03:00
garr - > show ( to ) ;
2008-01-09 21:59:23 +02:00
//draw creatures icons and their growths
2009-12-23 03:46:15 +02:00
for ( size_t i = 0 ; i < creainfo . size ( ) ; i + + )
creainfo [ i ] - > show ( to ) ;
2008-01-09 21:59:23 +02:00
2009-12-23 03:46:15 +02:00
//print name
2010-02-28 12:01:36 +02:00
CSDL_Ext : : printAt ( town - > name , pos . x + 85 , pos . y + 387 , FONT_MEDIUM , zwykly , to ) ;
2008-01-12 13:32:40 +02:00
//blit town icon
2009-12-23 03:46:15 +02:00
int pom = town - > subID * 2 ;
2008-01-12 13:32:40 +02:00
if ( ! town - > hasFort ( ) )
pom + = F_NUMBER * 2 ;
if ( town - > builded > = MAX_BUILDING_PER_TURN )
pom + + ;
2008-11-28 03:36:34 +02:00
blitAt ( graphics - > bigTownPic - > ourImages [ pom ] . bitmap , pos . x + 15 , pos . y + 387 , to ) ;
2008-01-12 13:32:40 +02:00
2009-04-14 15:47:09 +03:00
hslotup . show ( to ) ;
hslotdown . show ( to ) ;
2009-12-23 03:46:15 +02:00
market - > show ( to ) ;
fort - > show ( to ) ;
hall - > show ( to ) ;
2009-04-14 15:47:09 +03:00
show ( to ) ;
2008-12-08 00:38:04 +02:00
2008-12-22 19:48:41 +02:00
if ( screen - > w ! = 800 | | screen - > h ! = 600 )
CMessage : : drawBorder ( LOCPLINT - > playerID , to , 828 , 628 , pos . x - 14 , pos . y - 15 ) ;
2009-04-14 15:47:09 +03:00
exit - > show ( to ) ;
2009-09-11 08:45:40 +03:00
//split->show(to);
2008-01-19 14:26:55 +02:00
}
2009-04-14 15:47:09 +03:00
2008-01-31 23:35:30 +02:00
void CCastleInterface : : townChange ( )
{
2010-02-26 13:18:09 +02:00
const CGTownInstance * nt = LOCPLINT - > towns [ townlist - > selected ] ;
2009-07-20 11:18:33 +03:00
int tpos = townlist - > selected - townlist - > from ;
2009-08-07 01:36:51 +03:00
GH . popIntTotally ( this ) ;
GH . pushInt ( new CCastleInterface ( nt , tpos ) ) ;
2008-01-31 23:35:30 +02:00
}
2009-04-14 15:47:09 +03:00
2008-01-19 14:26:55 +02:00
void CCastleInterface : : show ( SDL_Surface * to )
{
2008-11-28 03:36:34 +02:00
blitAt ( cityBg , pos , to ) ;
2008-01-20 18:24:03 +02:00
2008-01-19 14:26:55 +02:00
2008-01-15 23:38:01 +02:00
//blit buildings
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < buildings . size ( ) ; i + + )
2008-01-15 23:38:01 +02:00
{
2010-11-15 17:15:00 +02:00
buildings [ i ] - > showAll ( to ) ;
2008-01-15 23:38:01 +02:00
}
2009-12-23 03:46:15 +02:00
statusbar - > show ( to ) ; //refreshing statusbar
2008-01-09 19:21:31 +02:00
}
2009-04-14 15:47:09 +03: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 ( ) ;
2010-02-15 08:54:57 +02:00
GH . statusbar = statusbar ;
2008-01-26 21:36:31 +02:00
exit - > activate ( ) ;
2009-12-23 03:46:15 +02:00
fort - > activate ( ) ;
hall - > activate ( ) ;
market - > activate ( ) ;
2009-09-11 08:45:40 +03:00
//split->activate();
2008-12-23 15:59:03 +02:00
for ( size_t i = 0 ; i < buildings . size ( ) ; i + + ) //XXX pls use iterators or at() but not []
{
2008-01-20 18:24:03 +02:00
buildings [ i ] - > activate ( ) ;
2008-12-23 15:59:03 +02:00
}
2009-12-23 03:46:15 +02:00
for ( size_t i = 0 ; i < creainfo . size ( ) ; i + + )
creainfo [ i ] - > activate ( ) ;
2008-08-16 11:47:41 +03:00
hslotdown . activate ( ) ;
hslotup . activate ( ) ;
2009-08-11 19:05:33 +03:00
activateKeys ( ) ;
2008-01-09 19:21:31 +02:00
}
2009-04-14 15:47:09 +03:00
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 ( ) ;
2009-12-23 03:46:15 +02:00
fort - > deactivate ( ) ;
hall - > deactivate ( ) ;
market - > deactivate ( ) ;
2009-09-11 08:45:40 +03:00
//split->deactivate();
2008-12-23 15:59:03 +02:00
for ( size_t i = 0 ; i < buildings . size ( ) ; i + + ) //XXX iterators
{
2008-01-20 18:24:03 +02:00
buildings [ i ] - > deactivate ( ) ;
2008-12-23 15:59:03 +02:00
}
2009-12-23 03:46:15 +02:00
for ( size_t i = 0 ; i < creainfo . size ( ) ; i + + )
creainfo [ i ] - > deactivate ( ) ;
2008-08-16 11:47:41 +03:00
hslotdown . deactivate ( ) ;
hslotup . deactivate ( ) ;
2009-08-11 19:05:33 +03:00
deactivateKeys ( ) ;
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
2010-02-28 12:01:36 +02:00
if ( winMode = = 2 ) //we will only build buildings, no need to update interface - it will be closed in a moment
return ;
2008-08-01 21:13:33 +03:00
deactivate ( ) ;
2008-03-23 03:01:17 +02:00
recreateBuildings ( ) ;
2009-12-23 03:46:15 +02:00
recreateIcons ( ) ;
2008-08-01 21:13:33 +03:00
activate ( ) ;
2008-03-23 03:01:17 +02:00
}
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 ( ) ;
2009-12-23 03:46:15 +02:00
recreateIcons ( ) ;
2008-03-23 03:01:17 +02:00
}
void CCastleInterface : : recreateBuildings ( )
{
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < buildings . size ( ) ; i + + )
2008-03-23 03:01:17 +02:00
{
if ( showing )
buildings [ i ] - > deactivate ( ) ;
delete buildings [ i ] ;
}
buildings . clear ( ) ;
hBuild = NULL ;
std : : set < std : : pair < int , int > > s ; //group - id
2008-08-01 14:21:15 +03:00
for ( std : : set < si32 > : : const_iterator i = town - > builtBuildings . begin ( ) ; i ! = town - > builtBuildings . end ( ) ; i + + )
2008-03-23 03:01:17 +02:00
{
2010-08-16 12:54:09 +03:00
if ( town - > subID > = 0 & & town - > subID < CGI - > townh - > structures . size ( ) ) //we have info about structures in this town
2008-03-23 03:01:17 +02:00
{
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 )
{
2008-08-02 18:08:03 +03:00
obecny = seti ;
2008-03-23 03:01:17 +02:00
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
{
2008-12-21 21:17:35 +02:00
for ( size_t itpb = 0 ; itpb < buildings . size ( ) ; itpb + + )
2008-03-23 03:01:17 +02:00
{
if ( buildings [ itpb ] - > str - > ID = = obecny - > second )
{
delete buildings [ itpb ] ;
buildings . erase ( buildings . begin ( ) + itpb ) ;
2008-08-02 18:08:03 +03:00
* ( const_cast < int * > ( & ( obecny - > second ) ) ) = st - > ID ;
2008-03-23 03:01:17 +02:00
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 ;
}
2009-07-26 06:33:13 +03:00
//ship in shipyard
2009-09-20 15:47:40 +03:00
bool isThereShip = false ;
2009-07-26 06:33:13 +03:00
if ( vstd : : contains ( town - > builtBuildings , 6 ) )
{
std : : vector < const CGObjectInstance * > vobjs = LOCPLINT - > cb - > getVisitableObjs ( town - > bestLocation ( ) ) ;
2010-06-30 22:27:35 +03:00
if ( ! vobjs . empty ( ) & & ( vobjs . front ( ) - > ID = = 8 | | vobjs . front ( ) - > ID = = HEROI_TYPE ) ) //there is visitable obj at shipyard output tile and it's a boat or hero (on boat)
2009-07-26 06:33:13 +03:00
{
Structure * st = CGI - > townh - > structures [ town - > subID ] [ 20 ] ;
buildings . push_back ( new CBuildingRect ( st ) ) ;
s . insert ( std : : pair < int , int > ( st - > group , st - > ID ) ) ;
2010-11-15 17:15:00 +02:00
isThereShip = true ;
2009-07-26 06:33:13 +03:00
}
}
2008-04-04 20:30:53 +03:00
std : : sort ( buildings . begin ( ) , buildings . end ( ) , srthlp ) ;
2008-06-01 16:42:29 +03:00
//code for Mana Vortex (there are two sets of animation frames - one without mage guild and one with
2008-08-02 18:08:03 +03:00
if ( ( town - > subID = = 5 ) & & ( town - > builtBuildings . find ( 21 ) ! = town - > builtBuildings . end ( ) ) )
2008-06-01 16:42:29 +03:00
{
CBuildingRect * vortex = NULL ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < buildings . size ( ) ; i + + )
2008-06-01 16:42:29 +03:00
{
if ( buildings [ i ] - > str - > ID = = 21 )
{
vortex = buildings [ i ] ;
break ;
}
}
if ( town - > builtBuildings . find ( 4 ) ! = town - > builtBuildings . end ( ) ) //there is mage Guild level 5
{
2010-11-15 17:15:00 +02:00
vortex - > set ( 0 , 10 ) ;
2008-06-01 16:42:29 +03:00
}
else
{
2010-11-15 17:15:00 +02:00
vortex - > set ( 0 , 0 , 9 ) ;
2008-06-01 16:42:29 +03:00
}
}
2008-06-04 16:00:56 +03:00
//code for the shipyard in the Castle
2009-09-20 15:47:40 +03:00
else if ( town - > subID = = 0 )
2008-06-04 16:00:56 +03:00
{
2009-09-20 15:47:40 +03:00
int shipID = 0 ;
if ( isThereShip )
shipID = 20 ;
else if ( vstd : : contains ( town - > builtBuildings , 6 ) )
shipID = 6 ;
if ( shipID )
2008-06-04 16:00:56 +03:00
{
2009-09-20 15:47:40 +03:00
CBuildingRect * shipyard = NULL ;
for ( size_t i = 0 ; i < buildings . size ( ) ; i + + )
2008-06-04 16:00:56 +03:00
{
2009-09-20 15:47:40 +03:00
if ( buildings [ i ] - > str - > ID = = shipID )
{
shipyard = buildings [ i ] ;
break ;
}
}
if ( town - > builtBuildings . find ( 8 ) ! = town - > builtBuildings . end ( ) ) //there is citadel
{
2010-11-15 17:15:00 +02:00
shipyard - > set ( 0 , 1 ) ;
2009-09-20 15:47:40 +03:00
}
else
{
2010-11-15 17:15:00 +02:00
shipyard - > set ( 0 , 0 , 0 ) ;
2008-06-04 16:00:56 +03:00
}
}
}
2009-07-26 06:33:13 +03:00
if ( showing )
for ( size_t i = 0 ; i < buildings . size ( ) ; i + + )
buildings [ i ] - > activate ( ) ;
2008-04-11 20:41:02 +03:00
}
2008-08-17 12:11:16 +03:00
2009-12-23 03:46:15 +02:00
void CCastleInterface : : recreateIcons ( )
{
delete fort ;
delete hall ;
delete market ;
hall = new CTownInfo ( 0 ) ;
fort = new CTownInfo ( 1 ) ;
market = new CTownInfo ( 2 ) ;
for ( size_t i = 0 ; i < creainfo . size ( ) ; i + + )
{
if ( showing )
creainfo [ i ] - > deactivate ( ) ;
delete creainfo [ i ] ;
}
creainfo . clear ( ) ;
for ( size_t i = 0 ; i < CREATURES_PER_TOWN ; i + + )
{
int crid = - 1 ;
int bid = 30 + i ;
if ( town - > builtBuildings . find ( bid ) ! = town - > builtBuildings . end ( ) )
{
if ( town - > builtBuildings . find ( bid + CREATURES_PER_TOWN ) ! = town - > builtBuildings . end ( ) )
{
crid = town - > town - > upgradedCreatures [ i ] ;
bid + = CREATURES_PER_TOWN ;
}
else
crid = town - > town - > basicCreatures [ i ] ;
}
if ( crid > = 0 )
2010-07-10 19:50:23 +03:00
creainfo . push_back ( new CCreaInfo ( crid , ( bid - 30 ) % CREATURES_PER_TOWN ) ) ;
2009-12-23 03:46:15 +02:00
}
2010-07-10 19:50:23 +03:00
if ( town - > subID = = 5 & & vstd : : contains ( town - > builtBuildings , 22 ) & & //we have Portal of Summoning
! town - > creatures [ CREATURES_PER_TOWN ] . second . empty ( ) ) // with some creatures in it
creainfo . push_back ( new CCreaInfo ( town - > creatures [ CREATURES_PER_TOWN ] . second [ 0 ] , CREATURES_PER_TOWN ) ) ;
2009-12-23 03:46:15 +02:00
}
CCastleInterface : : CCreaInfo : : ~ CCreaInfo ( )
{
}
2010-07-10 19:50:23 +03:00
CCastleInterface : : CCreaInfo : : CCreaInfo ( int CRID , int LVL )
2009-12-23 03:46:15 +02:00
{
used = LCLICK | RCLICK | HOVER ;
CCastleInterface * ci = LOCPLINT - > castleInt ;
2010-07-10 19:50:23 +03:00
level = LVL ;
2009-12-23 03:46:15 +02:00
crid = CRID ;
2010-07-10 19:50:23 +03:00
pos . x = ci - > pos . x + 14 + ( 55 * ( level % 4 ) ) ;
pos . y = ( level > 3 ) ? ( 507 + ci - > pos . y ) : ( 459 + ci - > pos . y ) ;
2009-12-23 03:46:15 +02:00
pos . w = 48 ;
pos . h = 48 ;
}
void CCastleInterface : : CCreaInfo : : hover ( bool on )
{
if ( on )
{
std : : string descr = CGI - > generaltexth - > allTexts [ 588 ] ;
2010-05-02 21:20:26 +03:00
boost : : algorithm : : replace_first ( descr , " %s " , CGI - > creh - > creatures [ crid ] - > namePl ) ;
2010-02-15 08:54:57 +02:00
GH . statusbar - > print ( descr ) ;
2009-12-23 03:46:15 +02:00
}
else
2010-02-15 08:54:57 +02:00
GH . statusbar - > clear ( ) ;
2009-12-23 03:46:15 +02:00
}
2010-07-10 19:50:23 +03:00
2009-12-23 03:46:15 +02:00
void CCastleInterface : : CCreaInfo : : clickLeft ( tribool down , bool previousState )
{
2010-01-01 20:54:31 +02:00
if ( previousState & & ( ! down ) )
2010-07-26 01:47:59 +03:00
LOCPLINT - > castleInt - > showRecruitmentWindow ( level ) ;
2010-07-10 19:50:23 +03:00
}
2009-12-23 03:46:15 +02:00
2009-12-29 15:40:16 +02:00
int CCastleInterface : : CCreaInfo : : AddToString ( std : : string from , std : : string & to , int numb )
2009-12-23 03:46:15 +02:00
{
if ( ! numb )
return 0 ; //do not add string if 0
2010-10-02 10:10:38 +03:00
boost : : algorithm : : replace_first ( from , " %+d " , ( numb > 0 ? " + " : " " ) + boost : : lexical_cast < std : : string > ( numb ) ) ; //negative values don't need "+"
2009-12-23 03:46:15 +02:00
to + = " \n " + from ;
return numb ;
2010-07-10 19:50:23 +03:00
}
2009-12-23 03:46:15 +02:00
void CCastleInterface : : CCreaInfo : : clickRight ( tribool down , bool previousState )
{
if ( down )
{
CCastleInterface * ci = LOCPLINT - > castleInt ;
2010-09-25 23:23:55 +03:00
std : : set < si32 > bld = ci - > town - > builtBuildings ;
2010-10-18 18:08:59 +03:00
int summ = 0 ;
2009-12-23 03:46:15 +02:00
std : : string descr = CGI - > generaltexth - > allTexts [ 589 ] ; //Growth of creature is number
2010-05-02 21:20:26 +03:00
boost : : algorithm : : replace_first ( descr , " %s " , CGI - > creh - > creatures [ crid ] - > nameSing ) ;
2010-08-26 10:23:08 +03:00
boost : : algorithm : : replace_first ( descr , " %d " , boost : : lexical_cast < std : : string > ( ci - > town - > creatureGrowth ( level ) ) ) ;
2009-12-23 03:46:15 +02:00
descr + = " \n " + CGI - > generaltexth - > allTexts [ 590 ] ;
2010-05-02 21:20:26 +03:00
summ = CGI - > creh - > creatures [ crid ] - > growth ;
2009-12-23 03:46:15 +02:00
boost : : algorithm : : replace_first ( descr , " %d " , boost : : lexical_cast < std : : string > ( summ ) ) ;
2010-11-15 17:15:00 +02:00
2010-07-10 19:50:23 +03:00
if ( level > = 0 & & level < CREATURES_PER_TOWN )
{
2009-12-23 03:46:15 +02:00
2010-07-10 19:50:23 +03:00
if ( bld . find ( 9 ) ! = bld . end ( ) ) //castle +100% to basic
summ + = AddToString ( CGI - > buildh - > buildings [ ci - > town - > subID ] [ 9 ] - > Name ( ) + " %+d " , descr , summ ) ;
else if ( bld . find ( 8 ) ! = bld . end ( ) ) //else if citadel+50% to basic
summ + = AddToString ( CGI - > buildh - > buildings [ ci - > town - > subID ] [ 8 ] - > Name ( ) + " %+d " , descr , summ / 2 ) ;
2009-12-23 03:46:15 +02:00
2010-10-02 10:10:38 +03:00
summ + = AddToString ( CGI - > generaltexth - > allTexts [ 63 ] + " %+d " , descr , //double growth or plague
2010-08-26 10:23:08 +03:00
summ * CGI - > creh - > creatures [ crid ] - > valOfBonuses ( Bonus : : CREATURE_GROWTH_PERCENT ) / 100 ) ;
2010-09-25 23:23:55 +03:00
summ + = AddToString ( CGI - > generaltexth - > artifNames [ 133 ] + " %+d " , descr ,
2010-10-02 12:43:22 +03:00
summ * ci - > town - > valOfGlobalBonuses
2010-11-15 17:15:00 +02:00
( Selector : : type ( Bonus : : CREATURE_GROWTH_PERCENT ) & & Selector : : sourceType ( Bonus : : ARTIFACT ) ) / 100 ) ; //Statue of Legion
2010-09-25 23:23:55 +03:00
2010-07-10 19:50:23 +03:00
if ( ci - > town - > town - > hordeLvl [ 0 ] = = level ) //horde, x to summ
if ( ( bld . find ( 18 ) ! = bld . end ( ) ) | | ( bld . find ( 19 ) ! = bld . end ( ) ) )
summ + = AddToString ( CGI - > buildh - > buildings [ ci - > town - > subID ] [ 18 ] - > Name ( ) + " %+d " , descr ,
CGI - > creh - > creatures [ crid ] - > hordeGrowth ) ;
2009-12-23 03:46:15 +02:00
2010-07-10 19:50:23 +03:00
if ( ci - > town - > town - > hordeLvl [ 1 ] = = level ) //horde, x to summ
if ( ( bld . find ( 24 ) ! = bld . end ( ) ) | | ( bld . find ( 25 ) ! = bld . end ( ) ) )
summ + = AddToString ( CGI - > buildh - > buildings [ ci - > town - > subID ] [ 24 ] - > Name ( ) + " %+d " , descr ,
CGI - > creh - > creatures [ crid ] - > hordeGrowth ) ;
2009-12-23 03:46:15 +02:00
2010-10-18 18:08:59 +03:00
int cnt = 0 ;
2010-02-13 17:56:34 +02:00
2010-08-16 12:54:09 +03:00
std : : vector < const CGDwelling * > myDwellings = LOCPLINT - > cb - > getMyDwellings ( ) ;
for ( std : : vector < const CGDwelling * > : : const_iterator it = myDwellings . begin ( ) ; it ! = myDwellings . end ( ) ; + + it )
if ( CGI - > creh - > creatures [ ci - > town - > town - > basicCreatures [ level ] ] - > idNumber = = ( * it ) - > creatures [ 0 ] . second [ 0 ] )
cnt + + ; //external dwellings count to summ
2010-07-10 19:50:23 +03:00
summ + = AddToString ( CGI - > generaltexth - > allTexts [ 591 ] , descr , cnt ) ;
2009-12-23 03:46:15 +02:00
2010-07-10 19:50:23 +03:00
const CGHeroInstance * ch = ci - > town - > garrisonHero ;
2010-09-26 08:21:09 +03:00
BonusList bl ;
2010-07-10 19:50:23 +03:00
for ( cnt = 0 ; cnt < 2 ; cnt + + ) // "loop" to avoid copy-pasting code
2009-12-23 03:46:15 +02:00
{
2010-07-10 19:50:23 +03:00
if ( ch )
{
2010-09-26 08:21:09 +03:00
ch - > getBonuses ( bl , Selector : : type ( Bonus : : CREATURE_GROWTH ) & & Selector : : subtype ( level ) & & Selector : : sourceType ( Bonus : : ARTIFACT ) , ch ) ;
2010-07-10 19:50:23 +03:00
} ;
ch = ci - > town - > visitingHero ;
2009-12-23 03:46:15 +02:00
} ;
2010-09-26 08:21:09 +03:00
if ( bl . size ( ) )
summ + = AddToString ( CGI - > arth - > artifacts [ bl . front ( ) . id ] - > Name ( ) + " %+d " , descr , bl . totalValue ( ) ) ;
2010-11-15 17:15:00 +02:00
2010-08-26 10:23:08 +03:00
//TODO: player bonuses
2010-02-10 04:56:00 +02:00
2010-07-10 19:50:23 +03:00
if ( bld . find ( 26 ) ! = bld . end ( ) ) //grail - +50% to ALL growth
summ + = AddToString ( CGI - > buildh - > buildings [ ci - > town - > subID ] [ 26 ] - > Name ( ) + " %+d " , descr , summ / 2 ) ;
2010-08-26 10:23:08 +03:00
summ + = AddToString ( CGI - > generaltexth - > allTexts [ 63 ] + " %+d " , descr , CGI - > creh - > creatures [ crid ] - > valOfBonuses ( Bonus : : CREATURE_GROWTH ) ) ;
2010-07-10 19:50:23 +03:00
}
2009-12-23 03:46:15 +02:00
CInfoPopup * mess = new CInfoPopup ( ) ; //creating popup
mess - > free = true ;
mess - > bitmap = CMessage : : drawBoxTextBitmapSub
( LOCPLINT - > playerID , descr , graphics - > bigImgs [ crid ] , " " ) ;
mess - > pos . x = screen - > w / 2 - mess - > bitmap - > w / 2 ;
mess - > pos . y = screen - > h / 2 - mess - > bitmap - > h / 2 ;
GH . pushInt ( mess ) ;
}
}
2010-06-30 22:27:35 +03:00
2009-12-23 03:46:15 +02:00
void CCastleInterface : : CCreaInfo : : show ( SDL_Surface * to )
{
blitAt ( graphics - > smallImgs [ crid ] , pos . x + 8 , pos . y , to ) ;
std : : ostringstream oss ;
2010-07-10 19:50:23 +03:00
oss < < ' + ' < < LOCPLINT - > castleInt - > town - > creatureGrowth ( level ) ;
2010-06-30 22:27:35 +03:00
CSDL_Ext : : printAtMiddle ( oss . str ( ) , pos . x + 24 , pos . y + 40 , FONT_SMALL , zwykly , to ) ;
2009-12-23 03:46:15 +02:00
}
CCastleInterface : : CTownInfo : : ~ CTownInfo ( )
{
delete pic ;
}
2010-06-30 22:27:35 +03:00
2009-12-23 03:46:15 +02:00
CCastleInterface : : CTownInfo : : CTownInfo ( int BID )
{
used = LCLICK | RCLICK | HOVER ;
CCastleInterface * ci = LOCPLINT - > castleInt ;
switch ( BID )
{
case 0 : //hall
bid = 10 + ci - > town - > hallLevel ( ) ;
pos . x = ci - > pos . x + 80 ; pos . y = ci - > pos . y + 413 ; pos . w = 40 ; pos . h = 40 ;
pic = CDefHandler : : giveDef ( " ITMTL.DEF " ) ;
break ;
case 1 : //fort
bid = 6 + ci - > town - > fortLevel ( ) ;
pos . x = ci - > pos . x + 122 ; pos . y = ci - > pos . y + 413 ; pos . w = 40 ; pos . h = 40 ;
pic = CDefHandler : : giveDef ( " ITMCL.DEF " ) ;
break ;
case 2 : pos . x = ci - > pos . x + 164 ; pos . y = ci - > pos . y + 409 ; pos . w = 64 ; pos . h = 44 ;
pic = NULL ;
bid = 14 ;
break ;
}
}
void CCastleInterface : : CTownInfo : : hover ( bool on )
{
if ( on )
{
std : : string descr ;
if ( bid = = 6 ) { } //empty "no fort" icon. no hover message
2010-11-15 17:15:00 +02:00
else
2009-12-23 03:46:15 +02:00
if ( bid = = 14 ) //marketplace/income icon
descr = CGI - > generaltexth - > allTexts [ 255 ] ;
else
descr = CGI - > buildh - > buildings [ LOCPLINT - > castleInt - > town - > subID ] [ bid ] - > Name ( ) ;
2010-02-15 08:54:57 +02:00
GH . statusbar - > print ( descr ) ;
2009-12-23 03:46:15 +02:00
}
else
2010-02-15 08:54:57 +02:00
GH . statusbar - > clear ( ) ;
2009-12-23 03:46:15 +02:00
}
2010-06-30 22:27:35 +03:00
2009-12-23 03:46:15 +02:00
void CCastleInterface : : CTownInfo : : clickLeft ( tribool down , bool previousState )
{
2010-01-01 20:54:31 +02:00
if ( previousState & & ( ! down ) )
2009-12-23 03:46:15 +02:00
if ( LOCPLINT - > castleInt - > town - > builtBuildings . find ( bid ) ! = LOCPLINT - > castleInt - > town - > builtBuildings . end ( ) )
LOCPLINT - > castleInt - > buildingClicked ( bid ) ; //activate building
}
2010-06-30 22:27:35 +03:00
2009-12-23 03:46:15 +02:00
void CCastleInterface : : CTownInfo : : clickRight ( tribool down , bool previousState )
{
if ( down )
2010-11-15 17:15:00 +02:00
{
2009-12-23 03:46:15 +02:00
if ( ( bid = = 6 ) | | ( bid = = 14 ) )
return ;
CInfoPopup * mess = new CInfoPopup ( ) ;
mess - > free = true ;
CCastleInterface * ci = LOCPLINT - > castleInt ;
CBuilding * bld = CGI - > buildh - > buildings [ ci - > town - > subID ] [ bid ] ;
mess - > bitmap = CMessage : : drawBoxTextBitmapSub
( LOCPLINT - > playerID , bld - > Description ( ) ,
LOCPLINT - > castleInt - > bicons - > ourImages [ bid ] . bitmap ,
bld - > Name ( ) ) ;
mess - > pos . x = screen - > w / 2 - mess - > bitmap - > w / 2 ;
mess - > pos . y = screen - > h / 2 - mess - > bitmap - > h / 2 ;
GH . pushInt ( mess ) ;
}
}
2010-06-30 22:27:35 +03:00
2009-12-23 03:46:15 +02:00
void CCastleInterface : : CTownInfo : : show ( SDL_Surface * to )
{
if ( bid = = 14 ) //marketplace/income
{
std : : ostringstream oss ;
oss < < LOCPLINT - > castleInt - > town - > dailyIncome ( ) ;
2010-06-30 22:27:35 +03:00
CSDL_Ext : : printAtMiddle ( oss . str ( ) , pos . x + 33 , pos . y + 34 , FONT_SMALL , zwykly , to ) ;
2009-12-23 03:46:15 +02:00
}
else if ( bid = = 6 ) //no fort
blitAt ( pic - > ourImages [ 3 ] . bitmap , pos . x , pos . y , to ) ;
else if ( bid < 10 ) //fort-castle
blitAt ( pic - > ourImages [ bid - 7 ] . bitmap , pos . x , pos . y , to ) ;
else //town halls
blitAt ( pic - > ourImages [ bid - 10 ] . bitmap , pos . x , pos . y , to ) ;
}
2010-07-26 01:47:59 +03:00
void CCastleInterface : : showRecruitmentWindow ( int level )
2008-03-10 01:06:35 +02:00
{
2010-07-10 19:50:23 +03:00
assert ( level > = 0 & & level < town - > creatures . size ( ) ) ;
2009-07-06 22:41:27 +03:00
2010-07-10 19:50:23 +03:00
CRecruitmentWindow * rw = new CRecruitmentWindow ( town , level , town , boost : : bind ( & CCallback : : recruitCreatures , LOCPLINT - > cb , town , _1 , _2 , level ) , - 87 ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( rw ) ;
2008-08-17 12:11:16 +03:00
}
2008-08-25 13:25:16 +03:00
void CCastleInterface : : enterMageGuild ( )
{
2009-08-07 01:36:51 +03:00
GH . pushInt ( new CMageGuildScreen ( this ) ) ;
2008-08-25 13:25:16 +03:00
}
2009-05-22 02:50:45 +03:00
void CCastleInterface : : enterTavern ( )
{
2010-07-09 02:03:27 +03:00
LOCPLINT - > showTavernWindow ( town ) ;
2009-05-22 02:50:45 +03:00
}
2009-07-20 11:18:33 +03:00
void CCastleInterface : : keyPressed ( const SDL_KeyboardEvent & key )
{
2009-09-07 05:29:44 +03:00
if ( key . state ! = SDL_PRESSED ) return ;
2009-07-20 11:18:33 +03:00
switch ( key . keysym . sym )
{
case SDLK_UP :
if ( townlist - > selected )
{
townlist - > selected - - ;
townlist - > from - - ;
townChange ( ) ;
}
break ;
case SDLK_DOWN :
2010-02-26 13:18:09 +02:00
if ( townlist - > selected < LOCPLINT - > towns . size ( ) - 1 )
2009-07-20 11:18:33 +03:00
{
townlist - > selected + + ;
townlist - > from + + ;
townChange ( ) ;
}
break ;
case SDLK_SPACE :
if ( town - > visitingHero & & town - > garrisonHero )
{
LOCPLINT - > cb - > swapGarrisonHero ( town ) ;
}
break ;
2009-10-13 07:07:26 +03:00
default :
break ;
2009-07-20 11:18:33 +03:00
}
}
2009-09-09 09:04:42 +03:00
void CCastleInterface : : splitClicked ( )
{
if ( town - > visitingHero & & town - > garrisonHero & & ( hslotdown . highlight | | hslotup . highlight ) )
{
LOCPLINT - > heroExchangeStarted ( town - > visitingHero - > id , town - > garrisonHero - > id ) ;
}
}
2008-03-10 01:06:35 +02:00
void CHallInterface : : CBuildingBox : : hover ( bool on )
{
2009-08-11 19:05:33 +03:00
//Hoverable::hover(on);
2008-03-16 02:09:43 +02:00
if ( on )
{
2008-06-03 21:16:54 +03:00
std : : string toPrint ;
if ( state = = 8 )
2008-12-22 19:48:41 +02:00
toPrint = CGI - > generaltexth - > hcommands [ 5 ] ;
2009-12-23 03:46:15 +02:00
else if ( state = = 5 ) //"already builded today" message
toPrint = CGI - > generaltexth - > allTexts [ 223 ] ;
2008-06-03 21:16:54 +03:00
else
2008-12-22 19:48:41 +02:00
toPrint = CGI - > generaltexth - > hcommands [ state ] ;
2008-03-16 02:09:43 +02:00
std : : vector < std : : string > name ;
2008-12-22 19:48:41 +02:00
name . push_back ( CGI - > buildh - > buildings [ LOCPLINT - > castleInt - > town - > subID ] [ BID ] - > Name ( ) ) ;
2010-02-15 08:54:57 +02:00
GH . statusbar - > print ( CSDL_Ext : : processStr ( toPrint , name ) ) ;
2008-03-16 02:09:43 +02:00
}
else
2010-02-15 08:54:57 +02:00
GH . statusbar - > clear ( ) ;
2008-03-10 01:06:35 +02:00
}
2009-08-11 19:05:33 +03:00
void CHallInterface : : CBuildingBox : : clickLeft ( tribool down , bool previousState )
2008-03-10 01:06:35 +02:00
{
2009-08-11 19:05:33 +03:00
if ( previousState & & ( ! down ) )
2008-03-21 02:03:31 +02:00
{
2009-08-07 01:36:51 +03:00
GH . pushInt ( new CHallInterface : : CBuildWindow ( LOCPLINT - > castleInt - > town - > subID , BID , state , 0 ) ) ;
2008-03-21 02:03:31 +02:00
}
2009-08-11 19:05:33 +03:00
//ClickableL::clickLeft(down);
2008-03-10 01:06:35 +02:00
}
2009-08-11 19:05:33 +03:00
void CHallInterface : : CBuildingBox : : clickRight ( tribool down , bool previousState )
2008-03-10 01:06:35 +02:00
{
2008-03-21 02:03:31 +02:00
if ( down )
{
2009-08-07 01:36:51 +03:00
GH . pushInt ( new CHallInterface : : CBuildWindow ( LOCPLINT - > castleInt - > town - > subID , BID , state , 1 ) ) ;
2008-03-21 02:03:31 +02:00
}
2009-08-11 19:05:33 +03:00
//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 )
{
2009-04-14 15:47:09 +03:00
CCastleInterface * ci = LOCPLINT - > castleInt ;
2010-01-01 20:54:31 +02:00
if ( ( ( BID = = 18 ) & & ( vstd : : contains ( ci - > town - > builtBuildings , ( ci - > town - > town - > hordeLvl [ 0 ] + 37 ) ) ) )
| | ( ( BID = = 24 ) & & ( vstd : : contains ( ci - > town - > builtBuildings , ( ci - > town - > town - > hordeLvl [ 1 ] + 37 ) ) ) ) )
2010-11-15 17:15:00 +02:00
blitAt ( ci - > bicons - > ourImages [ BID + 1 ] . bitmap , pos . x , pos . y , to ) ;
2010-01-01 20:54:31 +02:00
else
blitAt ( ci - > bicons - > ourImages [ BID ] . bitmap , pos . x , pos . y , to ) ;
2008-03-16 02:09:43 +02:00
int pom , pom2 = - 1 ;
2008-03-11 23:36:59 +02:00
switch ( state )
{
2008-08-02 18:08:03 +03: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 ;
2009-07-11 02:40:10 +03:00
case 5 : case 8 :
2008-03-16 02:09:43 +02:00
pom2 = 1 ;
pom = 2 ;
break ;
2009-07-11 02:40:10 +03:00
case 0 : 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
}
2009-04-14 15:47:09 +03:00
blitAt ( ci - > bars - > ourImages [ pom ] . bitmap , pos . x - 1 , pos . y + 71 , to ) ;
2008-03-16 02:09:43 +02:00
if ( pom2 > = 0 )
2009-04-14 15:47:09 +03:00
blitAt ( ci - > status - > ourImages [ pom2 ] . bitmap , pos . x + 135 , pos . y + 54 , to ) ;
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAtMiddle ( CGI - > buildh - > buildings [ ci - > town - > subID ] [ BID ] - > Name ( ) , pos . x - 1 + ci - > bars - > ourImages [ 0 ] . bitmap - > w / 2 , pos . y + 71 + ci - > bars - > ourImages [ 0 ] . bitmap - > h / 2 , FONT_SMALL , zwykly , to ) ;
2008-03-11 23:36:59 +02:00
}
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
{
2010-01-01 20:54:31 +02:00
used = LCLICK | RCLICK | HOVER ;
2008-03-11 23:36:59 +02:00
pos . w = 150 ;
2009-12-29 15:40:16 +02:00
pos . h = 88 ;
2008-03-11 23:36:59 +02:00
}
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
{
2010-01-01 20:54:31 +02:00
used = LCLICK | RCLICK | HOVER ;
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 ;
2009-12-29 15:40:16 +02:00
pos . h = 88 ;
2008-03-11 23:36:59 +02:00
}
2008-03-10 01:06:35 +02:00
CHallInterface : : CHallInterface ( CCastleInterface * owner )
{
2009-05-20 12:02:50 +03:00
resdatabar = new CMinorResDataBar ;
2008-11-28 03:36:34 +02:00
pos = owner - > pos ;
2009-05-20 12:02:50 +03:00
resdatabar - > pos . x + = pos . x ;
resdatabar - > pos . y + = pos . y ;
2009-12-23 03:46:15 +02:00
LOCPLINT - > castleInt - > statusbar - > clear ( ) ;
2009-12-30 09:49:25 +02:00
bg = BitmapHandler : : loadBitmap ( CGI - > buildh - > hall [ owner - > town - > subID ] . first ) ;
2009-12-29 15:40:16 +02:00
bid = owner - > town - > hallLevel ( ) + 10 ;
2008-06-30 03:06:41 +03:00
graphics - > blueToPlayersAdv ( bg , LOCPLINT - > playerID ) ;
2008-05-18 20:33:39 +03:00
exit = new AdventureMapButton
2009-12-23 03:46:15 +02:00
( CGI - > generaltexth - > hcommands [ 8 ] , " " , boost : : bind ( & CHallInterface : : close , this ) , pos . x + 748 , pos . y + 556 , " TPMAGE1.DEF " , SDLK_RETURN ) ;
2008-11-28 03:36:34 +02:00
exit - > assignedKeys . insert ( SDLK_ESCAPE ) ;
2008-03-21 02:03:31 +02:00
//preparing boxes with buildings//
2008-03-16 02:09:43 +02:00
boxes . resize ( 5 ) ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < 5 ; i + + ) //for each row
2008-03-11 23:36:59 +02:00
{
2009-03-12 20:50:36 +02:00
std : : vector < std : : vector < std : : vector < int > > > & boxList = CGI - > buildh - > hall [ owner - > town - > subID ] . second ;
for ( size_t j = 0 ; j < boxList [ i ] . size ( ) ; j + + ) //for each box
2008-03-11 23:36:59 +02:00
{
2008-12-21 21:17:35 +02:00
size_t k = 0 ;
2010-06-30 22:27:35 +03:00
2009-03-12 20:50:36 +02:00
for ( ; k < boxList [ i ] [ j ] . size ( ) ; k + + ) //we are looking for the first not build structure
2008-03-11 23:36:59 +02:00
{
2009-03-12 20:50:36 +02:00
int bid = boxList [ i ] [ j ] [ k ] ;
2010-06-30 22:27:35 +03:00
//if building not build or this is unupgraded horde
if ( ! vstd : : contains ( owner - > town - > builtBuildings , bid ) | | bid = = 18 | | bid = = 24 )
2008-03-11 23:36:59 +02:00
{
int x = 34 + 194 * j ,
2008-03-16 02:09:43 +02:00
y = 37 + 104 * i ,
2009-03-12 20:50:36 +02:00
ID = bid ;
2010-06-30 22:27:35 +03:00
if ( ( bid = = 18 & & vstd : : contains ( owner - > town - > builtBuildings , owner - > town - > town - > hordeLvl [ 0 ] + 37 ) )
| | ( bid = = 24 & & vstd : : contains ( owner - > town - > builtBuildings , owner - > town - > town - > hordeLvl [ 1 ] + 37 ) ) )
continue ; //we have upgraded dwelling, horde description should be for upgraded creatures
2009-03-12 20:50:36 +02:00
if ( boxList [ i ] . size ( ) = = 2 ) //only two boxes in this row
2008-03-11 23:36:59 +02:00
x + = 194 ;
2009-03-12 20:50:36 +02:00
else if ( boxList [ i ] . size ( ) = = 3 ) //only three boxes in this row
2008-03-11 23:36:59 +02:00
x + = 97 ;
2009-03-12 20:50:36 +02:00
boxes [ i ] . push_back ( new CBuildingBox ( bid , pos . x + x , pos . y + y ) ) ;
2010-06-30 22:27:35 +03:00
boxes [ i ] . back ( ) - > state = LOCPLINT - > cb - > canBuildStructure ( owner - > town , ID ) ;
2008-03-11 23:36:59 +02:00
break ;
}
}
2009-03-12 20:50:36 +02:00
if ( k = = boxList [ i ] [ j ] . size ( ) ) //all buildings built - let's take the last one
2008-03-11 23:36:59 +02:00
{
int x = 34 + 194 * j ,
y = 37 + 104 * i ;
2009-03-12 20:50:36 +02:00
if ( boxList [ i ] . size ( ) = = 2 )
2008-03-11 23:36:59 +02:00
x + = 194 ;
2009-03-12 20:50:36 +02:00
else if ( boxList [ i ] . size ( ) = = 3 )
2008-03-11 23:36:59 +02:00
x + = 97 ;
2009-03-12 20:50:36 +02:00
boxes [ i ] . push_back ( new CBuildingBox ( boxList [ i ] [ j ] [ k - 1 ] , pos . x + x , pos . y + 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
SDL_FreeSurface ( bg ) ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < boxes . size ( ) ; i + + )
for ( size_t j = 0 ; j < boxes [ i ] . size ( ) ; j + + )
delete boxes [ i ] [ j ] ; //TODO whats wrong with smartpointers?
2008-03-16 02:09:43 +02:00
delete exit ;
2009-05-20 12:02:50 +03:00
delete resdatabar ;
2008-03-10 01:06:35 +02:00
}
void CHallInterface : : close ( )
{
2010-02-28 12:01:36 +02:00
GH . popInts ( LOCPLINT - > castleInt - > winMode = = 2 ? 2 : 1 ) ;
2008-03-10 01:06:35 +02:00
}
2009-01-11 00:08:18 +02:00
void CHallInterface : : show ( SDL_Surface * to )
2009-12-30 09:49:25 +02:00
{
blitAt ( bg , pos , to ) ;
LOCPLINT - > castleInt - > statusbar - > show ( to ) ;
2010-02-02 18:24:53 +02:00
printAtMiddle ( CGI - > buildh - > buildings [ LOCPLINT - > castleInt - > town - > subID ] [ bid ] - > Name ( ) , 399 + pos . x , 12 + pos . y , FONT_MEDIUM , zwykly , to ) ;
2009-05-20 12:02:50 +03:00
resdatabar - > show ( to ) ;
2009-04-14 15:47:09 +03:00
exit - > show ( to ) ;
2008-03-11 23:36:59 +02:00
for ( int i = 0 ; i < 5 ; i + + )
{
2008-12-21 21:17:35 +02:00
for ( size_t j = 0 ; j < boxes [ i ] . size ( ) ; + + j )
2009-04-14 15:47:09 +03:00
boxes [ i ] [ j ] - > show ( to ) ;
2009-12-30 09:49:25 +02:00
}
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 + + )
2008-12-23 15:59:03 +02:00
{
for ( size_t j = 0 ; j < boxes [ i ] . size ( ) ; + + j )
{
2008-03-11 23:36:59 +02:00
boxes [ i ] [ j ] - > activate ( ) ;
2008-12-23 15:59:03 +02:00
}
}
2008-03-11 23:36:59 +02:00
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 + + )
{
2008-12-21 21:17:35 +02:00
for ( size_t j = 0 ; j < boxes [ i ] . size ( ) ; + + j )
2008-03-11 23:36:59 +02:00
{
boxes [ i ] [ j ] - > deactivate ( ) ;
}
}
exit - > deactivate ( ) ;
2008-03-16 02:09:43 +02:00
}
void CHallInterface : : CBuildWindow : : activate ( )
{
2009-08-11 19:05:33 +03:00
activateRClick ( ) ;
2008-03-23 03:01:17 +02:00
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
}
2009-04-14 15:47:09 +03:00
2008-03-16 02:09:43 +02:00
void CHallInterface : : CBuildWindow : : deactivate ( )
{
2009-08-11 19:05:33 +03:00
deactivateRClick ( ) ;
2008-03-23 03:01:17 +02:00
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 ( ) ;
}
2009-04-14 15:47:09 +03:00
2008-03-21 02:03:31 +02:00
void CHallInterface : : CBuildWindow : : Buy ( )
{
2009-04-14 15:47:09 +03:00
int building = bid ;
LOCPLINT - > cb - > buildBuilding ( LOCPLINT - > castleInt - > town , building ) ;
2010-02-28 12:01:36 +02:00
GH . popInts ( LOCPLINT - > castleInt - > winMode = = 2 ? 3 : 2 ) ; //we - build window and hall screen
2008-03-21 02:03:31 +02:00
}
2009-04-14 15:47:09 +03:00
2008-03-21 02:03:31 +02:00
void CHallInterface : : CBuildWindow : : close ( )
{
2009-08-07 01:36:51 +03:00
GH . popIntTotally ( this ) ;
2008-03-21 02:03:31 +02:00
}
2009-04-14 15:47:09 +03:00
2009-08-11 19:05:33 +03:00
void CHallInterface : : CBuildWindow : : clickRight ( tribool down , bool previousState )
2008-03-21 02:03:31 +02:00
{
if ( ( ! down | | indeterminate ( down ) ) & & mode )
close ( ) ;
2008-03-16 02:09:43 +02:00
}
2009-04-14 15:47:09 +03:00
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 ;
2009-04-14 15:47:09 +03:00
SDL_BlitSurface ( bitmap , & poms , to , & pom ) ;
2008-03-23 03:01:17 +02:00
if ( ! mode )
{
2009-04-14 15:47:09 +03:00
buy - > show ( to ) ;
cancel - > show ( to ) ;
2008-03-23 03:01:17 +02:00
}
2008-03-21 02:03:31 +02:00
}
2009-04-14 15:47:09 +03: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-12-22 19:48:41 +02:00
ret = CGI - > generaltexth - > hcommands [ state ] ;
2008-03-21 02:03:31 +02:00
switch ( state )
{
2008-06-03 21:16:54 +03:00
case 4 : case 5 : case 6 :
2008-12-22 19:48:41 +02:00
ret . replace ( ret . find_first_of ( " %s " ) , 2 , CGI - > buildh - > buildings [ tid ] [ bid ] - > Name ( ) ) ;
2008-03-23 03:01:17 +02:00
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 ] ;
2009-12-30 09:49:25 +02:00
std : : set < int > reqs = LOCPLINT - > cb - > getBuildingRequiments ( LOCPLINT - > castleInt - > town , bid ) ;
2008-03-23 03:01:17 +02:00
bool first = true ;
for ( std : : set < int > : : iterator i = reqs . begin ( ) ; i ! = reqs . end ( ) ; i + + )
2009-12-30 09:49:25 +02:00
{
if ( vstd : : contains ( LOCPLINT - > castleInt - > town - > builtBuildings , * i ) )
2009-12-29 15:40:16 +02:00
continue ; //skipping constructed buildings
2008-12-22 19:48:41 +02:00
ret + = ( ( ( first ) ? ( " " ) : ( " , " ) ) + CGI - > buildh - > buildings [ tid ] [ * i ] - > Name ( ) ) ;
2009-12-29 15:40:16 +02:00
first = false ; //TODO - currently can return "Mage guild lvl 1, MG lvl 2..." - extra check needed
2008-03-23 03:01:17 +02:00
}
}
2008-03-21 02:03:31 +02:00
}
2009-12-29 15:40:16 +02:00
2008-03-23 03:01:17 +02:00
return ret ;
2008-03-16 02:09:43 +02:00
}
2009-04-14 15:47:09 +03:00
2008-03-16 02:09:43 +02:00
CHallInterface : : CBuildWindow : : CBuildWindow ( int Tid , int Bid , int State , bool Mode )
2008-12-21 21:17:35 +02:00
: tid ( Tid ) , bid ( Bid ) , state ( State ) , mode ( Mode )
2008-03-16 02:09:43 +02:00
{
2008-06-12 09:45:51 +03:00
SDL_Surface * hhlp = BitmapHandler : : loadBitmap ( " TPUBUILD.bmp " ) ;
2008-08-02 18:08:03 +03:00
graphics - > blueToPlayersAdv ( hhlp , LOCPLINT - > playerID ) ;
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-21 02:03:31 +02:00
blitAt ( LOCPLINT - > castleInt - > bicons - > ourImages [ bid ] . bitmap , 125 , 50 , bitmap ) ;
2008-12-22 19:48:41 +02:00
std : : vector < std : : string > pom ; pom . push_back ( CGI - > buildh - > buildings [ tid ] [ bid ] - > Name ( ) ) ;
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAtMiddleWB ( CGI - > buildh - > buildings [ tid ] [ bid ] - > Description ( ) , 197 , 168 , FONT_MEDIUM , 43 , zwykly , bitmap ) ;
CSDL_Ext : : printAtMiddleWB ( getTextForState ( state ) , 199 , 248 , FONT_SMALL , 50 , zwykly , bitmap ) ;
CSDL_Ext : : printAtMiddle ( CSDL_Ext : : processStr ( CGI - > generaltexth - > hcommands [ 7 ] , pom ) , 197 , 30 , FONT_BIG , tytulowy , bitmap ) ;
2008-12-23 15:59:03 +02:00
2010-11-15 17:15:00 +02:00
int resamount = 0 ;
2008-12-23 15:59:03 +02:00
for ( int i = 0 ; i < 7 ; i + + )
{
if ( CGI - > buildh - > buildings [ tid ] [ bid ] - > resources [ i ] )
{
resamount + + ;
}
}
2010-02-02 18:24:53 +02:00
int ah = ( resamount > 4 ) ? 304 : 340 ;
2008-03-21 02:03:31 +02:00
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 ;
2008-08-02 18:08:03 +03:00
SDL_itoa ( CGI - > buildh - > buildings [ tid ] [ bid ] - > resources [ cn ] , buf , 10 ) ;
2008-03-21 02:03:31 +02:00
if ( it < 4 )
{
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAtMiddle ( buf , ( bitmap - > w / 2 - row1w / 2 ) + 77 * it + 16 , ah + 47 , FONT_SMALL , zwykly , bitmap ) ;
2008-06-13 11:16:51 +03:00
blitAt ( graphics - > resources32 - > ourImages [ cn ] . bitmap , ( bitmap - > w / 2 - row1w / 2 ) + 77 * it + + , ah , bitmap ) ;
2008-03-21 02:03:31 +02:00
}
else
{
2010-02-02 18:24:53 +02:00
CSDL_Ext : : printAtMiddle ( buf , ( bitmap - > w / 2 - row2w / 2 ) + 77 * it + 16 - 308 , ah + 47 , FONT_SMALL , zwykly , bitmap ) ;
2008-06-13 11:16:51 +03:00
blitAt ( graphics - > resources32 - > ourImages [ cn ] . bitmap , ( bitmap - > w / 2 - row2w / 2 ) + 77 * it + + - 308 , ah , bitmap ) ;
2008-03-21 02:03:31 +02:00
}
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
2008-10-19 16:17:32 +03:00
( " " , " " , boost : : bind ( & CBuildWindow : : Buy , this ) , pos . x + 45 , pos . y + 446 , " IBUY30.DEF " , SDLK_RETURN ) ;
2008-05-18 20:33:39 +03:00
cancel = new AdventureMapButton
2008-10-19 16:17:32 +03:00
( " " , " " , boost : : bind ( & CBuildWindow : : close , this ) , pos . x + 290 , pos . y + 445 , " ICANCEL.DEF " , SDLK_ESCAPE ) ;
2008-04-04 20:30:53 +03:00
if ( state ! = 7 )
buy - > state = 2 ;
2008-03-23 03:01:17 +02:00
}
2008-03-16 02:09:43 +02:00
}
2009-04-14 15:47:09 +03:00
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-08-02 18:08:03 +03:00
}
2008-08-17 12:11:16 +03:00
CFortScreen : : ~ CFortScreen ( )
{
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < crePics . size ( ) ; i + + )
2008-08-17 12:11:16 +03:00
delete crePics [ i ] ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < recAreas . size ( ) ; i + + )
2008-08-17 12:11:16 +03:00
delete recAreas [ i ] ;
SDL_FreeSurface ( bg ) ;
delete exit ;
2009-05-20 12:02:50 +03:00
delete resdatabar ;
2008-08-17 12:11:16 +03:00
}
void CFortScreen : : show ( SDL_Surface * to )
{
2009-04-14 15:47:09 +03:00
blitAt ( bg , pos , to ) ;
2010-07-26 01:47:59 +03:00
for ( int i = 0 ; i < crePics . size ( ) ; i + + )
2008-08-17 12:11:16 +03:00
{
2010-11-15 17:15:00 +02:00
crePics [ i ] - > show ( to ) ;
2008-08-17 12:11:16 +03:00
}
2009-04-14 15:47:09 +03:00
exit - > show ( to ) ;
2009-05-20 12:02:50 +03:00
resdatabar - > show ( to ) ;
2010-02-15 08:54:57 +02:00
GH . statusbar - > show ( to ) ;
2008-08-17 12:11:16 +03:00
}
void CFortScreen : : activate ( )
{
2010-02-15 08:54:57 +02:00
GH . statusbar = LOCPLINT - > castleInt - > statusbar ;
2008-08-17 12:11:16 +03:00
exit - > activate ( ) ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < recAreas . size ( ) ; + + i )
2008-08-17 12:11:16 +03:00
{
recAreas [ i ] - > activate ( ) ;
}
}
void CFortScreen : : deactivate ( )
{
exit - > deactivate ( ) ;
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < recAreas . size ( ) ; i + + )
2008-08-17 12:11:16 +03:00
{
recAreas [ i ] - > deactivate ( ) ;
}
}
void CFortScreen : : close ( )
{
2010-02-28 12:01:36 +02:00
GH . popInts ( LOCPLINT - > castleInt - > winMode = = 3 ? 2 : 1 ) ;
2008-08-17 12:11:16 +03:00
}
2009-04-14 15:47:09 +03:00
2008-08-17 12:11:16 +03:00
CFortScreen : : CFortScreen ( CCastleInterface * owner )
{
2010-11-15 17:15:00 +02:00
if ( owner - > town - > creatures . size ( ) > CREATURES_PER_TOWN
2010-07-26 01:47:59 +03:00
& & owner - > town - > creatures [ CREATURES_PER_TOWN ] . second . size ( ) ) //dungeon with active portal
fortSize = CREATURES_PER_TOWN + 1 ;
else
fortSize = CREATURES_PER_TOWN ;
2009-05-20 12:02:50 +03:00
resdatabar = new CMinorResDataBar ;
2008-11-28 03:36:34 +02:00
pos = owner - > pos ;
2008-08-17 12:11:16 +03:00
bg = NULL ;
2009-12-23 03:46:15 +02:00
LOCPLINT - > castleInt - > statusbar - > clear ( ) ;
std : : string temp = CGI - > generaltexth - > fcommands [ 6 ] ;
boost : : algorithm : : replace_first ( temp , " %s " , CGI - > buildh - > buildings [ owner - > town - > subID ] [ owner - > town - > fortLevel ( ) + 6 ] - > Name ( ) ) ;
exit = new AdventureMapButton ( temp , " " , boost : : bind ( & CFortScreen : : close , this ) , pos . x + 748 , pos . y + 556 , " TPMAGE1.DEF " , SDLK_RETURN ) ;
2008-08-17 12:11:16 +03:00
positions + = genRect ( 126 , 386 , 10 , 22 ) , genRect ( 126 , 386 , 404 , 22 ) ,
genRect ( 126 , 386 , 10 , 155 ) , genRect ( 126 , 386 , 404 , 155 ) ,
2010-07-26 01:47:59 +03:00
genRect ( 126 , 386 , 10 , 288 ) , genRect ( 126 , 386 , 404 , 288 ) ;
if ( fortSize = = CREATURES_PER_TOWN )
positions + = genRect ( 126 , 386 , 206 , 421 ) ;
else
positions + = genRect ( 126 , 386 , 10 , 421 ) , genRect ( 126 , 386 , 404 , 421 ) ;
2008-08-17 12:11:16 +03:00
draw ( owner , true ) ;
2009-05-20 12:02:50 +03:00
resdatabar - > pos + = pos ;
2008-08-17 12:11:16 +03:00
}
void CFortScreen : : draw ( CCastleInterface * owner , bool first )
{
if ( bg )
SDL_FreeSurface ( bg ) ;
char buf [ 20 ] ;
memset ( buf , 0 , 20 ) ;
2010-07-26 01:47:59 +03:00
SDL_Surface * bg2 ;
if ( fortSize = = CREATURES_PER_TOWN )
bg2 = BitmapHandler : : loadBitmap ( " TPCASTL7.bmp " ) ;
else
bg2 = BitmapHandler : : loadBitmap ( " TPCASTL8.bmp " ) ;
2010-11-15 17:15:00 +02:00
2010-07-26 01:47:59 +03:00
SDL_Surface * icons = BitmapHandler : : loadBitmap ( " ZPCAINFO.bmp " ) ;
2008-08-17 12:11:16 +03:00
SDL_SetColorKey ( icons , SDL_SRCCOLORKEY , SDL_MapRGB ( icons - > format , 0 , 255 , 255 ) ) ;
graphics - > blueToPlayersAdv ( bg2 , LOCPLINT - > playerID ) ;
2010-11-15 17:15:00 +02:00
bg = SDL_ConvertSurface ( bg2 , screen - > format , 0 ) ;
2008-08-17 12:11:16 +03:00
SDL_FreeSurface ( bg2 ) ;
2010-02-02 18:24:53 +02:00
printAtMiddle ( CGI - > buildh - > buildings [ owner - > town - > subID ] [ owner - > town - > fortLevel ( ) + 6 ] - > Name ( ) , 400 , 13 , FONT_MEDIUM , zwykly , bg ) ;
2010-07-26 01:47:59 +03:00
for ( int i = 0 ; i < fortSize ; i + + )
2008-08-17 12:11:16 +03:00
{
2010-07-26 01:47:59 +03:00
int dwelling ; // ID of buiding with this creature
CCreature * c ;
bool present = true ;
if ( i < CREATURES_PER_TOWN )
{
bool upgraded = owner - > town - > creatureDwelling ( i , true ) ;
present = owner - > town - > creatureDwelling ( i , false ) ;
c = CGI - > creh - > creatures [ upgraded ? owner - > town - > town - > upgradedCreatures [ i ] : owner - > town - > town - > basicCreatures [ i ] ] ;
dwelling = 30 + i + upgraded * 7 ;
}
else
{
c = CGI - > creh - > creatures [ owner - > town - > creatures [ i ] . second [ 0 ] ] ;
dwelling = 22 ; //Portal of summon
}
2010-02-02 18:24:53 +02:00
printAtMiddle ( c - > namePl , positions [ i ] . x + 79 , positions [ i ] . y + 10 , FONT_SMALL , zwykly , bg ) ; //cr. name
2010-07-26 01:47:59 +03:00
blitAt ( owner - > bicons - > ourImages [ dwelling ] . bitmap , positions [ i ] . x + 4 , positions [ i ] . y + 21 , bg ) ; //dwelling pic
printAtMiddle ( CGI - > buildh - > buildings [ owner - > town - > subID ] [ dwelling ] - > Name ( ) , positions [ i ] . x + 79 , positions [ i ] . y + 100 , FONT_SMALL , zwykly , bg ) ; //dwelling name
if ( present ) //if creature is present print available quantity
2008-08-17 12:11:16 +03:00
{
2009-07-06 22:41:27 +03:00
SDL_itoa ( owner - > town - > creatures [ i ] . first , buf , 10 ) ;
2010-02-02 18:24:53 +02:00
printAtMiddle ( CGI - > generaltexth - > allTexts [ 217 ] + buf , positions [ i ] . x + 79 , positions [ i ] . y + 118 , FONT_SMALL , zwykly , bg ) ;
2008-08-17 12:11:16 +03:00
}
blitAt ( icons , positions [ i ] . x + 261 , positions [ i ] . y + 3 , bg ) ;
2009-07-16 02:58:47 +03:00
//attack
2010-02-02 18:24:53 +02:00
printAt ( CGI - > generaltexth - > allTexts [ 190 ] , positions [ i ] . x + 288 , positions [ i ] . y + 5 , FONT_SMALL , zwykly , bg ) ;
2010-05-02 21:20:26 +03:00
SDL_itoa ( c - > Attack ( ) , buf , 10 ) ;
2010-02-02 18:24:53 +02:00
printTo ( buf , positions [ i ] . x + 381 , positions [ i ] . y + 21 , FONT_SMALL , zwykly , bg ) ;
2008-08-17 12:11:16 +03:00
//defense
2010-02-02 18:24:53 +02:00
printAt ( CGI - > generaltexth - > allTexts [ 191 ] , positions [ i ] . x + 288 , positions [ i ] . y + 25 , FONT_SMALL , zwykly , bg ) ;
2010-05-02 21:20:26 +03:00
SDL_itoa ( c - > Defense ( ) , buf , 10 ) ;
2010-02-02 18:24:53 +02:00
printTo ( buf , positions [ i ] . x + 381 , positions [ i ] . y + 41 , FONT_SMALL , zwykly , bg ) ;
2008-08-17 12:11:16 +03:00
//damage
2010-02-02 18:24:53 +02:00
printAt ( CGI - > generaltexth - > allTexts [ 199 ] , positions [ i ] . x + 288 , positions [ i ] . y + 46 , FONT_SMALL , zwykly , bg ) ;
2008-08-17 12:11:16 +03:00
SDL_itoa ( c - > damageMin , buf , 10 ) ;
2008-11-06 19:17:48 +02:00
int hlp ;
if ( c - > damageMin > 0 )
hlp = log10f ( c - > damageMin ) + 2 ;
else
hlp = 2 ;
2008-08-17 12:11:16 +03:00
buf [ hlp - 1 ] = ' ' ; buf [ hlp ] = ' - ' ; buf [ hlp + 1 ] = ' ' ;
SDL_itoa ( c - > damageMax , buf + hlp + 2 , 10 ) ;
2010-02-02 18:24:53 +02:00
printTo ( buf , positions [ i ] . x + 381 , positions [ i ] . y + 62 , FONT_SMALL , zwykly , bg ) ;
2008-08-17 12:11:16 +03:00
//health
2010-02-02 18:24:53 +02:00
printAt ( CGI - > generaltexth - > zelp [ 439 ] . first , positions [ i ] . x + 288 , positions [ i ] . y + 66 , FONT_SMALL , zwykly , bg ) ;
2010-05-02 21:20:26 +03:00
SDL_itoa ( c - > MaxHealth ( ) , buf , 10 ) ;
2010-02-02 18:24:53 +02:00
printTo ( buf , positions [ i ] . x + 381 , positions [ i ] . y + 82 , FONT_SMALL , zwykly , bg ) ;
2008-08-17 12:11:16 +03:00
//speed
2010-02-02 18:24:53 +02:00
printAt ( CGI - > generaltexth - > zelp [ 441 ] . first , positions [ i ] . x + 288 , positions [ i ] . y + 87 , FONT_SMALL , zwykly , bg ) ;
2010-05-02 21:20:26 +03:00
SDL_itoa ( c - > valOfBonuses ( Bonus : : STACKS_SPEED ) , buf , 10 ) ;
2010-02-02 18:24:53 +02:00
printTo ( buf , positions [ i ] . x + 381 , positions [ i ] . y + 103 , FONT_SMALL , zwykly , bg ) ;
2008-08-17 12:11:16 +03:00
if ( present ) //growth
{
2010-02-02 18:24:53 +02:00
printAt ( CGI - > generaltexth - > allTexts [ 194 ] , positions [ i ] . x + 288 , positions [ i ] . y + 107 , FONT_SMALL , zwykly , bg ) ;
2008-08-17 12:11:16 +03:00
SDL_itoa ( owner - > town - > creatureGrowth ( i ) , buf , 10 ) ;
2010-02-02 18:24:53 +02:00
printTo ( buf , positions [ i ] . x + 381 , positions [ i ] . y + 123 , FONT_SMALL , zwykly , bg ) ;
2008-08-17 12:11:16 +03:00
}
if ( first )
{
2010-11-15 17:15:00 +02:00
crePics . push_back ( new CCreaturePic ( positions [ i ] . x + pos . x + 160 , positions [ i ] . y + pos . y + 5 , c , false ) ) ;
2008-08-17 12:11:16 +03:00
if ( present )
{
2010-07-26 01:47:59 +03:00
recAreas . push_back ( new RecArea ( i ) ) ;
2009-02-11 19:03:30 +02:00
recAreas . back ( ) - > pos = positions [ i ] + pos ;
2008-08-17 12:11:16 +03:00
}
}
}
SDL_FreeSurface ( icons ) ;
}
2009-08-11 19:05:33 +03:00
void CFortScreen : : RecArea : : clickLeft ( tribool down , bool previousState )
2008-08-17 12:11:16 +03:00
{
2009-08-11 19:05:33 +03:00
if ( ! down & & previousState )
2010-07-26 01:47:59 +03:00
LOCPLINT - > castleInt - > showRecruitmentWindow ( level ) ;
2008-08-17 12:11:16 +03:00
}
2008-08-20 09:57:53 +03:00
2009-08-11 19:05:33 +03:00
void CFortScreen : : RecArea : : clickRight ( tribool down , bool previousState )
2009-01-22 19:30:15 +02:00
{
2009-08-11 19:05:33 +03:00
clickLeft ( down , false ) ; //r-click does same as l-click - opens recr. window
2009-01-22 19:30:15 +02:00
}
2008-08-20 09:57:53 +03:00
CMageGuildScreen : : CMageGuildScreen ( CCastleInterface * owner )
{
2010-11-15 17:15:00 +02:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
bg = new CPicture ( " TPMAGE.bmp " ) ;
pos = bg - > center ( ) ;
2009-05-20 12:02:50 +03:00
resdatabar = new CMinorResDataBar ;
resdatabar - > pos . x + = pos . x ;
resdatabar - > pos . y + = pos . y ;
2009-12-23 03:46:15 +02:00
LOCPLINT - > castleInt - > statusbar - > clear ( ) ;
2010-11-15 17:15:00 +02:00
exit = new AdventureMapButton ( CGI - > generaltexth - > allTexts [ 593 ] , " " , boost : : bind ( & CMageGuildScreen : : close , this ) , 748 , 556 , " TPMAGE1.DEF " , SDLK_RETURN ) ;
2008-11-28 03:36:34 +02:00
exit - > assignedKeys . insert ( SDLK_ESCAPE ) ;
2010-11-15 17:15:00 +02:00
CAnimation scrolls ( " TPMAGES.DEF " ) ;
scrolls . load ( ) ;
2008-08-20 09:57:53 +03:00
SDL_Surface * view = BitmapHandler : : loadBitmap ( graphics - > guildBgs [ owner - > town - > subID ] ) ;
SDL_SetColorKey ( view , SDL_SRCCOLORKEY , SDL_MapRGB ( view - > format , 0 , 255 , 255 ) ) ;
2010-11-15 17:15:00 +02:00
blitAt ( view , 332 , 76 , * bg ) ;
SDL_FreeSurface ( view ) ;
2008-08-20 09:57:53 +03:00
positions . resize ( 5 ) ;
positions [ 0 ] + = genRect ( 61 , 83 , 222 , 445 ) , genRect ( 61 , 83 , 312 , 445 ) , genRect ( 61 , 83 , 402 , 445 ) , genRect ( 61 , 83 , 520 , 445 ) , genRect ( 61 , 83 , 610 , 445 ) , genRect ( 61 , 83 , 700 , 445 ) ;
positions [ 1 ] + = genRect ( 61 , 83 , 48 , 53 ) , genRect ( 61 , 83 , 48 , 147 ) , genRect ( 61 , 83 , 48 , 241 ) , genRect ( 61 , 83 , 48 , 335 ) , genRect ( 61 , 83 , 48 , 429 ) ;
positions [ 2 ] + = genRect ( 61 , 83 , 570 , 82 ) , genRect ( 61 , 83 , 672 , 82 ) , genRect ( 61 , 83 , 570 , 157 ) , genRect ( 61 , 83 , 672 , 157 ) ;
positions [ 3 ] + = genRect ( 61 , 83 , 183 , 42 ) , genRect ( 61 , 83 , 183 , 148 ) , genRect ( 61 , 83 , 183 , 253 ) ;
positions [ 4 ] + = genRect ( 61 , 83 , 491 , 325 ) , genRect ( 61 , 83 , 591 , 325 ) ;
2010-11-15 17:15:00 +02:00
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < owner - > town - > town - > mageLevel ; i + + )
2008-08-20 09:57:53 +03:00
{
2008-12-21 21:17:35 +02:00
size_t sp = owner - > town - > spellsAtLevel ( i + 1 , false ) ; //spell at level with -1 hmmm?
for ( size_t j = 0 ; j < sp ; j + + )
2008-08-20 09:57:53 +03:00
{
2008-09-23 13:58:54 +03:00
if ( i < owner - > town - > mageGuildLevel ( ) & & owner - > town - > spells [ i ] . size ( ) > j )
2008-08-20 09:57:53 +03:00
{
2010-11-15 17:15:00 +02:00
spells . push_back ( new Scroll ( & CGI - > spellh - > spells [ owner - > town - > spells [ i ] [ j ] ] ) ) ;
spells [ spells . size ( ) - 1 ] - > pos = positions [ i ] [ j ] ;
blitAt ( graphics - > spellscr - > ourImages [ owner - > town - > spells [ i ] [ j ] ] . bitmap , positions [ i ] [ j ] , * bg ) ;
2008-08-20 09:57:53 +03:00
}
else
{
2010-11-15 17:15:00 +02:00
blitAt ( scrolls . image ( 1 ) , positions [ i ] [ j ] , * bg ) ;
2008-08-20 09:57:53 +03:00
}
}
}
2010-11-15 17:15:00 +02:00
2008-12-21 21:17:35 +02:00
for ( size_t i = 0 ; i < spells . size ( ) ; i + + )
2008-11-28 03:36:34 +02:00
{
2010-11-15 17:15:00 +02:00
spells [ i ] - > pos . x + = pos . x ;
spells [ i ] - > pos . y + = pos . y ;
2008-11-28 03:36:34 +02:00
}
2008-08-20 09:57:53 +03:00
}
2009-04-14 15:47:09 +03:00
2008-08-20 09:57:53 +03:00
CMageGuildScreen : : ~ CMageGuildScreen ( )
{
2010-11-15 17:15:00 +02:00
2008-08-20 09:57:53 +03:00
}
2009-04-14 15:47:09 +03:00
2008-08-20 09:57:53 +03:00
void CMageGuildScreen : : close ( )
{
2009-08-07 01:36:51 +03:00
GH . popIntTotally ( this ) ;
2008-08-20 09:57:53 +03:00
}
2009-04-14 15:47:09 +03:00
2010-11-15 17:15:00 +02:00
CMageGuildScreen : : Scroll : : Scroll ( CSpell * Spell )
: spell ( Spell )
2008-08-20 09:57:53 +03:00
{
2010-11-15 17:15:00 +02:00
used = LCLICK | RCLICK | HOVER ;
2008-08-20 09:57:53 +03:00
}
2009-04-14 15:47:09 +03:00
2009-08-11 19:05:33 +03:00
void CMageGuildScreen : : Scroll : : clickLeft ( tribool down , bool previousState )
2008-08-20 09:57:53 +03:00
{
2008-08-27 13:19:18 +03:00
if ( down )
{
std : : vector < SComponent * > comps ( 1 ,
2010-08-18 17:24:30 +03:00
new SComponent ( SComponent : : spell , spell - > id , 0 )
2008-08-27 13:19:18 +03:00
) ;
2009-04-22 21:48:56 +03:00
LOCPLINT - > showInfoDialog ( spell - > descriptions [ 0 ] , comps , soundBase : : sound_todo ) ;
2008-08-27 13:19:18 +03:00
}
2008-08-20 09:57:53 +03:00
}
2009-04-14 15:47:09 +03:00
2009-08-11 19:05:33 +03:00
void CMageGuildScreen : : Scroll : : clickRight ( tribool down , bool previousState )
2008-08-20 09:57:53 +03:00
{
if ( down )
{
CInfoPopup * vinya = new CInfoPopup ( ) ;
vinya - > free = true ;
vinya - > bitmap = CMessage : : drawBoxTextBitmapSub
( LOCPLINT - > playerID ,
2009-04-14 15:47:09 +03:00
spell - > descriptions [ 0 ] , graphics - > spellscr - > ourImages [ spell - > id ] . bitmap ,
2008-08-20 22:02:48 +03:00
spell - > name , 30 , 30 ) ;
2008-08-20 09:57:53 +03:00
vinya - > pos . x = screen - > w / 2 - vinya - > bitmap - > w / 2 ;
vinya - > pos . y = screen - > h / 2 - vinya - > bitmap - > h / 2 ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( vinya ) ;
2008-08-20 09:57:53 +03:00
}
}
2009-04-14 15:47:09 +03:00
2008-08-20 09:57:53 +03:00
void CMageGuildScreen : : Scroll : : hover ( bool on )
{
2008-08-27 13:19:18 +03:00
if ( on )
2010-02-15 08:54:57 +02:00
GH . statusbar - > print ( spell - > name ) ;
2008-08-27 13:19:18 +03:00
else
2010-02-15 08:54:57 +02:00
GH . statusbar - > clear ( ) ;
2008-08-20 09:57:53 +03:00
}
2009-04-14 15:47:09 +03:00
2008-08-27 13:19:18 +03:00
CBlacksmithDialog : : CBlacksmithDialog ( bool possible , int creMachineID , int aid , int hid )
{
2010-11-15 17:15:00 +02:00
OBJ_CONSTRUCTION_CAPTURING_ALL ;
// SDL_SetColorKey(bg2,SDL_SRCCOLORKEY,SDL_MapRGB(bg2->format,0,255,255));
bmp = new CPicture ( " TPSMITH " ) ;
bmp - > colorizeAndConvert ( LOCPLINT - > playerID ) ;
pos = bmp - > center ( ) ;
SDL_Surface * bg = BitmapHandler : : loadBitmap ( " TPSMITBK.bmp " ) ;
blitAt ( bg , 64 , 50 , * bmp ) ;
SDL_FreeSurface ( bg ) ;
2009-05-07 20:20:41 +03:00
2010-11-15 17:15:00 +02:00
CCreatureAnim cra ( 170 , 120 , CGI - > creh - > creatures [ creMachineID ] - > animDefName ) ;
2008-08-27 13:19:18 +03:00
char pom [ 75 ] ;
2010-05-02 21:20:26 +03:00
sprintf ( pom , CGI - > generaltexth - > allTexts [ 274 ] . c_str ( ) , CGI - > creh - > creatures [ creMachineID ] - > nameSing . c_str ( ) ) ; //build a new ...
2010-11-15 17:15:00 +02:00
printAtMiddle ( pom , 165 , 28 , FONT_MEDIUM , tytulowy , * bmp ) ;
printAtMiddle ( CGI - > generaltexth - > jktexts [ 43 ] , 165 , 218 , FONT_MEDIUM , zwykly , * bmp ) ; //resource cost
2010-06-26 19:02:10 +03:00
SDL_itoa ( CGI - > arth - > artifacts [ aid ] - > price , pom , 10 ) ;
2010-11-15 17:15:00 +02:00
printAtMiddle ( pom , 165 , 290 , FONT_MEDIUM , zwykly , * bmp ) ;
2009-05-07 20:20:41 +03:00
2010-11-15 17:15:00 +02:00
buy = new AdventureMapButton ( " " , " " , boost : : bind ( & CBlacksmithDialog : : close , this ) , 42 , 312 , " IBUY30.DEF " , SDLK_RETURN ) ;
cancel = new AdventureMapButton ( " " , " " , boost : : bind ( & CBlacksmithDialog : : close , this ) , 224 , 312 , " ICANCEL.DEF " , SDLK_ESCAPE ) ;
2009-05-07 20:20:41 +03:00
2008-08-27 13:19:18 +03:00
if ( possible )
buy - > callback + = boost : : bind ( & CCallback : : buyArtifact , LOCPLINT - > cb , LOCPLINT - > cb - > getHeroInfo ( hid , 2 ) , aid ) ;
else
2010-11-15 17:15:00 +02:00
buy - > block ( 2 ) ;
2009-05-07 20:20:41 +03:00
2010-11-15 17:15:00 +02:00
blitAt ( graphics - > resources32 - > ourImages [ 6 ] . bitmap , 148 , 244 , * bmp ) ;
2008-08-27 13:19:18 +03:00
}
CBlacksmithDialog : : ~ CBlacksmithDialog ( )
{
2010-11-15 17:15:00 +02:00
2008-08-27 13:19:18 +03:00
}
void CBlacksmithDialog : : close ( )
{
2009-08-07 01:36:51 +03:00
GH . popIntTotally ( this ) ;
2009-05-06 05:32:36 +03:00
}