2011-12-14 00:23:17 +03:00
# include "StdInc.h"
2008-03-16 02:09:43 +02:00
# include "CAdvmapInterface.h"
2011-12-14 00:23:17 +03:00
# include "BattleInterface/CBattleInterface.h"
2011-12-22 16:05:19 +03:00
# include "BattleInterface/CBattleInterfaceClasses.h"
2009-05-20 13:08:56 +03:00
# include "../CCallback.h"
2008-08-27 13:19:18 +03:00
# include "CCastleInterface.h"
2011-12-22 16:05:19 +03:00
# include "UIFramework/CCursorHandler.h"
2011-07-22 19:22:22 +03:00
# include "CKingdomInterface.h"
2008-08-27 13:19:18 +03:00
# include "CGameInfo.h"
# include "CHeroWindow.h"
2012-05-16 20:29:05 +03:00
# include "CCreatureWindow.h"
2007-11-19 00:58:28 +02:00
# include "CMessage.h"
2008-08-27 13:19:18 +03:00
# include "CPlayerInterface.h"
2011-12-22 16:05:19 +03:00
//#include "UIFramework/SDL_Extensions.h"
# include "UIFramework/SDL_Extensions.h"
2009-05-20 13:08:56 +03:00
# include "CConfigHandler.h"
2011-12-17 21:59:59 +03:00
# include "BattleInterface/CCreatureAnimation.h"
2009-05-20 13:08:56 +03:00
# include "Graphics.h"
2010-12-20 23:22:53 +02:00
# include "../lib/CArtHandler.h"
# include "../lib/CGeneralTextHandler.h"
# include "../lib/CHeroHandler.h"
# include "../lib/CLodHandler.h"
# include "../lib/CObjectHandler.h"
2009-05-20 13:08:56 +03:00
# include "../lib/Connection.h"
2010-12-20 23:22:53 +02:00
# include "../lib/CSpellHandler.h"
# include "../lib/CTownHandler.h"
2010-12-25 21:23:30 +02:00
# include "../lib/BattleState.h"
2012-01-12 18:23:00 +03:00
# include "../lib/JsonNode.h"
2010-12-20 23:22:53 +02:00
# include "CMusicHandler.h"
2009-05-20 13:08:56 +03:00
# include "../lib/CondSh.h"
# include "../lib/NetPacks.h"
# include "../lib/map.h"
2009-10-10 08:47:59 +03:00
# include "../lib/VCMIDirs.h"
2010-04-06 16:19:54 +03:00
# include "mapHandler.h"
2011-12-17 21:59:59 +03:00
# include "../lib/CStopWatch.h"
2011-12-14 00:23:17 +03:00
# include "../lib/StartInfo.h"
2011-05-10 01:20:47 +03:00
# include "../lib/CGameState.h"
2011-12-14 00:23:17 +03:00
# include "../lib/GameConstants.h"
2011-12-17 21:59:59 +03:00
# include "UIFramework/CGuiHandler.h"
2012-02-20 00:03:43 +03:00
# include "../lib/UnlockGuard.h"
2009-12-28 06:08:24 +02:00
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
*
*/
2012-04-06 18:02:15 +03:00
// The macro below is used to mark functions that are called by client when game state changes.
// They all assume that CPlayerInterface::pim mutex is locked.
# define EVENT_HANDLER_CALLED_BY_CLIENT
// The macro marks functions that are run on a new thread by client.
// They do not own any mutexes intiially.
# define THREAD_CREATED_BY_CLIENT
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 ) ;
2010-08-26 18:33:55 +03:00
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 ;
2012-02-14 21:04:45 +03:00
boost : : recursive_mutex * CPlayerInterface : : pim = new boost : : recursive_mutex ;
2008-01-30 16:19:35 +02:00
2009-04-21 01:57:07 +03:00
CPlayerInterface * LOCPLINT ;
2010-02-19 18:02:34 +02:00
CBattleInterface * CPlayerInterface : : battleInt ;
2009-04-21 01:57:07 +03:00
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
2010-05-27 00:59:58 +03:00
int CPlayerInterface : : howManyPeople = 0 ;
2010-02-20 15:24:38 +02: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
2010-08-03 14:36:52 +03:00
CPlayerInterface : : CPlayerInterface ( int Player )
2008-01-26 21:36:31 +02:00
{
2010-12-23 02:33:48 +02:00
observerInDuelMode = false ;
2010-02-20 15:24:38 +02:00
howManyPeople + + ;
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 ;
human = true ;
castleInt = NULL ;
battleInt = NULL ;
2011-02-24 15:57:47 +02:00
//pim = new boost::recursive_mutex;
2009-05-19 21:23:04 +03:00
makingTurn = false ;
showingDialog = new CondSh < bool > ( false ) ;
cingconsole = new CInGameConsole ;
2009-11-01 03:15:16 +02:00
terminate_cond . set ( false ) ;
2009-12-28 06:08:24 +02:00
firstCall = 1 ; //if loading will be overwritten in serialize
autosaveCount = 0 ;
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
{
2010-02-20 15:24:38 +02:00
howManyPeople - - ;
2011-02-24 15:57:47 +02:00
//delete pim;
2011-12-14 00:23:17 +03:00
//vstd::clear_pointer(pim);
2009-05-19 21:23:04 +03:00
delete showingDialog ;
2010-02-22 15:30:46 +02:00
if ( adventureInt )
{
if ( adventureInt - > active & CIntObject : : KEYBOARD )
adventureInt - > deactivateKeys ( ) ;
delete adventureInt ;
adventureInt = NULL ;
}
if ( cingconsole - > active ) //TODO
cingconsole - > deactivate ( ) ;
2009-05-19 21:23:04 +03:00
delete cingconsole ;
2008-05-23 22:50:11 +03:00
2009-11-01 03:15:16 +02:00
LOCPLINT = NULL ;
2009-02-04 15:40:54 +02:00
}
2011-05-03 06:14:18 +03:00
void CPlayerInterface : : init ( CCallback * CB )
2008-01-26 21:36:31 +02:00
{
2009-05-19 21:23:04 +03:00
cb = dynamic_cast < CCallback * > ( CB ) ;
2010-12-23 02:33:48 +02:00
if ( observerInDuelMode )
{
return ;
}
2010-02-20 15:24:38 +02:00
if ( ! adventureInt )
adventureInt = new CAdvMapInt ( ) ;
2010-02-26 13:18:09 +02:00
if ( ! towns . size ( ) & & ! wanderingHeroes . size ( ) )
{
recreateHeroTownList ( ) ;
}
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
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-20 15:24:38 +02:00
{
boost : : unique_lock < boost : : mutex > lock ( eventsM ) ; //block handling events until interface is ready
2010-02-13 06:47:31 +02:00
2010-02-20 15:24:38 +02:00
LOCPLINT = this ;
GH . curInt = this ;
2010-02-28 14:39:38 +02:00
adventureInt - > selection = NULL ;
2009-04-14 15:47:09 +03:00
2010-02-20 15:24:38 +02:00
if ( firstCall )
2009-05-19 21:23:04 +03:00
{
2010-02-20 15:24:38 +02:00
if ( howManyPeople = = 1 )
adventureInt - > setPlayer ( playerID ) ;
2009-03-27 01:05:40 +02:00
2010-02-20 15:24:38 +02:00
autosaveCount = getLastIndex ( " Autosave_ " ) ;
2009-05-19 21:23:04 +03:00
2010-02-20 15:24:38 +02:00
if ( firstCall > 0 ) //new game, not loaded
{
int index = getLastIndex ( " Newgame_Autosave_ " ) ;
index % = SAVES_COUNT ;
cb - > save ( " Newgame_Autosave_ " + boost : : lexical_cast < std : : string > ( index + 1 ) ) ;
}
firstCall = 0 ;
}
else
{
LOCPLINT - > cb - > save ( " Autosave_ " + boost : : lexical_cast < std : : string > ( autosaveCount + + + 1 ) ) ;
autosaveCount % = 5 ;
}
2009-05-19 21:23:04 +03:00
2010-07-24 14:46:04 +03:00
if ( adventureInt - > player ! = playerID )
adventureInt - > setPlayer ( playerID ) ;
2010-02-20 15:24:38 +02:00
if ( howManyPeople > 1 ) //hot seat message
{
adventureInt - > startHotSeatWait ( playerID ) ;
2010-02-24 15:03:36 +02:00
makingTurn = true ;
2010-02-20 15:24:38 +02:00
std : : string msg = CGI - > generaltexth - > allTexts [ 13 ] ;
2010-08-03 14:36:52 +03:00
boost : : replace_first ( msg , " %s " , cb - > getStartInfo ( ) - > playerInfos . find ( playerID ) - > second . name ) ;
2011-12-22 16:05:19 +03:00
std : : vector < CComponent * > cmp ;
cmp . push_back ( new CComponent ( CComponent : : flag , playerID , 0 ) ) ;
2010-02-20 15:24:38 +02:00
showInfoDialog ( msg , cmp ) ;
}
else
2010-02-24 15:03:36 +02:00
{
makingTurn = true ;
2010-02-20 15:24:38 +02:00
adventureInt - > startTurn ( ) ;
2010-02-24 15:03:36 +02:00
}
2010-02-20 15:24:38 +02:00
}
2009-11-01 03:15:16 +02:00
2010-02-20 15:24:38 +02:00
acceptTurn ( ) ;
2008-01-26 21:36:31 +02:00
}
2009-05-19 21:23:04 +03:00
2010-08-16 16:51:31 +03:00
STRONG_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
2010-08-16 16:51:31 +03:00
STRONG_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
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2012-02-17 00:19:07 +03:00
waitWhileDialog ( ) ;
2010-02-20 15:24:38 +02:00
if ( LOCPLINT ! = this )
return ;
2012-04-06 18:02:15 +03:00
2011-05-03 06:14:18 +03:00
const CGHeroInstance * ho = cb - > getHero ( details . id ) ; //object representing this hero
2010-01-02 03:48:44 +02:00
int3 hp = details . start ;
2009-05-19 21:23:04 +03:00
2011-07-17 21:49:05 +03:00
if ( ! ho )
{
//AI hero left the visible area (we can't obtain info)
2012-02-14 21:04:45 +03:00
//TODO very evil workaround -> retreive pointer to hero so we could animate it
// TODO -> we should not need full CGHeroInstance structure to display animation or it should not be handled by playerint (but by the client itself)
const TerrainTile2 & tile = CGI - > mh - > ttiles [ hp . x - 1 ] [ hp . y ] [ hp . z ] ;
for ( int i = 0 ; i < tile . objects . size ( ) ; i + + )
if ( tile . objects [ i ] . first - > id = = details . id )
ho = dynamic_cast < const CGHeroInstance * > ( tile . objects [ i ] . first ) ;
2012-02-16 20:10:58 +03:00
if ( ! ho ) //still nothing...
2012-02-14 21:04:45 +03:00
return ;
2011-07-17 21:49:05 +03:00
}
2010-03-21 00:17:19 +02:00
adventureInt - > centerOn ( ho ) ; //actualizing screen pos
2009-05-19 21:23:04 +03:00
adventureInt - > minimap . draw ( screen2 ) ;
adventureInt - > heroList . draw ( screen2 ) ;
2010-05-06 15:13:31 +03:00
bool directlyAttackingCreature =
CGI - > mh - > map - > isInTheMap ( details . attackedFrom )
2010-11-13 22:26:15 +02:00
& & adventureInt - > terrain . currentPath //in case if movement has been canceled in the meantime and path was already erased
& & adventureInt - > terrain . currentPath - > nodes . size ( ) = = 3 ; //FIXME should be 2 but works nevertheless...
2009-07-31 23:10:22 +03:00
2010-01-02 03:48:44 +02:00
if ( makingTurn & & ho - > tempOwner = = playerID ) //we are moving our hero - we may need to update assigned path
2008-08-02 18:08:03 +03:00
{
2011-08-19 22:50:24 +03:00
//We may need to change music - select new track, music handler will change it if needed
2012-05-18 20:35:46 +03:00
CCS - > musich - > playMusic ( CCS - > musich - > terrainMusics [ LOCPLINT - > cb - > getTile ( ho - > visitablePos ( ) ) - > tertype ] , - 1 ) ;
2011-09-19 23:50:25 +03:00
if ( details . result = = TryMoveHero : : TELEPORTATION )
2010-01-02 03:48:44 +02:00
{
2012-02-18 17:59:37 +03:00
if ( adventureInt - > terrain . currentPath )
{
assert ( adventureInt - > terrain . currentPath - > nodes . size ( ) > = 2 ) ;
std : : vector < CGPathNode > : : const_iterator nodesIt = adventureInt - > terrain . currentPath - > nodes . end ( ) - 1 ;
if ( ( nodesIt ) - > coord = = CGHeroInstance : : convertPosition ( details . start , false )
& & ( nodesIt - 1 ) - > coord = = CGHeroInstance : : convertPosition ( details . end , false ) )
{
//path was between entrance and exit of teleport -> OK, erase node as usual
removeLastNodeFromPath ( ho ) ;
}
else
{
//teleport was not along current path, it'll now be invalid (hero is somewhere else)
eraseCurrentPathOf ( ho ) ;
}
}
2011-09-19 23:50:25 +03:00
return ; //teleport - no fancy moving animation
2010-01-02 03:48:44 +02:00
//TODO: smooth disappear / appear effect
}
2011-09-19 23:50:25 +03:00
if ( ho - > pos ! = details . end //hero didn't change tile but visit succeeded
2010-05-06 15:13:31 +03:00
| | directlyAttackingCreature ) // or creature was attacked from endangering tile.
2008-01-26 21:36:31 +02:00
{
2010-02-20 15:24:38 +02:00
eraseCurrentPathOf ( ho ) ;
2008-01-26 21:36:31 +02:00
}
2011-09-19 23:50:25 +03:00
else if ( adventureInt - > terrain . currentPath & & ho - > pos = = details . end ) //&& hero is moving
2009-07-31 23:10:22 +03:00
{
2012-02-18 17:59:37 +03:00
if ( details . start ! = details . end ) //so we don't touch path when revisiting with spacebar
2011-11-25 22:41:23 +03:00
removeLastNodeFromPath ( ho ) ;
2009-07-31 23:10:22 +03:00
}
}
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
2010-01-02 03:48:44 +02:00
initMovement ( details , ho , hp ) ;
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02:00
//first initializing done
2011-04-05 20:38:24 +03:00
GH . mainFPSmng - > framerateDelay ( ) ; // after first move
2009-05-19 21:23:04 +03:00
2012-01-12 18:23:00 +03:00
ui32 speed = settings [ " adventure " ] [ " heroSpeed " ] . Float ( ) ;
2010-01-02 03:48:44 +02:00
//main moving
2012-01-12 18:23:00 +03:00
for ( int i = 1 ; i < 32 ; i + = 2 * speed )
2010-01-02 03:48:44 +02:00
{
movementPxStep ( details , i , hp , ho ) ;
adventureInt - > updateScreen = true ;
adventureInt - > show ( screen ) ;
CSDL_Ext : : update ( screen ) ;
2011-04-05 20:38:24 +03:00
GH . mainFPSmng - > framerateDelay ( ) ; //for animation purposes
2010-01-02 03:48:44 +02:00
} //for(int i=1; i<32; i+=4)
//main moving done
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02:00
//finishing move
finishMovement ( details , hp , ho ) ;
ho - > isStanding = true ;
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02:00
//move finished
adventureInt - > minimap . draw ( screen2 ) ;
adventureInt - > heroList . updateMove ( ho ) ;
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02:00
//check if user cancelled movement
2008-08-17 12:11:16 +03:00
{
2010-01-02 03:48:44 +02:00
boost : : unique_lock < boost : : mutex > un ( eventsM ) ;
while ( events . size ( ) )
{
SDL_Event * ev = events . front ( ) ;
events . pop ( ) ;
switch ( ev - > type )
{
case SDL_MOUSEBUTTONDOWN :
stillMoveHero . setn ( STOP_MOVE ) ;
break ;
case SDL_KEYDOWN :
if ( ev - > key . keysym . sym < SDLK_F1 | | ev - > key . keysym . sym > SDLK_F15 )
stillMoveHero . setn ( STOP_MOVE ) ;
break ;
}
delete ev ;
}
}
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02:00
if ( stillMoveHero . get ( ) = = WAITING_MOVE )
stillMoveHero . setn ( DURING_MOVE ) ;
2009-05-19 21:23:04 +03:00
2010-05-06 15:13:31 +03:00
// Hero attacked creature directly, set direction to face it.
if ( directlyAttackingCreature ) {
// Get direction to attacker.
int3 posOffset = details . attackedFrom - details . end + int3 ( 2 , 1 , 0 ) ;
2010-10-31 00:53:41 +03:00
static const ui8 dirLookup [ 3 ] [ 3 ] = {
{ 1 , 2 , 3 } ,
{ 8 , 0 , 4 } ,
{ 7 , 6 , 5 }
2010-05-06 15:13:31 +03:00
} ;
// FIXME: Avoid const_cast, make moveDir mutable in some other way?
const_cast < CGHeroInstance * > ( ho ) - > moveDir = dirLookup [ posOffset . y ] [ posOffset . x ] ;
}
2010-01-02 03:48:44 +02:00
}
void CPlayerInterface : : heroKilled ( const CGHeroInstance * hero )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-01-02 03:48:44 +02:00
wanderingHeroes - = hero ;
2012-02-16 20:10:58 +03:00
if ( vstd : : contains ( paths , hero ) )
2011-01-24 02:09:08 +02:00
paths . erase ( hero ) ;
2010-01-02 03:48:44 +02:00
adventureInt - > heroList . updateHList ( hero ) ;
}
void CPlayerInterface : : heroCreated ( const CGHeroInstance * hero )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-01-02 03:48:44 +02:00
wanderingHeroes . push_back ( hero ) ;
adventureInt - > heroList . updateHList ( ) ;
}
void CPlayerInterface : : openTownWindow ( const CGTownInstance * town )
{
2010-07-27 02:20:21 +03:00
if ( castleInt )
GH . popIntTotally ( castleInt ) ;
2010-01-02 03:48:44 +02:00
castleInt = new CCastleInterface ( town ) ;
GH . pushInt ( castleInt ) ;
}
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02:00
SDL_Surface * CPlayerInterface : : infoWin ( const CGObjectInstance * specific ) //specific=0 => draws info about selected town/hero
{
2010-03-21 00:17:19 +02:00
if ( ! specific )
specific = adventureInt - > selection ;
assert ( specific ) ;
switch ( specific - > ID )
2010-01-02 03:48:44 +02:00
{
2012-02-16 20:10:58 +03:00
case GameConstants : : HEROI_TYPE :
2010-01-02 03:48:44 +02:00
{
2010-03-21 00:17:19 +02:00
InfoAboutHero iah ;
bool gotInfo = LOCPLINT - > cb - > getHeroInfo ( specific , iah ) ;
assert ( gotInfo ) ;
return graphics - > drawHeroInfoWin ( iah ) ;
2010-01-02 03:48:44 +02:00
}
2011-12-14 00:23:17 +03:00
case GameConstants : : TOWNI_TYPE :
2010-03-21 00:17:19 +02:00
case 33 : // Garrison
case 219 :
2010-01-02 03:48:44 +02:00
{
2010-03-21 00:17:19 +02:00
InfoAboutTown iah ;
bool gotInfo = LOCPLINT - > cb - > getTownInfo ( specific , iah ) ;
assert ( gotInfo ) ;
return graphics - > drawTownInfoWin ( iah ) ;
2010-01-02 03:48:44 +02:00
}
2010-03-21 00:17:19 +02:00
default :
return NULL ;
2010-01-02 03:48:44 +02:00
}
}
2008-04-19 19:15:04 +03:00
2010-01-02 03:48:44 +02:00
int3 CPlayerInterface : : repairScreenPos ( int3 pos )
{
if ( pos . x < - CGI - > mh - > frameW )
pos . x = - CGI - > mh - > frameW ;
if ( pos . y < - CGI - > mh - > frameH )
pos . y = - CGI - > mh - > frameH ;
2010-08-16 16:51:31 +03:00
if ( pos . x > CGI - > mh - > sizes . x - adventureInt - > terrain . tilesw + CGI - > mh - > frameW )
pos . x = CGI - > mh - > sizes . x - adventureInt - > terrain . tilesw + CGI - > mh - > frameW ;
if ( pos . y > CGI - > mh - > sizes . y - adventureInt - > terrain . tilesh + CGI - > mh - > frameH )
pos . y = CGI - > mh - > sizes . y - adventureInt - > terrain . tilesh + CGI - > mh - > frameH ;
2010-01-02 03:48:44 +02:00
return pos ;
}
void CPlayerInterface : : heroPrimarySkillChanged ( const CGHeroInstance * hero , int which , si64 val )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-07-20 09:05:45 +03:00
if ( which = = 4 )
{
if ( CAltarWindow * ctw = dynamic_cast < CAltarWindow * > ( GH . topInt ( ) ) )
ctw - > setExpToLevel ( ) ;
}
2011-12-14 00:23:17 +03:00
else if ( which < GameConstants : : PRIMARY_SKILLS ) //no need to redraw infowin if this is experience (exp is treated as prim skill with id==4)
2010-07-20 12:16:48 +03:00
updateInfo ( hero ) ;
2010-01-02 03:48:44 +02:00
}
2010-07-20 17:08:13 +03:00
void CPlayerInterface : : heroSecondarySkillChanged ( const CGHeroInstance * hero , int which , int val )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-07-20 17:08:13 +03:00
CUniversityWindow * cuw = dynamic_cast < CUniversityWindow * > ( GH . topInt ( ) ) ;
if ( cuw ) //university window is open
{
GH . totalRedraw ( ) ;
}
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : heroManaPointsChanged ( const CGHeroInstance * hero )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-03-21 00:17:19 +02:00
updateInfo ( hero ) ;
2010-01-02 03:48:44 +02:00
}
void CPlayerInterface : : heroMovePointsChanged ( const CGHeroInstance * hero )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-03-01 20:22:22 +02:00
if ( makingTurn & & hero - > tempOwner = = playerID )
adventureInt - > heroList . redraw ( ) ;
2010-01-02 03:48:44 +02:00
}
void CPlayerInterface : : receivedResource ( int type , int val )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-07-20 09:05:45 +03:00
if ( CMarketplaceWindow * mw = dynamic_cast < CMarketplaceWindow * > ( GH . topInt ( ) ) )
mw - > resourceChanged ( type , val ) ;
2012-02-16 20:10:58 +03:00
2010-01-02 03:48:44 +02:00
GH . totalRedraw ( ) ;
}
2008-01-26 21:36:31 +02:00
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : heroGotLevel ( const CGHeroInstance * hero , int pskill , std : : vector < ui16 > & skills , boost : : function < void ( ui32 ) > & callback )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-01-02 03:48:44 +02:00
waitWhileDialog ( ) ;
2010-12-19 16:39:56 +02:00
CCS - > soundh - > playSound ( soundBase : : heroNewLevel ) ;
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02:00
CLevelWindow * lw = new CLevelWindow ( hero , pskill , skills , callback ) ;
GH . pushInt ( lw ) ;
}
2012-05-18 17:02:27 +03:00
void CPlayerInterface : : commanderGotLevel ( const CCommanderInstance * commander , std : : vector < ui32 > skills , boost : : function < void ( ui32 ) > & callback )
2012-05-16 20:29:05 +03:00
{
EVENT_HANDLER_CALLED_BY_CLIENT ;
waitWhileDialog ( ) ;
CCS - > soundh - > playSound ( soundBase : : heroNewLevel ) ;
2012-05-18 17:02:27 +03:00
//boost::function<void(ui32)>(boost::bind(&CCallback::selectionMade,cl->callbacks[h->tempOwner].get(),_1,id))
auto callback2 = boost : : bind ( & CCallback : : selectionMade , cb , 0 , playerID ) ;
showYesNoDialog ( " Commander got level " , callback2 , callback2 , true , std : : vector < CComponent * > ( ) ) ;
//showYesNoDialog ("Commander got level", callback, callback, true, std::vector<CComponent*>());
//TODO: display full window
//CCreatureWindow * cw = new CCreatureWindow(commander);
//GH.pushInt(cw);
2012-05-16 20:29:05 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : heroInGarrisonChange ( const CGTownInstance * town )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-03-21 00:17:19 +02:00
updateInfo ( town ) ;
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02:00
if ( town - > garrisonHero & & vstd : : contains ( wanderingHeroes , town - > garrisonHero ) ) //wandering hero moved to the garrison
2008-01-26 21:36:31 +02:00
{
2010-01-02 03:48:44 +02:00
CGI - > mh - > hideObject ( town - > garrisonHero ) ;
wanderingHeroes - = town - > garrisonHero ;
}
2008-01-26 21:36:31 +02:00
2010-01-02 03:48:44 +02:00
if ( town - > visitingHero & & ! vstd : : contains ( wanderingHeroes , town - > visitingHero ) ) //hero leaves garrison
{
CGI - > mh - > printObject ( town - > visitingHero ) ;
wanderingHeroes . push_back ( town - > visitingHero ) ;
}
2011-10-04 22:43:49 +03:00
adventureInt - > updateNextHero ( NULL ) ;
2009-04-11 04:32:50 +03:00
2011-02-25 19:57:30 +02:00
if ( CCastleInterface * c = castleInt )
2010-01-02 03:48:44 +02:00
{
c - > garr - > highlighted = NULL ;
2011-02-25 19:57:30 +02:00
c - > garr - > setArmy ( town - > getUpperArmy ( ) , 0 ) ;
2011-02-05 15:39:10 +02:00
c - > garr - > setArmy ( town - > visitingHero , 1 ) ;
2010-01-02 03:48:44 +02:00
c - > garr - > recreateSlots ( ) ;
2011-04-30 21:16:58 +03:00
c - > heroes - > update ( ) ;
2008-08-15 15:11:42 +03:00
}
2011-12-17 21:59:59 +03:00
BOOST_FOREACH ( IShowActivatable * isa , GH . listInt )
2011-07-22 19:22:22 +03:00
{
CKingdomInterface * ki = dynamic_cast < CKingdomInterface * > ( isa ) ;
if ( ki )
{
ki - > townChanged ( town ) ;
ki - > updateGarrisons ( ) ;
}
}
2010-01-02 03:48:44 +02:00
GH . totalRedraw ( ) ;
}
void CPlayerInterface : : heroVisitsTown ( const CGHeroInstance * hero , const CGTownInstance * town )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-08-12 18:54:25 +03:00
if ( hero - > tempOwner ! = playerID )
2010-01-02 03:48:44 +02:00
return ;
2011-05-25 17:48:49 +03:00
waitWhileDialog ( ) ;
2010-01-02 03:48:44 +02:00
openTownWindow ( town ) ;
}
2011-02-24 15:14:52 +02:00
void CPlayerInterface : : garrisonChanged ( const CGObjectInstance * obj , bool updateInfobox /*= true*/ )
2010-01-02 03:48:44 +02:00
{
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2011-02-24 15:14:52 +02:00
if ( updateInfobox )
updateInfo ( obj ) ;
2009-04-14 15:47:09 +03:00
2011-12-17 21:59:59 +03:00
for ( std : : list < IShowActivatable * > : : iterator i = GH . listInt . begin ( ) ; i ! = GH . listInt . end ( ) ; i + + )
2008-01-31 23:35:30 +02:00
{
2011-12-17 21:59:59 +03:00
if ( ( * i ) - > type & IShowActivatable : : WITH_GARRISON )
2008-01-31 23:35:30 +02:00
{
2011-01-06 22:00:19 +02:00
CGarrisonHolder * cgh = dynamic_cast < CGarrisonHolder * > ( * i ) ;
2010-07-22 03:32:45 +03:00
cgh - > updateGarrisons ( ) ;
2010-05-26 12:47:53 +03:00
}
2010-07-20 09:05:45 +03:00
else if ( CTradeWindow * cmw = dynamic_cast < CTradeWindow * > ( * i ) )
2010-05-26 12:47:53 +03:00
{
if ( obj = = cmw - > hero )
cmw - > garrisonChanged ( ) ;
2010-02-06 15:27:58 +02:00
}
2008-01-31 23:35:30 +02:00
}
2008-05-18 20:33:39 +03:00
2010-01-02 03:48:44 +02:00
GH . totalRedraw ( ) ;
2008-05-18 20:33:39 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : buildChanged ( const CGTownInstance * town , int buildingID , int what ) //what: 1 - built, 2 - demolished
2008-05-18 20:33:39 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-01-02 03:48:44 +02:00
switch ( buildingID )
{
case 7 : case 8 : case 9 : case 10 : case 11 : case 12 : case 13 : case 15 :
2010-03-21 00:17:19 +02:00
updateInfo ( town ) ;
break ;
2010-01-02 03:48:44 +02:00
}
2010-03-21 00:17:19 +02:00
2010-01-02 03:48:44 +02:00
if ( ! castleInt )
return ;
if ( castleInt - > town ! = town )
return ;
switch ( what )
{
case 1 :
2010-12-19 16:39:56 +02:00
CCS - > soundh - > playSound ( soundBase : : newBuilding ) ;
2010-01-02 03:48:44 +02:00
castleInt - > addBuilding ( buildingID ) ;
break ;
case 2 :
castleInt - > removeBuilding ( buildingID ) ;
break ;
}
2008-05-18 20:33:39 +03:00
}
2010-01-02 03:48:44 +02:00
2010-12-04 21:15:20 +02:00
void CPlayerInterface : : battleStart ( const CCreatureSet * army1 , const CCreatureSet * army2 , int3 tile , const CGHeroInstance * hero1 , const CGHeroInstance * hero2 , bool side )
2008-05-18 20:33:39 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2012-02-22 16:41:27 +03:00
waitForAllDialogs ( ) ;
2010-01-02 03:48:44 +02:00
GH . pushInt ( battleInt ) ;
2008-05-18 20:33:39 +03:00
}
2010-01-02 03:48:44 +02:00
2008-05-18 20:33:39 +03:00
2011-06-21 15:45:57 +03:00
void CPlayerInterface : : battleStacksHealedRes ( const std : : vector < std : : pair < ui32 , ui32 > > & healedStacks , bool lifeDrain , bool tentHeal , si32 lifeDrainFrom )
2008-05-18 20:33:39 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2010-01-02 03:48:44 +02:00
for ( int b = 0 ; b < healedStacks . size ( ) ; + + b )
2008-05-18 20:33:39 +03:00
{
2010-01-02 03:48:44 +02:00
const CStack * healed = cb - > battleGetStackByID ( healedStacks [ b ] . first ) ;
2011-02-09 15:56:30 +02:00
if ( battleInt - > creAnims [ healed - > ID ] - > getType ( ) = = CCreatureAnim : : DEATH )
2008-05-18 20:33:39 +03:00
{
2010-01-02 03:48:44 +02:00
//stack has been resurrected
2011-02-09 15:56:30 +02:00
battleInt - > creAnims [ healed - > ID ] - > setType ( CCreatureAnim : : HOLDING ) ;
2008-05-18 20:33:39 +03:00
}
}
2010-05-07 15:29:41 +03:00
if ( lifeDrain )
{
const CStack * attacker = cb - > battleGetStackByID ( healedStacks [ 0 ] . first , false ) ;
const CStack * defender = cb - > battleGetStackByID ( lifeDrainFrom , false ) ;
2011-05-04 05:35:44 +03:00
int textOff = 0 ;
2010-05-07 15:29:41 +03:00
if ( attacker )
{
2011-09-05 09:37:24 +03:00
battleInt - > displayEffect ( 52 , attacker - > position ) ; //TODO: transparency
2011-05-04 05:35:44 +03:00
if ( attacker - > count > 1 )
{
textOff + = 1 ;
}
2011-06-25 18:05:01 +03:00
CCS - > soundh - > playSound ( soundBase : : DRAINLIF ) ;
2010-05-07 15:29:41 +03:00
}
2011-05-04 05:35:44 +03:00
2010-05-07 15:29:41 +03:00
//print info about life drain
char textBuf [ 1000 ] ;
sprintf ( textBuf , CGI - > generaltexth - > allTexts [ 361 + textOff ] . c_str ( ) , attacker - > getCreature ( ) - > nameSing . c_str ( ) ,
healedStacks [ 0 ] . second , defender - > getCreature ( ) - > namePl . c_str ( ) ) ;
battleInt - > console - > addText ( textBuf ) ;
}
2011-06-21 15:45:57 +03:00
if ( tentHeal )
{
std : : string text = CGI - > generaltexth - > allTexts [ 414 ] ;
boost : : algorithm : : replace_first ( text , " %s " , cb - > battleGetStackByID ( lifeDrainFrom , false ) - > getCreature ( ) - > nameSing ) ;
boost : : algorithm : : replace_first ( text , " %s " , cb - > battleGetStackByID ( healedStacks [ 0 ] . first , false ) - > getCreature ( ) - > nameSing ) ;
boost : : algorithm : : replace_first ( text , " %d " , boost : : lexical_cast < std : : string > ( healedStacks [ 0 ] . second ) ) ;
battleInt - > console - > addText ( text ) ;
}
2010-01-02 03:48:44 +02:00
}
2010-12-23 22:18:10 +02:00
void CPlayerInterface : : battleNewStackAppeared ( const CStack * stack )
2010-01-02 03:48:44 +02:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2012-04-06 18:02:15 +03:00
2010-12-23 22:18:10 +02:00
battleInt - > newStack ( stack ) ;
2010-01-02 03:48:44 +02:00
}
void CPlayerInterface : : battleObstaclesRemoved ( const std : : set < si32 > & removedObstacles )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2012-05-18 23:50:16 +03:00
// for(std::set<si32>::const_iterator it = removedObstacles.begin(); it != removedObstacles.end(); ++it)
// {
// for(std::map< int, CDefHandler * >::iterator itBat = battleInt->idToObstacle.begin(); itBat != battleInt->idToObstacle.end(); ++itBat)
// {
// if(itBat->first == *it) //remove this obstacle
// {
// battleInt->idToObstacle.erase(itBat);
// break;
// }
// }
// }
2010-01-02 03:48:44 +02:00
//update accessible hexes
battleInt - > redrawBackgroundWithHexes ( battleInt - > activeStack ) ;
2008-05-18 20:33:39 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : battleCatapultAttacked ( const CatapultAttack & ca )
2008-05-18 20:33:39 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2010-01-02 03:48:44 +02:00
battleInt - > stackIsCatapulting ( ca ) ;
2008-05-18 20:33:39 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : battleStacksRemoved ( const BattleStacksRemoved & bsr )
2008-05-18 20:33:39 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2010-01-02 03:48:44 +02:00
for ( std : : set < ui32 > : : const_iterator it = bsr . stackIDs . begin ( ) ; it ! = bsr . stackIDs . end ( ) ; + + it ) //for each removed stack
{
2011-05-30 02:49:25 +03:00
battleInt - > stackRemoved ( * it ) ;
//battleInt->stackRemoved(LOCPLINT->cb->battleGetStackByID(*it));
2010-01-02 03:48:44 +02:00
}
2008-05-18 20:33:39 +03:00
}
2010-01-02 03:48:44 +02:00
2011-09-24 04:15:36 +03:00
void CPlayerInterface : : battleNewRound ( int round ) //called at the beginning of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
2008-05-31 23:37:54 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2010-01-02 03:48:44 +02:00
battleInt - > newRound ( round ) ;
2008-05-31 23:37:54 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : actionStarted ( const BattleAction * action )
2008-05-18 20:33:39 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2010-01-02 03:48:44 +02:00
curAction = new BattleAction ( * action ) ;
battleInt - > startAction ( action ) ;
2008-05-18 20:33:39 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : actionFinished ( const BattleAction * action )
2008-05-18 20:33:39 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2010-01-02 03:48:44 +02:00
delete curAction ;
curAction = NULL ;
battleInt - > endAction ( action ) ;
2008-05-27 16:16:35 +03:00
}
2008-08-13 03:44:31 +03:00
2010-12-23 22:18:10 +02:00
BattleAction CPlayerInterface : : activeStack ( const CStack * stack ) //called when it's turn of that stack
2008-08-13 03:44:31 +03:00
{
2012-04-06 18:02:15 +03:00
THREAD_CREATED_BY_CLIENT ;
2012-04-03 02:23:14 +03:00
tlog5 < < " Awaiting command for " < < stack - > nodeName ( ) < < std : : endl ;
2010-01-02 03:48:44 +02:00
CBattleInterface * b = battleInt ;
2012-04-03 02:23:14 +03:00
assert ( ! b - > givenCommand - > get ( ) ) ; //command buffer must be clean (we don't want to use old command)
2010-01-02 03:48:44 +02:00
{
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2010-12-23 22:18:10 +02:00
b - > stackActivated ( stack ) ;
2011-07-06 20:00:45 +03:00
//Regeneration & mana drain go there
2010-01-02 03:48:44 +02:00
}
//wait till BattleInterface sets its command
boost : : unique_lock < boost : : mutex > lock ( b - > givenCommand - > mx ) ;
while ( ! b - > givenCommand - > data )
2012-02-20 00:03:43 +03:00
{
2010-01-02 03:48:44 +02:00
b - > givenCommand - > cond . wait ( lock ) ;
2012-02-20 00:03:43 +03:00
if ( ! battleInt ) //batle ended while we were waiting for movement (eg. because of spell)
throw boost : : thread_interrupted ( ) ; //will shut the thread peacefully
}
2010-01-02 03:48:44 +02:00
//tidy up
BattleAction ret = * ( b - > givenCommand - > data ) ;
delete b - > givenCommand - > data ;
b - > givenCommand - > data = NULL ;
//return command
2012-04-03 02:23:14 +03:00
tlog5 < < " Giving command for " < < stack - > nodeName ( ) < < std : : endl ;
2010-01-02 03:48:44 +02:00
return ret ;
}
2009-05-19 21:23:04 +03:00
2010-12-04 21:44:23 +02:00
void CPlayerInterface : : battleEnd ( const BattleResult * br )
2010-01-02 03:48:44 +02:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2010-01-02 03:48:44 +02:00
battleInt - > battleFinished ( * br ) ;
2009-05-19 21:23:04 +03:00
}
2010-01-02 03:48:44 +02:00
2011-12-22 16:05:19 +03:00
void CPlayerInterface : : battleStackMoved ( const CStack * stack , std : : vector < BattleHex > dest , int distance )
2008-08-13 03:44:31 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2011-08-01 20:36:18 +03:00
battleInt - > stackMoved ( stack , dest , distance ) ;
2010-01-02 03:48:44 +02:00
}
2010-12-04 21:44:23 +02:00
void CPlayerInterface : : battleSpellCast ( const BattleSpellCast * sc )
2010-01-02 03:48:44 +02:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2010-01-02 03:48:44 +02:00
battleInt - > spellCast ( sc ) ;
}
2010-12-04 21:44:23 +02:00
void CPlayerInterface : : battleStacksEffectsSet ( const SetStackEffect & sse )
2010-01-02 03:48:44 +02:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2010-01-02 03:48:44 +02:00
battleInt - > battleStacksEffectsSet ( sse ) ;
}
2011-10-08 16:02:58 +03:00
void CPlayerInterface : : battleTriggerEffect ( const BattleTriggerEffect & bte )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-10-08 16:02:58 +03:00
battleInt - > battleTriggerEffect ( bte ) ;
}
2010-12-04 21:44:23 +02:00
void CPlayerInterface : : battleStacksAttacked ( const std : : vector < BattleStackAttacked > & bsa )
2010-01-02 03:48:44 +02:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2012-04-06 18:02:15 +03:00
2011-12-22 16:05:19 +03:00
std : : vector < StackAttackedInfo > arg ;
2010-12-04 21:44:23 +02:00
for ( std : : vector < BattleStackAttacked > : : const_iterator i = bsa . begin ( ) ; i ! = bsa . end ( ) ; i + + )
2009-02-14 15:51:21 +02:00
{
2010-12-24 23:44:48 +02:00
const CStack * defender = cb - > battleGetStackByID ( i - > stackAttacked , false ) ;
const CStack * attacker = cb - > battleGetStackByID ( i - > attackerID , false ) ;
2010-01-02 03:48:44 +02:00
if ( i - > isEffect ( ) & & i - > effect ! = 12 ) //and not armageddon
{
2011-07-03 08:55:57 +03:00
if ( defender & & ! i - > isSecondary ( ) )
2010-12-24 23:44:48 +02:00
battleInt - > displayEffect ( i - > effect , defender - > position ) ;
2010-01-02 03:48:44 +02:00
}
2012-04-18 18:57:49 +03:00
bool shooting = ( LOCPLINT - > curAction ? LOCPLINT - > curAction - > actionType = = BattleAction : : SHOOT : false ) ; //FIXME: why action is deleted during enchanter cast?
StackAttackedInfo to_put = { defender , i - > damageAmount , i - > killedAmount , attacker , shooting , i - > killed ( ) , i - > willRebirth ( ) , i - > cloneKilled ( ) } ;
2010-01-02 03:48:44 +02:00
arg . push_back ( to_put ) ;
2009-02-04 05:55:12 +02:00
}
2009-06-11 20:21:06 +03:00
2010-01-02 03:48:44 +02:00
if ( bsa . begin ( ) - > isEffect ( ) & & bsa . begin ( ) - > effect = = 12 ) //for armageddon - I hope this condition is enough
2008-08-13 03:44:31 +03:00
{
2010-01-02 03:48:44 +02:00
battleInt - > displayEffect ( bsa . begin ( ) - > effect , - 1 ) ;
2008-08-13 03:44:31 +03:00
}
2009-06-11 20:21:06 +03:00
2010-01-02 03:48:44 +02:00
battleInt - > stacksAreAttacked ( arg ) ;
}
2010-12-04 21:44:23 +02:00
void CPlayerInterface : : battleAttack ( const BattleAttack * ba )
2010-01-02 03:48:44 +02:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-19 18:02:34 +02:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
2010-01-02 03:48:44 +02:00
assert ( curAction ) ;
if ( ba - > lucky ( ) ) //lucky hit
{
const CStack * stack = cb - > battleGetStackByID ( ba - > stackAttacking ) ;
std : : string hlp = CGI - > generaltexth - > allTexts [ 45 ] ;
2011-07-06 20:00:45 +03:00
boost : : algorithm : : replace_first ( hlp , " %s " , ( stack - > count ! = 1 ) ? stack - > getCreature ( ) - > namePl . c_str ( ) : stack - > getCreature ( ) - > nameSing . c_str ( ) ) ;
2010-01-02 03:48:44 +02:00
battleInt - > console - > addText ( hlp ) ;
2011-07-06 20:00:45 +03:00
battleInt - > displayEffect ( 18 , stack - > position ) ;
2010-01-02 03:48:44 +02:00
}
//TODO: bad luck?
2011-07-06 20:00:45 +03:00
if ( ba - > deathBlow ( ) )
{
const CStack * stack = cb - > battleGetStackByID ( ba - > stackAttacking ) ;
2011-09-01 04:40:46 +03:00
std : : string hlp = CGI - > generaltexth - > allTexts [ ( stack - > count ! = 1 ) ? 366 : 365 ] ;
2011-07-06 20:00:45 +03:00
boost : : algorithm : : replace_first ( hlp , " %s " , ( stack - > count ! = 1 ) ? stack - > getCreature ( ) - > namePl . c_str ( ) : stack - > getCreature ( ) - > nameSing . c_str ( ) ) ;
battleInt - > console - > addText ( hlp ) ;
for ( std : : vector < BattleStackAttacked > : : const_iterator i = ba - > bsa . begin ( ) ; i ! = ba - > bsa . end ( ) ; i + + )
{
const CStack * attacked = cb - > battleGetStackByID ( i - > stackAttacked ) ;
battleInt - > displayEffect ( 73 , attacked - > position ) ;
}
2012-02-16 20:10:58 +03:00
2011-07-06 20:00:45 +03:00
}
2009-02-14 16:37:13 +02:00
2010-12-23 22:18:10 +02:00
const CStack * attacker = cb - > battleGetStackByID ( ba - > stackAttacking ) ;
2010-01-02 03:48:44 +02:00
if ( ba - > shot ( ) )
2009-02-14 16:37:13 +02:00
{
2010-12-04 21:44:23 +02:00
for ( std : : vector < BattleStackAttacked > : : const_iterator i = ba - > bsa . begin ( ) ; i ! = ba - > bsa . end ( ) ; i + + )
2010-12-23 22:18:10 +02:00
{
2011-07-02 20:40:33 +03:00
if ( ! i - > isSecondary ( ) ) //display projectile only for primary target
{
2011-07-06 20:00:45 +03:00
const CStack * attacked = cb - > battleGetStackByID ( i - > stackAttacked ) ;
2011-07-02 20:40:33 +03:00
battleInt - > stackAttacking ( attacker , cb - > battleGetPos ( i - > stackAttacked ) , attacked , true ) ;
}
2010-12-23 22:18:10 +02:00
}
2010-01-02 03:48:44 +02:00
}
else
2011-07-06 20:00:45 +03:00
{
2010-01-02 03:48:44 +02:00
int shift = 0 ;
2011-12-22 16:05:19 +03:00
if ( ba - > counter ( ) & & BattleHex : : mutualPosition ( curAction - > destinationTile , attacker - > position ) < 0 )
2010-01-02 03:48:44 +02:00
{
2011-12-22 16:05:19 +03:00
int distp = BattleHex : : getDistance ( curAction - > destinationTile + 1 , attacker - > position ) ;
int distm = BattleHex : : getDistance ( curAction - > destinationTile - 1 , attacker - > position ) ;
2010-07-29 15:54:30 +03:00
if ( distp < distm )
2010-01-02 03:48:44 +02:00
shift = 1 ;
else
shift = - 1 ;
}
2010-12-23 22:18:10 +02:00
const CStack * attacked = cb - > battleGetStackByID ( ba - > bsa . begin ( ) - > stackAttacked ) ;
battleInt - > stackAttacking ( attacker , ba - > counter ( ) ? curAction - > destinationTile + shift : curAction - > additionalInfo , attacked , false ) ;
2009-02-14 16:37:13 +02:00
}
2008-08-13 03:44:31 +03:00
}
2012-05-05 11:32:55 +03:00
void CPlayerInterface : : battleObstaclePlaced ( const CObstacleInstance & obstacle )
2012-05-05 00:16:39 +03:00
{
EVENT_HANDLER_CALLED_BY_CLIENT ;
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
battleInt - > obstaclePlaced ( obstacle ) ;
}
2011-08-25 18:24:37 +03:00
void CPlayerInterface : : yourTacticPhase ( int distance )
{
2012-04-06 18:02:15 +03:00
THREAD_CREATED_BY_CLIENT ;
2011-08-26 00:08:53 +03:00
while ( battleInt & & battleInt - > tacticsMode )
2011-08-25 18:24:37 +03:00
boost : : this_thread : : sleep ( boost : : posix_time : : millisec ( 1 ) ) ;
}
2012-04-06 18:02:15 +03:00
void CPlayerInterface : : showComp ( const CComponent & comp )
2008-08-13 03:44:31 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
waitWhileDialog ( ) ; //Fix for mantis #98
2010-01-02 03:48:44 +02:00
2010-12-19 16:39:56 +02:00
CCS - > soundh - > playSoundFromSet ( CCS - > soundh - > pickupSounds ) ;
2010-01-02 03:48:44 +02:00
adventureInt - > infoBar . showComp ( & comp , 4000 ) ;
2008-08-17 12:11:16 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : showInfoDialog ( const std : : string & text , const std : : vector < Component * > & components , int soundID )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-12-22 16:05:19 +03:00
std : : vector < CComponent * > intComps ;
2010-01-02 03:48:44 +02:00
for ( int i = 0 ; i < components . size ( ) ; i + + )
2011-12-22 16:05:19 +03:00
intComps . push_back ( new CComponent ( * components [ i ] ) ) ;
2010-01-02 03:48:44 +02:00
showInfoDialog ( text , intComps , soundID ) ;
}
2011-12-22 16:05:19 +03:00
void CPlayerInterface : : showInfoDialog ( const std : : string & text , const std : : vector < CComponent * > & components , int soundID , bool delComps )
2008-08-17 12:11:16 +03:00
{
2010-01-02 03:48:44 +02:00
waitWhileDialog ( ) ;
2012-02-16 20:10:58 +03:00
2010-05-14 05:18:37 +03:00
stopMovement ( ) ;
2010-03-08 00:56:51 +02:00
CInfoWindow * temp = CInfoWindow : : create ( text , playerID , & components ) ;
2010-07-21 13:09:29 +03:00
temp - > setDelComps ( delComps ) ;
2010-02-22 15:30:46 +02:00
if ( makingTurn & & GH . listInt . size ( ) & & LOCPLINT = = this )
2008-08-17 12:11:16 +03:00
{
2010-12-19 16:39:56 +02:00
CCS - > soundh - > playSound ( static_cast < soundBase : : soundID > ( soundID ) ) ;
2010-01-02 03:48:44 +02:00
showingDialog - > set ( true ) ;
GH . pushInt ( temp ) ;
2008-08-17 12:11:16 +03:00
}
2010-01-02 03:48:44 +02:00
else
2009-05-19 21:23:04 +03:00
{
2010-01-02 03:48:44 +02:00
dialogs . push_back ( temp ) ;
}
}
2012-04-09 05:53:50 +03:00
void CPlayerInterface : : showYesNoDialog ( const std : : string & text , CFunctionList < void ( ) > onYes , CFunctionList < void ( ) > onNo , bool DelComps , const std : : vector < CComponent * > & components )
2010-01-02 03:48:44 +02:00
{
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2010-05-14 05:18:37 +03:00
stopMovement ( ) ;
2010-01-02 03:48:44 +02:00
LOCPLINT - > showingDialog - > setn ( true ) ;
CInfoWindow : : showYesNoDialog ( text , & components , onYes , onNo , DelComps , playerID ) ;
}
void CPlayerInterface : : showBlockingDialog ( const std : : string & text , const std : : vector < Component > & components , ui32 askID , int soundID , bool selection , bool cancel )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-01-02 03:48:44 +02:00
waitWhileDialog ( ) ;
2012-02-16 20:10:58 +03:00
2010-05-14 05:18:37 +03:00
stopMovement ( ) ;
2010-12-19 16:39:56 +02:00
CCS - > soundh - > playSound ( static_cast < soundBase : : soundID > ( soundID ) ) ;
2010-01-02 03:48:44 +02:00
if ( ! selection & & cancel ) //simple yes/no dialog
{
2011-12-22 16:05:19 +03:00
std : : vector < CComponent * > intComps ;
2010-01-02 03:48:44 +02:00
for ( int i = 0 ; i < components . size ( ) ; i + + )
2011-12-22 16:05:19 +03:00
intComps . push_back ( new CComponent ( components [ i ] ) ) ; //will be deleted by close in window
2009-04-14 15:47:09 +03:00
2012-04-09 05:53:50 +03:00
showYesNoDialog ( text , boost : : bind ( & CCallback : : selectionMade , cb , 1 , askID ) , boost : : bind ( & CCallback : : selectionMade , cb , 0 , askID ) , true , intComps ) ;
2009-05-19 21:23:04 +03:00
}
2010-01-02 03:48:44 +02:00
else if ( selection )
2009-05-19 21:23:04 +03:00
{
2010-01-02 03:48:44 +02: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-05-19 21:23:04 +03:00
{
2010-01-02 03:48:44 +02:00
pom . push_back ( std : : pair < std : : string , CFunctionList < void ( ) > > ( " ICANCEL.DEF " , 0 ) ) ;
2009-05-19 21:23:04 +03:00
}
2010-01-02 03:48:44 +02:00
int charperline = 35 ;
if ( pom . size ( ) > 1 )
2010-01-25 05:09:42 +02:00
charperline = 50 ;
2010-01-02 03:48:44 +02:00
CSelWindow * temp = new CSelWindow ( text , playerID , charperline , intComps , pom , askID ) ;
GH . pushInt ( temp ) ;
intComps [ 0 ] - > clickLeft ( true , false ) ;
2009-05-19 21:23:04 +03:00
}
2008-08-27 13:19:18 +03:00
}
2011-01-20 19:25:15 +02:00
void CPlayerInterface : : tileRevealed ( const boost : : unordered_set < int3 , ShashInt3 > & pos )
2008-08-27 13:19:18 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-01-20 19:25:15 +02:00
for ( boost : : unordered_set < int3 , ShashInt3 > : : const_iterator i = pos . begin ( ) ; i ! = pos . end ( ) ; i + + )
2010-01-02 03:48:44 +02:00
adventureInt - > minimap . showTile ( * i ) ;
if ( pos . size ( ) )
GH . totalRedraw ( ) ;
2008-08-27 13:19:18 +03:00
}
2011-01-20 19:25:15 +02:00
void CPlayerInterface : : tileHidden ( const boost : : unordered_set < int3 , ShashInt3 > & pos )
2008-08-27 13:19:18 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-01-20 19:25:15 +02:00
for ( boost : : unordered_set < int3 , ShashInt3 > : : const_iterator i = pos . begin ( ) ; i ! = pos . end ( ) ; i + + )
2010-01-02 03:48:44 +02:00
adventureInt - > minimap . hideTile ( * i ) ;
2010-06-06 09:05:39 +03:00
if ( pos . size ( ) )
GH . totalRedraw ( ) ;
2008-09-07 06:38:37 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : openHeroWindow ( const CGHeroInstance * hero )
2008-09-07 06:38:37 +03:00
{
2010-01-02 03:48:44 +02:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2011-01-06 22:00:19 +02:00
GH . pushInt ( new CHeroWindow ( hero ) ) ;
2008-09-07 06:38:37 +03:00
}
2011-01-06 22:00:19 +02:00
/*
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : heroArtifactSetChanged ( const CGHeroInstance * hero )
2009-08-05 15:46:08 +03:00
{
2010-01-02 03:48:44 +02:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2010-07-20 21:34:32 +03:00
if ( adventureInt - > heroWindow - > curHero & & adventureInt - > heroWindow - > curHero - > id = = hero - > id ) //hero window is opened
2009-08-05 15:46:08 +03:00
{
2010-01-02 03:48:44 +02:00
adventureInt - > heroWindow - > deactivate ( ) ;
2010-07-20 21:34:32 +03:00
adventureInt - > heroWindow - > setHero ( hero ) ;
2010-01-02 03:48:44 +02:00
adventureInt - > heroWindow - > activate ( ) ;
2009-08-05 15:46:08 +03:00
}
2010-07-24 14:46:04 +03:00
else if ( CExchangeWindow * cew = dynamic_cast < CExchangeWindow * > ( GH . topInt ( ) ) ) //exchange window is open
2009-08-19 13:59:42 +03:00
{
2010-01-02 03:48:44 +02:00
cew - > deactivate ( ) ;
for ( int g = 0 ; g < ARRAY_COUNT ( cew - > heroInst ) ; + + g )
2009-08-19 13:59:42 +03:00
{
2010-07-20 21:34:32 +03:00
if ( cew - > heroInst [ g ] - > id = = hero - > id )
2009-08-19 13:59:42 +03:00
{
2010-07-20 21:34:32 +03:00
cew - > heroInst [ g ] = hero ;
2010-02-08 23:17:22 +02:00
cew - > artifs [ g ] - > updateState = true ;
2010-01-02 03:48:44 +02:00
cew - > artifs [ g ] - > setHero ( hero ) ;
2010-02-08 23:17:22 +02:00
cew - > artifs [ g ] - > updateState = false ;
2009-08-19 13:59:42 +03:00
}
}
2010-01-02 03:48:44 +02:00
cew - > prepareBackground ( ) ;
cew - > activate ( ) ;
2009-08-19 13:59:42 +03:00
}
2010-07-20 09:05:45 +03:00
else if ( CTradeWindow * caw = dynamic_cast < CTradeWindow * > ( GH . topInt ( ) ) )
{
2010-07-26 18:37:58 +03:00
if ( caw - > arts )
{
caw - > deactivate ( ) ;
caw - > arts - > updateState = true ;
caw - > arts - > setHero ( hero ) ;
caw - > arts - > updateState = false ;
caw - > activate ( ) ;
}
2010-07-20 09:05:45 +03:00
}
2010-07-24 14:46:04 +03:00
updateInfo ( hero ) ;
2011-01-06 22:00:19 +02:00
} */
2009-09-01 16:54:13 +03:00
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : availableCreaturesChanged ( const CGDwelling * town )
2009-09-05 17:10:26 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-07-22 19:22:22 +03:00
if ( const CGTownInstance * townObj = dynamic_cast < const CGTownInstance * > ( town ) )
2009-09-05 17:10:26 +03:00
{
2010-01-02 03:48:44 +02:00
CFortScreen * fs = dynamic_cast < CFortScreen * > ( GH . topInt ( ) ) ;
if ( fs )
2011-04-07 20:54:08 +03:00
fs - > creaturesChanged ( ) ;
2011-07-22 19:22:22 +03:00
2011-12-17 21:59:59 +03:00
BOOST_FOREACH ( IShowActivatable * isa , GH . listInt )
2011-07-22 19:22:22 +03:00
{
CKingdomInterface * ki = dynamic_cast < CKingdomInterface * > ( isa ) ;
if ( ki & & townObj )
ki - > townChanged ( townObj ) ;
}
2010-01-02 03:48:44 +02:00
}
2010-05-15 11:33:32 +03:00
else if ( GH . listInt . size ( ) & & ( town - > ID = = 17 | | town - > ID = = 20 | | town - > ID = = 106 ) ) //external dwelling
2010-01-02 03:48:44 +02:00
{
CRecruitmentWindow * crw = dynamic_cast < CRecruitmentWindow * > ( GH . topInt ( ) ) ;
if ( crw )
crw - > initCres ( ) ;
2009-09-05 17:10:26 +03:00
}
}
2010-05-02 21:20:26 +03:00
void CPlayerInterface : : heroBonusChanged ( const CGHeroInstance * hero , const Bonus & bonus , bool gain )
2008-09-07 06:38:37 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
if ( bonus . type = = Bonus : : NONE )
return ;
2010-03-21 00:17:19 +02:00
updateInfo ( hero ) ;
2011-03-22 15:19:07 +02:00
if ( ( bonus . type = = Bonus : : FLYING_MOVEMENT | | bonus . type = = Bonus : : WATER_WALKING ) & & ! gain )
2010-05-15 18:00:19 +03:00
{
//recalculate paths because hero has lost bonus influencing pathfinding
2010-05-16 16:42:19 +03:00
eraseCurrentPathOf ( hero , false ) ;
2010-05-15 18:00:19 +03:00
}
2008-09-07 06:38:37 +03:00
}
2010-01-02 03:48:44 +02:00
template < typename Handler > void CPlayerInterface : : serializeTempl ( Handler & h , const int version )
2008-09-07 06:38:37 +03:00
{
2010-08-03 14:36:52 +03:00
h & playerID ;
2010-07-21 13:09:29 +03:00
h & spellbookSettings ;
2011-09-24 19:46:23 +03:00
2011-10-10 23:37:11 +03:00
//sleeping heroes
2011-09-24 19:46:23 +03:00
ui8 sleepingSize ;
2011-10-10 23:37:11 +03:00
if ( h . saving )
2011-09-24 19:46:23 +03:00
sleepingSize = sleepingHeroes . size ( ) ;
h & sleepingSize ;
for ( int i = 0 ; i < sleepingSize ; i + + )
{
si32 hid ;
if ( h . saving )
hid = sleepingHeroes [ i ] - > id ;
h & hid ;
if ( ! h . saving )
{
const CGHeroInstance * hero = cb - > getHero ( hid ) ;
2012-01-12 18:23:00 +03:00
sleepingHeroes + = hero ;
2011-09-24 19:46:23 +03:00
}
}
2011-10-10 23:37:11 +03:00
//hero list order
ui8 heroListSize ;
if ( h . saving )
heroListSize = wanderingHeroes . size ( ) ;
else
wanderingHeroes . clear ( ) ;
h & heroListSize ;
for ( int i = 0 ; i < heroListSize ; i + + )
{
si32 hid ;
if ( h . saving )
hid = wanderingHeroes [ i ] - > id ;
h & hid ;
if ( ! h . saving )
{
const CGHeroInstance * hero = cb - > getHero ( hid ) ;
2012-01-12 18:23:00 +03:00
wanderingHeroes + = hero ;
2011-10-10 23:37:11 +03:00
}
}
2008-09-07 06:38:37 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : serialize ( COSer < CSaveFile > & h , const int version )
2008-09-07 06:38:37 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-01-02 03:48:44 +02:00
serializeTempl ( h , version ) ;
2008-09-07 06:38:37 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : serialize ( CISer < CLoadFile > & h , const int version )
2008-09-07 06:38:37 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-01-02 03:48:44 +02:00
serializeTempl ( h , version ) ;
firstCall = - 1 ;
}
bool CPlayerInterface : : moveHero ( const CGHeroInstance * h , CGPath path )
{
2011-05-30 02:49:25 +03:00
if ( ! LOCPLINT - > makingTurn )
return false ;
2010-01-02 03:48:44 +02:00
if ( ! h )
return false ; //can't find hero
2011-09-24 19:46:23 +03:00
if ( adventureInt & & adventureInt - > isHeroSleeping ( h ) )
{
adventureInt - > sleepWake . clickLeft ( true , false ) ;
adventureInt - > sleepWake . clickLeft ( false , true ) ;
2012-02-16 20:10:58 +03:00
//could've just called
2011-09-24 19:46:23 +03:00
//adventureInt->fsleepWake();
//but no authentic button click/sound ;-)
}
2012-02-16 20:10:58 +03:00
2011-10-04 22:43:49 +03:00
int i = 1 ;
2012-02-20 00:03:43 +03:00
bool result = false ; //TODO why not set to true anywhere?
2010-01-02 03:48:44 +02:00
{
2012-02-20 00:03:43 +03:00
//evil...
auto unlockEvents = vstd : : makeUnlockGuard ( eventsM ) ;
auto unlockPim = vstd : : makeUnlockGuard ( * pim ) ;
auto unlockGs = vstd : : makeUnlockSharedGuard ( cb - > getGsMutex ( ) ) ;
2010-03-21 00:17:19 +02:00
2012-02-20 00:03:43 +03:00
{
path . convert ( 0 ) ;
boost : : unique_lock < boost : : mutex > un ( stillMoveHero . mx ) ;
stillMoveHero . data = CONTINUE_MOVE ;
2010-03-21 00:17:19 +02:00
2012-02-20 00:03:43 +03:00
enum TerrainTile : : EterrainType currentTerrain = TerrainTile : : border ; // not init yet
enum TerrainTile : : EterrainType newTerrain ;
int sh = - 1 ;
2010-05-16 16:42:19 +03:00
2012-02-20 00:03:43 +03:00
const TerrainTile * curTile = cb - > getTile ( CGHeroInstance : : convertPosition ( h - > pos , false ) ) ;
2011-09-19 23:50:25 +03:00
2012-02-20 00:03:43 +03:00
for ( i = path . nodes . size ( ) - 1 ; i > 0 & & ( stillMoveHero . data = = CONTINUE_MOVE | | curTile - > blocked ) ; i - - )
2010-03-21 00:17:19 +02:00
{
2012-02-20 00:03:43 +03:00
//changing z coordinate means we're moving through subterranean gate -> it's done automatically upon the visit, so we don't have to request that move here
if ( path . nodes [ i - 1 ] . coord . z ! = path . nodes [ i ] . coord . z )
continue ;
//stop sending move requests if the next node can't be reached at the current turn (hero exhausted his move points)
if ( path . nodes [ i - 1 ] . turns )
{
stillMoveHero . data = STOP_MOVE ;
break ;
}
2010-05-06 15:13:31 +03:00
2012-02-20 00:03:43 +03:00
// Start a new sound for the hero movement or let the existing one carry on.
2010-01-02 03:48:44 +02:00
#if 0
2012-02-20 00:03:43 +03:00
// TODO
if ( hero is flying & & sh = = - 1 )
sh = CCS - > soundh - > playSound ( soundBase : : horseFlying , - 1 ) ;
2010-01-02 03:48:44 +02:00
# endif
2011-09-19 23:50:25 +03:00
{
2012-02-20 00:03:43 +03:00
newTerrain = cb - > getTile ( CGHeroInstance : : convertPosition ( path . nodes [ i ] . coord , false ) ) - > tertype ;
if ( newTerrain ! = currentTerrain )
{
CCS - > soundh - > stopSound ( sh ) ;
sh = CCS - > soundh - > playSound ( CCS - > soundh - > horseSounds [ newTerrain ] , - 1 ) ;
currentTerrain = newTerrain ;
}
2010-03-21 00:17:19 +02:00
}
2009-05-19 21:23:04 +03:00
2012-02-20 00:03:43 +03:00
stillMoveHero . data = WAITING_MOVE ;
2009-05-19 21:23:04 +03:00
2012-02-20 00:03:43 +03:00
int3 endpos ( path . nodes [ i - 1 ] . coord . x , path . nodes [ i - 1 ] . coord . y , h - > pos . z ) ;
bool guarded = CGI - > mh - > map - > isInTheMap ( cb - > guardingCreaturePosition ( endpos - int3 ( 1 , 0 , 0 ) ) ) ;
2010-05-06 15:13:31 +03:00
2012-02-20 00:03:43 +03:00
cb - > moveHero ( h , endpos ) ;
2010-02-28 14:39:38 +02:00
2012-02-20 00:03:43 +03:00
while ( stillMoveHero . data ! = STOP_MOVE & & stillMoveHero . data ! = CONTINUE_MOVE )
stillMoveHero . cond . wait ( un ) ;
2010-05-06 15:13:31 +03:00
2012-02-20 00:03:43 +03:00
if ( guarded ) // Abort movement if a guard was fought.
break ;
}
CCS - > soundh - > stopSound ( sh ) ;
2010-03-21 00:17:19 +02:00
}
2008-09-07 06:38:37 +03:00
2012-02-20 00:03:43 +03:00
//RAII unlocks
2010-03-21 00:17:19 +02:00
}
2008-09-07 06:38:37 +03:00
2011-10-04 22:43:49 +03:00
if ( adventureInt )
{
// (i == 0) means hero went through all the path
2012-02-16 20:10:58 +03:00
adventureInt - > updateMoveHero ( h , ( i ! = 0 ) ) ;
2011-10-04 22:43:49 +03:00
adventureInt - > updateNextHero ( h ) ;
}
2010-01-02 03:48:44 +02:00
return result ;
2008-09-07 06:38:37 +03:00
}
2010-01-02 03:48:44 +02:00
bool CPlayerInterface : : shiftPressed ( ) const
2008-09-07 06:38:37 +03:00
{
2010-01-02 03:48:44 +02:00
return SDL_GetKeyState ( NULL ) [ SDLK_LSHIFT ] | | SDL_GetKeyState ( NULL ) [ SDLK_RSHIFT ] ;
}
2008-09-07 06:38:37 +03:00
2010-07-21 13:09:29 +03:00
bool CPlayerInterface : : altPressed ( ) const
{
return SDL_GetKeyState ( NULL ) [ SDLK_LALT ] | | SDL_GetKeyState ( NULL ) [ SDLK_RALT ] ;
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : showGarrisonDialog ( const CArmedInstance * up , const CGHeroInstance * down , bool removableUnits , boost : : function < void ( ) > & onEnd )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2012-03-12 18:00:32 +03:00
if ( stillMoveHero . get ( ) = = DURING_MOVE & & adventureInt - > terrain . currentPath & & adventureInt - > terrain . currentPath - > nodes . size ( ) > 1 ) //to ignore calls on passing through garrisons
2012-04-06 18:02:15 +03:00
{
2011-09-17 21:15:10 +03:00
onEnd ( ) ;
2010-01-02 03:48:44 +02:00
return ;
2011-09-17 21:15:10 +03:00
}
2008-09-07 06:38:37 +03:00
2012-04-06 18:02:15 +03:00
waitForAllDialogs ( ) ;
2010-01-02 03:48:44 +02:00
CGarrisonWindow * cgw = new CGarrisonWindow ( up , down , removableUnits ) ;
cgw - > quit - > callback + = onEnd ;
GH . pushInt ( cgw ) ;
}
2008-09-25 17:09:31 +03:00
2010-02-27 03:05:39 +02:00
/**
* Shows the dialog that appears when right - clicking an artifact that can be assembled
* into a combinational one on an artifact screen . Does not require the combination of
* artifacts to be legal .
* @ param artifactID ID of a constituent artifact .
* @ param assembleTo ID of artifact to assemble a constituent into , not used when assemble
* is false .
* @ param assemble True if the artifact is to be assembled , false if it is to be disassembled .
*/
void CPlayerInterface : : showArtifactAssemblyDialog ( ui32 artifactID , ui32 assembleTo , bool assemble , CFunctionList < void ( ) > onYes , CFunctionList < void ( ) > onNo )
{
2010-06-26 19:02:10 +03:00
const CArtifact & artifact = * CGI - > arth - > artifacts [ artifactID ] ;
2010-02-27 03:05:39 +02:00
std : : string text = artifact . Description ( ) ;
text + = " \n \n " ;
2011-12-22 16:05:19 +03:00
std : : vector < CComponent * > scs ;
2010-02-27 03:05:39 +02:00
if ( assemble ) {
2010-06-26 19:02:10 +03:00
const CArtifact & assembledArtifact = * CGI - > arth - > artifacts [ assembleTo ] ;
2010-02-27 03:05:39 +02:00
// You possess all of the components to...
text + = boost : : str ( boost : : format ( CGI - > generaltexth - > allTexts [ 732 ] ) % assembledArtifact . Name ( ) ) ;
// Picture of assembled artifact at bottom.
2011-12-22 16:05:19 +03:00
CComponent * sc = new CComponent ;
sc - > type = CComponent : : artifact ;
2010-02-27 03:05:39 +02:00
sc - > subtype = assembledArtifact . id ;
sc - > description = assembledArtifact . Description ( ) ;
sc - > subtitle = assembledArtifact . Name ( ) ;
scs . push_back ( sc ) ;
} else {
// Do you wish to disassemble this artifact?
text + = CGI - > generaltexth - > allTexts [ 733 ] ;
}
2012-04-09 05:53:50 +03:00
showYesNoDialog ( text , onYes , onNo , true , scs ) ;
2010-02-27 03:05:39 +02:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : requestRealized ( PackageApplied * pa )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-01-02 03:48:44 +02:00
if ( stillMoveHero . get ( ) = = DURING_MOVE )
stillMoveHero . setn ( CONTINUE_MOVE ) ;
2009-05-19 21:23:04 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : heroExchangeStarted ( si32 hero1 , si32 hero2 )
2008-09-25 17:09:31 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-08-12 18:54:25 +03:00
GH . pushInt ( new CExchangeWindow ( hero1 , hero2 ) ) ;
2010-01-02 03:48:44 +02:00
}
2009-05-06 13:14:48 +03:00
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : objectPropertyChanged ( const SetObjectProperty * sop )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-01-02 03:48:44 +02:00
//redraw minimap if owner changed
2010-05-02 21:20:26 +03:00
if ( sop - > what = = ObjProperty : : OWNER )
2009-05-19 21:23:04 +03:00
{
2011-05-03 06:14:18 +03:00
const CGObjectInstance * obj = cb - > getObj ( sop - > id ) ;
2010-01-02 03:48:44 +02:00
std : : set < int3 > pos = obj - > getBlockedPos ( ) ;
for ( std : : set < int3 > : : const_iterator it = pos . begin ( ) ; it ! = pos . end ( ) ; + + it )
2009-08-18 14:49:34 +03:00
{
2010-01-02 03:48:44 +02:00
if ( cb - > isVisible ( * it ) )
adventureInt - > minimap . showTile ( * it ) ;
2009-08-18 14:49:34 +03:00
}
2010-01-02 03:48:44 +02:00
2011-12-14 00:23:17 +03:00
if ( obj - > ID = = GameConstants : : TOWNI_TYPE )
2011-03-22 15:19:07 +02:00
{
2010-02-26 13:18:09 +02:00
if ( obj - > tempOwner = = playerID )
towns . push_back ( static_cast < const CGTownInstance * > ( obj ) ) ;
else
towns - = obj ;
2011-03-22 15:19:07 +02:00
}
2010-02-26 13:18:09 +02:00
assert ( cb - > getTownsInfo ( ) . size ( ) = = towns . size ( ) ) ;
2009-05-08 05:58:41 +03:00
}
2010-01-02 03:48:44 +02:00
2008-09-25 17:09:31 +03:00
}
2010-02-26 13:18:09 +02:00
void CPlayerInterface : : recreateHeroTownList ( )
2008-09-25 17:09:31 +03:00
{
2011-10-10 23:37:11 +03:00
std : : vector < const CGHeroInstance * > newWanderingHeroes ;
std : : vector < const CGHeroInstance * > allHeroes = cb - > getHeroesInfo ( ) ;
//applying current heroes order to new heroes info
int j ;
for ( int i = 0 ; i < wanderingHeroes . size ( ) ; i + + )
2011-12-14 00:23:17 +03:00
if ( ( j = vstd : : find_pos ( allHeroes , wanderingHeroes [ i ] ) ) > = 0 )
2011-10-10 23:37:11 +03:00
if ( ! allHeroes [ j ] - > inTownGarrison )
{
newWanderingHeroes + = allHeroes [ j ] ;
allHeroes - = allHeroes [ j ] ;
}
2012-02-16 20:10:58 +03:00
//all the rest of new heroes go the end of the list
2010-01-02 03:48:44 +02:00
wanderingHeroes . clear ( ) ;
2011-10-10 23:37:11 +03:00
wanderingHeroes = newWanderingHeroes ;
newWanderingHeroes . clear ( ) ;
for ( int i = 0 ; i < allHeroes . size ( ) ; i + + )
if ( ! allHeroes [ i ] - > inTownGarrison )
2012-02-16 20:10:58 +03:00
wanderingHeroes + = allHeroes [ i ] ;
2011-10-10 23:37:11 +03:00
std : : vector < const CGTownInstance * > newTowns ;
std : : vector < const CGTownInstance * > allTowns = cb - > getTownsInfo ( ) ;
for ( int i = 0 ; i < towns . size ( ) ; i + + )
2011-12-14 00:23:17 +03:00
if ( ( j = vstd : : find_pos ( allTowns , towns [ i ] ) ) > = 0 )
2011-10-10 23:37:11 +03:00
{
newTowns + = allTowns [ j ] ;
allTowns - = allTowns [ j ] ;
}
2010-02-26 13:18:09 +02:00
towns . clear ( ) ;
2011-10-10 23:37:11 +03:00
towns = newTowns ;
newTowns . clear ( ) ;
for ( int i = 0 ; i < allTowns . size ( ) ; i + + )
towns . push_back ( allTowns [ i ] ) ;
2011-10-04 22:43:49 +03:00
adventureInt - > updateNextHero ( NULL ) ;
2008-09-25 17:09:31 +03:00
}
2010-01-02 03:48:44 +02:00
const CGHeroInstance * CPlayerInterface : : getWHero ( int pos )
2008-09-25 17:09:31 +03:00
{
2010-01-02 03:48:44 +02:00
if ( pos < 0 | | pos > = wanderingHeroes . size ( ) )
return NULL ;
return wanderingHeroes [ pos ] ;
2008-09-25 17:09:31 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : showRecruitmentDialog ( const CGDwelling * dwelling , const CArmedInstance * dst , int level )
2008-09-25 17:09:31 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2009-07-21 02:34:06 +03:00
waitWhileDialog ( ) ;
2010-07-10 19:50:23 +03:00
CRecruitmentWindow * cr = new CRecruitmentWindow ( dwelling , level , dst , boost : : bind ( & CCallback : : recruitCreatures , cb , dwelling , _1 , _2 , - 1 ) ) ;
2010-01-02 03:48:44 +02:00
GH . pushInt ( cr ) ;
}
2009-03-28 02:38:48 +02:00
2012-04-06 18:02:15 +03:00
void CPlayerInterface : : waitWhileDialog ( bool unlockPim /*= true*/ )
2010-01-02 03:48:44 +02:00
{
2012-04-08 04:15:18 +03:00
if ( GH . amIGuiThread ( ) )
{
tlog3 < < " Cannot wait for dialogs in gui thread (deadlock risk)! \n " ;
return ;
}
2012-04-06 18:02:15 +03:00
auto unlock = vstd : : makeUnlockGuardIf ( * pim , unlockPim ) ;
2010-01-02 03:48:44 +02:00
boost : : unique_lock < boost : : mutex > un ( showingDialog - > mx ) ;
while ( showingDialog - > data )
showingDialog - > cond . wait ( un ) ;
2008-09-25 17:09:31 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : showShipyardDialog ( const IShipyard * obj )
2008-09-25 17:09:31 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-01-02 03:48:44 +02:00
int state = obj - > state ( ) ;
std : : vector < si32 > cost ;
obj - > getBoatCost ( cost ) ;
2010-02-13 06:47:31 +02:00
CShipyardWindow * csw = new CShipyardWindow ( cost , state , obj - > getBoatType ( ) , boost : : bind ( & CCallback : : buildBoat , cb , obj ) ) ;
2010-01-02 03:48:44 +02:00
GH . pushInt ( csw ) ;
2008-09-25 17:09:31 +03:00
}
2008-10-26 22:58:34 +02:00
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : newObject ( const CGObjectInstance * obj )
2008-10-26 22:58:34 +02:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-01-02 03:48:44 +02:00
//we might have built a boat in shipyard in opened town screen
2010-01-25 05:09:42 +02:00
if ( obj - > ID = = 8
& & LOCPLINT - > castleInt
2010-01-02 03:48:44 +02:00
& & obj - > pos - obj - > getVisitableOffset ( ) = = LOCPLINT - > castleInt - > town - > bestLocation ( ) )
2009-02-09 18:18:48 +02:00
{
2010-12-19 16:39:56 +02:00
CCS - > soundh - > playSound ( soundBase : : newBuilding ) ;
2011-03-22 15:19:07 +02:00
LOCPLINT - > castleInt - > addBuilding ( 20 ) ;
2009-02-09 18:18:48 +02:00
}
2010-01-02 03:48:44 +02:00
}
void CPlayerInterface : : centerView ( int3 pos , int focusTime )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-08-18 13:53:59 +03:00
waitWhileDialog ( ) ;
2010-02-20 15:24:38 +02:00
adventureInt - > centerOn ( pos ) ;
2010-01-02 03:48:44 +02:00
if ( focusTime )
2009-02-09 18:18:48 +02:00
{
2010-01-02 03:48:44 +02:00
bool activeAdv = ( GH . topInt ( ) = = adventureInt & & adventureInt - > isActive ( ) ) ;
if ( activeAdv )
adventureInt - > deactivate ( ) ;
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02:00
SDL_Delay ( focusTime ) ;
2008-10-26 22:58:34 +02:00
2010-01-02 03:48:44 +02:00
if ( activeAdv )
adventureInt - > activate ( ) ;
2009-05-19 21:23:04 +03:00
}
2008-10-26 22:58:34 +02:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : objectRemoved ( const CGObjectInstance * obj )
2008-10-26 22:58:34 +02:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-12-14 00:23:17 +03:00
if ( obj - > ID = = GameConstants : : HEROI_TYPE & & obj - > tempOwner = = playerID )
2010-01-02 03:48:44 +02:00
{
const CGHeroInstance * h = static_cast < const CGHeroInstance * > ( obj ) ;
heroKilled ( h ) ;
}
2008-10-26 22:58:34 +02:00
}
2010-01-02 03:48:44 +02:00
bool CPlayerInterface : : ctrlPressed ( ) const
2008-10-26 22:58:34 +02:00
{
2010-01-02 03:48:44 +02:00
return SDL_GetKeyState ( NULL ) [ SDLK_LCTRL ] | | SDL_GetKeyState ( NULL ) [ SDLK_RCTRL ] ;
2008-10-26 22:58:34 +02:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : update ( )
2008-10-26 22:58:34 +02:00
{
2010-02-13 06:47:31 +02:00
while ( ! terminate_cond . get ( ) & & ! pim - > try_lock ( ) ) //try acquiring long until it succeeds or we are told to terminate
boost : : this_thread : : sleep ( boost : : posix_time : : milliseconds ( 15 ) ) ;
if ( terminate_cond . get ( ) )
return ;
2012-02-16 20:10:58 +03:00
2012-02-22 16:41:27 +03:00
boost : : unique_lock < boost : : recursive_mutex > un ( * pim , boost : : adopt_lock ) ; //create lock from already owned mutex
2011-05-30 02:49:25 +03:00
//make sure that gamestate won't change when GUI objects may obtain its parts on event processing or drawing request
boost : : shared_lock < boost : : shared_mutex > gsLock ( cb - > getGsMutex ( ) ) ;
2010-01-02 03:48:44 +02:00
//if there are any waiting dialogs, show them
2010-07-24 14:46:04 +03:00
if ( ( howManyPeople < = 1 | | makingTurn ) & & dialogs . size ( ) & & ! showingDialog - > get ( ) )
2009-02-09 18:18:48 +02:00
{
2010-01-02 03:48:44 +02:00
showingDialog - > set ( true ) ;
GH . pushInt ( dialogs . front ( ) ) ;
dialogs . pop_front ( ) ;
2009-02-09 18:18:48 +02:00
}
2010-01-02 03:48:44 +02:00
2010-06-01 02:53:35 +03:00
//in some conditions we may receive calls before selection is initialized - we must ignore them
2010-12-23 02:33:48 +02:00
if ( adventureInt & & ! adventureInt - > selection & & GH . topInt ( ) = = adventureInt )
2011-05-29 17:06:52 +03:00
{
2010-06-01 02:53:35 +03:00
return ;
2011-05-29 17:06:52 +03:00
}
2010-06-01 02:53:35 +03:00
2011-04-13 22:52:56 +03:00
// Handles mouse and key input
GH . updateTime ( ) ;
GH . handleEvents ( ) ;
2010-12-23 02:33:48 +02:00
if ( adventureInt & & ! adventureInt - > isActive ( ) & & adventureInt - > scrollingDir ) //player forces map scrolling though interface is disabled
2010-01-02 03:48:44 +02:00
GH . totalRedraw ( ) ;
else
GH . simpleRedraw ( ) ;
2012-01-12 18:23:00 +03:00
if ( settings [ " general " ] [ " showfps " ] . Bool ( ) )
2011-04-17 21:02:13 +03:00
GH . drawFPSCounter ( ) ;
2011-04-13 22:52:56 +03:00
// draw the mouse cursor and update the screen
CCS - > curh - > draw1 ( ) ;
CSDL_Ext : : update ( screen ) ;
CCS - > curh - > draw2 ( ) ;
2010-01-02 03:48:44 +02:00
}
int CPlayerInterface : : getLastIndex ( std : : string namePrefix )
{
using namespace boost : : filesystem ;
using namespace boost : : algorithm ;
std : : map < std : : time_t , int > dates ; //save number => datestamp
directory_iterator enddir ;
2010-01-25 05:09:42 +02:00
for ( directory_iterator dir ( GVCMIDirs . UserPath + " /Games " ) ; dir ! = enddir ; dir + + )
2010-01-02 03:48:44 +02:00
{
if ( is_regular ( dir - > status ( ) ) )
2009-06-28 16:49:39 +03:00
{
2011-02-24 16:01:58 +02:00
std : : string name = dir - > path ( ) . leaf ( ) ;
2010-01-02 03:48:44 +02:00
if ( starts_with ( name , namePrefix ) & & ends_with ( name , " .vlgm1 " ) )
2009-06-28 16:49:39 +03:00
{
2010-01-02 03:48:44 +02:00
char nr = name [ namePrefix . size ( ) ] ;
if ( std : : isdigit ( nr ) )
{
dates [ last_write_time ( dir - > path ( ) ) ] = boost : : lexical_cast < int > ( nr ) ;
}
2009-06-28 16:49:39 +03:00
}
}
}
2010-01-02 03:48:44 +02:00
if ( dates . size ( ) )
return ( - - dates . end ( ) ) - > second ; //return latest file number
return 0 ;
2008-10-26 22:58:34 +02:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : initMovement ( const TryMoveHero & details , const CGHeroInstance * ho , const int3 & hp )
2008-10-26 22:58:34 +02:00
{
2010-01-02 03:48:44 +02:00
if ( details . end . x + 1 = = details . start . x & & details . end . y + 1 = = details . start . y ) //tl
2009-07-26 13:43:22 +03:00
{
2010-01-02 03:48:44 +02:00
//ho->moveDir = 1;
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 ) ) ) ;
2009-02-09 18:18:48 +02:00
2010-01-02 03:48:44 +02:00
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 ) ;
2009-04-03 18:55:26 +03:00
2010-01-02 03:48:44 +02:00
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 ) ;
2009-04-03 18:55:26 +03:00
2010-01-02 03:48:44 +02:00
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 ) ;
2009-04-03 18:55:26 +03:00
2010-01-02 03:48:44 +02: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-03 18:55:26 +03:00
2010-01-02 03:48:44 +02: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-04 22:26:41 +03:00
}
2010-01-02 03:48:44 +02:00
else if ( details . end . x = = details . start . x & & details . end . y + 1 = = details . start . y ) //t
{
//ho->moveDir = 2;
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 ) ) ) ;
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02:00
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 ) ;
2009-04-04 22:26:41 +03:00
2010-01-02 03:48:44 +02:00
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 ) ;
2009-04-05 17:37:14 +03:00
2010-01-02 03:48:44 +02:00
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 ) ;
}
else if ( details . end . x - 1 = = details . start . x & & details . end . y + 1 = = details . start . y ) //tr
2009-04-03 18:55:26 +03:00
{
2010-01-02 03:48:44 +02:00
//ho->moveDir = 3;
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 ) ) ) ;
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02: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 ) ) ) ;
2009-04-03 18:55:26 +03:00
2010-01-02 03:48:44 +02: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 ) ) ) ;
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02:00
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 ) ;
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02: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-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02: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 ) ;
}
else if ( details . end . x - 1 = = details . start . x & & details . end . y = = details . start . y ) //r
{
//ho->moveDir = 4;
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 ) ) ) ;
2009-04-03 18:55:26 +03:00
2010-01-02 03:48:44 +02: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-03 18:55:26 +03:00
2010-01-02 03:48:44 +02: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-12-20 19:14:14 +02:00
2010-01-02 03:48:44 +02: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 ) ;
2009-04-04 22:26:41 +03:00
}
2010-01-02 03:48:44 +02:00
else if ( details . end . x - 1 = = details . start . x & & details . end . y - 1 = = details . start . y ) //br
2009-04-04 22:26:41 +03:00
{
2010-01-02 03:48:44 +02:00
//ho->moveDir = 5;
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 ) ) ) ;
2009-04-14 15:47:09 +03:00
2010-01-02 03:48:44 +02: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 ) ) ) ;
2009-04-14 15:47:09 +03:00
2010-01-02 03:48:44 +02: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-06-16 14:18:14 +03:00
2010-01-02 03:48:44 +02: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 ) ;
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 ) ;
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 ) ;
}
else if ( details . end . x = = details . start . x & & details . end . y - 1 = = details . start . y ) //b
2009-07-30 15:49:45 +03:00
{
2010-01-02 03:48:44 +02:00
//ho->moveDir = 6;
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 ) ;
2009-08-22 16:59:15 +03:00
2010-01-02 03:48:44 +02: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 ) ;
2009-07-30 15:49:45 +03:00
2010-01-02 03:48:44 +02: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 ) ) ) ;
2009-07-30 15:49:45 +03:00
2010-01-02 03:48:44 +02: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 ) ;
}
else if ( details . end . x + 1 = = details . start . x & & details . end . y - 1 = = details . start . y ) //bl
{
//ho->moveDir = 7;
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 ) ;
2009-06-11 20:21:06 +03:00
2010-01-02 03:48:44 +02: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-07-06 22:41:27 +03:00
2010-01-02 03:48:44 +02: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-07-18 06:13:13 +03:00
2010-01-02 03:48:44 +02: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-07-21 02:34:06 +03:00
2010-01-02 03:48:44 +02: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-07-26 06:33:13 +03:00
2010-01-02 03:48:44 +02: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 ) ;
2009-07-26 06:33:13 +03:00
}
2010-01-02 03:48:44 +02:00
else if ( details . end . x + 1 = = details . start . x & & details . end . y = = details . start . y ) //l
2009-08-13 04:03:11 +03:00
{
2010-01-02 03:48:44 +02:00
//ho->moveDir = 8;
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-08-13 04:03:11 +03:00
2010-01-02 03:48:44 +02: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-08-13 04:03:11 +03:00
2010-01-02 03:48:44 +02: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 - 3 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . end ( ) , ocmptwo_cgin ) ;
2009-08-13 04:03:11 +03:00
}
2009-08-11 10:50:29 +03:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : movementPxStep ( const TryMoveHero & details , int i , const int3 & hp , const CGHeroInstance * ho )
2009-08-04 02:53:18 +03:00
{
2010-01-02 03:48:44 +02:00
if ( details . end . x + 1 = = details . start . x & & details . end . y + 1 = = details . start . y ) //tl
2009-08-04 02:53:18 +03:00
{
2010-01-02 03:48:44 +02:00
//setting advmap shift
adventureInt - > terrain . moveX = i - 32 ;
adventureInt - > terrain . moveY = i - 32 ;
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 ) ;
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 ) ;
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-08-04 02:53:18 +03:00
}
2010-01-02 03:48:44 +02:00
else if ( details . end . x = = details . start . x & & details . end . y + 1 = = details . start . y ) //t
{
//setting advmap shift
adventureInt - > terrain . moveY = i - 32 ;
2009-08-04 02:53:18 +03:00
2010-01-02 03:48:44 +02: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 ) ;
2009-11-29 04:46:30 +02:00
2010-01-02 03:48:44 +02: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-12-28 06:08:24 +02:00
2010-01-02 03:48:44 +02: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 ) ;
}
else if ( details . end . x - 1 = = details . start . x & & details . end . y + 1 = = details . start . y ) //tr
2009-12-28 06:08:24 +02:00
{
2010-01-02 03:48:44 +02:00
//setting advmap shift
adventureInt - > terrain . moveX = - i + 32 ;
adventureInt - > terrain . moveY = i - 32 ;
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 ) ;
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 ) ;
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 ) ;
}
else if ( details . end . x - 1 = = details . start . x & & details . end . y = = details . start . y ) //r
{
//setting advmap shift
adventureInt - > terrain . moveX = - i + 32 ;
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 ) ;
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-12-28 06:08:24 +02:00
}
2010-01-02 03:48:44 +02:00
else if ( details . end . x - 1 = = details . start . x & & details . end . y - 1 = = details . start . y ) //br
{
2009-12-28 06:08:24 +02:00
2010-01-02 03:48:44 +02:00
//setting advmap shift
adventureInt - > terrain . moveX = - i + 32 ;
adventureInt - > terrain . moveY = - i + 32 ;
2009-12-28 06:08:24 +02:00
2010-01-02 03:48:44 +02: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-12-28 06:08:24 +02:00
2010-01-02 03:48:44 +02: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-12-28 06:08:24 +02:00
2010-01-02 03:48:44 +02: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 ) ;
}
else if ( details . end . x = = details . start . x & & details . end . y - 1 = = details . start . y ) //b
{
//setting advmap shift
adventureInt - > terrain . moveY = - i + 32 ;
2009-12-28 06:08:24 +02:00
2010-01-02 03:48:44 +02: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 ) ;
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 ) ;
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 ) ;
}
else if ( details . end . x + 1 = = details . start . x & & details . end . y - 1 = = details . start . y ) //bl
{
//setting advmap shift
adventureInt - > terrain . moveX = i - 32 ;
adventureInt - > terrain . moveY = - i + 32 ;
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 ) ;
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 ) ;
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 ) ;
}
else if ( details . end . x + 1 = = details . start . x & & details . end . y = = details . start . y ) //l
{
//setting advmap shift
adventureInt - > terrain . moveX = i - 32 ;
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 ) ;
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 ) ;
}
2009-12-28 06:08:24 +02:00
}
2010-01-02 03:48:44 +02:00
void CPlayerInterface : : finishMovement ( const TryMoveHero & details , const int3 & hp , const CGHeroInstance * ho )
2009-12-28 06:08:24 +02:00
{
2010-01-02 03:48:44 +02:00
adventureInt - > terrain . moveX = adventureInt - > terrain . moveY = 0 ;
2009-12-28 06:08:24 +02:00
2010-01-02 03:48:44 +02:00
if ( details . end . x + 1 = = details . start . x & & details . end . y + 1 = = details . start . y ) //tl
2009-12-28 06:08:24 +02:00
{
2010-01-02 03:48:44 +02: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 ) ;
}
else if ( details . end . x = = details . start . x & & details . end . y + 1 = = details . start . y ) //t
{
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 ) ;
}
else if ( details . end . x - 1 = = details . start . x & & details . end . y + 1 = = details . start . y ) //tr
{
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 ) ;
}
else if ( details . end . x - 1 = = details . start . x & & details . end . y = = details . start . y ) //r
{
delObjRect ( hp . x - 2 , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x - 2 , hp . y , hp . z , ho - > id ) ;
}
else if ( details . end . x - 1 = = details . start . x & & details . end . y - 1 = = details . start . y ) //br
{
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 ) ;
}
else if ( details . end . x = = details . start . x & & details . end . y - 1 = = details . start . y ) //b
{
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 ) ;
}
else if ( details . end . x + 1 = = details . start . x & & details . end . y - 1 = = details . start . y ) //bl
{
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 ) ;
}
else if ( details . end . x + 1 = = details . start . x & & details . end . y = = details . start . y ) //l
{
delObjRect ( hp . x , hp . y - 1 , hp . z , ho - > id ) ;
delObjRect ( hp . x , hp . y , hp . z , ho - > id ) ;
2009-12-28 06:08:24 +02:00
}
2010-01-02 03:48:44 +02:00
//restoring good rects
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 ) ;
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 ) ;
//restoring good order of objects
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-12-28 06:08:24 +02:00
2010-01-02 03:48:44 +02: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 ) ;
}
2010-01-29 22:52:45 +02:00
void CPlayerInterface : : gameOver ( ui8 player , bool victory )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-22 15:30:46 +02:00
if ( LOCPLINT ! = this )
return ;
2010-01-29 22:52:45 +02:00
if ( player = = playerID )
{
if ( ! victory )
showInfoDialog ( CGI - > generaltexth - > allTexts [ 95 ] ) ;
// else
// showInfoDialog("Placeholder message: you won!");
2010-02-24 15:03:36 +02:00
makingTurn = true ;
2012-04-14 10:39:32 +03:00
waitForAllDialogs ( ) ; //wait till all dialogs are displayed and closed
2010-02-24 15:03:36 +02:00
makingTurn = false ;
2010-01-29 22:52:45 +02:00
2010-07-24 14:46:04 +03:00
howManyPeople - - ;
if ( ! howManyPeople ) //all human players eliminated
{
2010-08-18 12:50:25 +03:00
if ( cb - > getStartInfo ( ) - > mode ! = StartInfo : : CAMPAIGN )
requestReturningToMainMenu ( ) ;
2010-08-20 16:34:39 +03:00
else
requestStoppingClient ( ) ;
2010-07-24 14:46:04 +03:00
}
2011-05-30 02:49:25 +03:00
cb - > unregisterMyInterface ( ) ; //we already won/lost, nothing else matters
2010-01-29 22:52:45 +02:00
}
2012-02-16 20:10:58 +03:00
2010-02-01 19:07:46 +02:00
else
{
2010-09-03 21:42:54 +03:00
if ( ! victory & & cb - > getPlayerStatus ( playerID ) = = PlayerState : : INGAME ) //enemy has lost
2012-04-06 18:02:15 +03:00
{
std : : string txt = CGI - > generaltexth - > allTexts [ 5 ] ; //%s has been vanquished!
boost : : algorithm : : replace_first ( txt , " %s " , CGI - > generaltexth - > capColors [ player ] ) ;
showInfoDialog ( txt , std : : vector < CComponent * > ( 1 , new CComponent ( CComponent : : flag , player , 0 ) ) ) ;
2010-02-01 19:07:46 +02:00
}
}
2010-01-29 22:52:45 +02:00
}
2010-05-02 21:20:26 +03:00
void CPlayerInterface : : playerBonusChanged ( const Bonus & bonus , bool gain )
2010-02-10 04:56:00 +02:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-10 04:56:00 +02:00
}
void CPlayerInterface : : showPuzzleMap ( )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-10 04:56:00 +02:00
waitWhileDialog ( ) ;
//TODO: interface should not know the real position of Grail...
2011-12-14 00:23:17 +03:00
double ratio = 0 ;
2010-02-10 04:56:00 +02:00
int3 grailPos = cb - > getGrailPos ( ratio ) ;
GH . pushInt ( new CPuzzleWindow ( grailPos , ratio ) ) ;
}
2010-05-16 16:42:19 +03:00
void CPlayerInterface : : advmapSpellCast ( const CGHeroInstance * caster , int spellID )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-05-16 16:42:19 +03:00
if ( spellID = = Spells : : FLY | | spellID = = Spells : : WATER_WALK )
{
eraseCurrentPathOf ( caster , false ) ;
}
2012-05-18 20:35:46 +03:00
const CSpell * spell = CGI - > spellh - > spells [ spellID ] ;
if ( vstd : : contains ( CCS - > soundh - > spellSounds , spell ) )
CCS - > soundh - > playSound ( CCS - > soundh - > spellSounds [ spell ] ) ;
2010-05-16 16:42:19 +03:00
}
void CPlayerInterface : : eraseCurrentPathOf ( const CGHeroInstance * ho , bool checkForExistanceOfPath /*= true */ )
2010-02-20 15:24:38 +02:00
{
2010-05-16 16:42:19 +03:00
if ( checkForExistanceOfPath )
{
assert ( vstd : : contains ( paths , ho ) ) ;
}
else if ( ! vstd : : contains ( paths , ho ) )
{
return ;
}
2010-02-20 15:24:38 +02:00
assert ( ho = = adventureInt - > selection ) ;
paths . erase ( ho ) ;
adventureInt - > terrain . currentPath = NULL ;
2012-02-18 17:59:37 +03:00
adventureInt - > updateMoveHero ( ho , false ) ;
2010-02-20 15:24:38 +02:00
}
2011-09-19 23:50:25 +03:00
void CPlayerInterface : : removeLastNodeFromPath ( const CGHeroInstance * ho )
{
adventureInt - > terrain . currentPath - > nodes . erase ( adventureInt - > terrain . currentPath - > nodes . end ( ) - 1 ) ;
2012-02-18 17:59:37 +03:00
if ( adventureInt - > terrain . currentPath - > nodes . size ( ) < 2 ) //if it was the last one, remove entire path and path with only one tile is not a real path
2011-09-19 23:50:25 +03:00
eraseCurrentPathOf ( ho ) ;
}
2010-02-20 15:24:38 +02:00
CGPath * CPlayerInterface : : getAndVerifyPath ( const CGHeroInstance * h )
{
if ( vstd : : contains ( paths , h ) ) //hero has assigned path
{
CGPath & path = paths [ h ] ;
if ( ! path . nodes . size ( ) )
{
tlog3 < < " Warning: empty path found... \n " ;
paths . erase ( h ) ;
}
else
{
2012-02-16 20:10:58 +03:00
assert ( h - > getPosition ( false ) = = path . startPos ( ) ) ;
2010-02-20 15:24:38 +02:00
//update the hero path in case of something has changed on map
if ( LOCPLINT - > cb - > getPath2 ( path . endPos ( ) , path ) )
return & path ;
else
paths . erase ( h ) ;
}
}
return NULL ;
}
void CPlayerInterface : : acceptTurn ( )
{
2012-01-12 18:23:00 +03:00
if ( settings [ " session " ] [ " autoSkip " ] . Bool ( ) )
2012-01-03 04:55:26 +03:00
{
while ( CInfoWindow * iw = dynamic_cast < CInfoWindow * > ( GH . topInt ( ) ) )
iw - > close ( ) ;
}
2010-02-20 15:24:38 +02:00
waitWhileDialog ( ) ;
if ( howManyPeople > 1 )
adventureInt - > startTurn ( ) ;
2012-04-06 18:02:15 +03:00
//boost::unique_lock<boost::recursive_mutex> un(*pim);
2010-02-20 15:24:38 +02:00
2011-08-19 22:50:24 +03:00
//Select sound for day start
int totalDays = cb - > getDate ( ) ;
2010-02-20 15:24:38 +02:00
int day = cb - > getDate ( 1 ) ;
2011-08-19 22:50:24 +03:00
int week = cb - > getDate ( 2 ) ;
if ( totalDays = = 1 )
2010-12-19 16:39:56 +02:00
CCS - > soundh - > playSound ( soundBase : : newDay ) ;
2011-08-19 22:50:24 +03:00
else if ( day ! = 1 )
CCS - > soundh - > playSound ( soundBase : : newDay ) ;
else if ( week ! = 1 )
2010-12-19 16:39:56 +02:00
CCS - > soundh - > playSound ( soundBase : : newWeek ) ;
2011-08-19 22:50:24 +03:00
else
CCS - > soundh - > playSound ( soundBase : : newMonth ) ;
2010-02-20 15:24:38 +02:00
adventureInt - > infoBar . newDay ( day ) ;
//select first hero if available.
//TODO: check if hero is slept
if ( wanderingHeroes . size ( ) )
2010-02-26 13:18:09 +02:00
adventureInt - > select ( wanderingHeroes . front ( ) ) ;
2010-02-20 15:24:38 +02:00
else
2010-02-26 13:18:09 +02:00
adventureInt - > select ( towns . front ( ) ) ;
2010-02-20 15:24:38 +02:00
2012-05-11 22:03:40 +03:00
adventureInt - > updateNextHero ( NULL ) ;
2010-02-20 15:24:38 +02:00
adventureInt - > showAll ( screen ) ;
2012-01-03 04:55:26 +03:00
2012-01-12 18:23:00 +03:00
if ( settings [ " session " ] [ " autoSkip " ] . Bool ( ) & & ! LOCPLINT - > shiftPressed ( ) )
2012-01-03 04:55:26 +03:00
{
if ( CInfoWindow * iw = dynamic_cast < CInfoWindow * > ( GH . topInt ( ) ) )
iw - > close ( ) ;
adventureInt - > endTurn . callback ( ) ;
}
2010-02-24 15:03:36 +02:00
}
void CPlayerInterface : : tryDiggging ( const CGHeroInstance * h )
{
std : : string hlp ;
2012-01-03 04:55:26 +03:00
CGI - > mh - > getTerrainDescr ( h - > getPosition ( false ) , hlp , false ) ;
int msgToShow = - 1 ;
CGHeroInstance : : ECanDig isDiggingPossible = h - > diggingStatus ( ) ;
if ( hlp . length ( ) )
isDiggingPossible = CGHeroInstance : : TILE_OCCUPIED ; //TODO integrate with canDig
switch ( isDiggingPossible )
2010-02-24 15:03:36 +02:00
{
2012-01-03 04:55:26 +03:00
case CGHeroInstance : : CAN_DIG :
break ;
case CGHeroInstance : : LACK_OF_MOVEMENT :
msgToShow = 56 ; //"Digging for artifacts requires a whole day, try again tomorrow."
break ;
case CGHeroInstance : : TILE_OCCUPIED :
msgToShow = 97 ; //Try searching on clear ground.
break ;
case CGHeroInstance : : WRONG_TERRAIN :
msgToShow = 60 ; ////Try looking on land!
break ;
default :
assert ( 0 ) ;
2010-02-24 15:03:36 +02:00
}
2012-01-03 04:55:26 +03:00
if ( msgToShow < 0 )
cb - > dig ( h ) ;
else
showInfoDialog ( CGI - > generaltexth - > allTexts [ msgToShow ] ) ;
2010-02-27 17:59:21 +02:00
}
2010-03-21 00:17:19 +02:00
void CPlayerInterface : : updateInfo ( const CGObjectInstance * specific )
{
adventureInt - > infoBar . updateSelection ( specific ) ;
// if (adventureInt->selection == specific)
// adventureInt->infoBar.showAll(screen);
2010-05-07 15:29:41 +03:00
}
void CPlayerInterface : : battleNewRoundFirst ( int round )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-05-07 15:29:41 +03:00
if ( LOCPLINT ! = this )
{ //another local interface should do this
return ;
}
battleInt - > newRoundFirst ( round ) ;
}
2010-05-14 05:18:37 +03:00
void CPlayerInterface : : stopMovement ( )
{
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
2010-05-18 10:01:54 +03:00
}
void CPlayerInterface : : showMarketWindow ( const IMarket * market , const CGHeroInstance * visitor )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-07-20 09:05:45 +03:00
if ( market - > o - > ID = = 2 ) //Altar
{
2011-12-14 00:23:17 +03:00
//EEMarketMode mode = market->availableModes().front();
if ( market - > allowsTrade ( EMarketMode : : ARTIFACT_EXP ) & & visitor - > getAlignment ( ) ! = EAlignment : : EVIL )
GH . pushInt ( new CAltarWindow ( market , visitor , EMarketMode : : ARTIFACT_EXP ) ) ;
else if ( market - > allowsTrade ( EMarketMode : : CREATURE_EXP ) & & visitor - > getAlignment ( ) ! = EAlignment : : GOOD )
GH . pushInt ( new CAltarWindow ( market , visitor , EMarketMode : : CREATURE_EXP ) ) ;
2010-07-20 09:05:45 +03:00
}
else
GH . pushInt ( new CMarketplaceWindow ( market , visitor , market - > availableModes ( ) . front ( ) ) ) ;
2010-06-27 19:03:01 +03:00
}
2010-07-20 17:08:13 +03:00
void CPlayerInterface : : showUniversityWindow ( const IMarket * market , const CGHeroInstance * visitor )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-07-20 17:08:13 +03:00
CUniversityWindow * cuw = new CUniversityWindow ( visitor , market ) ;
GH . pushInt ( cuw ) ;
}
2010-07-22 03:32:45 +03:00
void CPlayerInterface : : showHillFortWindow ( const CGObjectInstance * object , const CGHeroInstance * visitor )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-07-22 03:32:45 +03:00
CHillFortWindow * chfw = new CHillFortWindow ( visitor , object ) ;
GH . pushInt ( chfw ) ;
}
2010-06-27 19:03:01 +03:00
void CPlayerInterface : : availableArtifactsChanged ( const CGBlackMarket * bm /*= NULL*/ )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-06-27 19:03:01 +03:00
if ( CMarketplaceWindow * cmw = dynamic_cast < CMarketplaceWindow * > ( GH . topInt ( ) ) )
cmw - > artifactsChanged ( false ) ;
2010-07-09 02:03:27 +03:00
}
void CPlayerInterface : : showTavernWindow ( const CGObjectInstance * townOrTavern )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-07-09 02:03:27 +03:00
CTavernWindow * tv = new CTavernWindow ( townOrTavern ) ;
GH . pushInt ( tv ) ;
2010-07-13 08:25:40 +03:00
}
2012-03-07 17:05:54 +03:00
void CPlayerInterface : : showThievesGuildWindow ( const CGObjectInstance * obj )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2012-03-07 17:05:54 +03:00
CThievesGuildWindow * tgw = new CThievesGuildWindow ( obj ) ;
GH . pushInt ( tgw ) ;
}
2010-07-13 08:25:40 +03:00
void CPlayerInterface : : showShipyardDialogOrProblemPopup ( const IShipyard * obj )
{
if ( obj - > state ( ) )
{
MetaString txt ;
obj - > getProblemText ( txt ) ;
showInfoDialog ( txt . toString ( ) ) ;
}
else
showShipyardDialog ( obj ) ;
2010-07-21 13:09:29 +03:00
}
2010-08-18 12:50:25 +03:00
void CPlayerInterface : : requestReturningToMainMenu ( )
2010-08-20 16:34:39 +03:00
{
2012-04-08 05:29:11 +03:00
sendCustomEvent ( RETURN_TO_MAIN_MENU ) ;
2010-08-20 16:34:39 +03:00
}
void CPlayerInterface : : requestStoppingClient ( )
{
2012-04-08 05:29:11 +03:00
sendCustomEvent ( STOP_CLIENT ) ;
2010-08-20 16:34:39 +03:00
}
void CPlayerInterface : : sendCustomEvent ( int code )
2010-08-18 12:50:25 +03:00
{
SDL_Event event ;
event . type = SDL_USEREVENT ;
2010-08-20 16:34:39 +03:00
event . user . code = code ;
2010-08-18 12:50:25 +03:00
SDL_PushEvent ( & event ) ;
}
2010-12-14 23:55:23 +02:00
void CPlayerInterface : : stackChagedCount ( const StackLocation & location , const TQuantity & change , bool isAbsolute )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-12-14 23:55:23 +02:00
garrisonChanged ( location . army ) ;
}
void CPlayerInterface : : stackChangedType ( const StackLocation & location , const CCreature & newType )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-12-14 23:55:23 +02:00
garrisonChanged ( location . army ) ;
}
void CPlayerInterface : : stacksErased ( const StackLocation & location )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-12-14 23:55:23 +02:00
garrisonChanged ( location . army ) ;
}
2011-02-24 15:14:52 +02:00
# define UPDATE_IF(LOC) static_cast<const CArmedInstance*>(adventureInt->infoBar.curSel) == LOC.army.get()
2010-12-14 23:55:23 +02:00
void CPlayerInterface : : stacksSwapped ( const StackLocation & loc1 , const StackLocation & loc2 )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-02-24 15:14:52 +02:00
garrisonChanged ( loc1 . army , UPDATE_IF ( loc1 ) ) ;
2010-12-14 23:55:23 +02:00
if ( loc2 . army ! = loc1 . army )
2011-02-24 15:14:52 +02:00
garrisonChanged ( loc2 . army , UPDATE_IF ( loc2 ) ) ;
2010-12-14 23:55:23 +02:00
}
void CPlayerInterface : : newStackInserted ( const StackLocation & location , const CStackInstance & stack )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-12-14 23:55:23 +02:00
garrisonChanged ( location . army ) ;
}
void CPlayerInterface : : stacksRebalanced ( const StackLocation & src , const StackLocation & dst , TQuantity count )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-02-24 15:14:52 +02:00
garrisonChanged ( src . army , UPDATE_IF ( src ) ) ;
2010-12-14 23:55:23 +02:00
if ( dst . army ! = src . army )
2011-02-24 15:14:52 +02:00
garrisonChanged ( dst . army , UPDATE_IF ( dst ) ) ;
2010-12-14 23:55:23 +02:00
}
2011-02-24 15:14:52 +02:00
# undef UPDATE_IF
2010-12-14 23:55:23 +02:00
2011-01-06 22:00:19 +02:00
void CPlayerInterface : : artifactPut ( const ArtifactLocation & al )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-01-06 22:00:19 +02:00
}
void CPlayerInterface : : artifactRemoved ( const ArtifactLocation & al )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-12-17 21:59:59 +03:00
BOOST_FOREACH ( IShowActivatable * isa , GH . listInt )
2011-04-23 00:51:10 +03:00
{
2011-12-17 21:59:59 +03:00
if ( isa - > type & IShowActivatable : : WITH_ARTIFACTS )
2011-04-23 00:51:10 +03:00
{
2011-07-01 19:26:36 +03:00
( dynamic_cast < CArtifactHolder * > ( isa ) ) - > artifactRemoved ( al ) ;
2011-04-23 00:51:10 +03:00
}
}
2011-01-06 22:00:19 +02:00
}
void CPlayerInterface : : artifactMoved ( const ArtifactLocation & src , const ArtifactLocation & dst )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-12-17 21:59:59 +03:00
BOOST_FOREACH ( IShowActivatable * isa , GH . listInt )
2011-03-22 15:19:07 +02:00
{
2011-12-17 21:59:59 +03:00
if ( isa - > type & IShowActivatable : : WITH_ARTIFACTS )
2011-03-22 15:19:07 +02:00
{
2011-07-01 19:26:36 +03:00
( dynamic_cast < CArtifactHolder * > ( isa ) ) - > artifactMoved ( src , dst ) ;
2011-03-22 15:19:07 +02:00
}
}
2011-01-06 22:00:19 +02:00
}
2011-01-22 05:43:20 +02:00
void CPlayerInterface : : artifactAssembled ( const ArtifactLocation & al )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-12-17 21:59:59 +03:00
BOOST_FOREACH ( IShowActivatable * isa , GH . listInt )
2011-03-22 15:19:07 +02:00
{
2011-12-17 21:59:59 +03:00
if ( isa - > type & IShowActivatable : : WITH_ARTIFACTS )
2011-03-22 15:19:07 +02:00
{
2011-07-01 19:26:36 +03:00
( dynamic_cast < CArtifactHolder * > ( isa ) ) - > artifactAssembled ( al ) ;
2011-03-22 15:19:07 +02:00
}
}
2011-01-22 05:43:20 +02:00
}
void CPlayerInterface : : artifactDisassembled ( const ArtifactLocation & al )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2011-12-17 21:59:59 +03:00
BOOST_FOREACH ( IShowActivatable * isa , GH . listInt )
2011-03-22 15:19:07 +02:00
{
2011-12-17 21:59:59 +03:00
if ( isa - > type & IShowActivatable : : WITH_ARTIFACTS )
2011-03-22 15:19:07 +02:00
{
2011-07-01 19:26:36 +03:00
( dynamic_cast < CArtifactHolder * > ( isa ) ) - > artifactDisassembled ( al ) ;
2011-03-22 15:19:07 +02:00
}
}
2011-01-22 05:43:20 +02:00
}
2012-02-14 21:04:45 +03:00
void CPlayerInterface : : playerStartsTurn ( ui8 player )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
if ( ! GH . listInt . size ( ) )
2012-02-17 00:19:07 +03:00
{
2012-04-06 18:02:15 +03:00
GH . pushInt ( adventureInt ) ;
adventureInt - > activateKeys ( ) ;
}
if ( howManyPeople = = 1 )
{
GH . curInt = this ;
adventureInt - > startTurn ( ) ;
2012-02-17 00:19:07 +03:00
}
2012-02-14 21:04:45 +03:00
if ( player ! = playerID & & this = = LOCPLINT )
{
2012-02-17 00:19:07 +03:00
waitWhileDialog ( ) ;
2012-02-22 16:41:27 +03:00
adventureInt - > aiTurnStarted ( ) ;
}
}
2012-02-17 00:19:07 +03:00
2012-04-06 18:02:15 +03:00
void CPlayerInterface : : waitForAllDialogs ( bool unlockPim /*= true*/ )
2012-02-22 16:41:27 +03:00
{
2012-04-06 18:02:15 +03:00
while ( dialogs . size ( ) )
2012-02-22 16:41:27 +03:00
{
2012-04-06 18:02:15 +03:00
auto unlock = vstd : : makeUnlockGuardIf ( * pim , unlockPim ) ;
SDL_Delay ( 5 ) ;
2012-02-14 21:04:45 +03:00
}
2012-04-06 18:02:15 +03:00
waitWhileDialog ( unlockPim ) ;
2012-02-14 21:04:45 +03:00
}
2011-02-24 15:57:47 +02:00
2012-04-09 05:53:50 +03:00
void CPlayerInterface : : proposeLoadingGame ( )
{
showYesNoDialog ( CGI - > generaltexth - > allTexts [ 68 ] , [ this ] { sendCustomEvent ( RETURN_TO_MENU_LOAD ) ; } , 0 , false ) ;
}
2010-07-21 13:09:29 +03:00
CPlayerInterface : : SpellbookLastSetting : : SpellbookLastSetting ( )
{
spellbookLastPageBattle = spellbokLastPageAdvmap = 0 ;
spellbookLastTabBattle = spellbookLastTabAdvmap = 4 ;
2010-10-31 00:53:41 +03:00
}