2009-05-20 13:08:56 +03:00
# include "../stdafx.h"
2008-03-16 02:09:43 +02:00
# include "CAdvmapInterface.h"
2008-08-27 13:19:18 +03:00
# include "CBattleInterface.h"
2009-05-20 13:08:56 +03:00
# include "../CCallback.h"
2008-08-27 13:19:18 +03:00
# include "CCastleInterface.h"
# include "CCursorHandler.h"
# include "CGameInfo.h"
# include "CHeroWindow.h"
2007-11-19 00:58:28 +02:00
# include "CMessage.h"
2008-08-27 13:19:18 +03:00
# include "CPlayerInterface.h"
2008-12-17 23:16:19 +02:00
//#include "SDL_Extensions.h"
2007-11-19 00:58:28 +02:00
# include "SDL_Extensions.h"
2008-12-17 23:16:19 +02:00
//#include "SDL_framerate.h"
2008-08-27 13:19:18 +03:00
# include "SDL_framerate.h"
2009-05-20 13:08:56 +03:00
# include "CConfigHandler.h"
# include "CCreatureAnimation.h"
# include "Graphics.h"
# include "../hch/CArtHandler.h"
# include "../hch/CGeneralTextHandler.h"
# include "../hch/CHeroHandler.h"
# include "../hch/CLodHandler.h"
# include "../hch/CObjectHandler.h"
# include "../lib/Connection.h"
# include "../hch/CSpellHandler.h"
# include "../hch/CTownHandler.h"
# include "../lib/CondSh.h"
# include "../lib/NetPacks.h"
# include "../lib/map.h"
# include "../mapHandler.h"
# include "../timeHandler.h"
2009-02-09 18:18:48 +02:00
# include <boost/lexical_cast.hpp>
2008-01-29 15:00:45 +02:00
# include <boost/algorithm/string.hpp>
# include <boost/algorithm/string/replace.hpp>
2008-09-07 06:38:37 +03:00
# include <boost/assign/std/vector.hpp>
2008-10-17 19:30:56 +03:00
# include <boost/assign/list_of.hpp>
2009-03-28 02:38:48 +02:00
# include <boost/date_time/posix_time/posix_time.hpp>
2008-08-27 13:19:18 +03:00
# include <boost/thread.hpp>
2008-05-23 22:50:11 +03:00
# include <cmath>
2008-08-27 13:19:18 +03:00
# include <queue>
# include <sstream>
2008-10-19 02:20:48 +03:00
# ifdef min
# undef min
# endif
# ifdef max
# undef max
# endif
2009-04-15 17:03:31 +03:00
/*
* CPlayerInterface . 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
*
*/
2008-09-07 06:38:37 +03:00
using namespace boost : : assign ;
2007-11-19 00:58:28 +02:00
using namespace CSDL_Ext ;
2009-04-21 01:57:07 +03:00
void processCommand ( const std : : string & message , CClient * & client ) ;
2009-03-12 20:50:36 +02:00
extern std : : queue < SDL_Event * > events ;
2008-07-27 20:07:37 +03:00
extern boost : : mutex eventsM ;
2008-01-30 16:19:35 +02:00
2009-04-21 01:57:07 +03:00
CPlayerInterface * LOCPLINT ;
enum EMoveState { STOP_MOVE , WAITING_MOVE , CONTINUE_MOVE , DURING_MOVE } ;
CondSh < EMoveState > stillMoveHero ; //used during hero movement
2008-07-31 00:27:15 +03:00
2008-12-17 23:16:19 +02:00
struct OCM_HLP_CGIN
2007-11-19 00:58:28 +02:00
{
2008-11-28 14:11:31 +02:00
bool inline operator ( ) ( const std : : pair < const CGObjectInstance * , SDL_Rect > & a , const std : : pair < const CGObjectInstance * , SDL_Rect > & b ) const
2007-11-19 00:58:28 +02:00
{
return ( * a . first ) < ( * b . first ) ;
}
} ocmptwo_cgin ;
2008-11-02 00:32:56 +02:00
2009-05-19 21:23:04 +03:00
CPlayerInterface : : CPlayerInterface ( int Player , int serial )
2008-01-26 21:36:31 +02:00
{
2009-08-18 11:22:56 +03:00
GH . defActionsDef = 0 ;
2009-05-19 21:23:04 +03:00
LOCPLINT = this ;
curAction = NULL ;
playerID = Player ;
serialID = serial ;
human = true ;
castleInt = NULL ;
adventureInt = NULL ;
battleInt = NULL ;
pim = new boost : : recursive_mutex ;
makingTurn = false ;
showingDialog = new CondSh < bool > ( false ) ;
2009-07-18 06:13:13 +03:00
sysOpts = GDefaultOptions ;
2009-05-19 21:23:04 +03:00
//initializing framerate keeper
mainFPSmng = new FPSmanager ;
SDL_initFramerate ( mainFPSmng ) ;
SDL_setFramerate ( mainFPSmng , 48 ) ;
//framerate keeper initialized
cingconsole = new CInGameConsole ;
2008-01-26 21:36:31 +02:00
}
2009-05-19 21:23:04 +03:00
CPlayerInterface : : ~ CPlayerInterface ( )
2008-05-23 22:50:11 +03:00
{
2009-05-19 21:23:04 +03:00
delete pim ;
delete showingDialog ;
delete mainFPSmng ;
delete adventureInt ;
delete cingconsole ;
2008-05-23 22:50:11 +03:00
2009-05-19 21:23:04 +03:00
for ( std : : map < int , SDL_Surface * > : : iterator i = graphics - > heroWins . begin ( ) ; i ! = graphics - > heroWins . end ( ) ; i + + )
SDL_FreeSurface ( i - > second ) ;
for ( std : : map < int , SDL_Surface * > : : iterator i = graphics - > townWins . begin ( ) ; i ! = graphics - > townWins . end ( ) ; i + + )
SDL_FreeSurface ( i - > second ) ;
2009-02-04 15:40:54 +02:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : init ( ICallback * CB )
2008-01-26 21:36:31 +02:00
{
2009-05-19 21:23:04 +03:00
cb = dynamic_cast < CCallback * > ( CB ) ;
adventureInt = new CAdvMapInt ( playerID ) ;
std : : vector < const CGTownInstance * > tt = cb - > getTownsInfo ( false ) ;
for ( int i = 0 ; i < tt . size ( ) ; i + + )
2008-05-23 22:50:11 +03:00
{
2009-05-19 21:23:04 +03:00
SDL_Surface * pom = infoWin ( tt [ i ] ) ;
graphics - > townWins . insert ( std : : pair < int , SDL_Surface * > ( tt [ i ] - > id , pom ) ) ;
2008-05-23 22:50:11 +03:00
}
2009-06-11 20:21:06 +03:00
recreateWanderingHeroes ( ) ;
2008-01-26 21:36:31 +02:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : yourTurn ( )
2008-01-26 21:36:31 +02:00
{
2009-05-19 21:23:04 +03:00
try
2008-01-26 21:36:31 +02:00
{
2009-05-19 21:23:04 +03:00
LOCPLINT = this ;
makingTurn = true ;
2009-07-11 02:40:10 +03:00
static bool firstCall = true ;
2009-05-19 21:23:04 +03:00
static int autosaveCount = 0 ;
2009-07-11 02:40:10 +03:00
if ( firstCall )
firstCall = false ;
else
LOCPLINT - > cb - > save ( " Autosave_ " + boost : : lexical_cast < std : : string > ( autosaveCount + + + 1 ) ) ;
2009-05-19 21:23:04 +03:00
autosaveCount % = 5 ;
for ( std : : map < int , SDL_Surface * > : : iterator i = graphics - > heroWins . begin ( ) ; i ! = graphics - > heroWins . end ( ) ; i + + ) //redraw hero infoboxes
SDL_FreeSurface ( i - > second ) ;
graphics - > heroWins . clear ( ) ;
std : : vector < const CGHeroInstance * > hh = cb - > getHeroesInfo ( false ) ;
for ( int i = 0 ; i < hh . size ( ) ; i + + )
2008-01-26 21:36:31 +02:00
{
2009-05-19 21:23:04 +03:00
SDL_Surface * pom = infoWin ( hh [ i ] ) ;
graphics - > heroWins . insert ( std : : pair < int , SDL_Surface * > ( hh [ i ] - > subID , pom ) ) ;
}
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
/* TODO: This isn't quite right. First day in game should play
* NEWDAY . And we don ' t play NEWMONTH . */
int day = cb - > getDate ( 1 ) ;
if ( day ! = 1 )
2009-05-22 07:14:59 +03:00
CGI - > soundh - > playSound ( soundBase : : newDay ) ;
2009-05-19 21:23:04 +03:00
else
2009-05-22 07:14:59 +03:00
CGI - > soundh - > playSound ( soundBase : : newWeek ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
adventureInt - > infoBar . newDay ( day ) ;
//select first hero if available.
//TODO: check if hero is slept
2009-06-11 20:21:06 +03:00
if ( wanderingHeroes . size ( ) )
adventureInt - > select ( wanderingHeroes [ 0 ] ) ;
2009-05-19 21:23:04 +03:00
else
adventureInt - > select ( adventureInt - > townList . items [ 0 ] ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
adventureInt - > showAll ( screen ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( adventureInt ) ;
2009-08-11 19:05:33 +03:00
adventureInt - > activateKeys ( ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
while ( makingTurn ) // main loop
{
updateWater ( ) ;
pim - > lock ( ) ;
//if there are any waiting dialogs, show them
if ( dialogs . size ( ) & & ! showingDialog - > get ( ) )
2008-04-19 19:15:04 +03:00
{
2009-05-19 21:23:04 +03:00
showingDialog - > set ( true ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( dialogs . front ( ) ) ;
2009-05-19 21:23:04 +03:00
dialogs . pop_front ( ) ;
}
2009-03-27 01:05:40 +02:00
2009-08-07 01:36:51 +03:00
GH . updateTime ( ) ;
GH . handleEvents ( ) ;
2009-05-19 21:23:04 +03:00
2009-08-07 01:36:51 +03:00
if ( ! adventureInt - > active & & adventureInt - > scrollingDir ) //player forces map scrolling though interface is disabled
GH . totalRedraw ( ) ;
2009-05-19 21:23:04 +03:00
else
2009-08-07 01:36:51 +03:00
GH . simpleRedraw ( ) ;
2009-05-19 21:23:04 +03:00
CGI - > curh - > draw1 ( ) ;
CSDL_Ext : : update ( screen ) ;
CGI - > curh - > draw2 ( ) ;
pim - > unlock ( ) ;
SDL_framerateDelay ( mainFPSmng ) ;
2008-01-26 21:36:31 +02:00
}
2009-05-19 21:23:04 +03:00
2009-08-11 19:05:33 +03:00
adventureInt - > deactivateKeys ( ) ;
2009-08-07 01:36:51 +03:00
GH . popInt ( adventureInt ) ;
2009-05-19 21:23:04 +03:00
cb - > endTurn ( ) ;
} HANDLE_EXCEPTION
2008-01-26 21:36:31 +02:00
}
2009-05-19 21:23:04 +03:00
inline void subRect ( const int & x , const int & y , const int & z , const SDL_Rect & r , const int & hid )
2008-01-26 21:36:31 +02:00
{
2009-05-19 21:23:04 +03:00
TerrainTile2 & hlp = CGI - > mh - > ttiles [ x ] [ y ] [ z ] ;
for ( int h = 0 ; h < hlp . objects . size ( ) ; + + h )
if ( hlp . objects [ h ] . first - > id = = hid )
{
hlp . objects [ h ] . second = r ;
return ;
}
2008-01-26 21:36:31 +02:00
}
2009-05-19 21:23:04 +03:00
inline void delObjRect ( const int & x , const int & y , const int & z , const int & hid )
2008-04-11 20:41:02 +03:00
{
2009-05-19 21:23:04 +03:00
TerrainTile2 & hlp = CGI - > mh - > ttiles [ x ] [ y ] [ z ] ;
for ( int h = 0 ; h < hlp . objects . size ( ) ; + + h )
if ( hlp . objects [ h ] . first - > id = = hid )
{
hlp . objects . erase ( hlp . objects . begin ( ) + h ) ;
return ;
}
2008-04-11 20:41:02 +03:00
}
2009-07-03 22:57:14 +03:00
void CPlayerInterface : : heroMoved ( const TryMoveHero & details )
2008-01-26 21:36:31 +02:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2009-07-03 22:57:14 +03:00
const CGHeroInstance * ho = cb - > getHeroInfo ( details . id ) ; //object representing this hero
2009-05-19 21:23:04 +03:00
2009-07-03 22:57:14 +03:00
adventureInt - > centerOn ( ho - > pos ) ; //actualizing screen pos
2009-05-19 21:23:04 +03:00
adventureInt - > minimap . draw ( screen2 ) ;
adventureInt - > heroList . draw ( screen2 ) ;
2009-07-03 22:57:14 +03:00
if ( details . result = = TryMoveHero : : TELEPORTATION | | details . start = = details . end )
2009-05-19 21:23:04 +03:00
return ;
2009-07-03 22:57:14 +03:00
int3 hp = details . start ;
2009-07-31 23:10:22 +03:00
if ( makingTurn & & ho - > tempOwner = = playerID ) //we are moving our hero
2008-08-02 18:08:03 +03:00
{
2009-07-31 23:10:22 +03:00
if ( details . result ! = TryMoveHero : : SUCCESS & & details . result ! = TryMoveHero : : FAILED ) //hero didn't change tile but visit succeeded
2008-01-26 21:36:31 +02:00
{
2009-06-11 20:21:06 +03:00
adventureInt - > paths . erase ( ho ) ;
2009-05-19 21:23:04 +03:00
adventureInt - > terrain . currentPath = NULL ;
2008-01-26 21:36:31 +02:00
}
2009-07-31 23:10:22 +03:00
else if ( adventureInt - > terrain . currentPath ) //&& hero is moving
{
//remove one node from the path (the one we went)
adventureInt - > terrain . currentPath - > nodes . erase ( adventureInt - > terrain . currentPath - > nodes . end ( ) - 1 ) ;
if ( ! adventureInt - > terrain . currentPath - > nodes . size ( ) ) //if it was the last one, remove entire path
{
adventureInt - > paths . erase ( ho ) ;
adventureInt - > terrain . currentPath = NULL ;
}
}
}
2009-07-03 22:57:14 +03:00
2009-07-31 23:10:22 +03:00
if ( details . result ! = TryMoveHero : : SUCCESS ) //hero failed to move
{
2009-07-03 22:57:14 +03:00
ho - > isStanding = true ;
2009-05-19 21:23:04 +03:00
stillMoveHero . setn ( STOP_MOVE ) ;
2009-08-07 01:36:51 +03:00
GH . totalRedraw ( ) ;
2009-05-19 21:23:04 +03:00
return ;
2008-01-26 21:36:31 +02:00
}
2009-05-19 21:23:04 +03:00
2009-07-31 23:10:22 +03:00
//initializing objects and performing first step of move
2009-07-03 22:57:14 +03:00
if ( details . end . x + 1 = = details . start . x & & details . end . y + 1 = = details . start . y ) //tl
2008-01-26 21:36:31 +02:00
{
2009-07-18 06:13:13 +03:00
//ho->moveDir = 1;
2009-05-19 21:23:04 +03:00
ho - > isStanding = false ;
CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 2 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , - 31 , - 31 ) ) ) ;
CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y - 2 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 1 , - 31 ) ) ) ;
CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y - 2 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 33 , - 31 ) ) ) ;
CGI - > mh - > ttiles [ hp . x ] [ hp . y - 2 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 65 , - 31 ) ) ) ;
CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , - 31 , 1 ) ) ) ;
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 1 , 1 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 33 , 1 ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 65 , 1 ) , ho - > id ) ;
CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , - 31 , 33 ) ) ) ;
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , 1 , 33 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 33 , 33 ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 65 , 33 ) , ho - > id ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 2 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 2 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y - 2 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y - 2 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y - 2 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y - 2 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x ] [ hp . y - 2 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x ] [ hp . y - 2 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2008-01-26 21:36:31 +02:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x = = details . start . x & & details . end . y + 1 = = details . start . y ) //t
2008-08-17 12:11:16 +03:00
{
2009-07-18 06:13:13 +03:00
//ho->moveDir = 2;
2009-05-19 21:23:04 +03:00
ho - > isStanding = false ;
CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y - 2 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 0 , - 31 ) ) ) ;
CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y - 2 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 32 , - 31 ) ) ) ;
CGI - > mh - > ttiles [ hp . x ] [ hp . y - 2 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 64 , - 31 ) ) ) ;
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 0 , 1 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 32 , 1 ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 64 , 1 ) , ho - > id ) ;
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , 0 , 33 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 32 , 33 ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 64 , 33 ) , ho - > id ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y - 2 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y - 2 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y - 2 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y - 2 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x ] [ hp . y - 2 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x ] [ hp . y - 2 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2008-08-17 12:11:16 +03:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x - 1 = = details . start . x & & details . end . y + 1 = = details . start . y ) //tr
2008-08-17 12:11:16 +03:00
{
2009-07-18 06:13:13 +03:00
//ho->moveDir = 3;
2009-05-19 21:23:04 +03:00
ho - > isStanding = false ;
CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y - 2 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , - 1 , - 31 ) ) ) ;
CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y - 2 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 31 , - 31 ) ) ) ;
CGI - > mh - > ttiles [ hp . x ] [ hp . y - 2 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 63 , - 31 ) ) ) ;
CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 2 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 95 , - 31 ) ) ) ;
2008-04-19 19:15:04 +03:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , - 1 , 1 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 31 , 1 ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 63 , 1 ) , ho - > id ) ;
CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 95 , 1 ) ) ) ;
2008-01-26 21:36:31 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , - 1 , 33 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 31 , 33 ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 63 , 33 ) , ho - > id ) ;
CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 95 , 33 ) ) ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y - 2 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y - 2 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y - 2 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y - 2 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x ] [ hp . y - 2 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x ] [ hp . y - 2 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 2 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 2 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2008-01-26 21:36:31 +02:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x - 1 = = details . start . x & & details . end . y = = details . start . y ) //r
2008-01-26 21:36:31 +02:00
{
2009-07-18 06:13:13 +03:00
//ho->moveDir = 4;
2009-05-19 21:23:04 +03:00
ho - > isStanding = false ;
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , - 1 , 0 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 31 , 0 ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 63 , 0 ) , ho - > id ) ;
CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 95 , 0 ) ) ) ;
2008-01-26 21:36:31 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , - 1 , 32 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 31 , 32 ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 63 , 32 ) , ho - > id ) ;
CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 95 , 32 ) ) ) ;
2009-04-11 04:32:50 +03:00
2009-05-19 21:23:04 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2009-04-11 04:32:50 +03:00
2009-05-19 21:23:04 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2008-08-15 15:11:42 +03:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x - 1 = = details . start . x & & details . end . y - 1 = = details . start . y ) //br
2008-08-16 11:47:41 +03:00
{
2009-07-18 06:13:13 +03:00
//ho->moveDir = 5;
2009-05-19 21:23:04 +03:00
ho - > isStanding = false ;
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , - 1 , - 1 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 31 , - 1 ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 63 , - 1 ) , ho - > id ) ;
CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 95 , - 1 ) ) ) ;
2008-03-06 20:54:35 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , - 1 , 31 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 31 , 31 ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 63 , 31 ) , ho - > id ) ;
CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 95 , 31 ) ) ) ;
2008-03-06 20:54:35 +02:00
2009-05-19 21:23:04 +03:00
CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , - 1 , 63 ) ) ) ;
CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y + 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 31 , 63 ) ) ) ;
CGI - > mh - > ttiles [ hp . x ] [ hp . y + 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 63 , 63 ) ) ) ;
CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y + 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 95 , 63 ) ) ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2008-03-06 20:54:35 +02:00
2009-05-19 21:23:04 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2008-02-23 00:26:31 +02:00
2009-05-19 21:23:04 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2007-11-24 00:33:55 +02:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x = = details . start . x & & details . end . y - 1 = = details . start . y ) //b
2009-03-14 13:25:25 +02:00
{
2009-07-18 06:13:13 +03:00
//ho->moveDir = 6;
2009-05-19 21:23:04 +03:00
ho - > isStanding = false ;
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 0 , - 1 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 32 , - 1 ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 64 , - 1 ) , ho - > id ) ;
2007-11-24 00:33:55 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , 0 , 31 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 32 , 31 ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 64 , 31 ) , ho - > id ) ;
2008-08-13 03:44:31 +03:00
2009-05-19 21:23:04 +03:00
CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 0 , 63 ) ) ) ;
CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y + 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 32 , 63 ) ) ) ;
CGI - > mh - > ttiles [ hp . x ] [ hp . y + 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 64 , 63 ) ) ) ;
2007-12-19 02:06:51 +02:00
2009-05-19 21:23:04 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2007-12-19 02:06:51 +02:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x + 1 = = details . start . x & & details . end . y - 1 = = details . start . y ) //bl
2007-11-24 00:33:55 +02:00
{
2009-07-18 06:13:13 +03:00
//ho->moveDir = 7;
2009-05-19 21:23:04 +03:00
ho - > isStanding = false ;
CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , - 31 , - 1 ) ) ) ;
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 1 , - 1 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 33 , - 1 ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 65 , - 1 ) , ho - > id ) ;
2007-11-24 00:33:55 +02:00
2009-05-19 21:23:04 +03:00
CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , - 31 , 31 ) ) ) ;
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , 1 , 31 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 33 , 31 ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 65 , 31 ) , ho - > id ) ;
2009-02-09 18:18:48 +02:00
2009-05-19 21:23:04 +03:00
CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y + 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , - 31 , 63 ) ) ) ;
CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 1 , 63 ) ) ) ;
CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y + 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 33 , 63 ) ) ) ;
CGI - > mh - > ttiles [ hp . x ] [ hp . y + 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , 65 , 63 ) ) ) ;
2009-04-11 04:32:50 +03:00
2009-05-19 21:23:04 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2009-02-09 18:18:48 +02:00
2009-05-19 21:23:04 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2009-04-11 04:32:50 +03:00
2009-05-19 21:23:04 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2008-08-02 18:08:03 +03:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x + 1 = = details . start . x & & details . end . y = = details . start . y ) //l
2009-05-19 21:23:04 +03:00
{
2009-07-18 06:13:13 +03:00
//ho->moveDir = 8;
2009-05-19 21:23:04 +03:00
ho - > isStanding = false ;
CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , - 31 , 0 ) ) ) ;
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 1 , 0 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 33 , 0 ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 65 , 0 ) , ho - > id ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . push_back ( std : : make_pair ( ho , genRect ( 32 , 32 , - 31 , 32 ) ) ) ;
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , 1 , 32 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 33 , 32 ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 65 , 32 ) , ho - > id ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2007-11-19 00:58:28 +02:00
}
2009-05-19 21:23:04 +03:00
//first initializing done
SDL_framerateDelay ( mainFPSmng ) ; // after first move
//main moving
2009-07-18 06:13:13 +03:00
for ( int i = 1 ; i < 32 ; i + = 2 * sysOpts . heroMoveSpeed )
2007-11-19 00:58:28 +02:00
{
2009-07-03 22:57:14 +03:00
if ( details . end . x + 1 = = details . start . x & & details . end . y + 1 = = details . start . y ) //tl
2009-05-19 21:23:04 +03:00
{
//setting advmap shift
adventureInt - > terrain . moveX = i - 32 ;
adventureInt - > terrain . moveY = i - 32 ;
2008-12-17 23:16:19 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 3 , hp . y - 2 , hp . z , genRect ( 32 , 32 , - 31 + i , - 31 + i ) , ho - > id ) ;
subRect ( hp . x - 2 , hp . y - 2 , hp . z , genRect ( 32 , 32 , 1 + i , - 31 + i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 2 , hp . z , genRect ( 32 , 32 , 33 + i , - 31 + i ) , ho - > id ) ;
subRect ( hp . x , hp . y - 2 , hp . z , genRect ( 32 , 32 , 65 + i , - 31 + i ) , ho - > id ) ;
2008-12-17 23:16:19 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 3 , hp . y - 1 , hp . z , genRect ( 32 , 32 , - 31 + i , 1 + i ) , ho - > id ) ;
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 1 + i , 1 + i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 33 + i , 1 + i ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 65 + i , 1 + i ) , ho - > id ) ;
2008-12-17 23:16:19 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 3 , hp . y , hp . z , genRect ( 32 , 32 , - 31 + i , 33 + i ) , ho - > id ) ;
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , 1 + i , 33 + i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 33 + i , 33 + i ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 65 + i , 33 + i ) , ho - > id ) ;
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x = = details . start . x & & details . end . y + 1 = = details . start . y ) //t
2009-05-19 21:23:04 +03:00
{
//setting advmap shift
adventureInt - > terrain . moveY = i - 32 ;
2008-12-17 23:16:19 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y - 2 , hp . z , genRect ( 32 , 32 , 0 , - 31 + i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 2 , hp . z , genRect ( 32 , 32 , 32 , - 31 + i ) , ho - > id ) ;
subRect ( hp . x , hp . y - 2 , hp . z , genRect ( 32 , 32 , 64 , - 31 + i ) , ho - > id ) ;
2008-12-17 23:16:19 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 0 , 1 + i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 32 , 1 + i ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 64 , 1 + i ) , ho - > id ) ;
2008-12-17 23:16:19 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , 0 , 33 + i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 32 , 33 + i ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 64 , 33 + i ) , ho - > id ) ;
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x - 1 = = details . start . x & & details . end . y + 1 = = details . start . y ) //tr
2009-05-19 21:23:04 +03:00
{
//setting advmap shift
adventureInt - > terrain . moveX = - i + 32 ;
adventureInt - > terrain . moveY = i - 32 ;
2008-12-17 23:16:19 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y - 2 , hp . z , genRect ( 32 , 32 , - 1 - i , - 31 + i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 2 , hp . z , genRect ( 32 , 32 , 31 - i , - 31 + i ) , ho - > id ) ;
subRect ( hp . x , hp . y - 2 , hp . z , genRect ( 32 , 32 , 63 - i , - 31 + i ) , ho - > id ) ;
subRect ( hp . x + 1 , hp . y - 2 , hp . z , genRect ( 32 , 32 , 95 - i , - 31 + i ) , ho - > id ) ;
2008-12-17 23:16:19 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , - 1 - i , 1 + i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 31 - i , 1 + i ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 63 - i , 1 + i ) , ho - > id ) ;
subRect ( hp . x + 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 95 - i , 1 + i ) , ho - > id ) ;
2008-12-17 23:16:19 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , - 1 - i , 33 + i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 31 - i , 33 + i ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 63 - i , 33 + i ) , ho - > id ) ;
subRect ( hp . x + 1 , hp . y , hp . z , genRect ( 32 , 32 , 95 - i , 33 + i ) , ho - > id ) ;
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x - 1 = = details . start . x & & details . end . y = = details . start . y ) //r
2009-05-19 21:23:04 +03:00
{
//setting advmap shift
adventureInt - > terrain . moveX = - i + 32 ;
2008-12-17 23:16:19 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , - 1 - i , 0 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 31 - i , 0 ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 63 - i , 0 ) , ho - > id ) ;
subRect ( hp . x + 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 95 - i , 0 ) , ho - > id ) ;
2008-12-17 23:16:19 +02:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , - 1 - i , 32 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 31 - i , 32 ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 63 - i , 32 ) , ho - > id ) ;
subRect ( hp . x + 1 , hp . y , hp . z , genRect ( 32 , 32 , 95 - i , 32 ) , ho - > id ) ;
2009-04-11 04:32:50 +03:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x - 1 = = details . start . x & & details . end . y - 1 = = details . start . y ) //br
2009-04-23 22:50:27 +03:00
{
2009-05-19 21:23:04 +03:00
//setting advmap shift
adventureInt - > terrain . moveX = - i + 32 ;
adventureInt - > terrain . moveY = - i + 32 ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , - 1 - i , - 1 - i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 31 - i , - 1 - i ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 63 - i , - 1 - i ) , ho - > id ) ;
subRect ( hp . x + 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 95 - i , - 1 - i ) , ho - > id ) ;
2009-04-12 03:58:41 +03:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , - 1 - i , 31 - i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 31 - i , 31 - i ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 63 - i , 31 - i ) , ho - > id ) ;
subRect ( hp . x + 1 , hp . y , hp . z , genRect ( 32 , 32 , 95 - i , 31 - i ) , ho - > id ) ;
2009-04-21 01:57:07 +03:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y + 1 , hp . z , genRect ( 32 , 32 , - 1 - i , 63 - i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y + 1 , hp . z , genRect ( 32 , 32 , 31 - i , 63 - i ) , ho - > id ) ;
subRect ( hp . x , hp . y + 1 , hp . z , genRect ( 32 , 32 , 63 - i , 63 - i ) , ho - > id ) ;
subRect ( hp . x + 1 , hp . y + 1 , hp . z , genRect ( 32 , 32 , 95 - i , 63 - i ) , ho - > id ) ;
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x = = details . start . x & & details . end . y - 1 = = details . start . y ) //b
2009-05-19 21:23:04 +03:00
{
//setting advmap shift
adventureInt - > terrain . moveY = - i + 32 ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 0 , - 1 - i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 32 , - 1 - i ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 64 , - 1 - i ) , ho - > id ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , 0 , 31 - i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 32 , 31 - i ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 64 , 31 - i ) , ho - > id ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 2 , hp . y + 1 , hp . z , genRect ( 32 , 32 , 0 , 63 - i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y + 1 , hp . z , genRect ( 32 , 32 , 32 , 63 - i ) , ho - > id ) ;
subRect ( hp . x , hp . y + 1 , hp . z , genRect ( 32 , 32 , 64 , 63 - i ) , ho - > id ) ;
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x + 1 = = details . start . x & & details . end . y - 1 = = details . start . y ) //bl
2009-05-19 21:23:04 +03:00
{
//setting advmap shift
adventureInt - > terrain . moveX = i - 32 ;
adventureInt - > terrain . moveY = - i + 32 ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 3 , hp . y - 1 , hp . z , genRect ( 32 , 32 , - 31 + i , - 1 - i ) , ho - > id ) ;
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 1 + i , - 1 - i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 33 + i , - 1 - i ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 65 + i , - 1 - i ) , ho - > id ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 3 , hp . y , hp . z , genRect ( 32 , 32 , - 31 + i , 31 - i ) , ho - > id ) ;
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , 1 + i , 31 - i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 33 + i , 31 - i ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 65 + i , 31 - i ) , ho - > id ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 3 , hp . y + 1 , hp . z , genRect ( 32 , 32 , - 31 + i , 63 - i ) , ho - > id ) ;
subRect ( hp . x - 2 , hp . y + 1 , hp . z , genRect ( 32 , 32 , 1 + i , 63 - i ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y + 1 , hp . z , genRect ( 32 , 32 , 33 + i , 63 - i ) , ho - > id ) ;
subRect ( hp . x , hp . y + 1 , hp . z , genRect ( 32 , 32 , 65 + i , 63 - i ) , ho - > id ) ;
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x + 1 = = details . start . x & & details . end . y = = details . start . y ) //l
2009-05-19 21:23:04 +03:00
{
//setting advmap shift
adventureInt - > terrain . moveX = i - 32 ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 3 , hp . y - 1 , hp . z , genRect ( 32 , 32 , - 31 + i , 0 ) , ho - > id ) ;
subRect ( hp . x - 2 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 1 + i , 0 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y - 1 , hp . z , genRect ( 32 , 32 , 33 + i , 0 ) , ho - > id ) ;
subRect ( hp . x , hp . y - 1 , hp . z , genRect ( 32 , 32 , 65 + i , 0 ) , ho - > id ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
subRect ( hp . x - 3 , hp . y , hp . z , genRect ( 32 , 32 , - 31 + i , 32 ) , ho - > id ) ;
subRect ( hp . x - 2 , hp . y , hp . z , genRect ( 32 , 32 , 1 + i , 32 ) , ho - > id ) ;
subRect ( hp . x - 1 , hp . y , hp . z , genRect ( 32 , 32 , 33 + i , 32 ) , ho - > id ) ;
subRect ( hp . x , hp . y , hp . z , genRect ( 32 , 32 , 65 + i , 32 ) , ho - > id ) ;
}
adventureInt - > updateScreen = true ;
adventureInt - > show ( screen ) ;
//LOCPLINT->adventureInt->show(); //updating screen
CSDL_Ext : : update ( screen ) ;
2008-01-31 23:35:30 +02:00
2009-05-19 21:23:04 +03:00
SDL_Delay ( 5 ) ;
SDL_framerateDelay ( mainFPSmng ) ; //for animation purposes
} //for(int i=1; i<32; i+=4)
//main moving done
//finishing move
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
//restoring adventureInt->terrain.move*
adventureInt - > terrain . moveX = adventureInt - > terrain . moveY = 0 ;
2009-04-14 15:47:09 +03:00
2009-07-03 22:57:14 +03:00
if ( details . end . x + 1 = = details . start . x & & details . end . y + 1 = = details . start . y ) //tl
2008-02-15 20:40:58 +02:00
{
2009-05-19 21:23:04 +03:00
delObjRect ( hp . x , hp . y - 2 , hp . z , ho - > id ) ;
delObjRect ( hp . x , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x , hp . y , hp . z , ho - > id ) ;
delObjRect ( hp . x - 1 , hp . y , hp . z , ho - > id ) ;
delObjRect ( hp . x - 2 , hp . y , hp . z , ho - > id ) ;
delObjRect ( hp . x - 3 , hp . y , hp . z , ho - > id ) ;
2008-02-15 20:40:58 +02:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x = = details . start . x & & details . end . y + 1 = = details . start . y ) //t
2009-02-06 17:56:03 +02:00
{
2009-05-19 21:23:04 +03:00
delObjRect ( hp . x , hp . y , hp . z , ho - > id ) ;
delObjRect ( hp . x - 1 , hp . y , hp . z , ho - > id ) ;
delObjRect ( hp . x - 2 , hp . y , hp . z , ho - > id ) ;
2009-02-06 17:56:03 +02:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x - 1 = = details . start . x & & details . end . y + 1 = = details . start . y ) //tr
2009-02-06 17:56:03 +02:00
{
2009-05-19 21:23:04 +03:00
delObjRect ( hp . x - 2 , hp . y - 2 , hp . z , ho - > id ) ;
delObjRect ( hp . x - 2 , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x + 1 , hp . y , hp . z , ho - > id ) ;
delObjRect ( hp . x , hp . y , hp . z , ho - > id ) ;
delObjRect ( hp . x - 1 , hp . y , hp . z , ho - > id ) ;
delObjRect ( hp . x - 2 , hp . y , hp . z , ho - > id ) ;
2009-02-06 17:56:03 +02:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x - 1 = = details . start . x & & details . end . y = = details . start . y ) //r
2008-01-31 23:35:30 +02:00
{
2009-05-19 21:23:04 +03:00
delObjRect ( hp . x - 2 , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x - 2 , hp . y , hp . z , ho - > id ) ;
2008-01-31 23:35:30 +02:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x - 1 = = details . start . x & & details . end . y - 1 = = details . start . y ) //br
2008-01-31 23:35:30 +02:00
{
2009-05-19 21:23:04 +03:00
delObjRect ( hp . x - 2 , hp . y + 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x - 2 , hp . y , hp . z , ho - > id ) ;
delObjRect ( hp . x + 1 , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x - 1 , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x - 2 , hp . y - 1 , hp . z , ho - > id ) ;
2008-01-31 23:35:30 +02:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x = = details . start . x & & details . end . y - 1 = = details . start . y ) //b
2008-01-31 23:35:30 +02:00
{
2009-05-19 21:23:04 +03:00
delObjRect ( hp . x , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x - 1 , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x - 2 , hp . y - 1 , hp . z , ho - > id ) ;
2008-01-31 23:35:30 +02:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x + 1 = = details . start . x & & details . end . y - 1 = = details . start . y ) //bl
2008-01-31 23:35:30 +02:00
{
2009-05-19 21:23:04 +03:00
delObjRect ( hp . x , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x - 1 , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x - 2 , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x - 3 , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x , hp . y , hp . z , ho - > id ) ;
delObjRect ( hp . x , hp . y + 1 , hp . z , ho - > id ) ;
2008-01-31 23:35:30 +02:00
}
2009-07-03 22:57:14 +03:00
else if ( details . end . x + 1 = = details . start . x & & details . end . y = = details . start . y ) //l
2008-01-31 23:35:30 +02:00
{
2009-05-19 21:23:04 +03:00
delObjRect ( hp . x , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x , hp . y , hp . z , ho - > id ) ;
2008-01-31 23:35:30 +02:00
}
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
//restoring good rects
2009-07-03 22:57:14 +03:00
subRect ( details . end . x - 2 , details . end . y - 1 , details . end . z , genRect ( 32 , 32 , 0 , 0 ) , ho - > id ) ;
subRect ( details . end . x - 1 , details . end . y - 1 , details . end . z , genRect ( 32 , 32 , 32 , 0 ) , ho - > id ) ;
subRect ( details . end . x , details . end . y - 1 , details . end . z , genRect ( 32 , 32 , 64 , 0 ) , ho - > id ) ;
2009-04-14 15:47:09 +03:00
2009-07-03 22:57:14 +03:00
subRect ( details . end . x - 2 , details . end . y , details . end . z , genRect ( 32 , 32 , 0 , 32 ) , ho - > id ) ;
subRect ( details . end . x - 1 , details . end . y , details . end . z , genRect ( 32 , 32 , 32 , 32 ) , ho - > id ) ;
subRect ( details . end . x , details . end . y , details . end . z , genRect ( 32 , 32 , 64 , 32 ) , ho - > id ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
//restoring good order of objects
2009-07-03 22:57:14 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ details . end . x - 2 ] [ details . end . y - 1 ] [ details . end . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ details . end . x - 2 ] [ details . end . y - 1 ] [ details . end . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ details . end . x - 1 ] [ details . end . y - 1 ] [ details . end . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ details . end . x - 1 ] [ details . end . y - 1 ] [ details . end . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ details . end . x ] [ details . end . y - 1 ] [ details . end . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ details . end . x ] [ details . end . y - 1 ] [ details . end . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2009-04-14 15:47:09 +03:00
2009-07-03 22:57:14 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ details . end . x - 2 ] [ details . end . y ] [ details . end . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ details . end . x - 2 ] [ details . end . y ] [ details . end . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ details . end . x - 1 ] [ details . end . y ] [ details . end . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ details . end . x - 1 ] [ details . end . y ] [ details . end . z ] . objects . end ( ) , ocmptwo_cgin ) ;
std : : stable_sort ( CGI - > mh - > ttiles [ details . end . x ] [ details . end . y ] [ details . end . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ details . end . x ] [ details . end . y ] [ details . end . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
ho - > isStanding = true ;
//move finished
adventureInt - > minimap . draw ( screen2 ) ;
adventureInt - > heroList . updateMove ( ho ) ;
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
//check if user cancelled movement
2008-01-31 23:35:30 +02:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : mutex > un ( eventsM ) ;
while ( events . size ( ) )
2008-01-31 23:35:30 +02:00
{
2009-05-19 21:23:04 +03:00
SDL_Event * ev = events . front ( ) ;
events . pop ( ) ;
switch ( ev - > type )
{
case SDL_MOUSEBUTTONDOWN :
stillMoveHero . setn ( STOP_MOVE ) ;
break ;
case SDL_KEYDOWN :
2009-07-19 04:00:19 +03:00
if ( ev - > key . keysym . sym < SDLK_F1 | | ev - > key . keysym . sym > SDLK_F15 )
2009-05-19 21:23:04 +03:00
stillMoveHero . setn ( STOP_MOVE ) ;
break ;
}
delete ev ;
2008-01-31 23:35:30 +02:00
}
}
2008-05-18 20:33:39 +03:00
2009-08-07 01:36:51 +03:00
if ( stillMoveHero . get ( ) = = WAITING_MOVE )
2009-05-19 21:23:04 +03:00
stillMoveHero . setn ( DURING_MOVE ) ;
2008-05-18 20:33:39 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : heroKilled ( const CGHeroInstance * hero )
2008-05-18 20:33:39 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
graphics - > heroWins . erase ( hero - > ID ) ;
2009-06-11 20:21:06 +03:00
wanderingHeroes - = hero ;
2009-05-19 21:23:04 +03:00
adventureInt - > heroList . updateHList ( hero ) ;
2008-05-18 20:33:39 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : heroCreated ( const CGHeroInstance * hero )
2008-05-18 20:33:39 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
if ( graphics - > heroWins . find ( hero - > subID ) = = graphics - > heroWins . end ( ) )
graphics - > heroWins . insert ( std : : pair < int , SDL_Surface * > ( hero - > subID , infoWin ( hero ) ) ) ;
2009-06-11 20:21:06 +03:00
wanderingHeroes . push_back ( hero ) ;
2009-05-19 21:23:04 +03:00
adventureInt - > heroList . updateHList ( ) ;
2008-05-18 20:33:39 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : openTownWindow ( const CGTownInstance * town )
2008-05-18 20:33:39 +03:00
{
2009-05-19 21:23:04 +03:00
castleInt = new CCastleInterface ( town ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( castleInt ) ;
2008-05-18 20:33:39 +03:00
}
2009-05-19 21:23:04 +03:00
SDL_Surface * CPlayerInterface : : infoWin ( const CGObjectInstance * specific ) //specific=0 => draws info about selected town/hero
2008-05-18 20:33:39 +03:00
{
2009-05-19 21:23:04 +03:00
if ( specific )
2008-05-18 20:33:39 +03:00
{
2009-05-19 21:23:04 +03:00
switch ( specific - > ID )
2008-05-18 20:33:39 +03:00
{
2009-05-19 21:23:04 +03:00
case HEROI_TYPE :
return graphics - > drawHeroInfoWin ( dynamic_cast < const CGHeroInstance * > ( specific ) ) ;
break ;
case TOWNI_TYPE :
return graphics - > drawTownInfoWin ( dynamic_cast < const CGTownInstance * > ( specific ) ) ;
break ;
default :
return NULL ;
break ;
2008-05-18 20:33:39 +03:00
}
}
else
{
2009-05-19 21:23:04 +03:00
switch ( adventureInt - > selection - > ID )
2008-05-18 20:33:39 +03:00
{
2009-05-19 21:23:04 +03:00
case HEROI_TYPE :
2008-05-18 20:33:39 +03:00
{
2009-05-19 21:23:04 +03:00
const CGHeroInstance * curh = ( const CGHeroInstance * ) adventureInt - > selection ;
return graphics - > drawHeroInfoWin ( curh ) ;
2008-05-18 20:33:39 +03:00
}
2009-05-19 21:23:04 +03:00
case TOWNI_TYPE :
2008-05-18 20:33:39 +03:00
{
2009-05-19 21:23:04 +03:00
return graphics - > drawTownInfoWin ( ( const CGTownInstance * ) adventureInt - > selection ) ;
2008-05-18 20:33:39 +03:00
}
2009-05-19 21:23:04 +03:00
default :
tlog1 < < " Strange... selection is neither hero nor town \n " ;
return NULL ;
2008-05-18 20:33:39 +03:00
}
}
}
2009-05-19 21:23:04 +03:00
int3 CPlayerInterface : : repairScreenPos ( int3 pos )
2008-05-18 20:33:39 +03:00
{
2009-06-14 10:02:06 +03:00
if ( pos . x < - CGI - > mh - > frameW )
pos . x = - CGI - > mh - > frameW ;
if ( pos . y < - CGI - > mh - > frameH )
pos . y = - CGI - > mh - > frameH ;
if ( pos . x > CGI - > mh - > map - > width - this - > adventureInt - > terrain . tilesw + CGI - > mh - > frameW )
pos . x = CGI - > mh - > map - > width - this - > adventureInt - > terrain . tilesw + CGI - > mh - > frameW ;
if ( pos . y > CGI - > mh - > map - > height - this - > adventureInt - > terrain . tilesh + CGI - > mh - > frameH )
pos . y = CGI - > mh - > map - > height - this - > adventureInt - > terrain . tilesh + CGI - > mh - > frameH ;
2009-05-19 21:23:04 +03:00
return pos ;
2008-05-18 20:33:39 +03:00
}
2009-08-16 18:39:18 +03:00
void CPlayerInterface : : heroPrimarySkillChanged ( const CGHeroInstance * hero , int which , si64 val )
2008-05-18 20:33:39 +03:00
{
2009-05-19 21:23:04 +03:00
if ( which > = PRIMARY_SKILLS ) //no need to redraw infowin if this is experience (exp is treated as prim skill with id==4)
2008-05-18 20:33:39 +03:00
return ;
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
redrawHeroWin ( hero ) ;
2008-05-18 20:33:39 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : heroManaPointsChanged ( const CGHeroInstance * hero )
2008-05-31 23:37:54 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
redrawHeroWin ( hero ) ;
2008-05-31 23:37:54 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : heroMovePointsChanged ( const CGHeroInstance * hero )
2008-05-18 20:33:39 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
//adventureInt->heroList.draw();
2008-05-18 20:33:39 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : receivedResource ( int type , int val )
2008-05-18 20:33:39 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2009-08-07 01:36:51 +03:00
GH . totalRedraw ( ) ;
2008-05-27 16:16:35 +03:00
}
2008-08-13 03:44:31 +03:00
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : heroGotLevel ( const CGHeroInstance * hero , int pskill , std : : vector < ui16 > & skills , boost : : function < void ( ui32 ) > & callback )
2008-08-13 03:44:31 +03:00
{
2009-07-21 02:34:06 +03:00
waitWhileDialog ( ) ;
2009-05-22 07:14:59 +03:00
CGI - > soundh - > playSound ( soundBase : : heroNewLevel ) ;
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
CLevelWindow * lw = new CLevelWindow ( hero , pskill , skills , callback ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( lw ) ;
2009-05-19 21:23:04 +03:00
}
void CPlayerInterface : : heroInGarrisonChange ( const CGTownInstance * town )
2008-08-13 03:44:31 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
//redraw infowindow
SDL_FreeSurface ( graphics - > townWins [ town - > id ] ) ;
graphics - > townWins [ town - > id ] = infoWin ( town ) ;
2009-06-11 20:21:06 +03:00
if ( town - > garrisonHero & & vstd : : contains ( wanderingHeroes , town - > garrisonHero ) ) //wandering hero moved to the garrison
2009-02-14 15:51:21 +02:00
{
2009-05-19 21:23:04 +03:00
CGI - > mh - > hideObject ( town - > garrisonHero ) ;
2009-06-11 20:21:06 +03:00
wanderingHeroes - = town - > garrisonHero ;
2009-02-04 05:55:12 +02:00
}
2009-06-11 20:21:06 +03:00
if ( town - > visitingHero & & ! vstd : : contains ( wanderingHeroes , town - > visitingHero ) ) //hero leaves garrison
2008-08-13 03:44:31 +03:00
{
2009-05-19 21:23:04 +03:00
CGI - > mh - > printObject ( town - > visitingHero ) ;
2009-06-11 20:21:06 +03:00
wanderingHeroes . push_back ( town - > visitingHero ) ;
2008-08-13 03:44:31 +03:00
}
2009-06-11 20:21:06 +03:00
//adventureInt->heroList.updateHList();
2009-02-14 16:37:13 +02:00
2009-05-19 21:23:04 +03:00
CCastleInterface * c = castleInt ;
if ( c )
2009-02-14 16:37:13 +02:00
{
2009-05-19 21:23:04 +03:00
c - > garr - > highlighted = NULL ;
c - > hslotup . hero = town - > garrisonHero ;
c - > garr - > odown = c - > hslotdown . hero = town - > visitingHero ;
c - > garr - > set2 = town - > visitingHero ? & town - > visitingHero - > army : NULL ;
c - > garr - > recreateSlots ( ) ;
2009-02-14 16:37:13 +02:00
}
2009-08-07 01:36:51 +03:00
GH . totalRedraw ( ) ;
2008-08-13 03:44:31 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : heroVisitsTown ( const CGHeroInstance * hero , const CGTownInstance * town )
2008-08-13 03:44:31 +03:00
{
2009-05-19 21:23:04 +03:00
if ( hero - > tempOwner ! = town - > tempOwner )
return ;
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
openTownWindow ( town ) ;
2008-08-17 12:11:16 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : garrisonChanged ( const CGObjectInstance * obj )
2008-08-17 12:11:16 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
if ( obj - > ID = = HEROI_TYPE ) //hero
2008-08-17 12:11:16 +03:00
{
2009-05-19 21:23:04 +03:00
const CGHeroInstance * hh ;
if ( hh = dynamic_cast < const CGHeroInstance * > ( obj ) )
{
SDL_FreeSurface ( graphics - > heroWins [ hh - > subID ] ) ;
graphics - > heroWins [ hh - > subID ] = infoWin ( hh ) ;
}
2008-08-17 12:11:16 +03:00
}
2009-05-19 21:23:04 +03:00
else if ( obj - > ID = = TOWNI_TYPE ) //town
{
const CGTownInstance * tt ;
if ( tt = static_cast < const CGTownInstance * > ( obj ) )
{
SDL_FreeSurface ( graphics - > townWins [ tt - > id ] ) ;
graphics - > townWins [ tt - > id ] = infoWin ( tt ) ;
}
if ( tt - > visitingHero )
{
SDL_FreeSurface ( graphics - > heroWins [ tt - > visitingHero - > subID ] ) ;
graphics - > heroWins [ tt - > visitingHero - > subID ] = infoWin ( tt - > visitingHero ) ;
}
2009-04-14 15:47:09 +03:00
2009-05-19 21:23:04 +03:00
}
2008-08-27 13:19:18 +03:00
2009-05-19 21:23:04 +03:00
bool wasGarrison = false ;
2009-08-07 01:36:51 +03:00
for ( std : : list < IShowActivable * > : : iterator i = GH . listInt . begin ( ) ; i ! = GH . listInt . end ( ) ; i + + )
2009-05-19 21:23:04 +03:00
{
if ( ( * i ) - > type & IShowActivable : : WITH_GARRISON )
{
CWindowWithGarrison * wwg = static_cast < CWindowWithGarrison * > ( * i ) ;
wwg - > garr - > recreateSlots ( ) ;
wasGarrison = true ;
}
}
2009-08-07 01:36:51 +03:00
GH . totalRedraw ( ) ;
2008-08-27 13:19:18 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : buildChanged ( const CGTownInstance * town , int buildingID , int what ) //what: 1 - built, 2 - demolished
2008-08-27 13:19:18 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
switch ( buildingID )
{
case 7 : case 8 : case 9 : case 10 : case 11 : case 12 : case 13 : case 15 :
{
SDL_FreeSurface ( graphics - > townWins [ town - > id ] ) ;
graphics - > townWins [ town - > id ] = infoWin ( town ) ;
break ;
}
}
if ( ! castleInt )
return ;
if ( castleInt - > town ! = town )
return ;
switch ( what )
{
case 1 :
2009-05-22 07:14:59 +03:00
CGI - > soundh - > playSound ( soundBase : : newBuilding ) ;
2009-05-19 21:23:04 +03:00
castleInt - > addBuilding ( buildingID ) ;
break ;
case 2 :
castleInt - > removeBuilding ( buildingID ) ;
break ;
}
2008-08-27 13:19:18 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : battleStart ( CCreatureSet * army1 , CCreatureSet * army2 , int3 tile , CGHeroInstance * hero1 , CGHeroInstance * hero2 , bool side ) //called by engine when battle starts; side=0 - left, side=1 - right
2008-08-27 13:19:18 +03:00
{
2009-05-19 21:23:04 +03:00
while ( showingDialog - > get ( ) )
SDL_Delay ( 20 ) ;
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
battleInt = new CBattleInterface ( army1 , army2 , hero1 , hero2 , genRect ( 600 , 800 , ( conf . cc . resx - 800 ) / 2 , ( conf . cc . resy - 600 ) / 2 ) ) ;
2009-05-22 07:14:59 +03:00
CGI - > musich - > playMusicFromSet ( CGI - > musich - > battleMusics , - 1 ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( battleInt ) ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : battlefieldPrepared ( int battlefieldType , std : : vector < CObstacle * > obstacles ) //called when battlefield is prepared, prior the battle beginning
2008-09-07 06:38:37 +03:00
{
}
2009-08-06 08:08:17 +03:00
void CPlayerInterface : : battleStacksHealedRes ( const std : : vector < std : : pair < ui32 , ui32 > > & healedStacks )
2009-08-05 15:46:08 +03:00
{
for ( int b = 0 ; b < healedStacks . size ( ) ; + + b )
{
const CStack * healed = cb - > battleGetStackByID ( healedStacks [ b ] . first ) ;
if ( battleInt - > creAnims [ healed - > ID ] - > getType ( ) = = 5 )
{
//stack has been resurrected
battleInt - > creAnims [ healed - > ID ] - > setType ( 2 ) ;
}
}
}
2009-08-06 17:02:21 +03:00
void CPlayerInterface : : battleNewStackAppeared ( int stackID )
{
//changing necessary things in battle interface
2009-08-07 12:45:21 +03:00
battleInt - > newStack ( stackID ) ;
2009-08-06 17:02:21 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : battleNewRound ( int round ) //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
battleInt - > newRound ( round ) ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : actionStarted ( const BattleAction * action )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
curAction = new BattleAction ( * action ) ;
if ( ( action - > actionType = = 2 | | ( action - > actionType = = 6 & & action - > destinationTile ! = cb - > battleGetPos ( action - > stackNumber ) ) ) )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
battleInt - > moveStarted = true ;
if ( battleInt - > creAnims [ action - > stackNumber ] - > framesInGroup ( 20 ) )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
battleInt - > creAnims [ action - > stackNumber ] - > setType ( 20 ) ;
2008-09-07 06:38:37 +03:00
}
}
2009-05-19 21:23:04 +03:00
battleInt - > deactivate ( ) ;
2008-09-07 06:38:37 +03:00
2009-08-04 20:05:49 +03:00
const CStack * stack = cb - > battleGetStackByID ( action - > stackNumber ) ;
2009-05-19 21:23:04 +03:00
char txt [ 400 ] ;
if ( action - > actionType = = 1 )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
if ( action - > side )
battleInt - > defendingHero - > setPhase ( 4 ) ;
else
battleInt - > attackingHero - > setPhase ( 4 ) ;
return ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
if ( ! stack )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
tlog1 < < " Something wrong with stackNumber in actionStarted. Stack number: " < < action - > stackNumber < < std : : endl ;
return ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
int txtid = 0 ;
switch ( action - > actionType )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
case 3 : //defend
txtid = 120 ;
break ;
case 8 : //wait
txtid = 136 ;
break ;
case 11 : //bad morale
txtid = - 34 ; //negative -> no separate singular/plural form
battleInt - > displayEffect ( 30 , stack - > position ) ;
break ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
if ( txtid > 0 & & stack - > amount ! = 1 )
txtid + + ; //move to plural text
else if ( txtid < 0 )
txtid = - txtid ;
2008-09-07 06:38:37 +03:00
2009-05-19 21:23:04 +03:00
if ( txtid )
{
sprintf ( txt , CGI - > generaltexth - > allTexts [ txtid ] . c_str ( ) , ( stack - > amount ! = 1 ) ? stack - > creature - > namePl . c_str ( ) : stack - > creature - > nameSing . c_str ( ) , 0 ) ;
LOCPLINT - > battleInt - > console - > addText ( txt ) ;
}
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : actionFinished ( const BattleAction * action )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
delete curAction ;
curAction = NULL ;
//if((action->actionType==2 || (action->actionType==6 && action->destinationTile!=cb->battleGetPos(action->stackNumber)))) //activating interface when move is finished
{
battleInt - > activate ( ) ;
}
if ( action - > actionType = = 1 )
{
if ( action - > side )
battleInt - > defendingHero - > setPhase ( 0 ) ;
else
battleInt - > attackingHero - > setPhase ( 0 ) ;
}
2009-08-03 17:29:29 +03:00
if ( action - > actionType = = 6 | | action - > actionType = = 2 & & battleInt - > creAnims [ action - > stackNumber ] - > getType ( ) ! = 2 ) //walk or walk & attack
{
battleInt - > handleEndOfMove ( action - > stackNumber , action - > destinationTile ) ;
}
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
BattleAction CPlayerInterface : : activeStack ( int stackID ) //called when it's turn of that stack
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
CBattleInterface * b = battleInt ;
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2009-08-04 20:05:49 +03:00
const CStack * stack = cb - > battleGetStackByID ( stackID ) ;
2009-05-19 21:23:04 +03:00
if ( vstd : : contains ( stack - > state , MOVED ) ) //this stack has moved and makes second action -> high morale
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
std : : string hlp = CGI - > generaltexth - > allTexts [ 33 ] ;
boost : : algorithm : : replace_first ( hlp , " %s " , ( stack - > amount ! = 1 ) ? stack - > creature - > namePl : stack - > creature - > nameSing ) ;
battleInt - > displayEffect ( 20 , stack - > position ) ;
battleInt - > console - > addText ( hlp ) ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
b - > stackActivated ( stackID ) ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
//wait till BattleInterface sets its command
boost : : unique_lock < boost : : mutex > lock ( b - > givenCommand - > mx ) ;
while ( ! b - > givenCommand - > data )
b - > givenCommand - > cond . wait ( lock ) ;
//tidy up
BattleAction ret = * ( b - > givenCommand - > data ) ;
delete b - > givenCommand - > data ;
b - > givenCommand - > data = NULL ;
//return command
return ret ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : battleEnd ( BattleResult * br )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
battleInt - > battleFinished ( * br ) ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : battleStackMoved ( int ID , int dest , int distance , bool end )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
battleInt - > stackMoved ( ID , dest , end , distance ) ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : battleSpellCast ( SpellCast * sc )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
battleInt - > spellCast ( sc ) ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : battleStacksEffectsSet ( SetStackEffect & sse )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
battleInt - > battleStacksEffectsSet ( sse ) ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : battleStacksAttacked ( std : : set < BattleStackAttacked > & bsa )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
tlog5 < < " CPlayerInterface::battleStackAttacked - locking... " ;
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
tlog5 < < " done! \n " ;
2008-09-07 06:38:37 +03:00
2009-05-19 21:23:04 +03:00
std : : vector < CBattleInterface : : SStackAttackedInfo > arg ;
for ( std : : set < BattleStackAttacked > : : iterator i = bsa . begin ( ) ; i ! = bsa . end ( ) ; i + + )
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
if ( i - > isEffect ( ) & & i - > effect ! = 12 ) //and not armageddon
2008-09-07 06:38:37 +03:00
{
2009-05-19 21:23:04 +03:00
battleInt - > displayEffect ( i - > effect , cb - > battleGetStackByID ( i - > stackAttacked ) - > position ) ;
2008-09-07 06:38:37 +03:00
}
2009-05-19 21:23:04 +03:00
CBattleInterface : : SStackAttackedInfo to_put = { i - > stackAttacked , i - > damageAmount , i - > killedAmount , LOCPLINT - > curAction - > stackNumber , LOCPLINT - > curAction - > actionType = = 7 , i - > killed ( ) } ;
arg . push_back ( to_put ) ;
}
if ( bsa . begin ( ) - > isEffect ( ) & & bsa . begin ( ) - > effect = = 12 ) //for armageddon - I hope this condition is enough
{
battleInt - > displayEffect ( bsa . begin ( ) - > effect , - 1 ) ;
2008-09-07 06:38:37 +03:00
}
2008-09-25 17:09:31 +03:00
2009-05-19 21:23:04 +03:00
battleInt - > stacksAreAttacked ( arg ) ;
}
void CPlayerInterface : : battleAttack ( BattleAttack * ba )
2008-09-25 17:09:31 +03:00
{
2009-05-19 21:23:04 +03:00
tlog5 < < " CPlayerInterface::battleAttack - locking... " ;
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
tlog5 < < " done! \n " ;
2009-06-02 01:31:11 +03:00
assert ( curAction ) ;
2009-05-19 21:23:04 +03:00
if ( ba - > lucky ( ) ) //lucky hit
2009-05-06 13:14:48 +03:00
{
2009-08-04 20:05:49 +03:00
const CStack * stack = cb - > battleGetStackByID ( ba - > stackAttacking ) ;
2009-05-19 21:23:04 +03:00
std : : string hlp = CGI - > generaltexth - > allTexts [ 45 ] ;
boost : : algorithm : : replace_first ( hlp , " %s " , ( stack - > amount ! = 1 ) ? stack - > creature - > namePl . c_str ( ) : stack - > creature - > nameSing . c_str ( ) ) ;
battleInt - > console - > addText ( hlp ) ;
battleInt - > displayEffect ( 18 , stack - > position ) ;
2009-05-06 13:14:48 +03:00
}
2009-05-19 21:23:04 +03:00
//TODO: bad luck?
2009-05-06 13:14:48 +03:00
2009-05-19 21:23:04 +03:00
if ( ba - > shot ( ) )
{
for ( std : : set < BattleStackAttacked > : : iterator i = ba - > bsa . begin ( ) ; i ! = ba - > bsa . end ( ) ; i + + )
battleInt - > stackIsShooting ( ba - > stackAttacking , cb - > battleGetPos ( i - > stackAttacked ) ) ;
}
else
2009-05-08 05:58:41 +03:00
{
2009-08-04 20:05:49 +03:00
const CStack * attacker = cb - > battleGetStackByID ( ba - > stackAttacking ) ;
2009-05-19 21:23:04 +03:00
int shift = 0 ;
if ( ba - > counter ( ) & & BattleInfo : : mutualPosition ( curAction - > destinationTile , attacker - > position ) < 0 )
{
if ( attacker - > attackerOwned )
shift = 1 ;
else
shift = - 1 ;
}
battleInt - > stackAttacking ( ba - > stackAttacking , ba - > counter ( ) ? curAction - > destinationTile + shift : curAction - > additionalInfo ) ;
2009-05-08 05:58:41 +03:00
}
2008-09-25 17:09:31 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : showComp ( SComponent comp )
2008-09-25 17:09:31 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2009-05-22 07:14:59 +03:00
CGI - > soundh - > playSoundFromSet ( CGI - > soundh - > pickupSounds ) ;
2009-05-19 21:23:04 +03:00
adventureInt - > infoBar . showComp ( & comp , 4000 ) ;
2008-09-25 17:09:31 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : showInfoDialog ( const std : : string & text , const std : : vector < Component * > & components , int soundID )
2008-09-25 17:09:31 +03:00
{
2009-05-19 21:23:04 +03:00
std : : vector < SComponent * > intComps ;
for ( int i = 0 ; i < components . size ( ) ; i + + )
intComps . push_back ( new SComponent ( * components [ i ] ) ) ;
showInfoDialog ( text , intComps , soundID ) ;
2008-09-25 17:09:31 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : showInfoDialog ( const std : : string & text , const std : : vector < SComponent * > & components , int soundID )
2008-09-25 17:09:31 +03:00
{
2009-07-21 02:34:06 +03:00
waitWhileDialog ( ) ;
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
if ( stillMoveHero . get ( ) = = DURING_MOVE ) //if we are in the middle of hero movement
stillMoveHero . setn ( STOP_MOVE ) ; //after showing dialog movement will be stopped
2009-03-28 02:38:48 +02:00
2009-05-19 21:23:04 +03:00
std : : vector < std : : pair < std : : string , CFunctionList < void ( ) > > > pom ;
pom . push_back ( std : : pair < std : : string , CFunctionList < void ( ) > > ( " IOKAY.DEF " , 0 ) ) ;
2009-06-02 05:15:23 +03:00
CInfoWindow * temp = new CInfoWindow ( text , playerID , 0 , components , pom , false ) ;
2009-03-28 02:38:48 +02:00
2009-08-07 01:36:51 +03:00
if ( makingTurn & & GH . listInt . size ( ) )
2009-05-19 21:23:04 +03:00
{
2009-05-22 07:14:59 +03:00
CGI - > soundh - > playSound ( static_cast < soundBase : : soundID > ( soundID ) ) ;
2009-05-19 21:23:04 +03:00
showingDialog - > set ( true ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( temp ) ;
2009-05-19 21:23:04 +03:00
}
else
{
dialogs . push_back ( temp ) ;
}
2008-09-25 17:09:31 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : showYesNoDialog ( const std : : string & text , const std : : vector < SComponent * > & components , CFunctionList < void ( ) > onYes , CFunctionList < void ( ) > onNo , bool DelComps )
2008-09-25 17:09:31 +03:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
LOCPLINT - > showingDialog - > setn ( true ) ;
std : : vector < std : : pair < std : : string , CFunctionList < void ( ) > > > pom ;
pom . push_back ( std : : pair < std : : string , CFunctionList < void ( ) > > ( " IOKAY.DEF " , 0 ) ) ;
pom . push_back ( std : : pair < std : : string , CFunctionList < void ( ) > > ( " ICANCEL.DEF " , 0 ) ) ;
2009-06-02 05:15:23 +03:00
CInfoWindow * temp = new CInfoWindow ( text , playerID , 0 , components , pom , DelComps ) ;
2009-05-19 21:23:04 +03:00
temp - > delComps = DelComps ;
for ( int i = 0 ; i < onYes . funcs . size ( ) ; i + + )
temp - > buttons [ 0 ] - > callback + = onYes . funcs [ i ] ;
for ( int i = 0 ; i < onNo . funcs . size ( ) ; i + + )
temp - > buttons [ 1 ] - > callback + = onNo . funcs [ i ] ;
2008-09-25 17:09:31 +03:00
2009-08-07 01:36:51 +03:00
GH . pushInt ( temp ) ;
2008-09-25 17:09:31 +03:00
}
2008-10-26 22:58:34 +02:00
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : showBlockingDialog ( const std : : string & text , const std : : vector < Component > & components , ui32 askID , int soundID , bool selection , bool cancel )
2008-10-26 22:58:34 +02:00
{
2009-07-21 02:34:06 +03:00
waitWhileDialog ( ) ;
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2009-05-22 07:14:59 +03:00
CGI - > soundh - > playSound ( static_cast < soundBase : : soundID > ( soundID ) ) ;
2009-05-19 21:23:04 +03:00
if ( ! selection & & cancel ) //simple yes/no dialog
2009-02-09 18:18:48 +02:00
{
2009-05-19 21:23:04 +03:00
std : : vector < SComponent * > intComps ;
for ( int i = 0 ; i < components . size ( ) ; i + + )
intComps . push_back ( new SComponent ( components [ i ] ) ) ; //will be deleted by close in window
showYesNoDialog ( text , intComps , boost : : bind ( & CCallback : : selectionMade , cb , 1 , askID ) , boost : : bind ( & CCallback : : selectionMade , cb , 0 , askID ) , true ) ;
2009-02-09 18:18:48 +02:00
}
2009-05-19 21:23:04 +03:00
else if ( selection )
2009-02-09 18:18:48 +02:00
{
2009-05-19 21:23:04 +03:00
std : : vector < CSelectableComponent * > intComps ;
for ( int i = 0 ; i < components . size ( ) ; i + + )
intComps . push_back ( new CSelectableComponent ( components [ i ] ) ) ; //will be deleted by CSelWindow::close
std : : vector < std : : pair < std : : string , CFunctionList < void ( ) > > > pom ;
pom . push_back ( std : : pair < std : : string , CFunctionList < void ( ) > > ( " IOKAY.DEF " , 0 ) ) ;
if ( cancel )
2009-02-09 18:18:48 +02:00
{
2009-05-19 21:23:04 +03:00
pom . push_back ( std : : pair < std : : string , CFunctionList < void ( ) > > ( " ICANCEL.DEF " , 0 ) ) ;
2009-02-09 18:18:48 +02:00
}
2008-10-26 22:58:34 +02:00
2009-05-19 21:23:04 +03:00
CSelWindow * temp = new CSelWindow ( text , playerID , 35 , intComps , pom , askID ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( temp ) ;
2009-08-11 19:05:33 +03:00
intComps [ 0 ] - > clickLeft ( true , false ) ;
2009-05-19 21:23:04 +03:00
}
2008-10-26 22:58:34 +02:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : tileRevealed ( const std : : set < int3 > & pos )
2008-10-26 22:58:34 +02:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
for ( std : : set < int3 > : : const_iterator i = pos . begin ( ) ; i ! = pos . end ( ) ; i + + )
adventureInt - > minimap . showTile ( * i ) ;
2008-10-26 22:58:34 +02:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : tileHidden ( const std : : set < int3 > & pos )
2008-10-26 22:58:34 +02:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
for ( std : : set < int3 > : : const_iterator i = pos . begin ( ) ; i ! = pos . end ( ) ; i + + )
adventureInt - > minimap . hideTile ( * i ) ;
2008-10-26 22:58:34 +02:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : openHeroWindow ( const CGHeroInstance * hero )
2008-10-26 22:58:34 +02:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
adventureInt - > heroWindow - > setHero ( hero ) ;
adventureInt - > heroWindow - > quitButton - > callback = boost : : bind ( & CHeroWindow : : quit , adventureInt - > heroWindow ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( adventureInt - > heroWindow ) ;
2008-10-26 22:58:34 +02:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : heroArtifactSetChanged ( const CGHeroInstance * hero )
2008-10-26 22:58:34 +02:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2009-06-30 18:36:12 +03:00
if ( adventureInt - > heroWindow - > curHero ) //hero window is opened
2009-02-09 18:18:48 +02:00
{
2009-05-19 21:23:04 +03:00
adventureInt - > heroWindow - > deactivate ( ) ;
adventureInt - > heroWindow - > setHero ( adventureInt - > heroWindow - > curHero ) ;
adventureInt - > heroWindow - > activate ( ) ;
2009-06-30 18:36:12 +03:00
return ;
2009-02-09 18:18:48 +02:00
}
2009-08-07 01:36:51 +03:00
CExchangeWindow * cew = dynamic_cast < CExchangeWindow * > ( GH . topInt ( ) ) ;
2009-06-28 16:49:39 +03:00
if ( cew ) //exchange window is open
{
cew - > deactivate ( ) ;
for ( int g = 0 ; g < ARRAY_COUNT ( cew - > heroInst ) ; + + g )
{
if ( cew - > heroInst [ g ] = = hero )
{
cew - > artifs [ g ] - > setHero ( hero ) ;
}
}
cew - > prepareBackground ( ) ;
cew - > activate ( ) ;
}
2008-10-26 22:58:34 +02:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : updateWater ( )
2008-10-26 22:58:34 +02:00
{
2009-05-19 21:23:04 +03:00
2008-10-26 22:58:34 +02:00
}
2009-05-19 21:23:04 +03:00
2009-07-26 13:43:22 +03:00
void CPlayerInterface : : availableCreaturesChanged ( const CGDwelling * town )
2008-10-26 22:58:34 +02:00
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2009-07-26 13:43:22 +03:00
if ( castleInt & & town - > ID = = TOWNI_TYPE )
2009-02-09 18:18:48 +02:00
{
2009-08-07 01:36:51 +03:00
CFortScreen * fs = dynamic_cast < CFortScreen * > ( GH . topInt ( ) ) ;
2009-05-19 21:23:04 +03:00
if ( fs )
fs - > draw ( castleInt , false ) ;
2009-02-09 18:18:48 +02:00
}
2009-08-07 01:36:51 +03:00
else if ( GH . listInt . size ( ) & & ( town - > ID = = 17 | | town - > ID = = 20 ) ) //external dwelling
2009-07-26 13:43:22 +03:00
{
2009-08-07 01:36:51 +03:00
CRecruitmentWindow * crw = dynamic_cast < CRecruitmentWindow * > ( GH . topInt ( ) ) ;
2009-07-26 13:43:22 +03:00
if ( crw )
crw - > initCres ( ) ;
}
2008-10-26 22:58:34 +02:00
}
2009-02-09 18:18:48 +02:00
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : heroBonusChanged ( const CGHeroInstance * hero , const HeroBonus & bonus , bool gain )
2009-02-09 18:18:48 +02:00
{
2009-05-19 21:23:04 +03:00
if ( bonus . type = = HeroBonus : : NONE ) return ;
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
redrawHeroWin ( hero ) ;
2009-04-03 18:55:26 +03:00
}
2009-05-19 21:23:04 +03:00
template < typename Handler > void CPlayerInterface : : serializeTempl ( Handler & h , const int version )
2009-04-03 18:55:26 +03:00
{
2009-05-19 21:23:04 +03:00
h & playerID & serialID ;
2009-07-18 06:13:13 +03:00
h & sysOpts ;
2009-05-19 21:23:04 +03:00
h & CBattleInterface : : settings ;
2009-04-03 18:55:26 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : serialize ( COSer < CSaveFile > & h , const int version )
2009-04-03 18:55:26 +03:00
{
2009-05-19 21:23:04 +03:00
serializeTempl ( h , version ) ;
2009-04-03 18:55:26 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : serialize ( CISer < CLoadFile > & h , const int version )
2009-04-03 18:55:26 +03:00
{
2009-05-19 21:23:04 +03:00
serializeTempl ( h , version ) ;
2009-07-18 06:13:13 +03:00
sysOpts . apply ( ) ;
2009-04-03 18:55:26 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : redrawHeroWin ( const CGHeroInstance * hero )
2009-04-04 22:26:41 +03:00
{
2009-05-19 21:23:04 +03:00
if ( ! vstd : : contains ( graphics - > heroWins , hero - > subID ) )
2009-04-04 22:26:41 +03:00
{
2009-05-19 21:23:04 +03:00
tlog1 < < " Cannot redraw infowindow for hero with subID= " < < hero - > subID < < " - not present in our map \n " ;
return ;
2009-04-04 22:26:41 +03:00
}
2009-05-19 21:23:04 +03:00
SDL_FreeSurface ( graphics - > heroWins [ hero - > subID ] ) ;
graphics - > heroWins [ hero - > subID ] = infoWin ( hero ) ;
if ( adventureInt - > selection = = hero )
adventureInt - > infoBar . draw ( screen ) ;
2009-04-04 22:26:41 +03:00
}
2009-05-19 21:23:04 +03:00
bool CPlayerInterface : : moveHero ( const CGHeroInstance * h , CPath path )
2009-04-03 18:55:26 +03:00
{
2009-05-19 21:23:04 +03:00
if ( ! h )
return false ; //can't find hero
bool result = false ;
path . convert ( 0 ) ;
boost : : unique_lock < boost : : mutex > un ( stillMoveHero . mx ) ;
stillMoveHero . data = CONTINUE_MOVE ;
2009-04-04 22:26:41 +03:00
2009-05-19 21:23:04 +03:00
enum TerrainTile : : EterrainType currentTerrain = TerrainTile : : border ; // not init yet
enum TerrainTile : : EterrainType newTerrain ;
int sh = - 1 ;
2009-04-05 17:37:14 +03:00
2009-05-19 21:23:04 +03:00
for ( int i = path . nodes . size ( ) - 1 ; i > 0 & & stillMoveHero . data = = CONTINUE_MOVE ; i - - )
2009-04-03 18:55:26 +03:00
{
2009-07-19 06:10:24 +03:00
//stop sending move requests if hero exhausted all his move points
if ( ! h - > movement )
{
stillMoveHero . data = STOP_MOVE ;
break ;
}
2009-05-19 21:23:04 +03:00
// Start a new sound for the hero movement or let the existing one carry on.
#if 0
// TODO
if ( hero is flying & & sh = = - 1 )
2009-05-22 07:14:59 +03:00
sh = CGI - > soundh - > playSound ( soundBase : : horseFlying , - 1 ) ;
2009-05-19 21:23:04 +03:00
}
else if ( hero is in a boat & & sh = - 1 ) {
2009-05-22 07:14:59 +03:00
sh = CGI - > soundh - > playSound ( soundBase : : sound_todo , - 1 ) ;
2009-05-19 21:23:04 +03:00
} else
# endif
2009-04-04 22:26:41 +03:00
{
2009-05-22 22:20:30 +03:00
newTerrain = cb - > getTileInfo ( CGHeroInstance : : convertPosition ( path . nodes [ i ] . coord , false ) ) - > tertype ;
2009-05-19 21:23:04 +03:00
if ( newTerrain ! = currentTerrain ) {
2009-05-22 07:14:59 +03:00
CGI - > soundh - > stopSound ( sh ) ;
sh = CGI - > soundh - > playSound ( CGI - > soundh - > horseSounds [ newTerrain ] , - 1 ) ;
2009-05-19 21:23:04 +03:00
currentTerrain = newTerrain ;
2009-04-03 18:55:26 +03:00
}
}
2009-05-19 21:23:04 +03:00
stillMoveHero . data = WAITING_MOVE ;
int3 endpos ( path . nodes [ i - 1 ] . coord . x , path . nodes [ i - 1 ] . coord . y , h - > pos . z ) ;
cb - > moveHero ( h , endpos ) ;
while ( stillMoveHero . data ! = STOP_MOVE & & stillMoveHero . data ! = CONTINUE_MOVE )
stillMoveHero . cond . wait ( un ) ;
2009-04-03 18:55:26 +03:00
}
2009-05-19 21:23:04 +03:00
2009-05-22 07:14:59 +03:00
CGI - > soundh - > stopSound ( sh ) ;
2009-05-19 21:23:04 +03:00
//stillMoveHero = false;
return result ;
2009-04-03 18:55:26 +03:00
}
2009-05-19 21:23:04 +03:00
bool CPlayerInterface : : shiftPressed ( ) const
2009-04-03 18:55:26 +03:00
{
2009-05-19 21:23:04 +03:00
return SDL_GetKeyState ( NULL ) [ SDLK_LSHIFT ] | | SDL_GetKeyState ( NULL ) [ SDLK_RSHIFT ] ;
2009-04-03 18:55:26 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : showGarrisonDialog ( const CArmedInstance * up , const CGHeroInstance * down , boost : : function < void ( ) > & onEnd )
2009-04-04 22:26:41 +03:00
{
{
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : mutex > un ( showingDialog - > mx ) ;
while ( showingDialog - > data )
showingDialog - > cond . wait ( un ) ;
2009-04-04 22:26:41 +03:00
}
2009-05-19 21:23:04 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
while ( dialogs . size ( ) )
2009-04-04 22:26:41 +03:00
{
2009-05-19 21:23:04 +03:00
pim - > unlock ( ) ;
SDL_Delay ( 20 ) ;
pim - > lock ( ) ;
2009-04-04 22:26:41 +03:00
}
2009-05-19 21:23:04 +03:00
CGarrisonWindow * cgw = new CGarrisonWindow ( up , down ) ;
cgw - > quit - > callback + = onEnd ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( cgw ) ;
2009-04-14 15:47:09 +03:00
}
2009-05-19 21:23:04 +03:00
void CPlayerInterface : : requestRealized ( PackageApplied * pa )
2009-04-14 15:47:09 +03:00
{
2009-05-19 21:23:04 +03:00
if ( stillMoveHero . get ( ) = = DURING_MOVE )
stillMoveHero . setn ( CONTINUE_MOVE ) ;
2009-04-14 15:47:09 +03:00
}
2009-06-16 14:18:14 +03:00
void CPlayerInterface : : heroExchangeStarted ( si32 hero1 , si32 hero2 )
{
2009-08-07 01:36:51 +03:00
GH . pushInt ( new CExchangeWindow ( hero2 , hero1 ) ) ;
2009-06-16 14:18:14 +03:00
}
2009-07-30 15:49:45 +03:00
void CPlayerInterface : : objectPropertyChanged ( const SetObjectProperty * sop )
{
//redraw minimap if owner changed
if ( sop - > what = = 1 )
{
2009-07-31 14:20:53 +03:00
const CGObjectInstance * obj = cb - > getObjectInfo ( sop - > id ) ;
2009-07-30 15:49:45 +03:00
std : : set < int3 > pos = obj - > getBlockedPos ( ) ;
for ( std : : set < int3 > : : const_iterator it = pos . begin ( ) ; it ! = pos . end ( ) ; + + it )
{
2009-07-31 14:20:53 +03:00
if ( cb - > isVisible ( * it ) )
adventureInt - > minimap . showTile ( * it ) ;
2009-07-30 15:49:45 +03:00
}
}
}
2009-06-11 20:21:06 +03:00
void CPlayerInterface : : recreateWanderingHeroes ( )
{
2009-06-13 02:34:02 +03:00
wanderingHeroes . clear ( ) ;
2009-06-11 20:21:06 +03:00
std : : vector < const CGHeroInstance * > heroes = cb - > getHeroesInfo ( ) ;
for ( size_t i = 0 ; i < heroes . size ( ) ; i + + )
if ( ! heroes [ i ] - > inTownGarrison )
wanderingHeroes . push_back ( heroes [ i ] ) ;
}
const CGHeroInstance * CPlayerInterface : : getWHero ( int pos )
{
if ( pos < 0 | | pos > = wanderingHeroes . size ( ) )
return NULL ;
return wanderingHeroes [ pos ] ;
2009-06-12 06:26:41 +03:00
}
2009-07-06 22:41:27 +03:00
2009-07-26 13:43:22 +03:00
void CPlayerInterface : : showRecruitmentDialog ( const CGDwelling * dwelling , const CArmedInstance * dst , int level )
2009-07-06 22:41:27 +03:00
{
2009-07-21 02:34:06 +03:00
waitWhileDialog ( ) ;
2009-07-26 06:33:13 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2009-07-26 13:43:22 +03:00
CRecruitmentWindow * cr = new CRecruitmentWindow ( dwelling , level , dst , boost : : bind ( & CCallback : : recruitCreatures , cb , dwelling , _1 , _2 ) ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( cr ) ;
2009-07-18 06:13:13 +03:00
}
2009-07-21 02:34:06 +03:00
void CPlayerInterface : : waitWhileDialog ( )
{
boost : : unique_lock < boost : : mutex > un ( showingDialog - > mx ) ;
while ( showingDialog - > data )
showingDialog - > cond . wait ( un ) ;
}
2009-07-26 06:33:13 +03:00
void CPlayerInterface : : showShipyardDialog ( const IShipyard * obj )
{
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
int state = obj - > state ( ) ;
std : : vector < si32 > cost ;
obj - > getBoatCost ( cost ) ;
CShipyardWindow * csw = new CShipyardWindow ( cost , state , boost : : bind ( & CCallback : : buildBoat , cb , obj ) ) ;
2009-08-07 01:36:51 +03:00
GH . pushInt ( csw ) ;
2009-07-26 06:33:13 +03:00
}
void CPlayerInterface : : newObject ( const CGObjectInstance * obj )
{
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
CGI - > mh - > printObject ( obj ) ;
//we might have built a boat in shipyard in opened town screen
if ( obj - > ID = = 8
& & LOCPLINT - > castleInt
& & obj - > pos - obj - > getVisitableOffset ( ) = = LOCPLINT - > castleInt - > town - > bestLocation ( ) )
{
CGI - > soundh - > playSound ( soundBase : : newBuilding ) ;
LOCPLINT - > castleInt - > recreateBuildings ( ) ;
}
}
2009-08-13 04:03:11 +03:00
void CPlayerInterface : : centerView ( int3 pos , int focusTime )
2009-08-11 10:50:29 +03:00
{
LOCPLINT - > adventureInt - > centerOn ( pos ) ;
2009-08-13 04:03:11 +03:00
if ( focusTime )
{
bool activeAdv = ( GH . topInt ( ) = = adventureInt & & adventureInt - > active ) ;
if ( activeAdv )
adventureInt - > deactivate ( ) ;
SDL_Delay ( focusTime ) ;
if ( activeAdv )
adventureInt - > activate ( ) ;
}
2009-08-11 10:50:29 +03:00
}
2009-08-04 02:53:18 +03:00
void CPlayerInterface : : objectRemoved ( const CGObjectInstance * obj )
{
if ( obj - > ID = = HEROI_TYPE & & obj - > tempOwner = = playerID )
{
const CGHeroInstance * h = static_cast < const CGHeroInstance * > ( obj ) ;
heroKilled ( h ) ;
}
}
2009-07-18 06:13:13 +03:00
void SystemOptions : : setMusicVolume ( int newVolume )
{
musicVolume = newVolume ;
CGI - > musich - > setVolume ( newVolume ) ;
settingsChanged ( ) ;
}
void SystemOptions : : setSoundVolume ( int newVolume )
{
soundVolume = newVolume ;
CGI - > soundh - > setVolume ( newVolume ) ;
settingsChanged ( ) ;
}
void SystemOptions : : setHeroMoveSpeed ( int newSpeed )
{
heroMoveSpeed = newSpeed ;
settingsChanged ( ) ;
}
void SystemOptions : : setMapScrollingSpeed ( int newSpeed )
{
mapScrollingSpeed = newSpeed ;
settingsChanged ( ) ;
}
void SystemOptions : : settingsChanged ( )
{
CSaveFile settings ( " config " PATHSEPARATOR " sysopts.bin " ) ;
if ( settings . sfile )
settings < < * this ;
else
tlog1 < < " Cannot save settings to config " PATHSEPARATOR " sysopts.bin! \n " ;
}
void SystemOptions : : apply ( )
{
CGI - > musich - > setVolume ( musicVolume ) ;
CGI - > soundh - > setVolume ( soundVolume ) ;
settingsChanged ( ) ;
2009-08-06 08:08:17 +03:00
}