2011-12-14 00:23:17 +03:00
# include "StdInc.h"
2008-03-16 02:09:43 +02:00
# include "CAdvmapInterface.h"
2013-04-07 14:52:07 +03:00
# include "battle/CBattleInterface.h"
# include "battle/CBattleInterfaceClasses.h"
2009-05-20 13:08:56 +03:00
# include "../CCallback.h"
2008-08-27 13:19:18 +03:00
# include "CCastleInterface.h"
2013-04-07 14:52:07 +03:00
# include "gui/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"
2012-07-06 22:12:04 +03:00
# include "CQuestLog.h"
2007-11-19 00:58:28 +02:00
# include "CMessage.h"
2008-08-27 13:19:18 +03:00
# include "CPlayerInterface.h"
2013-04-07 14:52:07 +03:00
# include "gui/SDL_Extensions.h"
2012-09-29 13:59:43 +03:00
# include "../lib/CConfigHandler.h"
2013-04-07 14:52:07 +03:00
# include "battle/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"
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"
2013-04-07 13:48:07 +03:00
# include "../lib/mapping/CMap.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"
2013-04-07 14:52:07 +03:00
# include "gui/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
2013-06-23 14:25:48 +03:00
# define RETURN_IF_QUICK_COMBAT \
2013-06-23 19:09:15 +03:00
if ( isAutoFightOn & & ! battleInt ) \
2013-06-23 14:25:48 +03:00
return ;
# define BATTLE_EVENT_POSSIBLE_RETURN\
if ( LOCPLINT ! = this ) \
return ; \
RETURN_IF_QUICK_COMBAT
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
2012-09-11 17:25:19 +03: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 ;
2013-02-05 23:06:13 +03:00
CondSh < bool > CPlayerInterface : : terminate_cond ;
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
2014-06-24 02:26:36 +03:00
static bool objectBlitOrderSorter ( const std : : pair < const CGObjectInstance * , SDL_Rect > & a , const std : : pair < const CGObjectInstance * , SDL_Rect > & b )
2007-11-19 00:58:28 +02:00
{
2014-06-24 02:26:36 +03:00
return CMapHandler : : compareObjectBlitOrder ( a . first , b . first ) ;
}
2008-11-02 00:32:56 +02:00
2013-03-03 20:06:03 +03:00
CPlayerInterface : : CPlayerInterface ( PlayerColor Player )
2008-01-26 21:36:31 +02:00
{
2013-04-09 17:31:36 +03:00
logGlobal - > traceStream ( ) < < " \t Human player interface for player " < < Player < < " being constructed " ;
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 ;
2013-06-26 14:18:27 +03:00
curAction = nullptr ;
2009-05-19 21:23:04 +03:00
playerID = Player ;
human = true ;
2013-06-26 14:18:27 +03:00
castleInt = nullptr ;
battleInt = nullptr ;
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 ;
2013-06-23 19:09:15 +03:00
isAutoFightOn = false ;
2014-06-21 09:49:27 +03:00
duringMovement = false ;
2014-07-02 22:53:49 +03:00
ignoreEvents = false ;
2014-07-03 21:05:59 +03:00
locked = false ;
2008-01-26 21:36:31 +02:00
}
2013-02-19 02:10:46 +03:00
2009-05-19 21:23:04 +03:00
CPlayerInterface : : ~ CPlayerInterface ( )
2008-05-23 22:50:11 +03:00
{
2013-09-02 01:55:57 +03:00
logGlobal - > traceStream ( ) < < " \t Human player interface for player " < < playerID < < " being destructed " ;
//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 ;
delete cingconsole ;
2013-09-02 01:55:57 +03:00
if ( LOCPLINT = = this )
LOCPLINT = nullptr ;
2009-02-04 15:40:54 +02:00
}
2013-06-22 17:47:20 +03:00
void CPlayerInterface : : init ( shared_ptr < CCallback > CB )
2008-01-26 21:36:31 +02:00
{
2013-06-22 17:47:20 +03:00
cb = CB ;
2010-12-23 02:33:48 +02:00
if ( observerInDuelMode )
return ;
2012-06-13 16:04:06 +03:00
if ( ! towns . size ( ) & & ! wanderingHeroes . size ( ) )
initializeHeroTownList ( ) ;
2010-12-23 02:33:48 +02:00
2010-02-20 15:24:38 +02:00
if ( ! adventureInt )
adventureInt = new CAdvMapInt ( ) ;
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 ;
2013-06-26 14:18:27 +03:00
adventureInt - > selection = nullptr ;
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 ;
2012-08-07 14:28:52 +03:00
cb - > save ( " Saves/Newgame_Autosave_ " + boost : : lexical_cast < std : : string > ( index + 1 ) ) ;
2010-02-20 15:24:38 +02:00
}
firstCall = 0 ;
}
else
{
2012-08-07 14:28:52 +03:00
LOCPLINT - > cb - > save ( " Saves/Autosave_ " + boost : : lexical_cast < std : : string > ( autosaveCount + + + 1 ) ) ;
2010-02-20 15:24:38 +02:00
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 ;
2013-03-03 20:06:03 +03:00
cmp . push_back ( new CComponent ( CComponent : : flag , playerID . getNum ( ) , 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
2013-02-14 02:55:42 +03:00
STRONG_INLINE void subRect ( const int & x , const int & y , const int & z , const SDL_Rect & r , const ObjectInstanceID & 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 ] ;
2013-06-29 16:05:48 +03:00
for ( auto & elem : hlp . objects )
if ( elem . first - > id = = hid )
2009-05-19 21:23:04 +03:00
{
2013-06-29 16:05:48 +03:00
elem . second = r ;
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
2013-02-14 02:55:42 +03:00
STRONG_INLINE void delObjRect ( const int & x , const int & y , const int & z , const ObjectInstanceID & 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 )
2013-02-14 02:55:42 +03:00
if ( hlp . objects [ h ] . first - > id = = hid )
2009-05-19 21:23:04 +03:00
{
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
2013-04-20 14:34:01 +03:00
const CGHeroInstance * hero = 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
2013-04-20 14:34:01 +03:00
if ( ! hero )
2011-07-17 21:49:05 +03:00
{
//AI hero left the visible area (we can't obtain info)
2014-03-23 15:59:03 +03:00
//TODO very evil workaround -> retrieve pointer to hero so we could animate it
2012-02-14 21:04:45 +03:00
// 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 ] ;
2013-06-29 16:05:48 +03:00
for ( auto & elem : tile . objects )
if ( elem . first - > id = = details . id )
hero = dynamic_cast < const CGHeroInstance * > ( elem . first ) ;
2012-02-14 21:04:45 +03:00
2013-04-20 14:34:01 +03:00
if ( ! hero ) //still nothing...
2012-02-14 21:04:45 +03:00
return ;
2011-07-17 21:49:05 +03:00
}
2013-04-20 14:34:01 +03:00
adventureInt - > centerOn ( hero ) ; //actualizing screen pos
2012-06-13 16:04:06 +03:00
adventureInt - > minimap . redraw ( ) ;
adventureInt - > heroList . redraw ( ) ;
2009-05-19 21:23:04 +03:00
2010-05-06 15:13:31 +03:00
bool directlyAttackingCreature =
2013-04-20 14:34:01 +03:00
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
2013-04-20 14:34:01 +03:00
if ( makingTurn & & hero - > 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
2013-04-20 14:34:01 +03:00
CCS - > musich - > playMusicFromSet ( " terrain " , LOCPLINT - > cb - > getTile ( hero - > visitablePos ( ) ) - > terType , true ) ;
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 )
2014-03-07 16:21:09 +03:00
{
2012-02-18 17:59:37 +03:00
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
2013-04-20 14:34:01 +03:00
removeLastNodeFromPath ( hero ) ;
2012-02-18 17:59:37 +03:00
}
else
{
//teleport was not along current path, it'll now be invalid (hero is somewhere else)
2013-04-20 14:34:01 +03:00
eraseCurrentPathOf ( hero ) ;
2012-02-18 17:59:37 +03:00
}
}
2013-04-20 14:34:01 +03:00
adventureInt - > heroList . update ( hero ) ;
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
}
2013-04-20 14:34:01 +03:00
if ( hero - > 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
{
2013-04-20 14:34:01 +03:00
eraseCurrentPathOf ( hero , false ) ;
2008-01-26 21:36:31 +02:00
}
2013-04-20 14:34:01 +03:00
else if ( adventureInt - > terrain . currentPath & & hero - > 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
2013-04-20 14:34:01 +03:00
removeLastNodeFromPath ( hero ) ;
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
{
2013-04-20 14:34:01 +03:00
hero - > isStanding = true ;
2009-05-19 21:23:04 +03:00
stillMoveHero . setn ( STOP_MOVE ) ;
2009-08-07 01:36:51 +03:00
GH . totalRedraw ( ) ;
2013-04-20 14:34:01 +03:00
adventureInt - > heroList . update ( hero ) ;
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
2013-04-20 14:34:01 +03:00
initMovement ( details , hero , 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
{
2013-04-20 14:34:01 +03:00
movementPxStep ( details , i , hp , hero ) ;
2010-01-02 03:48:44 +02:00
adventureInt - > updateScreen = true ;
adventureInt - > show ( screen ) ;
2014-06-21 11:13:19 +03:00
{
//evil returns here ...
//todo: get rid of it
logGlobal - > traceStream ( ) < < " before [un]locks in " < < __FUNCTION__ ;
auto unlockPim = vstd : : makeUnlockGuard ( * pim ) ; //let frame to be rendered
GH . mainFPSmng - > framerateDelay ( ) ; //for animation purposes
logGlobal - > traceStream ( ) < < " after [un]locks in " < < __FUNCTION__ ;
}
//CSDL_Ext::update(screen);
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
2013-04-20 14:34:01 +03:00
finishMovement ( details , hp , hero ) ;
hero - > isStanding = true ;
2009-05-19 21:23:04 +03:00
2010-01-02 03:48:44 +02:00
//move finished
2012-06-13 16:04:06 +03:00
adventureInt - > minimap . redraw ( ) ;
2013-04-20 14:34:01 +03:00
adventureInt - > heroList . update ( hero ) ;
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 ) ;
2013-11-03 15:51:25 +03:00
while ( ! events . empty ( ) )
2010-01-02 03:48:44 +02:00
{
2012-09-11 17:25:19 +03:00
SDL_Event ev = events . front ( ) ;
2010-01-02 03:48:44 +02:00
events . pop ( ) ;
2012-09-11 17:25:19 +03:00
switch ( ev . type )
2010-01-02 03:48:44 +02:00
{
case SDL_MOUSEBUTTONDOWN :
stillMoveHero . setn ( STOP_MOVE ) ;
break ;
case SDL_KEYDOWN :
2012-09-11 17:25:19 +03:00
if ( ev . key . keysym . sym < SDLK_F1 | | ev . key . keysym . sym > SDLK_F15 )
2010-01-02 03:48:44 +02:00
stillMoveHero . setn ( STOP_MOVE ) ;
break ;
}
}
}
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.
2013-04-20 14:34:01 +03:00
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?
2013-04-20 14:34:01 +03:00
const_cast < CGHeroInstance * > ( hero ) - > moveDir = dirLookup [ posOffset . y ] [ posOffset . x ] ;
2010-05-06 15:13:31 +03:00
}
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 ;
2013-09-02 01:55:57 +03:00
LOG_TRACE_PARAMS ( logGlobal , " Hero %s killed handler for player %s " , hero - > name % playerID ) ;
2012-06-22 14:40:16 +03:00
const CArmedInstance * newSelection = nullptr ;
if ( makingTurn )
{
//find new object for selection: either hero
int next = adventureInt - > getNextHeroIndex ( vstd : : find_pos ( wanderingHeroes , hero ) ) ;
if ( next > = 0 )
newSelection = wanderingHeroes [ next ] ;
//or town
if ( ! newSelection | | newSelection = = hero )
{
if ( towns . empty ( ) )
newSelection = nullptr ;
else
newSelection = towns . front ( ) ;
}
}
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 ) ;
2012-06-13 16:04:06 +03:00
adventureInt - > heroList . update ( hero ) ;
2013-09-02 01:55:57 +03:00
if ( makingTurn & & newSelection )
2012-06-22 14:40:16 +03:00
adventureInt - > select ( newSelection , true ) ;
2013-09-02 01:55:57 +03:00
else if ( adventureInt - > selection = = hero )
2012-06-22 14:40:16 +03:00
adventureInt - > selection = nullptr ;
2010-01-02 03:48:44 +02:00
}
2012-06-22 14:40:16 +03:00
2010-01-02 03:48:44 +02:00
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 ) ;
2012-06-13 16:04:06 +03:00
adventureInt - > heroList . update ( hero ) ;
2010-01-02 03:48:44 +02:00
}
void CPlayerInterface : : openTownWindow ( const CGTownInstance * town )
{
2010-07-27 02:20:21 +03:00
if ( castleInt )
2012-06-15 20:08:19 +03:00
castleInt - > close ( ) ;
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
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 ) ;
2012-06-17 01:40:28 +03:00
if ( makingTurn & & hero - > tempOwner = = playerID )
adventureInt - > heroList . update ( 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 )
2012-06-17 01:40:28 +03:00
adventureInt - > heroList . update ( hero ) ;
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
2013-05-27 13:53:28 +03:00
void CPlayerInterface : : heroGotLevel ( const CGHeroInstance * hero , PrimarySkill : : PrimarySkill pskill , std : : vector < SecondarySkill > & skills , QueryID queryID )
2010-01-02 03:48:44 +02:00
{
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
2012-07-15 18:34:00 +03:00
CLevelWindow * lw = new CLevelWindow ( hero , pskill , skills ,
[ = ] ( ui32 selection ) { cb - > selectionMade ( selection , queryID ) ; } ) ;
2010-01-02 03:48:44 +02:00
GH . pushInt ( lw ) ;
}
2013-05-27 13:53:28 +03:00
void CPlayerInterface : : commanderGotLevel ( const CCommanderInstance * commander , std : : vector < ui32 > skills , QueryID queryID )
2012-05-16 20:29:05 +03:00
{
EVENT_HANDLER_CALLED_BY_CLIENT ;
waitWhileDialog ( ) ;
CCS - > soundh - > playSound ( soundBase : : heroNewLevel ) ;
2014-03-07 16:21:09 +03:00
CCreatureWindow * cw = new CCreatureWindow ( skills , commander ,
2012-07-15 18:34:00 +03:00
[ = ] ( ui32 selection ) { cb - > selectionMade ( selection , queryID ) ; } ) ;
2012-07-03 11:07:34 +03:00
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 ) ;
2013-02-23 15:22:23 +03:00
if ( town - > garrisonHero - > tempOwner = = playerID ) // our hero
wanderingHeroes - = town - > garrisonHero ;
2010-01-02 03:48:44 +02:00
}
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 ) ;
2013-02-28 08:09:08 +03:00
if ( town - > visitingHero - > tempOwner = = playerID ) // our hero
2013-02-23 15:22:23 +03:00
wanderingHeroes . push_back ( town - > visitingHero ) ;
2010-01-02 03:48:44 +02:00
}
2012-06-13 16:04:06 +03:00
adventureInt - > heroList . update ( ) ;
2013-06-26 14:18:27 +03:00
adventureInt - > updateNextHero ( nullptr ) ;
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
{
2012-12-11 15:12:46 +03:00
c - > garr - > selectSlot ( nullptr ) ;
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
}
2013-06-29 16:05:48 +03:00
for ( 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 ) ;
}
2012-12-11 15:12:46 +03:00
void CPlayerInterface : : garrisonsChanged ( std : : vector < const CGObjectInstance * > objs )
2010-01-02 03:48:44 +02:00
{
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
2013-06-29 16:05:48 +03:00
for ( auto object : objs )
2012-12-11 15:12:46 +03:00
updateInfo ( object ) ;
2009-04-14 15:47:09 +03:00
2013-06-29 16:05:48 +03:00
for ( auto & elem : GH . listInt )
2008-01-31 23:35:30 +02:00
{
2013-06-29 16:05:48 +03:00
CGarrisonHolder * cgh = dynamic_cast < CGarrisonHolder * > ( elem ) ;
2012-06-13 16:04:06 +03:00
if ( cgh )
2010-07-22 03:32:45 +03:00
cgh - > updateGarrisons ( ) ;
2012-06-13 16:04:06 +03:00
2013-06-29 16:05:48 +03:00
if ( CTradeWindow * cmw = dynamic_cast < CTradeWindow * > ( elem ) )
2010-05-26 12:47:53 +03:00
{
2012-12-11 15:12:46 +03:00
if ( vstd : : contains ( objs , cmw - > hero ) )
2010-05-26 12:47:53 +03:00
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
2012-12-11 15:12:46 +03:00
void CPlayerInterface : : garrisonChanged ( const CGObjectInstance * obj )
{
garrisonsChanged ( std : : vector < const CGObjectInstance * > ( 1 , obj ) ) ;
}
2013-02-11 22:11:34 +03:00
void CPlayerInterface : : buildChanged ( const CGTownInstance * town , BuildingID 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 )
{
2013-02-11 22:11:34 +03:00
case BuildingID : : FORT : case BuildingID : : CITADEL : case BuildingID : : CASTLE :
case BuildingID : : VILLAGE_HALL : case BuildingID : : TOWN_HALL : case BuildingID : : CITY_HALL : case BuildingID : : CAPITOL :
case BuildingID : : RESOURCE_SILO :
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 ;
}
2012-06-13 16:04:06 +03:00
adventureInt - > townList . update ( town ) ;
2012-06-22 14:40:16 +03:00
castleInt - > townlist - > update ( town ) ;
2008-05-18 20:33:39 +03:00
}
2010-01-02 03:48:44 +02:00
2013-09-14 22:09:35 +03:00
void CPlayerInterface : : battleStartBefore ( const CCreatureSet * army1 , const CCreatureSet * army2 , int3 tile , const CGHeroInstance * hero1 , const CGHeroInstance * hero2 )
{
//Don't wait for dialogs when we are non-active hot-seat player
if ( LOCPLINT = = this )
waitForAllDialogs ( ) ;
}
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 ;
2013-06-23 14:25:48 +03:00
if ( settings [ " adventure " ] [ " quickCombat " ] . Bool ( ) )
{
autofightingAI = CDynLibHandler : : getNewBattleAI ( settings [ " server " ] [ " neutralAI " ] . String ( ) ) ;
autofightingAI - > init ( cb ) ;
autofightingAI - > battleStart ( army1 , army2 , int3 ( 0 , 0 , 0 ) , hero1 , hero2 , side ) ;
isAutoFightOn = true ;
cb - > registerBattleInterface ( autofightingAI ) ;
2010-02-19 18:02:34 +02:00
}
2014-03-07 16:21:09 +03:00
2013-09-02 01:55:57 +03:00
//Don't wait for dialogs when we are non-active hot-seat player
if ( LOCPLINT = = this )
waitForAllDialogs ( ) ;
2014-03-07 16:21:09 +03:00
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2010-02-19 18:02:34 +02:00
2013-06-29 16:05:48 +03:00
for ( auto & healedStack : healedStacks )
2008-05-18 20:33:39 +03:00
{
2013-06-29 16:05:48 +03:00
const CStack * healed = cb - > battleGetStackByID ( healedStack . first ) ;
2013-07-06 19:10:20 +03:00
if ( battleInt - > creAnims [ healed - > ID ] - > isDead ( ) )
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 ) ;
2011-05-04 05:35:44 +03:00
2013-11-07 15:48: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 ) ;
}
2010-05-07 15:29:41 +03:00
}
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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2010-02-19 18:02:34 +02:00
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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2010-02-19 18:02:34 +02:00
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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2010-02-19 18:02:34 +02:00
2013-06-29 16:05:48 +03:00
for ( auto & elem : bsr . stackIDs ) //for each removed stack
2010-01-02 03:48:44 +02:00
{
2013-06-29 16:05:48 +03:00
battleInt - > stackRemoved ( elem ) ;
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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2010-02-19 18:02:34 +02:00
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
2013-05-09 14:09:23 +03: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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2010-02-19 18:02:34 +02:00
2013-05-09 14:09:23 +03:00
curAction = new BattleAction ( action ) ;
battleInt - > startAction ( curAction ) ;
2008-05-18 20:33:39 +03:00
}
2010-01-02 03:48:44 +02:00
2013-05-09 14:09:23 +03: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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2010-02-19 18:02:34 +02:00
2013-05-09 14:09:23 +03:00
battleInt - > endAction ( curAction ) ;
2010-01-02 03:48:44 +02:00
delete curAction ;
2013-06-26 14:18:27 +03:00
curAction = nullptr ;
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 ;
2013-04-09 17:31:36 +03:00
logGlobal - > traceStream ( ) < < " Awaiting command for " < < stack - > nodeName ( ) ;
2013-06-23 14:25:48 +03:00
if ( autofightingAI )
{
if ( isAutoFightOn )
{
auto ret = autofightingAI - > activeStack ( stack ) ;
if ( isAutoFightOn )
{
return ret ;
}
}
cb - > unregisterBattleInterface ( autofightingAI ) ;
2013-06-23 22:35:54 +03:00
autofightingAI . reset ( ) ;
2013-06-23 14:25:48 +03:00
}
2010-01-02 03:48:44 +02:00
CBattleInterface * b = battleInt ;
2012-04-03 02:23:14 +03:00
2014-01-14 17:34:08 +03:00
if ( b - > givenCommand - > get ( ) )
{
logGlobal - > errorStream ( ) < < " Command buffer must be clean! (we don't want to use old command) " ;
vstd : : clear_pointer ( b - > givenCommand - > data ) ;
}
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 ;
2013-06-26 14:18:27 +03:00
b - > givenCommand - > data = nullptr ;
2010-01-02 03:48:44 +02:00
//return command
2013-04-09 17:31:36 +03:00
logGlobal - > traceStream ( ) < < " Giving command for " < < stack - > nodeName ( ) ;
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 ;
2013-06-23 14:25:48 +03:00
if ( isAutoFightOn )
{
isAutoFightOn = false ;
cb - > unregisterBattleInterface ( autofightingAI ) ;
2013-06-23 22:35:54 +03:00
autofightingAI . reset ( ) ;
2013-06-23 14:25:48 +03:00
2013-06-23 19:09:15 +03:00
if ( ! battleInt )
{
SDL_Rect temp_rect = genRect ( 561 , 470 , ( screen - > w - 800 ) / 2 + 165 , ( screen - > h - 600 ) / 2 + 19 ) ;
2013-06-29 16:05:48 +03:00
auto resWindow = new CBattleResultWindow ( * br , temp_rect , * this ) ;
2013-06-23 19:09:15 +03:00
GH . pushInt ( resWindow ) ;
2013-10-13 20:37:59 +03:00
// #1490 - during AI turn when quick combat is on, we need to display the message and wait for user to close it.
// Otherwise NewTurn causes freeze.
waitWhileDialog ( ) ;
2013-06-23 19:09:15 +03:00
return ;
}
2010-02-19 18:02:34 +02:00
}
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2010-02-19 18:02:34 +02:00
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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2010-02-19 18:02:34 +02:00
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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2010-02-19 18:02:34 +02:00
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 ;
2013-06-23 14:25:48 +03:00
//TODO why is this different (no return on LOPLINT != this) ?
RETURN_IF_QUICK_COMBAT ;
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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2014-03-07 16:21:09 +03:00
2011-12-22 16:05:19 +03:00
std : : vector < StackAttackedInfo > arg ;
2013-06-29 16:05:48 +03:00
for ( auto & elem : bsa )
2009-02-14 15:51:21 +02:00
{
2013-06-29 16:05:48 +03:00
const CStack * defender = cb - > battleGetStackByID ( elem . stackAttacked , false ) ;
const CStack * attacker = cb - > battleGetStackByID ( elem . attackerID , false ) ;
if ( elem . isEffect ( ) & & elem . effect ! = 12 ) //and not armageddon
2010-01-02 03:48:44 +02:00
{
2013-06-29 16:05:48 +03:00
if ( defender & & ! elem . isSecondary ( ) )
battleInt - > displayEffect ( elem . effect , defender - > position ) ;
2010-01-02 03:48:44 +02:00
}
2013-08-09 20:37:41 +03:00
//FIXME: why action is deleted during enchanter cast?
bool remoteAttack = false ;
if ( LOCPLINT - > curAction )
remoteAttack | = LOCPLINT - > curAction - > actionType ! = Battle : : WALK_AND_ATTACK ;
StackAttackedInfo to_put = { defender , elem . damageAmount , elem . killedAmount , attacker , remoteAttack , elem . killed ( ) , elem . willRebirth ( ) , elem . 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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2010-02-19 18:02:34 +02:00
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 ) ;
2013-05-04 16:14:23 +03:00
CCS - > soundh - > playSound ( soundBase : : GOODLUCK ) ;
}
if ( ba - > unlucky ( ) ) //unlucky hit
{
const CStack * stack = cb - > battleGetStackByID ( ba - > stackAttacking ) ;
std : : string hlp = CGI - > generaltexth - > allTexts [ 44 ] ;
boost : : algorithm : : replace_first ( hlp , " %s " , ( stack - > count ! = 1 ) ? stack - > getCreature ( ) - > namePl . c_str ( ) : stack - > getCreature ( ) - > nameSing . c_str ( ) ) ;
battleInt - > console - > addText ( hlp ) ;
battleInt - > displayEffect ( 48 , stack - > position ) ;
CCS - > soundh - > playSound ( soundBase : : BADLUCK ) ;
2010-01-02 03:48:44 +02:00
}
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 ) ;
2013-06-29 16:05:48 +03:00
for ( auto & elem : ba - > bsa )
2011-07-06 20:00:45 +03:00
{
2013-06-29 16:05:48 +03:00
const CStack * attacked = cb - > battleGetStackByID ( elem . stackAttacked ) ;
2011-07-06 20:00:45 +03:00
battleInt - > displayEffect ( 73 , attacked - > position ) ;
}
2013-05-04 16:14:23 +03:00
CCS - > soundh - > playSound ( soundBase : : deathBlow ) ;
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
{
2013-06-29 16:05:48 +03:00
for ( auto & elem : ba - > bsa )
2010-12-23 22:18:10 +02:00
{
2013-06-29 16:05:48 +03:00
if ( ! elem . isSecondary ( ) ) //display projectile only for primary target
2011-07-02 20:40:33 +03:00
{
2013-06-29 16:05:48 +03:00
const CStack * attacked = cb - > battleGetStackByID ( elem . stackAttacked ) ;
2012-08-26 12:07:48 +03:00
battleInt - > stackAttacking ( attacker , attacked - > position , attacked , true ) ;
2011-07-02 20:40:33 +03:00
}
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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2012-05-05 00:16:39 +03:00
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-06-13 16:04:06 +03:00
void CPlayerInterface : : showComp ( const Component & comp , std : : string message )
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 ) ;
2012-06-13 16:04:06 +03:00
adventureInt - > infoBar . showComponent ( comp , message ) ;
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 ;
2012-09-28 18:46:09 +03:00
if ( settings [ " session " ] [ " autoSkip " ] . Bool ( ) & & ! LOCPLINT - > shiftPressed ( ) )
{
return ;
}
2011-12-22 16:05:19 +03:00
std : : vector < CComponent * > intComps ;
2013-06-29 16:05:48 +03:00
for ( auto & component : components )
intComps . push_back ( new CComponent ( * component ) ) ;
2010-01-02 03:48:44 +02:00
showInfoDialog ( text , intComps , soundID ) ;
2012-09-28 18:46:09 +03:00
2010-01-02 03:48:44 +02:00
}
2012-12-11 15:12:46 +03:00
void CPlayerInterface : : showInfoDialog ( const std : : string & text , CComponent * component )
{
std : : vector < CComponent * > intComps ;
intComps . push_back ( component ) ;
showInfoDialog ( text , intComps , soundBase : : sound_todo , true ) ;
}
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
{
2013-09-14 22:09:35 +03:00
LOG_TRACE_PARAMS ( logGlobal , " player=%s, text=%s, is LOCPLINT=%d " , playerID % text % ( this = = LOCPLINT ) ) ;
2010-01-02 03:48:44 +02:00
waitWhileDialog ( ) ;
2012-02-16 20:10:58 +03:00
2012-09-28 18:46:09 +03:00
if ( settings [ " session " ] [ " autoSkip " ] . Bool ( ) & & ! LOCPLINT - > shiftPressed ( ) )
{
return ;
}
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 ) ;
2012-10-05 22:57:28 +03:00
stopMovement ( ) ; // interrupt movement to show dialog
2010-01-02 03:48:44 +02:00
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 ) ;
}
}
2013-11-30 12:43:31 +03:00
void CPlayerInterface : : showInfoDialogAndWait ( std : : vector < Component > & components , const MetaString & text )
{
EVENT_HANDLER_CALLED_BY_CLIENT ;
std : : vector < Component * > comps ;
for ( auto & elem : components )
{
comps . push_back ( & elem ) ;
}
std : : string str ;
text . toString ( str ) ;
showInfoDialog ( str , comps , 0 ) ;
waitWhileDialog ( ) ;
}
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 ) ;
}
2013-11-30 12:43:31 +03:00
void CPlayerInterface : : showOkDialog ( std : : vector < Component > & components , const MetaString & text , const boost : : function < void ( ) > & onOk )
{
boost : : unique_lock < boost : : recursive_mutex > un ( * pim ) ;
std : : vector < Component * > comps ;
for ( auto & elem : components )
{
comps . push_back ( & elem ) ;
}
std : : string str ;
text . toString ( str ) ;
stopMovement ( ) ;
showingDialog - > setn ( true ) ;
std : : vector < CComponent * > intComps ;
for ( auto & component : comps )
intComps . push_back ( new CComponent ( * component ) ) ;
CInfoWindow : : showOkDialog ( str , & intComps , onOk , true , playerID ) ;
}
2013-05-27 13:53:28 +03:00
void CPlayerInterface : : showBlockingDialog ( const std : : string & text , const std : : vector < Component > & components , QueryID askID , int soundID , bool selection , bool cancel )
2010-01-02 03:48:44 +02:00
{
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 ;
2013-06-29 16:05:48 +03:00
for ( auto & component : components )
intComps . push_back ( new CComponent ( component ) ) ; //will be deleted by close in window
2009-04-14 15:47:09 +03:00
2013-06-23 19:09:15 +03:00
showYesNoDialog ( text , [ = ] { cb - > selectionMade ( 1 , askID ) ; } , [ = ] { cb - > selectionMade ( 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 ;
2013-06-29 16:05:48 +03:00
for ( auto & component : components )
intComps . push_back ( new CSelectableComponent ( component ) ) ; //will be deleted by CSelWindow::close
2010-01-02 03:48:44 +02:00
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 ;
2013-06-29 16:05:48 +03:00
auto temp = new CSelWindow ( text , playerID , charperline , intComps , pom , askID ) ;
2010-01-02 03:48:44 +02:00
GH . pushInt ( temp ) ;
intComps [ 0 ] - > clickLeft ( true , false ) ;
2009-05-19 21:23:04 +03:00
}
2008-08-27 13:19:18 +03:00
}
2013-06-29 16:05:48 +03:00
void CPlayerInterface : : tileRevealed ( const std : : 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 ;
2013-12-04 06:54:02 +03:00
//FIXME: wait for dialog? Magi hut/eye would benefit from this but may break other areas
2013-06-29 16:05:48 +03:00
for ( auto & po : pos )
adventureInt - > minimap . showTile ( po ) ;
2013-11-03 15:51:25 +03:00
if ( ! pos . empty ( ) )
2010-01-02 03:48:44 +02:00
GH . totalRedraw ( ) ;
2008-08-27 13:19:18 +03:00
}
2013-06-29 16:05:48 +03:00
void CPlayerInterface : : tileHidden ( const std : : 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 ;
2013-06-29 16:05:48 +03:00
for ( auto & po : pos )
adventureInt - > minimap . hideTile ( po ) ;
2013-11-03 15:51:25 +03:00
if ( ! pos . empty ( ) )
2010-06-06 09:05:39 +03:00
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
2013-06-29 16:05:48 +03:00
for ( 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
}
2012-09-23 21:01:04 +03:00
else if ( GH . listInt . size ( ) & & ( town - > ID = = Obj : : CREATURE_GENERATOR1
| | town - > ID = = Obj : : CREATURE_GENERATOR4 | | town - > ID = = Obj : : WAR_MACHINE_FACTORY ) )
2010-01-02 03:48:44 +02:00
{
CRecruitmentWindow * crw = dynamic_cast < CRecruitmentWindow * > ( GH . topInt ( ) ) ;
2012-06-22 14:40:16 +03:00
if ( crw & & crw - > dwelling = = town )
crw - > availableCreaturesChanged ( ) ;
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 ;
2014-03-07 16:21:09 +03:00
if ( bonus . type = = Bonus : : NONE )
2012-04-06 18:02:15 +03:00
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
{
2011-09-24 19:46:23 +03:00
2013-05-09 14:09:23 +03:00
h & observerInDuelMode ;
h & wanderingHeroes & towns & sleepingHeroes ;
std : : map < const CGHeroInstance * , int3 > pathsMap ; //hero -> dest
if ( h . saving )
2011-09-24 19:46:23 +03:00
{
2013-06-29 16:05:48 +03:00
for ( auto & p : paths )
2013-08-18 18:46:28 +03:00
{
if ( p . second . nodes . size ( ) )
pathsMap [ p . first ] = p . second . endPos ( ) ;
else
logGlobal - > errorStream ( ) < < p . first - > name < < " has assigned an empty path! Ignoring it... " ;
}
2013-05-09 14:09:23 +03:00
h & pathsMap ;
2011-09-24 19:46:23 +03:00
}
2011-10-10 23:37:11 +03:00
else
{
2013-05-09 14:09:23 +03:00
h & pathsMap ;
CPathsInfo pathsInfo ( cb - > getMapSize ( ) ) ;
2013-06-29 16:05:48 +03:00
for ( auto & p : pathsMap )
2011-10-10 23:37:11 +03:00
{
2013-05-09 14:09:23 +03:00
cb - > calculatePaths ( p . first , pathsInfo ) ;
CGPath path ;
pathsInfo . getPath ( p . second , path ) ;
paths [ p . first ] = path ;
logGlobal - > traceStream ( ) < < boost : : format ( " Restored path for hero %s leading to %s with %d nodes " )
% p . first - > nodeName ( ) % p . second % path . nodes . size ( ) ;
2011-10-10 23:37:11 +03:00
}
}
2013-05-09 14:09:23 +03:00
h & spellbookSettings ;
2008-09-07 06:38:37 +03:00
}
2013-05-09 14:09:23 +03:00
void CPlayerInterface : : saveGame ( 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
}
2013-05-09 14:09:23 +03:00
void CPlayerInterface : : loadGame ( 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 ;
}
2014-06-18 13:31:11 +03:00
void CPlayerInterface : : moveHero ( const CGHeroInstance * h , CGPath path )
2010-01-02 03:48:44 +02:00
{
2013-04-09 17:31:36 +03:00
logGlobal - > traceStream ( ) < < __FUNCTION__ ;
2011-05-30 02:49:25 +03:00
if ( ! LOCPLINT - > makingTurn )
2014-06-18 13:31:11 +03:00
return ;
2010-01-02 03:48:44 +02:00
if ( ! h )
2014-06-18 13:31:11 +03:00
return ; //can't find hero
2010-01-02 03:48:44 +02:00
2012-09-08 01:43:41 +03:00
//It shouldn't be possible to move hero with open dialog (or dialog waiting in bg)
2013-11-03 15:51:25 +03:00
if ( showingDialog - > get ( ) | | ! dialogs . empty ( ) )
2014-06-18 13:31:11 +03:00
return ;
2012-09-08 01:43:41 +03:00
2014-06-21 09:49:27 +03:00
duringMovement = true ;
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 ;-)
}
2014-06-21 09:49:27 +03:00
2014-06-21 10:35:08 +03:00
boost : : thread moveHeroTask ( boost : : bind ( & CPlayerInterface : : doMoveHero , this , h , path ) ) ;
2012-02-16 20:10:58 +03:00
2014-06-21 09:49:27 +03:00
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
{
2014-05-21 22:14:05 +03:00
return isShiftKeyDown ( ) ;
2010-01-02 03:48:44 +02:00
}
2008-09-07 06:38:37 +03:00
2010-07-21 13:09:29 +03:00
bool CPlayerInterface : : altPressed ( ) const
{
2014-05-21 22:14:05 +03:00
return isAltKeyDown ( ) ;
2010-07-21 13:09:29 +03:00
}
2013-05-27 13:53:28 +03:00
void CPlayerInterface : : showGarrisonDialog ( const CArmedInstance * up , const CGHeroInstance * down , bool removableUnits , QueryID queryID )
2010-01-02 03:48:44 +02:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2012-07-15 18:34:00 +03:00
auto onEnd = [ = ] { cb - > selectionMade ( 0 , queryID ) ; } ;
2012-04-06 18:02:15 +03:00
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 ( ) ;
2013-06-29 16:05:48 +03:00
auto cgw = new CGarrisonWindow ( up , down , removableUnits ) ;
2010-01-02 03:48:44 +02:00
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.
2013-06-29 16:05:48 +03:00
auto sc = new CComponent ( CComponent : : artifact , assembledArtifact . id , 0 ) ;
2012-06-15 20:08:19 +03:00
//sc->description = assembledArtifact.Description();
//sc->subtitle = assembledArtifact.Name();
2010-02-27 03:05:39 +02:00
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 ;
2012-09-08 01:43:41 +03:00
if ( pa - > packType = = typeList . getTypeID < MoveHero > ( ) & & stillMoveHero . get ( ) = = DURING_MOVE )
2010-01-02 03:48:44 +02:00
stillMoveHero . setn ( CONTINUE_MOVE ) ;
2009-05-19 21:23:04 +03:00
}
2010-01-02 03:48:44 +02:00
2013-05-27 13:53:28 +03:00
void CPlayerInterface : : heroExchangeStarted ( ObjectInstanceID hero1 , ObjectInstanceID hero2 , QueryID query )
2008-09-25 17:09:31 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2013-05-27 13:53:28 +03:00
GH . pushInt ( new CExchangeWindow ( hero1 , hero2 , query ) ) ;
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 ( ) ;
2013-06-29 16:05:48 +03:00
for ( auto & po : pos )
2009-08-18 14:49:34 +03:00
{
2013-06-29 16:05:48 +03:00
if ( cb - > isVisible ( po ) )
adventureInt - > minimap . showTile ( po ) ;
2009-08-18 14:49:34 +03:00
}
2010-01-02 03:48:44 +02:00
2012-09-23 21:01:04 +03:00
if ( obj - > ID = = Obj : : TOWN )
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 ;
2012-06-13 16:04:06 +03:00
adventureInt - > townList . update ( ) ;
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
}
2012-06-13 16:04:06 +03:00
void CPlayerInterface : : initializeHeroTownList ( )
2008-09-25 17:09:31 +03:00
{
2011-10-10 23:37:11 +03:00
std : : vector < const CGHeroInstance * > allHeroes = cb - > getHeroesInfo ( ) ;
2012-06-13 16:04:06 +03:00
/*
std : : vector < const CGHeroInstance * > newWanderingHeroes ;
2011-10-10 23:37:11 +03:00
//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 ;
2012-06-13 16:04:06 +03:00
newWanderingHeroes . clear ( ) ; */
2013-06-29 16:05:48 +03:00
for ( auto & allHeroe : allHeroes )
if ( ! allHeroe - > inTownGarrison )
wanderingHeroes + = allHeroe ;
2011-10-10 23:37:11 +03:00
std : : vector < const CGTownInstance * > allTowns = cb - > getTownsInfo ( ) ;
2012-06-13 16:04:06 +03:00
/*
std : : vector < const CGTownInstance * > newTowns ;
2011-10-10 23:37:11 +03:00
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 ;
2012-06-13 16:04:06 +03:00
newTowns . clear ( ) ; */
2013-06-29 16:05:48 +03:00
for ( auto & allTown : allTowns )
towns . push_back ( allTown ) ;
2011-10-04 22:43:49 +03:00
2012-06-13 16:04:06 +03:00
if ( adventureInt )
2013-06-26 14:18:27 +03:00
adventureInt - > updateNextHero ( nullptr ) ;
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 ( ) ;
2013-06-23 19:09:15 +03:00
auto recruitCb = [ = ] ( CreatureID id , int count ) { LOCPLINT - > cb - > recruitCreatures ( dwelling , id , count , - 1 ) ; } ;
CRecruitmentWindow * cr = new CRecruitmentWindow ( dwelling , level , dst , recruitCb ) ;
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 ( ) )
{
2013-04-09 17:31:36 +03:00
logGlobal - > warnStream ( ) < < " Cannot wait for dialogs in gui thread (deadlock risk)! " ;
2012-04-08 04:15:18 +03:00
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 ;
2013-07-21 13:08:32 +03:00
auto state = obj - > shipyardStatus ( ) ;
2010-01-02 03:48:44 +02:00
std : : vector < si32 > cost ;
obj - > getBoatCost ( cost ) ;
2013-06-23 19:09:15 +03:00
CShipyardWindow * csw = new CShipyardWindow ( cost , state , obj - > getBoatType ( ) , [ = ] { cb - > buildBoat ( 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
2012-09-23 21:01:04 +03:00
if ( obj - > ID = = Obj : : BOAT
2010-01-25 05:09:42 +02:00
& & 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 ) ;
2013-02-11 02:24:57 +03:00
LOCPLINT - > castleInt - > addBuilding ( BuildingID : : SHIP ) ;
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
{
2013-12-04 06:54:02 +03:00
GH . totalRedraw ( ) ;
2014-06-21 16:41:05 +03:00
# ifdef VCMI_SDL1
2013-12-04 06:54:02 +03:00
CSDL_Ext : : update ( screen ) ;
2010-01-02 03:48:44 +02:00
SDL_Delay ( focusTime ) ;
2014-06-21 16:41:05 +03:00
# else
{
auto unlockPim = vstd : : makeUnlockGuard ( * pim ) ;
IgnoreEvents ignore ( * this ) ;
SDL_Delay ( focusTime ) ;
}
# endif
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 ;
2012-09-23 21:01:04 +03:00
if ( obj - > ID = = Obj : : HERO & & 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
{
2014-05-21 22:14:05 +03:00
return isCtrlKeyDown ( ) ;
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
{
2014-07-03 21:05:59 +03:00
if ( ! locked )
2014-02-01 16:35:03 +03:00
{
2014-07-03 21:05:59 +03:00
logGlobal - > errorStream ( ) < < " Non synchronized update of PlayerInterface " ;
2010-02-13 06:47:31 +02:00
return ;
2014-02-01 16:35:03 +03:00
}
2010-01-02 03:48:44 +02:00
//if there are any waiting dialogs, show them
2013-11-03 15:51:25 +03:00
if ( ( howManyPeople < = 1 | | makingTurn ) & & ! dialogs . empty ( ) & & ! 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 ( ) ;
2010-01-02 03:48:44 +02:00
}
2014-07-03 21:05:59 +03:00
void CPlayerInterface : : runLocked ( std : : function < void ( IUpdateable * ) > functor )
{
// Updating GUI requires locking pim mutex (that protects screen and GUI state).
// When ending the game, the pim mutex might be hold by other thread,
// that will notify us about the ending game by setting terminate_cond flag.
bool acquiredTheLockOnPim = false ; //for tracking whether pim mutex locking succeeded
while ( ! terminate_cond . get ( ) & & ! ( acquiredTheLockOnPim = 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 ( ! acquiredTheLockOnPim )
{
// We broke the while loop above and not because of mutex, so we must be terminating.
assert ( terminate_cond . get ( ) ) ;
return ;
}
// If we are here, pim mutex has been successfully locked - let's store it in a safe RAII lock.
boost : : unique_lock < boost : : recursive_mutex > un ( * pim , boost : : adopt_lock ) ;
// While mutexes were locked away we may be have stopped being the active interface
if ( LOCPLINT ! = this )
return ;
// 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 ( ) ) ;
locked = true ;
functor ( this ) ;
locked = false ;
}
2010-01-02 03:48:44 +02:00
int CPlayerInterface : : getLastIndex ( std : : string namePrefix )
{
using namespace boost : : filesystem ;
using namespace boost : : algorithm ;
2013-07-08 23:55:22 +03:00
path gamesDir = VCMIDirs : : get ( ) . userSavePath ( ) ;
2010-01-02 03:48:44 +02:00
std : : map < std : : time_t , int > dates ; //save number => datestamp
directory_iterator enddir ;
2012-12-19 21:19:09 +03:00
if ( ! exists ( gamesDir ) )
create_directory ( gamesDir ) ;
for ( directory_iterator dir ( gamesDir ) ; dir ! = enddir ; dir + + )
2010-01-02 03:48:44 +02:00
{
if ( is_regular ( dir - > status ( ) ) )
2009-06-28 16:49:39 +03:00
{
2012-07-02 12:04:05 +03:00
std : : string name = dir - > path ( ) . leaf ( ) . string ( ) ;
2014-03-01 20:35:56 +03:00
if ( starts_with ( name , namePrefix ) & & ends_with ( name , " .vcgm1 " ) )
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
2013-11-03 15:51:25 +03:00
if ( ! dates . empty ( ) )
2010-01-02 03:48:44 +02:00
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
2014-06-24 02:26:36 +03: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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
2009-04-03 18:55:26 +03:00
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
2009-04-03 18:55:26 +03:00
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
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
2014-06-24 02:26:36 +03: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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
2010-01-02 03:48:44 +02:00
}
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
2014-06-24 02:26:36 +03: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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
2009-05-19 21:23:04 +03:00
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
2009-05-19 21:23:04 +03:00
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
2010-01-02 03:48:44 +02:00
}
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
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
2009-12-20 19:14:14 +02:00
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
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
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y - 1 ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
2010-01-02 03:48:44 +02:00
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x + 1 ] [ hp . y ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
2010-01-02 03:48:44 +02:00
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
2010-01-02 03:48:44 +02:00
}
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
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 2 ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
2010-01-02 03:48:44 +02:00
}
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
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
2009-07-21 02:34:06 +03:00
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
2009-07-26 06:33:13 +03:00
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y + 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y + 1 ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y - 1 ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
2010-01-02 03:48:44 +02:00
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ hp . x - 3 ] [ hp . y ] [ hp . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
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
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ details . end . x - 2 ] [ details . end . y - 1 ] [ details . end . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ details . end . x - 2 ] [ details . end . y - 1 ] [ details . end . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
2009-12-28 06:08:24 +02:00
2014-06-24 02:26:36 +03:00
std : : stable_sort ( CGI - > mh - > ttiles [ details . end . x - 2 ] [ details . end . y ] [ details . end . z ] . objects . begin ( ) , CGI - > mh - > ttiles [ details . end . x - 2 ] [ details . end . y ] [ details . end . z ] . objects . end ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
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 ( ) , objectBlitOrderSorter ) ;
2010-01-02 03:48:44 +02:00
}
2010-01-29 22:52:45 +02:00
2013-11-17 20:57:04 +03:00
void CPlayerInterface : : gameOver ( PlayerColor player , const EVictoryLossCheckResult & victoryLossCheckResult )
2010-01-29 22:52:45 +02:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2010-02-22 15:30:46 +02:00
2010-01-29 22:52:45 +02:00
if ( player = = playerID )
{
2013-12-29 14:27:38 +03:00
if ( victoryLossCheckResult . loss ( ) )
showInfoDialog ( CGI - > generaltexth - > allTexts [ 95 ] ) ;
2013-12-06 22:44:11 +03:00
2013-09-02 01:55:57 +03:00
if ( LOCPLINT = = this )
{
GH . curInt = this ; //waiting for dialogs requires this to get events
waitForAllDialogs ( ) ; //wait till all dialogs are displayed and closed
}
2010-01-29 22:52:45 +02:00
2013-12-06 22:44:11 +03:00
- - howManyPeople ;
2013-12-20 18:00:48 +03:00
if ( howManyPeople = = 0 ) //all human players eliminated
{
if ( adventureInt )
{
terminate_cond . setn ( true ) ;
adventureInt - > deactivate ( ) ;
if ( GH . topInt ( ) = = adventureInt )
GH . popInt ( adventureInt ) ;
delete adventureInt ;
adventureInt = nullptr ;
}
}
2013-12-07 13:04:17 +03:00
if ( cb - > getStartInfo ( ) - > mode = = StartInfo : : CAMPAIGN )
{
// if you lose the campaign go back to the main menu
// campaign wins are handled in proposeNextMission
if ( victoryLossCheckResult . loss ( ) ) requestReturningToMainMenu ( ) ;
}
else
2010-07-24 14:46:04 +03:00
{
2013-12-06 22:44:11 +03:00
if ( howManyPeople = = 0 ) //all human players eliminated
{
requestReturningToMainMenu ( ) ;
}
else if ( victoryLossCheckResult . victory ( ) & & LOCPLINT = = this ) // end game if current human player has won
2013-09-02 01:55:57 +03:00
{
2013-12-06 22:44:11 +03:00
requestReturningToMainMenu ( ) ;
2013-09-02 01:55:57 +03:00
}
2010-07-24 14:46:04 +03:00
}
2013-09-02 01:55:57 +03:00
2013-12-06 22:44:11 +03:00
if ( GH . curInt = = this ) GH . curInt = nullptr ;
2010-01-29 22:52:45 +02:00
}
2010-02-01 19:07:46 +02:00
else
{
2013-11-17 20:57:04 +03:00
if ( victoryLossCheckResult . loss ( ) & & cb - > getPlayerStatus ( playerID ) = = EPlayerStatus : : INGAME ) //enemy has lost
2012-04-06 18:02:15 +03:00
{
2013-12-29 14:27:38 +03:00
std : : string str = victoryLossCheckResult . messageToSelf ;
boost : : algorithm : : replace_first ( str , " %s " , CGI - > generaltexth - > capColors [ player . getNum ( ) ] ) ;
showInfoDialog ( str , std : : vector < CComponent * > ( 1 , new CComponent ( CComponent : : flag , player . getNum ( ) , 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 ;
2013-02-11 02:24:57 +03:00
if ( spellID = = SpellID : : FLY | | spellID = = SpellID : : WATER_WALK )
2010-05-16 16:42:19 +03:00
{
eraseCurrentPathOf ( caster , false ) ;
}
2014-03-07 16:21:09 +03:00
const CSpell * spell = CGI - > spellh - > objects [ spellID ] ;
2014-03-10 19:00:58 +03:00
auto castSoundPath = spell - > getCastSound ( ) ;
if ( ! castSoundPath . empty ( ) )
CCS - > soundh - > playSound ( castSoundPath ) ;
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 ) ;
2013-06-26 14:18:27 +03:00
adventureInt - > terrain . currentPath = nullptr ;
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 ( ) )
{
2013-04-09 17:31:36 +03:00
logGlobal - > warnStream ( ) < < " Warning: empty path found... " ;
2010-02-20 15:24:38 +02:00
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 ) ;
}
}
2013-06-26 14:18:27 +03:00
return nullptr ;
2010-02-20 15:24:38 +02:00
}
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-09-21 20:59:54 +03:00
adventureInt - > heroList . update ( ) ;
adventureInt - > townList . update ( ) ;
2013-07-21 21:27:33 +03:00
const CGHeroInstance * heroToSelect = nullptr ;
// find first non-sleeping hero
for ( auto hero : wanderingHeroes )
{
if ( boost : : range : : find ( sleepingHeroes , hero ) = = sleepingHeroes . end ( ) )
{
heroToSelect = hero ;
break ;
}
}
//select first hero if available.
if ( heroToSelect ! = nullptr )
{
adventureInt - > select ( heroToSelect ) ;
}
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-06-13 16:04:06 +03:00
//show new day animation and sound on infobar
adventureInt - > infoBar . showDate ( ) ;
2013-06-26 14:18:27 +03:00
adventureInt - > updateNextHero ( nullptr ) ;
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 ( ) ;
}
2013-11-30 12:43:31 +03:00
// warn player if he has no town
if ( cb - > howManyTowns ( ) = = 0 )
{
auto playerColor = * cb - > getPlayerID ( ) ;
std : : vector < Component > components ;
components . push_back ( Component ( Component : : FLAG , playerColor . getNum ( ) , 0 , 0 ) ) ;
MetaString text ;
2013-12-06 22:44:11 +03:00
auto daysWithoutCastle = * cb - > getPlayer ( playerColor ) - > daysWithoutCastle ;
if ( daysWithoutCastle < 6 )
2013-11-30 12:43:31 +03:00
{
2013-12-06 22:44:11 +03:00
text . addTxt ( MetaString : : ARRAY_TXT , 128 ) ; //%s, you only have %d days left to capture a town or you will be banished from this land.
2013-11-30 12:43:31 +03:00
text . addReplacement ( MetaString : : COLOR , playerColor . getNum ( ) ) ;
2013-12-06 22:44:11 +03:00
text . addReplacement ( 7 - daysWithoutCastle ) ;
2013-11-30 12:43:31 +03:00
}
2013-12-06 22:44:11 +03:00
else if ( daysWithoutCastle = = 6 )
2013-11-30 12:43:31 +03:00
{
2013-12-06 22:44:11 +03:00
text . addTxt ( MetaString : : ARRAY_TXT , 129 ) ; //%s, this is your last day to capture a town or you will be banished from this land.
2013-11-30 12:43:31 +03:00
text . addReplacement ( MetaString : : COLOR , playerColor . getNum ( ) ) ;
}
showInfoDialogAndWait ( components , text ) ;
}
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 )
{
2012-06-22 14:40:16 +03:00
adventureInt - > infoBar . showSelection ( ) ;
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 ;
2013-06-23 14:25:48 +03:00
BATTLE_EVENT_POSSIBLE_RETURN ;
2010-05-07 15:29:41 +03:00
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 ;
2012-09-23 21:01:04 +03:00
if ( market - > o - > ID = = Obj : : ALTAR_OF_SACRIFICE )
2010-07-20 09:05:45 +03:00
{
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 ;
2013-06-29 16:05:48 +03:00
auto cuw = new CUniversityWindow ( visitor , market ) ;
2010-07-20 17:08:13 +03:00
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 ;
2013-06-29 16:05:48 +03:00
auto chfw = new CHillFortWindow ( visitor , object ) ;
2010-07-22 03:32:45 +03:00
GH . pushInt ( chfw ) ;
}
2013-06-26 14:18:27 +03:00
void CPlayerInterface : : availableArtifactsChanged ( const CGBlackMarket * bm /*= nullptr*/ )
2010-06-27 19:03:01 +03:00
{
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 ;
2013-06-29 16:05:48 +03:00
auto tv = new CTavernWindow ( townOrTavern ) ;
2010-07-09 02:03:27 +03:00
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 ;
2013-06-29 16:05:48 +03:00
auto tgw = new CThievesGuildWindow ( obj ) ;
2012-03-07 17:05:54 +03:00
GH . pushInt ( tgw ) ;
}
2012-07-06 22:12:04 +03:00
void CPlayerInterface : : showQuestLog ( )
{
EVENT_HANDLER_CALLED_BY_CLIENT ;
CQuestLog * ql = new CQuestLog ( LOCPLINT - > cb - > getMyQuests ( ) ) ;
GH . pushInt ( ql ) ;
}
2010-07-13 08:25:40 +03:00
void CPlayerInterface : : showShipyardDialogOrProblemPopup ( const IShipyard * obj )
{
2013-07-21 13:08:32 +03:00
if ( obj - > shipyardStatus ( ) ! = IBoatGenerator : : GOOD )
2010-07-13 08:25:40 +03:00
{
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 ) ;
2013-12-06 22:44:11 +03:00
cb - > unregisterAllInterfaces ( ) ;
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
{
2012-09-11 17:25:19 +03:00
CGuiHandler : : pushSDLEvent ( SDL_USEREVENT , code ) ;
2010-08-18 12:50:25 +03:00
}
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 ) ;
}
void CPlayerInterface : : stacksSwapped ( const StackLocation & loc1 , const StackLocation & loc2 )
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2012-12-11 15:12:46 +03:00
std : : vector < const CGObjectInstance * > objects ;
objects . push_back ( loc1 . army ) ;
2010-12-14 23:55:23 +02:00
if ( loc2 . army ! = loc1 . army )
2012-12-11 15:12:46 +03:00
objects . push_back ( loc2 . army ) ;
garrisonsChanged ( objects ) ;
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 ;
2012-12-11 15:12:46 +03:00
std : : vector < const CGObjectInstance * > objects ;
objects . push_back ( src . army ) ;
if ( src . army ! = dst . army )
objects . push_back ( dst . army ) ;
garrisonsChanged ( objects ) ;
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 ;
2013-12-28 21:57:08 +03:00
adventureInt - > infoBar . showSelection ( ) ;
2013-06-29 16:05:48 +03:00
for ( IShowActivatable * isa : GH . listInt )
2011-04-23 00:51:10 +03:00
{
2012-06-15 20:08:19 +03:00
auto artWin = dynamic_cast < CArtifactHolder * > ( isa ) ;
if ( artWin )
artWin - > 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 ;
2013-12-28 21:57:08 +03:00
adventureInt - > infoBar . showSelection ( ) ;
2013-06-29 16:05:48 +03:00
for ( IShowActivatable * isa : GH . listInt )
2011-03-22 15:19:07 +02:00
{
2012-06-15 20:08:19 +03:00
auto artWin = dynamic_cast < CArtifactHolder * > ( isa ) ;
if ( artWin )
artWin - > 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 ;
2013-12-28 21:57:08 +03:00
adventureInt - > infoBar . showSelection ( ) ;
2013-06-29 16:05:48 +03:00
for ( IShowActivatable * isa : GH . listInt )
2011-03-22 15:19:07 +02:00
{
2012-06-15 20:08:19 +03:00
auto artWin = dynamic_cast < CArtifactHolder * > ( isa ) ;
if ( artWin )
artWin - > 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 ;
2013-12-28 21:57:08 +03:00
adventureInt - > infoBar . showSelection ( ) ;
2013-06-29 16:05:48 +03:00
for ( IShowActivatable * isa : GH . listInt )
2011-03-22 15:19:07 +02:00
{
2012-06-15 20:08:19 +03:00
auto artWin = dynamic_cast < CArtifactHolder * > ( isa ) ;
if ( artWin )
artWin - > artifactDisassembled ( al ) ;
2011-03-22 15:19:07 +02:00
}
2011-01-22 05:43:20 +02:00
}
2013-03-03 20:06:03 +03:00
void CPlayerInterface : : playerStartsTurn ( PlayerColor player )
2012-02-14 21:04:45 +03:00
{
2012-04-06 18:02:15 +03:00
EVENT_HANDLER_CALLED_BY_CLIENT ;
2013-12-28 21:57:08 +03:00
adventureInt - > infoBar . showSelection ( ) ;
2013-01-25 17:39:28 +03:00
if ( ! vstd : : contains ( GH . listInt , adventureInt ) )
2012-02-17 00:19:07 +03:00
{
2013-01-25 17:39:28 +03:00
GH . popInts ( GH . listInt . size ( ) ) ; //after map load - remove everything else
GH . pushInt ( adventureInt ) ;
2012-04-06 18:02:15 +03:00
}
2013-01-25 17:39:28 +03:00
else
{
while ( GH . listInt . front ( ) ! = adventureInt & & ! dynamic_cast < CInfoWindow * > ( GH . listInt . front ( ) ) ) //don't remove dialogs that expect query answer
GH . popInts ( 1 ) ;
}
2012-04-06 18:02:15 +03:00
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
{
2013-11-03 15:51:25 +03:00
while ( ! dialogs . empty ( ) )
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
}
2014-06-18 13:31:11 +03:00
bool CPlayerInterface : : capturedAllEvents ( )
{
2014-06-21 09:49:27 +03:00
if ( duringMovement )
{
2014-06-21 10:35:08 +03:00
//just inform that we are capturing events. they will be processed by heroMoved() in client thread.
2014-06-21 09:49:27 +03:00
return true ;
}
2014-06-21 16:41:05 +03:00
if ( ignoreEvents )
{
boost : : unique_lock < boost : : mutex > un ( eventsM ) ;
while ( ! events . empty ( ) )
{
events . pop ( ) ;
}
return true ;
}
2014-06-18 13:31:11 +03:00
return false ;
}
void CPlayerInterface : : doMoveHero ( const CGHeroInstance * h , CGPath path )
{
int i = 1 ;
2014-06-21 09:49:27 +03:00
2014-06-18 13:31:11 +03:00
{
2014-06-21 09:49:27 +03:00
path . convert ( 0 ) ;
boost : : unique_lock < boost : : mutex > un ( stillMoveHero . mx ) ;
stillMoveHero . data = CONTINUE_MOVE ;
2014-06-18 13:31:11 +03:00
2014-06-21 09:49:27 +03:00
ETerrainType currentTerrain = ETerrainType : : BORDER ; // not init yet
ETerrainType newTerrain ;
int sh = - 1 ;
2014-06-18 13:31:11 +03:00
2014-06-21 09:49:27 +03:00
const TerrainTile * curTile = cb - > getTile ( CGHeroInstance : : convertPosition ( h - > pos , false ) ) ;
2014-06-18 13:31:11 +03:00
2014-06-21 09:49:27 +03:00
for ( i = path . nodes . size ( ) - 1 ; i > 0 & & ( stillMoveHero . data = = CONTINUE_MOVE | | curTile - > blocked ) ; i - - )
{
//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 ;
2014-06-18 13:31:11 +03:00
2014-06-21 09:49:27 +03:00
//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 )
2014-06-18 13:31:11 +03:00
{
2014-06-21 09:49:27 +03:00
stillMoveHero . data = STOP_MOVE ;
break ;
}
2014-06-18 13:31:11 +03:00
2014-06-21 09:49:27 +03:00
// Start a new sound for the hero movement or let the existing one carry on.
2014-06-18 13:31:11 +03:00
#if 0
2014-06-21 09:49:27 +03:00
// TODO
if ( hero is flying & & sh = = - 1 )
sh = CCS - > soundh - > playSound ( soundBase : : horseFlying , - 1 ) ;
2014-06-18 13:31:11 +03:00
# endif
2014-06-21 09:49:27 +03:00
{
newTerrain = cb - > getTile ( CGHeroInstance : : convertPosition ( path . nodes [ i ] . coord , false ) ) - > terType ;
if ( newTerrain ! = currentTerrain )
2014-06-18 13:31:11 +03:00
{
2014-06-21 09:49:27 +03:00
CCS - > soundh - > stopSound ( sh ) ;
sh = CCS - > soundh - > playSound ( CCS - > soundh - > horseSounds [ newTerrain ] , - 1 ) ;
currentTerrain = newTerrain ;
2014-06-18 13:31:11 +03:00
}
2014-06-21 09:49:27 +03:00
}
2014-06-18 13:31:11 +03:00
2014-06-21 09:49:27 +03:00
stillMoveHero . data = WAITING_MOVE ;
2014-06-18 13:31:11 +03:00
2014-06-21 09:49:27 +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 - > getGuardingCreaturePosition ( endpos - int3 ( 1 , 0 , 0 ) ) ) ;
2014-06-18 13:31:11 +03:00
2014-06-21 09:49:27 +03:00
logGlobal - > traceStream ( ) < < " Requesting hero movement to " < < endpos ;
cb - > moveHero ( h , endpos ) ;
2014-06-18 13:31:11 +03:00
2014-06-21 09:49:27 +03:00
while ( stillMoveHero . data ! = STOP_MOVE & & stillMoveHero . data ! = CONTINUE_MOVE )
stillMoveHero . cond . wait ( un ) ;
2014-06-18 13:31:11 +03:00
2014-06-21 09:49:27 +03:00
logGlobal - > traceStream ( ) < < " Resuming " < < __FUNCTION__ ;
if ( guarded | | showingDialog - > get ( ) = = true ) // Abort movement if a guard was fought or there is a dialog to display (Mantis #1136)
break ;
2014-06-18 13:31:11 +03:00
}
2014-06-21 09:49:27 +03:00
CCS - > soundh - > stopSound ( sh ) ;
2014-06-18 13:31:11 +03:00
}
2014-06-21 09:49:27 +03:00
//Update cursor so icon can change if needed when it reappears; doesn;'t apply if a dialog box pops up at the end of the movement
if ( ! showingDialog - > get ( ) )
GH . fakeMouseMove ( ) ;
2014-06-18 13:31:11 +03:00
//todo: this should be in main thread
if ( adventureInt )
{
// (i == 0) means hero went through all the path
adventureInt - > updateMoveHero ( h , ( i ! = 0 ) ) ;
adventureInt - > updateNextHero ( h ) ;
}
2014-06-21 09:49:27 +03:00
duringMovement = false ;
2014-06-18 13:31:11 +03:00
}